diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/reportdoc/service/ReportDocumentDataServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/reportdoc/service/ReportDocumentDataServiceImpl.java index 40b2521..e185723 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/reportdoc/service/ReportDocumentDataServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/business/reportdoc/service/ReportDocumentDataServiceImpl.java @@ -21,8 +21,6 @@ import org.springframework.util.ObjectUtils; import org.springframework.validation.annotation.Validated; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -113,12 +111,14 @@ public class ReportDocumentDataServiceImpl implements ReportDocumentDataService return new ArrayList<>(); JSONObject jsonObject = JSONObject.parseObject(customConfig); Integer dynamicColCount = 3; - Integer fixedColCount = 3; + Integer fixedColCount = 0; Integer maxRowCount = 3; String dynamicColCountStr = jsonObject.getString("dynamicColCount"); //动态列(检测项)数量 - String fixedColCountStr = jsonObject.getString("fixedColCount"); //固定列(样品名称、样品编号等)数量 +// String fixedColCountStr = jsonObject.getString("fixedColCount"); //固定列(样品名称、样品编号等)数量 + JSONArray fixedCol = jsonObject.getJSONArray("fixedCol"); //固定列,举例:["sampleName", "sampleCode"] + JSONArray fixedColShow = jsonObject.getJSONArray("fixedColShow"); //固定列,举例:["产品名称", "编 号"] String maxRowCountStr = jsonObject.getString("maxRowCount"); //最大行数 - String nameCodeType = jsonObject.getString("nameCodeType"); //名称、编号处理方式:merge-合并, name-只显示名称, code-只显示编号, split-2列分开显示 +// 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-纵表, 否则为横表 @@ -130,7 +130,7 @@ public class ReportDocumentDataServiceImpl implements ReportDocumentDataService return assembleFixedFieldsData(fieldList, dataList, customConfig); } if(!ObjectUtils.isEmpty(dynamicColCountStr)) dynamicColCount = Integer.parseInt(dynamicColCountStr); - if(!ObjectUtils.isEmpty(fixedColCountStr)) fixedColCount = Integer.parseInt(fixedColCountStr); + if(fixedCol != null) fixedColCount = fixedCol.size(); if(!ObjectUtils.isEmpty(maxRowCountStr)) maxRowCount = Integer.parseInt(maxRowCountStr); Integer eleCount = 0; //元素数量,即元素列总数 @@ -144,14 +144,14 @@ public class ReportDocumentDataServiceImpl implements ReportDocumentDataService Integer colCountOneSample = fixedColCount + dynamicColCount; //每个样品要占的列数 Integer dataLength = dataList.size(); Integer emptyRowCount = dataLength < maxRowCount ? 1 : 0; //空行数 - Integer allRowCount = 1 + dataLength + emptyRowCount + 1; //标题 + 样品数 + 空行 +// Integer allRowCount = 1 + dataLength + emptyRowCount + 1; //标题 + 样品数 + 空行 if("1".equals(hasRange)) emptyRowCount ++; - if(rowCountOneSample > 1){ - allRowCount = (1 + dataLength + emptyRowCount + 9) * rowCountOneSample + emptyRowCount; //(标题 + 样品数 + 空行) * 但样品行数 + 末尾行 - } +// if(rowCountOneSample > 1){ +// allRowCount = (1 + dataLength + emptyRowCount + 9) * rowCountOneSample + emptyRowCount; //(标题 + 样品数 + 空行) * 但样品行数 + 末尾行 +// } List rowList = new ArrayList<>(); for(int i = 0; i < maxRowCount; i++){ JSONObject row = new JSONObject(); @@ -193,7 +193,7 @@ public class ReportDocumentDataServiceImpl implements ReportDocumentDataService r.put(colPrefix + "01", "方法检出限"); lastObjFlag = true; if(colIndex % colCountOneSample == 0){ - addTitleToRowList(nameCodeType, rowAssist, t, dataLength, emptyRowCount, rowList, fieldList); + addTitleToRowList(rowAssist, t, dataLength, emptyRowCount, rowList, fieldList); if("1".equals(hasRange)) addRangeToRowList(rowAssist, r, dataLength, emptyRowCount, rowList); t = new JSONObject(); @@ -211,7 +211,7 @@ public class ReportDocumentDataServiceImpl implements ReportDocumentDataService colIndex++; } if(lastObjFlag){ - addTitleToRowList(nameCodeType, rowAssist, t, dataLength, emptyRowCount, rowList, fieldList); + addTitleToRowList(rowAssist, t, dataLength, emptyRowCount, rowList, fieldList); if("1".equals(hasRange)) addRangeToRowList(rowAssist, r, dataLength, emptyRowCount, rowList); } @@ -252,7 +252,7 @@ public class ReportDocumentDataServiceImpl implements ReportDocumentDataService t.put(colPrefix + colKey, fieldValue); lastObjFlag = true; if(colIndex % colCountOneSample == 0){ - addDataToRowList(nameCodeType, dataDO, rowAssist, t, dataLength, emptyRowCount, dataIndex, rowList, fieldList); + addFixedDataToRowList(fixedCol, dataDO, rowAssist, t, dataLength, emptyRowCount, dataIndex, rowList, fieldList); t = new JSONObject(); if("1".equals(hasRemark)){ t.put(colPrefix + parseNumToString(colCountOneSample + 1, 2), remark); @@ -265,7 +265,7 @@ public class ReportDocumentDataServiceImpl implements ReportDocumentDataService colIndex++; } if(lastObjFlag){ - addDataToRowList(nameCodeType, dataDO, rowAssist, t, dataLength, emptyRowCount, dataIndex, rowList, fieldList); + addFixedDataToRowList(fixedCol, dataDO, rowAssist, t, dataLength, emptyRowCount, dataIndex, rowList, fieldList); } dataIndex ++; } @@ -290,30 +290,15 @@ public class ReportDocumentDataServiceImpl implements ReportDocumentDataService } /** - * @param nameCodeType: merge-合并, name-只显示名称, code-只显示编号, split-2列分开显示 + * @param * * */ - private void addTitleToRowList(String nameCodeType, Integer rowAssist, JSONObject t, Integer dataLength, Integer emptyRowCount, + private void addTitleToRowList(Integer rowAssist, JSONObject t, Integer dataLength, Integer emptyRowCount, List rowList, List fieldList){ int rowIndex = (1 + dataLength + emptyRowCount) * (rowAssist - 1) + 1; //(标题 + 数据行 + 空行) //处理固定列 int index = 1; - String colKey = parseNumToString(index, 2); - if(name_code_merge.equals(nameCodeType)){ - t.put(colPrefix + colKey, "样品名称及编号"); - rowList.set(rowIndex, t.clone()); - return; - } - if(name_code_name.equals(nameCodeType)){ - t.put(colPrefix + colKey, "样品名称"); - rowList.set(rowIndex, t.clone()); - return; - } - if(name_code_code.equals(nameCodeType)){ - t.put(colPrefix + colKey, "样品编号"); - rowList.set(rowIndex, t.clone()); - return; - } + String colKey = ""; for(ConfigReportFieldDO fieldDO : fieldList){ String fieldName = fieldDO.getFieldName(); String fieldType = fieldDO.getFieldType(); @@ -336,44 +321,63 @@ public class ReportDocumentDataServiceImpl implements ReportDocumentDataService } - private void addDataToRowList(String nameCodeType, ReportDocumentDataDO dataDO, Integer rowAssist, JSONObject t, Integer dataLength, Integer emptyRowCount, Integer dataIndex, List rowList, List fieldList){ + /** + * 添加固定列的数据 + * */ + private void addFixedDataToRowList(JSONArray fixedCol, ReportDocumentDataDO dataDO, Integer rowAssist, JSONObject t, Integer dataLength, Integer emptyRowCount, Integer dataIndex, List rowList, List fieldList){ int rowIndex = (1 + dataLength + emptyRowCount) * (rowAssist - 1) + dataIndex + 1; //(标题 + 数据行 + 空行) t.put("id", dataDO.getId()); //处理固定列 int index = 1; //处理固定列 - String colKey = parseNumToString(index, 2); - if(name_code_merge.equals(nameCodeType)){ - String merge = dataDO.getSampleName() + " " + dataDO.getSampleCode(); - t.put(colPrefix + colKey, merge); - rowList.set(rowIndex, t.clone()); - return; - } - if(name_code_name.equals(nameCodeType)){ - t.put(colPrefix + colKey, dataDO.getSampleName()); - rowList.set(rowIndex, t.clone()); - return; - } - if(name_code_code.equals(nameCodeType)){ - t.put(colPrefix + colKey, dataDO.getSampleCode()); - rowList.set(rowIndex, t.clone()); - return; - } - for(ConfigReportFieldDO fieldDO : fieldList){ - String fieldName = fieldDO.getFieldName(); - String fieldType = fieldDO.getFieldType(); - String field = fieldDO.getField(); - if(FIELD_FIXED.equals(fieldType)){ + String colKey = ""; + if(fixedCol != null && !fixedCol.isEmpty()){ + for(int i=0;i