dobe_comic8/main/java/shkd/repc/repe/opplugin/RepeOrderSubmitOPPlugin.java

83 lines
4.4 KiB
Java

package shkd.repc.repe.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.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.Objects;
import static shkd.repc.repe.formplugin.RepeOrderFormPlugin.getOrderCount;
public class RepeOrderSubmitOPPlugin extends AbstractOperationServicePlugIn {
@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 "save":
case "submit":
// 在订单提交校验时,查询当前合同所有订单当前明细行的数量,超过合同数量时校验
for (int i = 0; i < dataEntities1.length; i++) {
//
DynamicObject dataEntity = dataEntities1[i].getDataEntity();
DynamicObjectCollection orderformentrys = dataEntity.getDynamicObjectCollection("orderformentry");
for (int j = 0; j < orderformentrys.size(); j++) {
DynamicObject dy = orderformentrys.get(j);
String number = "";
String name = "";
DynamicObject cqcontract = dataEntity.getDynamicObject("cqcontract");
if (null != cqcontract) {
number = cqcontract.getString("number");
name = cqcontract.getString("name");
}
QFilter q1 = new QFilter("billno", QCP.equals, number);
QFilter q2 = new QFilter("billname", QCP.equals, name);
DynamicObject recon_contractbill = BusinessDataServiceHelper.loadSingle("recon_contractbill", new QFilter[]{q1,q2});
if (null != recon_contractbill) {
//查询当前合同所有相关订单
QFilter q3 = new QFilter("cqcontract.number", QCP.equals, recon_contractbill.getString("billno"));
QFilter q4 = new QFilter("cqcontract.name", QCP.equals, recon_contractbill.getString("billname"));
DynamicObject[] repeOrderforms = BusinessDataServiceHelper.load("repe_orderform",
"id,cqcontract.number,cqcontract.name,cqcontract,orderformentry," +
"orderformentry.ordercount,orderformentry.contractnum", new QFilter[]{q3, q4});
//通过行号获取--订货数量总和
BigDecimal ordercount = getOrderCount(repeOrderforms, j);//订货数量总和
BigDecimal contractnum =(BigDecimal) dy.get("contractnum");//合同数量
BigDecimal contractremainnum = contractnum.subtract(ordercount);//剩余订货数量 = 合同数量 - 总订货数量
BigDecimal ordercounts = dy.getBigDecimal("ordercount");//本次订货数量
int result = ordercounts.compareTo(contractremainnum);
if (result > 0) {
this.addErrorMessage(dataEntities1[i], "订单明细第" + (j + 1) + "行 本次订货数量 不能大于 合同剩余数量");
System.out.println("num1 < num2");
}
}
}
}
break;
default:
break;
}
}
});
}
}