合同物料非定额导入校验
This commit is contained in:
parent
d724f240f0
commit
c1ef44e138
|
@ -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<BasedataItem, List<Object>> entry : searchResult.entrySet()) {
|
||||
List<Object> basedata = entry.getValue();
|
||||
if (basedata.isEmpty()) { // 查不到基础资料数据
|
||||
//数据去重
|
||||
//List<ImportMaterial> 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<String> 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<Map.Entry<String, List<ImportEntryData>>> entries = itemEntry.entrySet();
|
||||
for (Map.Entry<String, List<ImportEntryData>> entry : entries) {
|
||||
String entryName = entry.getKey();
|
||||
List<ImportEntryData> entryEntityImportDataList = entry.getValue();
|
||||
if (CollectionUtils.isEmpty(entryEntityImportDataList)) {
|
||||
return;
|
||||
}
|
||||
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);
|
||||
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();
|
||||
Integer rowNum = (Integer) entryData.getData().get("rowNum");
|
||||
if (indexSet.contains(rowNum)) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<ImportMaterial> getDistinctMaterialsByNumber() {
|
||||
private Map<Integer, String> validateEntry(List<ImportEntryData> entryDataList,Set<String> existingMaterialCodes) {
|
||||
Map<Integer, String> indexVsMsgMap = new HashMap<>();
|
||||
Set<String> 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<String, Object> 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<ImportMaterial> set) {
|
||||
ImportMaterial result = null;
|
||||
if (set != null && !set.isEmpty()) {
|
||||
|
@ -156,6 +218,4 @@ public class ContractMaterialImportPlugin extends AbstractFormPlugin {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue