From c1ef44e138dd84773c318393f20ced729c6cf6b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E8=B4=B5=E5=BC=BA?= Date: Thu, 2 Jan 2025 16:13:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=90=8C=E7=89=A9=E6=96=99=E9=9D=9E?= =?UTF-8?q?=E5=AE=9A=E9=A2=9D=E5=AF=BC=E5=85=A5=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ContractMaterialImportPlugin.java | 120 +++++++++++++----- .../formplugin/dynamic/ImportMaterial.java | 14 ++ 2 files changed, 104 insertions(+), 30 deletions(-) diff --git a/main/java/shkd/repc/recon/formplugin/ContractMaterialImportPlugin.java b/main/java/shkd/repc/recon/formplugin/ContractMaterialImportPlugin.java index 43d3cdd..7ce02ed 100644 --- a/main/java/shkd/repc/recon/formplugin/ContractMaterialImportPlugin.java +++ b/main/java/shkd/repc/recon/formplugin/ContractMaterialImportPlugin.java @@ -1,11 +1,13 @@ package shkd.repc.recon.formplugin; +import com.alibaba.dubbo.common.utils.CollectionUtils; import com.alibaba.fastjson.JSONObject; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObjectCollection; import kd.bos.entity.datamodel.BasedataItem; import kd.bos.entity.datamodel.events.BeforeImportEntryEventArgs; import kd.bos.entity.datamodel.events.QueryImportBasedataEventArgs; +import kd.bos.entity.plugin.ImportLogger; import kd.bos.form.plugin.AbstractFormPlugin; import kd.bos.form.plugin.importentry.resolving.ImportEntryData; import kd.bos.form.plugin.impt.BatchImportPlugin; @@ -37,13 +39,8 @@ public class ContractMaterialImportPlugin extends AbstractFormPlugin { for (Map.Entry> entry : searchResult.entrySet()) { List basedata = entry.getValue(); if (basedata.isEmpty()) { // 查不到基础资料数据 - //数据去重 - //List list = getDistinctMaterialsByNumber(); - Long materialId = newMaterial(entry.getKey().getSearchValue(),materialList); basedata.add(materialId); - //algo.storage.redis.ip_port -// System.getProperty("algo.storage.redis.ip_port"); } else { // 查到多个基础资料数据 // 业务场景,应根据需求剔除不合法的基础资料数据(最终保留一个) @@ -70,22 +67,22 @@ public class ContractMaterialImportPlugin extends AbstractFormPlugin { bd_material.set("createorg",org); } //物料分类 - QFilter type = new QFilter("name", QCP.equals, materialByNumber.getMaterialType()); - DynamicObject materialGroup = BusinessDataServiceHelper.loadSingle("bd_materialgroup",type.toArray()); - if (null!=materialGroup){ - //物料分组 - bd_material.set("group",materialGroup); - //分类标准 - DynamicObjectCollection groupStandard = bd_material.getDynamicObjectCollection("entry_groupstandard"); - DynamicObject newEntry = groupStandard.addNew(); - QFilter qFilter = new QFilter("name", QCP.equals, "物料基本分类标准"); - DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle("bd_materialgroupstandard", qFilter.toArray()); - if (null!=dynamicObject){ - newEntry.set("standardid",dynamicObject); - } - //分类 - newEntry.set("groupid",materialGroup); + DynamicObject materialGroup = BusinessDataServiceHelper.loadSingle("bd_materialgroup",(new QFilter("name", QCP.equals, materialByNumber.getMaterialType())).toArray()); + if (null==materialGroup){ + materialGroup=BusinessDataServiceHelper.loadSingle("bd_materialgroup",(new QFilter("number", QCP.equals, "waitgroup")).toArray()); } + //物料分组 + bd_material.set("group",materialGroup); + //分类标准 + DynamicObjectCollection groupStandard = bd_material.getDynamicObjectCollection("entry_groupstandard"); + DynamicObject newEntry = groupStandard.addNew(); + QFilter qFilter = new QFilter("name", QCP.equals, "物料基本分类标准"); + DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle("bd_materialgroupstandard", qFilter.toArray()); + if (null!=dynamicObject){ + newEntry.set("standardid",dynamicObject); + } + //分类 + newEntry.set("groupid",materialGroup); //物料单位 QFilter unit = new QFilter("name", QCP.equals, materialByNumber.getMaterialUnit()); DynamicObject measureUnits = BusinessDataServiceHelper.loadSingle("bd_measureunits",unit.toArray()); @@ -108,6 +105,14 @@ public class ContractMaterialImportPlugin extends AbstractFormPlugin { public void beforeImportEntry(BeforeImportEntryEventArgs e) { super.beforeImportEntry(e); materialList.clear(); + Set existCodes=new HashSet<>(); + DynamicObjectCollection orderFormEntry = (DynamicObjectCollection) this.getModel().getValue("qeug_orderformentry"); + if (null!=orderFormEntry&&orderFormEntry.size()!=0){ + 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++) { @@ -128,20 +133,77 @@ public class ContractMaterialImportPlugin extends AbstractFormPlugin { importMaterial.setMaterialUnit((String) map.get("qeug_importunit")); materialList.add(importMaterial); } + Set>> entries = itemEntry.entrySet(); + for (Map.Entry> entry : entries) { + String entryName = entry.getKey(); + List entryEntityImportDataList = entry.getValue(); + if (CollectionUtils.isEmpty(entryEntityImportDataList)) { + return; + } + Map indexVsMsgMap = validateEntry(entryEntityImportDataList,existCodes); + Set indexSet = indexVsMsgMap.keySet(); + Map> logMap = e.getEntryDataMap(); + 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(); + Integer rowNum = (Integer) entryData.getData().get("rowNum"); + if (indexSet.contains(rowNum)) { + iterator.remove(); + } + } + } } - public List getDistinctMaterialsByNumber() { + private Map validateEntry(List entryDataList,Set existingMaterialCodes) { + Map indexVsMsgMap = new HashMap<>(); + Set encounteredMaterialCodes = new HashSet<>(); // 用于记录当前批次中的物料编码 + for (int i = 0; i < entryDataList.size(); i++) { + ImportEntryData entryData = entryDataList.get(i); - return new ArrayList<>(materialList.stream() - .collect(Collectors.toMap( - ImportMaterial::getMaterialNumber, // 根据 materialNumber 去重 - material -> material, // 保留第一个匹配的元素 - (existing, replacement) -> existing // 如果有重复的 materialNumber,保留第一个 - )) - .values()); // 收集成 List + // 获取当前行的 JSONObject 数据 + JSONObject data = entryData.getData(); + Map map = data.toJavaObject(Map.class); + JSONObject material = (JSONObject) map.get("qeug_material"); + + // 获取物料编码和物料单位 + String materialCode = material.getString("number"); // 物料编码 + String materialUnit = (String) map.get("qeug_importunit"); // 物料单位 + // 获取当前行号 + Integer rowNum = (Integer) entryData.getData().get("rowNum"); + + // 校验物料编码和物料单位 + if (materialCode == null || materialCode.trim().isEmpty()) { + indexVsMsgMap.put(rowNum, "第" + (i + 1) + "行:物料编码不能为空或空字符串"); + } + if (materialUnit == null || materialUnit.trim().isEmpty()) { + indexVsMsgMap.put(rowNum, "第" + (i + 1) + "行:物料单位不能为空或空字符串"); + } + + // 校验物料编码是否重复 + if (encounteredMaterialCodes.contains(materialCode)) { + indexVsMsgMap.put(rowNum, "第" + (i + 1) + "行:物料编码重复"); + } else { + encounteredMaterialCodes.add(materialCode); + } + + // 校验物料编码是否已经存在于当前页面的表格中 + if (existingMaterialCodes.contains(materialCode)) { + indexVsMsgMap.put(rowNum, "第" + (i + 1) + "行:物料编码已存在,不能重复"); + } + } + + return indexVsMsgMap; } + public ImportMaterial getMaterialByNumber(String number, Set set) { ImportMaterial result = null; if (set != null && !set.isEmpty()) { @@ -156,6 +218,4 @@ public class ContractMaterialImportPlugin extends AbstractFormPlugin { } return result; } - - } diff --git a/main/java/shkd/repc/recon/formplugin/dynamic/ImportMaterial.java b/main/java/shkd/repc/recon/formplugin/dynamic/ImportMaterial.java index 1501869..987f3fc 100644 --- a/main/java/shkd/repc/recon/formplugin/dynamic/ImportMaterial.java +++ b/main/java/shkd/repc/recon/formplugin/dynamic/ImportMaterial.java @@ -62,4 +62,18 @@ public class ImportMaterial { ", materialUnit='" + materialUnit + '\'' + '}'; } + + public ImportMaterial() { + super(); + } + + @Override + public int hashCode() { + return super.hashCode(); + } + + @Override + public boolean equals(Object obj) { + return super.equals(obj); + } }