下推-红字采购入库单
This commit is contained in:
parent
d0db2bd13d
commit
8be467b085
|
|
@ -0,0 +1,108 @@
|
||||||
|
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<Long> 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<DynamicObject> 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<String, Set<JSONObject>> param = new HashMap<>();//传入转换规则处理参数
|
||||||
|
HashMap<Long, Set<Long>> 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<SourceBillReport> billReports = pushResult.getBillReports();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,161 @@
|
||||||
|
package tqq9.lc123.cloud.app.plugin.operate.im;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.common.utils.StringUtils;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||||
|
import kd.bos.dataentity.metadata.IDataEntityProperty;
|
||||||
|
import kd.bos.dataentity.metadata.clr.DataEntityPropertyCollection;
|
||||||
|
import kd.bos.entity.ExtendedDataEntity;
|
||||||
|
import kd.bos.entity.ExtendedDataEntitySet;
|
||||||
|
import kd.bos.entity.botp.plugin.AbstractConvertPlugIn;
|
||||||
|
import kd.bos.entity.botp.plugin.args.AfterConvertEventArgs;
|
||||||
|
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.sdk.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 采购入库转换插件
|
||||||
|
*/
|
||||||
|
public class PurInHzrkConvertPlugin extends AbstractConvertPlugIn implements Plugin {
|
||||||
|
|
||||||
|
private final static Log logger = LogFactory.getLog(PurInHzrkConvertPlugin.class);
|
||||||
|
private static String IM_PURINBILL = "im_purinbill";
|
||||||
|
private final static HashMap<String, String> wareTypeMap = new HashMap<String, String>() {{
|
||||||
|
put("地堆区", "SHZC01");
|
||||||
|
put("存储区", "SHZC01");
|
||||||
|
put("立库区", "SHZC01");
|
||||||
|
put("新仓", "SHZC01");
|
||||||
|
put("破损区", "SHZC02");
|
||||||
|
put("零拣区", "SHZC02");
|
||||||
|
put("收货中转", "SHZC03");
|
||||||
|
put("退货中转", "SHZC03");
|
||||||
|
put("虚拟区", "SHZC03");
|
||||||
|
}};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 入库回传下推写入对应的
|
||||||
|
* quantity 入库数量
|
||||||
|
* manufactureDate 生产日期
|
||||||
|
* expirationDate 失效期
|
||||||
|
* batch 批次
|
||||||
|
* registrationCode 注册证号
|
||||||
|
* licenceCode 生产许可证号
|
||||||
|
* producer 生产厂商
|
||||||
|
*
|
||||||
|
* @param e
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void afterConvert(AfterConvertEventArgs e) {
|
||||||
|
super.afterConvert(e);
|
||||||
|
ExtendedDataEntitySet targetExtDataEntitySet = e.getTargetExtDataEntitySet();
|
||||||
|
ExtendedDataEntity[] extendedDataEntities = targetExtDataEntitySet.FindByEntityKey(IM_PURINBILL);
|
||||||
|
Map<String, String> variables = this.getOption().getVariables();
|
||||||
|
for (ExtendedDataEntity extendedDataEntity : extendedDataEntities) {
|
||||||
|
//采购入库单
|
||||||
|
DynamicObject dataEntity = extendedDataEntity.getDataEntity();
|
||||||
|
DynamicObjectCollection dynamicObjectCollection = dataEntity.getDynamicObjectCollection("billentry");
|
||||||
|
ListIterator<DynamicObject> iterator = dynamicObjectCollection.listIterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
DynamicObject entry = iterator.next();
|
||||||
|
String srcbillentryid = entry.getString("srcbillentryid");
|
||||||
|
//核心单据号一致,写入数据
|
||||||
|
if (variables.containsKey(srcbillentryid)) {
|
||||||
|
String jsonString = variables.get(srcbillentryid);
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
List<HashMap<String, Object>> jsonList = null;
|
||||||
|
try {
|
||||||
|
jsonList = objectMapper.readValue(jsonString, objectMapper.getTypeFactory().constructCollectionType(List.class, HashMap.class));
|
||||||
|
} catch (JsonProcessingException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
if (jsonList != null) {
|
||||||
|
dataEntity.set("tqq9_isrebulidlink",true);
|
||||||
|
for (int i = 0; i < jsonList.size(); i++) {
|
||||||
|
HashMap<String, Object> jsonMap = jsonList.get(i);
|
||||||
|
String VoucherType = jsonMap.get("VoucherType").toString();//类型
|
||||||
|
Date manufactureDate = null;
|
||||||
|
Date expirationDate = null;
|
||||||
|
if (jsonMap.get("manufactureDate") instanceof Long) {
|
||||||
|
manufactureDate = new Date((Long) jsonMap.get("manufactureDate")); //生产日期
|
||||||
|
}
|
||||||
|
if (jsonMap.get("expirationDate") instanceof Long) {
|
||||||
|
expirationDate = new Date((Long) jsonMap.get("expirationDate")); //生产日期
|
||||||
|
}
|
||||||
|
BigDecimal quantity = BigDecimal.ZERO;
|
||||||
|
if (StringUtils.equals("pm_receiptnotice", VoucherType)) {
|
||||||
|
quantity = new BigDecimal(jsonMap.get("quantity").toString());//入库数量
|
||||||
|
} else {
|
||||||
|
quantity = new BigDecimal(jsonMap.get("quantity").toString()).negate();//入库数量
|
||||||
|
}
|
||||||
|
String batch = jsonMap.get("batch") != null ? jsonMap.get("batch").toString() : null; // 批次
|
||||||
|
String toZone = jsonMap.get("toZone") != null ? jsonMap.get("toZone").toString() : null; // 库区
|
||||||
|
DynamicObject bd_warehouse=null;
|
||||||
|
if(toZone!=null){
|
||||||
|
String wareNumber = wareTypeMap.get(toZone);
|
||||||
|
bd_warehouse = BusinessDataServiceHelper.loadSingle("bd_warehouse", new QFilter[]{new QFilter("number", QCP.equals, wareNumber)});
|
||||||
|
}
|
||||||
|
String wmsDetailId = jsonMap.get("wmsDetailId") != null ? jsonMap.get("wmsDetailId").toString() : null; // WMS分录id
|
||||||
|
String uniqueCode = jsonMap.get("uniqueCode") != null ? jsonMap.get("uniqueCode").toString() : null; // 商品编码
|
||||||
|
String registrationCode = jsonMap.get("registrationCode") != null ? jsonMap.get("registrationCode").toString() : null; // 注册证号
|
||||||
|
String licenceCode = jsonMap.get("licenceCode") != null ? jsonMap.get("licenceCode").toString() : null; // 生产许可证号
|
||||||
|
String producer = jsonMap.get("producer") != null ? jsonMap.get("producer").toString() : null; // 生产厂商
|
||||||
|
DynamicObject tqq9_goodspackage = BusinessDataServiceHelper.loadSingle("tqq9_goodspackage", new QFilter[]{new QFilter("tqq9_mater.number", QCP.equals, uniqueCode).and("tqq9_isauto", QCP.equals, true)});
|
||||||
|
DynamicObject tqq9_registration = BusinessDataServiceHelper.loadSingle("tqq9_registration", new QFilter[]{new QFilter("number", QCP.equals, registrationCode)});
|
||||||
|
DynamicObject tqq9_proxyandfactory = BusinessDataServiceHelper.loadSingle("tqq9_proxyandfactory", new QFilter[]{new QFilter("number", QCP.equals, producer)});
|
||||||
|
// 处理第一次逻辑
|
||||||
|
if (i == 0) {
|
||||||
|
// 第一次直接赋值
|
||||||
|
entry.set("qty", quantity);
|
||||||
|
entry.set("baseqty", quantity);
|
||||||
|
entry.set("tqq9_goods", tqq9_goodspackage);
|
||||||
|
entry.set("producedate", manufactureDate);
|
||||||
|
entry.set("expirydate", expirationDate);
|
||||||
|
entry.set("lotnumber", batch);
|
||||||
|
entry.set("warehouse", bd_warehouse);
|
||||||
|
entry.set("tqq9_wmsdetailid", wmsDetailId);
|
||||||
|
entry.set("tqq9_licenseno", licenceCode);
|
||||||
|
entry.set("tqq9_registration", tqq9_registration);
|
||||||
|
entry.set("tqq9_proxyandfactory", tqq9_proxyandfactory);
|
||||||
|
DynamicObjectCollection billentry_lk = entry.getDynamicObjectCollection("billentry_lk");
|
||||||
|
billentry_lk.clear();
|
||||||
|
} else {
|
||||||
|
DataEntityPropertyCollection properties = entry.getDataEntityType().getProperties();
|
||||||
|
// 后续循环复制entry并赋值
|
||||||
|
DynamicObject newEntry = new DynamicObject(dynamicObjectCollection.getDynamicObjectType());
|
||||||
|
for (IDataEntityProperty property : properties) {
|
||||||
|
newEntry.set(property.getName(), entry.get(property.getName()));
|
||||||
|
}
|
||||||
|
newEntry.set("qty", quantity);
|
||||||
|
newEntry.set("baseqty", quantity);
|
||||||
|
newEntry.set("tqq9_goods", tqq9_goodspackage);
|
||||||
|
newEntry.set("producedate", manufactureDate);
|
||||||
|
newEntry.set("expirydate", expirationDate);
|
||||||
|
newEntry.set("lotnumber", batch);
|
||||||
|
newEntry.set("warehouse", bd_warehouse);
|
||||||
|
newEntry.set("tqq9_wmsdetailid", wmsDetailId);
|
||||||
|
newEntry.set("tqq9_licenseno", licenceCode);
|
||||||
|
newEntry.set("tqq9_registration", tqq9_registration);
|
||||||
|
newEntry.set("tqq9_proxyandfactory", tqq9_proxyandfactory);
|
||||||
|
DynamicObjectCollection billentry_lk = newEntry.getDynamicObjectCollection("billentry_lk");
|
||||||
|
billentry_lk.clear();
|
||||||
|
// 处理完新entry后的逻辑(比如加入集合或其他操作)
|
||||||
|
iterator.add(newEntry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue