2024-12-14 05:01:21 +00:00
|
|
|
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;
|
2024-12-16 10:20:13 +00:00
|
|
|
import kd.bos.util.StringUtils;
|
2024-12-14 05:01:21 +00:00
|
|
|
|
|
|
|
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) {
|
2024-12-16 10:20:13 +00:00
|
|
|
// 控制金额校验
|
2024-12-14 05:01:21 +00:00
|
|
|
DynamicObject dataEntity = extendedDataEntity.getDataEntity();
|
|
|
|
List<Long> ids = new ArrayList<>();
|
|
|
|
Map<Long, BigDecimal> XqMap = new HashMap<>();
|
2024-12-16 10:20:13 +00:00
|
|
|
DynamicObjectCollection bidSections = dataEntity.getDynamicObjectCollection("bidsection"); // 标段
|
|
|
|
BigDecimal totalAmount = BigDecimal.ZERO; // 遍历明细, 需求单去重后累加申请金额, 非需求单累加规划金额
|
|
|
|
|
2024-12-14 05:01:21 +00:00
|
|
|
if (bidSections != null) {
|
|
|
|
for (DynamicObject bidSection : bidSections) {
|
2024-12-16 10:20:13 +00:00
|
|
|
DynamicObjectCollection projectEntries = bidSection.getDynamicObjectCollection("projectentry"); // 采购明细
|
|
|
|
|
2024-12-14 05:01:21 +00:00
|
|
|
if (projectEntries != null) {
|
|
|
|
for (DynamicObject projectEntry : projectEntries) {
|
|
|
|
long id = projectEntry.getLong("qeug_purentry_id");
|
2024-12-16 10:20:13 +00:00
|
|
|
|
|
|
|
// 需求_对应金额, 若id相同, 覆盖
|
|
|
|
if (id != 0) {
|
2024-12-14 05:01:21 +00:00
|
|
|
DynamicObject qeugCgxq = projectEntry.getDynamicObject("qeug_cgxq");
|
2024-12-16 10:20:13 +00:00
|
|
|
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"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-12-14 05:01:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-12-16 10:20:13 +00:00
|
|
|
|
|
|
|
// 累加需求对应金额
|
|
|
|
for (BigDecimal value : XqMap.values()) {
|
|
|
|
totalAmount = totalAmount.add(value);
|
2024-12-14 05:01:21 +00:00
|
|
|
}
|
|
|
|
}
|
2024-12-16 10:20:13 +00:00
|
|
|
|
|
|
|
// 采购立项_采购控制总金额(单头)
|
2024-12-14 05:01:21 +00:00
|
|
|
BigDecimal totalcontrol = dataEntity.getBigDecimal("totalcontrol");
|
|
|
|
if (totalcontrol.compareTo(totalAmount) > 0) {
|
|
|
|
this.addErrorMessage(extendedDataEntity, "采购控制总金额不能大于采购申请总金额与规划金额之和");
|
|
|
|
}
|
|
|
|
}
|
2024-12-16 10:20:13 +00:00
|
|
|
|
2024-12-14 05:01:21 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|