理财批量预提2.0计算逻辑修改
This commit is contained in:
		
							parent
							
								
									48a8d64455
								
							
						
					
					
						commit
						08e591b4fc
					
				|  | @ -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; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
		Loading…
	
		Reference in New Issue