dobe_comic8/main/java/shkd/repc/rebm/opplugin/PurProjectSubmitOPPlugin.java

118 lines
6.9 KiB
Java
Raw Normal View History

package shkd.repc.rebm.opplugin;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.ExtendedDataEntity;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.AddValidatorsEventArgs;
import kd.bos.entity.validate.AbstractValidator;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.util.StringUtils;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
/**
* 采购立项提交
* qeug_rebm_project_ext
*/
public class PurProjectSubmitOPPlugin extends AbstractOperationServicePlugIn {
@Override
public void onAddValidators(AddValidatorsEventArgs e) {
super.onAddValidators(e);
/*
校验金额逻辑
1)引用合约规划:遍历子单据体,取计划,需求均为空并且合约规划名称不为空的行,累加规划金额
2)引用采购计划:遍历子单据体,取计划不为空的行,穿透到计划中累加对应明细的控制金额
3)引用采购需求:合并相同的采购需求单,累加需求金额
*/
e.addValidator(new AbstractValidator() {
@Override
public void validate() {
String operateKey = this.getOperateKey();
ExtendedDataEntity[] dataEntities1 = this.getDataEntities();
if ("submit".equals(operateKey)) {
for (ExtendedDataEntity extendedDataEntity : dataEntities1) {
// 控制金额校验
DynamicObject dataEntity = extendedDataEntity.getDataEntity();
Map<Long, BigDecimal> XqMap = new HashMap<>();
DynamicObjectCollection bidSections = dataEntity.getDynamicObjectCollection("bidsection"); // 标段
BigDecimal totalAmount = BigDecimal.ZERO; // 遍历明细, 需求单去重后累加申请金额, 非需求单累加规划金额
if (bidSections != null) {
for (DynamicObject bidSection : bidSections) {
DynamicObjectCollection projectEntries = bidSection.getDynamicObjectCollection("projectentry"); // 采购明细
if (projectEntries != null) {
for (DynamicObject projectEntry : projectEntries) {
long id = projectEntry.getLong("qeug_purentry_id");
// 需求_对应金额, 若id相同, 覆盖
if (id != 0) {
DynamicObject qeugCgxq = projectEntry.getDynamicObject("qeug_cgxq");
if (qeugCgxq != null) {
qeugCgxq = BusinessDataServiceHelper.loadSingle(qeugCgxq.getPkValue(), "recon_settleplanbill");
if (qeugCgxq != null) {
XqMap.put(qeugCgxq.getLong("id"), qeugCgxq.getBigDecimal("qeug_applyamount"));
}
}
}
// 非采购需求
else {
String purplanname = projectEntry.getString("purplanname"); // 采购计划名称
DynamicObject programcontract = projectEntry.getDynamicObject("programcontract"); // 合约规划
DynamicObject cqprogcon = projectEntry.getDynamicObject("cqprogcon"); // 合约规划树形
// 合约规划
if (StringUtils.isEmpty(purplanname) && projectEntry.getDynamicObject("qeug_cgxq") == null) {
if (programcontract != null || cqprogcon != null) {
totalAmount = totalAmount.add(projectEntry.getBigDecimal("planamount"));
}
}
// 采购计划
if (!StringUtils.isEmpty(purplanname)) {
DynamicObject purplanentry = projectEntry.getDynamicObject("purplanentry"); // 采购计划分录
if (purplanentry != null) {
purplanentry = BusinessDataServiceHelper.loadSingle(purplanentry.getPkValue(), "rebm_purplanentry_f7");
DynamicObject purplan = purplanentry.getDynamicObject("purplan");
if (purplan != null) {
DynamicObject rebm_purplan = BusinessDataServiceHelper.loadSingle(purplan.getPkValue(), "rebm_purplan");
DynamicObjectCollection collection = rebm_purplan.getDynamicObjectCollection("entryentity");
for (DynamicObject dynamicObject : collection) {
long id1 = purplanentry.getLong("id"); // 计划分录id
long id2 = dynamicObject.getLong("id");
if (id1 == id2) {
totalAmount = totalAmount.add(dynamicObject.getBigDecimal("prucontrolamount"));
}
}
}
}
}
}
}
}
}
// 累加需求对应金额
for (BigDecimal value : XqMap.values()) {
totalAmount = totalAmount.add(value);
}
}
// 采购立项_采购控制总金额(单头)
BigDecimal totalcontrol = dataEntity.getBigDecimal("totalcontrol");
if (totalcontrol.compareTo(totalAmount) > 0) {
this.addErrorMessage(extendedDataEntity, "采购控制总金额不能大于采购申请总金额与规划金额之和");
}
}
}
}
});
}
}