From b003a49794f49a329e2702918ecfc8d14b371d0d Mon Sep 17 00:00:00 2001
From: chen.lin <1442464845@qq.com>
Date: 星期三, 04 三月 2026 14:51:25 +0800
Subject: [PATCH] 云仓WMS接口流程

---
 rsf-open-api/src/main/java/com/vincent/rsf/openApi/service/impl/WmsErpServiceImpl.java |  455 ++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 327 insertions(+), 128 deletions(-)

diff --git a/rsf-open-api/src/main/java/com/vincent/rsf/openApi/service/impl/WmsErpServiceImpl.java b/rsf-open-api/src/main/java/com/vincent/rsf/openApi/service/impl/WmsErpServiceImpl.java
index 8688b10..89571c8 100644
--- a/rsf-open-api/src/main/java/com/vincent/rsf/openApi/service/impl/WmsErpServiceImpl.java
+++ b/rsf-open-api/src/main/java/com/vincent/rsf/openApi/service/impl/WmsErpServiceImpl.java
@@ -10,9 +10,14 @@
 import com.vincent.rsf.openApi.config.PlatformProperties;
 import com.vincent.rsf.openApi.entity.constant.WmsConstant;
 import com.vincent.rsf.openApi.entity.dto.CommonResponse;
+import com.vincent.rsf.openApi.entity.dto.ErpCommonResponse;
+import com.vincent.rsf.openApi.entity.dto.ResultData;
 import com.vincent.rsf.openApi.entity.dto.OrderDto;
 import com.vincent.rsf.openApi.entity.params.ErpMatnrParms;
 import com.vincent.rsf.openApi.entity.params.ErpOpParams;
+import com.vincent.rsf.openApi.entity.params.ReportParams;
+import com.vincent.rsf.openApi.entity.params.WmsOrderItemParam;
+import com.vincent.rsf.openApi.feign.wms.WmsServerFeignClient;
 import com.vincent.rsf.openApi.service.WmsErpService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -24,6 +29,7 @@
 import org.springframework.web.client.RestTemplate;
 
 import java.util.*;
+import java.util.stream.Collectors;
 
 @Slf4j
 @Service("WmsErpService")
@@ -33,7 +39,51 @@
     private PlatformProperties.WmsApi wmsApi;
 
     @Autowired
+    private PlatformProperties.ErpApi erpApi;
+
+    @Autowired
     private RestTemplate restTemplate;
+
+    @Autowired
+    private WmsServerFeignClient wmsServerFeignClient;
+
+    /**
+     * 鍙�夛細鏀圭敤 OpenFeign 璋冪敤 ERP 涓婃姤锛堣鍗曞畬鎴愬洖鍐欍�佺洏鐐瑰樊寮備慨鏀癸級鏃跺惎鐢ㄣ��
+     * 1锛夊鍔� import锛歝om.vincent.rsf.openApi.feign.erp.ErpReportFeignClient锛�
+     * 2锛夊彇娑堜笅闈袱琛屾敞閲婏紝娉ㄥ叆 ErpReportFeignClient锛�
+     * 3锛夊湪 reportOrders銆乺eportCheck 涓敞閲婃帀鏈柟娉曞唴鏁存 HttpEntity/restTemplate 璇锋眰锛屾敼涓轰娇鐢ㄤ笅闈㈡敞閲婁腑鐨� erpReportFeignClient.report(params) 鍙婂搷搴旇В鏋愰�昏緫銆�
+     */
+    // @Autowired
+    // private ErpReportFeignClient erpReportFeignClient;
+
+    /**
+     * 灏� Feign 杩斿洖鐨� Map锛堟垨 R锛夎浆涓� CommonResponse锛岀鍚� 8.2.3锛歝ode銆乵sg銆乨ata锛堝惈 result锛夈��
+     * 鏃犳硶瑙f瀽鎴栭潪鎴愬姛锛坈ode!=200锛夋椂鐩存帴 throw CoolException锛屼笉杩斿洖閿欒浣撱��
+     */
+    private CommonResponse mapToCommonResponse(Map<String, Object> map) {
+        if (map == null) {
+            throw new CoolException("璇锋眰澶辫触");
+        }
+        Object c = map.get("code");
+        int code = c instanceof Number ? ((Number) c).intValue() : 500;
+        if (code != 200) {
+            String msg = map.get("msg") != null ? map.get("msg").toString() : "璇锋眰澶辫触";
+            throw new CoolException(msg);
+        }
+        CommonResponse r = new CommonResponse();
+        r.setCode(200);
+        r.setMsg(map.get("msg") != null ? map.get("msg").toString() : "鎿嶄綔鎴愬姛");
+        Object rawData = map.get("data");
+        if (rawData == null) {
+            r.setData(ResultData.success());
+        } else {
+            Map<String, Object> dataModel = new LinkedHashMap<>();
+            dataModel.put("result", ResultData.SUCCESS);
+            dataModel.put("data", rawData);
+            r.setData(dataModel);
+        }
+        return r;
+    }
 
     /**
      * 鑾峰彇璁㈠崟鏄庣粏
@@ -46,161 +96,310 @@
         if (Objects.isNull(params.getOrderNo()) || params.getOrderNo().isEmpty()) {
             throw new CoolException("璁㈠崟鍙蜂笉鑳戒负绌猴紒锛�");
         }
-        /**WMS鍩虹閰嶇疆閾炬帴*/
-        String rcsUrl = wmsApi.getHost() + ":" + wmsApi.getPort() + WmsConstant.QUERY_ORDER_AND_DETLS;
-        log.info("鏌ヨ璁㈠崟淇℃伅鍙婄姸鎬侊細 {}锛� 璇锋眰鍙傛暟锛� {}", rcsUrl, JSONObject.toJSONString(params));
-        HttpHeaders headers = new HttpHeaders();
-        headers.add("Content-Type", "application/json");
-        headers.add("api-version", "v2.0");
-        HttpEntity httpEntity = new HttpEntity(params, headers);
-        ResponseEntity<String> exchange = restTemplate.exchange(rcsUrl, HttpMethod.POST, httpEntity, String.class);
-        log.info("鏌ヨ鍝嶅簲缁撴灉锛� {}", exchange);
-        if (Objects.isNull(exchange.getBody())) {
-            throw new CoolException("鏌ヨ澶辫触锛侊紒");
-        } else {
-            ObjectMapper objectMapper = new ObjectMapper();
-            objectMapper.coercionConfigDefaults().setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
-            try {
-                CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
-                if (result.getCode() == 200) {
-                    JSONObject object = JSONObject.parseObject(JSONObject.toJSONString(result.getData()));
-                    OrderDto dto = new OrderDto();
-                    dto.setOrderNo(object.getString("code")).setAnfme(object.getDouble("anfme")).setType(object.getString("type")).setWkType(object.getString("wkType")).setQty(object.getDouble("qty")).setPoCode(object.getString("poCode")).setExceStatus(object.getShort("exceStatus")).setWorkQty(object.getDouble("workQty"));
-                    result.setData(dto);
-                    return result;
-                } else {
-                    throw new CoolException("鏌ヨ澶辫触锛侊紒");
-                }
-            } catch (JsonProcessingException e) {
-                throw new CoolException(e.getMessage());
+        log.info("鏌ヨ璁㈠崟淇℃伅鍙婄姸鎬侊紝璇锋眰鍙傛暟锛� {}", JSONObject.toJSONString(params));
+        Map<String, Object> res = wmsServerFeignClient.queryOrderAndDetls(params);
+        CommonResponse result = mapToCommonResponse(res);
+        if (result.getCode() == 200 && result.getData() instanceof Map) {
+            @SuppressWarnings("unchecked")
+            Map<String, Object> dataModel = (Map<String, Object>) result.getData();
+            Object inner = dataModel.get("data");
+            if (inner != null) {
+                JSONObject object = JSONObject.parseObject(JSONObject.toJSONString(inner));
+                OrderDto dto = new OrderDto();
+                dto.setOrderNo(object.getString("code"))
+                        .setAnfme(object.getDouble("anfme"))
+                        .setType(object.getString("type"))
+                        .setWkType(object.getString("wkType"))
+                        .setQty(object.getDouble("qty"))
+                        .setPoCode(object.getString("poCode"))
+                        .setExceStatus(object.getShort("exceStatus"))
+                        .setWorkQty(object.getDouble("workQty"));
+                Map<String, Object> wrap = new LinkedHashMap<>();
+                wrap.put("result", ResultData.SUCCESS);
+                wrap.put("data", dto);
+                result.setData(wrap);
             }
+        }
+        return result;
+    }
+
+    /**
+     * 鏂板鍗曟嵁锛堝吋瀹逛慨鏀广�佸彇娑堬級锛�8.3 鍏�/鍑哄簱閫氱煡鍗曚笅鍙戙�俹perateType=3 鏃舵寜鍙栨秷澶勭悊銆�
+     * 浠� 8.3 鏂囨。瀛楁涓轰富锛岃浆鍙戠珛搴撴椂鏄犲皠涓烘湇鍔$ SyncOrderParams 瀛楁銆�
+     */
+    @Override
+    public CommonResponse addOrUpdateOrder(ErpOpParams params) {
+        if (Objects.isNull(params.getOrderNo()) || params.getOrderNo().isEmpty()) {
+            throw new CoolException("璁㈠崟鍙蜂笉鑳戒负绌猴紒锛�");
+        }
+        if (Integer.valueOf(3).equals(params.getOperateType())) {
+            log.info("order/add 鏀跺埌 operateType=3锛岃蛋缁熶竴鍙栨秷閫昏緫锛� {}", params.getOrderNo());
+            return doCancel(params);
+        }
+        if (params.getOrderInternalCode() == null || params.getOrderInternalCode().trim().isEmpty()) {
+            throw new CoolException("鍗曟嵁鍐呯爜涓嶈兘涓虹┖锛侊紒");
+        }
+        Map<String, Object> mapParams = toServerOrderMap(params);
+        List<Map<String, Object>> maps = Collections.singletonList(mapParams);
+        log.info("鏂板/淇敼鍗曟嵁锛岃姹傚弬鏁帮細 {}", JSONArray.toJSONString(maps));
+        Map<String, Object> res = wmsServerFeignClient.updateOrderDetls(maps);
+        CommonResponse r = mapToCommonResponse(res);
+        // 8.3.3锛歞ata 浠呭惈 result锛屼笉杩斿洖涓氬姟杞借嵎
+        r.setData(ResultData.success());
+        return r;
+    }
+
+    /** 8.3 鍙傛暟杞负绔嬪簱 SyncOrderParams 缁撴瀯锛坥rderNo/type/wkType/anfme/arrTime/orderItems 绛夛級 */
+    private Map<String, Object> toServerOrderMap(ErpOpParams params) {
+        Map<String, Object> m = new HashMap<>();
+        m.put("orderNo", params.getOrderNo());
+        m.put("orderInternalCode", params.getOrderInternalCode());
+        m.put("stationId", params.getStationId());
+        m.put("wkType", params.getWkType());
+        m.put("type", params.getOrderType() != null ? String.valueOf(params.getOrderType()) : null);
+        m.put("orderId", params.getOrderId());
+        m.put("operateType", params.getOperateType());
+        double anfmeSum = 0;
+        if (params.getOrderItems() != null) {
+            List<Map<String, Object>> items = params.getOrderItems().stream()
+                    .map(this::toServerOrderItemMap)
+                    .collect(Collectors.toList());
+            m.put("orderItems", items);
+            for (WmsOrderItemParam item : params.getOrderItems()) {
+                anfmeSum += parseAnfme(item.getAnfme());
+            }
+        } else {
+            m.put("orderItems", Collections.emptyList());
+        }
+        m.put("anfme", anfmeSum);
+        if (params.getBusinessTime() != null) {
+            m.put("arrTime", params.getBusinessTime());
+        } else if (params.getCreateTime() != null) {
+            m.put("arrTime", params.getCreateTime());
+        }
+        return m;
+    }
+
+    private Map<String, Object> toServerOrderItemMap(WmsOrderItemParam item) {
+        Map<String, Object> m = new HashMap<>();
+        m.put("matnr", item.getMatNr());
+        m.put("maktx", item.getMakTx());
+        m.put("platItemId", item.getLineId());
+        m.put("anfme", parseAnfme(item.getAnfme()));
+        m.put("spec", item.getSpec());
+        m.put("model", item.getModel());
+        m.put("unit", item.getUnit());
+        m.put("batch", item.getBatch());
+        m.put("planNo", item.getPlanNo());
+        m.put("palletId", item.getPalletId());
+        m.put("targetWareHouseId", item.getTargetWareHouseId());
+        m.put("sourceWareHouseId", item.getSourceWareHouseId());
+        return m;
+    }
+
+    private static double parseAnfme(String anfme) {
+        if (anfme == null || anfme.trim().isEmpty()) {
+            return 0;
+        }
+        try {
+            return Double.parseDouble(anfme.trim());
+        } catch (NumberFormatException e) {
+            return 0;
         }
     }
 
     /**
-     * 璁㈠崟淇敼
+     * 鍙栨秷璁㈠崟/鍙栨秷鍗曟嵁銆備笌 /order/add锛坥perateType=3锛夊叡鐢ㄥ悓涓�濂楀彇娑堥�昏緫锛岃浆鍙戠珛搴� sync/orders/delete銆�
+     */
+    @Override
+    public CommonResponse orderCancel(ErpOpParams params) {
+        if (Objects.isNull(params.getOrderNo()) || params.getOrderNo().isEmpty()) {
+            throw new CoolException("璁㈠崟鍙蜂笉鑳戒负绌猴紒锛�");
+        }
+        return doCancel(params);
+    }
+
+    /** 缁熶竴鍙栨秷閫昏緫锛�/order/add(operateType=3) 涓� /order/cancel銆�/order/del 鍧囪蛋姝ゆ柟娉曪紱8.3.3 data 浠呭惈 result */
+    private CommonResponse doCancel(ErpOpParams params) {
+        log.info("鍙栨秷鍗曟嵁锛岃姹傚弬鏁帮細 {}", JSONObject.toJSONString(params));
+        Map<String, Object> one = new HashMap<>();
+        one.put("orderNo", params.getOrderNo());
+        one.put("orderItems", params.getOrderItems() != null ? params.getOrderItems().stream()
+                .map(this::toServerOrderItemMap)
+                .collect(Collectors.toList()) : Collections.emptyList());
+        Map<String, Object> res = wmsServerFeignClient.orderDel(Collections.singletonList(one));
+        CommonResponse r = mapToCommonResponse(res);
+        r.setData(ResultData.success());
+        return r;
+    }
+
+    /**
+     * 鐗╂枡淇℃伅淇敼
      *
      * @param params
      * @return
      */
     @Override
-    public CommonResponse updateOrderDetl(ErpOpParams params) {
-        if (Objects.isNull(params.getOrderNo()) || params.getOrderNo().isEmpty()) {
-            throw new CoolException("璁㈠崟鍙蜂笉鑳戒负绌猴紒锛�");
-        }
-        /**WMS鍩虹閰嶇疆閾炬帴*/
-        String wmsUrl = wmsApi.getHost() + ":" + wmsApi.getPort() + WmsConstant.MODIFY_ORDER_DETLS;
-        HttpHeaders headers = new HttpHeaders();
-        headers.add("Content-Type", "application/json");
-        headers.add("api-version", "v2.0");
-
-        List<Map<String, Object>> maps = new ArrayList<>();
-        Map<String, Object> mapParams = new HashMap<>();
-        mapParams.put("orderNo", params.getOrderNo());
-        mapParams.put("anfme", params.getAnfme());
-        mapParams.put("type", params.getType());
-        mapParams.put("wkType", params.getWkType());
-        mapParams.put("exceStatus", params.getExceStatus());
-        mapParams.put("orderItems", params.getOrderItems());
-        maps.add(mapParams);
-        log.info("淇敼璁㈠崟淇℃伅鍙婄姸鎬侊細 {}锛� 璇锋眰鍙傛暟锛� {}", wmsUrl, JSONArray.toJSONString(maps));
-        HttpEntity<List<Map<String, Object>>> httpEntity = new HttpEntity<>(maps, headers);
-        ResponseEntity<String> exchange = restTemplate.exchange(wmsUrl, HttpMethod.POST, httpEntity, String.class);
-        log.info("璁㈠崟淇敼杩斿洖缁撴灉锛� {}", exchange);
-        if (Objects.isNull(exchange.getBody())) {
-            throw new CoolException("鏌ヨ澶辫触锛侊紒");
-        } else {
-            ObjectMapper objectMapper = new ObjectMapper();
-            objectMapper.coercionConfigDefaults().setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
-            try {
-                CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
-                if (result.getCode() == 200) {
-//                    JSONObject object = JSONObject.parseObject(JSONObject.toJSONString(result.getData()));
-                    return result;
-                } else {
-                    throw new CoolException("鏌ヨ澶辫触锛侊紒");
-                }
-            } catch (JsonProcessingException e) {
-                throw new CoolException(e.getMessage());
-            }
-        }
-    }
-
-    /**
-     * 鍒犻櫎鍗曟嵁
-     * @param params
-     * @return
-     */
-    @Override
-    public CommonResponse orderDel(ErpOpParams params) {
-        if (Objects.isNull(params.getOrderNo()) || params.getOrderNo().isEmpty()) {
-            throw new CoolException("璁㈠崟鍙蜂笉鑳戒负绌猴紒锛�");
-        }
-        /**WMS鍩虹閰嶇疆閾炬帴*/
-        String rcsUrl = wmsApi.getHost() + ":" + wmsApi.getPort() + WmsConstant.ORDER_DEL;
-        log.info("鏌ヨ璁㈠崟淇℃伅鍙婄姸鎬侊細 {}锛� 璇锋眰鍙傛暟锛� {}", rcsUrl, JSONObject.toJSONString(params));
-        HttpHeaders headers = new HttpHeaders();
-        headers.add("Content-Type", "application/json");
-        headers.add("api-version", "v2.0");
-        HttpEntity httpEntity = new HttpEntity(params, headers);
-        ResponseEntity<String> exchange = restTemplate.exchange(rcsUrl, HttpMethod.POST, httpEntity, String.class);
-        log.info("鏌ヨ鍝嶅簲缁撴灉锛� {}", exchange);
-        if (Objects.isNull(exchange.getBody())) {
-            throw new CoolException("鏌ヨ澶辫触锛侊紒");
-        } else {
-            ObjectMapper objectMapper = new ObjectMapper();
-            objectMapper.coercionConfigDefaults().setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
-            try {
-                CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
-                if (result.getCode() == 200) {
-                    return result;
-                } else {
-                    throw new CoolException("鏌ヨ澶辫触锛侊紒");
-                }
-            } catch (JsonProcessingException e) {
-                throw new CoolException(e.getMessage());
-            }
-        }
-    }
-
-    /**
-     * 鐗╂枡淇℃伅淇敼
-     * @param params
-     * @return
-     */
-    @Override
     public CommonResponse syncMatnrs(ErpMatnrParms params) {
-        if (Objects.isNull(params.getMatnr()) ) {
+        if (Objects.isNull(params.getMatnr())) {
             throw new CoolException("鐗╂枡缂栫爜涓嶈兘涓虹┖锛侊紒");
         }
         if (Objects.isNull(params.getMaktx())) {
             throw new CoolException("鐗╂枡鍚嶇О涓嶈兘涓虹┖锛侊紒");
         }
+        log.info("鐗╂枡淇敼锛岃姹傚弬鏁帮細 {}", JSONObject.toJSONString(params));
+        Map<String, Object> res = wmsServerFeignClient.syncMatnrs(params);
+        return mapToCommonResponse(res);
+    }
+
+    /**
+     * @author Ryan
+     * @date 2025/10/27
+     * @description: 涓婃姤鍗曟嵁鐘舵��
+     * @version 1.0
+     */
+    @Override
+    public CommonResponse reportOrders(ReportParams params) {
+        if (Objects.isNull(params)) {
+            throw new CoolException("鍙傛暟涓嶈兘涓虹┖锛侊紒");
+        }
         /**WMS鍩虹閰嶇疆閾炬帴*/
-        String rcsUrl = wmsApi.getHost() + ":" + wmsApi.getPort() + WmsConstant.UPDATE_MATNR_INFO;
-        log.info("鐗╂枡淇敼锛歿}锛� 璇锋眰鍙傛暟锛� {}", rcsUrl, JSONObject.toJSONString(params));
+        String rcsUrl = erpApi.getHost() + ":" + erpApi.getPort() + WmsConstant.REPORT_ORDER_CALLBACK;
         HttpHeaders headers = new HttpHeaders();
         headers.add("Content-Type", "application/json");
         headers.add("api-version", "v2.0");
         HttpEntity httpEntity = new HttpEntity(params, headers);
+        log.info("宸插畬鎴愯鍗曚笂浼狅細{}锛� 璇锋眰鍙傛暟锛� {}", rcsUrl, httpEntity.getBody());
+
         ResponseEntity<String> exchange = restTemplate.exchange(rcsUrl, HttpMethod.POST, httpEntity, String.class);
-        log.info("淇敼缁撴灉锛� {}", exchange);
+        log.info("宸插畬鎴愯鍗曚笂浼狅紝璇锋眰缁撴灉锛� {}", exchange.getBody());
+        if (Objects.isNull(exchange.getBody())) {
+            throw new CoolException("涓婁紶澶辫触锛侊紒");
+        } else {
+            CommonResponse commonResponse = new CommonResponse();
+            ErpCommonResponse result = JSONObject.parseObject(exchange.getBody(), ErpCommonResponse.class);
+            if (!result.getIsError()) {
+                commonResponse.setCode(200).setMsg(result.getMessage()).setData(result.getData());
+                return commonResponse;
+            } else {
+                throw new CoolException("涓婁紶澶辫触锛侊紒");
+            }
+        }
+        // Map<String, Object> res = erpReportFeignClient.report(params);
+        // if (res == null) throw new CoolException("涓婁紶澶辫触锛侊紒");
+        // Object c = res.get("code"); int code = c instanceof Number ? ((Number) c).intValue() : 500;
+        // if (code != 200) throw new CoolException("涓婁紶澶辫触锛侊紒");
+        // CommonResponse commonResponse = new CommonResponse();
+        // commonResponse.setCode(200).setMsg(String.valueOf(res.get("msg"))).setData(res.get("data"));
+        // return commonResponse;
+    }
+
+    /**
+     * @author Ryan
+     * @date 2025/10/27
+     * @description: 鐩樼偣宸紓鍗曚慨鏀�
+     * @version 1.0
+     */
+    @Override
+    public CommonResponse reportCheck(ReportParams params) {
+        if (Objects.isNull(params)) {
+            throw new CoolException("鍙傛暟涓嶈兘涓虹┖锛侊紒");
+        }
+        /**WMS鍩虹閰嶇疆閾炬帴*/
+        String rcsUrl = erpApi.getHost() + ":" + erpApi.getPort() + WmsConstant.REPORT_ORDER_CALLBACK;
+        log.info("鐗╂枡淇敼锛歿}锛� 璇锋眰鍙傛暟锛� {}", rcsUrl, JSONObject.toJSONString(params));
+        HttpHeaders headers = new HttpHeaders();
+        headers.add("Content-Type", "application/json");
+        headers.add("api-version", "v2.0");
+
+        HttpEntity httpEntity = new HttpEntity(params, headers);
+        ResponseEntity<String> exchange = restTemplate.exchange(rcsUrl, HttpMethod.POST, httpEntity, String.class);
+        log.info("淇敼缁撴灉锛� {}", exchange.getBody());
         if (Objects.isNull(exchange.getBody())) {
             throw new CoolException("淇敼澶辫触锛侊紒");
         } else {
-            ObjectMapper objectMapper = new ObjectMapper();
-            objectMapper.coercionConfigDefaults().setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
-            try {
-                CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
-                if (result.getCode() == 200) {
-                    return result;
-                } else {
-                    throw new CoolException("淇敼澶辫触锛侊紒");
-                }
-            } catch (JsonProcessingException e) {
-                throw new CoolException(e.getMessage());
+            CommonResponse commonResponse = new CommonResponse();
+            ErpCommonResponse result = JSONObject.parseObject(exchange.getBody(), ErpCommonResponse.class);
+            if (!result.getIsError()) {
+                commonResponse.setCode(200).setMsg(result.getMessage()).setData(result.getData());
+                return commonResponse;
+            } else {
+                throw new CoolException("淇敼澶辫触锛侊紒");
             }
         }
+        // Map<String, Object> res = erpReportFeignClient.report(params);
+        // if (res == null) throw new CoolException("淇敼澶辫触锛侊紒");
+        // Object c = res.get("code"); int code = c instanceof Number ? ((Number) c).intValue() : 500;
+        // if (code != 200) throw new CoolException("淇敼澶辫触锛侊紒");
+        // CommonResponse commonResponse = new CommonResponse();
+        // commonResponse.setCode(200).setMsg(String.valueOf(res.get("msg"))).setData(res.get("data"));
+        // return commonResponse;
+    }
+
+    @Override
+    public CommonResponse queryLocsDetls(Map<String, Object> params) {
+        Map<String, Object> p = params == null ? new HashMap<>() : params;
+        log.info("搴撲綅淇℃伅鏌ヨ锛岃姹傚弬鏁帮細 {}", JSONObject.toJSONString(p));
+        return mapToCommonResponse(wmsServerFeignClient.queryLocsDetls(p));
+    }
+
+    /** 8.4 搴撳瓨鏄庣粏鏌ヨ锛氳繑鍥炲�� data 涓哄璞℃暟缁勶紝涓嶅寘 result 澶栧眰 */
+    @Override
+    public CommonResponse inventoryDetails(Map<String, Object> params) {
+        Map<String, Object> p = params == null ? new HashMap<>() : params;
+        log.info("搴撳瓨鏄庣粏鏌ヨ锛岃姹傚弬鏁帮細 {}", JSONObject.toJSONString(p));
+        CommonResponse r = mapToCommonResponse(wmsServerFeignClient.inventoryDetails(p));
+        unwrapDataToArray(r);
+        return r;
+    }
+
+    /** 8.5 搴撳瓨姹囨�绘煡璇細杩斿洖鍊� data 涓哄璞℃暟缁勶紝涓嶅寘 result 澶栧眰 */
+    @Override
+    public CommonResponse inventorySummary(Map<String, Object> params) {
+        Map<String, Object> p = params == null ? new HashMap<>() : params;
+        log.info("搴撳瓨姹囨�绘煡璇紝璇锋眰鍙傛暟锛� {}", JSONObject.toJSONString(p));
+        CommonResponse r = mapToCommonResponse(wmsServerFeignClient.inventorySummary(p));
+        unwrapDataToArray(r);
+        return r;
+    }
+
+    /** 8.4/8.5 瑙勮寖锛歞ata 涓哄璞℃暟缁勶紝灏� { result, data: array } 鏀逛负 data = array */
+    private void unwrapDataToArray(CommonResponse r) {
+        if (r.getData() instanceof Map) {
+            @SuppressWarnings("unchecked")
+            Map<String, Object> dataModel = (Map<String, Object>) r.getData();
+            Object inner = dataModel.get("data");
+            if (inner != null) {
+                r.setData(inner);
+            }
+        }
+    }
+
+    @Override
+    public CommonResponse forwardToWms(String wmsPath, Object body) {
+        String url = wmsApi.getHost() + ":" + wmsApi.getPort() + wmsPath;
+        Object payload = body != null ? body : new HashMap<String, Object>();
+        log.info("杞彂璇锋眰锛� {}锛� 璇锋眰浣撻暱搴︼細 {}", url, payload instanceof List ? ((List<?>) payload).size() : 1);
+        return postToWms(url, payload);
+    }
+
+    /** 缁熶竴杞彂骞惰В鏋愪负 CommonResponse */
+    private CommonResponse postToWms(String url, Object body) {
+        HttpHeaders headers = new HttpHeaders();
+        headers.add("Content-Type", "application/json");
+        headers.add("api-version", "v2.0");
+        HttpEntity<Object> httpEntity = new HttpEntity<>(body, headers);
+        ResponseEntity<String> exchange = restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
+        if (Objects.isNull(exchange.getBody())) {
+            throw new CoolException("璇锋眰澶辫触锛侊紒");
+        }
+        ObjectMapper objectMapper = new ObjectMapper();
+        objectMapper.coercionConfigDefaults().setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
+        try {
+            return objectMapper.readValue(exchange.getBody(), CommonResponse.class);
+        } catch (JsonProcessingException e) {
+            throw new CoolException("瑙f瀽鍝嶅簲澶辫触锛�" + e.getMessage());
+        }
     }
 
 }

--
Gitblit v1.9.1