package tqq9.lc123.cloud.app.plugin.form.result; import kd.bos.dataentity.OperateOption; import kd.bos.dataentity.entity.CloneUtils; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.entity.botp.runtime.BFRow; import kd.bos.entity.operate.result.OperationResult; import kd.bos.entity.plugin.AbstractOperationServicePlugIn; import kd.bos.entity.plugin.args.BeforeOperationArgs; 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.servicehelper.botp.BFTrackerServiceHelper; import kd.bos.servicehelper.operation.OperationServiceHelper; import kd.bos.servicehelper.operation.SaveServiceHelper; import kd.sdk.plugin.Plugin; import java.util.List; import java.util.Map; /** * 单据操作插件 */ public class WarehouseReceiptClone extends AbstractOperationServicePlugIn implements Plugin { private final static Log logger = LogFactory.getLog(WarehouseReceiptClone.class); @Override public void beforeExecuteOperationTransaction(BeforeOperationArgs e) { super.beforeExecuteOperationTransaction(e); DynamicObject[] dataEntities1 = e.getDataEntities();//获取数据实体 for (DynamicObject dynamicObject : dataEntities1) { StringBuilder billnoSet = new StringBuilder(); //查找上游单据 Map> sourceBillsMap = BFTrackerServiceHelper.findDirtSourceBills(dynamicObject.getDataEntityType().getName(), new Long[]{dynamicObject.getLong("id")}); if (sourceBillsMap.size() > 0 && sourceBillsMap != null) { List bfRows = sourceBillsMap.get(dynamicObject.getLong("id")); if (bfRows != null) { for (BFRow bfRow : bfRows) { Long billId = bfRow.getSId().getBillId();//获取上游订单ID DynamicObject[] im_otheroutbill = BusinessDataServiceHelper.load("im_otheroutbill", "billno", new QFilter[]{new QFilter("id", QCP.equals, billId)}); if (im_otheroutbill != null) { for (int i = 0; i < im_otheroutbill.length; i++) { DynamicObject doj = im_otheroutbill[i]; billnoSet.append(doj.get("billno")); if (i < im_otheroutbill.length - 1) { billnoSet.append("、"); } } } } } } //查找再克隆 QFilter qf1 = new QFilter("id", QCP.equals, dynamicObject.getLong("id")); dynamicObject = BusinessDataServiceHelper.loadSingle(dynamicObject.getDataEntityType().getName(), new QFilter[]{qf1}); DynamicObject newData = (DynamicObject) new CloneUtils(false, true).clone(dynamicObject); newData.set("billno", dynamicObject.getString("billno")); newData.set("billstatus", "C"); newData.set("tqq9_sourcebillno", billnoSet); //保存 SaveServiceHelper.save(new DynamicObject[]{newData}); //反审核 OperateOption option = OperateOption.create(); StringBuilder message = new StringBuilder(); OperationResult unauditResult = OperationServiceHelper.executeOperate("unaudit", dynamicObject.getDataEntityType().getName(), new DynamicObject[]{dynamicObject}, OperateOption.create()); if (unauditResult.isSuccess()) { OperationResult deleteResult = OperationServiceHelper.executeOperate("delete", dynamicObject.getDataEntityType().getName(), new DynamicObject[]{dynamicObject}, OperateOption.create()); deleteResult.getAllErrorOrValidateInfo().forEach((error) -> { message.append(error.getMessage()); }); } else { unauditResult.getAllErrorOrValidateInfo().forEach((error) -> { message.append(error.getMessage()); }); } } } }