From 9e9d5d9aed6a29b8b6b1c38cfbb7fb94b21c478b Mon Sep 17 00:00:00 2001
From: cl <1442464845@qq.com>
Date: 星期四, 16 四月 2026 10:39:15 +0800
Subject: [PATCH] 报警回调

---
 rsf-open-api/src/main/java/com/vincent/rsf/openApi/controller/WmsRcsController.java |  144 +++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 137 insertions(+), 7 deletions(-)

diff --git a/rsf-open-api/src/main/java/com/vincent/rsf/openApi/controller/WmsRcsController.java b/rsf-open-api/src/main/java/com/vincent/rsf/openApi/controller/WmsRcsController.java
index 379b594..eace48f 100644
--- a/rsf-open-api/src/main/java/com/vincent/rsf/openApi/controller/WmsRcsController.java
+++ b/rsf-open-api/src/main/java/com/vincent/rsf/openApi/controller/WmsRcsController.java
@@ -2,28 +2,98 @@
 
 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.params.ExMsgCallbackParams;
+import com.vincent.rsf.openApi.entity.params.LocSiteParams;
+import com.vincent.rsf.openApi.entity.params.LocationAllocateParams;
 import com.vincent.rsf.openApi.entity.params.RcsPubTaskParams;
 import com.vincent.rsf.openApi.entity.params.SyncRcsLocsParam;
+import com.vincent.rsf.openApi.entity.params.TaskReportParams;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.vincent.rsf.httpaudit.support.HttpAuditSupport;
 import com.vincent.rsf.openApi.service.WmsRcsService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.StreamUtils;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+import java.nio.charset.Charset;
 import java.util.Map;
 import java.util.Objects;
 
+@Slf4j
 @RestController
 @Api("RCS璋冨害浜や簰鎺ュ彛")
 @RequestMapping("/rcs")
 public class WmsRcsController {
 
+    private static final String API_AGV_ERROR = "RCS-AGV寮傚父涓婃姤锛堜粎鎺ユ敹锛�";
+    private static final String API_PUB_TASK = "璋冨害浠诲姟涓嬪彂";
+    private static final String API_CANCEL_TASK = "鍙栨秷璋冨害浠诲姟";
+    private static final String API_CALLBACK_EVENT = "鐘舵�佷笂鎶ュ洖璋�";
+    private static final String API_SYNC_LOCS = "RCS搴撲綅淇℃伅鍚屾";
+    private static final String API_MODIFY_STATUS = "RCS淇敼搴撲綅鎴栫珯鐐圭姸鎬�";
+    private static final String API_TASK_REPORT = "RCS鍥炶皟鎺ュ彛";
+    private static final String API_ALLOCATE = "RCS-鐢宠鍏ュ簱浠诲姟";
+
     @Autowired
     private WmsRcsService wmsRcsService;
+
+    @Resource
+    private ObjectMapper objectMapper;
+
+    /**
+     * RCS AGV 寮傚父涓婃姤锛氬師鏍锋帴鏀惰姹備綋锛屾墦鏃ュ織锛沨ttp-audit 闇�閰嶇疆 URI 鐧藉悕鍗曡 version/db
+     */
+    @ApiOperation(API_AGV_ERROR)
+    @PostMapping("/api/open/agvError")
+    public CommonResponse agvError(HttpServletRequest request) throws IOException {
+        Charset charset = HttpAuditSupport.resolveCharset(request);
+        String body = StreamUtils.copyToString(request.getInputStream(), charset);
+        log.info("RCS POST /rcs/api/open/agvError | {} contentType={} charset={} bytes={}\n{}",
+                API_AGV_ERROR,
+                request.getContentType(),
+                charset.name(),
+                body.getBytes(charset).length,
+                formatBodyForLog(body));
+        return CommonResponse.ok();
+    }
+
+    private String formatBodyForLog(String body) {
+        if (body.isEmpty()) {
+            return "(empty body)";
+        }
+        try {
+            JsonNode n = objectMapper.readTree(body);
+            return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(n);
+        } catch (Exception e) {
+            int max = 16384;
+            return body.length() > max ? body.substring(0, max) + "...(truncated,len=" + body.length() + ")" : body;
+        }
+    }
+
+    /** RCS 鍏ョ珯璇锋眰浣撴墦鏃ュ織锛堝惈 @ApiOperation 涓枃璇存槑锛� */
+    private void logRcsRequest(String action, String apiOperationValue, Object body) {
+        if (body == null) {
+            log.info("RCS {} | {} request body=null", action, apiOperationValue);
+            return;
+        }
+        try {
+            log.info("RCS {} | {} request:\n{}", action, apiOperationValue,
+                    objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(body));
+        } catch (Exception e) {
+            log.info("RCS {} | {} request: {}", action, apiOperationValue, body);
+        }
+    }
 
     /**
      * @author Ryan
@@ -31,9 +101,10 @@
      * @description: 浠诲姟涓嬪彂
      * @version 1.0
      */
-    @ApiOperation("璋冨害浠诲姟涓嬪彂")
+    @ApiOperation(API_PUB_TASK)
     @PostMapping("/pub/task")
-    public R pubTasks(@RequestBody RcsPubTaskParams params) {
+    public CommonResponse pubTasks(@RequestBody RcsPubTaskParams params) {
+        logRcsRequest("POST /rcs/pub/task", API_PUB_TASK, params);
         if (Objects.isNull(params)) {
             throw new CoolException("鍙傛暟涓嶈兘涓虹┖锛侊紒");
         }
@@ -46,9 +117,10 @@
      * @description: 鍙栨秷浠诲姟
      * @version 1.0
      */
-    @ApiOperation("鍙栨秷璋冨害浠诲姟")
+    @ApiOperation(API_CANCEL_TASK)
     @PostMapping("/cancel/task")
-    public R cancelTasks(@RequestBody Map<String, Object> params) {
+    public CommonResponse cancelTasks(@RequestBody Map<String, Object> params) {
+        logRcsRequest("POST /rcs/cancel/task", API_CANCEL_TASK, params);
         return wmsRcsService.cancelTasks(params);
     }
 
@@ -58,9 +130,10 @@
      * @description: 浠诲姟鍥炶皟锛岀姸鎬佸洖鍐�
      * @version 1.0
      */
-    @ApiOperation("寮傚父浠诲姟鍥炶皟")
+    @ApiOperation(API_CALLBACK_EVENT)
     @PostMapping("/callback/event")
-    public R callBackEvent(@RequestBody ExMsgCallbackParams params) {
+    public CommonResponse callBackEvent(@RequestBody ExMsgCallbackParams params) {
+        logRcsRequest("POST /rcs/callback/event", API_CALLBACK_EVENT, params);
         return wmsRcsService.callBackEvent(params);
     }
 
@@ -71,14 +144,71 @@
      * @description: RCS搴撲綅淇℃伅鍚屾
      * @version 1.0
      */
-    @ApiOperation("RCS搴撲綅淇℃伅鍚屾")
+    @ApiOperation(API_SYNC_LOCS)
     @PostMapping("/sync/locs")
     public R syncLocsToWms(@RequestBody SyncRcsLocsParam params) {
+        logRcsRequest("POST /rcs/sync/locs", API_SYNC_LOCS, params);
          if (Objects.isNull(params)) {
              return R.error("鍙傛暟涓嶈兘涓虹┖锛侊紒");
          }
          return R.ok().add(wmsRcsService.syncLocs(params));
     }
 
+    /**
+     * @author Ryan
+     * @date 2025/11/10
+     * @description: WMS 鍑哄簱鎴愬姛鍚庯紝淇敼搴撲綅銆佺珯鐐圭姸鎬�
+     * @version 1.0
+     */
+    @ApiOperation(API_MODIFY_STATUS)
+    @PostMapping("/modify/status")
+    public R modifyLocOrSite(@RequestBody LocSiteParams params) {
+        logRcsRequest("POST /rcs/modify/status", API_MODIFY_STATUS, params);
+        if (Objects.isNull(params)) {
+            return R.error("鍙傛暟涓嶈兘涓虹┖锛侊紒");
+        }
+        return wmsRcsService.modifyLocOrSite(params);
+    }
+
+    /**
+     * @author Ryan
+     * @date 2026/2/3
+     * @description: RCS鍥炶皟鎺ュ彛
+     * @version 1.0
+     */
+    @ApiOperation(API_TASK_REPORT)
+    @PostMapping("/api/open/task/report")
+    public CommonResponse reportTask(@RequestBody TaskReportParams params) {
+        logRcsRequest("POST /rcs/api/open/task/report", API_TASK_REPORT, params);
+        if (Objects.isNull(params)) {
+            throw new CoolException("鍙傛暟涓嶈兘涓虹┖锛侊紒");
+        }
+        return wmsRcsService.reportTask(params);
+    }
+
+    /**
+     * @author Ryan
+     * @date 2026/2/6
+     * @description: 鐢宠鍏ュ簱浠诲姟
+     * @version 1.0
+     */
+    @ApiOperation(API_ALLOCATE)
+    @PostMapping("/api/open/location/allocate")
+    public R allocateLocation(@RequestBody LocationAllocateParams params) {
+        logRcsRequest("POST /rcs/api/open/location/allocate", API_ALLOCATE, params);
+        if (Objects.isNull(params)) {
+            return R.error("鍙傛暟涓嶈兘涓虹┖锛侊紒");
+        }
+        if (Objects.isNull(params.getBarcode()) || params.getBarcode().isEmpty()) {
+            return R.error("鏂欑鐮佷笉鑳戒负绌猴紒锛�");
+        }
+        if (Objects.isNull(params.getStaNo()) || params.getStaNo().isEmpty()) {
+            return R.error("鍏ュ簱绔欑偣涓嶈兘涓虹┖锛侊紒");
+        }
+        if (Objects.isNull(params.getType())) {
+            params.setType(18);
+        }
+        return wmsRcsService.allocateLocation(params);
+    }
 
 }

--
Gitblit v1.9.1