2025-08-12 03:42:59 +00:00
|
|
|
|
package tqq9.lc123.cloud.app.plugin.operate.im;
|
|
|
|
|
|
|
2025-10-31 10:14:18 +00:00
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
2025-08-12 03:42:59 +00:00
|
|
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
|
|
|
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
2025-11-07 04:42:48 +00:00
|
|
|
|
import kd.bos.dataentity.metadata.IDataEntityProperty;
|
|
|
|
|
|
import kd.bos.dataentity.metadata.clr.DataEntityPropertyCollection;
|
2025-08-12 03:42:59 +00:00
|
|
|
|
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.sdk.plugin.Plugin;
|
|
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
2025-10-31 10:14:18 +00:00
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
import java.util.List;
|
2025-11-07 04:42:48 +00:00
|
|
|
|
import java.util.ListIterator;
|
2025-08-12 03:42:59 +00:00
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2025-09-09 08:38:22 +00:00
|
|
|
|
* 采购订单下推收获通知单转换插件
|
2025-08-12 03:42:59 +00:00
|
|
|
|
* 退货补货数量修改
|
|
|
|
|
|
*/
|
|
|
|
|
|
public class PurOrderPushReceiptNoticePlugin extends AbstractConvertPlugIn implements Plugin {
|
|
|
|
|
|
private final static Log logger = LogFactory.getLog(PurOrderPushReceiptNoticePlugin.class);
|
|
|
|
|
|
private static String RECEIPTNOTICE = "pm_receiptnotice";
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void afterConvert(AfterConvertEventArgs e) {
|
|
|
|
|
|
super.afterConvert(e);
|
|
|
|
|
|
ExtendedDataEntitySet targetExtDataEntitySet = e.getTargetExtDataEntitySet();
|
|
|
|
|
|
ExtendedDataEntity[] extendedDataEntities = targetExtDataEntitySet.FindByEntityKey(RECEIPTNOTICE);
|
|
|
|
|
|
Map<String, String> variables = this.getOption().getVariables();
|
|
|
|
|
|
for (ExtendedDataEntity extendedDataEntity : extendedDataEntities) {
|
|
|
|
|
|
//收货通知单
|
|
|
|
|
|
DynamicObject dataEntity = extendedDataEntity.getDataEntity();
|
|
|
|
|
|
DynamicObjectCollection dynamicObjectCollection = dataEntity.getDynamicObjectCollection("billentry");
|
2025-11-07 04:42:48 +00:00
|
|
|
|
ListIterator<DynamicObject> iterator = dynamicObjectCollection.listIterator();
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
|
|
DynamicObject entry = iterator.next();
|
|
|
|
|
|
String mainbillentryid = entry.getString("mainbillentryid");
|
2025-08-12 03:42:59 +00:00
|
|
|
|
//核心单据号一致,修改补货数量
|
|
|
|
|
|
if (variables.containsKey(mainbillentryid)) {
|
2025-10-31 10:14:18 +00:00
|
|
|
|
String jsonString = variables.get(mainbillentryid);
|
|
|
|
|
|
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) {
|
|
|
|
|
|
for (int i = 0; i < jsonList.size(); i++) {
|
|
|
|
|
|
HashMap<String, Object> jsonMap = jsonList.get(i);
|
2025-11-03 08:25:12 +00:00
|
|
|
|
BigDecimal entry_qty = new BigDecimal(jsonMap.get("qty").toString()).negate();//入库数量
|
2025-11-07 04:42:48 +00:00
|
|
|
|
if (i == 0) {
|
|
|
|
|
|
entry.set("qty", entry_qty);//数量
|
|
|
|
|
|
entry.set("baseqty", entry_qty);//基本数量
|
|
|
|
|
|
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()));
|
|
|
|
|
|
}
|
|
|
|
|
|
entry.set("qty", entry_qty);//数量
|
|
|
|
|
|
entry.set("baseqty", entry_qty);//基本数量
|
|
|
|
|
|
DynamicObjectCollection billentry_lk = newEntry.getDynamicObjectCollection("billentry_lk");
|
|
|
|
|
|
billentry_lk.clear();
|
|
|
|
|
|
// 处理完新entry后的逻辑(比如加入集合或其他操作)
|
|
|
|
|
|
iterator.add(newEntry);
|
|
|
|
|
|
}
|
2025-10-31 10:14:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-12 03:42:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|