diff --git a/detection/src/main/java/com/njcn/gather/report/service/impl/ReportServiceImpl.java b/detection/src/main/java/com/njcn/gather/report/service/impl/ReportServiceImpl.java index b002444d..412b3ad6 100644 --- a/detection/src/main/java/com/njcn/gather/report/service/impl/ReportServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/report/service/impl/ReportServiceImpl.java @@ -27,6 +27,7 @@ import com.njcn.gather.storage.pojo.po.AdHarmonicResult; import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult; import com.njcn.gather.storage.service.AdHarmonicService; import com.njcn.gather.storage.service.AdNonHarmonicService; +import com.njcn.gather.system.dictionary.pojo.po.DictData; import com.njcn.gather.system.dictionary.service.IDictDataService; import com.njcn.gather.type.pojo.po.DevType; import com.njcn.gather.type.service.IDevTypeService; @@ -78,22 +79,27 @@ public class ReportServiceImpl implements IReportService { @Override public void generateReport(DevReportParam devReportParam) { + // 根据设备类型找到报告模板 + PqDevVO pqDevVO = iPqDevService.getPqDevById(devReportParam.getDevId()); + if (Objects.isNull(pqDevVO)) { + throw new BusinessException("请检查装置是否存在!"); + } + // 获取设备型号 + DevType devType = devTypeService.getById(pqDevVO.getDevType()); + if (Objects.isNull(devType)) { + throw new BusinessException("设备类型缺失,请联系管理员!"); + } + DictData reportName = devTypeService.getReportName(pqDevVO.getDevType()); + if (Objects.isNull(reportName)) { + throw new BusinessException("报告模板缺失,请联系管理员!"); + } // 读取模板文件 - ClassPathResource resource = new ClassPathResource("/model/BaseModel.docx"); + ClassPathResource resource = new ClassPathResource("/model/" + reportName.getCode() + ".docx"); try (InputStream inputStream = resource.getInputStream()) { // 加载Word文档 XWPFDocument baseModelDocument = new XWPFDocument(inputStream); - PqDevVO pqDevVO = iPqDevService.getPqDevById(devReportParam.getDevId()); - if (Objects.isNull(pqDevVO)) { - throw new BusinessException("请检查装置是否存在!"); - } - // 获取设备型号 - DevType devType = devTypeService.getById(pqDevVO.getDevType()); - if (Objects.isNull(devType)) { - throw new BusinessException("设备类型丢失,请联系管理员!"); - } // 处理基础模版中的信息 - dealBaseModel(baseModelDocument, pqDevVO); + dealBaseModel(baseModelDocument, pqDevVO, devType); // 处理数据页中的信息 dealDataModel(baseModelDocument, devReportParam, pqDevVO); // 处理需要输出的目录地址 基础路径+设备类型+装置编号.docx @@ -124,7 +130,7 @@ public class ReportServiceImpl implements IReportService { updateWrapper.set(AdPlan::getReportState, PlanReportStateEnum.REPORT_STATE_PARTIALLY_GENERATED.getValue()); } adPlanService.update(updateWrapper); - } catch (Exception e) { + } catch (IOException e) { log.error("生成报告文件失败", e); throw new RuntimeException(e); } @@ -179,11 +185,10 @@ public class ReportServiceImpl implements IReportService { * * @param baseModelDocument 模板文件 */ - private void dealBaseModel(XWPFDocument baseModelDocument, PqDevVO pqDevVO) { + private void dealBaseModel(XWPFDocument baseModelDocument, PqDevVO pqDevVO, DevType devType) { // 首先获取非数据页中需要的信息 Map baseModelMap = new HashMap<>(16); // 获取设备型号 - DevType devType = devTypeService.getById(pqDevVO.getDevType()); baseModelMap.put("${devType}", devType.getName()); // 调试人员,todo... 待咨询曹泽辉如何获取当前用户信息,目前先写死 baseModelMap.put("${userName}", "管理员"); @@ -195,6 +200,8 @@ public class ReportServiceImpl implements IReportService { } // 装置编码 baseModelMap.put("${CreateId}", pqDevVO.getCreateId()); + // 工作电源 + baseModelMap.put("${power}", devType.getPower()); // 额定电流 baseModelMap.put("${devCurr}", pqDevVO.getDevCurr().toString().concat("A")); // 额定电压 @@ -226,7 +233,7 @@ public class ReportServiceImpl implements IReportService { String scriptId = adPlan.getScriptId(); Integer devChns = pqDevVO.getDevChns(); for (int i = 1; i <= devChns; i++) { - ClassPathResource resource = new ClassPathResource("/model/BaseDataModel.docx"); + ClassPathResource resource = new ClassPathResource("/model/report_table.docx"); XWPFDocument dataModelDocumentTemp = new XWPFDocument(resource.getInputStream()); SingleNonHarmParam singleNonHarmParam = new SingleNonHarmParam(); @@ -399,11 +406,18 @@ public class ReportServiceImpl implements IReportService { private void fillMapValueHarm(SingleNonHarmParam singleNonHarmParam, Map dataModelMap, String aSymbol, String bSymbol, String cSymbol, double baseValue, int percent) { AdHarmonicResult adHarmonicResult = adHarmonicService.getSingleResult(singleNonHarmParam); if (Objects.nonNull(adHarmonicResult)) { + // 要处理 2 5 7 11 23 35 43 50 + // 基波 + dataModelMap.put("${" + aSymbol + "1}", devValue(adHarmonicResult.getAValue1(), baseValue, percent)); + dataModelMap.put("${" + bSymbol + "1}", devValue(adHarmonicResult.getBValue1(), baseValue, percent)); + dataModelMap.put("${" + cSymbol + "1}", devValue(adHarmonicResult.getCValue1(), baseValue, percent)); + dataModelMap.put("${" + aSymbol + "2}", devValue(adHarmonicResult.getAValue2(), baseValue, percent)); dataModelMap.put("${" + bSymbol + "2}", devValue(adHarmonicResult.getBValue2(), baseValue, percent)); dataModelMap.put("${" + cSymbol + "2}", devValue(adHarmonicResult.getCValue2(), baseValue, percent)); + dataModelMap.put("${" + aSymbol + "5}", devValue(adHarmonicResult.getAValue5(), baseValue, percent)); dataModelMap.put("${" + bSymbol + "5}", devValue(adHarmonicResult.getBValue5(), baseValue, percent)); dataModelMap.put("${" + cSymbol + "5}", devValue(adHarmonicResult.getCValue5(), baseValue, percent)); diff --git a/detection/src/main/java/com/njcn/gather/type/service/IDevTypeService.java b/detection/src/main/java/com/njcn/gather/type/service/IDevTypeService.java index 07760bd9..2519f973 100644 --- a/detection/src/main/java/com/njcn/gather/type/service/IDevTypeService.java +++ b/detection/src/main/java/com/njcn/gather/type/service/IDevTypeService.java @@ -2,6 +2,7 @@ package com.njcn.gather.type.service; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; +import com.njcn.gather.system.dictionary.pojo.po.DictData; import com.njcn.gather.type.pojo.param.DevTypeParam; import com.njcn.gather.type.pojo.po.DevType; @@ -79,4 +80,11 @@ public interface IDevTypeService extends IService { * @return 成功返回true,失败返回false */ boolean deleteDevType(List ids); + + /** + * 根据设备蕾西id获取报告名称 + * @param devType 设备类型Id + * @return 报告字典 + */ + DictData getReportName(String devType); } diff --git a/detection/src/main/java/com/njcn/gather/type/service/impl/DevTypeServiceImpl.java b/detection/src/main/java/com/njcn/gather/type/service/impl/DevTypeServiceImpl.java index 31a9f7f2..e4a235e0 100644 --- a/detection/src/main/java/com/njcn/gather/type/service/impl/DevTypeServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/type/service/impl/DevTypeServiceImpl.java @@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.njcn.common.pojo.enums.common.DataStateEnum; import com.njcn.common.pojo.exception.BusinessException; +import com.njcn.gather.system.dictionary.pojo.po.DictData; +import com.njcn.gather.system.dictionary.service.IDictDataService; import com.njcn.gather.type.mapper.DevTypeMapper; import com.njcn.gather.type.pojo.enums.DevTypeResponseEnum; import com.njcn.gather.type.pojo.param.DevTypeParam; @@ -16,7 +18,9 @@ import com.njcn.web.factory.PageFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.annotation.Resource; import java.util.List; +import java.util.Objects; /** *

@@ -29,6 +33,10 @@ import java.util.List; @Service public class DevTypeServiceImpl extends ServiceImpl implements IDevTypeService { + @Resource + private IDictDataService dictDataService; + + @Override public List listAll() { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); @@ -87,6 +95,15 @@ public class DevTypeServiceImpl extends ServiceImpl impl return this.lambdaUpdate().in(DevType::getId, ids).set(DevType::getState, DataStateEnum.DELETED.getCode()).update(); } + @Override + public DictData getReportName(String devTypeId) { + DevType devType = this.lambdaQuery().eq(DevType::getId, devTypeId).eq(DevType::getState, DataStateEnum.ENABLE.getCode()).one(); + if (Objects.nonNull(devType)) { + return dictDataService.getDictDataById(devType.getReportName()); + } + return null; + } + private void checkRepeat(DevTypeParam param, boolean isExcludeSelf) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(DevType::getName, param.getName()) diff --git a/entrance/src/main/resources/model/BaseModel.docx b/entrance/src/main/resources/model/BaseModel.docx deleted file mode 100644 index 815f0447..00000000 Binary files a/entrance/src/main/resources/model/BaseModel.docx and /dev/null differ diff --git a/entrance/src/main/resources/model/njcn_882.docx b/entrance/src/main/resources/model/njcn_882.docx new file mode 100644 index 00000000..7596037a Binary files /dev/null and b/entrance/src/main/resources/model/njcn_882.docx differ diff --git a/entrance/src/main/resources/model/njcn_882A.docx b/entrance/src/main/resources/model/njcn_882A.docx new file mode 100644 index 00000000..6794cdc6 Binary files /dev/null and b/entrance/src/main/resources/model/njcn_882A.docx differ diff --git a/entrance/src/main/resources/model/njcn_882B1.docx b/entrance/src/main/resources/model/njcn_882B1.docx new file mode 100644 index 00000000..f7ff66d3 Binary files /dev/null and b/entrance/src/main/resources/model/njcn_882B1.docx differ diff --git a/entrance/src/main/resources/model/njcn_882B2.docx b/entrance/src/main/resources/model/njcn_882B2.docx new file mode 100644 index 00000000..aca5f527 Binary files /dev/null and b/entrance/src/main/resources/model/njcn_882B2.docx differ diff --git a/entrance/src/main/resources/model/njcn_882B3.docx b/entrance/src/main/resources/model/njcn_882B3.docx new file mode 100644 index 00000000..b020dcfc Binary files /dev/null and b/entrance/src/main/resources/model/njcn_882B3.docx differ diff --git a/entrance/src/main/resources/model/njcn_882B4.docx b/entrance/src/main/resources/model/njcn_882B4.docx new file mode 100644 index 00000000..ec679f67 Binary files /dev/null and b/entrance/src/main/resources/model/njcn_882B4.docx differ diff --git a/entrance/src/main/resources/model/njcn_882B5.docx b/entrance/src/main/resources/model/njcn_882B5.docx new file mode 100644 index 00000000..03c28b55 Binary files /dev/null and b/entrance/src/main/resources/model/njcn_882B5.docx differ diff --git a/entrance/src/main/resources/model/njcn_882B6.docx b/entrance/src/main/resources/model/njcn_882B6.docx new file mode 100644 index 00000000..d6cb8c40 Binary files /dev/null and b/entrance/src/main/resources/model/njcn_882B6.docx differ diff --git a/entrance/src/main/resources/model/BaseDataModel.docx b/entrance/src/main/resources/model/report_table.docx similarity index 100% rename from entrance/src/main/resources/model/BaseDataModel.docx rename to entrance/src/main/resources/model/report_table.docx