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

60 lines
2.8 KiB
Java

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 java.math.BigDecimal;
public class PurPlanSubmitOPPlugin extends AbstractOperationServicePlugIn {
private static final Log logger = LogFactory.getLog(PurPlanSubmitOPPlugin.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();
DynamicObjectCollection cgxuentry = dataEntity.getDynamicObjectCollection("qeug_cgxuentryss");
if (cgxuentry.isEmpty()) {
this.addErrorMessage(extendedDataEntity, "采购需求明细不能为空,不允许提交。");
}
//采购计划明细
BigDecimal cgxuentry_a = BigDecimal.ZERO;
for (DynamicObject dynamicObject : cgxuentry) {
cgxuentry_a = cgxuentry_a.add(dynamicObject.getBigDecimal("qeug_applyamount"));
}
//合约规划金额 entryentity
DynamicObjectCollection entryentity = dataEntity.getDynamicObjectCollection("entryentity");
BigDecimal cgxuentry_b = BigDecimal.ZERO;
for (DynamicObject dynamicObject : entryentity) {
cgxuentry_b = cgxuentry_b.add(dynamicObject.getBigDecimal("planamount"));
}
if (cgxuentry_a.compareTo(cgxuentry_b) > 0) { // 如果 cgxuentry_a 大于 cgxuentry_b
this.addErrorMessage(extendedDataEntity, "采购计划明细中的申请金额大于合约规划金额,不允许提交。");
}
}
break;
default:
break;
}
}
});
}
}