From 52e09a6b7b7054fc51b9d4bf5f1fbec0a57e60f1 Mon Sep 17 00:00:00 2001
From: cl <1442464845@qq.com>
Date: 星期三, 08 四月 2026 11:37:39 +0800
Subject: [PATCH] 云仓回报调整

---
 rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/CloudWmsReportServiceImpl.java |  175 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 152 insertions(+), 23 deletions(-)

diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/CloudWmsReportServiceImpl.java b/rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/CloudWmsReportServiceImpl.java
index ca1da5c..fbaa4ca 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/CloudWmsReportServiceImpl.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/CloudWmsReportServiceImpl.java
@@ -1,20 +1,26 @@
 package com.vincent.rsf.server.api.service.impl;
 
 import com.vincent.rsf.server.api.config.RemotesInfoProperties;
+import com.vincent.rsf.server.api.controller.erp.params.DapIlcwmsCompletionLine;
+import com.vincent.rsf.server.api.controller.erp.params.DapIlcwmsCompletionRequest;
 import com.vincent.rsf.server.api.controller.erp.params.InOutResultReportParam;
 import com.vincent.rsf.server.api.controller.erp.params.InventoryAdjustReportParam;
 import com.vincent.rsf.server.api.feign.CloudWmsErpFeignClient;
+import com.vincent.rsf.server.api.integration.dap.DapIlcwmsResponseNormalizer;
 import com.vincent.rsf.server.api.service.CloudWmsReportService;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
- * 绔嬪簱渚ц姹備簯浠擄細鍏�/鍑哄簱缁撴灉涓婃姤锛�9.1锛夈�佸簱瀛樿皟鏁翠富鍔ㄤ笂鎶ワ紙9.2锛夈�佺墿鏂欏熀纭�淇℃伅鍚屾銆�
- * 浣跨敤 OpenFeign 璋冪敤锛涘彲閫� HttpEntity(RestTemplate) 鏂瑰紡宸叉敞閲婁繚鐣欍��
+ * 绔嬪簱渚ц姹備簯浠擄細9.1 榧庢嵎 ilcwmsplus 鍏�/鍑哄簱涓ゆ帴鍙o紱9.2 浠嶄负 /api/report/inventoryAdjust锛屾姤鏂囦笌 9.1 鍚屼负 {data:[]}銆�
  */
 @Slf4j
 @Service
@@ -24,16 +30,7 @@
     private RemotesInfoProperties erpApi;
 
     @Autowired
-    private RemotesInfoProperties.ApiInfo erpApiInfo;
-
-    @Autowired
     private CloudWmsErpFeignClient cloudWmsErpFeignClient;
-
-    /**
-     * 鍙�夛細鏀圭敤 HttpEntity(RestTemplate) 璋冪敤浜戜粨鏃跺惎鐢ㄣ��
-     */
-    // @Autowired
-    // private RestTemplate restTemplate;
 
     @Override
     public Map<String, Object> syncMatnrsToCloud(Object body) {
@@ -53,7 +50,17 @@
             log.warn("ErpApi(浜戜粨WMS) 鏈厤缃� host锛岃烦杩� 9.1 鍏�/鍑哄簱缁撴灉涓婃姤锛岃鍗曪細{}", param.getOrderNo());
             return stubSuccess("浜戜粨鍦板潃鏈厤缃紝鏈疄闄呬笂鎶�");
         }
-        return cloudWmsErpFeignClient.reportInOutResult(param);
+        String err = validateDapBase();
+        if (err != null) {
+            return resultMap(400, err, null);
+        }
+        boolean inbound = param.getInbound() == null || Boolean.TRUE.equals(param.getInbound());
+        DapIlcwmsCompletionRequest req = new DapIlcwmsCompletionRequest()
+                .setData(Collections.singletonList(buildInOutLine(param, inbound)));
+        Map<String, Object> raw = inbound
+                ? cloudWmsErpFeignClient.cusInventoryCompletionReport(req)
+                : cloudWmsErpFeignClient.cusOutboundCompletionReport(req);
+        return DapIlcwmsResponseNormalizer.toNotifyFormat(raw);
     }
 
     @Override
@@ -65,7 +72,139 @@
             log.warn("ErpApi(浜戜粨WMS) 鏈厤缃� host锛岃烦杩� 9.2 搴撳瓨璋冩暣涓婃姤锛岀墿鏂欙細{}", param.getMatNr());
             return stubSuccess("浜戜粨鍦板潃鏈厤缃紝鏈疄闄呬笂鎶�");
         }
-        return cloudWmsErpFeignClient.reportInventoryAdjust(param);
+        String err = validateDapBase();
+        if (err != null) {
+            return resultMap(400, err, null);
+        }
+        Integer changeType = param.getChangeType();
+        if (changeType == null) {
+            return resultMap(400, "changeType 涓嶈兘涓虹┖", null);
+        }
+        DapIlcwmsCompletionRequest req = new DapIlcwmsCompletionRequest();
+        if (changeType == 3) {
+            String baseSeq = StringUtils.isNotBlank(param.getDocSeqNo()) ? param.getDocSeqNo() : "1";
+            List<DapIlcwmsCompletionLine> lines = new ArrayList<>(2);
+            lines.add(buildAdjustLine(param, false, true, baseSeq + "-O"));
+            lines.add(buildAdjustLine(param, true, false, baseSeq + "-I"));
+            req.setData(lines);
+        } else if (changeType == 1) {
+            req.setData(Collections.singletonList(buildAdjustLine(param, true, false, null)));
+        } else if (changeType == 2) {
+            req.setData(Collections.singletonList(buildAdjustLine(param, false, true, null)));
+        } else {
+            return resultMap(400, "涓嶆敮鎸佺殑 changeType锛�" + changeType, null);
+        }
+        Map<String, Object> raw = cloudWmsErpFeignClient.reportInventoryAdjust(req);
+        return DapIlcwmsResponseNormalizer.toNotifyFormatFlexible(raw);
+    }
+
+    private DapIlcwmsCompletionLine buildInOutLine(InOutResultReportParam param, boolean inbound) {
+        RemotesInfoProperties.Dap dap = erpApi.getDap();
+        DapIlcwmsCompletionLine line = new DapIlcwmsCompletionLine()
+                .setOrgNo(dap.getOrgNo())
+                .setDocType(inbound ? dap.getDocTypeIn() : dap.getDocTypeOut())
+                .setDocNo(param.getOrderNo())
+                .setDocSeqNo(StringUtils.isNotBlank(param.getLineId()) ? param.getLineId() : "1")
+                .setItemNo(param.getMatNr())
+                .setQty(parseQty(param.getQty()))
+                .setUnitNo(dap.getUnitNo())
+                .setCombinationLotNo(param.getBatch())
+                .setBarcode(resolveBarcode(param));
+        if (inbound) {
+            line.setInWarehouseNo(param.getWareHouseId()).setInCellNo(param.getLocId());
+        } else {
+            line.setOutWarehouseNo(param.getWareHouseId()).setOutCellNo(param.getLocId());
+        }
+        return line;
+    }
+
+    /**
+     * @param fillIn 鏄惁濉叆搴撳偍浣�
+     * @param fillOut 鏄惁濉嚭搴撳偍浣�
+     * @param docSeqOverride 闈炵┖鏃剁敤浣滈」娆★紙绉诲簱绗簩琛岀瓑锛�
+     */
+    private DapIlcwmsCompletionLine buildAdjustLine(InventoryAdjustReportParam param, boolean fillIn, boolean fillOut, String docSeqOverride) {
+        RemotesInfoProperties.Dap dap = erpApi.getDap();
+        String docType = resolveAdjustDocType(param, dap);
+        String docNo = StringUtils.isNotBlank(param.getDocNo()) ? param.getDocNo() : "ADJ";
+        String docSeq = docSeqOverride != null ? docSeqOverride
+                : (StringUtils.isNotBlank(param.getDocSeqNo()) ? param.getDocSeqNo() : "1");
+        String unit = StringUtils.isNotBlank(param.getUnitNo()) ? param.getUnitNo() : dap.getUnitNo();
+        DapIlcwmsCompletionLine line = new DapIlcwmsCompletionLine()
+                .setOrgNo(dap.getOrgNo())
+                .setDocType(docType)
+                .setDocNo(docNo)
+                .setDocSeqNo(docSeq)
+                .setItemNo(param.getMatNr())
+                .setQty(parseQty(param.getQty()))
+                .setUnitNo(unit)
+                .setCombinationLotNo(param.getBatch())
+                .setBarcode(resolveAdjustBarcode(param));
+        if (fillIn) {
+            line.setInWarehouseNo(param.getWareHouseId());
+            line.setInCellNo(StringUtils.isNotBlank(param.getTargetLocId()) ? param.getTargetLocId() : param.getSourceLocId());
+        }
+        if (fillOut) {
+            line.setOutWarehouseNo(param.getWareHouseId());
+            line.setOutCellNo(StringUtils.isNotBlank(param.getSourceLocId()) ? param.getSourceLocId() : param.getTargetLocId());
+        }
+        return line;
+    }
+
+    private static String resolveAdjustDocType(InventoryAdjustReportParam param, RemotesInfoProperties.Dap dap) {
+        if (StringUtils.isNotBlank(param.getDocType())) {
+            return param.getDocType();
+        }
+        Integer ct = param.getChangeType();
+        if (ct != null && ct == 2) {
+            return dap.getDocTypeOut();
+        }
+        if (ct != null && ct == 3) {
+            return dap.getDocTypeAdj();
+        }
+        return dap.getDocTypeIn();
+    }
+
+    private static String resolveBarcode(InOutResultReportParam param) {
+        if (StringUtils.isNotBlank(param.getBarcode())) {
+            return param.getBarcode();
+        }
+        if (StringUtils.isNotBlank(param.getPalletId())) {
+            return param.getPalletId();
+        }
+        if (param.getMatNr() != null && param.getLocId() != null) {
+            return param.getMatNr() + ":" + param.getLocId();
+        }
+        return param.getMatNr();
+    }
+
+    private static String resolveAdjustBarcode(InventoryAdjustReportParam param) {
+        if (StringUtils.isNotBlank(param.getBarcode())) {
+            return param.getBarcode();
+        }
+        if (StringUtils.isNotBlank(param.getPalletId())) {
+            return param.getPalletId();
+        }
+        return param.getMatNr();
+    }
+
+    private static Double parseQty(String q) {
+        if (StringUtils.isBlank(q)) {
+            return 0d;
+        }
+        try {
+            return Double.parseDouble(q.trim());
+        } catch (NumberFormatException e) {
+            return 0d;
+        }
+    }
+
+    private String validateDapBase() {
+        RemotesInfoProperties.Dap d = erpApi.getDap();
+        if (d == null || StringUtils.isBlank(d.getOrgNo())) {
+            return "鏈厤缃� platform.erp.dap.org-no";
+        }
+        return null;
     }
 
     private boolean isCloudWmsConfigured() {
@@ -86,14 +225,4 @@
         map.put("data", data);
         return map;
     }
-
-    // ========== 鍙�夛細HttpEntity(RestTemplate) 鏂瑰紡锛堝綋鍓嶆湭浣跨敤锛� ==========
-    // 鍚敤姝ラ锛�1锛夊彇娑堜笂鏂� restTemplate 鐨� @Autowired 娉ㄥ叆锛�
-    // 2锛夊彇娑堜笅闈㈡暣娈垫敞閲婏紝鎭㈠ buildUrl銆乸ostToCloudWms銆乸arseResponse 鏂规硶鍙� OBJECT_MAPPER锛�
-    // 3锛夊湪 syncMatnrsToCloud/reportInOutResult/reportInventoryAdjust 涓敼涓猴細String url = buildUrl(erpApiInfo.getXxxPath()); if (url == null) return stubSuccess(...); return postToCloudWms(url, body);
-    //
-    // private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
-    // private String buildUrl(String path) { ... }
-    // private Map<String, Object> postToCloudWms(String url, Object body) { HttpHeaders headers = ...; HttpEntity<Object> entity = new HttpEntity<>(body, headers); ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class); return parseResponse(response.getBody()); }
-    // private Map<String, Object> parseResponse(String json) { ... }
 }

--
Gitblit v1.9.1