|
|
@@ -1,16 +1,21 @@
|
|
|
package nckd.jxccl.sit.hcsi.business.importtaskguide;
|
|
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
|
import kd.bos.dataentity.resource.ResManager;
|
|
|
+import kd.bos.exception.ErrorCode;
|
|
|
+import kd.bos.exception.KDException;
|
|
|
import kd.bos.form.FormShowParameter;
|
|
|
import kd.bos.form.IFormView;
|
|
|
import kd.bos.logging.Log;
|
|
|
import kd.bos.logging.LogFactory;
|
|
|
import kd.bos.orm.query.QFilter;
|
|
|
+import kd.bos.orm.util.CollectionUtils;
|
|
|
import kd.swc.hsas.business.cal.export.SWCExportDataHelper;
|
|
|
import kd.swc.hsas.business.cal.service.CalResultCoverImportService;
|
|
|
import kd.swc.hsbp.common.enums.DataTypeEnum;
|
|
|
import kd.swc.hsbp.common.enums.SWCShowType;
|
|
|
+import kd.swc.hsbp.common.enums.WriteTaskTypeEnum;
|
|
|
import kd.swc.hsbp.common.util.SWCDateTimeUtils;
|
|
|
import kd.swc.hsbp.common.util.SWCStringUtils;
|
|
|
import nckd.jxccl.sit.hcsi.business.importtaskguide.utils.ImportTaskUtils;
|
|
|
@@ -26,6 +31,7 @@ import org.apache.poi.xssf.usermodel.XSSFRichTextString;
|
|
|
|
|
|
import java.text.MessageFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.IntStream;
|
|
|
|
|
|
/**
|
|
|
* Tyx 2025-10-21
|
|
|
@@ -36,9 +42,15 @@ public class ImportTaskGuideExportService {
|
|
|
private static final Log logger = LogFactory.getLog(ImportTaskGuideExportService.class);
|
|
|
private static final int PAGE_SIZE = 500;
|
|
|
private static final String TPLERROR = "1";
|
|
|
+ private static final String IMPORT_ERROR_TEMPLATE = "外部数据导入任务_数据导入失败结果_{0}";
|
|
|
+ private static final String DATA_IMPORT_SHEET = "数据导入模板";
|
|
|
+ private static final String ERROR_CODE = "getImportErrorExcelFile_error";
|
|
|
+ private static final int COLUMN_WIDTH_MULTIPLIER = 3;
|
|
|
+ private static final int FIRST_COLUMN_WIDTH_MULTIPLIER = 4;
|
|
|
|
|
|
/**
|
|
|
* 导入模板方法
|
|
|
+ *
|
|
|
* @param view
|
|
|
*/
|
|
|
public void exportExcelTemplate(IFormView view) {
|
|
|
@@ -84,12 +96,13 @@ public class ImportTaskGuideExportService {
|
|
|
|
|
|
/**
|
|
|
* 创建Excel
|
|
|
+ *
|
|
|
* @param sinsurTplId
|
|
|
* @param wb
|
|
|
* @param importTaskId
|
|
|
*/
|
|
|
private void createImportTaskDataSheet(Long sinsurTplId, SXSSFWorkbook wb, Long importTaskId) {
|
|
|
- DynamicObject sinsurData = ImportTaskUtils.getSinsurTplData(sinsurTplId, "id,number,nckd_startline", (QFilter)null);
|
|
|
+ DynamicObject sinsurData = ImportTaskUtils.getSinsurTplData(sinsurTplId, "id,number,nckd_startline", (QFilter) null);
|
|
|
int startLine = sinsurData.getInt("nckd_startline");
|
|
|
String sheetName = ResManager.loadKDString("数据导入模板", "ImportTaskGuideExportService_2", "swc-hsas-business", new Object[0]);
|
|
|
SXSSFSheet sheet = wb.createSheet(sheetName);
|
|
|
@@ -101,7 +114,7 @@ public class ImportTaskGuideExportService {
|
|
|
CellStyle headRequriedNumStyle = CalResultCoverImportService.getColumnStyle(true, 0, 0, SWCShowType.NUM.getCode(), HorizontalAlignment.LEFT, sheet.getWorkbook(), HSSFColor.HSSFColorPredefined.GREY_25_PERCENT.getIndex(), true);
|
|
|
Font font = sheet.getWorkbook().createFont();
|
|
|
CellStyle requrriedStyle = CalResultCoverImportService.getColumnStyle(true, 0, 0, SWCShowType.TEXT.getCode(), HorizontalAlignment.LEFT, sheet.getWorkbook(), HSSFColor.HSSFColorPredefined.GREY_25_PERCENT.getIndex(), true);
|
|
|
- font.setColor((short)10);
|
|
|
+ font.setColor((short) 10);
|
|
|
requrriedStyle.setFont(font);
|
|
|
headRequriedNumStyle.setFont(font);
|
|
|
Map<Long, SinsurPresetItemEnum> itemEnumMap = SinsurPresetItemEnum.getSinsurPresetItemEnumMap();
|
|
|
@@ -111,18 +124,18 @@ public class ImportTaskGuideExportService {
|
|
|
SinsurPresetItemEnum presetItemEnum = null;
|
|
|
for (int i = 0; i < columnHeadList.size(); ++i) {
|
|
|
Map<String, String> columnHead = columnHeadList.get(i);
|
|
|
- String columnIndexStr = (String)columnHead.get("columnIndex");
|
|
|
- String dataTypeIdStr = (String)columnHead.get("datatypeid");
|
|
|
- String name = (String)columnHead.get("name");
|
|
|
- String itemType = (String)columnHead.get("itemType");
|
|
|
- String comment = (String)columnHead.get("comment");
|
|
|
+ String columnIndexStr = (String) columnHead.get("columnIndex");
|
|
|
+ String dataTypeIdStr = (String) columnHead.get("datatypeid");
|
|
|
+ String name = (String) columnHead.get("name");
|
|
|
+ String itemType = (String) columnHead.get("itemType");
|
|
|
+ String comment = (String) columnHead.get("comment");
|
|
|
int columnIndex = Integer.parseInt(columnIndexStr);
|
|
|
if (allIndexSet.add(columnIndex) && !textIndexList.contains(columnIndex)) {
|
|
|
if (Long.parseLong(dataTypeIdStr) == DataTypeEnum.STRING.getDbId()) {
|
|
|
textIndexList.add(columnIndex);
|
|
|
}
|
|
|
if ("0".equals(itemType)) {
|
|
|
- presetItemEnum = (SinsurPresetItemEnum)itemEnumMap.get(Long.valueOf((String)columnHead.get("id")));
|
|
|
+ presetItemEnum = (SinsurPresetItemEnum) itemEnumMap.get(Long.valueOf((String) columnHead.get("id")));
|
|
|
CellStyle style = this.getFixCellStyle(presetItemEnum, requrriedStyle, headDateStyle, headTextStyle, headRequriedNumStyle);
|
|
|
this.createCell(comment, headRow, columnIndex, presetItemEnum.getImportColumnName(), presetItemEnum.isRequire(), style, this.getDataType(presetItemEnum), drawingPatriarch);
|
|
|
} else {
|
|
|
@@ -132,8 +145,8 @@ public class ImportTaskGuideExportService {
|
|
|
}
|
|
|
|
|
|
Iterator<Integer> it = allIndexSet.iterator();
|
|
|
- while(it.hasNext()) {
|
|
|
- int index = (Integer)it.next();
|
|
|
+ while (it.hasNext()) {
|
|
|
+ int index = (Integer) it.next();
|
|
|
int columnIndex = sheet.getColumnWidth(index);
|
|
|
sheet.setColumnWidth(index, columnIndex * 3);
|
|
|
}
|
|
|
@@ -172,15 +185,15 @@ public class ImportTaskGuideExportService {
|
|
|
|
|
|
private void batchSetDefaulColumnStyle(SXSSFSheet sheet, List<Integer> indexList, CellStyle cellStyle) {
|
|
|
Iterator var4 = indexList.iterator();
|
|
|
- while(var4.hasNext()) {
|
|
|
- int index = (Integer)var4.next();
|
|
|
+ while (var4.hasNext()) {
|
|
|
+ int index = (Integer) var4.next();
|
|
|
sheet.setDefaultColumnStyle(index, cellStyle);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private CellStyle getTextCellStyle(SXSSFSheet sheet) {
|
|
|
CellStyle textCellStyle = sheet.getWorkbook().createCellStyle();
|
|
|
- textCellStyle.setDataFormat((short)49);
|
|
|
+ textCellStyle.setDataFormat((short) 49);
|
|
|
return textCellStyle;
|
|
|
}
|
|
|
|
|
|
@@ -199,4 +212,167 @@ public class ImportTaskGuideExportService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-}
|
|
|
+ public String getImportErrorExcelFile(List<Map<Integer, String>> dataHeadList, List<Map<Integer, String>> dataRowList, List<Map<String, String>> errDataList,
|
|
|
+ int headIndex, String writeTaskType, Map<Integer, List<Map<String, String>>> columnIndexMap, boolean hasWorkStartDate) {
|
|
|
+ logger.info("getImportErrorExcelFile begin");
|
|
|
+ String url = "";
|
|
|
+ int rowNum = headIndex + dataRowList.size() + 2;
|
|
|
+
|
|
|
+ try {
|
|
|
+ SXSSFWorkbook wb = new SXSSFWorkbook(rowNum);
|
|
|
+
|
|
|
+ try {
|
|
|
+ String dd = SWCDateTimeUtils.format(new Date(), "yyyyMMdd");
|
|
|
+ String exportFileName = MessageFormat.format(ResManager.loadKDString("历史数据迁移任务_数据导入失败结果_{0}", "ImportTaskGuideExportService_3", "swc-hsas-business", new Object[0]), dd);
|
|
|
+ String sheetName = ResManager.loadKDString("数据导入模板", "ImportTaskGuideExportService_2", "swc-hsas-business", new Object[0]);
|
|
|
+ SXSSFSheet sheet = wb.createSheet(sheetName);
|
|
|
+ sheet.setRandomAccessWindowSize(-1);
|
|
|
+ SXSSFDrawing drawingPatriarch = sheet.createDrawingPatriarch();
|
|
|
+ this.createHeadRow(dataHeadList, headIndex, sheet, drawingPatriarch, writeTaskType);
|
|
|
+ this.batchSetDefaulColumnStyle(sheet, this.getTextColumnIndexList(columnIndexMap), this.getTextCellStyle(sheet));
|
|
|
+ Set<Integer> allIndexSet = new HashSet(columnIndexMap.size() + 12);
|
|
|
+ Iterator var18 = columnIndexMap.keySet().iterator();
|
|
|
+
|
|
|
+ while (true) {
|
|
|
+ int index;
|
|
|
+ if (!var18.hasNext()) {
|
|
|
+ allIndexSet.addAll(Lists.newArrayList(new Integer[]{1, 2, 3, 4}));
|
|
|
+ sheet.setColumnWidth(0, sheet.getColumnWidth(0) * 4);
|
|
|
+ var18 = allIndexSet.iterator();
|
|
|
+
|
|
|
+ while (var18.hasNext()) {
|
|
|
+ index = (Integer) var18.next();
|
|
|
+ int columnWidth = sheet.getColumnWidth(index);
|
|
|
+ sheet.setColumnWidth(index, columnWidth * 3);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.addDataRow(dataRowList, errDataList, headIndex, wb, sheet);
|
|
|
+ url = SWCExportDataHelper.storeFile(wb, exportFileName);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ index = (Integer) var18.next();
|
|
|
+ allIndexSet.add(index + 1);
|
|
|
+ }
|
|
|
+ } catch (Throwable e) {
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("getImportErrorExcelFile error : ", e);
|
|
|
+ throw new KDException(e, new ErrorCode("getImportErrorExcelFile_error", e.getMessage()), new Object[0]);
|
|
|
+ }
|
|
|
+
|
|
|
+ logger.info("getImportErrorExcelFile end");
|
|
|
+ return url;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createHeadRow(List<Map<Integer, String>> dataHeadList, int headIndex, SXSSFSheet sheet, SXSSFDrawing drawingPatriarch, String writeTaskType) {
|
|
|
+ SXSSFRow headRow = sheet.createRow(headIndex);
|
|
|
+ CellStyle headTextStyle = CalResultCoverImportService.getColumnStyle(true, 0, 0, SWCShowType.TEXT.getCode(), HorizontalAlignment.LEFT, sheet.getWorkbook(), HSSFColor.HSSFColorPredefined.GREY_25_PERCENT.getIndex(), true);
|
|
|
+ SXSSFCell errMsgCell = headRow.createCell(0);
|
|
|
+ errMsgCell.setCellValue(ResManager.loadKDString("失败原因", "CalResultCoverImportService_58", "swc-hsas-business", new Object[0]));
|
|
|
+ errMsgCell.setCellStyle(headTextStyle);
|
|
|
+ Font font = sheet.getWorkbook().createFont();
|
|
|
+ CellStyle requrriedStyle = CalResultCoverImportService.getColumnStyle(true, 0, 0, SWCShowType.TEXT.getCode(), HorizontalAlignment.LEFT, sheet.getWorkbook(), HSSFColor.HSSFColorPredefined.GREY_25_PERCENT.getIndex(), true);
|
|
|
+ font.setColor((short)10);
|
|
|
+ requrriedStyle.setFont(font);
|
|
|
+ Set<Integer> requireFixColumnSet = ImportTaskUtils.getExportTplRequireColumnSet();
|
|
|
+ Map<Integer, String> headMap = (Map)dataHeadList.get(0);
|
|
|
+ CellStyle style = null;
|
|
|
+
|
|
|
+ Map.Entry entry;
|
|
|
+ for(Iterator var15 = headMap.entrySet().iterator(); var15.hasNext(); this.createCell("", headRow, (Integer)entry.getKey() + 1, (String)entry.getValue(), false, style, (String)null, drawingPatriarch)) {
|
|
|
+ entry = (Map.Entry)var15.next();
|
|
|
+ if (requireFixColumnSet.contains(entry.getKey())) {
|
|
|
+ style = requrriedStyle;
|
|
|
+ } else {
|
|
|
+ style = headTextStyle;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Integer> getTextColumnIndexList(Map<Integer, List<Map<String, String>>> columnIndexMap) {
|
|
|
+ List<Integer> textIndexList = new ArrayList(columnIndexMap.size() + 12);
|
|
|
+ textIndexList.addAll(Lists.newArrayList(new Integer[]{1, 2, 3, 4}));
|
|
|
+ Iterator var5 = columnIndexMap.entrySet().iterator();
|
|
|
+ while(var5.hasNext()) {
|
|
|
+ Map.Entry<Integer, List<Map<String, String>>> entry = (Map.Entry)var5.next();
|
|
|
+ List<Map<String, String>> paramMapList = (List)entry.getValue();
|
|
|
+ if (!CollectionUtils.isEmpty(paramMapList)) {
|
|
|
+ String dataTypeIdStr = (String)((Map)paramMapList.get(0)).get("datatypeid");
|
|
|
+ if (!SWCStringUtils.isEmpty(dataTypeIdStr) && Long.parseLong(dataTypeIdStr) == DataTypeEnum.STRING.getDbId()) {
|
|
|
+ textIndexList.add((Integer)entry.getKey() + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return textIndexList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addDataRow(List<Map<Integer, String>> dataRowList, List<Map<String, String>> errDataList, int headIndex, SXSSFWorkbook wb, SXSSFSheet sheet) {
|
|
|
+ Map<Integer, List<String>> errorMap = this.getErrorMap(errDataList);
|
|
|
+ boolean isTplError = "1".equals(((Map)errDataList.get(0)).get("isAll"));
|
|
|
+ int tplIndex = headIndex++;
|
|
|
+ CellStyle errColumnStyle = CalResultCoverImportService.getColumnStyle(true, 0, 0, "text", HorizontalAlignment.LEFT, wb, (short)9, true);
|
|
|
+ Font font = wb.createFont();
|
|
|
+ font.setColor((short)10);
|
|
|
+ errColumnStyle.setFont(font);
|
|
|
+ CellStyle columnStyle = CalResultCoverImportService.getColumnStyle(true, 0, 0, "text", HorizontalAlignment.LEFT, wb, (short)9, true);
|
|
|
+ List<String> errorList = null;
|
|
|
+ Map<Integer, String> rowMap = null;
|
|
|
+ SXSSFRow dataRow = null;
|
|
|
+ SXSSFCell cell = null;
|
|
|
+ int index = 0;
|
|
|
+
|
|
|
+ for(int length = dataRowList.size(); index < length; ++index) {
|
|
|
+ errorList = (List)errorMap.get(index);
|
|
|
+ if (isTplError) {
|
|
|
+ errorList = (List)errorMap.get(tplIndex);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (errorList != null) {
|
|
|
+ rowMap = (Map)dataRowList.get(index);
|
|
|
+ dataRow = sheet.createRow(headIndex);
|
|
|
+ ++headIndex;
|
|
|
+ cell = dataRow.createCell(0);
|
|
|
+ cell.setCellStyle(errColumnStyle);
|
|
|
+ cell.setCellValue(this.getErrorMsg(errorList));
|
|
|
+ Iterator var18 = rowMap.entrySet().iterator();
|
|
|
+
|
|
|
+ while(var18.hasNext()) {
|
|
|
+ Map.Entry<Integer, String> entry = (Map.Entry)var18.next();
|
|
|
+ cell = dataRow.createCell((Integer)entry.getKey() + 1);
|
|
|
+ cell.setCellStyle(columnStyle);
|
|
|
+ cell.setCellValue((String)entry.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<Integer, List<String>> getErrorMap(List<Map<String, String>> errDataList) {
|
|
|
+ Map<Integer, List<String>> errorMap = new HashMap(16);
|
|
|
+ List<String> tempList = null;
|
|
|
+ Iterator var4 = errDataList.iterator();
|
|
|
+
|
|
|
+ while(var4.hasNext()) {
|
|
|
+ Map<String, String> tempMap = (Map)var4.next();
|
|
|
+ tempList = (List)errorMap.getOrDefault(Integer.valueOf((String)tempMap.get("dataIndex")), new ArrayList());
|
|
|
+ tempList.add(tempMap.get("errMsg"));
|
|
|
+ errorMap.put(Integer.valueOf((String)tempMap.get("dataIndex")), tempList);
|
|
|
+ }
|
|
|
+
|
|
|
+ return errorMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getErrorMsg(List<String> errorList) {
|
|
|
+ StringBuilder key = new StringBuilder();
|
|
|
+ int index = 1;
|
|
|
+
|
|
|
+ for(Iterator var4 = errorList.iterator(); var4.hasNext(); ++index) {
|
|
|
+ String msg = (String)var4.next();
|
|
|
+ key.append(index).append('.').append(' ').append(msg).append(' ');
|
|
|
+ }
|
|
|
+
|
|
|
+ return key.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|