From a056e71046fc335229898eb50ba04513cebbccf8 Mon Sep 17 00:00:00 2001 From: xiaoshi <2272816786@qq.com> Date: Thu, 5 Dec 2024 17:47:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B6=E5=85=A5=E4=B8=8E=E6=94=AF=E5=87=BA?= =?UTF-8?q?=E5=90=88=E5=90=8C=E8=AE=A1=E9=87=8F=E6=A0=A1=E9=AA=8C=E5=8E=BB?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../form/ContractEeasurementBillPlugin.java | 32 +++++ .../InContractMeasurementBillEditPlugin.java | 33 +++++ .../operate/ContractMeasurementValidator.java | 129 ++++++++++++++++++ .../operate/InContractMeasurementOp.java | 22 +++ .../operate/OutContractMeasurementOp.java | 21 +++ 5 files changed, 237 insertions(+) create mode 100644 code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/ContractEeasurementBillPlugin.java create mode 100644 code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/InContractMeasurementBillEditPlugin.java create mode 100644 code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/operate/ContractMeasurementValidator.java create mode 100644 code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/operate/InContractMeasurementOp.java create mode 100644 code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/operate/OutContractMeasurementOp.java diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/ContractEeasurementBillPlugin.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/ContractEeasurementBillPlugin.java new file mode 100644 index 0000000..97ed124 --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/ContractEeasurementBillPlugin.java @@ -0,0 +1,32 @@ +package zcgj.zcdev.zcdev.pr.plugin.form; + +import kd.bos.entity.datamodel.events.ChangeData; +import kd.ec.contract.formplugin.ContractMeasureBillEditPlugin; + +import java.math.BigDecimal; + +public class ContractEeasurementBillPlugin extends ContractMeasureBillEditPlugin { + + @Override + protected void onThisQtyChanged(ChangeData changeData) { + BigDecimal qty = this.defaultZeroBigDecimal((BigDecimal)changeData.getNewValue()); + int rowIndex = changeData.getRowIndex(); + int parentRowIndex = changeData.getParentRowIndex(); + BigDecimal totalqty = (BigDecimal)this.getModel().getValue("totalqty", rowIndex, parentRowIndex); + BigDecimal preQty = (BigDecimal)this.getModel().getValue("preqty", rowIndex, parentRowIndex); + BigDecimal balanceQty = totalqty.subtract(preQty); + if (qty.compareTo(balanceQty) > 0) { +// this.getView().showMessage(String.format(ResManager.loadKDString("本期计量数量不能超过%s(总数量-期初累计计量数量)。", "ContractMeasureBillEditPlugin_4", "ec-contract-formplugin", new Object[0]), balanceQty.intValue())); +// this.getModel().setValue("thisqty", BigDecimal.ZERO, rowIndex, parentRowIndex); + } else { + this.getModel().setValue("lstqty", preQty.add(qty), rowIndex, parentRowIndex); + BigDecimal taxPrice = (BigDecimal)this.getModel().getValue("curtaxprice", rowIndex, parentRowIndex); + BigDecimal amount = taxPrice.multiply(qty); + this.getModel().setValue("thisoftaxmount", amount, rowIndex, parentRowIndex); + if (this.isInContract()) { + this.countPercent(rowIndex, parentRowIndex); + } + + } + } +} diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/InContractMeasurementBillEditPlugin.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/InContractMeasurementBillEditPlugin.java new file mode 100644 index 0000000..4622ccb --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/InContractMeasurementBillEditPlugin.java @@ -0,0 +1,33 @@ +package zcgj.zcdev.zcdev.pr.plugin.form; + +import kd.bos.entity.datamodel.events.ChangeData; +import kd.ec.contract.formplugin.InContractMeasureBillEditPlugin; + +import java.math.BigDecimal; + +public class InContractMeasurementBillEditPlugin extends InContractMeasureBillEditPlugin { + + @Override + protected void onThisQtyChanged(ChangeData changeData) { + BigDecimal qty = this.defaultZeroBigDecimal((BigDecimal)changeData.getNewValue()); + int rowIndex = changeData.getRowIndex(); + int parentRowIndex = changeData.getParentRowIndex(); + BigDecimal totalqty = (BigDecimal)this.getModel().getValue("totalqty", rowIndex, parentRowIndex); + BigDecimal preQty = (BigDecimal)this.getModel().getValue("preqty", rowIndex, parentRowIndex); + BigDecimal balanceQty = totalqty.subtract(preQty); + if (qty.compareTo(balanceQty) > 0) { +// this.getView().showMessage(String.format(ResManager.loadKDString("本期计量数量不能超过%s(总数量-期初累计计量数量)。", "ContractMeasureBillEditPlugin_4", "ec-contract-formplugin", new Object[0]), balanceQty.intValue())); +// this.getModel().setValue("thisqty", BigDecimal.ZERO, rowIndex, parentRowIndex); + } else { + this.getModel().setValue("lstqty", preQty.add(qty), rowIndex, parentRowIndex); + BigDecimal taxPrice = (BigDecimal)this.getModel().getValue("curtaxprice", rowIndex, parentRowIndex); + BigDecimal amount = taxPrice.multiply(qty); + this.getModel().setValue("thisoftaxmount", amount, rowIndex, parentRowIndex); + if (this.isInContract()) { + this.countPercent(rowIndex, parentRowIndex); + } + + } + } + +} diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/operate/ContractMeasurementValidator.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/operate/ContractMeasurementValidator.java new file mode 100644 index 0000000..97d02c3 --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/operate/ContractMeasurementValidator.java @@ -0,0 +1,129 @@ +package zcgj.zcdev.zcdev.pr.plugin.operate; + +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.dataentity.resource.ResManager; +import kd.bos.entity.ExtendedDataEntity; +import kd.bos.orm.query.QFilter; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.bos.servicehelper.QueryServiceHelper; +import kd.ec.basedata.common.enums.BillStatusEnum; +import kd.ec.contract.opplugin.validator.ContractMeasureValidator; + +import java.math.BigDecimal; +import java.util.*; + +public class ContractMeasurementValidator extends ContractMeasureValidator { + + @Override + protected void validateListingQty(Set excludeIds) { + { + ExtendedDataEntity[] dataEntities = this.getDataEntities(); + Set listingIds = new HashSet(16); + Set measureIds = new HashSet(16); + Set repeatListingIds = new HashSet(16); + ExtendedDataEntity[] var6 = dataEntities; + int var7 = dataEntities.length; + + DynamicObject changeListing; + for(int var8 = 0; var8 < var7; ++var8) { + ExtendedDataEntity dataEntity = var6[var8]; + changeListing = dataEntity.getDataEntity(); + if (!excludeIds.contains(changeListing.getLong("id"))) { + measureIds.add(changeListing.getLong("id")); + DynamicObjectCollection modelEntries = changeListing.getDynamicObjectCollection("listmodelentry"); + Iterator var12 = modelEntries.iterator(); + + while(var12.hasNext()) { + DynamicObject modelEntry = (DynamicObject)var12.next(); + DynamicObjectCollection listingEntries = modelEntry.getDynamicObjectCollection("listentry"); + Iterator var15 = listingEntries.iterator(); + + while(var15.hasNext()) { + DynamicObject listingEntry = (DynamicObject)var15.next(); + DynamicObject listing = listingEntry.getDynamicObject("listing"); + if (listing != null && !listingIds.add(listing.getLong("id"))) { + repeatListingIds.add(listing.getLong("id")); + } + } + } + } + } + + listingIds.removeAll(repeatListingIds); + QFilter changeFilter = new QFilter("kapianentry.entryentity.listid", "in", listingIds); + changeFilter.and("billstatus", "=", BillStatusEnum.SUBMIT.getValue()); + DynamicObjectCollection changeListings = QueryServiceHelper.query("ec_inrevision", "kapianentry.entryentity.listid", new QFilter[]{changeFilter}); + Set changedListingIds = new HashSet(16); + Iterator var30 = changeListings.iterator(); + + while(var30.hasNext()) { + changeListing = (DynamicObject)var30.next(); + changedListingIds.add(changeListing.getLong("kapianentry.entryentity.listid")); + } + + QFilter listingFilter = new QFilter("id", "in", listingIds); + DynamicObject[] listings = BusinessDataServiceHelper.load("ec_intreelisting", "id,totalqty", new QFilter[]{listingFilter}); + Map listingQtyBalance = new HashMap(16); + DynamicObject[] var34 = listings; + int var36 = listings.length; + + DynamicObject measureListing; + for(int var38 = 0; var38 < var36; ++var38) { + measureListing = var34[var38]; + listingQtyBalance.put(measureListing.getLong("id"), measureListing.getBigDecimal("totalqty")); + } + + QFilter filter = new QFilter("listmodelentry.listentry.listing", "in", listingIds); + filter.and("billstatus", "in", new String[]{BillStatusEnum.SUBMIT.getValue(), BillStatusEnum.AUDIT.getValue()}); + filter.and("id", "not in", measureIds); + DynamicObjectCollection measureListings = QueryServiceHelper.query("ec_incontractmeasure", "listmodelentry.listentry.listing,listmodelentry.listentry.thisqty", new QFilter[]{filter}); + Iterator var39 = measureListings.iterator(); + + while(var39.hasNext()) { + measureListing = (DynamicObject)var39.next(); + long listingId = measureListing.getLong("listmodelentry.listentry.listing"); + if (listingId != 0L) { + BigDecimal qtyBalance = (BigDecimal)listingQtyBalance.getOrDefault(listingId, BigDecimal.ZERO); + listingQtyBalance.put(listingId, qtyBalance.subtract(measureListing.getBigDecimal("listmodelentry.listentry.thisqty"))); + } + } + + ExtendedDataEntity[] var41 = dataEntities; + int var42 = dataEntities.length; + + for(int var44 = 0; var44 < var42; ++var44) { + ExtendedDataEntity dataEntity = var41[var44]; + DynamicObject bill = dataEntity.getDataEntity(); + if (!excludeIds.contains(bill.getLong("id"))) { + DynamicObjectCollection modelEntries = bill.getDynamicObjectCollection("listmodelentry"); + Iterator var20 = modelEntries.iterator(); + + while(var20.hasNext()) { + DynamicObject modelEntry = (DynamicObject)var20.next(); + DynamicObjectCollection listingEntries = modelEntry.getDynamicObjectCollection("listentry"); + Iterator var23 = listingEntries.iterator(); + + while(var23.hasNext()) { + DynamicObject listingEntry = (DynamicObject)var23.next(); + DynamicObject listing = listingEntry.getDynamicObject("listing"); + if (listing != null) { + if (repeatListingIds.contains(listing.getLong("id"))) { + this.addErrorMessage(dataEntity, String.format(ResManager.loadKDString("本次操作的单据中清单【%s】存在重复,请检查。", "ContractMeasureValidator_2", "ec-contract-opplugin", new Object[0]), listing.getString("name"))); + } else if (changedListingIds.contains(listing.getLong("id"))) { + this.addErrorMessage(dataEntity, String.format(ResManager.loadKDString("清单【%s】正在变更中,请检查。", "ContractMeasureValidator_3", "ec-contract-opplugin", new Object[0]), listing.getString("name"))); + } else { +// BigDecimal thisQty = listingEntry.getBigDecimal("thisqty"); +// if (thisQty != null && thisQty.compareTo(BigDecimal.ZERO) != 0 && thisQty.compareTo((BigDecimal)listingQtyBalance.getOrDefault(listing.getLong("id"), BigDecimal.ZERO)) > 0) { +// this.addErrorMessage(dataEntity, String.format(ResManager.loadKDString("清单【%s】本次计量数量已超剩余可计量数量,请修改。", "ContractMeasureValidator_4", "ec-contract-opplugin", new Object[0]), listing.getString("name"))); +// } + } + } + } + } + } + } + + } + } +} diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/operate/InContractMeasurementOp.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/operate/InContractMeasurementOp.java new file mode 100644 index 0000000..0ee10c9 --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/operate/InContractMeasurementOp.java @@ -0,0 +1,22 @@ +package zcgj.zcdev.zcdev.pr.plugin.operate; + +import kd.bos.entity.plugin.AddValidatorsEventArgs; +import kd.bos.entity.validate.AbstractValidator; +import kd.ec.contract.opplugin.ContractMeasureOp; +import kd.ec.contract.opplugin.validator.ContractMeasureValidator; + +import java.util.List; + +public class InContractMeasurementOp extends ContractMeasureOp { + + @Override + public void onAddValidators(AddValidatorsEventArgs e) { + super.onAddValidators(e); + List validators = e.getValidators(); + // 删除标品校验器 + validators.removeIf(validator -> validator instanceof ContractMeasureValidator); + + // 添加定制二开的校验器(位置放第一位,优先执行) + validators.add(0, new ContractMeasurementValidator()); + } +} diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/operate/OutContractMeasurementOp.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/operate/OutContractMeasurementOp.java new file mode 100644 index 0000000..fa58863 --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/operate/OutContractMeasurementOp.java @@ -0,0 +1,21 @@ +package zcgj.zcdev.zcdev.pr.plugin.operate; + +import kd.bos.entity.plugin.AddValidatorsEventArgs; +import kd.bos.entity.validate.AbstractValidator; +import kd.ec.contract.opplugin.OutContractMeasureOp; +import kd.ec.contract.opplugin.validator.ContractMeasureValidator; +import java.util.List; + +public class OutContractMeasurementOp extends OutContractMeasureOp{ + + @Override + public void onAddValidators(AddValidatorsEventArgs e) { + super.onAddValidators(e); + List validators = e.getValidators(); + // 删除标品校验器 + validators.removeIf(validator -> validator instanceof ContractMeasureValidator); + + // 添加定制二开的校验器(位置放第一位,优先执行) + validators.add(0, new ContractMeasurementValidator()); + } +}