UPDATE:完善导出子计划元信息zip包;
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
@@ -173,10 +173,19 @@ public interface IAdPlanService extends IService<AdPlan> {
|
||||
boolean updateBindStandardDev(String planId, List<String> 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);
|
||||
|
||||
}
|
||||
|
||||
@@ -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<AdPlanMapper, AdPlan> impleme
|
||||
private final IAdPlanStandardDevService adPlanContrastStandardDevService;
|
||||
private final IPqMonitorService pqMonitorService;
|
||||
private final IPqErrSysDtlsService pqErrSysDtlsService;
|
||||
private final IPqStandardDevService pqStandardDevService;
|
||||
|
||||
@Override
|
||||
public List<AdPlanVO> listAdPlan(AdPlanParam.QueryParam queryParam) {
|
||||
@@ -1572,6 +1574,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> 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<AdPlanMapper, AdPlan> 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<AdPlanMapper, AdPlan> 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<PqDev> devList = subPlanMetaDataVO.getDevList();
|
||||
List<PqStandardDev> 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<String> devIds = devList.stream().map(PqDev::getId).collect(Collectors.toList());
|
||||
// 守时检测
|
||||
pqDevService.updatePqDevTimeCheckResult(devIds, TimeCheckResultEnum.UNKNOWN);
|
||||
|
||||
// 批量更新标准设备信息
|
||||
pqStandardDevService.saveOrUpdateBatch(standardDevList);
|
||||
List<String> standardDevIds = standardDevList.stream().map(PqStandardDev::getId).collect(Collectors.toList());
|
||||
adPlanStandardDevService.updateAdPlanStandardDev(plan.getId(), standardDevIds);
|
||||
|
||||
// 批量更新字典数据
|
||||
AdSubPlanMetaDataVO.Dict dict = subPlanMetaDataVO.getDict();
|
||||
if (dict != null) {
|
||||
List<DictType> typeList = dict.getTypeList();
|
||||
if (CollUtil.isNotEmpty(typeList)) {
|
||||
dictTypeService.saveOrUpdateBatch(typeList);
|
||||
List<DictData> dataList = dict.getDataList();
|
||||
if(CollUtil.isNotEmpty(dataList)) {
|
||||
dictDataService.saveOrUpdateBatch(dataList);
|
||||
}
|
||||
}
|
||||
List<DictTree> treeList = dict.getTreeList();
|
||||
if (treeList != null) {
|
||||
dictTreeService.saveOrUpdateBatch(treeList);
|
||||
}
|
||||
}
|
||||
// 更新检测配置
|
||||
SysTestConfig testConfig = subPlanMetaDataVO.getTestConfig();
|
||||
if (testConfig != null) {
|
||||
sysTestConfigService.saveOrUpdate(testConfig);
|
||||
}
|
||||
|
||||
// 批量更新误差体系
|
||||
List<PqErrSys> errSysList = subPlanMetaDataVO.getErrSysList();
|
||||
if (CollUtil.isNotEmpty(errSysList)) {
|
||||
pqErrSysService.saveOrUpdateBatch(errSysList);
|
||||
List<PqErrSysDtls> errSysDtlsList = subPlanMetaDataVO.getErrSysDtlsList();
|
||||
if (CollUtil.isNotEmpty(errSysDtlsList)) {
|
||||
pqErrSysDtlsService.saveOrUpdateBatch(errSysDtlsList);
|
||||
}
|
||||
}
|
||||
// 批量更新设备类型数据
|
||||
List<DevType> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user