From 0ec2c7e88583e89cebcfa9395348dbb4f8c6cddb 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 14:28:26 +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=E6=A0=A1=E9=AA=8C=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../formplugin/ConNoTextBillFromPlugin.java | 65 +++++++++------ .../recon/validator/ConNoTextValidator.java | 82 +++++++++++++++++++ 2 files changed, 120 insertions(+), 27 deletions(-) create mode 100644 main/java/shkd/repc/recon/validator/ConNoTextValidator.java diff --git a/main/java/shkd/repc/recon/formplugin/ConNoTextBillFromPlugin.java b/main/java/shkd/repc/recon/formplugin/ConNoTextBillFromPlugin.java index ad9a30b..3da67a5 100644 --- a/main/java/shkd/repc/recon/formplugin/ConNoTextBillFromPlugin.java +++ b/main/java/shkd/repc/recon/formplugin/ConNoTextBillFromPlugin.java @@ -13,13 +13,11 @@ 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; +import java.util.*; /** * 动态表单插件 - * 【费用登记】- + * 【费用登记】-采购计划F7过滤 */ public class ConNoTextBillFromPlugin extends AbstractFormPlugin implements Plugin, BeforeF7SelectListener { @@ -34,37 +32,50 @@ public class ConNoTextBillFromPlugin extends AbstractFormPlugin implements Plugi @Override public void beforeF7Select(BeforeF7SelectEvent evt) { ListShowParameter formShowParameter = (ListShowParameter) evt.getFormShowParameter(); - ArrayList canSeeDataId = new ArrayList<>(); - //查找所有已审核采购需求数据 + List 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]; + String orgName = org.getString("name"); + + // 查找所有已审核的采购需求数据(单据状态 = "C") + QFilter statusFilter = new QFilter("billstatus", QCP.equals, "C"); + QFilter orgFilter = new QFilter("org.name", QCP.equals, orgName); + DynamicObject[] settlePlanBills = BusinessDataServiceHelper.load("recon_settleplanbill", "id,bill,qeug_applyamount", statusFilter.and(orgFilter).toArray()); + + // 若无数据,直接返回 + if (settlePlanBills == null || settlePlanBills.length == 0) { + return; + } + + // 遍历所有采购需求数据 + for (DynamicObject settlePlanBill : settlePlanBills) { 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){ + + // 查询当前采购需求的所有相关费用登记 + QFilter refFilter = new QFilter("qeug_refbillfield.id", QCP.equals, id); + DynamicObject[] conNoTextBills = BusinessDataServiceHelper.load("recon_connotextbill", "id,oriamt", refFilter.toArray()); + + // 计算所有已使用金额 + BigDecimal totalUsedAmount = Arrays.stream(conNoTextBills) + .map(bill -> bill.getBigDecimal("oriamt")) + .reduce(BigDecimal.ZERO, BigDecimal::add); + + // 若申请金额大于已使用金额,则允许选择 + if (applyAmount.compareTo(totalUsedAmount) > 0) { canSeeDataId.add(id); } } - List qFilters = new ArrayList<>(); - qFilters.add(new QFilter("id", QCP.in, canSeeDataId)); - formShowParameter.getListFilterParameter().setQFilters(qFilters); + + // 仅当有可用数据时,才设置过滤条件 + if (!canSeeDataId.isEmpty()) { + List qFilters = Collections.singletonList(new QFilter("id", QCP.in, canSeeDataId)); + formShowParameter.getListFilterParameter().setQFilters(qFilters); + } } + } \ No newline at end of file diff --git a/main/java/shkd/repc/recon/validator/ConNoTextValidator.java b/main/java/shkd/repc/recon/validator/ConNoTextValidator.java new file mode 100644 index 0000000..fc4e425 --- /dev/null +++ b/main/java/shkd/repc/recon/validator/ConNoTextValidator.java @@ -0,0 +1,82 @@ +package shkd.repc.recon.validator; + +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.entity.ExtendedDataEntity; +import kd.bos.entity.validate.AbstractValidator; +import kd.bos.form.plugin.AbstractFormPlugin; +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; + +/** + * 动态表单插件 + */ +public class ConNoTextValidator extends AbstractValidator { + + @Override + public void validate() { + ExtendedDataEntity[] dataEntities = this.getDataEntities(); + if (dataEntities == null || dataEntities.length == 0) { + return; + } + + for (ExtendedDataEntity dataEntity : dataEntities) { + if (dataEntity == null) { + continue; + } + + DynamicObject bill = dataEntity.getDataEntity(); + DynamicObject currentBill = BusinessDataServiceHelper.loadSingle(bill.getLong("id"), "recon_connotextbill"); + + if (currentBill == null) { + continue; + } + + DynamicObject refBill = currentBill.getDynamicObject("qeug_refbillfield"); + if (refBill == null) { + continue; + } + DynamicObject settlePlanBill = BusinessDataServiceHelper.loadSingle(refBill.getLong("id"), "recon_settleplanbill"); + // 获取申请总额 + BigDecimal applyAmount = settlePlanBill.getBigDecimal("qeug_applyamount"); + + // 查找已占用金额的其他单据 + QFilter filter = new QFilter("qeug_refbillfield.id", QCP.equals, refBill.getLong("id")); + DynamicObject[] relatedBills = BusinessDataServiceHelper.load("recon_connotextbill", "id, oriamt, billno", filter.toArray()); + + // 计算占用金额,并收集提示信息 + BigDecimal occupationAmount = BigDecimal.ZERO; + StringBuilder message = new StringBuilder(); + + for (DynamicObject otherBill : relatedBills) { + if (otherBill.getLong("id") == currentBill.getLong("id")) { + continue; // 跳过当前单据 + } + + BigDecimal otherOriAmt = otherBill.getBigDecimal("oriamt"); + occupationAmount = occupationAmount.add(otherOriAmt); + message.append("【") + .append(otherBill.getString("billno")) + .append("】已占用该采购计划申请金额: ") + .append(otherOriAmt.setScale(2).toPlainString()) + .append("\n"); + } + + // 计算超额情况 + BigDecimal currentOriAmt = currentBill.getBigDecimal("oriamt"); + BigDecimal excessAmount = currentOriAmt.add(occupationAmount).subtract(applyAmount); + + if (excessAmount.compareTo(BigDecimal.ZERO) > 0) { + message.append("当前单据金额: ").append(currentOriAmt.setScale(2).toPlainString()) + .append(",累计占用金额: ").append(occupationAmount.setScale(2).toPlainString()) + .append(",超出申请总额: ").append(applyAmount.setScale(2).toPlainString()) + .append("\n"); + this.addErrorMessage(dataEntity, message.toString()); + } + } + } +} \ No newline at end of file