package tqq9.lc123.cloud.app.plugin.operate.im; import com.alibaba.fastjson.JSONObject; import com.grapecity.documents.excel.L; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObjectCollection; import kd.bos.entity.botp.runtime.ConvertOperationResult; import kd.bos.entity.botp.runtime.PushArgs; import kd.bos.entity.botp.runtime.SourceBillReport; import kd.bos.entity.plugin.AbstractOperationServicePlugIn; import kd.bos.entity.plugin.PreparePropertysEventArgs; import kd.bos.entity.plugin.args.AfterOperationArgs; 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.ConvertServiceHelper; import kd.bos.servicehelper.operation.SaveServiceHelper; import kd.bos.util.StringUtils; import kd.sdk.plugin.Plugin; import tqq9.lc123.cloud.app.plugin.utils.BotpParamUtils; import java.math.BigDecimal; import java.util.*; /** * 单据操作插件 */ public class OtherInYdthPlugin extends AbstractOperationServicePlugIn implements Plugin { private final static Log logger = LogFactory.getLog(OtherInYdthPlugin.class); private static String PM_PURREFUNDAPPLYBILL = "pm_purrefundapplybill";//采购退货申请单 private static String IM_PURINBILL = "im_purinbill";//采购入库单 private static String BILLENTRY = "billentry";//收货通知单分录,采购退货申请单分录 @Override public void onPreparePropertys(PreparePropertysEventArgs e) { super.onPreparePropertys(e); e.getFieldKeys().add("billentry.tqq9_cgthflid"); } @Override public void afterExecuteOperationTransaction(AfterOperationArgs e) { super.afterExecuteOperationTransaction(e); DynamicObject[] dataEntities1 = e.getDataEntities(); for (DynamicObject dynamicObject : dataEntities1) { DynamicObjectCollection billentry = dynamicObject.getDynamicObjectCollection("billentry"); List cgthflidList = new ArrayList<>(); for (DynamicObject object : billentry) { String tqq9_cgthflid = object.getString("tqq9_cgthflid"); if (StringUtils.isNotEmpty(tqq9_cgthflid) && !"0".equals(tqq9_cgthflid)) { cgthflidList.add(Long.valueOf(tqq9_cgthflid)); } } //根据采购退货分录id找到采购退货申请单,下推-红字采购入库单 DynamicObject pm_purrefundapplybill = BusinessDataServiceHelper.loadSingle("pm_purrefundapplybill", new QFilter[]{new QFilter("billentry.id", QCP.in, cgthflidList)}); List details = new ArrayList<>(); DynamicObjectCollection billentry_cgth = pm_purrefundapplybill.getDynamicObjectCollection("billentry"); for (DynamicObject object : billentry_cgth) { long id = object.getLong("id"); if (cgthflidList.contains(id)) { details.add(dynamicObject); } } if (null != pm_purrefundapplybill) { Long id = pm_purrefundapplybill.getLong("id"); Map> param = new HashMap<>();//传入转换规则处理参数 HashMap> entitypkMap = new HashMap<>();//上下游id映射Map for (Object detail : details) { JSONObject detailObject = new JSONObject(); JSONObject detail1 = (JSONObject) detail; String entryId = detail1.getString("erpDetailId");//金蝶源头单据细单号 String wmsDetailId = detail1.getString("wmsDetailId");//WMS入库单细单号 BigDecimal quantity = detail1.getBigDecimal("quantity");//入库数量 String uniqueCode = detail1.getString("uniqueCode");//商品编码 Date manufactureDate = detail1.getDate("manufactureDate");//生产日期 Date expirationDate = detail1.getDate("expirationDate");//失效期 String batch = detail1.getString("batch");//批次 String registrationCode = detail1.getString("registrationCode");//注册证号 String licenceCode = detail1.getString("licenceCode");//生产许可证 String producer = detail1.getString("producer");//生产厂商 detailObject.put("entryId", entryId); detailObject.put("wmsDetailId", wmsDetailId); detailObject.put("uniqueCode", uniqueCode); detailObject.put("quantity", quantity); detailObject.put("manufactureDate", manufactureDate); detailObject.put("expirationDate", expirationDate); detailObject.put("batch", batch); detailObject.put("registrationCode", registrationCode); detailObject.put("licenceCode", licenceCode); detailObject.put("producer", producer); entitypkMap.computeIfAbsent(id, k -> new HashSet<>()).add(detail1.getLong("erpDetailId")); param.computeIfAbsent(entryId, k -> new HashSet<>()).add(detailObject); } String rule = BotpParamUtils.getBotpRuleId(PM_PURREFUNDAPPLYBILL, IM_PURINBILL, ""); PushArgs pushArgs = BotpParamUtils.getPushArgs(PM_PURREFUNDAPPLYBILL, IM_PURINBILL, BILLENTRY, param, entitypkMap, rule); ConvertOperationResult pushResult = ConvertServiceHelper.pushAndSave(pushArgs); List billReports = pushResult.getBillReports(); } } } }