Эх сурвалжийг харах

feat(outdata): 优化导入任务处理逻辑并增强数据解析功能

- 修改 OutImportTaskGuideImportService 中 getItemEntryList 方法签名,增加 commonColumnIndexMap 参数以支持固定列处理
- 重构 getColumnIndexMap 和 getCommonColumnIndexMap 方法,使用 computeIfAbsent 简化代码逻辑并提高可读性
- 在 OutImportTaskUtils 中增强 addFixValue 方法,添加空值检查避免空指针异常
- 更新 OutImpTemplateHelper 添加 getAllBaseItemMap 方法用于获取所有基础项目映射
- 调整 OutTempDataViewBillListPlugin 中 itemType 判断逻辑,从 "0" 改为 "999" 作为固定列标识
- 重写 addItemProp 方法,优化遍历逻辑并明确区分不同类型属性的创建过程
- 改进 getData 方法中的数据填充逻辑,提升代码健壮性和性能
- 在 SinsurCoordSplitService 中增加 sinsurstd_r31 字段清空处理,并调整保存方式避免校验拦截
Tyx 5 цаг өмнө
parent
commit
b2ad758576

+ 7 - 5
code/swc/nckd-jxccl-swc/src/main/java/nckd/jxccl/sit/hcsi/business/coordination/SinsurCoordSplitService.java

@@ -69,6 +69,7 @@ public class SinsurCoordSplitService {
             // 复制后处理相关字段
             newBill.set("dealresult", "0");
             newBill.set("nckd_issplit", true);
+            newBill.set("sinsurstd_r31", null);
             newBill.set("nckd_sourcebillid", bill.getLong("id"));
             // 处理分录数据
             DynamicObjectCollection entryCols = newBill.getDynamicObjectCollection("nckd_entryentity");
@@ -82,11 +83,12 @@ public class SinsurCoordSplitService {
             newBillCol.add(newBill);
         }
         if(newBillCol.size() > 0) {
-            OperationResult result = SaveServiceHelper.saveOperate(SitConstant.COORDVERIFYBILL_HELPER.getEntityName(), newBillCol.stream().toArray(DynamicObject[]::new), OperateOption.create());
-            if(!result.isSuccess()) {
-                throw new KDBizException(result.getMessage());
-            }
-            //SitConstant.COORDVERIFYBILL_HELPER.save(newBillCol);
+            // 直接保存 不走校验 需要把参保标准清除掉 但是参保标准是必填字段
+            SitConstant.COORDVERIFYBILL_HELPER.save(newBillCol);
+//            OperationResult result = SaveServiceHelper.saveOperate(SitConstant.COORDVERIFYBILL_HELPER.getEntityName(), newBillCol.stream().toArray(DynamicObject[]::new), OperateOption.create());
+//            if(!result.isSuccess()) {
+//                throw new KDBizException(result.getMessage());
+//            }
         }
         // 判断下当前单据是否有需要生效的数据
         Long welfArePayerId = bill.getLong("welfarepayer_r31.id");

+ 14 - 25
code/swc/nckd-jxccl-swc/src/main/java/nckd/jxccl/swc/hsas/business/outdata/OutImportTaskGuideImportService.java

@@ -213,7 +213,7 @@ public class OutImportTaskGuideImportService {
                 temporary.set("modifier", RequestContext.get().getCurrUserId());
                 temporary.set("modifytime", new Date());
                 temporary.set("billstatus", "A");
-                temporary.set("entryentity", OutImportTaskUtils.getItemEntryList(rowMap, columnIndexMap, entryType));
+                temporary.set("entryentity", OutImportTaskUtils.getItemEntryList(rowMap, columnIndexMap, commonColumnIndexMap, entryType));
                 result.add(temporary);
             }
             HRBaseServiceHelper helper = new HRBaseServiceHelper("nckd_outtempdata");
@@ -306,22 +306,16 @@ public class OutImportTaskGuideImportService {
 
     private Map<Integer, List<Map<String, String>>> getColumnIndexMap() {
         List<Map<String, String>> columnHeadList = OutImportTaskUtils.getColumnHeadList(this.tplId, this.importTaskId);
-        Map<Integer, List<Map<String, String>>> columnIndexMap = new HashMap(columnHeadList.size());
-        List<Map<String, String>> tempMapList = null;
-        Iterator var4 = columnHeadList.iterator();
+        Map<Integer, List<Map<String, String>>> columnIndexMap = new HashMap<>(columnHeadList.size());
 
-        while(var4.hasNext()) {
-            Map<String, String> obj = (Map)var4.next();
+        for (Map<String, String> obj : columnHeadList) {
+            // 只处理非固定列(itemType != "0")
             if (!"0".equals(obj.get("itemType"))) {
-                tempMapList = (List) columnIndexMap.get(Integer.valueOf((String) obj.get("columnIndex")));
-                if (tempMapList == null) {
-                    tempMapList = new ArrayList(10);
-                    columnIndexMap.put(Integer.valueOf((String) obj.get("columnIndex")), tempMapList);
-                }
-                ((List) tempMapList).add(obj);
+                // 使用 computeIfAbsent 简化逻辑
+                columnIndexMap.computeIfAbsent(Integer.valueOf(obj.get("columnIndex")),
+                        k -> new ArrayList<>()).add(obj);
             }
         }
-
         return columnIndexMap;
     }
 
@@ -331,22 +325,16 @@ public class OutImportTaskGuideImportService {
      */
     private Map<Integer, List<Map<String, String>>> getCommonColumnIndexMap() {
         List<Map<String, String>> columnHeadList = OutImportTaskUtils.getColumnHeadList(this.tplId, this.importTaskId);
-        Map<Integer, List<Map<String, String>>> columnIndexMap = new HashMap(columnHeadList.size());
-        List<Map<String, String>> tempMapList = null;
-        Iterator var4 = columnHeadList.iterator();
+        Map<Integer, List<Map<String, String>>> columnIndexMap = new HashMap<>(columnHeadList.size());
 
-        while(var4.hasNext()) {
-            Map<String, String> obj = (Map)var4.next();
+        for (Map<String, String> obj : columnHeadList) {
+            // 只处理固定列(itemType == "0")
             if ("0".equals(obj.get("itemType"))) {
-                tempMapList = (List) columnIndexMap.get(Integer.valueOf((String) obj.get("columnIndex")));
-                if (tempMapList == null) {
-                    tempMapList = new ArrayList(10);
-                    columnIndexMap.put(Integer.valueOf((String) obj.get("columnIndex")), tempMapList);
-                }
-                ((List) tempMapList).add(obj);
+                // 使用 computeIfAbsent 简化逻辑
+                columnIndexMap.computeIfAbsent(Integer.valueOf(obj.get("columnIndex")),
+                        k -> new ArrayList<>()).add(obj);
             }
         }
-
         return columnIndexMap;
     }
 
@@ -366,6 +354,7 @@ public class OutImportTaskGuideImportService {
         Iterator var7 = tplFixItemMap.entrySet().iterator();
         while(var7.hasNext()) {
             Map.Entry<Integer, OutImpPresetItem> entry = (Map.Entry)var7.next();
+            if(entry.getValue() == null)  continue;
             excelName = (String)dataHeadMap.get(entry.getKey());
             if (StringUtils.isEmpty(excelName)) {
                 errDataList.add(((OutImpPresetItem)entry.getValue()).getItemName());

+ 40 - 5
code/swc/nckd-jxccl-swc/src/main/java/nckd/jxccl/swc/hsas/business/utils/OutImportTaskUtils.java

@@ -119,18 +119,21 @@ public class OutImportTaskUtils {
      */
     private static void addFixValue(Map<String, String> commentMap, Set<Long> itemSet, String itemKey, Map<String, Map<String, String>> itemMap, String itemType) {
         if (itemSet.size() != 0) {
+            //Map<Long, DynamicObject> map = OutImpTemplateHelper.getAllBaseItemMap();
             Map<Long, OutImpPresetItem> map = OutImpTemplateHelper.getPresetItemEnumMap();
             OutImpPresetItem itemEnum = null;
             Map<String, String> tempMap = null;
             Iterator it = itemSet.iterator();
-            while(it.hasNext()) {
-                Long itemId = (Long)it.next();
-                itemEnum = (OutImpPresetItem)map.get(itemId);
+            while (it.hasNext()) {
+                Long itemId = (Long) it.next();
+                itemEnum = map.get(itemId);
+                if(itemEnum == null)
+                    continue;
                 tempMap = new HashMap(16);
                 tempMap.put("name", itemEnum.getItemName());
                 tempMap.put("datatypeid", String.valueOf(itemEnum.getDataTypeId()));
                 tempMap.put("id", String.valueOf(itemId));
-                tempMap.put("key", getFixColumnKeyByItemId(itemId.toString()));
+                tempMap.put("key", itemKey + itemEnum.getItemId());
                 tempMap.put("itemType", itemType);
                 tempMap.put("comment", commentMap.get(itemKey + itemId));
                 itemMap.put(itemKey + itemId, tempMap);
@@ -211,7 +214,7 @@ public class OutImportTaskUtils {
 
     }
 
-    public static DynamicObjectCollection getItemEntryList(Map<Integer, Object> rowMap, Map<Integer, List<Map<String, String>>> columnIndexMap, EntityType entryType) {
+    public static DynamicObjectCollection getItemEntryList(Map<Integer, Object> rowMap, Map<Integer, List<Map<String, String>>> columnIndexMap, Map<Integer, List<Map<String, String>>> commonColumnIndexMap, EntityType entryType) {
         DynamicObjectCollection itemEntryList = new DynamicObjectCollection();
         int sequence = 0;
         for (Map.Entry<Integer, List<Map<String, String>>> entry : columnIndexMap.entrySet()) {
@@ -245,6 +248,38 @@ public class OutImportTaskUtils {
                 }
             }
         }
+        for (Map.Entry<Integer, List<Map<String, String>>> entry : commonColumnIndexMap.entrySet()) {
+            Object itemValue = rowMap.get(entry.getKey());
+            if (itemValue == null) {
+                continue;
+            }
+            for (Map<String, String> itemMap : entry.getValue()) {
+                try {
+                    DynamicObject item = (DynamicObject) entryType.createInstance();
+
+                    item.set("nckd_itemvalue", itemValue);
+                    item.set("nckd_itemtype", itemMap.get("itemType"));
+                    item.set("nckd_itemname", itemMap.get("name"));
+                    item.set("seq", sequence);
+
+                    String id = itemMap.get("id");
+                    if (id != null) {
+                        item.set("nckd_itemid", Long.valueOf(id));
+                    }
+
+                    String datatypeId = itemMap.get("datatypeid");
+                    if (datatypeId != null) {
+                        item.set("nckd_datatype", Long.valueOf(datatypeId));
+                    }
+                    sequence++;
+                    itemEntryList.add(item);
+                } catch (Exception e) {
+                    // 记录错误日志,但继续处理其他条目
+                    System.err.println("Error processing item: " + e.getMessage());
+                }
+            }
+        }
+
         return itemEntryList;
     }
 

+ 126 - 119
code/swc/nckd-jxccl-swc/src/main/java/nckd/jxccl/swc/hsas/formplugin/web/outdata/bill/OutTempDataViewBillListPlugin.java

@@ -185,7 +185,7 @@ public class OutTempDataViewBillListPlugin extends AbstractListPlugin implements
                 String name = (String)tempMap.get("name");
                 key = (String)tempMap.get("key");
                 itemType = (String)tempMap.get("itemType");
-                if ("0".equals(itemType)) {
+                if ("999".equals(itemType)) {
                     if (!COMMONCOLUMNSET.contains(key)) {
                         IListColumn tempColumn = (IListColumn)otherFixColumnMap.get(key);
                         if (tempColumn != null) {
@@ -238,40 +238,40 @@ public class OutTempDataViewBillListPlugin extends AbstractListPlugin implements
     }
 
     private void addItemProp(DynamicObjectType mainEntityType, List<Map<String, String>> columnHeadList) {
-        String key = null;
-        Long dataTypeId = null;
-        String name = null;
-        String itemType = null;
-        Iterator it = columnHeadList.iterator();
-
-        while(true) {
-            while(true) {
-                Map temMap;
-                do {
-                    if (!it.hasNext()) {
-                        return;
-                    }
-                    temMap = (Map)it.next();
-                    key = (String)temMap.get("key");
-                    itemType = (String)temMap.get("itemType");
-                } while("0".equals(itemType));
-
-                dataTypeId = Long.valueOf((String)temMap.get("datatypeid"));
-                name = (String)temMap.get("name");
-                if (1030L != dataTypeId && 1010L != dataTypeId && 1020L != dataTypeId) {
-                    if (1050L == dataTypeId) {
-                        DateProp property = new DateProp();
-                        property.setName(key);
-                        property.setDisplayName(new LocaleString(name));
-                        mainEntityType.addProperty(property);
-                    }
-                } else {
-                    TextProp property = new TextProp();
-                    property.setName(key);
-                    property.setDisplayName(new LocaleString(name));
-                    property.setMaxLenth(200);
-                    mainEntityType.addProperty(property);
-                }
+        // 遍历所有列定义
+        for (Map<String, String> columnDef : columnHeadList) {
+            String key = columnDef.get("key");
+            String itemType = columnDef.get("itemType");
+
+            // 只处理非固定列(itemType != "0")
+//            if ("0".equals(itemType)) {
+//                continue;
+//            }
+
+            Long dataTypeId = Long.valueOf(columnDef.get("datatypeid"));
+            String name = columnDef.get("name");
+
+            // 根据数据类型创建相应属性
+            if (dataTypeId == 1050L) {
+                // 日期类型属性
+                DateProp dateProperty = new DateProp();
+                dateProperty.setName(key);
+                dateProperty.setDisplayName(new LocaleString(name));
+                mainEntityType.addProperty(dateProperty);
+            } else if (dataTypeId == 1010L || dataTypeId == 1020L || dataTypeId == 1030L) {
+                // 文本类型属性(包括数值)
+                TextProp textProperty = new TextProp();
+                textProperty.setName(key);
+                textProperty.setDisplayName(new LocaleString(name));
+                textProperty.setMaxLenth(200);
+                mainEntityType.addProperty(textProperty);
+            } else {
+                // 其他文本类型属性
+                TextProp otherProperty = new TextProp();
+                otherProperty.setName(key);
+                otherProperty.setDisplayName(new LocaleString(name));
+                otherProperty.setMaxLenth(200);
+                mainEntityType.addProperty(otherProperty);
             }
         }
     }
@@ -283,111 +283,118 @@ public class OutTempDataViewBillListPlugin extends AbstractListPlugin implements
         @Override
         public DynamicObjectCollection getData(int start, int limit) {
             DynamicObjectCollection list = super.getData(start, limit);
+
+            // 如果是全选操作,直接返回基础数据
             if (this.getQueryBuilder().isSelectedAllRows()) {
                 return list;
-            } else {
-                List<Map<String, String>> columnHeadList = OutTempDataViewBillListPlugin.this.getColumnHeadList();
-                if (SWCHelper.isEmpty(columnHeadList)) {
-                    return list;
-                } else {
-                    OutTempDataViewBillListPlugin.this.addItemProp(list.getDynamicObjectType(), columnHeadList);
-                    List<Long> idList = (List)list.stream().map((objx) -> {
-                        return objx.getLong("id");
-                    }).collect(Collectors.toList());
-                    Map<Long, Map<String, Object>> itemDataMap = this.getItemDataMap(idList);
-                    if (itemDataMap.size() == 0) {
-                        return list;
-                    } else {
-                        Map<String, Object> tempMap = null;
-                        Iterator it = list.iterator();
-                        while(true) {
-                            DynamicObject obj;
-                            do {
-                                do {
-                                    if (!it.hasNext()) {
-                                        return list;
-                                    }
-                                    obj = (DynamicObject)it.next();
-                                    tempMap = (Map)itemDataMap.get(obj.getLong("id"));
-                                } while(tempMap == null);
-                            } while(tempMap.size() == 0);
-
-                            Iterator it1 = tempMap.entrySet().iterator();
-
-                            while(it1.hasNext()) {
-                                Map.Entry<String, Object> entry = (Map.Entry)it1.next();
-                                obj.set((String)entry.getKey(), entry.getValue());
-                            }
-                        }
+            }
+
+            List<Map<String, String>> columnHeadList = OutTempDataViewBillListPlugin.this.getColumnHeadList();
+            if (SWCHelper.isEmpty(columnHeadList)) {
+                return list;
+            }
+
+            // 添加动态属性到实体类型
+            OutTempDataViewBillListPlugin.this.addItemProp(list.getDynamicObjectType(), columnHeadList);
+
+            // 提取ID列表用于查询
+            List<Long> idList = list.stream()
+                    .map(obj -> obj.getLong("id"))
+                    .filter(Objects::nonNull)
+                    .collect(Collectors.toList());
+            if (idList.isEmpty()) {
+                return list;
+            }
+            // 获取详细数据映射
+            Map<Long, Map<String, Object>> itemDataMap = this.getItemDataMap(idList);
+            if (itemDataMap.isEmpty()) {
+                return list;
+            }
+            // 将详细数据填充到主列表中
+            for (DynamicObject obj : list) {
+                Long id = obj.getLong("id");
+                Map<String, Object> detailData = itemDataMap.get(id);
+                if (detailData != null && !detailData.isEmpty()) {
+                    for (Map.Entry<String, Object> entry : detailData.entrySet()) {
+                        obj.set(entry.getKey(), entry.getValue());
                     }
                 }
             }
+            return list;
         }
 
         private Map<Long, Map<String, Object>> getItemDataMap(List<Long> idList) {
-            Map<Long, Map<String, Object>> itemDataMap = new HashMap(16);
+            Map<Long, Map<String, Object>> itemDataMap = new HashMap<>(16);
             HRBaseServiceHelper helper = new HRBaseServiceHelper("nckd_outtempdata");
             String fields = "id,entryentity.nckd_itemtype,entryentity.nckd_itemid,entryentity.nckd_datatype,entryentity.nckd_itemvalue";
             QFilter qFilter = new QFilter("id", "in", idList);
             DynamicObjectCollection itemData = helper.queryOriginalCollection(fields, new QFilter[]{qFilter});
-            if (itemData.size() == 0) {
+
+            if (itemData.isEmpty()) {
                 return itemDataMap;
-            } else {
-                Map<String, Object> tempMap = null;
-                long dataTypeId = 0L;
-                String itemValue = null;
-                String columnKey = null;
-                Iterator var12 = itemData.iterator();
-
-                while(true) {
-                    while(true) {
-                        DynamicObject obj;
-                        do {
-                            if (!var12.hasNext()) {
-                                return itemDataMap;
-                            }
-
-                            obj = (DynamicObject)var12.next();
-                            tempMap = (Map)itemDataMap.get(obj.getLong("id"));
-                            if (tempMap == null) {
-                                tempMap = new HashMap(16);
-                                itemDataMap.put(obj.getLong("id"), tempMap);
-                            }
-
-                            dataTypeId = obj.getLong("entryentity.nckd_itemtype");
-                            itemValue = obj.getString("entryentity.nckd_itemvalue");
-                        } while(itemValue == null);
-
-                        columnKey = this.getColumnKey(obj.getString("entryentity.nckd_itemtype"), obj.getLong("entryentity.nckd_itemid"));
-                        if (1020L != dataTypeId && 1010L != dataTypeId) {
-                            if (1050L == dataTypeId) {
-                                try {
-                                    ((Map)tempMap).put(columnKey, DateTimeUtils.parseDate(itemValue, "yyyy-MM-dd"));
-                                } catch (ParseException var15) {
-                                    OutTempDataViewBillListPlugin.logger.error("parse itemValue error", var15);
-                                    throw new KDBizException(ExceptionUtils.getFullStackTrace(var15));
-                                }
-                            } else {
-                                ((Map)tempMap).put(columnKey, itemValue);
-                            }
-                        } else {
-                            ((Map)tempMap).put(columnKey, new BigDecimal(itemValue));
-                        }
-                    }
+            }
+
+            for (DynamicObject obj : itemData) {
+                Long objectId = obj.getLong("id");
+                String itemValue = obj.getString("entryentity.nckd_itemvalue");
+
+                // 跳过空值记录
+                if (itemValue == null) {
+                    continue;
                 }
+
+                // 获取或创建该对象的属性映射
+                Map<String, Object> objectProperties = itemDataMap.computeIfAbsent(objectId, k -> new HashMap<>(16));
+
+                // 获取列键和数据类型
+                String itemType = obj.getString("entryentity.nckd_itemtype");
+                Long itemId = obj.getLong("entryentity.nckd_itemid");
+                String columnKey = this.getColumnKey(itemType, itemId);
+                Long dataTypeId = obj.getLong("entryentity.nckd_datatype");
+
+                // 根据数据类型处理值
+                try {
+                    Object processedValue = this.processValueByDataType(dataTypeId, itemValue);
+                    objectProperties.put(columnKey, processedValue);
+                } catch (ParseException e) {
+                    OutTempDataViewBillListPlugin.logger.error("parse itemValue error", e);
+                    throw new KDBizException(ExceptionUtils.getFullStackTrace(e));
+                }
+            }
+
+            return itemDataMap;
+        }
+
+        /**
+         * 根据数据类型处理值
+         * @param dataTypeId 数据类型ID
+         * @param itemValue 原始值
+         * @return 处理后的值
+         * @throws ParseException 解析异常
+         */
+        private Object processValueByDataType(Long dataTypeId, String itemValue) throws ParseException {
+            if (dataTypeId == null) {
+                return itemValue;
+            }
+
+            if (dataTypeId == 1050L) {
+                // 日期类型
+                return DateTimeUtils.parseDate(itemValue, "yyyy-MM-dd");
+            } else if (dataTypeId == 1010L || dataTypeId == 1020L) {
+                // 数值类型
+                return new BigDecimal(itemValue);
+            } else {
+                // 其他类型作为字符串处理
+                return itemValue;
             }
         }
 
         private String getColumnKey(String itemType, long itemId) {
             String columnKey = "";
-            if ("4".equals(itemType)) {
-                columnKey = "ft" + itemId;
+            if ("0".equals(itemType)) {
+                columnKey = "fix" + itemId;
             } else if ("1".equals(itemType)) {
                 columnKey = "ii" + itemId;
-            } else if ("3".equals(itemType)) {
-                columnKey = "bs" + itemId;
-            } else if ("2".equals(itemType)) {
-                columnKey = "sp" + itemId;
             }
 
             return columnKey;

+ 7 - 0
code/swc/nckd-jxccl-swc/src/main/java/nckd/jxccl/swc/hsas/formplugin/web/outdata/helper/OutImpTemplateHelper.java

@@ -240,6 +240,13 @@ public class OutImpTemplateHelper {
                 ));
     }
 
+    public static Map<Long, DynamicObject> getAllBaseItemMap() {
+        String fields = "id,number,name,nckd_datatype.id,nckd_ispreset,nckd_presetcomment";
+        QFilter filter = new QFilter("enable", "=", "1");
+        DynamicObjectCollection dyns = SwcConstant.OUTIMPORTITEM_ENTITY.queryOriginalCollection(fields, new QFilter[]{filter});
+        return dyns.stream().collect(Collectors.toMap(item -> item.getLong("id"), item -> item));
+    }
+
 
     static {
 //        String fields = "id,number,name,nckd_datatype.id";