收货通知单待上架查询

This commit is contained in:
sez 2025-10-27 15:30:18 +08:00
parent 4c83d98db0
commit 2c18180a26
4 changed files with 177 additions and 118 deletions

View File

@ -0,0 +1,116 @@
package tqq9.lc123.cloud.app.plugin.operate.pm;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.args.AfterOperationArgs;
import kd.bos.exception.KDBizException;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import org.apache.commons.lang3.StringUtils;
import tqq9.lc123.cloud.app.plugin.utils.ConfigUtils;
import tqq9.lc123.cloud.app.plugin.utils.HttpRequestUtils;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class PmReceiptNoticeOpPlugin extends AbstractOperationServicePlugIn {
private final static Log logger = LogFactory.getLog(PmReceiptNoticeOpPlugin.class);
@Override
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
super.afterExecuteOperationTransaction(e);
DynamicObject[] dataEntities1 = e.getDataEntities();
if (null == dataEntities1 || dataEntities1.length == 0) {
throw new KDBizException("请至少选择一条数据");
} else {
for (DynamicObject dataEntity : dataEntities1) {
dataEntity = BusinessDataServiceHelper.loadSingle(dataEntity.getLong("id"), "pm_receiptnotice");
String ownerCode = "LICHI";
String billno = dataEntity.getString("billno");
String warehouseCode = null;
DynamicObjectCollection billentry = dataEntity.getDynamicObjectCollection("billentry");
for (DynamicObject entry : billentry) {
DynamicObject warehouse = entry.getDynamicObject("warehouse");
if (null != warehouse) {
warehouseCode = warehouse.getString("number");
}
}
String ttx_customerId = ConfigUtils.getThirdConfigByNumber("Ttx_CustomerId");
String ttx_mainUrl = ConfigUtils.getThirdConfigByNumber("Ttx_MainURL");
Map<String, String> headMap = new HashMap<>();
Map<String, Object> request = new HashMap<>();
request.put("receiptCode", billno);
request.put("ownerCode", ownerCode);
request.put("warehouseCode", warehouseCode);
Map<String, Object> finalMap = new HashMap<>();
finalMap.put("request", request);
StringBuilder xmlBuilder = new StringBuilder();
xmlBuilder.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
HttpRequestUtils.buildXml(xmlBuilder, finalMap, 0);
logger.info("待上架库存查询接口xml" + xmlBuilder);
ttx_mainUrl = ttx_mainUrl + "?method=checkInReport.query&v=2.0&format=xml&customerId=" + ttx_customerId;
try {
String response = HttpRequestUtils.postXml(ttx_mainUrl, xmlBuilder.toString(), headMap);
logger.info("待上架库存查询接口结果:" + response);
if (StringUtils.isNotBlank(response)) {
JSONObject resJSON = HttpRequestUtils.xmlToJson(response);
if (null != resJSON) {
JSONObject responseJson = resJSON.getJSONObject("response");
if (null != responseJson) {
String flag = responseJson.getString("flag");
String code = responseJson.getString("code");
JSONObject containerDetail = responseJson.getJSONObject("containerDetail");
if (null != containerDetail && "success".equals(flag) && "200".equals(code)) {
Map<String, Integer> result = new HashMap<>();
JSONObject items = responseJson.getJSONObject("items");
if (null != items) {
JSONArray jsonArray = items.getJSONArray("item");
if (null != jsonArray && jsonArray.size() > 0) {
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject item = jsonArray.getJSONObject(i);
String erpOrderLineNum = item.getString("erpOrderLineNum").replace("\"", "");//行号
int quantity = item.getIntValue("quantity");//数量
if (result.containsKey(erpOrderLineNum)) {
int currentSum = result.get(erpOrderLineNum);
result.put(erpOrderLineNum, currentSum + quantity);
} else {
result.put(erpOrderLineNum, quantity);
}
}
}
}
if (result.size() > 0) {
for (DynamicObject entry : billentry) {
String entryId = String.valueOf(entry.getLong("id"));
if (result.containsKey(entryId)) {
entry.set("tqq9_ckqty", result.get(entryId));
}
}
SaveServiceHelper.save(new DynamicObject[]{dataEntity});
}
}
}
}
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
}
}

View File

@ -106,7 +106,7 @@ public class WmsScsSyncOpPlugin extends AbstractOperationServicePlugIn {
logger.info("wms生产商同步——request" + request); logger.info("wms生产商同步——request" + request);
StringBuilder xmlBuilder = new StringBuilder(); StringBuilder xmlBuilder = new StringBuilder();
xmlBuilder.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); xmlBuilder.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
buildXml(xmlBuilder, finalMap, 0); HttpRequestUtils.buildXml(xmlBuilder, finalMap, 0);
logger.info("wms生产商同步——xml" + xmlBuilder); logger.info("wms生产商同步——xml" + xmlBuilder);
HashMap<String, String> headMap = new HashMap<>(); HashMap<String, String> headMap = new HashMap<>();
try { try {
@ -119,63 +119,5 @@ public class WmsScsSyncOpPlugin extends AbstractOperationServicePlugIn {
} }
} }
private static void buildXml(StringBuilder xmlBuilder, Map<String, Object> map, int indent) {
String indentStr = createIndent(indent);
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (value instanceof Map) {
// 处理嵌套Map
xmlBuilder.append(indentStr).append("<").append(key).append(">\n");
buildXml(xmlBuilder, (Map<String, Object>) value, indent + 1);
xmlBuilder.append(indentStr).append("</").append(key).append(">\n");
} else if (value instanceof List) {
// 处理List
List<?> list = (List<?>) value;
for (Object item : list) {
if (item instanceof Map) {
xmlBuilder.append(indentStr).append("<").append(key).append(">\n");
buildXml(xmlBuilder, (Map<String, Object>) item, indent + 1);
xmlBuilder.append(indentStr).append("</").append(key).append(">\n");
} else {
xmlBuilder.append(indentStr).append("<").append(key).append(">")
.append(escapeXml(item.toString()))
.append("</").append(key).append(">\n");
}
}
} else {
// 处理普通值
if (value == null) {
xmlBuilder.append(indentStr).append("<").append(key).append("/>\n");
} else {
xmlBuilder.append(indentStr).append("<").append(key).append(">")
.append(escapeXml(value.toString()))
.append("</").append(key).append(">\n");
}
}
}
}
/**
* XML特殊字符转义
*/
private static String escapeXml(String text) {
if (text == null) return "";
return text.replace("&", "&amp;")
.replace("<", "&lt;")
.replace(">", "&gt;")
.replace("\"", "&quot;")
.replace("'", "&apos;");
}
// 自定义缩进方法
private static String createIndent(int indent) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < indent; i++) {
sb.append(" "); // 4个空格
}
return sb.toString();
}
} }

View File

@ -140,7 +140,7 @@ public class WmsZczSyncOpPlugin extends AbstractOperationServicePlugIn {
logger.info("wms注册证同步request" + request); logger.info("wms注册证同步request" + request);
StringBuilder xmlBuilder = new StringBuilder(); StringBuilder xmlBuilder = new StringBuilder();
xmlBuilder.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); xmlBuilder.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
buildXml(xmlBuilder, finalMap, 0); HttpRequestUtils.buildXml(xmlBuilder, finalMap, 0);
logger.info("wms注册证同步xml" + xmlBuilder); logger.info("wms注册证同步xml" + xmlBuilder);
HashMap<String, String> headMap = new HashMap<>(); HashMap<String, String> headMap = new HashMap<>();
try { try {
@ -153,64 +153,6 @@ public class WmsZczSyncOpPlugin extends AbstractOperationServicePlugIn {
} }
} }
private static void buildXml(StringBuilder xmlBuilder, Map<String, Object> map, int indent) {
String indentStr = createIndent(indent);
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (value instanceof Map) {
// 处理嵌套Map
xmlBuilder.append(indentStr).append("<").append(key).append(">\n");
buildXml(xmlBuilder, (Map<String, Object>) value, indent + 1);
xmlBuilder.append(indentStr).append("</").append(key).append(">\n");
} else if (value instanceof List) {
// 处理List
List<?> list = (List<?>) value;
for (Object item : list) {
if (item instanceof Map) {
xmlBuilder.append(indentStr).append("<").append(key).append(">\n");
buildXml(xmlBuilder, (Map<String, Object>) item, indent + 1);
xmlBuilder.append(indentStr).append("</").append(key).append(">\n");
} else {
xmlBuilder.append(indentStr).append("<").append(key).append(">")
.append(escapeXml(item.toString()))
.append("</").append(key).append(">\n");
}
}
} else {
// 处理普通值
if (value == null) {
xmlBuilder.append(indentStr).append("<").append(key).append("/>\n");
} else {
xmlBuilder.append(indentStr).append("<").append(key).append(">")
.append(escapeXml(value.toString()))
.append("</").append(key).append(">\n");
}
}
}
}
/**
* XML特殊字符转义
*/
private static String escapeXml(String text) {
if (text == null) return "";
return text.replace("&", "&amp;")
.replace("<", "&lt;")
.replace(">", "&gt;")
.replace("\"", "&quot;")
.replace("'", "&apos;");
}
// 自定义缩进方法
private static String createIndent(int indent) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < indent; i++) {
sb.append(" "); // 4个空格
}
return sb.toString();
}
} }

View File

@ -418,4 +418,63 @@ public class HttpRequestUtils {
} }
public static void buildXml(StringBuilder xmlBuilder, Map<String, Object> map, int indent) {
String indentStr = createIndent(indent);
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (value instanceof Map) {
// 处理嵌套Map
xmlBuilder.append(indentStr).append("<").append(key).append(">\n");
buildXml(xmlBuilder, (Map<String, Object>) value, indent + 1);
xmlBuilder.append(indentStr).append("</").append(key).append(">\n");
} else if (value instanceof List) {
// 处理List
List<?> list = (List<?>) value;
for (Object item : list) {
if (item instanceof Map) {
xmlBuilder.append(indentStr).append("<").append(key).append(">\n");
buildXml(xmlBuilder, (Map<String, Object>) item, indent + 1);
xmlBuilder.append(indentStr).append("</").append(key).append(">\n");
} else {
xmlBuilder.append(indentStr).append("<").append(key).append(">")
.append(escapeXml(item.toString()))
.append("</").append(key).append(">\n");
}
}
} else {
// 处理普通值
if (value == null) {
xmlBuilder.append(indentStr).append("<").append(key).append("/>\n");
} else {
xmlBuilder.append(indentStr).append("<").append(key).append(">")
.append(escapeXml(value.toString()))
.append("</").append(key).append(">\n");
}
}
}
}
/**
* XML特殊字符转义
*/
public static String escapeXml(String text) {
if (text == null) return "";
return text.replace("&", "&amp;")
.replace("<", "&lt;")
.replace(">", "&gt;")
.replace("\"", "&quot;")
.replace("'", "&apos;");
}
// 自定义缩进方法
public static String createIndent(int indent) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < indent; i++) {
sb.append(" "); // 4个空格
}
return sb.toString();
}
} }