| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- package nckd.pur.scp.plugin.operate;
- import kd.bos.dataentity.entity.DynamicObject;
- import kd.bos.dataentity.entity.DynamicObjectCollection;
- import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
- import kd.bos.entity.plugin.args.AfterOperationArgs;
- 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 kd.sdk.plugin.Plugin;
- import nckd.pur.scp.common.DateUtil;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * 单据操作插件
- */
- public class SaloutStockOpPlugin extends AbstractOperationServicePlugIn{
- @Override
- public void afterExecuteOperationTransaction(AfterOperationArgs e) {
- super.afterExecuteOperationTransaction(e);
- DynamicObject[] entities = e.getDataEntities();
- String operationKey = e.getOperationKey();
- if("submit".equals(operationKey)){
- for (DynamicObject bill : entities) {
- String wuliu = bill.getString("nckd_textfield");
- String date = DateUtil.date2str(bill.getDate("delidate"),DateUtil.DATE_FORMAT_YYYY_MM_DD);
- String content = String.format("已发货,预计到货日期:%s,物流单号:%s",date,wuliu);
- //反写至 采购订单 采购申请单
- DynamicObjectCollection materialEntry = bill.getDynamicObjectCollection("materialentry");
- //采购订单编号
- List<String> poBillNo = materialEntry.stream().map(entry -> entry.getString("pobillno")).distinct().collect(Collectors.toList());
- //采购订单
- DynamicObject purOrder = BusinessDataServiceHelper.loadSingle("pm_purorderbill", new QFilter("billno", QCP.in, poBillNo).toArray());
- //采购申请单
- Map<String, HashSet<Long>> srcBills = BFTrackerServiceHelper.findSourceBills("pm_purorderbill", new Long[]{purOrder.getLong("id")});
- DynamicObject purApply = null;
- if(!srcBills.isEmpty()){
- if (srcBills.containsKey("pm_purapplybill")) {
- ArrayList list = new ArrayList(srcBills.get("pm_purapplybill"));
- purApply = BusinessDataServiceHelper.loadSingle(list.get(0),"pm_purapplybill");
- purApply.set("nckd_tracking",content);
- }
- }
- purOrder.set("·",content);
- if(purApply!=null) {
- SaveServiceHelper.save(new DynamicObject[]{purOrder});
- SaveServiceHelper.save(new DynamicObject[]{purApply});
- }else{
- SaveServiceHelper.save(new DynamicObject[]{purOrder});
- }
- }
- }
- }
- }
|