批量预提单改造
This commit is contained in:
parent
bb6bbae726
commit
e72b378a09
|
|
@ -0,0 +1,95 @@
|
|||
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.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.sdk.plugin.Plugin;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.EventObject;
|
||||
|
||||
/**
|
||||
* 理财批量预提表单插件
|
||||
*/
|
||||
public class CimIntBillBatchFormPlugin extends AbstractFormPlugin implements Plugin {
|
||||
|
||||
@Override
|
||||
public void afterBindData(EventObject e) {
|
||||
super.afterBindData(e);
|
||||
if ("A".equals((String) this.getModel().getValue("billstatus"))) {
|
||||
DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("entry");
|
||||
if (entryEntity != null && entryEntity.size() != 0) {
|
||||
for (int i = 0; i < entryEntity.size(); i++) {
|
||||
// 申购单id
|
||||
long id = entryEntity.get(i).getLong("finbillid");
|
||||
if (id != 0L) {
|
||||
DynamicObject finsubscribe = BusinessDataServiceHelper.loadSingle(id, "cim_finsubscribe");
|
||||
if (finsubscribe != null) {
|
||||
String cashManagementProducts = finsubscribe.getString("shjh_xjglcp");
|
||||
this.getModel().setValue("shjh_amountcontrl", cashManagementProducts, i);
|
||||
if ("1".equals(cashManagementProducts)) {
|
||||
// 预提日期
|
||||
Date preintdate = (Date) this.getModel().getValue("preintdate");
|
||||
if (preintdate != null) {
|
||||
// 表头购买日净值
|
||||
BigDecimal iopv = finsubscribe.getBigDecimal("iopv");
|
||||
// 表头购买日份数
|
||||
BigDecimal buycopies = finsubscribe.getBigDecimal("buycopies");
|
||||
DynamicObjectCollection valuationentry = finsubscribe.getDynamicObjectCollection("valuationentry");
|
||||
|
||||
if (valuationentry != null && valuationentry.size() != 0) {
|
||||
DynamicObject targetValuation = null;
|
||||
|
||||
// 1. 如果只有一条估值数据,直接使用
|
||||
if (valuationentry.size() == 1) {
|
||||
targetValuation = valuationentry.get(0);
|
||||
}
|
||||
// 2. 如果有多条,找到离预提日期最近的估值数据
|
||||
else {
|
||||
// 初始化最近日期和最小时间差
|
||||
long minDiff = Long.MAX_VALUE;
|
||||
|
||||
for (int j = 0; j < valuationentry.size(); j++) {
|
||||
DynamicObject valuation = valuationentry.get(j);
|
||||
Date valuationDate = valuation.getDate("e_valuationdate");
|
||||
|
||||
if (valuationDate != null) {
|
||||
// 计算时间差(绝对值)
|
||||
long diff = Math.abs(valuationDate.getTime() - preintdate.getTime());
|
||||
|
||||
// 如果找到更接近的日期,更新目标数据
|
||||
if (diff < minDiff) {
|
||||
minDiff = diff;
|
||||
targetValuation = valuation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 计算本次预算预提收益
|
||||
if (targetValuation != null) {
|
||||
BigDecimal currentIopv = targetValuation.getBigDecimal("e_iopv");
|
||||
BigDecimal currentSurpcopies = targetValuation.getBigDecimal("e_surpcopies");
|
||||
|
||||
if (currentIopv != null && currentSurpcopies != null && iopv != null && buycopies != null) {
|
||||
// 计算公式:预提收益 = (预提日净值 * 剩余份数) - (购买日净值 * 购买日份数)
|
||||
BigDecimal preIncome = currentIopv.multiply(currentSurpcopies)
|
||||
.subtract(iopv.multiply(buycopies));
|
||||
|
||||
// 将计算结果设置到模型
|
||||
this.getModel().setValue("interestamt", preIncome, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.getView().invokeOperation("save");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue