From bdfb0c16588846d30f297a83d8d7aacbd82f3472 Mon Sep 17 00:00:00 2001 From: xuhaihui <2098865055@qq.com> Date: Thu, 7 Aug 2025 10:35:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E5=87=BA=E5=90=88=E5=90=8C=E7=BB=93?= =?UTF-8?q?=E7=AE=97=E8=A1=A8=E5=8D=95=E6=8F=92=E4=BB=B6=E5=B7=A5=E5=BA=8F?= =?UTF-8?q?=E5=88=86=E6=91=8A=E9=80=BB=E8=BE=91=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/form/CostAllocatorBillPlugin.java | 81 ++++++++++++++++++- 1 file changed, 79 insertions(+), 2 deletions(-) diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/CostAllocatorBillPlugin.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/CostAllocatorBillPlugin.java index 697f58f..7f3fbd1 100644 --- a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/CostAllocatorBillPlugin.java +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/CostAllocatorBillPlugin.java @@ -11,7 +11,10 @@ import kd.bos.form.control.events.ItemClickEvent; import kd.bos.form.plugin.AbstractFormPlugin; import kd.bos.servicehelper.BusinessDataServiceHelper; +import java.math.BigDecimal; import java.util.EventObject; +import java.util.HashMap; +import java.util.Map; /* * 使用插件注册位置:支出合同结算表单插件 @@ -57,11 +60,12 @@ public class CostAllocatorBillPlugin extends AbstractFormPlugin { newProcessAllocEntity.set("zcgj_amountnotax", listEntry.get("thisamount"));//不含税金额-本期计量金额 newProcessAllocEntity.set("zcgj_rateval", listEntry.get("entrytaxrate"));//税率(%)-税率(%) newProcessAllocEntity.set("zcgj_taxamt", listEntry.get("thistax"));//税额-本期税额 - newProcessAllocEntity.set("zcgj_pa_remark", listEntry.get("desc"));//费用说明-说明 processAllocEntityCollection.add(newProcessAllocEntity); } } } + // 添加合并逻辑:按工序和税率组合合并相同项 + mergeProcessAllocEntriesByProcessAndRate(processAllocEntityCollection); } this.getView().updateView("zcgj_processallocatentity");//工序分摊 } else { @@ -124,14 +128,87 @@ public class CostAllocatorBillPlugin extends AbstractFormPlugin { newProcessAllocEntity.set("zcgj_amountnotax", listEntry.get("thisamount"));//不含税金额-本期计量金额 newProcessAllocEntity.set("zcgj_rateval", listEntry.get("entrytaxrate"));//税率(%)-税率(%) newProcessAllocEntity.set("zcgj_taxamt", listEntry.get("thistax"));//税额-本期税额 - newProcessAllocEntity.set("zcgj_pa_remark", listEntry.get("desc"));//费用说明-说明 processAllocEntityCollection.add(newProcessAllocEntity); } } } } } + // 添加合并逻辑:按工序和税率组合合并相同项 + mergeProcessAllocEntriesByProcessAndRate(processAllocEntityCollection); this.getView().updateView("zcgj_processallocatentity");//工序分摊 } } + + /** + * 按工序和税率组合合并工序分摊条目 + * + * @param processAllocEntityCollection 工序分摊集合 + */ + private void mergeProcessAllocEntriesByProcessAndRate(DynamicObjectCollection processAllocEntityCollection) { + // 使用Map来存储已存在的工序+税率组合,避免嵌套循环 + Map processRateMap = new HashMap<>(); + + for (int i = 0; i < processAllocEntityCollection.size(); i++) { + DynamicObject currentEntry = processAllocEntityCollection.get(i); + Object currentProcess = currentEntry.get("zcgj_pa_process"); // 工序 + Object currentRate = currentEntry.get("zcgj_rateval"); // 税率 + + // 创建唯一键值:工序ID + 税率值 + String key = (currentProcess != null ? currentProcess.toString() : "null") + + "_" + + (currentRate != null ? currentRate.toString() : "null"); + + if (processRateMap.containsKey(key)) { + // 如果已存在相同组合,则合并数值 + DynamicObject existingEntry = processRateMap.get(key); + + // 合并价税合计 + BigDecimal currentAmount = toBigDecimal(existingEntry.get("zcgj_pa_amount")); + BigDecimal nextAmount = toBigDecimal(currentEntry.get("zcgj_pa_amount")); + existingEntry.set("zcgj_pa_amount", currentAmount.add(nextAmount)); + + // 合并不含税金额 + BigDecimal currentAmountNoTax = toBigDecimal(existingEntry.get("zcgj_amountnotax")); + BigDecimal nextAmountNoTax = toBigDecimal(currentEntry.get("zcgj_amountnotax")); + existingEntry.set("zcgj_amountnotax", currentAmountNoTax.add(nextAmountNoTax)); + + // 合并税额 + BigDecimal currentTaxAmt = toBigDecimal(existingEntry.get("zcgj_taxamt")); + BigDecimal nextTaxAmt = toBigDecimal(currentEntry.get("zcgj_taxamt")); + existingEntry.set("zcgj_taxamt", currentTaxAmt.add(nextTaxAmt)); + + // 移除当前条目 + processAllocEntityCollection.remove(i); + i--; // 调整索引 + } else { + // 如果不存在相同组合,则添加到Map中 + processRateMap.put(key, currentEntry); + } + } + } + + /** + * 将对象转换为BigDecimal类型 + * + * @param obj 待转换对象 + * @return BigDecimal值 + */ + private BigDecimal toBigDecimal(Object obj) { + if (obj == null) { + return BigDecimal.ZERO; + } + + if (obj instanceof BigDecimal) { + return (BigDecimal) obj; + } else if (obj instanceof Number) { + return new BigDecimal(obj.toString()); + } else { + try { + return new BigDecimal(obj.toString()); + } catch (NumberFormatException e) { + return BigDecimal.ZERO; + } + } + } }