From cfb1943832cc253f43cddd164f468dfe6a32cb35 Mon Sep 17 00:00:00 2001
From: pang.jiabao <pang_jiabao@163.com>
Date: 星期日, 21 十二月 2025 18:50:21 +0800
Subject: [PATCH] 刀具库WMS功能完善

---
 src/main/java/com/zy/asrs/controller/MesController.java |  104 +++++++++++++++++++++++----------------------------
 1 files changed, 47 insertions(+), 57 deletions(-)

diff --git a/src/main/java/com/zy/asrs/controller/MesController.java b/src/main/java/com/zy/asrs/controller/MesController.java
index 6a7ba4a..68f483f 100644
--- a/src/main/java/com/zy/asrs/controller/MesController.java
+++ b/src/main/java/com/zy/asrs/controller/MesController.java
@@ -1,7 +1,9 @@
 package com.zy.asrs.controller;
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.core.annotations.AppAuth;
 import com.core.common.Cools;
 import com.core.common.R;
 import com.zy.asrs.entity.BasStation;
@@ -9,65 +11,56 @@
 import com.zy.asrs.service.BasStationService;
 import com.zy.asrs.service.MesService;
 import com.zy.common.web.BaseController;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
 import java.util.Date;
 import java.util.List;
 
 @RestController
+@Slf4j
 public class MesController extends BaseController {
 
     @Resource
     private MesService mesService;
 
+    private void auth(String appkey, Object obj, HttpServletRequest request) {
+        log.info("{}鎺ュ彛琚闂紱appkey:{}锛涜姹傛暟鎹細{}", request.getRequestURI(), appkey, JSON.toJSONString(obj));
+        request.setAttribute("cache", obj);
+    }
 
-    // 鐗╂枡淇℃伅鍚屾
     @PostMapping("/api/mes/synMatInfo")
-    public MesReturn synMatInfo(@RequestBody MesMatInfo param){
-
+    @AppAuth(memo = "鐗╂枡淇℃伅鍚屾")
+    public MesReturn synMatInfo(@RequestHeader(required = false) String appkey,@RequestBody MesMatInfo param,HttpServletRequest request){
+        auth(appkey, param, request);
         MesReturn mesReturn = new MesReturn();
         mesReturn.setSuccess(mesService.synMatInfo(param) == 1 ? "1" : "2");
         return mesReturn;
     }
 
+    @PostMapping("/api/tms/queryStock")
+    @AppAuth(memo = "TMS鏌ヨ搴撳瓨")
+    public R queryStock(@RequestHeader(required = false) String appkey,@RequestBody JSONObject param,HttpServletRequest request){
+        auth(appkey, param, request);
+        String matnr = param.getString("matnr");
+        return mesService.queryStock(matnr);
+    }
+
     // 鍑哄簱鐢宠
     @PostMapping("/api/mes/outBoundOrder")
-    public MesReturn outBoundOrder(@RequestBody MesInApply param){
-        MesReturn mesReturn = new MesReturn();
-        // 缁堢偣涓虹┖锛岃绠楁帴椹充綅
-        BasStation basStation = null;
-        if (Cools.isEmpty(param.getNextStationId())) {
-            List<BasStation> basStations = basStationService.selectList(new EntityWrapper<BasStation>().eq("loc_sts", "O"));
-            if(basStations.isEmpty()) {
-                mesReturn.setSuccess("2");
-                mesReturn.setMessage("鏃犵┖鎺ラ┏浣嶏紝璇风◢鍚庡啀璇�!");
-                return mesReturn;
-            }
-            // 鎺ラ┏鐐�
-            basStation = basStations.get(0);
-            param.setNextStationId(basStation.getDevNo());
-
-            // 鍏堟洿鏂版帴椹崇偣鐘舵��
-            basStation.setModiTime(new Date());
-            basStation.setLocSts("S");
-            basStation.setBarcode(param.getDjNo());
-            basStationService.updateById(basStation);
-        }
-        int i = mesService.outBoundOrder(param);
-        if(i == 1) {
-            mesReturn.setSuccess("1");
-        } else {
-            // 閲婃斁鎺ラ┏鐐�
-            if(basStation != null) {
-                basStation.setModiTime(new Date());
-                basStation.setLocSts("O");
-                basStation.setBarcode("");
-                basStationService.updateById(basStation);
-            }
+    @AppAuth(memo = "鍑哄簱鐢宠(TMS璋冪敤)")
+    public MesReturn outBoundOrder(@RequestHeader(required = false) String appkey,@RequestBody MesInApply param,HttpServletRequest request){
+        auth(appkey, param, request);
+        if(Cools.isEmpty(param.getTaskNo(),param.getOrderNo(),param.getStationId())) {
+            MesReturn mesReturn = new MesReturn();
             mesReturn.setSuccess("2");
+            mesReturn.setMessage("鍙傛暟涓嶈兘涓虹┖锛�" + JSONObject.toJSONString(param));
+            return  mesReturn;
         }
-        return mesReturn;
+
+        return mesService.outBoundOrder(param);
     }
 
 //    // 鍑哄簱鐢宠锛堝彨鏂欙級锛岃閰嶅簱銆佹粦鍧楀簱
@@ -88,10 +81,10 @@
         return mesReturn;
     }
 
-    // 鍏ョ珯鍏佽
     @PostMapping("/api/mes/allowInStation")
-    public MesReturn allowInStation(@RequestBody TransInOutStationAllow param){
-
+    @AppAuth(memo = "鍏ョ珯鍏佽")
+    public MesReturn allowInStation(@RequestHeader(required = false) String appkey,@RequestBody TransInOutStationAllow param,HttpServletRequest request){
+        auth(appkey, param, request);
         return mesService.allowInStation(param);
     }
 
@@ -108,6 +101,7 @@
     // 涓嬪彂杩愯緭浠诲姟锛宮es璋冪敤涓嬪垁06(鍛煎彨agv鎼繍)
     @PostMapping("/api/mes/submitTask")
     public JSONObject submitTask(@RequestBody TransTask param){
+        log.info("涓嬪垁(閫�鍒�)锛歿}",JSONObject.toJSONString(param));
         // 缁堢偣涓虹┖锛岃绠楁帴椹充綅
         BasStation basStation = null;
         if (Cools.isEmpty(param.getNextStationId())) {
@@ -129,11 +123,20 @@
             basStation.setBarcode(param.getDjNo());
             basStationService.updateById(basStation);
         }
-
+        JSONObject sendAgvTask;
         param.setAgvFactory(1); // 娴峰悍
-        param.setNextStationId("A1");
-        JSONObject sendAgvTask = mesService.submitTask(param);
-        if (!"1".equals(sendAgvTask.getString("Success"))) {
+        try {
+            sendAgvTask = mesService.submitTask(param);
+            if (!"1".equals(sendAgvTask.getString("Success"))) {
+                // 閲婃斁鎺ラ┏鐐�
+                if(basStation != null) {
+                    basStation.setModiTime(new Date());
+                    basStation.setLocSts("O");
+                    basStation.setBarcode("");
+                    basStationService.updateById(basStation);
+                }
+            }
+        }catch (Exception e){
             // 閲婃斁鎺ラ┏鐐�
             if(basStation != null) {
                 basStation.setModiTime(new Date());
@@ -141,6 +144,7 @@
                 basStation.setBarcode("");
                 basStationService.updateById(basStation);
             }
+            throw e;
         }
         return sendAgvTask;
     }
@@ -154,19 +158,5 @@
         return mesReturn;
     }
 
-
-    // region 娴嬭瘯
-    @GetMapping("/api/mes/transDj")
-    public int transDj(@RequestParam String taskNo,@RequestParam String djNo){
-
-        return mesService.transDj(taskNo,djNo);
-    }
-
-    // 閫�绌烘墭鐩樿繑鍥炰骇绾� pda涓婃搷浣滅┖鎵樿繑鍥炰骇绾�
-    @GetMapping("/tkt")
-    public R tkt(@RequestParam String taskNo){
-         return mesService.tkt(taskNo);
-    }
-    // endregion
 
 }

--
Gitblit v1.9.1