From 08e591b4fc489da256ef9732a65742e922b07aed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E8=B4=B5=E5=BC=BA?= Date: Wed, 9 Jul 2025 15:05:34 +0800 Subject: [PATCH] =?UTF-8?q?=E7=90=86=E8=B4=A2=E6=89=B9=E9=87=8F=E9=A2=84?= =?UTF-8?q?=E6=8F=902.0=E8=AE=A1=E7=AE=97=E9=80=BB=E8=BE=91=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../form/CimIntBillBatchFormPlugin.java | 89 ++++++++++++++++++- 1 file changed, 87 insertions(+), 2 deletions(-) diff --git a/main/java/shjh/jhzj7/fi/fi/plugin/form/CimIntBillBatchFormPlugin.java b/main/java/shjh/jhzj7/fi/fi/plugin/form/CimIntBillBatchFormPlugin.java index 48a8a5d..8986af8 100644 --- a/main/java/shjh/jhzj7/fi/fi/plugin/form/CimIntBillBatchFormPlugin.java +++ b/main/java/shjh/jhzj7/fi/fi/plugin/form/CimIntBillBatchFormPlugin.java @@ -3,10 +3,14 @@ package shjh.jhzj7.fi.fi.plugin.form; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObjectCollection; import kd.bos.form.plugin.AbstractFormPlugin; +import kd.bos.logging.Log; +import kd.bos.logging.LogFactory; import kd.bos.servicehelper.BusinessDataServiceHelper; import kd.sdk.plugin.Plugin; +import shjh.jhzj7.fi.fi.plugin.report.FinancialFormReport; import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.Date; import java.util.EventObject; @@ -14,6 +18,7 @@ import java.util.EventObject; * 理财批量预提表单插件 */ public class CimIntBillBatchFormPlugin extends AbstractFormPlugin implements Plugin { + private final static Log logger = LogFactory.getLog(CimIntBillBatchFormPlugin.class); @Override public void afterBindData(EventObject e) { @@ -40,6 +45,10 @@ public class CimIntBillBatchFormPlugin extends AbstractFormPlugin implements Plu DynamicObjectCollection valuationentry = finsubscribe.getDynamicObjectCollection("valuationentry"); if (valuationentry != null && valuationentry.size() != 0) { + + BigDecimal redProductAmount = this.getRedProductAmount(valuationentry, preintdate); + + DynamicObject targetValuation = null; // 1. 如果只有一条估值数据,直接使用 @@ -74,9 +83,9 @@ public class CimIntBillBatchFormPlugin extends AbstractFormPlugin implements Plu BigDecimal currentSurpcopies = targetValuation.getBigDecimal("e_surpcopies"); if (currentIopv != null && currentSurpcopies != null && iopv != null && buycopies != null) { - // 计算公式:预提收益 = (预提日净值 * 剩余份数) - (购买日净值 * 购买日份数) + // 计算公式:预提收益 = (预提日净值 * 剩余份数) - (购买日净值 * 购买日份数)*差值 BigDecimal preIncome = currentIopv.multiply(currentSurpcopies) - .subtract(iopv.multiply(buycopies)); + .subtract(iopv.multiply(buycopies).multiply(redProductAmount)); // 将计算结果设置到模型 this.getModel().setValue("interestamt", preIncome, i); @@ -92,4 +101,80 @@ public class CimIntBillBatchFormPlugin extends AbstractFormPlugin implements Plu } } } + + + /** + * 计提日最近估值记录获取——(1-赎回份额/赎回日剩余份额)* 所有赎回单 + * @param entry 输入数据集合 + * @param date 目标日期 + * @return 所有符合条件的赎回单的(1-赎回份额/剩余份额)的乘积 + */ + private BigDecimal getRedProductAmount(DynamicObjectCollection entry, Date date) { + // 1. 按估值日期和赎回日期排序 + DynamicObjectCollection sortedEntries = new DynamicObjectCollection(); + sortedEntries.addAll(entry); + + sortedEntries.sort((o1, o2) -> { + // 优先按估值日期排序(从小到大) + Date valDate1 = o1.getDate("e_valuationdate"); + Date valDate2 = o2.getDate("e_valuationdate"); + int compareValDate = valDate1.compareTo(valDate2); + if (compareValDate != 0) { + return compareValDate; + } + + // 估值日期相同时,按赎回日期排序 + Date redDate1 = o1.getDate("shjh_shrq"); + Date redDate2 = o2.getDate("shjh_shrq"); + if (redDate1 == null && redDate2 == null) return 0; + if (redDate1 == null) return -1; // null视为较小值 + if (redDate2 == null) return 1; + return redDate1.compareTo(redDate2); + }); + + // 2. 累乘符合条件的差额,初始值设为1 + BigDecimal product = BigDecimal.ONE; + + for (DynamicObject item : sortedEntries) { + try { + // 检查是否为赎回单(跳过非赎回条目) + DynamicObject shdh = item.getDynamicObject("shjh_shdh"); + if (shdh == null) { + continue; + } + + // 检查估值日期是否 ≤ 目标日期 + Date valDate = item.getDate("e_valuationdate"); + if (valDate == null || valDate.compareTo(date) > 0) { + continue; + } + + Object pkValue = shdh.getPkValue(); + DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(pkValue, "cim_redeem"); + + // 安全获取数值字段 + BigDecimal copies = dynamicObject.getBigDecimal("copies"); // 赎回份额 + BigDecimal remainderCopies = dynamicObject.getBigDecimal("shjh_shrsyfe"); // 赎回日剩余份额 + + if (copies == null || remainderCopies == null || remainderCopies.compareTo(BigDecimal.ZERO) == 0) { + continue; // 跳过无效数据 + } + + // 计算 (1 - 赎回份额/剩余日份额) + BigDecimal ratio = copies.divide(remainderCopies, 10, RoundingMode.HALF_UP); + BigDecimal difference = BigDecimal.ONE.subtract(ratio); + + // 累乘 + product = product.multiply(difference).setScale(10, RoundingMode.HALF_UP); + + } catch (Exception e) { + // 记录错误并跳过当前条目 + logger.error("处理赎回单数据出错: " + e.getMessage(), e); + continue; + } + } + + return product; + } + } \ No newline at end of file