借款单提交撤销和反审核逻辑扣除对应的定额备用金金额和校验逻辑
This commit is contained in:
parent
4c380dfdf0
commit
d24bcf8e06
|
@ -0,0 +1,94 @@
|
||||||
|
package zcgj.zcdev.zcdev.fs.plugin.operate;
|
||||||
|
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||||
|
import kd.bos.entity.ExtendedDataEntity;
|
||||||
|
import kd.bos.entity.operate.result.OperationResult;
|
||||||
|
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
|
||||||
|
import kd.bos.entity.plugin.AddValidatorsEventArgs;
|
||||||
|
import kd.bos.entity.plugin.PreparePropertysEventArgs;
|
||||||
|
import kd.bos.entity.plugin.args.AfterOperationArgs;
|
||||||
|
import kd.bos.entity.validate.AbstractValidator;
|
||||||
|
import kd.bos.orm.query.QCP;
|
||||||
|
import kd.bos.orm.query.QFilter;
|
||||||
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||||
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||||
|
import zcgj.zcdev.zcdev.fs.utils.OrgCheckUtils;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 借款单提交操作插件
|
||||||
|
* 说明:校验备用金类型中的借款金额是否满足对应备用金类型的条件
|
||||||
|
*/
|
||||||
|
public class DailyLoanBillSubValidatorOp extends AbstractOperationServicePlugIn {
|
||||||
|
public void onPreparePropertys(PreparePropertysEventArgs e) {
|
||||||
|
super.onPreparePropertys(e);
|
||||||
|
e.getFieldKeys().add("costcompany");//核算组织(费用承担公司)
|
||||||
|
e.getFieldKeys().add("zcgj_impresttype");//备用金类型
|
||||||
|
e.getFieldKeys().add("loanamount");//借款金额合计
|
||||||
|
e.getFieldKeys().add("applier");//申请人
|
||||||
|
e.getFieldKeys().add("bizdate");//申请日期
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAddValidators(AddValidatorsEventArgs e) {
|
||||||
|
super.onAddValidators(e);
|
||||||
|
e.getValidators().add(new ValidatorExt());
|
||||||
|
}
|
||||||
|
|
||||||
|
class ValidatorExt extends AbstractValidator {
|
||||||
|
@Override
|
||||||
|
public void validate() {
|
||||||
|
ExtendedDataEntity[] dataEntities = this.getDataEntities();
|
||||||
|
for (ExtendedDataEntity dataEnt : dataEntities) {
|
||||||
|
DynamicObject er_dailyLoanBill = dataEnt.getDataEntity();
|
||||||
|
DynamicObject companyObj = (DynamicObject) er_dailyLoanBill.get("costcompany");//核算组织(费用承担公司)
|
||||||
|
if (companyObj != null) {
|
||||||
|
Long companyId = companyObj.getLong("id");
|
||||||
|
if (OrgCheckUtils.isKS(companyId)) {
|
||||||
|
String impRestType = er_dailyLoanBill.getString("zcgj_impresttype");//备用金类型
|
||||||
|
DynamicObject applier = er_dailyLoanBill.getDynamicObject("applier");//申请人
|
||||||
|
if (impRestType != null && !"".equals(impRestType)) {
|
||||||
|
if (impRestType.equals("0")) {
|
||||||
|
//定额备用金
|
||||||
|
Date bizDate = er_dailyLoanBill.getDate("bizdate");//申请日期
|
||||||
|
BigDecimal loanAmount = er_dailyLoanBill.getBigDecimal("loanamount");//借款金额合计
|
||||||
|
LocalDate localDate = bizDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
||||||
|
String bizDateYear = String.valueOf(localDate.getYear());//申请日期年份
|
||||||
|
|
||||||
|
QFilter filter = new QFilter("zcgj_entryentity.zcgj_person", QCP.equals, applier.getPkValue());
|
||||||
|
filter.and(new QFilter("zcgj_currentyear", QCP.equals, bizDateYear));
|
||||||
|
DynamicObject quotaImprestLedger = BusinessDataServiceHelper.loadSingle("zcgj_quotaimprestledger", new QFilter[]{filter});//定额备用金初始台账
|
||||||
|
DynamicObjectCollection entryEntityCollection = quotaImprestLedger.getDynamicObjectCollection("zcgj_entryentity");//分录
|
||||||
|
for (DynamicObject entryEntity : entryEntityCollection) {
|
||||||
|
DynamicObject person = entryEntity.getDynamicObject("zcgj_person");//人员
|
||||||
|
if (person.getPkValue().equals(applier.getPkValue())) {
|
||||||
|
BigDecimal zcgj_remainingquota = entryEntity.getBigDecimal("zcgj_remainingquota");//剩余额度
|
||||||
|
if (zcgj_remainingquota.compareTo(loanAmount) < 0) {
|
||||||
|
this.addFatalErrorMessage(dataEnt, "借款金额超过剩余额度!!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}/* else if (impRestType.equals("1")) {
|
||||||
|
//临时备用金
|
||||||
|
} else if (impRestType.equals("2")) {
|
||||||
|
//项目筹备备用金
|
||||||
|
QFilter filter = new QFilter("zcgj_entryentity.zcgj_person", QCP.equals, applier.getPkValue());// 可借款人员
|
||||||
|
filter.and(new QFilter("zcgj_entryentity.zcgj_isenabled", QCP.equals, true));// 启用
|
||||||
|
filter.and(new QFilter("zcgj_entryentity.zcgj_company", QCP.equals, companyId));// 公司
|
||||||
|
DynamicObject projectReserveFund = BusinessDataServiceHelper.loadSingle("zcgj_projectreservefund", new QFilter[]{filter});//项目筹备备用金公司
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,94 @@
|
||||||
|
package zcgj.zcdev.zcdev.fs.plugin.operate;
|
||||||
|
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||||
|
import kd.bos.entity.operate.result.OperationResult;
|
||||||
|
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 zcgj.zcdev.zcdev.fs.utils.OrgCheckUtils;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 借款单提交撤销和反审核操作插件
|
||||||
|
* 说明:将对应备用金类型中的借款金额反写至对应基础资料中
|
||||||
|
*/
|
||||||
|
public class LoanSlipReserveFundReverserOp extends AbstractOperationServicePlugIn {
|
||||||
|
@Override
|
||||||
|
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
|
||||||
|
super.afterExecuteOperationTransaction(e);
|
||||||
|
|
||||||
|
String operationKey = e.getOperationKey();//操作标识
|
||||||
|
OperationResult operationResult = getOperationResult();
|
||||||
|
List<Object> successPkIds = operationResult.getSuccessPkIds();
|
||||||
|
List<DynamicObject> modifiedEntities = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Object model : successPkIds) {
|
||||||
|
long id = (long) model;
|
||||||
|
QFilter f1 = new QFilter("id", "=", id);
|
||||||
|
DynamicObject er_dailyLoanBill = BusinessDataServiceHelper.loadSingle("er_dailyloanbill", new QFilter[]{f1});//借款单
|
||||||
|
DynamicObject companyObj = (DynamicObject) er_dailyLoanBill.get("costcompany");//核算组织(费用承担公司)
|
||||||
|
if (companyObj != null) {
|
||||||
|
Long companyId = companyObj.getLong("id");
|
||||||
|
if (OrgCheckUtils.isKS(companyId)) {
|
||||||
|
String impRestType = er_dailyLoanBill.getString("zcgj_impresttype");//备用金类型
|
||||||
|
if (impRestType != null && !"".equals(impRestType)) {
|
||||||
|
if (impRestType.equals("0")) {
|
||||||
|
//定额备用金
|
||||||
|
DynamicObject applier = er_dailyLoanBill.getDynamicObject("applier");//申请人
|
||||||
|
Date bizDate = er_dailyLoanBill.getDate("bizdate");//申请日期
|
||||||
|
BigDecimal loanAmount = er_dailyLoanBill.getBigDecimal("loanamount");//借款金额合计
|
||||||
|
LocalDate localDate = bizDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
||||||
|
String bizDateYear = String.valueOf(localDate.getYear());//申请日期年份
|
||||||
|
QFilter filter = new QFilter("zcgj_entryentity.zcgj_person", QCP.equals, applier.getPkValue());
|
||||||
|
filter.and(new QFilter("zcgj_currentyear", QCP.equals, bizDateYear));
|
||||||
|
DynamicObject quotaImprestLedger = BusinessDataServiceHelper.loadSingle("zcgj_quotaimprestledger", new QFilter[]{filter});//定额备用金初始台账
|
||||||
|
DynamicObjectCollection entryEntityCollection = quotaImprestLedger.getDynamicObjectCollection("zcgj_entryentity");//分录
|
||||||
|
for (DynamicObject entryEntity : entryEntityCollection) {
|
||||||
|
DynamicObject person = entryEntity.getDynamicObject("zcgj_person");//人员
|
||||||
|
if (person.getPkValue().equals(applier.getPkValue())) {
|
||||||
|
if (operationKey.equals("submit")) {
|
||||||
|
//提交
|
||||||
|
BigDecimal zcgj_usedquota = entryEntity.getBigDecimal("zcgj_usedquota").add(loanAmount);//已使用+借款金额
|
||||||
|
entryEntity.set("zcgj_usedquota", zcgj_usedquota);//已使用
|
||||||
|
BigDecimal zcgj_quota = entryEntity.getBigDecimal("zcgj_quota");//额度
|
||||||
|
BigDecimal zcgj_remainingquota = zcgj_quota.subtract(entryEntity.getBigDecimal("zcgj_usedquota"));//额度-已使用
|
||||||
|
entryEntity.set("zcgj_remainingquota", zcgj_remainingquota);//剩余额度
|
||||||
|
} else if (operationKey.equals("unsubmit") || operationKey.equals("unaudit")) {
|
||||||
|
//撤销、反审核
|
||||||
|
BigDecimal zcgj_usedquota = entryEntity.getBigDecimal("zcgj_usedquota").subtract(er_dailyLoanBill.getBigDecimal("loanamount"));//已使用+借款金额
|
||||||
|
entryEntity.set("zcgj_usedquota", zcgj_usedquota);//已使用
|
||||||
|
BigDecimal zcgj_remainingquota = entryEntity.getBigDecimal("zcgj_quota").add(entryEntity.getBigDecimal("zcgj_usedquota"));//额度-已使用
|
||||||
|
entryEntity.set("zcgj_remainingquota", zcgj_remainingquota);//剩余额度
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
modifiedEntities.add(quotaImprestLedger);
|
||||||
|
}/* else if (impRestType.equals("1")) {
|
||||||
|
//临时备用金
|
||||||
|
} else if (impRestType.equals("2")) {
|
||||||
|
//项目筹备备用金
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!modifiedEntities.isEmpty()) {
|
||||||
|
try {
|
||||||
|
SaveServiceHelper.save(modifiedEntities.toArray(new DynamicObject[0]));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue