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

126 lines
7.2 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.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.util.StringUtils;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 采购立项提交
* qeug_rebm_project_ext
*/
public class PurProjectSubmitOPPlugin extends AbstractOperationServicePlugIn {
private static final Log logger = LogFactory.getLog(PurProjectSubmitOPPlugin.class);
@Override
public void onAddValidators(AddValidatorsEventArgs e) {
super.onAddValidators(e);
e.addValidator(new AbstractValidator() {
@Override
public void validate() {
String operateKey = this.getOperateKey();
ExtendedDataEntity[] dataEntities1 = this.getDataEntities();
switch (operateKey) {
case "submit":
for (ExtendedDataEntity extendedDataEntity : dataEntities1) {
// 控制金额校验
DynamicObject dataEntity = extendedDataEntity.getDataEntity();
List<Long> ids = new ArrayList<>();
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, "采购控制总金额不能大于采购申请总金额与规划金额之和");
}
}
break;
default:
break;
}
}
});
}
}