This commit is contained in:
sez 2025-11-20 11:00:23 +08:00
parent 3a2f2eba72
commit 21cd42d284
1 changed files with 92 additions and 160 deletions

View File

@ -11,7 +11,6 @@ import kd.bos.entity.ExtendedDataEntity;
import kd.bos.entity.ExtendedDataEntitySet; import kd.bos.entity.ExtendedDataEntitySet;
import kd.bos.entity.botp.plugin.AbstractConvertPlugIn; import kd.bos.entity.botp.plugin.AbstractConvertPlugIn;
import kd.bos.entity.botp.plugin.args.AfterConvertEventArgs; import kd.bos.entity.botp.plugin.args.AfterConvertEventArgs;
import kd.bos.entity.botp.runtime.ConvertConst;
import kd.bos.logging.Log; import kd.bos.logging.Log;
import kd.bos.logging.LogFactory; import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QCP; import kd.bos.orm.query.QCP;
@ -59,168 +58,101 @@ public class PurInConvertPlugin extends AbstractConvertPlugIn implements Plugin
super.afterConvert(e); super.afterConvert(e);
ExtendedDataEntitySet targetExtDataEntitySet = e.getTargetExtDataEntitySet(); ExtendedDataEntitySet targetExtDataEntitySet = e.getTargetExtDataEntitySet();
ExtendedDataEntity[] extendedDataEntities = targetExtDataEntitySet.FindByEntityKey(IM_PURINBILL); ExtendedDataEntity[] extendedDataEntities = targetExtDataEntitySet.FindByEntityKey(IM_PURINBILL);
ExtendedDataEntity[] entities = targetExtDataEntitySet.FindByEntityKey(getTgtMainType().getName());
List<DynamicObject> srcRows = (List<DynamicObject>) entities[0].getValue(ConvertConst.ConvExtDataKey_SourceRows);
DynamicObject srcRow = srcRows.get(0);
Object sourceBillPK = e.getFldProperties().get("id").getValue(srcRow);
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(sourceBillPK, "pm_purrefundapplybill");//采购退货申请单
boolean tqq9_isydth = dynamicObject.getBoolean("tqq9_isydth");//是否异地退货
Map<String, String> variables = this.getOption().getVariables(); Map<String, String> variables = this.getOption().getVariables();
if (!tqq9_isydth) { for (ExtendedDataEntity extendedDataEntity : extendedDataEntities) {
for (ExtendedDataEntity extendedDataEntity : extendedDataEntities) { //采购入库单
//采购入库单 DynamicObject dataEntity = extendedDataEntity.getDataEntity();
DynamicObject dataEntity = extendedDataEntity.getDataEntity(); DynamicObjectCollection dynamicObjectCollection = dataEntity.getDynamicObjectCollection("billentry");
DynamicObjectCollection dynamicObjectCollection = dataEntity.getDynamicObjectCollection("billentry"); ListIterator<DynamicObject> iterator = dynamicObjectCollection.listIterator();
ListIterator<DynamicObject> iterator = dynamicObjectCollection.listIterator(); while (iterator.hasNext()) {
while (iterator.hasNext()) { DynamicObject entry = iterator.next();
DynamicObject entry = iterator.next(); String srcbillentryid = entry.getString("srcbillentryid");
String srcbillentryid = entry.getString("srcbillentryid"); //核心单据号一致写入数据
//核心单据号一致写入数据 if (variables.containsKey(srcbillentryid)) {
if (variables.containsKey(srcbillentryid)) { String jsonString = variables.get(srcbillentryid);
String jsonString = variables.get(srcbillentryid); ObjectMapper objectMapper = new ObjectMapper();
ObjectMapper objectMapper = new ObjectMapper(); List<HashMap<String, Object>> jsonList = null;
List<HashMap<String, Object>> jsonList = null; try {
try { jsonList = objectMapper.readValue(jsonString, objectMapper.getTypeFactory().constructCollectionType(List.class, HashMap.class));
jsonList = objectMapper.readValue(jsonString, objectMapper.getTypeFactory().constructCollectionType(List.class, HashMap.class)); } catch (JsonProcessingException ex) {
} catch (JsonProcessingException ex) { throw new RuntimeException(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);
if (null != bd_warehouse) {
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);
if (null != bd_warehouse) {
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);
}
}
}
} }
} if (jsonList != null) {
} dataEntity.set("tqq9_isrebulidlink", true);
} else { for (int i = 0; i < jsonList.size(); i++) {
for (ExtendedDataEntity extendedDataEntity : extendedDataEntities) { HashMap<String, Object> jsonMap = jsonList.get(i);
//采购入库单 String VoucherType = jsonMap.get("VoucherType").toString();//类型
DynamicObject dataEntity = extendedDataEntity.getDataEntity(); Date manufactureDate = null;
DynamicObjectCollection dynamicObjectCollection = dataEntity.getDynamicObjectCollection("billentry"); Date expirationDate = null;
ListIterator<DynamicObject> iterator = dynamicObjectCollection.listIterator(); if (jsonMap.get("manufactureDate") instanceof Long) {
while (iterator.hasNext()) { manufactureDate = new Date((Long) jsonMap.get("manufactureDate")); //生产日期
DynamicObject entry = iterator.next(); }
String srcbillentryid = entry.getString("srcbillentryid"); if (jsonMap.get("expirationDate") instanceof Long) {
//核心单据号一致写入数据 expirationDate = new Date((Long) jsonMap.get("expirationDate")); //生产日期
if (variables.containsKey(srcbillentryid)) { }
String jsonString = variables.get(srcbillentryid); BigDecimal quantity = BigDecimal.ZERO;
ObjectMapper objectMapper = new ObjectMapper(); if (StringUtils.equals("pm_receiptnotice", VoucherType)) {
List<HashMap<String, Object>> jsonList = null; quantity = new BigDecimal(jsonMap.get("quantity").toString());//入库数量
try { } else {
jsonList = objectMapper.readValue(jsonString, objectMapper.getTypeFactory().constructCollectionType(List.class, HashMap.class)); quantity = new BigDecimal(jsonMap.get("quantity").toString()).negate();//入库数量
} catch (JsonProcessingException ex) { }
throw new RuntimeException(ex); String batch = jsonMap.get("batch") != null ? jsonMap.get("batch").toString() : null; // 批次
} String toZone = jsonMap.get("toZone") != null ? jsonMap.get("toZone").toString() : null; // 库区
if (jsonList != null) { DynamicObject bd_warehouse = null;
dataEntity.set("tqq9_isrebulidlink", true); if (toZone != null) {
for (int i = 0; i < jsonList.size(); i++) { String wareNumber = wareTypeMap.get(toZone);
HashMap<String, Object> jsonMap = jsonList.get(i); bd_warehouse = BusinessDataServiceHelper.loadSingle("bd_warehouse", new QFilter[]{new QFilter("number", QCP.equals, wareNumber)});
Object materialId = jsonMap.get("materialId"); }
Object qty = jsonMap.get("qty"); String wmsDetailId = jsonMap.get("wmsDetailId") != null ? jsonMap.get("wmsDetailId").toString() : null; // WMS分录id
Object returnEntryId = jsonMap.get("returnEntryId"); String uniqueCode = jsonMap.get("uniqueCode") != null ? jsonMap.get("uniqueCode").toString() : null; // 商品编码
// BigDecimal price = entry.getBigDecimal("price");//不含税单价 String registrationCode = jsonMap.get("registrationCode") != null ? jsonMap.get("registrationCode").toString() : null; // 注册证号
// BigDecimal priceandtax = entry.getBigDecimal("priceandtax");//含税单价 String licenceCode = jsonMap.get("licenceCode") != null ? jsonMap.get("licenceCode").toString() : null; // 生产许可证号
// 处理第一次逻辑 String producer = jsonMap.get("producer") != null ? jsonMap.get("producer").toString() : null; // 生产厂商
if (i == 0) { 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)});
entry.set("qty", qty); DynamicObject tqq9_proxyandfactory = BusinessDataServiceHelper.loadSingle("tqq9_proxyandfactory", new QFilter[]{new QFilter("number", QCP.equals, producer)});
// BigDecimal amount = // 处理第一次逻辑
//amount 金额 if (i == 0) {
//taxamount 税额 // 第一次直接赋值
//amountandtax 折扣后价税合计 entry.set("qty", quantity);
DynamicObjectCollection billentry_lk = entry.getDynamicObjectCollection("billentry_lk"); entry.set("baseqty", quantity);
billentry_lk.clear(); entry.set("tqq9_goods", tqq9_goodspackage);
} else { entry.set("producedate", manufactureDate);
DataEntityPropertyCollection properties = entry.getDataEntityType().getProperties(); entry.set("expirydate", expirationDate);
// 后续循环复制entry并赋值 entry.set("lotnumber", batch);
DynamicObject newEntry = new DynamicObject(dynamicObjectCollection.getDynamicObjectType()); if (null != bd_warehouse) {
for (IDataEntityProperty property : properties) { entry.set("warehouse", bd_warehouse);
newEntry.set(property.getName(), entry.get(property.getName()));
}
newEntry.set("qty", qty);
DynamicObjectCollection billentry_lk = newEntry.getDynamicObjectCollection("billentry_lk");
billentry_lk.clear();
// 处理完新entry后的逻辑比如加入集合或其他操作
iterator.add(newEntry);
} }
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);
if (null != bd_warehouse) {
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);
} }
} }
} }