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); + } + } + } + } +}