diff --git a/lc123/cloud/app/plugin/form/result/CloneBill.java b/lc123/cloud/app/plugin/form/result/CloneBill.java new file mode 100644 index 0000000..5d24db2 --- /dev/null +++ b/lc123/cloud/app/plugin/form/result/CloneBill.java @@ -0,0 +1,74 @@ +package tqq9.lc123.cloud.app.plugin.form.result; + +import kd.bos.dataentity.entity.CloneUtils; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.entity.botp.runtime.BFRow; +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.SaveServiceHelper; + +import java.util.List; +import java.util.Map; + +public class CloneBill extends AbstractOperationServicePlugIn { + private final static Log logger = LogFactory.getLog(CloneBill.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 (null != sourceBillsMap && sourceBillsMap.size() > 0) { + List bfRows = sourceBillsMap.get(dynamicObject.getLong("id")); + if (null != bfRows) { + for (BFRow bfRow : bfRows) { + Long billId = bfRow.getSId().getBillId();//获取到采购退货申请id + DynamicObject[] pm_purrefundapplybill = BusinessDataServiceHelper.load("pm_purrefundapplybill", "billno", + new QFilter[]{new QFilter("id", "=", billId)}); + + for (int i = 0; i < pm_purrefundapplybill.length; i++) { + DynamicObject object = pm_purrefundapplybill[i]; + String billno = object.getString("billno"); + billnoSet.append(billno); + if (i < pm_purrefundapplybill.length-1) { + billnoSet.append("、"); + } + } + + } + } + } + dynamicObject = BusinessDataServiceHelper.loadSingle(dynamicObject.getDataEntityType().getName(), + new QFilter[]{new QFilter("id", QCP.equals, dynamicObject.getLong("id"))}); + 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}); + StringBuilder message = new StringBuilder(); + /*OperateOption option = OperateOption.create(); + 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()); + }); + }*/ + } + } +}