From aaa92f87da808cc0d109841e283077297a1680b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E8=B4=B5=E5=BC=BA?= Date: Thu, 17 Jul 2025 11:01:16 +0800 Subject: [PATCH] =?UTF-8?q?=E7=90=86=E8=B4=A2=E7=94=B3=E8=B4=AD=E5=8D=95?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=A4=E4=B8=AA=E5=8A=9F=E8=83=BD=E6=8C=89?= =?UTF-8?q?=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/form/CimFinancialBillPlugin.java | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 main/java/shjh/jhzj7/fi/fi/plugin/form/CimFinancialBillPlugin.java diff --git a/main/java/shjh/jhzj7/fi/fi/plugin/form/CimFinancialBillPlugin.java b/main/java/shjh/jhzj7/fi/fi/plugin/form/CimFinancialBillPlugin.java new file mode 100644 index 0000000..1159c5b --- /dev/null +++ b/main/java/shjh/jhzj7/fi/fi/plugin/form/CimFinancialBillPlugin.java @@ -0,0 +1,119 @@ +package shjh.jhzj7.fi.fi.plugin.form; + +import kd.bos.bill.AbstractBillPlugIn; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.db.DB; +import kd.bos.db.DBRoute; +import kd.bos.form.control.events.ItemClickEvent; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.bos.servicehelper.operation.SaveServiceHelper; +import kd.sdk.plugin.Plugin; + +import java.math.BigDecimal; +import java.util.EventObject; + +/** + * 单据界面插件 + * 理财申购单表单插件 + */ +public class CimFinancialBillPlugin extends AbstractBillPlugIn implements Plugin { + + private static final String DELETE = "delete from t_cim_finsubscribe_v where fentryid=?;"; + + private static final String UPDATE = "update t_cim_finsubscribe set fexpiredate = ?,fterm = ?,fplanamount = ? where fid=?;"; + + @Override + public void registerListener(EventObject e) { + super.registerListener(e); + this.addItemClickListeners("tbmain"); + } + + @Override + public void itemClick(ItemClickEvent evt) { + super.itemClick(evt); + switch (evt.getItemKey()){ + //删除最新估值行 + case "shjh_deletevalue": + this.deleteValue(); + break; + //更新到期日、期限、预计收益金额 + case "shjh_updatedate": + this.updateBillInfo(); + break; + } + } + + private void deleteValue() { + DynamicObject financialBill = BusinessDataServiceHelper.loadSingle(this.getModel().getValue("id"), this.getModel().getDataEntityType().getName()); + if (financialBill !=null){ + // 获取估值分录 + DynamicObjectCollection entryEntity = financialBill.getDynamicObjectCollection("valuationentry"); + if (entryEntity == null || entryEntity.size()<=1) { + this.getView().showTipNotification("无可删除数据!"); + return; + } + DynamicObject maxSeqItem = findMaxSeqItem(entryEntity); + if (maxSeqItem!=null){ + DynamicObject redeemBill = maxSeqItem.getDynamicObject("shjh_shdh"); + if (redeemBill!=null){ + this.getView().showTipNotification("最新估值分录存在已审核赎回单!"); + }else { + entryEntity.remove(maxSeqItem); + DynamicObject newMaxSeqItem = findMaxSeqItem(entryEntity); + if (newMaxSeqItem!=null){ + BigDecimal e_surpcopies = newMaxSeqItem.getBigDecimal("e_surpcopies"); + financialBill.set("surpluscopies",e_surpcopies); + SaveServiceHelper.update(financialBill); + } + DB.update(DBRoute.of("fi"),DELETE,new Object[]{maxSeqItem.getPkValue()}); + this.getView().invokeOperation("refresh"); + } + } + } + + } + + private void updateBillInfo() { + boolean dataChanged = this.getModel().getDataChanged(); + if (dataChanged){ + int update = DB.update(DBRoute.of("fi"), UPDATE, new Object[]{ + this.getModel().getValue("expiredate"), + this.getModel().getValue("term"), + this.getModel().getValue("planamount"), + this.getModel().getValue("id") + }); + if (update==1){ + this.getView().showMessage("已更新到期日、期限、预计收益金额"); + this.getView().invokeOperation("refresh"); + } + } + } + + /** + * 从分录中查找行号最大的记录 + * @param entryEntity 分录集合 + * @return 行号最大的记录,如果没有记录则返回null + */ + private DynamicObject findMaxSeqItem(DynamicObjectCollection entryEntity) { + if (entryEntity == null || entryEntity.isEmpty()) { + return null; + } + + DynamicObject maxSeqItem = null; + int maxSeq = -1; + + for (DynamicObject item : entryEntity) { + int currentSeq = item.getInt("seq"); + if (currentSeq==0){ + throw new RuntimeException("初始行不可删除!"); + } + if (currentSeq > maxSeq) { + maxSeq = currentSeq; + maxSeqItem = item; + } + } + + return maxSeqItem; + } +} \ No newline at end of file