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

88 lines
4.5 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package tqq9.lc123.cloud.app.plugin.operate.im;
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.sdk.plugin.Plugin;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
/**
* 采购订单下推收获通知单转换插件
* 退货补货数量修改
*/
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");
ListIterator<DynamicObject> iterator = dynamicObjectCollection.listIterator();
while (iterator.hasNext()) {
DynamicObject entry = iterator.next();
String mainbillentryid = entry.getString("mainbillentryid");
//核心单据号一致,修改补货数量
if (variables.containsKey(mainbillentryid)) {
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);
BigDecimal entry_qty = new BigDecimal(jsonMap.get("qty").toString()).negate();//入库数量
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);
}
}
}
}
}
}
}
}