赎回功能

This commit is contained in:
李贵强 2025-06-30 16:57:48 +08:00
parent 79e973134a
commit f1a2bec1bc
7 changed files with 681 additions and 15 deletions

View File

@ -49,7 +49,7 @@ public class RedeemBillExtendEditPlugin extends RedeemBillEdit {
return;
}
//this.getModel().setValue("surpluscopies", surplusCopies.subtract(copies));
this.getModel().setValue("surpluscopies", shrsyfe.subtract(copies));
}
}

View File

@ -82,21 +82,20 @@ public class RedeemFormPlugin extends AbstractFormPlugin {
@Override
public void afterBindData(EventObject e) {
super.afterBindData(e);
//新增不可编辑字段是否现金管理类根据理财申购单表头字段带出
DynamicObject finbillno = (DynamicObject)this.getView().getModel().getValue("finbillno");//产品编号
if (null != finbillno) {
// 理财申购单
QFilter qFilter = new QFilter("id", QCP.equals, finbillno.getLong("id"));
DynamicObject cimFinsubscribe = BusinessDataServiceHelper.loadSingle("cim_finsubscribe", qFilter.toArray());
if (null != cimFinsubscribe) {
this.getView().getModel().setValue("shjh_xjglcp",cimFinsubscribe.getString("shjh_xjglcp"));
this.getView().updateView("shjh_xjglcp");
//字段赎回份数默认为赎回日期剩余份额可手工修改
this.getView().getModel().setValue("copies",cimFinsubscribe.getBigDecimal("surpluscopies"));
if ("A".equals((String)this.getModel().getValue("billstatus"))){
//新增不可编辑字段是否现金管理类根据理财申购单表头字段带出
DynamicObject finbillno = (DynamicObject)this.getView().getModel().getValue("finbillno");//产品编号
if (null != finbillno) {
// 理财申购单
QFilter qFilter = new QFilter("id", QCP.equals, finbillno.getLong("id"));
DynamicObject cimFinsubscribe = BusinessDataServiceHelper.loadSingle("cim_finsubscribe", qFilter.toArray());
if (null != cimFinsubscribe) {
this.getView().getModel().setValue("shjh_xjglcp",cimFinsubscribe.getString("shjh_xjglcp"));
this.getView().updateView("shjh_xjglcp");
//字段赎回份数默认为赎回日期剩余份额可手工修改
this.getView().getModel().setValue("copies",cimFinsubscribe.getBigDecimal("surpluscopies"));
}
}
}
}
}

View File

@ -0,0 +1,30 @@
package shjh.jhzj7.fi.fi.plugin.operate;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.args.AfterOperationArgs;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.sdk.plugin.Plugin;
import kd.tmc.cim.opplugin.redeem.RedeemBillAuditOp;
import kd.tmc.fbp.business.opservice.ITmcBizOppService;
import java.math.BigDecimal;
import java.util.Date;
/**
* 单据操作插件
* 理财赎回-审核后
* 赎回单审批后新增理财申购单估值行并触发剩余份额更新逻辑1.3
* 需改动标品的反写逻辑
*/
public class RedeemBillAuditOperation extends RedeemBillAuditOp implements Plugin {
@Override
public ITmcBizOppService getBizOppService() {
return new RedeemBillAuditServiceExt();
}
}

View File

@ -0,0 +1,240 @@
package shjh.jhzj7.fi.fi.plugin.operate;
import kd.bos.dataentity.OperateOption;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.exception.KDException;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.MetadataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.tmc.cim.bussiness.opservice.redeem.RedeemBillAuditService;
import kd.tmc.cim.common.enums.CimEntityEnum;
import kd.tmc.cim.common.enums.FinServiceStatusEnum;
import kd.tmc.cim.common.enums.RedeemWayEnum;
import kd.tmc.cim.common.enums.TradeChannelEnum;
import kd.tmc.cim.common.helper.RevenueCalcHelper;
import kd.tmc.fbp.common.helper.TmcBotpHelper;
import kd.tmc.fbp.common.helper.TmcDataServiceHelper;
import kd.tmc.fbp.common.helper.TmcOperateServiceHelper;
import kd.tmc.fbp.common.util.EmptyUtil;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
public class RedeemBillAuditServiceExt extends RedeemBillAuditService {
private static final Log logger = LogFactory.getLog(RedeemBillAuditServiceExt.class);
@Override
public void process(DynamicObject[] dataEntities) throws KDException {
List<Object> auditID = new ArrayList();
DynamicObject[] var3 = dataEntities;
int var4 = dataEntities.length;
for (int var5 = 0; var5 < var4; ++var5) {
DynamicObject dataEntitie = var3[var5];
DynamicObject finBillF7 = dataEntitie.getDynamicObject("finbillno");
if (EmptyUtil.isNoEmpty(finBillF7)) {
TmcBotpHelper.saveRelation(CimEntityEnum.cim_finsubscribe.getValue(), (Long) finBillF7.getPkValue(), CimEntityEnum.cim_redeem.getValue(), (Long) dataEntitie.getPkValue());
}
DynamicObject redeemApply = dataEntitie.getDynamicObject("redeemapply");
if (EmptyUtil.isNoEmpty(redeemApply)) {
TmcBotpHelper.saveRelation("cim_finapply", (Long) redeemApply.getPkValue(), CimEntityEnum.cim_redeem.getValue(), (Long) dataEntitie.getPkValue());
}
DynamicObject finSubscribe = TmcDataServiceHelper.loadSingle(finBillF7.getPkValue(), CimEntityEnum.cim_finsubscribe.getValue());
String tradeChannel = dataEntitie.getString("tradechannel");
if (!TradeChannelEnum.ONLINE.getValue().equals(tradeChannel)) {
this.writeBackFinBill(finSubscribe, dataEntitie);
}
boolean isRevenue = dataEntitie.getBoolean("isrevenue");
boolean isPushRev = dataEntitie.getBoolean("ispushrev");
if (isRevenue && isPushRev) {
QFilter qFilter = new QFilter("redeemid", "=", dataEntitie.getPkValue());
DynamicObject revenueBill = TmcDataServiceHelper.loadSingle(CimEntityEnum.cim_revenue.getValue(), "id", qFilter.toArray());
if (EmptyUtil.isNoEmpty(revenueBill) && (!TradeChannelEnum.ONLINE.getValue().equals(tradeChannel) || dataEntitie.getBoolean("isrenewal"))) {
auditID.add(revenueBill.getPkValue());
}
}
boolean isRenewal = dataEntitie.getBoolean("isrenewal");
if (isRenewal) {
this.copyFinSubscribe(finSubscribe, dataEntitie);
if (TradeChannelEnum.ONLINE.getValue().equals(tradeChannel)) {
this.writeBackFinBill(finSubscribe, dataEntitie);
}
}
}
if (auditID.size() > 0) {
this.updateRealRevenueAmt(dataEntities, auditID);
OperateOption operateOption = OperateOption.create();
operateOption.setVariableValue("redeemAudit", "true");
TmcOperateServiceHelper.execOperate("audit", CimEntityEnum.cim_revenue.getValue(), auditID.toArray(), operateOption);
}
}
private void writeBackFinBill(DynamicObject finSubscribe, DynamicObject dataEntitie) {
String redeemWay = dataEntitie.getString("redeemway");
finSubscribe.set("finservicestatus", FinServiceStatusEnum.subscribe_part.getValue());
BigDecimal redeemCopies;
BigDecimal finCopies;
BigDecimal surplusCopies;
if (RedeemWayEnum.amount_redeem.getValue().equals(redeemWay)) {
redeemCopies = finSubscribe.getBigDecimal("redeemamount").add(dataEntitie.getBigDecimal("amount"));
finSubscribe.set("redeemamount", redeemCopies);
finCopies = finSubscribe.getBigDecimal("amount");
surplusCopies = finCopies.subtract(redeemCopies);
finSubscribe.set("surplusamount", surplusCopies);
if (BigDecimal.ZERO.compareTo(surplusCopies) == 0) {
finSubscribe.set("finservicestatus", FinServiceStatusEnum.subscribe_end.getValue());
finSubscribe.set("cleardate", dataEntitie.getDate("redeemdate"));
}
boolean isRevenue = dataEntitie.getBoolean("isrevenue");
if (isRevenue) {
BigDecimal realRevenue = dataEntitie.getBigDecimal("realrevenue");
finSubscribe.set("totalamount", finSubscribe.getBigDecimal("totalamount").add(realRevenue));
}
}
if (RedeemWayEnum.copies_redeem.getValue().equals(redeemWay)) {
//新增一行估值分录
DynamicObjectCollection newDataEntitie = this.addNewEntryData(finSubscribe, dataEntitie);
//标品已赎回份数反写
redeemCopies = finSubscribe.getBigDecimal("redeemcopies").add(dataEntitie.getBigDecimal("copies"));
finSubscribe.set("redeemcopies", redeemCopies);
//剩余份数-扩展分录最新日期的剩余份额
//获取分录最新日期的剩余份额
surplusCopies = this.getNewCopies(newDataEntitie);
// finCopies = finSubscribe.getBigDecimal("buycopies");
// surplusCopies = finCopies.subtract(redeemCopies);
finSubscribe.set("surpluscopies", surplusCopies);
//已收益金额
finSubscribe.set("totalamount", finSubscribe.getBigDecimal("totalamount").add(dataEntitie.getBigDecimal("realrevenue")));
if (EmptyUtil.isEmpty(surplusCopies)) {
finSubscribe.set("finservicestatus", FinServiceStatusEnum.subscribe_end.getValue());
finSubscribe.set("cleardate", dataEntitie.getDate("redeemdate"));
}
}
SaveServiceHelper.save(new DynamicObject[]{finSubscribe});
}
private BigDecimal getNewCopies(DynamicObjectCollection newDataEntitie) {
BigDecimal eSurpCopies = BigDecimal.ZERO;
DynamicObject maxEvalDateEntry = newDataEntitie.stream()
.max((entry1, entry2) -> {
// 比较 e_valuationdate
Date evalDate1 = entry1.getDate("e_valuationdate");
Date evalDate2 = entry2.getDate("e_valuationdate");
int dateCompare = evalDate1.compareTo(evalDate2);
if (dateCompare != 0) {
return dateCompare; // e_valuationdate 不同直接返回比较结果
} else {
// e_valuationdate 相同再比较 shjh_shrq
Date shrq1 = entry1.getDate("shjh_shrq");
Date shrq2 = entry2.getDate("shjh_shrq");
// 情况1: shrq1 shrq2 都为 null 返回 0保持原顺序
if (shrq1 == null && shrq2 == null) {
return 0;
}
// 情况2: shrq1 nullshrq2 不为 null 返回 -1shrq2 更大
else if (shrq1 == null) {
return -1;
}
// 情况3: shrq1 不为 nullshrq2 null 返回 1shrq1 更大
else if (shrq2 == null) {
return 1;
}
// 情况4: shrq1 shrq2 都不为 null 正常比较
else {
return shrq1.compareTo(shrq2);
}
}
})
.orElse(null); // 如果没有数据返回 null
if (maxEvalDateEntry != null) {
eSurpCopies = maxEvalDateEntry.getBigDecimal("e_surpcopies");
}
return eSurpCopies;
}
private DynamicObjectCollection addNewEntryData(DynamicObject finSubscribe, DynamicObject dataEntitie) {
//剩余份数
BigDecimal subtract = dataEntitie.getBigDecimal("shjh_shrsyfe").subtract(dataEntitie.getBigDecimal("copies"));
//单位净值
BigDecimal decimal = dataEntitie.getBigDecimal("shjh_shrjz");
//估值分录
DynamicObjectCollection valuationentry = finSubscribe.getDynamicObjectCollection("valuationentry");
if (valuationentry != null) {
DynamicObject dynamicObject = valuationentry.addNew();
dynamicObject.set("e_valuationdate", dataEntitie.getDate("redeemdate"));//估值日期
dynamicObject.set("e_surpcopies", subtract);//剩余份数
dynamicObject.set("e_iopv", decimal);//单位净值
dynamicObject.set("e_valuation", subtract.multiply(decimal));//市值
dynamicObject.set("shjh_shdh", dataEntitie);//赎回单号
dynamicObject.set("shjh_shbs", "Y");
dynamicObject.set("shjh_shrq", dataEntitie.getDate("auditdate"));//赎回日期
dynamicObject.set("seq",valuationentry.size()-1);
}
return valuationentry;
}
private void copyFinSubscribe(DynamicObject finSubscribe, DynamicObject redeemBill) {
OperateOption option = OperateOption.create();
option.setVariableValue("from_redeemrenewal", " true");
option.setVariableValue("redeembillid", redeemBill.getPkValue().toString());
TmcOperateServiceHelper.execOperate("redeemrenewal", CimEntityEnum.cim_finsubscribe.getValue(), new DynamicObject[]{finSubscribe}, option);
}
private void updateRealRevenueAmt(DynamicObject[] redeemBills, List<Object> revenueBillIds) {
Map<Long, BigDecimal> releaseBillMap = (Map) Arrays.stream(redeemBills).filter((d) -> {
return d.getBoolean("isrevenue") && d.getBoolean("ispushrev");
}).collect(Collectors.toMap((d) -> {
return d.getLong("id");
}, (d) -> {
return d.getBigDecimal("realrevenue");
}));
if (!EmptyUtil.isEmpty(releaseBillMap)) {
DynamicObject[] revenueBills = TmcDataServiceHelper.load(revenueBillIds.toArray(), MetadataServiceHelper.getDataEntityType(CimEntityEnum.cim_revenue.getValue()));
List<String> updateBills = new ArrayList(revenueBills.length);
DynamicObject[] var6 = revenueBills;
int var7 = revenueBills.length;
for (int var8 = 0; var8 < var7; ++var8) {
DynamicObject revenueBill = var6[var8];
long srcReleaseId = revenueBill.getLong("redeemid");
BigDecimal realRevenueAmt = (BigDecimal) releaseBillMap.get(srcReleaseId);
if (revenueBill.getBigDecimal("amount").compareTo(realRevenueAmt) != 0) {
revenueBill.set("amount", realRevenueAmt);
DynamicObjectCollection rows = revenueBill.getDynamicObjectCollection("entrys");
if (EmptyUtil.isEmpty(rows)) {
revenueBill.set("realrate", BigDecimal.ZERO);
}
revenueBill.set("realrate", RevenueCalcHelper.calcRealRate(rows, realRevenueAmt));
updateBills.add(revenueBill.getString("billno"));
}
}
if (updateBills.size() > 0) {
SaveServiceHelper.update(revenueBills);
logger.info("updateRealRevenueAmt : " + String.join("\n", updateBills));
}
}
}
}

View File

@ -0,0 +1,12 @@
package shjh.jhzj7.fi.fi.plugin.operate;
import kd.tmc.cim.opplugin.redeem.RedeemBillSubmitOp;
import kd.tmc.fbp.business.validate.AbstractTmcBizOppValidator;
public class RedeemBillSubmitExtendOperation extends RedeemBillSubmitOp {
@Override
public AbstractTmcBizOppValidator getBizOppValidator() {
return new RedeemBillSubmitValidatorExt();
}
}

View File

@ -0,0 +1,285 @@
package shjh.jhzj7.fi.fi.plugin.operate;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.resource.ResManager;
import kd.bos.dataentity.utils.StringUtils;
import kd.bos.entity.ExtendedDataEntity;
import kd.bos.exception.KDBizException;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.QueryServiceHelper;
import kd.tmc.cim.bussiness.validate.redeem.RedeemBillSubmitValidator;
import kd.tmc.cim.common.enums.RedeemWayEnum;
import kd.tmc.cim.common.enums.SupermarketCardEnum;
import kd.tmc.cim.common.enums.TradeChannelEnum;
import kd.tmc.cim.common.helper.RedeemBillHelper;
import kd.tmc.cim.common.helper.SuperMarketHelper;
import kd.tmc.fbp.common.enums.BillStatusEnum;
import kd.tmc.fbp.common.helper.TmcDataServiceHelper;
import kd.tmc.fbp.common.util.DateUtils;
import kd.tmc.fbp.common.util.EmptyUtil;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
public class RedeemBillSubmitValidatorExt extends RedeemBillSubmitValidator {
private static final Log LOG = LogFactory.getLog(RedeemBillSubmitValidatorExt.class);
@Override
public void validate(ExtendedDataEntity[] dataEntities) throws KDBizException {
List<ExtendedDataEntity> dataEntityList = new ArrayList(dataEntities.length);
ExtendedDataEntity[] var3 = dataEntities;
int var4 = dataEntities.length;
for(int var5 = 0; var5 < var4; ++var5) {
ExtendedDataEntity dataEntity = var3[var5];
boolean isPass = this.someSimpleValidate(dataEntity);
if (isPass) {
dataEntityList.add(dataEntity);
}
}
dataEntityList = this.validateRedeemDate(dataEntityList);
dataEntityList = this.validateExistDoingRedeem(dataEntityList);
this.validateExistDoingRevenueBill(dataEntityList);
}
private boolean someSimpleValidate(ExtendedDataEntity dataEntity) {
boolean isPass = true;
DynamicObject redeem = dataEntity.getDataEntity();
boolean isRevenue = redeem.getBoolean("isrevenue");
boolean isRenewal = redeem.getBoolean("isrenewal");
String redeemWay = redeem.getString("redeemway");
String tradeChannel = redeem.getString("tradechannel");
DynamicObject finBillF7 = redeem.getDynamicObject("finbillno");
boolean isinit = redeem.getBoolean("isinit");
BigDecimal copies;
if (RedeemWayEnum.amount_redeem.getValue().equals(redeemWay)) {
copies = redeem.getBigDecimal("amount");
if (EmptyUtil.isEmpty(copies)) {
this.addErrorMessage(dataEntity, ResManager.loadKDString("请填写\"赎回金额\"", "RedeemBillSaveValidator_3", "tmc-cim-business", new Object[0]));
isPass = false;
}
if (EmptyUtil.isEmpty(redeem.getBigDecimal("realrevenue")) && isRevenue && !TradeChannelEnum.ONLINE.getValue().equals(tradeChannel)) {
this.addErrorMessage(dataEntity, ResManager.loadKDString("请填写\"实际收益\"", "RedeemBillSubmitValidator_4", "tmc-cim-business", new Object[0]));
isPass = false;
}
if (isRenewal && EmptyUtil.isEmpty(redeem.getBigDecimal("renewalamount"))) {
this.addErrorMessage(dataEntity, ResManager.loadKDString("请填写\"理财续期金额\"", "RedeemBillSubmitValidator_5", "tmc-cim-business", new Object[0]));
isPass = false;
}
if (!isinit && copies.compareTo(finBillF7.getBigDecimal("surplusamount")) > 0) {
this.addErrorMessage(dataEntity, ResManager.loadKDString("赎回金额必须小于等于申购单的剩余金额。", "RedeemBillSubmitValidator_8", "tmc-cim-business", new Object[0]));
isPass = false;
}
}
if (RedeemWayEnum.copies_redeem.getValue().equals(redeemWay)) {
copies = redeem.getBigDecimal("copies");
if (EmptyUtil.isEmpty(copies)) {
this.addErrorMessage(dataEntity, ResManager.loadKDString("请填写\"赎回份数\"", "RedeemBillSaveValidator_4", "tmc-cim-business", new Object[0]));
isPass = false;
}
BigDecimal iopv = redeem.getBigDecimal("iopv");
if (EmptyUtil.isEmpty(iopv) && !TradeChannelEnum.ONLINE.getValue().equals(tradeChannel)) {
this.addErrorMessage(dataEntity, ResManager.loadKDString("请填写\"单位净值\"", "RedeemBillSaveValidator_5", "tmc-cim-business", new Object[0]));
isPass = false;
}
if (isRenewal && EmptyUtil.isEmpty(redeem.getBigDecimal("renewalcopies"))) {
this.addErrorMessage(dataEntity, ResManager.loadKDString("请填写\"续期购买份数\"", "RedeemBillSubmitValidator_6", "tmc-cim-business", new Object[0]));
isPass = false;
}
if (isRenewal && EmptyUtil.isEmpty(redeem.getBigDecimal("renewaliopv"))) {
this.addErrorMessage(dataEntity, ResManager.loadKDString("请填写\"续期单位净值\"", "RedeemBillSubmitValidator_7", "tmc-cim-business", new Object[0]));
isPass = false;
}
if (!isinit && copies.compareTo(redeem.getBigDecimal("shjh_shrsyfe")) > 0 && !TradeChannelEnum.ONLINE.getValue().equals(tradeChannel)) {
this.addErrorMessage(dataEntity, ResManager.loadKDString("赎回份数必须小于等于赎回日剩余份数。", "RedeemBillSubmitValidator_9", "tmc-cim-business", new Object[0]));
isPass = false;
}
}
Date redeemDate = redeem.getDate("redeemdate");
DynamicObject finBill = redeem.getDynamicObject("finbillno");
Date lastEndIntDate = finBill.getDate("endinstdate");
if (!EmptyUtil.isAnyoneEmpty(new Object[]{redeemDate, lastEndIntDate}) && redeemDate.compareTo(lastEndIntDate) <= 0) {
this.addErrorMessage(dataEntity, String.format(ResManager.loadKDString("赎回单的赎回日期必须大于当前申购单的上次收益日%s。", "RedeemBillSaveValidator_7", "tmc-cim-business", new Object[0]), DateUtils.formatString(lastEndIntDate, "yyyy-MM-dd")));
isPass = false;
}
Date purchaseDate = finBill.getDate("purchasedate");
if (lastEndIntDate == null && redeemDate != null && !redeemDate.after(purchaseDate)) {
this.addErrorMessage(dataEntity, String.format(ResManager.loadKDString("赎回单的赎回日期必须大于当前申购单的申购日期%s。", "RedeemBillSaveValidator_2", "tmc-cim-business", new Object[0]), DateUtils.formatString(purchaseDate, "yyyy-MM-dd")));
isPass = false;
}
boolean validResult = this.validateRedeemAmtWhenPrdExist(redeem, dataEntity);
if (!validResult) {
isPass = false;
}
return isPass;
}
private List<ExtendedDataEntity> validateRedeemDate(List<ExtendedDataEntity> dataEntityList) {
if (EmptyUtil.isEmpty(dataEntityList)) {
return dataEntityList;
} else {
List<Long> finIdList = (List)dataEntityList.stream().map((r) -> {
return r.getDataEntity();
}).map((r) -> {
return r.getDynamicObject("finbillno");
}).map((r) -> {
return r.getLong("id");
}).collect(Collectors.toList());
Map<Long, Date> id2DateMap = RedeemBillHelper.checkLastRedeemDate(finIdList);
List<ExtendedDataEntity> resultList = new ArrayList(dataEntityList.size());
Iterator var5 = dataEntityList.iterator();
while(true) {
while(var5.hasNext()) {
ExtendedDataEntity extData = (ExtendedDataEntity)var5.next();
DynamicObject redeem = extData.getDataEntity();
Date lastRedeemDate = (Date)id2DateMap.get(redeem.getLong("finbillno.id"));
if (EmptyUtil.isNoEmpty(lastRedeemDate) && redeem.getDate("redeemdate").before(lastRedeemDate)) {
this.addErrorMessage(extData, String.format(ResManager.loadKDString("赎回日期必须大于等于上一次的赎回日期[%s]。", "RedeemBillSaveValidator_1", "tmc-cim-business", new Object[0]), DateUtils.formatString(lastRedeemDate, "yyyy-MM-dd")));
} else {
resultList.add(extData);
}
}
return resultList;
}
}
}
private List<ExtendedDataEntity> validateExistDoingRedeem(List<ExtendedDataEntity> dataEntityList) {
if (EmptyUtil.isEmpty(dataEntityList)) {
return dataEntityList;
} else {
Map<Long, Long> fin2RedMap = RedeemBillHelper.getFinRedMapFromDb(dataEntityList);
List<ExtendedDataEntity> resultList = new ArrayList(dataEntityList.size());
Iterator var4 = dataEntityList.iterator();
while(var4.hasNext()) {
ExtendedDataEntity extData = (ExtendedDataEntity)var4.next();
DynamicObject redeem = extData.getDataEntity();
Long dbRedeemId = (Long)fin2RedMap.get(redeem.getLong("finbillno.id"));
if (EmptyUtil.isNoEmpty(dbRedeemId)) {
this.addErrorMessage(extData, ResManager.loadKDString("申购单下存在流程中的赎回单记录未处理,不能提交。", "RedeemBillSubmitValidator_1", "tmc-cim-business", new Object[0]));
} else {
resultList.add(extData);
}
}
return resultList;
}
}
private List<ExtendedDataEntity> validateExistDoingRevenueBill(List<ExtendedDataEntity> dataEntityList) {
if (EmptyUtil.isEmpty(dataEntityList)) {
return dataEntityList;
} else {
List<ExtendedDataEntity> hasRevenueList = (List)dataEntityList.stream().filter((r) -> {
return r.getDataEntity().getBoolean("isrevenue");
}).collect(Collectors.toList());
if (EmptyUtil.isEmpty(hasRevenueList)) {
return dataEntityList;
} else {
List<Long> finIdList = (List)hasRevenueList.stream().map((r) -> {
return r.getDataEntity();
}).map((r) -> {
return r.getDynamicObject("finbillno");
}).map((r) -> {
return r.getLong("id");
}).collect(Collectors.toList());
QFilter submitFilter = new QFilter("billstatus", "!=", BillStatusEnum.AUDIT.getValue());
QFilter idFilter = new QFilter("finbillno", "in", finIdList);
DynamicObjectCollection dbRevenueBills = QueryServiceHelper.query("cim_revenue", "id,finbillno", new QFilter[]{submitFilter, idFilter});
Map<Long, Long> fin2RevMap = (Map)dbRevenueBills.stream().collect(Collectors.toMap((r) -> {
return r.getLong("finbillno");
}, (r) -> {
return r.getLong("id");
}, (r1, r2) -> {
return r2;
}));
List<ExtendedDataEntity> resultList = new ArrayList(dataEntityList.size());
Iterator var9 = dataEntityList.iterator();
while(var9.hasNext()) {
ExtendedDataEntity extData = (ExtendedDataEntity)var9.next();
DynamicObject redeem = extData.getDataEntity();
Long dbRevenueId = (Long)fin2RevMap.get(redeem.getLong("finbillno.id"));
if (EmptyUtil.isNoEmpty(dbRevenueId)) {
this.addErrorMessage(extData, ResManager.loadKDString("申购单下存在流程中的收益记录,请先处理。", "RedeemBillSubmitValidator_2", "tmc-cim-business", new Object[0]));
} else {
resultList.add(extData);
}
}
return resultList;
}
}
}
private boolean validateRedeemAmtWhenPrdExist(DynamicObject redeem, ExtendedDataEntity dataEntity) {
boolean isPass = true;
Optional<DynamicObject> prdOption = Optional.ofNullable(redeem.getDynamicObject("finbillno")).map((r) -> {
return r.getDynamicObject("product");
});
if (prdOption.isPresent()) {
DynamicObject product = (DynamicObject)prdOption.get();
DynamicObject productBill = TmcDataServiceHelper.loadSingle(product.getPkValue(), "cim_supermarket", "bankcate,prdcardid");
Long bankCateId = (Long)Optional.ofNullable(productBill.getDynamicObject("bankcate")).map((r) -> {
return r.getLong("id");
}).orElse(0L);
String cardEntity = SupermarketCardEnum.getCardEntity(bankCateId);
if (EmptyUtil.isEmpty(cardEntity)) {
return isPass;
}
DynamicObject prdCardBill = TmcDataServiceHelper.loadSingle(cardEntity, SuperMarketHelper.getCardPropByEntityWhenRedeem(cardEntity), new QFilter[]{new QFilter("id", "=", productBill.getLong("prdcardid"))});
BigDecimal redeemAmt = redeem.getBigDecimal("amount");
BigDecimal redeemFloor;
if (StringUtils.equals("cim_market_icbc", cardEntity)) {
redeemFloor = prdCardBill.getBigDecimal("icbc_mincopy");
if (redeemAmt.compareTo(redeemFloor) < 0) {
this.addErrorMessage(dataEntity, ResManager.loadKDString("“理财金额”必须大于等于该理财产品的“单笔赎回最低金额”。", "RedeemBillSubmitValidator_11", "tmc-cim-business", new Object[0]));
isPass = false;
}
} else {
BigDecimal redeemCeil;
if (StringUtils.equals("cim_market_cmb", cardEntity)) {
redeemFloor = prdCardBill.getBigDecimal("cmb_redeemfloor");
redeemCeil = prdCardBill.getBigDecimal("cmb_redeemceil");
if (redeemAmt.compareTo(redeemFloor) < 0 || redeemAmt.compareTo(redeemCeil) > 0) {
LOG.info("赎回金额:{},赎回上限:{},赎回下限:{}", new Object[]{redeemAmt, redeemCeil, redeemFloor});
this.addErrorMessage(dataEntity, ResManager.loadKDString("“赎回金额”必须在该理财产品的“赎回下限”与“赎回上限”之间。", "RedeemBillSubmitValidator_10", "tmc-cim-business", new Object[0]));
isPass = false;
}
} else if (StringUtils.equals("cim_market_abc", cardEntity)) {
redeemFloor = prdCardBill.getBigDecimal("abc_redeemminamt");
redeemCeil = prdCardBill.getBigDecimal("abc_redeemmaxamt");
if (redeemAmt.compareTo(redeemFloor) < 0 || redeemAmt.compareTo(redeemCeil) > 0) {
LOG.info("赎回金额:{},赎回上限:{},赎回下限:{}", new Object[]{redeemAmt, redeemCeil, redeemFloor});
this.addErrorMessage(dataEntity, ResManager.loadKDString("“赎回金额”必须在该理财产品的“赎回起点金额”与“赎回最高金额”之间。", "RedeemBillSubmitValidator_12", "tmc-cim-business", new Object[0]));
isPass = false;
}
}
}
}
return isPass;
}
}

View File

@ -0,0 +1,100 @@
package shjh.jhzj7.fi.fi.plugin.operate;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.args.AfterOperationArgs;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.sdk.plugin.Plugin;
import java.math.BigDecimal;
import java.util.Date;
/**
* 单据操作插件
*/
public class RedeemBillUnAuditOperation extends AbstractOperationServicePlugIn implements Plugin {
@Override
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
super.afterExecuteOperationTransaction(e);
DynamicObject[] dataEntities = e.getDataEntities();
for (DynamicObject bill : dataEntities) {
Long pkValue = (Long) bill.getPkValue();
//理财赎回
bill = BusinessDataServiceHelper.loadSingle(pkValue, "cim_redeem");
Long finbillid = bill.getLong("finbillno.id");
//理财申购
DynamicObject finsubscribe = BusinessDataServiceHelper.loadSingle(finbillid,"cim_finsubscribe");
if (null != finsubscribe) {
DynamicObjectCollection dynamicObjectCollection = this.removeCollection(pkValue, finsubscribe);
BigDecimal surplusCopies = this.getNewCopies(dynamicObjectCollection);
finsubscribe.set("surpluscopies", surplusCopies);
finsubscribe.set("valuationentry",dynamicObjectCollection);
SaveServiceHelper.save(new DynamicObject[]{finsubscribe});
}
}
}
private DynamicObjectCollection removeCollection(Long pkValue,DynamicObject finsubscribe){
DynamicObjectCollection valuationentry = finsubscribe.getDynamicObjectCollection("valuationentry");
if (valuationentry!=null && valuationentry.size()!=0) {
for (DynamicObject dynamicObject : valuationentry) {
DynamicObject shdh = dynamicObject.getDynamicObject("shjh_shdh");
if (pkValue.compareTo((Long) shdh.getPkValue()) == 0) {
valuationentry.remove(dynamicObject);
break;
}
}
}
return valuationentry;
}
private BigDecimal getNewCopies(DynamicObjectCollection newDataEntitie) {
BigDecimal eSurpCopies = BigDecimal.ZERO;
DynamicObject maxEvalDateEntry = newDataEntitie.stream()
.max((entry1, entry2) -> {
// 比较 e_valuationdate
Date evalDate1 = entry1.getDate("e_valuationdate");
Date evalDate2 = entry2.getDate("e_valuationdate");
int dateCompare = evalDate1.compareTo(evalDate2);
if (dateCompare != 0) {
return dateCompare; // e_valuationdate 不同直接返回比较结果
} else {
// e_valuationdate 相同再比较 shjh_shrq
Date shrq1 = entry1.getDate("shjh_shrq");
Date shrq2 = entry2.getDate("shjh_shrq");
// 情况1: shrq1 shrq2 都为 null 返回 0保持原顺序
if (shrq1 == null && shrq2 == null) {
return 0;
}
// 情况2: shrq1 nullshrq2 不为 null 返回 -1shrq2 更大
else if (shrq1 == null) {
return -1;
}
// 情况3: shrq1 不为 nullshrq2 null 返回 1shrq1 更大
else if (shrq2 == null) {
return 1;
}
// 情况4: shrq1 shrq2 都不为 null 正常比较
else {
return shrq1.compareTo(shrq2);
}
}
})
.orElse(null); // 如果没有数据返回 null
if (maxEvalDateEntry != null) {
eSurpCopies = maxEvalDateEntry.getBigDecimal("e_surpcopies");
}
return eSurpCopies;
}
}