From e1872d030a144fd6fb765474aca29c661a70d476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=BE=E5=90=8C=E5=AD=A6?= Date: Mon, 18 Aug 2025 16:26:30 +0800 Subject: [PATCH] =?UTF-8?q?UPDATE:=E5=AE=8C=E5=96=84=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E5=AD=90=E8=AE=A1=E5=88=92=E5=85=83=E4=BF=A1=E6=81=AFzip?= =?UTF-8?q?=E5=8C=85=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plan/controller/AdPlanController.java | 1 + .../gather/plan/service/IAdPlanService.java | 11 +- .../plan/service/impl/AdPlanServiceImpl.java | 191 ++++++++++++++---- 3 files changed, 165 insertions(+), 38 deletions(-) diff --git a/detection/src/main/java/com/njcn/gather/plan/controller/AdPlanController.java b/detection/src/main/java/com/njcn/gather/plan/controller/AdPlanController.java index 02eb52c4..0b9ae7be 100644 --- a/detection/src/main/java/com/njcn/gather/plan/controller/AdPlanController.java +++ b/detection/src/main/java/com/njcn/gather/plan/controller/AdPlanController.java @@ -375,6 +375,7 @@ public class AdPlanController extends BaseController { fileTypeError.setMessage("请上传zip文件"); throw new BusinessException(fileTypeError); } + adPlanService.importSubPlanDataZip(file, patternId, response); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe); } diff --git a/detection/src/main/java/com/njcn/gather/plan/service/IAdPlanService.java b/detection/src/main/java/com/njcn/gather/plan/service/IAdPlanService.java index 07bd6bfd..60ea8063 100644 --- a/detection/src/main/java/com/njcn/gather/plan/service/IAdPlanService.java +++ b/detection/src/main/java/com/njcn/gather/plan/service/IAdPlanService.java @@ -173,10 +173,19 @@ public interface IAdPlanService extends IService { boolean updateBindStandardDev(String planId, List standardDevIds); /** - * 导出子计划元信息 + * 项目负责人导出子计划元信息 * * @param planId * @param response */ void exportSubPlanDataZip(String planId, HttpServletResponse response); + /** + * 项目成员导入子计划元信息 + * + * @param file + * @param patternId + * @param response + */ + boolean importSubPlanDataZip(MultipartFile file, String patternId, HttpServletResponse response); + } diff --git a/detection/src/main/java/com/njcn/gather/plan/service/impl/AdPlanServiceImpl.java b/detection/src/main/java/com/njcn/gather/plan/service/impl/AdPlanServiceImpl.java index ebf511e3..43124cec 100644 --- a/detection/src/main/java/com/njcn/gather/plan/service/impl/AdPlanServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/plan/service/impl/AdPlanServiceImpl.java @@ -33,6 +33,7 @@ import com.njcn.gather.device.pojo.vo.PqDevVO; import com.njcn.gather.device.pojo.vo.ProvinceDevExcel; import com.njcn.gather.device.service.IPqDevService; import com.njcn.gather.device.service.IPqDevSubService; +import com.njcn.gather.device.service.IPqStandardDevService; import com.njcn.gather.err.pojo.po.PqErrSys; import com.njcn.gather.err.pojo.po.PqErrSysDtls; import com.njcn.gather.err.service.IPqErrSysDtlsService; @@ -126,6 +127,7 @@ public class AdPlanServiceImpl extends ServiceImpl impleme private final IAdPlanStandardDevService adPlanContrastStandardDevService; private final IPqMonitorService pqMonitorService; private final IPqErrSysDtlsService pqErrSysDtlsService; + private final IPqStandardDevService pqStandardDevService; @Override public List listAdPlan(AdPlanParam.QueryParam queryParam) { @@ -1572,6 +1574,7 @@ public class AdPlanServiceImpl extends ServiceImpl impleme PqReport reportTemplate = SpringUtil.getBean(IPqReportService.class).getById(subPlan.getReportTemplateId()); subPlanMetaData.setReportTemplate(reportTemplate); String basePath = reportTemplate.getBasePath(); + String detailPath = reportTemplate.getDetailPath(); // 导出数据.zip文件 String jsonStr = JSONUtil.toJsonStr(subPlanMetaData); @@ -1591,48 +1594,31 @@ public class AdPlanServiceImpl extends ServiceImpl impleme // 先将json文件添加到zip中 ZipUtil.zip(jsonFile.getAbsolutePath(), zipFile.getAbsolutePath()); + + // 创建一个临时目录存放两个文件 + File tempZipDir = FileUtil.mkdir(FileUtil.getTmpDirPath() + "temp_plan_" + System.currentTimeMillis() + "/"); + + // 复制json文件到临时目录 + FileUtil.copy(jsonFile, tempZipDir, true); // 如果basePath存在,则将basePath中的文件添加到已有的zip文件中 if (FileUtil.exist(basePath)) { File baseFile = new File(basePath); - if (baseFile.isDirectory()) { - // 如果是目录,将目录内容添加到zip中 - File[] files = baseFile.listFiles(); - if (files != null && files.length > 0) { - // 创建一个临时目录用于存放所有需要压缩的文件 - File tempZipDir = FileUtil.mkdir(FileUtil.getTmpDirPath() + "zip_temp_" + System.currentTimeMillis() + "/"); - - // 复制json文件到临时目录 - FileUtil.copy(jsonFile, tempZipDir, true); - - // 复制basePath目录下的所有文件到临时目录 - for (File file : files) { - FileUtil.copy(file, tempZipDir, true); - } - - // 重新创建zip文件,包含所有文件 - ZipUtil.zip(tempZipDir.getAbsolutePath(), zipFile.getAbsolutePath()); - - // 删除临时目录 - FileUtil.del(tempZipDir); - } - } else { - // 如果是单个文件,创建一个临时目录存放两个文件 - File tempZipDir = FileUtil.mkdir(FileUtil.getTmpDirPath() + "zip_temp_" + System.currentTimeMillis() + "/"); - - // 复制json文件到临时目录 - FileUtil.copy(jsonFile, tempZipDir, true); - - // 复制baseFile到临时目录 - FileUtil.copy(baseFile, tempZipDir, true); - - // 重新创建zip文件,包含所有文件 - ZipUtil.zip(tempZipDir.getAbsolutePath(), zipFile.getAbsolutePath()); - - // 删除临时目录 - FileUtil.del(tempZipDir); - } + // 复制baseFile到临时目录 + FileUtil.copy(baseFile, tempZipDir, true); + } + // 如果detailPath存在,则将detailPath中的文件添加到已有的zip文件中 + if (FileUtil.exist(detailPath)) { + File detailFile = new File(detailPath); + // 复制detailFile到临时目录 + FileUtil.copy(detailFile, tempZipDir, true); } + + // 重新创建zip文件,包含所有文件 + ZipUtil.zip(tempZipDir.getAbsolutePath(), zipFile.getAbsolutePath()); + + // 删除临时目录 + FileUtil.del(tempZipDir); // 设置响应头 response.reset(); response.setContentType("application/octet-stream;charset=UTF-8"); @@ -1651,4 +1637,135 @@ public class AdPlanServiceImpl extends ServiceImpl impleme throw new BusinessException(CommonResponseEnum.FAIL); } } + @Transactional + @Override + public boolean importSubPlanDataZip(MultipartFile file, String patternId, HttpServletResponse response) { + try { + // 创建临时目录用于解压文件 + File tempDir = FileUtil.mkdir(FileUtil.getTmpDirPath() + "import_plan_" + System.currentTimeMillis() + "/"); + + // 将上传的zip文件保存到临时目录 + File zipFile = FileUtil.file(tempDir, file.getOriginalFilename()); + file.transferTo(zipFile); + + // 解压zip文件 + File unzipDir = FileUtil.mkdir(FileUtil.file(tempDir, "unzip")); + ZipUtil.unzip(zipFile.getAbsolutePath(), unzipDir.getAbsolutePath()); + + // 查找解压目录中的json文件 + File[] files = unzipDir.listFiles(); + AdSubPlanMetaDataVO subPlanMetaDataVO = null; + if (files != null) { + for (File f : files) { + if (f.isFile() && f.getName().endsWith(".json")) { + // 读取json文件内容 + String jsonStr = FileUtil.readUtf8String(f); + subPlanMetaDataVO = JSONUtil.toBean(jsonStr, AdSubPlanMetaDataVO.class); + break; + } + } + } + + if (subPlanMetaDataVO == null) { + FileUtil.del(tempDir); + throw new BusinessException(CommonResponseEnum.FAIL, "ZIP文件中未找到JSON文件"); + } + AdPlan plan = subPlanMetaDataVO.getPlan(); + if (plan == null) { + FileUtil.del(tempDir); + throw new BusinessException(CommonResponseEnum.FAIL, "ZIP文件中未找到检测计划信息"); + } + if (!StrUtil.equals(plan.getPattern(), patternId)) { + FileUtil.del(tempDir); + throw new BusinessException(CommonResponseEnum.FAIL, "该检修计划当前模式不支持导入"); + } + // 更新检测计划信息 + plan.setFatherPlanId(CommonEnum.FATHER_ID.getValue()); + saveOrUpdate(plan); + + List devList = subPlanMetaDataVO.getDevList(); + List standardDevList = subPlanMetaDataVO.getStandardDevList(); + if(CollUtil.isEmpty(devList) || CollUtil.isEmpty(standardDevList)) { + FileUtil.del(tempDir); + throw new BusinessException(CommonResponseEnum.FAIL, "该检修计划未找到被检设备或标准设备信息"); + } + + // 批量更新被检设备信息 + pqDevService.saveOrUpdateBatch(devList); + devList.forEach(dev -> { + pqMonitorService.saveOrUpdateBatch(dev.getMonitorList()); + // 新增时默认设置 + PqDevSub pqDevSub = new PqDevSub(); + pqDevSub.setDevId(dev.getId()); + pqDevSub.setTimeCheckResult(TimeCheckResultEnum.UNKNOWN.getValue()); + pqDevSub.setFactorCheckResult(FactorCheckResultEnum.UNKNOWN.getValue()); + pqDevSub.setCheckState(CheckStateEnum.UNCHECKED.getValue()); + pqDevSub.setReportState(DevReportStateEnum.UNCHECKED.getValue()); + pqDevSub.setCheckResult(CheckResultEnum.UNCHECKED.getValue()); + pqDevSubService.save(pqDevSub); + }); + List devIds = devList.stream().map(PqDev::getId).collect(Collectors.toList()); + // 守时检测 + pqDevService.updatePqDevTimeCheckResult(devIds, TimeCheckResultEnum.UNKNOWN); + + // 批量更新标准设备信息 + pqStandardDevService.saveOrUpdateBatch(standardDevList); + List standardDevIds = standardDevList.stream().map(PqStandardDev::getId).collect(Collectors.toList()); + adPlanStandardDevService.updateAdPlanStandardDev(plan.getId(), standardDevIds); + + // 批量更新字典数据 + AdSubPlanMetaDataVO.Dict dict = subPlanMetaDataVO.getDict(); + if (dict != null) { + List typeList = dict.getTypeList(); + if (CollUtil.isNotEmpty(typeList)) { + dictTypeService.saveOrUpdateBatch(typeList); + List dataList = dict.getDataList(); + if(CollUtil.isNotEmpty(dataList)) { + dictDataService.saveOrUpdateBatch(dataList); + } + } + List treeList = dict.getTreeList(); + if (treeList != null) { + dictTreeService.saveOrUpdateBatch(treeList); + } + } + // 更新检测配置 + SysTestConfig testConfig = subPlanMetaDataVO.getTestConfig(); + if (testConfig != null) { + sysTestConfigService.saveOrUpdate(testConfig); + } + + // 批量更新误差体系 + List errSysList = subPlanMetaDataVO.getErrSysList(); + if (CollUtil.isNotEmpty(errSysList)) { + pqErrSysService.saveOrUpdateBatch(errSysList); + List errSysDtlsList = subPlanMetaDataVO.getErrSysDtlsList(); + if (CollUtil.isNotEmpty(errSysDtlsList)) { + pqErrSysDtlsService.saveOrUpdateBatch(errSysDtlsList); + } + } + // 批量更新设备类型数据 + List devTypeList = subPlanMetaDataVO.getDevTypeList(); + if (CollUtil.isNotEmpty(devTypeList)) { + devTypeService.saveOrUpdateBatch(devTypeList); + } + tableGenService.deleteTable(Collections.singletonList(plan.getCode().toString())); + tableGenService.genTable(plan.getCode().toString(), true); + + // 更新报告模版 + PqReport reportTemplate = subPlanMetaDataVO.getReportTemplate(); + SpringUtil.getBean(IPqReportService.class).saveOrUpdate(reportTemplate); + + // 删除临时目录 + FileUtil.del(tempDir); + return true; + } catch (IOException e) { + log.error("导入子计划数据失败: ", e); + throw new BusinessException(CommonResponseEnum.FAIL); + } catch (Exception e) { + log.error("处理JSON数据失败: ", e); + throw new BusinessException(CommonResponseEnum.FAIL); + } + } + }