From a38d4a8619b886e2544cdefe421f171765ad2229 Mon Sep 17 00:00:00 2001
From: chen.lin <1442464845@qq.com>
Date: 星期二, 03 二月 2026 10:11:51 +0800
Subject: [PATCH] 库存汇总

---
 rsf-open-api/src/main/java/com/vincent/rsf/openApi/controller/phyz/ERPController.java |  178 ++++++++++++++++++++++++++++++++++-------------------------
 1 files changed, 102 insertions(+), 76 deletions(-)

diff --git a/rsf-open-api/src/main/java/com/vincent/rsf/openApi/controller/phyz/ERPController.java b/rsf-open-api/src/main/java/com/vincent/rsf/openApi/controller/phyz/ERPController.java
index 8da1005..d2f59c7 100644
--- a/rsf-open-api/src/main/java/com/vincent/rsf/openApi/controller/phyz/ERPController.java
+++ b/rsf-open-api/src/main/java/com/vincent/rsf/openApi/controller/phyz/ERPController.java
@@ -2,17 +2,16 @@
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
 import com.vincent.rsf.framework.common.R;
 import com.vincent.rsf.framework.exception.CoolException;
 import com.vincent.rsf.openApi.entity.dto.CommonResponse;
 import com.vincent.rsf.openApi.entity.phyz.*;
 import com.vincent.rsf.openApi.feign.wms.WmsServerFeignClient;
+import com.vincent.rsf.openApi.feign.wms.fallback.WmsServerFeignClientFallback;
 import com.vincent.rsf.openApi.service.phyz.ErpReportService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.compress.utils.Lists;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -257,87 +256,114 @@
             }
         } catch (Exception e) {
             log.error("搴撳瓨鏌ヨ鏄庣粏澶辫触", e);
-            // 杩囨护閿欒娑堟伅涓殑URL锛屽彧淇濈暀閿欒绫诲瀷
-            String errorMessage = e.getMessage();
-            if (errorMessage != null) {
-                // 濡傛灉鍖呭惈"executing"锛岃鏄庢槸HTTP璇锋眰閿欒锛屽幓鎺塙RL閮ㄥ垎
-                if (errorMessage.contains("executing")) {
-                    int executingIndex = errorMessage.indexOf("executing");
-                    if (executingIndex > 0) {
-                        // 鎻愬彇"executing"涔嬪墠鐨勯儴鍒嗭紙濡�"Read timed out"锛�
-                        errorMessage = errorMessage.substring(0, executingIndex).trim();
-                    } else {
-                        // 濡傛灉"executing"鍦ㄥ紑澶达紝浣跨敤榛樿閿欒娑堟伅
-                        errorMessage = "璇锋眰瓒呮椂";
-                    }
-                }
-                // 濡傛灉鍖呭惈"http://"鎴�"https://"锛屼篃灏濊瘯鍘绘帀URL閮ㄥ垎
-                else if (errorMessage.contains("http://") || errorMessage.contains("https://")) {
-                    // 浣跨敤姝e垯琛ㄨ揪寮忓幓鎺塙RL
-                    errorMessage = errorMessage.replaceAll("https?://[^\\s]+", "").trim();
-                    if (errorMessage.isEmpty()) {
-                        errorMessage = "璇锋眰澶辫触";
-                    }
-                }
-            }
-            return CommonResponse.error("鏌ヨ澶辫触锛�" + (errorMessage != null && !errorMessage.isEmpty() ? errorMessage : "鏈煡閿欒"));
+            String errorMessage = WmsServerFeignClientFallback.filterErrorMessage(e);
+            return CommonResponse.error(errorMessage);
         }
     }
 
+    @ApiOperation("搴撳瓨鏌ヨ姹囨�伙紙琛ㄥ崟鎻愪氦锛�")
+    @PostMapping(value = "/inventory/summary", consumes = "application/x-www-form-urlencoded")
+    public CommonResponse queryInventorySummaryForm(HttpServletRequest request) {
+        // 浠庤〃鍗曞弬鏁版瀯寤烘煡璇㈡潯浠�
+        InventoryQueryCondition condition = buildConditionFromRequestParams(request);
+        // 璋冪敤JSON澶勭悊鏂规硶
+        return queryInventorySummary(condition);
+    }
+
     @ApiOperation("搴撳瓨鏌ヨ姹囨��")
-    @PostMapping("/inventory/summary")
-    public CommonResponse queryInventorySummary(@RequestBody JSONObject params) {
+    @PostMapping(value = "/inventory/summary", consumes = "application/json")
+    public CommonResponse queryInventorySummary(@RequestBody(required = false) InventoryQueryCondition condition) {
+        // JSON鏂瑰紡锛氭敮鎸佷笉浼犻�掑弬鏁帮紙{}鎴杗ull鎴栫┖璇锋眰浣擄級锛屽垱寤洪粯璁ょ殑绌烘煡璇㈡潯浠跺璞�
+        if (condition == null) {
+            condition = new InventoryQueryCondition();
+        }
+        
         if (SIMULATED_DATA_ENABLE.equals("1")) {
-            String s = "{\n" +
-                    "  \"code\": 200,\n" +
-                    "  \"msg\": \"鎿嶄綔鎴愬姛\",\n" +
-                    "  \"data\": [\n" +
-                    "    {\n" +
-                    "      \"wareHouseId\": \"WH001\",\n" +
-                    "      \"wareHouseName\": \"鍘熸枡浠撳簱\",\n" +
-                    "      \"matNr\": \"MAT10001\",\n" +
-                    "      \"makTx\": \"閽㈡潗Q235\",\n" +
-                    "      \"spec\": \"鍥芥爣GB/T700-2006\",\n" +
-                    "      \"anfme\": 10.5,\n" +
-                    "      \"unit\": \"鍚╘",\n" +
-                    "      \"stockOrgId\": \"ORG001\",\n" +
-                    "      \"batch\": \"BATCH20260106001\",\n" +
-                    "      \"planNo\": \"Plan20260106006\"\n" +
-                    "    },\n" +
-                    "    {\n" +
-                    "      \"wareHouseId\": \"WH001\",\n" +
-                    "      \"wareHouseName\": \"鍘熸枡浠撳簱\",\n" +
-                    "      \"matNr\": \"MAT10002\",\n" +
-                    "      \"makTx\": \"閾濆瀷鏉�6061\",\n" +
-                    "      \"spec\": \"鍥芥爣GB/T3190-2008\",\n" +
-                    "      \"anfme\": 20.3,\n" +
-                    "      \"unit\": \"鍚╘",\n" +
-                    "      \"stockOrgId\": \"ORG001\",\n" +
-                    "      \"batch\": \"BATCH20260106002\",\n" +
-                    "      \"planNo\": \"Plan20260106005\"\n" +
-                    "    },\n" +
-                    "    {\n" +
-                    "      \"wareHouseId\": \"WH002\",\n" +
-                    "      \"wareHouseName\": \"鎴愬搧浠撳簱\",\n" +
-                    "      \"matNr\": \"MAT30001\",\n" +
-                    "      \"makTx\": \"鐢垫満鎴愬搧\",\n" +
-                    "      \"spec\": \"380V 50Hz 15KW\",\n" +
-                    "      \"anfme\": 100,\n" +
-                    "      \"unit\": \"鍙癨",\n" +
-                    "      \"stockOrgId\": \"ORG001\",\n" +
-                    "      \"batch\": \"BATCH20260106003\",\n" +
-                    "      \"planNo\": \"Plan20260106004\"\n" +
-                    "    }\n" +
-                    "  ]\n" +
-                    "}";
-            return JSONObject.parseObject(s, CommonResponse.class);
+            String x = "[\n" +
+                    "  {\n" +
+                    "    \"wareHouseId\": \"WH001\",\n" +
+                    "    \"wareHouseName\": \"鍘熸枡浠撳簱\",\n" +
+                    "    \"matNr\": \"MAT10001\",\n" +
+                    "    \"matTx\": \"閽㈡潗Q235\",\n" +
+                    "    \"spec\": \"鍥芥爣GB/T700-2006\",\n" +
+                    "    \"anfme\": 10.5,\n" +
+                    "    \"unit\": \"鍚╘",\n" +
+                    "    \"stockOrgId\": \"ORG001\",\n" +
+                    "    \"batch\": \"BATCH20260106001\",\n" +
+                    "    \"planNo\": \"Plan20260106006\"\n" +
+                    "  },\n" +
+                    "  {\n" +
+                    "    \"wareHouseId\": \"WH001\",\n" +
+                    "    \"wareHouseName\": \"鍘熸枡浠撳簱\",\n" +
+                    "    \"matNr\": \"MAT10002\",\n" +
+                    "    \"matTx\": \"閾濆瀷鏉�6061\",\n" +
+                    "    \"spec\": \"鍥芥爣GB/T3190-2008\",\n" +
+                    "    \"anfme\": 20.3,\n" +
+                    "    \"unit\": \"鍚╘",\n" +
+                    "    \"stockOrgId\": \"ORG001\",\n" +
+                    "    \"batch\": \"BATCH20260106002\",\n" +
+                    "    \"planNo\": \"Plan20260106005\"\n" +
+                    "  },\n" +
+                    "  {\n" +
+                    "    \"wareHouseId\": \"WH002\",\n" +
+                    "    \"wareHouseName\": \"鎴愬搧浠撳簱\",\n" +
+                    "    \"matNr\": \"MAT30001\",\n" +
+                    "    \"matTx\": \"鐢垫満鎴愬搧\",\n" +
+                    "    \"spec\": \"380V 50Hz 15KW\",\n" +
+                    "    \"anfme\": 100,\n" +
+                    "    \"unit\": \"鍙癨",\n" +
+                    "    \"stockOrgId\": \"ORG001\",\n" +
+                    "    \"batch\": \"BATCH20260106003\",\n" +
+                    "    \"planNo\": \"Plan20260106004\"\n" +
+                    "  }\n" +
+                    "]";
+            return CommonResponse.ok(JSONArray.parseArray(x, InventorySummary.class));
         }
 
-        InventoryQueryCondition condition = JSON.parseObject(params.toJSONString(), InventoryQueryCondition.class);
-        // 鏁版嵁澶勭悊锛岃浆鍙憇erver
-        List<InventorySummary> inventorySummaries = Lists.newArrayList();
-        return new CommonResponse().setCode(200).setData(inventorySummaries);
-
+        try {
+            if (wmsServerFeignClient == null) {
+                log.warn("WmsServerFeignClient鏈敞鍏ワ紝鏃犳硶杩涜璋冪敤");
+                return CommonResponse.error("鏈嶅姟鏈垵濮嬪寲");
+            }
+            
+            log.info("搴撳瓨鏌ヨ姹囨�昏姹傚弬鏁帮細 {}", JSON.toJSONString(condition));
+            
+            // 鐩存帴浼犻�掑疄浣撶被锛孎eign浼氳嚜鍔ㄥ簭鍒楀寲涓篔SON
+            R result = wmsServerFeignClient.queryInventorySummary(condition);
+            
+            log.info("搴撳瓨鏌ヨ姹囨�昏繑鍥炵粨鏋滐細 {}", JSON.toJSONString(result));
+            
+            if (result != null) {
+                // R绫荤户鎵胯嚜HashMap锛屼娇鐢╣et鏂规硶鑾峰彇鍊�
+                Integer code = (Integer) result.get("code");
+                String msg = (String) result.get("msg");
+                Object data = result.get("data");
+                
+                if (code != null && code == 200) {
+                    // 灏哅ap鍒楄〃杞崲涓篒nventorySummary鍒楄〃
+                    if (data != null) {
+                        @SuppressWarnings("unchecked")
+                        List<Map<String, Object>> dataList = (List<Map<String, Object>>) data;
+                        List<InventorySummary> inventorySummaries = new ArrayList<>();
+                        for (Map<String, Object> item : dataList) {
+                            InventorySummary summary = JSON.parseObject(JSON.toJSONString(item), InventorySummary.class);
+                            inventorySummaries.add(summary);
+                        }
+                        return CommonResponse.ok(inventorySummaries);
+                    } else {
+                        return CommonResponse.ok(new ArrayList<>());
+                    }
+                } else {
+                    return CommonResponse.error(msg != null ? msg : "鏌ヨ澶辫触");
+                }
+            } else {
+                return CommonResponse.error("鏌ヨ澶辫触锛氳繑鍥炵粨鏋滀负绌�");
+            }
+        } catch (Exception e) {
+            log.error("搴撳瓨鏌ヨ姹囨�诲け璐�", e);
+            String errorMessage = WmsServerFeignClientFallback.filterErrorMessage(e);
+            return CommonResponse.error(errorMessage);
+        }
     }
 
     @ApiOperation("鐩樼偣缁撴灉纭")

--
Gitblit v1.9.1