fix:报告数据报错修复;增加固定字段的数据方式

This commit is contained in:
FCL
2025-11-19 16:10:18 +08:00
parent 0e07b41c22
commit 3c70d53533
7 changed files with 108 additions and 21 deletions

View File

@@ -78,6 +78,7 @@ public class ReportDocumentMainController extends AbstractFileUploadController i
if(typeDO == null){
return error(REPORT_DOCUMENT_TYPE_NOT_EXISTS, "报告类型不存在,请刷新后重试");
}
vo.setDocumentTitle(typeDO.getName());
vo.setFlowKey(typeDO.getFlowKey());
vo.setDocumentType(typeDO.getDocumentType());
vo.setConfigReportTypeId(typeDO.getConfigReportTypeId());
@@ -244,8 +245,8 @@ public class ReportDocumentMainController extends AbstractFileUploadController i
@Operation(summary = "获得检测报告业务分页")
//@PreAuthorize("@ss.hasPermission('qms:report-document-main:query')")
public CommonResult<PageResult<ReportDocumentMainRespVO>> getReportDocumentMainPage(@Valid ReportDocumentMainPageReqVO pageReqVO) {
PageResult<ReportDocumentMainDO> pageResult = reportDocumentMainService.getReportDocumentMainPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, ReportDocumentMainRespVO.class));
PageResult<ReportDocumentMainRespVO> pageResult = reportDocumentMainService.getReportDocumentMainPage(pageReqVO);
return success(pageResult);
}
@GetMapping("/export-excel")
@@ -255,10 +256,9 @@ public class ReportDocumentMainController extends AbstractFileUploadController i
public void exportReportDocumentMainExcel(@Valid ReportDocumentMainPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<ReportDocumentMainDO> list = reportDocumentMainService.getReportDocumentMainPage(pageReqVO).getList();
List<ReportDocumentMainRespVO> list = reportDocumentMainService.getReportDocumentMainPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "检测报告业务.xls", "数据", ReportDocumentMainRespVO.class,
BeanUtils.toBean(list, ReportDocumentMainRespVO.class));
ExcelUtils.write(response, "检测报告业务.xls", "数据", ReportDocumentMainRespVO.class, list);
}
}

View File

@@ -113,4 +113,10 @@ public class ReportDocumentMainRespVO {
@Schema(description = "表单设计器模板id")
@ExcelProperty("表单设计器模板id")
private Long dataTemplateId;
//==============================扩展字段=======================================
@Schema(description = "记录数")
@ExcelProperty("记录数")
private Long detailDataCount;
}

View File

@@ -3,7 +3,9 @@ package com.zt.plat.module.qms.business.reportdoc.dal.mapper;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.framework.mybatis.core.query.MPJLambdaWrapperX;
import com.zt.plat.module.qms.business.reportdoc.controller.vo.*;
import com.zt.plat.module.qms.business.reportdoc.dal.dataobject.ReportDocumentDataDO;
import com.zt.plat.module.qms.business.reportdoc.dal.dataobject.ReportDocumentMainDO;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.util.ObjectUtils;
@@ -21,10 +23,13 @@ import java.util.List;
public interface ReportDocumentMainMapper extends BaseMapperX<ReportDocumentMainDO> {
default PageResult<ReportDocumentMainDO> selectPage(ReportDocumentMainPageReqVO reqVO) {
default PageResult<ReportDocumentMainRespVO> selectPage(ReportDocumentMainPageReqVO reqVO) {
String flowStatus = reqVO.getFlowStatus();
LambdaQueryWrapperX<ReportDocumentMainDO> wrapper = new LambdaQueryWrapperX<>();
MPJLambdaWrapperX<ReportDocumentMainDO> wrapper = new MPJLambdaWrapperX<>();
wrapper.selectSub(ReportDocumentDataDO.class, s->
s.selectCount(ReportDocumentDataDO::getMainId).eq(ReportDocumentDataDO::getMainId, ReportDocumentMainDO::getId), ReportDocumentMainRespVO::getDetailDataCount);
wrapper.selectAll(ReportDocumentMainDO.class);
wrapper.ne(ReportDocumentMainDO::getCancelFlag, -1); //-1为临时数据
wrapper.eqIfPresent(ReportDocumentMainDO::getFlowInstanceId, reqVO.getFlowInstanceId());
wrapper.eqIfPresent(ReportDocumentMainDO::getReportDocumentTypeId, reqVO.getReportDocumentTypeId());
@@ -49,7 +54,7 @@ public interface ReportDocumentMainMapper extends BaseMapperX<ReportDocumentMain
wrapper.betweenIfPresent(ReportDocumentMainDO::getCreateTime, reqVO.getCreateTime());
wrapper.eqIfPresent(ReportDocumentMainDO::getRemark, reqVO.getRemark());
wrapper.orderByDesc(ReportDocumentMainDO::getId);
return selectPage(reqVO, wrapper);
return selectJoinPage(reqVO, ReportDocumentMainRespVO.class, wrapper);
}
}

View File

@@ -22,6 +22,7 @@ public interface ReportDocumentDataService {
CommonResult<List<JSONObject>> assembleDynamicData(ReportDocumentMainDO mainData, ReportDocumentTypeDO reportConfig);
CommonResult<List<ReportDocumentDataDO>> listByMainDataId(Long mainDataId);
CommonResult<Long> countMainDataId(Long mainDataId);
CommonResult<String> removeByMainIdAndDetailIds(Long mainDataId, List<Long> detailIds);

View File

@@ -50,7 +50,7 @@ public class ReportDocumentDataServiceImpl implements ReportDocumentDataService
private final String name_code_code = "code";
private final String name_code_split = "split";
private final String rangeKey = "minLimitValue";
private final String emptyText = "以下为空白";
/*
@@ -113,17 +113,20 @@ public class ReportDocumentDataServiceImpl implements ReportDocumentDataService
Integer dynamicColCount = 3;
Integer fixedColCount = 3;
Integer maxRowCount = 3;
String dynamicColCountStr = jsonObject.getString("dynamicColCount"); //动态列(检测项)数量
String fixedColCountStr = jsonObject.getString("fixedColCount"); //固定列(样品名称、样品编号等)数量
String maxRowCountStr = jsonObject.getString("maxRowCount"); //最大行数
String nameCodeType = jsonObject.getString("nameCodeType"); //名称、编号处理方式merge-合并, name-只显示名称, code-只显示编号, split-2列分开显示
String hasRemark = jsonObject.getString("hasRemark"); //是否有备注
String hasRange = jsonObject.getString("hasRange"); //是否有检出限
String verticalFlag = jsonObject.getString("verticalFlag"); //vertical-纵表, 否则为横表
String dynamicColCountStr = jsonObject.getString("dynamicColCount"); //动态列(检测项)数量
String fixedColCountStr = jsonObject.getString("fixedColCount"); //固定列(样品名称、样品编号等)数量
String maxRowCountStr = jsonObject.getString("maxRowCount"); //最大行数
String nameCodeType = jsonObject.getString("nameCodeType"); //名称、编号处理方式merge-合并, name-只显示名称, code-只显示编号, split-2列分开显示
String hasRemark = jsonObject.getString("hasRemark"); //是否有备注
String hasRange = jsonObject.getString("hasRange"); //是否有检出限
String verticalFlag = jsonObject.getString("verticalFlag"); //vertical-纵表, 否则为横表
String fixedFields = jsonObject.getString("fixedFields"); //固定检测项。如果固定检测项则以检测项作为数据Key
if("1".equals(verticalFlag)){
return assembleVerticalData(fieldList, dataList, customConfig);
}
if(!ObjectUtils.isEmpty(fixedFields)){
return assembleFixedFieldsData(fieldList, dataList, customConfig);
}
if(!ObjectUtils.isEmpty(dynamicColCountStr)) dynamicColCount = Integer.parseInt(dynamicColCountStr);
if(!ObjectUtils.isEmpty(fixedColCountStr)) fixedColCount = Integer.parseInt(fixedColCountStr);
@@ -261,13 +264,15 @@ public class ReportDocumentDataServiceImpl implements ReportDocumentDataService
//==============以下为空白=================
//实际使用行数小于总行数,显示“”以下为空白“
if(dataIndex < maxRowCount){
if(dataLength < maxRowCount){
String colKey = colPrefix + "01";
t = new JSONObject();
t.put(colKey, "以下为空白");
t.put(colKey, emptyText);
int rowIndex = (dataLength + emptyRowCount) * (rowAssist) + 2;
if(rowAssist == 1)
rowIndex = dataLength + emptyRowCount;
if(rowCountOneSample == 1)
rowIndex = dataLength + 2;
rowList.set(rowIndex, t.clone());
}
//前面的计数是从1开始移除第一个元素
@@ -371,6 +376,68 @@ public class ReportDocumentDataServiceImpl implements ReportDocumentDataService
return sb.append(num).toString();
}
/**
* 组装固定检测项的数据以检测项作为数据Key
* */
private List<JSONObject> assembleFixedFieldsData(List<ConfigReportFieldDO> fieldList, List<ReportDocumentDataDO> dataList, String customConfig){
JSONObject jsonObject = JSONObject.parseObject(customConfig);
Integer maxRowCount = 3;
String maxRowCountStr = jsonObject.getString("maxRowCount"); //最大行数
String hasRemark = jsonObject.getString("hasRemark"); //是否有备注
String hasRange = jsonObject.getString("hasRange"); //是否有检出限
String fixedFields = jsonObject.getString("fixedFields"); //固定检测项。如果固定检测项则以检测项作为数据Key
JSONArray fixedFieldsArray = JSONArray.parseArray(fixedFields);
if(!ObjectUtils.isEmpty(maxRowCountStr)) maxRowCount = Integer.parseInt(maxRowCountStr);
List<JSONObject> rowList = new ArrayList<>();
for(ReportDocumentDataDO dataDO : dataList) {
JSONObject t = new JSONObject();
String documentContent = dataDO.getDocumentContent();
String externalContent = dataDO.getExternalContent();
JSONObject s = JSONObject.parseObject(documentContent);
JSONObject e = new JSONObject();
if (!ObjectUtils.isEmpty(externalContent)) {
e = JSONObject.parseObject(externalContent);
}
String remark = e.getString("remark");
String sampleName = dataDO.getSampleName();
String sampleCode = dataDO.getSampleCode();
String sampleNameCode = sampleName + " " + sampleCode;
t.put("sampleNameCode", sampleNameCode);
t.put("sampleName", sampleName);
t.put("sampleCode", sampleCode);
for(ConfigReportFieldDO fieldDO : fieldList){
String fieldName = fieldDO.getFieldName();
String field = fieldDO.getField();
for(int i=0;i<fixedFieldsArray.size();i++){
String fieldKey = fixedFieldsArray.getString(i);
if(!fieldName.equals(fieldKey))
continue;
JSONObject fieldObj = s.getJSONObject( field);
String fieldValue = "";
String mathSymbol = "";
if(fieldObj != null){
fieldValue = fieldObj.getString("fieldValue");
mathSymbol = fieldObj.getString("mathSymbol");
}
if(!ObjectUtils.isEmpty(mathSymbol) && !"=".equals(mathSymbol))
fieldValue = mathSymbol + fieldValue;
t.put(fieldName, fieldValue);
}
}
rowList.add(t);
}
if(rowList.size() < maxRowCount){
JSONObject t = new JSONObject();
t.put("sampleNameCode", emptyText);
t.put("sampleName", emptyText);
t.put("sampleCode", emptyText);
rowList.add( t);
}
return rowList;
}
/**
* 组装纵表数据
* 第1列固定为元素 第2列方法检出限%);第三列开始为各个样品
@@ -463,6 +530,14 @@ public class ReportDocumentDataServiceImpl implements ReportDocumentDataService
return CommonResult.success(list);
}
@Override
public CommonResult<Long> countMainDataId(Long mainDataId) {
QueryWrapper<ReportDocumentDataDO> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("MAIN_ID", mainDataId);
queryWrapper.orderByAsc("ID");
return CommonResult.success(reportDocumentDataMapper.selectCount(queryWrapper));
}
@Override
public CommonResult<String> removeByMainIdAndDetailIds(Long mainDataId, List<Long> detailIds) {
QueryWrapper<ReportDocumentDataDO> queryWrapper = new QueryWrapper<>();

View File

@@ -77,7 +77,7 @@ public interface ReportDocumentMainService {
* @param pageReqVO 分页查询
* @return 检测报告业务分页
*/
PageResult<ReportDocumentMainDO> getReportDocumentMainPage(ReportDocumentMainPageReqVO pageReqVO);
PageResult<ReportDocumentMainRespVO> getReportDocumentMainPage(ReportDocumentMainPageReqVO pageReqVO);
//发起流程
CommonResult<ReportDocumentMainRespVO> createProcessInstance(ReportDocumentMainSaveReqVO entity);

View File

@@ -262,7 +262,7 @@ public class ReportDocumentMainServiceImpl implements ReportDocumentMainService,
}
@Override
public PageResult<ReportDocumentMainDO> getReportDocumentMainPage(ReportDocumentMainPageReqVO pageReqVO) {
public PageResult<ReportDocumentMainRespVO> getReportDocumentMainPage(ReportDocumentMainPageReqVO pageReqVO) {
return reportDocumentMainMapper.selectPage(pageReqVO);
}