物料导入优化

This commit is contained in:
李贵强 2025-03-11 09:48:02 +08:00
parent ae8c381fe7
commit 663dddcaf4
1 changed files with 32 additions and 15 deletions

View File

@ -120,34 +120,44 @@ public class ContractMaterialImportPlugin extends AbstractFormPlugin {
public void beforeImportEntry(BeforeImportEntryEventArgs e) {
super.beforeImportEntry(e);
materialList.clear();
Set<String> existCodes=new HashSet<>();
Set<String> 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<String, Object> 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<Map.Entry<String, List<ImportEntryData>>> entries = itemEntry.entrySet();
for (Map.Entry<String, List<ImportEntryData>> entry : entries) {
String entryName = entry.getKey();
@ -155,19 +165,25 @@ public class ContractMaterialImportPlugin extends AbstractFormPlugin {
if (CollectionUtils.isEmpty(entryEntityImportDataList)) {
return;
}
Map<Integer, String> indexVsMsgMap = validateEntry(entryEntityImportDataList,existCodes);
// 进行校验
Map<Integer, String> indexVsMsgMap = validateEntry(entryEntityImportDataList, existCodes);
Set<Integer> indexSet = indexVsMsgMap.keySet();
Map<String, List<Object>> logMap = e.getEntryDataMap();
ImportLogger importLogger = (ImportLogger)logMap.get(entryName).get(0);
ImportLogger importLogger = (ImportLogger) logMap.get(entryName).get(0);
// 记录错误日志
for (Map.Entry<Integer, String> indexVsMsgEntry : indexVsMsgMap.entrySet()) {
Integer index = indexVsMsgEntry.getKey();
importLogger.log(index, indexVsMsgEntry.getValue());
importLogger.fail();
importLogger.setTotal(importLogger.getTotal() + 1);
}
Iterator<ImportEntryData> iterator = entryEntityImportDataList.iterator();
while (iterator.hasNext()) {
ImportEntryData entryData = iterator.next();
// 移除校验失败的数据
Iterator<ImportEntryData> 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<Integer, String> validateEntry(List<ImportEntryData> entryDataList,Set<String> existingMaterialCodes) {
Map<Integer, String> indexVsMsgMap = new HashMap<>();
Set<String> encounteredMaterialCodes = new HashSet<>(); // 用于记录当前批次中的物料编码