diff --git a/main/java/shkd/repc/recon/formplugin/ContractMaterialImportPlugin.java b/main/java/shkd/repc/recon/formplugin/ContractMaterialImportPlugin.java index 7b844b7..8e89c05 100644 --- a/main/java/shkd/repc/recon/formplugin/ContractMaterialImportPlugin.java +++ b/main/java/shkd/repc/recon/formplugin/ContractMaterialImportPlugin.java @@ -120,34 +120,44 @@ public class ContractMaterialImportPlugin extends AbstractFormPlugin { public void beforeImportEntry(BeforeImportEntryEventArgs e) { super.beforeImportEntry(e); materialList.clear(); - Set existCodes=new HashSet<>(); + Set existCodes = new HashSet<>(); + + // 获取已存在的物料编码 DynamicObjectCollection orderFormEntry = (DynamicObjectCollection) this.getModel().getValue("qeug_orderformentry"); - if (null!=orderFormEntry&&orderFormEntry.size()!=0){ + if (orderFormEntry != null && !orderFormEntry.isEmpty()) { for (DynamicObject dynamicObject : orderFormEntry) { String number = dynamicObject.getString("qeug_material.number"); existCodes.add(number); } } + + // 处理导入数据 HashMap itemEntry = (HashMap) e.getSource(); ArrayList list = (ArrayList) itemEntry.get("qeug_orderformentry"); - for (int i = 0; i < list.size(); i++) { - ImportEntryData importData = (ImportEntryData) list.get(i); + + Iterator iterator = list.iterator(); + while (iterator.hasNext()) { + ImportEntryData importData = (ImportEntryData) iterator.next(); JSONObject data = importData.getData(); - ImportMaterial importMaterial = new ImportMaterial(); Map map = data.toJavaObject(Map.class); JSONObject material = (JSONObject) map.get("qeug_material"); - //物料编码 + + // 如果 material 为空,则直接移除该行数据 + if (material == null) { + iterator.remove(); + continue; + } + + ImportMaterial importMaterial = new ImportMaterial(); importMaterial.setMaterialNumber(material.getString("number")); - //物料名称 importMaterial.setMaterialName((String) map.get("qeug_materialnames")); - //物料类型 importMaterial.setMaterialType((String) map.get("qeug_importmaterialtype")); - //物料规格 importMaterial.setMaterialModel((String) map.get("qeug_importmodel")); - //物料单位 importMaterial.setMaterialUnit((String) map.get("qeug_importunit")); materialList.add(importMaterial); } + + // 校验数据 Set>> entries = itemEntry.entrySet(); for (Map.Entry> entry : entries) { String entryName = entry.getKey(); @@ -155,19 +165,25 @@ public class ContractMaterialImportPlugin extends AbstractFormPlugin { if (CollectionUtils.isEmpty(entryEntityImportDataList)) { return; } - Map indexVsMsgMap = validateEntry(entryEntityImportDataList,existCodes); + + // 进行校验 + Map indexVsMsgMap = validateEntry(entryEntityImportDataList, existCodes); Set indexSet = indexVsMsgMap.keySet(); Map> logMap = e.getEntryDataMap(); - ImportLogger importLogger = (ImportLogger)logMap.get(entryName).get(0); + ImportLogger importLogger = (ImportLogger) logMap.get(entryName).get(0); + + // 记录错误日志 for (Map.Entry indexVsMsgEntry : indexVsMsgMap.entrySet()) { Integer index = indexVsMsgEntry.getKey(); importLogger.log(index, indexVsMsgEntry.getValue()); importLogger.fail(); importLogger.setTotal(importLogger.getTotal() + 1); } - Iterator iterator = entryEntityImportDataList.iterator(); - while (iterator.hasNext()) { - ImportEntryData entryData = iterator.next(); + + // 移除校验失败的数据 + Iterator iterator2 = entryEntityImportDataList.iterator(); + while (iterator2.hasNext()) { + ImportEntryData entryData = iterator2.next(); Integer rowNum = (Integer) entryData.getData().get("rowNum"); if (indexSet.contains(rowNum)) { iterator.remove(); @@ -176,6 +192,7 @@ public class ContractMaterialImportPlugin extends AbstractFormPlugin { } } + private Map validateEntry(List entryDataList,Set existingMaterialCodes) { Map indexVsMsgMap = new HashMap<>(); Set encounteredMaterialCodes = new HashSet<>(); // 用于记录当前批次中的物料编码