eims-ui/apps/web-antd/src/views/_core/authentication/login.vue
@@ -51,10 +51,10 @@ onMounted(async () => { // 启动单点登录注释掉下边这一行,否则放开 await Promise.all([loadCaptcha(), loadTenant()]); // await Promise.all([loadCaptcha(), loadTenant()]); // 启动单点登录放开下边两行注释,否则注释掉 // const href = await authBinding('keycloak', '000000'); // window.location.href = href; const href = await authBinding('keycloak', '000000'); window.location.href = href; }); const formSchema = computed((): VbenFormSchema[] => { eims-ui/apps/web-antd/src/views/eims/insp-plan/insp-plan-import-modal.vue
@@ -26,15 +26,21 @@ async function handleSubmit() { try { modalApi.modalLoading(true); if (fileList.value.length !== 1) { if (fileList.value.length === 0) { handleCancel(); return; } const data = { file: fileList.value[0]!.originFileObj as Blob, updateSupport: unref(checked), }; const { code, msg } = await inspPlanImportData(data); // 构建包含多个文件的请求数据,支持多文件上传 const formData = new FormData(); fileList.value.forEach((file) => { const blob = file.originFileObj as Blob; formData.append('files', blob); // 将多个文件以数组形式添加到表单数据中 }); formData.append('updateSupport', unref(checked).toString()); // 添加 updateSupport 参数 // 调用接口上传多文件 const { code, msg } = await inspPlanImportData(formData); let modal = Modal.success; if (code === 200) { emit('reload'); @@ -76,7 +82,7 @@ <UploadDragger v-model:file-list="fileList" :before-upload="() => false" :max-count="1" :multiple="true" :show-upload-list="true" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" > eims-ui/apps/web-antd/src/views/eims/maint-plan/maint-plan-import-modal.vue
@@ -26,15 +26,21 @@ async function handleSubmit() { try { modalApi.modalLoading(true); if (fileList.value.length !== 1) { if (fileList.value.length === 0) { handleCancel(); return; } const data = { file: fileList.value[0]!.originFileObj as Blob, updateSupport: unref(checked), }; const { code, msg } = await maintPlanImportData(data); // 构建包含多个文件的请求数据,支持多文件上传 const formData = new FormData(); fileList.value.forEach((file) => { const blob = file.originFileObj as Blob; formData.append('files', blob); // 将多个文件以数组形式添加到表单数据中 }); formData.append('updateSupport', unref(checked).toString()); // 添加 updateSupport 参数 // 调用接口上传多文件 const { code, msg } = await maintPlanImportData(formData); let modal = Modal.success; if (code === 200) { emit('reload'); @@ -76,7 +82,7 @@ <UploadDragger v-model:file-list="fileList" :before-upload="() => false" :max-count="1" :multiple="true" :show-upload-list="true" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" > eims/ruoyi-admin/src/main/resources/application-prod.yml
@@ -193,7 +193,7 @@ type: keycloak: # keycloak 服务器地址 server-url: https://lanbaosystem.shlanbao.cn:8443 server-url: https://lanbaosystem.shlanbao.cn:8444 realm: lanbao client-id: DataCapture client-secret: kplisa4lJHEIM6knqefVbxln85QbA5NX eims/ruoyi-extend/ruoyi-snailjob-server/src/main/resources/application.yml
@@ -1,5 +1,5 @@ server: port: 8800 port: 8880 servlet: context-path: /snail-job eims/ruoyi-modules/lb-eims/src/main/java/org/dromara/eims/controller/EimsInspectPlanController.java
@@ -121,10 +121,13 @@ @Log(title = "点检计划", businessType = BusinessType.IMPORT) @SaCheckPermission("eims:inspectPlan:import") @PostMapping(value = "/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public R<Void> importData(@RequestPart("file") MultipartFile file, boolean updateSupport) throws Exception { // ExcelResult<InspectCheckItemVo> result = ExcelUtil.importExcel(file.getInputStream(), InspectCheckItemVo.class, new InspectCheckItemImportListener(updateSupport)); String res = eimsInspectPlanService.importData(file, updateSupport); return R.ok(res); public R<Void> importData(@RequestPart("files") List<MultipartFile> files, boolean updateSupport) throws Exception { StringBuilder successMsg = new StringBuilder(); for (MultipartFile file : files) { String res = eimsInspectPlanService.importData(file, updateSupport); successMsg.append(res).append(";"); } return R.ok(successMsg.toString()); } /** eims/ruoyi-modules/lb-eims/src/main/java/org/dromara/eims/controller/EimsMaintPlanController.java
@@ -120,13 +120,15 @@ @Log(title = "保养计划", businessType = BusinessType.IMPORT) @SaCheckPermission("eims:maintPlan:import") @PostMapping(value = "/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public R<Void> importData(@RequestPart("file") MultipartFile file, boolean updateSupport) throws Exception { //ExcelResult<MaintCheckItemVo> result = ExcelUtil.importExcel(file.getInputStream(), MaintCheckItemVo.class, new MaintCheckItemImportListener(updateSupport)); public R<Void> importData(@RequestPart("files") List<MultipartFile> files, boolean updateSupport) throws Exception { StringBuilder successMsg = new StringBuilder(); for (MultipartFile file : files) { String res = eimsMaintPlanService.importData(file, updateSupport); successMsg.append(res).append("; \r\n"); String res = eimsMaintPlanService.importData(file, updateSupport); return R.ok(res); } return R.ok(successMsg.toString()); } /** eims/ruoyi-modules/lb-eims/src/main/java/org/dromara/eims/domain/vo/InspectCheckItemVo.java
@@ -25,7 +25,7 @@ /** * 点检项名称 */ @ExcelProperty(value = "内容") @ExcelProperty(value = {"内容", "点检项目", "项目"}, index = 1) private String itemName; eims/ruoyi-modules/lb-eims/src/main/java/org/dromara/eims/service/impl/EimsInspectPlanServiceImpl.java
@@ -208,64 +208,73 @@ } @Override public String importData(MultipartFile file, boolean updateSupport) throws IOException, IOException { // 点检项目列表(假设存在对应的点检项VO) InspectCheckItemImportListener checkItemImportListener = new InspectCheckItemImportListener(updateSupport); EasyExcel.read(file.getInputStream(), InspectCheckItemVo.class, checkItemImportListener).headRowNumber(3).sheet().doRead(); List<InspectCheckItemVo> successList = checkItemImportListener.getSuccessList(); public String importData(MultipartFile file, boolean updateSupport) { try { // 点检项目列表(假设存在对应的点检项VO) InspectCheckItemImportListener checkItemImportListener = new InspectCheckItemImportListener(updateSupport); EasyExcel.read(file.getInputStream(), InspectCheckItemVo.class, checkItemImportListener) .headRowNumber(3).sheet().doRead(); List<InspectCheckItemVo> successList = checkItemImportListener.getSuccessList(); // 读取固定资产编号(假设位置不同) EasyExcelCellListener assetNoListener = new EasyExcelCellListener(2, 23); EasyExcel.read(file.getInputStream(), assetNoListener).headRowNumber(0).sheet().doReadSync(); String assetNo = Optional.ofNullable(assetNoListener.getCellValue()) .map(value -> { int colonIndex = Math.max(value.indexOf(":"), value.indexOf(":")); // 合并冒号处理 return colonIndex != -1 ? value.substring(colonIndex + 1) : value; }) .map(String::trim) .orElseThrow(() -> new ServiceException("导入失败,无法读取固定资产编号")); // 读取固定资产编号(假设位置不同) EasyExcelCellListener assetNoListener = new EasyExcelCellListener(2, 23); EasyExcel.read(file.getInputStream(), assetNoListener).headRowNumber(0).sheet().doReadSync(); String assetNo = Optional.ofNullable(assetNoListener.getCellValue()) .map(value -> { int colonIndex = Math.max(value.indexOf(":"), value.indexOf(":")); // 合并冒号处理 return colonIndex != -1 ? value.substring(colonIndex + 1) : value; }) .map(String::trim) .orElse(""); // 查询设备信息 QueryWrapper<EimsEqu> query = new QueryWrapper<>(); query.eq("asset_no", assetNo); EimsEquVo equVo = equMapper.selectVoOne(query); if (equVo == null) throw new ServiceException("设备未找到,请先在设备台帐中添加"); int successNum = 0; int failureNum = 0; StringBuilder successMsg = new StringBuilder(); StringBuilder failureMsg = new StringBuilder(); for (InspectCheckItemVo itemVo : successList) { if ("设备状态卡状态".equals(itemVo.getItemName())) break; // 如果允许覆盖,则删除已存在的记录 if (updateSupport) { LambdaQueryWrapper<EimsInspectPlan> deleteWrapper = Wrappers.lambdaQuery(); deleteWrapper.eq(EimsInspectPlan::getEquId, equVo.getEquId()) .eq(EimsInspectPlan::getInspName, itemVo.getItemName()) .eq(EimsInspectPlan::getStatus, "0"); baseMapper.delete(deleteWrapper); if (assetNo.isEmpty()) { return file.getOriginalFilename() + " 导入失败,无法读取固定资产编号"; } // 新增点检计划 EimsInspectPlanBo bo = new EimsInspectPlanBo(); bo.setEquId(equVo.getEquId()); bo.setInspName(itemVo.getItemName()); bo.setStatus("0"); bo.setInspType("1"); bo.setInspRule("0"); if (!insertByBo(bo)) { failureNum++; failureMsg.append(failureNum).append("、导入失败<br>"); } else { successNum++; successMsg.append(successNum).append("、导入成功<br>"); // 查询设备信息 QueryWrapper<EimsEqu> query = new QueryWrapper<>(); query.eq("asset_no", assetNo); EimsEquVo equVo = equMapper.selectVoOne(query); if (equVo == null) { return file.getOriginalFilename() + " 设备未找到,请先在设备台帐中添加"; } int successNum = 0; int failureNum = 0; for (InspectCheckItemVo itemVo : successList) { if ("设备状态卡状态".equals(itemVo.getItemName()) || itemVo.getItemName().contains("运行时间")) { break; } // 如果允许覆盖,则删除已存在的记录 if (updateSupport) { LambdaQueryWrapper<EimsInspectPlan> deleteWrapper = Wrappers.lambdaQuery(); deleteWrapper.eq(EimsInspectPlan::getEquId, equVo.getEquId()) .eq(EimsInspectPlan::getInspName, itemVo.getItemName()) .eq(EimsInspectPlan::getStatus, "0"); baseMapper.delete(deleteWrapper); } // 新增点检计划 EimsInspectPlanBo bo = new EimsInspectPlanBo(); bo.setEquId(equVo.getEquId()); bo.setInspName(itemVo.getItemName()); bo.setStatus("0"); bo.setInspType("1"); bo.setInspRule("0"); if (!insertByBo(bo)) { failureNum++; } else { successNum++; } } return file.getOriginalFilename() + " 导入成功:" + successNum + "条,导入失败:" + failureNum + "条"; } catch (Exception e) { return file.getOriginalFilename() + " 导入异常:" + e.getMessage(); } return failureNum > 0 ? failureMsg.toString() : successMsg.toString(); } eims/ruoyi-modules/lb-eims/src/main/java/org/dromara/eims/service/impl/EimsMaintPlanServiceImpl.java
@@ -204,153 +204,211 @@ } public String importData(MultipartFile is, boolean updateSupport) throws IOException { int successNum = 0; int failureNum = 0; StringBuilder successMsg = new StringBuilder(); StringBuilder failureMsg = new StringBuilder(); public String importData(MultipartFile is, boolean updateSupport) { try { int successNum = 0; int failureNum = 0; // 保养项目列表 MaintCheckItemImportListener checkItemImportListener = new MaintCheckItemImportListener(updateSupport); EasyExcel.read(is.getInputStream(), MaintCheckItemVo.class, checkItemImportListener).headRowNumber(4).sheet().doRead(); List<MaintCheckItemVo> successList = checkItemImportListener.getSuccessList(); // 保养项目列表 MaintCheckItemImportListener checkItemImportListener = new MaintCheckItemImportListener(updateSupport); EasyExcel.read(is.getInputStream(), MaintCheckItemVo.class, checkItemImportListener).headRowNumber(4).sheet().doRead(); List<MaintCheckItemVo> successList = checkItemImportListener.getSuccessList(); // 读取固定资产编号 EasyExcelCellListener readListener = new EasyExcelCellListener(3, 1); EasyExcel.read(is.getInputStream(), readListener).headRowNumber(0).sheet().doReadSync(); String assetNo = Optional.ofNullable(readListener.getCellValue()) .map(value -> { int colonIndex = Math.max(value.indexOf(":"), value.indexOf(":")); // 合并冒号处理 return colonIndex != -1 ? value.substring(colonIndex + 1) : value; }) .map(String::trim) .orElse(""); // 读取固定资产编号 EasyExcelCellListener readListener = new EasyExcelCellListener(3, 1); EasyExcel.read(is.getInputStream(), readListener).headRowNumber(0).sheet().doReadSync(); String assetNo = Optional.ofNullable(readListener.getCellValue()) .map(value -> { int colonIndex = Math.max(value.indexOf(":"), value.indexOf(":")); // 合并冒号处理 return colonIndex != -1 ? value.substring(colonIndex + 1) : value; }) .map(String::trim) .orElseThrow(() -> new ServiceException("导入失败,无法读取固定资产编号")); // 读取保养计划年份 EasyExcelCellListener readYearListener = new EasyExcelCellListener(2, 3); EasyExcel.read(is.getInputStream(), readYearListener).headRowNumber(0).sheet().doReadSync(); String yearStr = readYearListener.getCellValue(); String year = yearStr.replaceAll("[^\\d]", ""); // 去除非数字字符 year = (year.length() == 4) ? year : DateUtils.getDate().substring(0,4); QueryWrapper<EimsEqu> queryWrapper = new QueryWrapper<>(); queryWrapper.eq("asset_no", assetNo); EimsEquVo eimsEquVo = equMapper.selectVoOne(queryWrapper); if (eimsEquVo == null) throw new ServiceException("导入失败,设备未找到请在设备台帐中添加"); // 月份字段处理优化 String[] monthFields = {"january","february","march","april","may","june", "july","august","september","october","november","december"}; for (MaintCheckItemVo itemVo : successList) { if ("执行人签名".equals(itemVo.getItemName())) break; EimsMaintPlanBo maintPlanBo = new EimsMaintPlanBo(); maintPlanBo.setEquId(eimsEquVo.getEquId()); maintPlanBo.setMaintName(itemVo.getItemName()); maintPlanBo.setStatus("0"); maintPlanBo.setMaintType("1"); maintPlanBo.setMaintRule("0"); // 添加period校验 String period = itemVo.getPeriod(); if (StringUtils.isBlank(period)) { failureNum++; failureMsg.append(failureNum).append("、周期字段为空<br>"); continue; if (assetNo.isEmpty()) { return is.getOriginalFilename() + " 导入失败,无法读取固定资产编号"; } try { if (period.length() > 1) { maintPlanBo.setMaintCycle(Long.parseLong(period.substring(0, period.length() - 1))); String substring = period.substring(period.length() - 1); // 转换周期单位,M转换为3,D转换为1,Y转换为5,W转换为2,Q转换为4 switch (substring) { case "M": substring = "3"; break; case "D": substring = "1"; break; case "Y": substring = "5"; break; case "W": substring = "2"; break; case "Q": substring = "4"; break; default: } maintPlanBo.setMaintCycleUnit(substring); } else { maintPlanBo.setMaintCycle(Long.parseLong(period)); maintPlanBo.setMaintCycleUnit(""); } } catch (NumberFormatException e) { failureNum++; failureMsg.append(failureNum).append("、无效的周期格式:").append(period).append("<br>"); continue; // 读取保养计划年份 EasyExcelCellListener readYearListener = new EasyExcelCellListener(2, 3); EasyExcel.read(is.getInputStream(), readYearListener).headRowNumber(0).sheet().doReadSync(); String yearStr = readYearListener.getCellValue(); if (yearStr == null || yearStr.isEmpty()) { yearStr = ""; } String year = yearStr.replaceAll("[^\\d]", ""); // 去除非数字字符 year = (year.length() == 4) ? year : DateUtils.getDate().substring(0,4); QueryWrapper<EimsEqu> queryWrapper = new QueryWrapper<>(); queryWrapper.eq("asset_no", assetNo); EimsEquVo eimsEquVo = equMapper.selectVoOne(queryWrapper); if (eimsEquVo == null) { return is.getOriginalFilename() + " 设备未找到,请先在设备台帐中添加"; } // 月份判断优化 for (int i = 0; i < monthFields.length; i++) { try { String monthValue = (String) MaintCheckItemVo.class .getMethod("get" + StringUtils.capitalize(monthFields[i])) .invoke(itemVo); // 月份字段处理优化 String[] monthFields = {"january","february","march","april","may","june", "july","august","september","october","november","december"}; if (StringUtils.isNotBlank(monthValue)) { String month = String.format("%02d", i+1); // 保证两位月份 maintPlanBo.setMaintFirstTime(DateUtils.parseDate(year + "-" + month + "-01")); break; } } catch (Exception e) { // 反射异常处理 for (MaintCheckItemVo itemVo : successList) { if ("执行人签名".equals(itemVo.getItemName())) break; EimsMaintPlanBo maintPlanBo = new EimsMaintPlanBo(); maintPlanBo.setEquId(eimsEquVo.getEquId()); maintPlanBo.setMaintName(itemVo.getItemName()); maintPlanBo.setStatus("0"); maintPlanBo.setMaintType("1"); maintPlanBo.setMaintRule("0"); // 添加period校验 String period = itemVo.getPeriod(); if (StringUtils.isBlank(period)) { failureNum++; failureMsg.append(failureNum).append("、月份字段访问异常<br>"); continue; } if (period.length() == 1) { period = "1"+period; } try { if (period.length() > 1) { String num = period.replaceAll("[^\\d]", ""); if ("".equals(num)) { switch (period) { case "一个月": maintPlanBo.setMaintCycle(1L); maintPlanBo.setMaintCycleUnit("3"); break; case "两个月": maintPlanBo.setMaintCycle(2L); maintPlanBo.setMaintCycleUnit("3"); break; case "二个月": maintPlanBo.setMaintCycle(2L); maintPlanBo.setMaintCycleUnit("3"); break; case "三个月": maintPlanBo.setMaintCycle(3L); maintPlanBo.setMaintCycleUnit("3"); break; case "六个月": maintPlanBo.setMaintCycle(6L); maintPlanBo.setMaintCycleUnit("3"); break; default: break; } }else { maintPlanBo.setMaintCycle(Long.parseLong(num)); String substring = period.replace(num, ""); // 转换周期单位,M转换为3,D转换为1,Y转换为5,W转换为2,Q转换为4 switch (substring) { case "M": substring = "3"; break; case "D": substring = "1"; break; case "Y": substring = "5"; break; case "W": substring = "2"; break; case "Q": substring = "4"; break; case "个月": substring = "3"; break; case "天": substring = "1"; break; case "年": substring = "5"; break; case "周": substring = "2"; break; case "季度": substring = "4"; break; default: } maintPlanBo.setMaintCycleUnit(substring); } } else { maintPlanBo.setMaintCycle(Long.parseLong(period)); maintPlanBo.setMaintCycleUnit(""); } } catch (NumberFormatException e) { failureNum++; continue; } // 月份判断优化 boolean monthFound = false; for (int i = 0; i < monthFields.length; i++) { try { String monthValue = (String) MaintCheckItemVo.class .getMethod("get" + StringUtils.capitalize(monthFields[i])) .invoke(itemVo); if (StringUtils.isNotBlank(monthValue)) { String month = String.format("%02d", i+1); // 保证两位月份 maintPlanBo.setMaintFirstTime(DateUtils.parseDate(year + "-" + month + "-01")); monthFound = true; break; } } catch (Exception e) { // 反射异常处理,继续下一个月份 continue; } } if (!monthFound) { failureNum++; continue; } if (maintPlanBo.getMaintFirstTime() != null) { Date firstTime = maintPlanBo.getMaintFirstTime(); Date nextTime = calcNextTime(firstTime, maintPlanBo.getMaintCycle().intValue(), 1); maintPlanBo.setMaintNextTime(nextTime); } // 如果允许覆盖,则删除已存在的相同条件记录 if (updateSupport) { LambdaQueryWrapper<EimsMaintPlan> deleteWrapper = Wrappers.lambdaQuery(); deleteWrapper.eq(EimsMaintPlan::getEquId, maintPlanBo.getEquId()) .eq(EimsMaintPlan::getMaintName, maintPlanBo.getMaintName()) .eq(EimsMaintPlan::getStatus, maintPlanBo.getStatus()) .eq(EimsMaintPlan::getMaintCycle, maintPlanBo.getMaintCycle()) .eq(EimsMaintPlan::getMaintCycleUnit, maintPlanBo.getMaintCycleUnit()); baseMapper.delete(deleteWrapper); } if (!insertByBo(maintPlanBo)) { failureNum++; } else { successNum++; } } if (maintPlanBo.getMaintFirstTime() != null) { Date firstTime = maintPlanBo.getMaintFirstTime(); Date nextTime = calcNextTime(firstTime, maintPlanBo.getMaintCycle().intValue(), 1); maintPlanBo.setMaintNextTime(nextTime); } // 如果允许覆盖,则删除已存在的相同条件记录 if (updateSupport) { LambdaQueryWrapper<EimsMaintPlan> deleteWrapper = Wrappers.lambdaQuery(); deleteWrapper.eq(EimsMaintPlan::getEquId, maintPlanBo.getEquId()) .eq(EimsMaintPlan::getMaintName, maintPlanBo.getMaintName()) .eq(EimsMaintPlan::getStatus, maintPlanBo.getStatus()) .eq(EimsMaintPlan::getMaintCycle, maintPlanBo.getMaintCycle()) .eq(EimsMaintPlan::getMaintCycleUnit, maintPlanBo.getMaintCycleUnit()); baseMapper.delete(deleteWrapper); } if (!insertByBo(maintPlanBo)) { failureNum++; failureMsg.append(failureNum).append("、设备:").append(eimsEquVo.getEquName()).append(",导入失败<br>"); // 如果失败条件小于1则不打印信息 if (failureNum <= 0) { return "成功!"; } else { successNum++; successMsg.append("<br/>").append(successNum).append("、设备:").append(eimsEquVo.getEquName()).append(",导入成功"); return is.getOriginalFilename() + " 导入成功:" + successNum + "条,导入失败:" + failureNum + "条"; } } if (failureNum > 0) { failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); return failureMsg.toString(); } else { successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:"); return successMsg.toString(); } catch (Exception e) { return is.getOriginalFilename() + " 导入异常:" + e.getMessage(); } } } private Date calcNextTime(Date firstTime, int intervalMonths, int initialOffset) {