From 64b871a69f5416c9197dab168165b56fc8bdf6bf Mon Sep 17 00:00:00 2001 From: weiyunlong Date: Tue, 17 Jun 2025 17:43:45 +0800 Subject: [PATCH] =?UTF-8?q?=E7=82=B9=E5=87=BB=E4=BC=B0=E5=80=BC:=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E4=BC=B0=E5=80=BC=E9=A1=B5=E9=9D=A2=E6=8F=92=E4=BB=B6?= =?UTF-8?q?2=E3=80=81=E8=8B=A5=E5=8D=95=E6=8D=AE=E3=80=90=E8=B5=8E?= =?UTF-8?q?=E5=9B=9E=E6=96=B9=E5=BC=8F=E3=80=91=3D=E4=BB=BD=E9=A2=9D?= =?UTF-8?q?=E8=B5=8E=E5=9B=9E=EF=BC=8C=E4=B8=94=E3=80=90=E7=8E=B0=E9=87=91?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=B1=BB=E4=BA=A7=E5=93=81=E3=80=91=3D=20?= =?UTF-8?q?=E6=98=AF=EF=BC=8C=E8=B7=B3=E8=BF=87=E6=A0=87=E5=93=81=E4=BB=BD?= =?UTF-8?q?=E9=A2=9D=E6=A0=A1=E9=AA=8C=EF=BC=88=E5=8E=9F=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=EF=BC=9A=E4=BB=BD=E9=A2=9D=E4=B8=8D=E5=85=81=E8=AE=B8=E5=A4=A7?= =?UTF-8?q?=E4=BA=8E=E7=94=B3=E8=B4=AD=E4=BB=BD=E9=A2=9D=EF=BC=89=EF=BC=9B?= =?UTF-8?q?=203=E3=80=81=E8=8B=A5=E5=8D=95=E6=8D=AE=E3=80=90=E8=B5=8E?= =?UTF-8?q?=E5=9B=9E=E6=96=B9=E5=BC=8F=E3=80=91=3D=E4=BB=BD=E9=A2=9D?= =?UTF-8?q?=E8=B5=8E=E5=9B=9E=EF=BC=8C=E4=B8=94=E3=80=90=E7=8E=B0=E9=87=91?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=B1=BB=E4=BA=A7=E5=93=81=E3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= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../form/ValutionUpdateEditFormPlugin.java | 276 ++++++++++++++++++ .../operate/ValuateUpdateOperation.java | 41 +++ 2 files changed, 317 insertions(+) create mode 100644 main/java/shjh/jhzj7/fi/fi/plugin/form/ValutionUpdateEditFormPlugin.java create mode 100644 main/java/shjh/jhzj7/fi/fi/plugin/operate/ValuateUpdateOperation.java diff --git a/main/java/shjh/jhzj7/fi/fi/plugin/form/ValutionUpdateEditFormPlugin.java b/main/java/shjh/jhzj7/fi/fi/plugin/form/ValutionUpdateEditFormPlugin.java new file mode 100644 index 0000000..276e443 --- /dev/null +++ b/main/java/shjh/jhzj7/fi/fi/plugin/form/ValutionUpdateEditFormPlugin.java @@ -0,0 +1,276 @@ +package shjh.jhzj7.fi.fi.plugin.form; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.EventObject; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.dataentity.resource.ResManager; +import kd.bos.entity.EntityMetadataCache; +import kd.bos.entity.datamodel.ListSelectedRowCollection; +import kd.bos.entity.datamodel.events.PropertyChangedArgs; +import kd.bos.entity.property.BasedataProp; +import kd.bos.entity.property.DecimalProp; +import kd.bos.form.control.Control; +import kd.bos.form.control.events.BeforeClickEvent; +import kd.bos.form.field.BasedataEdit; +import kd.bos.form.field.DecimalEdit; +import kd.bos.form.plugin.AbstractFormPlugin; +import kd.bos.list.BillList; +import kd.bos.orm.query.QFilter; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.bos.servicehelper.QueryServiceHelper; +import kd.bos.servicehelper.operation.SaveServiceHelper; +import kd.tmc.cim.common.enums.RedeemWayEnum; +import kd.tmc.fbp.common.helper.TmcDataServiceHelper; +import kd.tmc.fbp.common.helper.TmcViewInputHelper; +import kd.tmc.fbp.common.util.EmptyUtil; + +public class ValutionUpdateEditFormPlugin extends AbstractFormPlugin { + public ValutionUpdateEditFormPlugin() { + } + + public void registerListener(EventObject e) { + super.registerListener(e); + this.addClickListeners(new String[]{"btnok"}); + } + + public void afterCreateNewData(EventObject e) { + super.afterCreateNewData(e); + Map paraMap = this.getView().getFormShowParameter().getCustomParams(); + Object currencyObject = paraMap.get("currency"); + this.getModel().setValue("valuationcurrency", currencyObject); + this.getModel().setValue("redeemway", paraMap.get("redeemway")); + this.getModel().setValue("valuation", paraMap.get("e_valuation")); + this.getModel().setValue("surpluscopies", paraMap.get("e_surpcopies")); + this.getModel().setValue("iopv", paraMap.get("e_iopv")); + } + + @Override + public void afterBindData(EventObject e) { + super.afterBindData(e); + + iopvChanged(); + } + + /** + * 若单据【赎回方式】=份额赎回,且【现金管理类产品】= 是,不允许编辑“单位净值”,且【份数】必填; + */ + private void iopvChanged() { + this.getView().getParentView().getModel(); + BillList billList = this.getView().getParentView().getControl("billlistap"); + //获取列表选中行 + ListSelectedRowCollection selectedRows = billList.getSelectedRows(); + //获取ID + Object[] primaryKeyValues = selectedRows.getPrimaryKeyValues(); + if (primaryKeyValues.length > 0) { + Long primaryKeyValue = (Long)primaryKeyValues[0]; + DynamicObject cimFinsubscribe = BusinessDataServiceHelper.loadSingle(primaryKeyValue, "cim_finsubscribe"); + if (null != cimFinsubscribe) { + String xjglcp = cimFinsubscribe.getString("shjh_xjglcp"); + String redeemway = cimFinsubscribe.getString("redeemway"); + DecimalEdit surpluscopies = this.getView().getControl("surpluscopies"); + DecimalProp tp = (DecimalProp) surpluscopies.getProperty(); + //3、若单据【赎回方式】=份额赎回,且【现金管理类产品】= 是,不允许编辑“单位净值”,且【份数】必填; + if ("1".equals(xjglcp) && "copies_redeem".equals(redeemway)) { + this.getView().setEnable(false,"iopv");//锁定"单位净值" + // 获取份数控件 + surpluscopies.setMustInput(true);//【份数】必填 + tp.setMustInput(true); + }else { + this.getView().setEnable(true,"iopv");//解锁"单位净值" + surpluscopies.setMustInput(false);//【份数】非必填 + tp.setMustInput(false); + } + } + } + } + + public void propertyChanged(PropertyChangedArgs e) { + switch (e.getProperty().getName()) { + case "valuation": + this.calOpposideAmt("valuation", "iopv"); + break; + case "iopv": + this.calOpposideAmt("iopv", "valuation"); + break; + case "surpluscopies": + BigDecimal surpluscopies = (BigDecimal) this.getModel().getValue("surpluscopies"); + BigDecimal iopv = (BigDecimal)this.getModel().getValue("iopv"); + this.getView().getModel().setValue("valuation",surpluscopies.multiply(iopv));//4、修改份数后,市值=剩余份额*单位净值; + this.getView().updateView("valuation"); + break; + } + iopvChanged(); + } + + public void beforeClick(BeforeClickEvent evt) { + Control source = (Control)evt.getSource(); + switch (source.getKey()) { + case "btnok": + BigDecimal surpluscopies = (BigDecimal)this.getView().getModel().getValue("surpluscopies"); + this.getView().getParentView().getModel(); + BillList billList = this.getView().getParentView().getControl("billlistap"); + //获取列表选中行 + ListSelectedRowCollection selectedRows = billList.getSelectedRows(); + //获取ID + Object[] primaryKeyValues = selectedRows.getPrimaryKeyValues(); + if (primaryKeyValues.length > 0) { + Long primaryKeyValue = (Long)primaryKeyValues[0]; + DynamicObject cimFinsubscribe = BusinessDataServiceHelper.loadSingle(primaryKeyValue, "cim_finsubscribe"); + if (null != cimFinsubscribe) { + cimFinsubscribe.set("surpluscopies", surpluscopies); + SaveServiceHelper.save(new DynamicObject[]{cimFinsubscribe}); + } + } + + + String redeemWay = (String)this.getModel().getValue("redeemway"); + if (!RedeemWayEnum.isCopiesRedeem(redeemWay)) { + return; + } else { + BigDecimal valuation = (BigDecimal) Optional.ofNullable((BigDecimal)this.getModel().getValue("valuation")).orElse(BigDecimal.ZERO); + BigDecimal ecopies = (BigDecimal)Optional.ofNullable((BigDecimal)this.getModel().getValue("surpluscopies")).orElse(BigDecimal.ZERO); + BigDecimal eiopv = (BigDecimal)Optional.ofNullable((BigDecimal)this.getModel().getValue("iopv")).orElse(BigDecimal.ZERO); + Integer scale = (Integer)Optional.ofNullable((DynamicObject)this.getModel().getValue("valuationcurrency")).map((r) -> { + return r.getInt("amtprecision"); + }).orElse(2); + if (eiopv.multiply(ecopies).setScale(scale, 4).compareTo(valuation) != 0) { + evt.setCancel(true); + this.getView().showTipNotification(ResManager.loadKDString("市值应等于剩余份数乘以单位净值。", "ValuationUpdateEditPlugin_1", "tmc-cim-formplugin", new Object[0])); + return; + } else { + Object finsubId = this.getView().getFormShowParameter().getCustomParam("ids"); + DynamicObject finsubDyn = QueryServiceHelper.queryOne("cim_finsubscribe", "buycopies", new QFilter[]{new QFilter("id", "=", finsubId)}); + if (EmptyUtil.isNoEmpty(finsubDyn) && ecopies.compareTo(finsubDyn.getBigDecimal("buycopies")) > 0) { +// evt.setCancel(true); +// this.getView().showTipNotification(ResManager.loadKDString("剩余份数不能大于申购单的购买份数。", "ValuationUpdateEditPlugin_2", "tmc-cim-formplugin", new Object[0])); +// return; + } else if (valuation.compareTo(BigDecimal.valueOf(Math.pow(10.0, 13.0))) > 0) { + evt.setCancel(true); + this.getView().showTipNotification(ResManager.loadKDString("市值过大,请检查。", "ValuationUpdateEditPlugin_3", "tmc-cim-formplugin", new Object[0])); + return; + } + } + } + default: + } + } + + public void click(EventObject evt) { + super.click(evt); + Control c = (Control)evt.getSource(); + String key = c.getKey().toLowerCase(); + if ("btnok".equals(key)) { + Date valuationDate = (Date)this.getModel().getValue("valuationdate"); + Object valuation = this.getModel().getValue("valuation"); + Object ecopies = this.getModel().getValue("surpluscopies"); + BigDecimal eiopv = (BigDecimal)this.getModel().getValue("iopv"); + Object finsubId = this.getView().getFormShowParameter().getCustomParam("ids"); + DynamicObject[] bills = TmcDataServiceHelper.load(Collections.singletonList(finsubId).toArray(), EntityMetadataCache.getDataEntityType("cim_finsubscribe")); + DynamicObject[] var10 = bills; + int var11 = bills.length; + + for(int var12 = 0; var12 < var11; ++var12) { + DynamicObject bill = var10[var12]; + DynamicObjectCollection valuationEntries = bill.getDynamicObjectCollection("valuationentry"); + if (EmptyUtil.isEmpty(valuationEntries)) { + DynamicObject newEntry = valuationEntries.addNew(); + newEntry.set("e_valuationdate", valuationDate); + newEntry.set("e_valuation", valuation); + newEntry.set("e_surpcopies", ecopies); + newEntry.set("e_iopv", eiopv); + newEntry.set("seq", 0); + } else { + boolean isReSort = false; + int index = -1; + + int i; + DynamicObject entry; + for(i = 0; i < valuationEntries.size(); ++i) { + entry = (DynamicObject)valuationEntries.get(i); + int compare = valuationDate.compareTo((Date)entry.get("e_valuationdate")); + if (compare == 0) { + entry.set("e_valuation", valuation); + entry.set("e_surpcopies", ecopies); + entry.set("e_iopv", eiopv); + break; + } + + DynamicObject newEntry; + if (compare < 0) { + newEntry = (DynamicObject)valuationEntries.getDynamicObjectType().createInstance(); + newEntry.set("e_valuationdate", valuationDate); + newEntry.set("e_valuation", valuation); + newEntry.set("e_surpcopies", ecopies); + newEntry.set("e_iopv", eiopv); + valuationEntries.add(i, newEntry); + isReSort = true; + index = i; + break; + } + + if (i == valuationEntries.size() - 1) { + newEntry = valuationEntries.addNew(); + newEntry.set("e_valuationdate", valuationDate); + newEntry.set("e_valuation", valuation); + newEntry.set("e_surpcopies", ecopies); + newEntry.set("e_iopv", eiopv); + newEntry.set("seq", i); + } + } + + if (isReSort) { + for(i = index; i < valuationEntries.size(); ++i) { + entry = (DynamicObject)valuationEntries.get(i); + entry.set("seq", i); + } + } + } + + List entryList = (List)valuationEntries.stream().sorted(Comparator.comparing((r) -> { + return r.getDate("e_valuationdate"); + }, Comparator.reverseOrder())).collect(Collectors.toList()); + if (EmptyUtil.isNoEmpty(entryList)) { + eiopv = ((DynamicObject)entryList.get(0)).getBigDecimal("e_iopv"); + } + + bill.set("futureamount", bill.getBigDecimal("surpluscopies").multiply(eiopv.subtract(bill.getBigDecimal("iopv")))); + } + + TmcDataServiceHelper.save(bills); + Map returnData = new HashMap(); + returnData.put("success", Boolean.TRUE); + this.getView().returnDataToParent(returnData); + this.getView().close(); + } + + } + + private void calOpposideAmt(String currField, String opposideField) { + String redeemWay = (String)this.getModel().getValue("redeemway"); + if (RedeemWayEnum.isCopiesRedeem(redeemWay)) { + BigDecimal amount = (BigDecimal)Optional.ofNullable((BigDecimal)this.getModel().getValue("valuation")).orElse(BigDecimal.ZERO); + BigDecimal copies = (BigDecimal)Optional.ofNullable((BigDecimal)this.getModel().getValue("surpluscopies")).orElse(BigDecimal.ZERO); + BigDecimal iopv = (BigDecimal)Optional.ofNullable((BigDecimal)this.getModel().getValue("iopv")).orElse(BigDecimal.ZERO); + BigDecimal oppSide = BigDecimal.ZERO; + if ("valuation".equals(currField) && EmptyUtil.isNoEmpty(copies)) { + oppSide = amount.divide(copies, 10, RoundingMode.HALF_UP); + } + + if ("iopv".equals(currField)) { + oppSide = iopv.multiply(copies); + } + + TmcViewInputHelper.setValWithoutPropChgEvt(this.getView(), this.getModel(), opposideField, oppSide); + } + } +} diff --git a/main/java/shjh/jhzj7/fi/fi/plugin/operate/ValuateUpdateOperation.java b/main/java/shjh/jhzj7/fi/fi/plugin/operate/ValuateUpdateOperation.java new file mode 100644 index 0000000..eb16b40 --- /dev/null +++ b/main/java/shjh/jhzj7/fi/fi/plugin/operate/ValuateUpdateOperation.java @@ -0,0 +1,41 @@ +package shjh.jhzj7.fi.fi.plugin.operate; + +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.entity.plugin.AbstractOperationServicePlugIn; +import kd.bos.entity.plugin.args.BeforeOperationArgs; +import kd.bos.orm.query.QCP; +import kd.bos.orm.query.QFilter; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.sdk.plugin.Plugin; + +/** + * 理财申购 + * cim_finsubscribe + */ +public class ValuateUpdateOperation extends AbstractOperationServicePlugIn implements Plugin { + + @Override + public void beforeExecuteOperationTransaction(BeforeOperationArgs e) { + super.beforeExecuteOperationTransaction(e); + String eok = e.getOperationKey(); + //估值 + if("valuateupdate".equals(eok)){ + DynamicObject[] dos = e.getDataEntities(); + DynamicObject prinfo; + for (int i = 0; i < dos.length; i++) { + prinfo = BusinessDataServiceHelper.loadSingle(dos[i].getPkValue(), dos[i].getDataEntityType().getName()); + //1、点击【估值】时,若申购单下游存在暂存、已提交的赎回单,提醒报错:“下游存在待审批的赎回单据,请删除或审批后再进行估值”; + //cim_redeem + QFilter q1 = new QFilter("finbillno.id", QCP.equals, prinfo.getLong("id")); + QFilter q2 = new QFilter("billstatus", QCP.equals, "A");//暂存 + QFilter q3 = new QFilter("billstatus", QCP.equals, "B");//已提交 + q1 = q1.and(q2.or(q3)); + DynamicObject cimRedeem = BusinessDataServiceHelper.loadSingle("cim_redeem", q1.toArray()); + if (null != cimRedeem) { + e.setCancelMessage("下游存在待审批的赎回单据,请删除或审批后再进行估值"); + e.setCancel(true); + } + } + } + } +}