From b783eca764ec8b274c4f2e23c5f3884506ee984d Mon Sep 17 00:00:00 2001 From: xuhaihui <2098865055@qq.com> Date: Mon, 29 Sep 2025 14:06:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=81=E4=B8=9A=E6=88=90=E6=9C=AC=E6=A0=B8?= =?UTF-8?q?=E7=AE=97=E8=A1=A8=E5=8D=95=E6=8F=92=E4=BB=B6=E5=8F=96=E6=95=B0?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E6=B7=BB=E5=8A=A0=E6=88=90=E6=9C=AC=E9=87=91?= =?UTF-8?q?=E9=A2=9D=E6=B1=87=E6=80=BB=E5=8E=BB=E9=87=8D=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/form/EntCostSplitBillPlugin.java | 110 +++++++++++++----- 1 file changed, 79 insertions(+), 31 deletions(-) diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/EntCostSplitBillPlugin.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/EntCostSplitBillPlugin.java index a1a27e7..489c28f 100644 --- a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/EntCostSplitBillPlugin.java +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/EntCostSplitBillPlugin.java @@ -12,7 +12,10 @@ import kd.bos.orm.query.QFilter; import kd.bos.servicehelper.BusinessDataServiceHelper; import kd.bos.servicehelper.QueryServiceHelper; +import java.math.BigDecimal; import java.util.EventObject; +import java.util.HashMap; +import java.util.Map; /** * 企业成本核算表单插件 @@ -51,11 +54,14 @@ public class EntCostSplitBillPlugin extends AbstractBillPlugIn { filter.and(new QFilter("zcgj_period", QCP.equals, period1.getPkValue()));//期间 filter.and(new QFilter("zcgj_isnew", QCP.equals, true));//是否最新 DynamicObjectCollection rptAssistBalanceGxCollection = QueryServiceHelper.query("zcgj_rpt_assistbalancegx", - "id,zcgj_account,zcgj_processname", + "id,zcgj_account,zcgj_processname,zcgj_debitlocal,zcgj_costcompanyname", new QFilter[]{filter});//"核算维度余额取数表(矿山工序维度)" + // 在循环开始前定义汇总Map + Map summaryMap = new HashMap<>(); + for (DynamicObject rptAssistBalanceGx : rptAssistBalanceGxCollection) { - QFilter[] qFilter = new QFilter[]{new QFilter("id", QCP.equals, rptAssistBalanceGx.get("zcgj_account"))}; + QFilter[] qFilter = new QFilter[]{new QFilter("id", QCP.equals, rptAssistBalanceGx.get("zcgj_account"))};//科目ID DynamicObject bd_accountview = BusinessDataServiceHelper.loadSingle("bd_accountview", "id,number,name", qFilter);//"会计科目" if (bd_accountview == null) { @@ -74,42 +80,84 @@ public class EntCostSplitBillPlugin extends AbstractBillPlugIn { if (ec_ecbd_pro_cbs == null && zcgj_accountcost == null && ec_projects.length == 0) { continue; } - DynamicObject newEntry = new DynamicObject(entryType); - DynamicObjectCollection subEntryEntityCollection = newEntry.getDynamicObjectCollection("zcgj_subentryentity");//成本核算维度明细 - DynamicObjectType subEntryEntityType = subEntryEntityCollection.getDynamicObjectType(); - DynamicObject newEntrySubEntryEntity = new DynamicObject(subEntryEntityType); - if (ec_projects.length != 0) { - for (DynamicObject ec_project : ec_projects) { - boolean zcgj_init = ec_project.getBoolean("zcgj_init");//默认项目 - if (zcgj_init) { + + // 构建去重key - 根据工序或成本中心分别处理 + String processName = rptAssistBalanceGx.getString("zcgj_processname"); // 工序名称 + String costCompanyName = rptAssistBalanceGx.getString("zcgj_costcompanyname"); // 成本中心名称 + Object costType = zcgj_accountcost != null ? zcgj_accountcost.get("zcgj_acccostentry.zcgj_costtype") : null; // 成本项 + Object secType = zcgj_accountcost != null ? zcgj_accountcost.get("zcgj_acccostentry.zcgj_sectype") : null; // 二级分类 + + String uniqueKey = ""; + if (processName != null && !processName.isEmpty()) { + // 存在工序时,按照工序+成本项+二级分类去重 + uniqueKey = "PROCESS_" + processName + "_" + (costType != null ? costType.toString() : "") + "_" + (secType != null ? secType.toString() : ""); + } else if (costCompanyName != null && !costCompanyName.isEmpty()) { + // 存在成本中心时,按照成本中心+成本项+二级分类去重 + uniqueKey = "COSTCENTER_" + costCompanyName + "_" + (costType != null ? costType.toString() : "") + "_" + (secType != null ? secType.toString() : ""); + } else { + // 如果既没有工序也没有成本中心,则不进行汇总,使用唯一ID + uniqueKey = "NONE_" + rptAssistBalanceGx.getString("id"); + } + + DynamicObject existingEntry = summaryMap.get(uniqueKey); + if (existingEntry != null) { + // 如果已存在相同key的记录,则累加成本金额 + Object existingAmount = existingEntry.get("costamount"); + Object newAmount = rptAssistBalanceGx.get("zcgj_debitlocal"); + + // 进行金额累加 + BigDecimal totalAmount = new BigDecimal(existingAmount != null ? existingAmount.toString() : "0") + .add(new BigDecimal(newAmount != null ? newAmount.toString() : "0")); + existingEntry.set("costamount", totalAmount); + } else { + // 如果不存在相同key的记录,则创建新记录 + DynamicObject newEntry = new DynamicObject(entryType); + DynamicObjectCollection subEntryEntityCollection = newEntry.getDynamicObjectCollection("zcgj_subentryentity");//成本核算维度明细 + DynamicObjectType subEntryEntityType = subEntryEntityCollection.getDynamicObjectType(); + DynamicObject newEntrySubEntryEntity = new DynamicObject(subEntryEntityType); + + if (ec_projects.length != 0) { + for (DynamicObject ec_project : ec_projects) { + boolean zcgj_init = ec_project.getBoolean("zcgj_init");//默认项目 + if (zcgj_init) { + DynamicObject ec_project_f7 = BusinessDataServiceHelper.loadSingle("ec_project_f7", "id", + new QFilter[]{new QFilter("id", QCP.equals, ec_project.getPkValue())});//项目 + newEntry.set("project", ec_project_f7);//"项目" + newEntrySubEntryEntity.set("zcgj_project", ec_project_f7);//项目 + break; + } + } + Object project = newEntry.get("project"); + if (project == null) { DynamicObject ec_project_f7 = BusinessDataServiceHelper.loadSingle("ec_project_f7", "id", - new QFilter[]{new QFilter("id", QCP.equals, ec_project.getPkValue())});//项目 - newEntry.set("project", ec_project_f7);//"项目" + new QFilter[]{new QFilter("id", QCP.equals, ec_projects[0].getPkValue())});//项目 + newEntry.set("project", ec_project_f7);//项目 newEntrySubEntryEntity.set("zcgj_project", ec_project_f7);//项目 - break; } } - Object project = newEntry.get("project"); - if (project == null) { - DynamicObject ec_project_f7 = BusinessDataServiceHelper.loadSingle("ec_project_f7", "id", - new QFilter[]{new QFilter("id", QCP.equals, ec_projects[0].getPkValue())});//项目 - newEntry.set("project", ec_project_f7);//项目 - newEntrySubEntryEntity.set("zcgj_project", ec_project_f7);//项目 + if (ec_ecbd_pro_cbs != null) { + newEntry.set("cbs", ec_ecbd_pro_cbs);//成本分解结构 + newEntrySubEntryEntity.set("zcgj_cbs", ec_ecbd_pro_cbs);//成本分解结构 } + if (zcgj_accountcost != null) { + newEntry.set("costtype", zcgj_accountcost.get("zcgj_acccostentry.zcgj_costtype"));//成本项 + newEntry.set("zcgj_sectype", zcgj_accountcost.get("zcgj_acccostentry.zcgj_sectype"));//二级分类 + newEntrySubEntryEntity.set("zcgj_costtype", zcgj_accountcost.get("zcgj_acccostentry.zcgj_costtype"));//成本项 + newEntrySubEntryEntity.set("zcgj_sectype1", zcgj_accountcost.get("zcgj_acccostentry.zcgj_sectype"));//二级分类 + } + newEntry.set("costamount", rptAssistBalanceGx.get("zcgj_debitlocal"));//成本金额 + + summaryMap.put(uniqueKey, newEntry); + subEntryEntityCollection.add(newEntrySubEntryEntity); } - if (ec_ecbd_pro_cbs != null) { - newEntry.set("cbs", ec_ecbd_pro_cbs);//成本分解结构 - newEntrySubEntryEntity.set("zcgj_cbs", ec_ecbd_pro_cbs);//成本分解结构 - } - if (zcgj_accountcost != null) { - newEntry.set("costtype", zcgj_accountcost.get("zcgj_acccostentry.zcgj_costtype"));//成本项 - newEntry.set("zcgj_sectype", zcgj_accountcost.get("zcgj_acccostentry.zcgj_sectype"));//二级分类 - newEntrySubEntryEntity.set("zcgj_costtype", zcgj_accountcost.get("zcgj_acccostentry.zcgj_costtype"));//成本项 - newEntrySubEntryEntity.set("zcgj_sectype1", zcgj_accountcost.get("zcgj_acccostentry.zcgj_sectype"));//二级分类 - } - entryCollection.add(newEntry); - subEntryEntityCollection.add(newEntrySubEntryEntity); } + + // 清空原集合并添加汇总后的数据 + entryCollection.clear(); + for (DynamicObject entry : summaryMap.values()) { + entryCollection.add(entry); + } + this.getView().updateView("entryentity");//刷新分录 this.getView().updateView("zcgj_subentryentity");//刷新分录 this.getModel().endInit();