楼下报告调整

This commit is contained in:
2025-02-17 11:14:01 +08:00
parent dd96bc4171
commit 422645bcfd
13 changed files with 54 additions and 15 deletions

View File

@@ -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<String, String> 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<String, String> 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));

View File

@@ -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<DevType> {
* @return 成功返回true失败返回false
*/
boolean deleteDevType(List<String> ids);
/**
* 根据设备蕾西id获取报告名称
* @param devType 设备类型Id
* @return 报告字典
*/
DictData getReportName(String devType);
}

View File

@@ -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;
/**
* <p>
@@ -29,6 +33,10 @@ import java.util.List;
@Service
public class DevTypeServiceImpl extends ServiceImpl<DevTypeMapper, DevType> implements IDevTypeService {
@Resource
private IDictDataService dictDataService;
@Override
public List<DevType> listAll() {
LambdaQueryWrapper<DevType> queryWrapper = new LambdaQueryWrapper<>();
@@ -87,6 +95,15 @@ public class DevTypeServiceImpl extends ServiceImpl<DevTypeMapper, DevType> 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<DevType> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(DevType::getName, param.getName())