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

88 lines
4.5 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 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");
//非采购需求,计算规划金额
if (id == 0) {
totalAmount = totalAmount.add(projectEntry.getBigDecimal("planamount"));
}else {
//需求_对应金额,若id相同,覆盖
DynamicObject qeugCgxq = projectEntry.getDynamicObject("qeug_cgxq");
if (null != qeugCgxq) {
qeugCgxq = BusinessDataServiceHelper.loadSingle(qeugCgxq.getPkValue(),"recon_settleplanbill");
XqMap.put(qeugCgxq.getLong("id"), qeugCgxq.getBigDecimal("qeug_applyamount"));
}
}
}
}
}
if (!XqMap.isEmpty()) {
for (Map.Entry<Long, BigDecimal> entry : XqMap.entrySet()) {
BigDecimal value = entry.getValue();
totalAmount = totalAmount.add(value);
}
}
}
//采购立项_采购控制总金额(单头)
BigDecimal totalcontrol = dataEntity.getBigDecimal("totalcontrol");
if (totalcontrol.compareTo(totalAmount) > 0) {
this.addErrorMessage(extendedDataEntity, "采购控制总金额不能大于采购申请总金额与规划金额之和");
}
}
break;
default:
break;
}
}
});
}
}