From 486001ab859f36c743f058416c1a57d7ba185938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E8=B4=B5=E5=BC=BA?= Date: Sat, 15 Mar 2025 11:17:34 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=87=E8=B4=AD=E8=AE=A1=E5=88=92F7=E8=B6=85?= =?UTF-8?q?=E9=A2=9D=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rebm/listplugin/PurDemandListPlugin.java | 7 +- .../formplugin/ConNoTextBillFromPlugin.java | 70 ++++++ .../ContractMaterialImportPlugin.java | 229 +++++++++--------- 3 files changed, 193 insertions(+), 113 deletions(-) create mode 100644 main/java/shkd/repc/recon/formplugin/ConNoTextBillFromPlugin.java diff --git a/main/java/shkd/repc/rebm/listplugin/PurDemandListPlugin.java b/main/java/shkd/repc/rebm/listplugin/PurDemandListPlugin.java index 25d0e27..6246b8d 100644 --- a/main/java/shkd/repc/rebm/listplugin/PurDemandListPlugin.java +++ b/main/java/shkd/repc/rebm/listplugin/PurDemandListPlugin.java @@ -29,15 +29,16 @@ public class PurDemandListPlugin extends AbstractListPlugin { public void setFilter(SetFilterEvent e) { super.setFilter(e); - e.getQFilters().clear(); + IFormView parentView = this.getView().getParentView(); IDataModel model = parentView.getModel(); DynamicObject dataEntity = model.getDataEntity(); IDataEntityType dataEntityType = dataEntity.getDataEntityType(); String name = dataEntityType.getName(); - //立项||费用登记 - if ("rebm_project".equals(name) || "recon_connotextbill".equals(name) ||"rebm_purplan".equals(name)) { + //立项||采购计划 + if ("rebm_project".equals(name) ||"rebm_purplan".equals(name)) { + e.getQFilters().clear(); DynamicObject org = dataEntity.getDynamicObject("org"); if (null != org) { List qFilters = e.getQFilters(); diff --git a/main/java/shkd/repc/recon/formplugin/ConNoTextBillFromPlugin.java b/main/java/shkd/repc/recon/formplugin/ConNoTextBillFromPlugin.java new file mode 100644 index 0000000..ad9a30b --- /dev/null +++ b/main/java/shkd/repc/recon/formplugin/ConNoTextBillFromPlugin.java @@ -0,0 +1,70 @@ +package shkd.repc.recon.formplugin; + +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.form.field.BasedataEdit; +import kd.bos.form.field.RefBillEdit; +import kd.bos.form.field.events.BeforeF7SelectEvent; +import kd.bos.form.field.events.BeforeF7SelectListener; +import kd.bos.form.plugin.AbstractFormPlugin; +import kd.bos.list.ListShowParameter; +import kd.bos.orm.query.QCP; +import kd.bos.orm.query.QFilter; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.sdk.plugin.Plugin; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.EventObject; +import java.util.List; + +/** + * 动态表单插件 + * 【费用登记】- + */ +public class ConNoTextBillFromPlugin extends AbstractFormPlugin implements Plugin, BeforeF7SelectListener { + + + @Override + public void registerListener(EventObject e) { + super.registerListener(e); + RefBillEdit bEdit = this.getView().getControl("qeug_refbillfield"); + bEdit.addBeforeF7SelectListener(this); + } + + @Override + public void beforeF7Select(BeforeF7SelectEvent evt) { + ListShowParameter formShowParameter = (ListShowParameter) evt.getFormShowParameter(); + ArrayList canSeeDataId = new ArrayList<>(); + //查找所有已审核采购需求数据 + DynamicObject org = (DynamicObject) this.getModel().getValue("org"); + QFilter qFilter = new QFilter("billstatus", QCP.equals, "C"); + qFilter.and(new QFilter("org.name", QCP.equals, org.getString("name"))); + DynamicObject[] settlePlanBills = BusinessDataServiceHelper.load("recon_settleplanbill", "id,bill,qeug_applyamount", qFilter.toArray()); + //判断申请金额是否被费用登记用完 + for (int i = 0; i < settlePlanBills.length; i++) { + DynamicObject settlePlanBill = settlePlanBills[i]; + long id = settlePlanBill.getLong("id"); + BigDecimal applyAmount = settlePlanBill.getBigDecimal("qeug_applyamount"); + BigDecimal allOriAmt=BigDecimal.ZERO; + QFilter qFilter1 = new QFilter("qeug_refbillfield.id", QCP.equals, id); + DynamicObject[] conNoTextBills = BusinessDataServiceHelper.load("recon_connotextbill", "id,oriamt", qFilter1.toArray()); + if (conNoTextBills.length!=0){ + for (int j = 0; j < conNoTextBills.length; j++) { + DynamicObject conNoTextBill = conNoTextBills[j]; + BigDecimal oriAmt = conNoTextBill.getBigDecimal("oriamt"); + allOriAmt=allOriAmt.add(oriAmt); + } + } + //还有余额 + if (applyAmount.compareTo(allOriAmt)>0){ + canSeeDataId.add(id); + } + } + List qFilters = new ArrayList<>(); + qFilters.add(new QFilter("id", QCP.in, canSeeDataId)); + formShowParameter.getListFilterParameter().setQFilters(qFilters); + } + + + +} \ No newline at end of file diff --git a/main/java/shkd/repc/recon/formplugin/ContractMaterialImportPlugin.java b/main/java/shkd/repc/recon/formplugin/ContractMaterialImportPlugin.java index 8e89c05..5a3aa42 100644 --- a/main/java/shkd/repc/recon/formplugin/ContractMaterialImportPlugin.java +++ b/main/java/shkd/repc/recon/formplugin/ContractMaterialImportPlugin.java @@ -68,127 +68,136 @@ public class ContractMaterialImportPlugin extends AbstractFormPlugin { } } private Long newMaterial(String number,Set set){ - ImportMaterial materialByNumber = getMaterialByNumber(number, set); + DynamicObject bd_material = null; + try { + ImportMaterial materialByNumber = getMaterialByNumber(number, set); - DynamicObject bd_material = BusinessDataServiceHelper.newDynamicObject(BD_MATERIAL); - //物料编码 - bd_material.set("number",number); - //物料名称 - bd_material.set("name",materialByNumber.getMaterialName()); - //所属组织 - long rootOrgId = OrgUnitServiceHelper.getRootOrgId(); - DynamicObject org = BusinessDataServiceHelper.loadSingle(rootOrgId, BOS_ORG); - if (null != org) { - bd_material.set("createorg",org); + bd_material = BusinessDataServiceHelper.newDynamicObject(BD_MATERIAL); + //物料编码 + bd_material.set("number",number); + //物料名称 + bd_material.set("name",materialByNumber.getMaterialName()); + //所属组织 + long rootOrgId = OrgUnitServiceHelper.getRootOrgId(); + DynamicObject org = BusinessDataServiceHelper.loadSingle(rootOrgId, BOS_ORG); + if (null != org) { + bd_material.set("createorg",org); + } + //物料分类 + 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, "gc-tlfs")).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.getLong("id")); + //物料单位 + QFilter unit = new QFilter("name", QCP.equals, materialByNumber.getMaterialUnit()); + DynamicObject measureUnits = BusinessDataServiceHelper.loadSingle("bd_measureunits",unit.toArray()); + if (null!=measureUnits){ + bd_material.set("baseunit",measureUnits); + } + bd_material.set("modelnum",materialByNumber.getMaterialModel());//规格 + bd_material.set("materialtype","1");//物料类型:物资 + bd_material.set("enable", "1");//使用状态:可用 + bd_material.set("status", "C");//数据状态:审核 + bd_material.set("ctrlstrategy", "5");//控制策略:全局共享 + bd_material.set("enablepur",true);//可采购 + bd_material.set("enablesale",true);//可销售 + bd_material.set("enableinv",true);//可库存 + SaveServiceHelper.save(new DynamicObject[]{bd_material}); + } catch (Exception e) { + this.getView().showMessage(e.getMessage()); } - //物料分类 - 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()); - if (null!=measureUnits){ - bd_material.set("baseunit",measureUnits); - } - bd_material.set("modelnum",materialByNumber.getMaterialModel());//规格 - bd_material.set("materialtype","1");//物料类型:物资 - bd_material.set("enable", "1");//使用状态:可用 - bd_material.set("status", "C");//数据状态:审核 - bd_material.set("ctrlstrategy", "5");//控制策略:全局共享 - bd_material.set("enablepur",true);//可采购 - bd_material.set("enablesale",true);//可销售 - bd_material.set("enableinv",true);//可库存 - SaveServiceHelper.save(new DynamicObject[]{bd_material}); return bd_material.getLong("id"); } @Override public void beforeImportEntry(BeforeImportEntryEventArgs e) { super.beforeImportEntry(e); - materialList.clear(); - Set existCodes = new HashSet<>(); + try { + materialList.clear(); + Set existCodes = new HashSet<>(); - // 获取已存在的物料编码 - DynamicObjectCollection orderFormEntry = (DynamicObjectCollection) this.getModel().getValue("qeug_orderformentry"); - 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"); - - Iterator iterator = list.iterator(); - while (iterator.hasNext()) { - ImportEntryData importData = (ImportEntryData) iterator.next(); - JSONObject data = importData.getData(); - 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(); - 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 iterator2 = entryEntityImportDataList.iterator(); - while (iterator2.hasNext()) { - ImportEntryData entryData = iterator2.next(); - Integer rowNum = (Integer) entryData.getData().get("rowNum"); - if (indexSet.contains(rowNum)) { - iterator.remove(); + // 获取已存在的物料编码 + DynamicObjectCollection orderFormEntry = (DynamicObjectCollection) this.getModel().getValue("qeug_orderformentry"); + 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"); + + Iterator iterator = list.iterator(); + while (iterator.hasNext()) { + ImportEntryData importData = (ImportEntryData) iterator.next(); + JSONObject data = importData.getData(); + 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(); + 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 iterator2 = entryEntityImportDataList.iterator(); + while (iterator2.hasNext()) { + ImportEntryData entryData = iterator2.next(); + Integer rowNum = (Integer) entryData.getData().get("rowNum"); + if (indexSet.contains(rowNum)) { + iterator.remove(); + } + } + } + } catch (Exception ex) { + this.getView().showMessage(ex.getMessage()); } }