lc/lc123/cloud/app/plugin/operate/im/OtherInApplyPushOtherInConv...

168 lines
9.5 KiB
Java
Raw Normal View History

package tqq9.lc123.cloud.app.plugin.operate.im;
import com.alibaba.nacos.common.utils.StringUtils;
2025-10-31 10:14:18 +00:00
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
2025-10-31 10:14:18 +00:00
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;
2025-11-28 08:30:59 +00:00
import java.math.RoundingMode;
2025-10-31 10:14:18 +00:00
import java.util.*;
/**
* 其他入库申请下推其他入库
*/
public class OtherInApplyPushOtherInConvertPlugin extends AbstractConvertPlugIn implements Plugin {
private final static Log logger = LogFactory.getLog(OtherInApplyPushOtherInConvertPlugin.class);
private static String OTHERINBILL = "im_otherinbill";
2025-11-17 10:15:54 +00:00
private final static HashMap<String, String> wareTypeMap = new HashMap<String, String>() {{
2025-12-12 09:18:45 +00:00
put("地堆区", "ZC01");
put("存储区", "ZC01");
put("立库区", "ZC01");
put("新仓", "ZC01 ");
put("破损区", "ZC02");
put("零拣区", "ZC02");
put("收货中转", "ZC03");
put("退货中转", "ZC03");
put("虚拟区", "ZC03");
2025-11-17 10:15:54 +00:00
}};
/**
* 入库回传下推写入对应的
* quantity 入库数量
* manufactureDate 生产日期
* expirationDate 失效期
* batch 批次
* registrationCode 注册证号
* licenceCode 生产许可证号
* producer 生产厂商
2025-10-31 10:14:18 +00:00
*
* @param e
*/
@Override
public void afterConvert(AfterConvertEventArgs e) {
super.afterConvert(e);
ExtendedDataEntitySet targetExtDataEntitySet = e.getTargetExtDataEntitySet();
ExtendedDataEntity[] extendedDataEntities = targetExtDataEntitySet.FindByEntityKey(OTHERINBILL);
Map<String, String> variables = this.getOption().getVariables();
for (ExtendedDataEntity extendedDataEntity : extendedDataEntities) {
//采购入库单
DynamicObject dataEntity = extendedDataEntity.getDataEntity();
DynamicObjectCollection dynamicObjectCollection = dataEntity.getDynamicObjectCollection("billentry");
2025-10-31 10:14:18 +00:00
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);
2025-10-31 10:14:18 +00:00
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 = new BigDecimal(jsonMap.get("quantity").toString());//入库数量
2025-10-31 10:14:18 +00:00
String batch = jsonMap.get("batch") != null ? jsonMap.get("batch").toString() : null; // 批次
2025-11-17 10:15:54 +00:00
String toZone = jsonMap.get("toZone") != null ? jsonMap.get("toZone").toString() : null; // 库区
2025-11-24 02:44:01 +00:00
DynamicObject bd_warehouse = null;
if (jsonMap.containsKey("warehouseCode")) {
String warehouseCode = jsonMap.get("warehouseCode").toString();//仓库
if (StringUtils.equals("01", warehouseCode)) {
if (toZone != null) {
String wareNumber = wareTypeMap.get(toZone);
bd_warehouse = BusinessDataServiceHelper.loadSingle("bos_assistantdata_detail", new QFilter[]{new QFilter("number", QCP.equals, wareNumber)});
}
}
2025-11-17 10:15:54 +00:00
}
2025-10-31 10:14:18 +00:00
String wmsDetailId = jsonMap.get("wmsDetailId") != null ? jsonMap.get("wmsDetailId").toString() : null; // WMS分录id
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_registration = BusinessDataServiceHelper.loadSingle("tqq9_registration", new QFilter[]{new QFilter("number", QCP.equals, registrationCode)});
2025-11-24 02:37:46 +00:00
BigDecimal qty = entry.getBigDecimal("qty");//原数量
2025-11-24 02:44:01 +00:00
BigDecimal amount = entry.getBigDecimal("amount");//金额
2025-11-28 08:30:59 +00:00
amount = amount.multiply(quantity).divide(qty, 10, RoundingMode.HALF_UP);//金额
2025-10-31 10:14:18 +00:00
// 处理第一次逻辑
if (i == 0) {
2025-11-24 02:44:01 +00:00
entry.set("amount", amount);
2025-10-31 10:14:18 +00:00
// 第一次直接赋值
entry.set("qty", quantity);
entry.set("baseqty", quantity);
entry.set("producedate", manufactureDate);
entry.set("expirydate", expirationDate);
entry.set("lotnumber", batch);
2025-11-24 02:44:01 +00:00
if (bd_warehouse != null) {
entry.set("tqq9_cksx", bd_warehouse);
2025-11-19 09:32:35 +00:00
}
2025-10-31 10:14:18 +00:00
entry.set("tqq9_wmsdetailid", wmsDetailId);
entry.set("tqq9_licenseno", licenceCode);
entry.set("tqq9_zczh", tqq9_registration);
entry.set("tqq9_cs", producer);
2025-10-31 10:14:18 +00:00
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()));
}
2025-11-24 02:44:01 +00:00
newEntry.set("amount", amount);
2025-10-31 10:14:18 +00:00
newEntry.set("qty", quantity);
newEntry.set("baseqty", quantity);
newEntry.set("producedate", manufactureDate);
newEntry.set("expirydate", expirationDate);
newEntry.set("lotnumber", batch);
2025-11-24 02:44:01 +00:00
if (bd_warehouse != null) {
newEntry.set("tqq9_cksx", bd_warehouse);
2025-11-19 09:32:35 +00:00
}
2025-10-31 10:14:18 +00:00
newEntry.set("tqq9_wmsdetailid", wmsDetailId);
newEntry.set("tqq9_licenseno", licenceCode);
newEntry.set("tqq9_zczh", tqq9_registration);
newEntry.set("tqq9_cs", producer);
2025-10-31 10:14:18 +00:00
DynamicObjectCollection billentry_lk = newEntry.getDynamicObjectCollection("billentry_lk");
billentry_lk.clear();
// 处理完新entry后的逻辑比如加入集合或其他操作
iterator.add(newEntry);
}
}
}
}
}
}
}
}