From 5fb7dae61f9d6c38c37014cf27f28107c6f52e74 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期三, 19 十一月 2025 16:18:19 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/controller/ConsoleController.java |  409 ++++++++++++++++++++++++++++++---------------------------
 1 files changed, 216 insertions(+), 193 deletions(-)

diff --git a/src/main/java/com/zy/asrs/controller/ConsoleController.java b/src/main/java/com/zy/asrs/controller/ConsoleController.java
index 1c61d5e..4f9560e 100644
--- a/src/main/java/com/zy/asrs/controller/ConsoleController.java
+++ b/src/main/java/com/zy/asrs/controller/ConsoleController.java
@@ -6,36 +6,42 @@
 import com.core.annotations.ManagerAuth;
 import com.core.common.Cools;
 import com.core.common.R;
+import com.zy.asrs.domain.enums.CrnStatusType;
+import com.zy.asrs.domain.enums.StationStatusType;
 import com.zy.asrs.domain.param.SystemSwitchParam;
-import com.zy.asrs.entity.BasMap;
-import com.zy.asrs.entity.DeviceConfig;
-import com.zy.asrs.entity.LocMast;
-import com.zy.asrs.service.BasMapService;
-import com.zy.asrs.service.DeviceConfigService;
-import com.zy.asrs.service.LocMastService;
+import com.zy.asrs.domain.vo.CrnDetailVo;
+import com.zy.asrs.domain.vo.CrnLatestDataVo;
+import com.zy.asrs.domain.vo.StationLatestDataVo;
+import com.zy.asrs.domain.vo.RgvLatestDataVo;
+import com.zy.asrs.entity.*;
+import com.zy.asrs.service.*;
 import com.zy.asrs.utils.Utils;
+import com.zy.common.CodeRes;
 import com.zy.common.model.MapNode;
-import com.zy.common.model.NavigateNode;
-import com.zy.common.model.enums.NavigationMapType;
-import com.zy.common.utils.NavigateMapData;
 import com.zy.common.utils.RedisUtil;
+import com.zy.core.News;
 import com.zy.core.cache.SlaveConnection;
+import com.zy.core.enums.CrnModeType;
+import com.zy.core.enums.MapNodeType;
 import com.zy.core.enums.RedisKeyType;
+import com.zy.core.enums.RgvStatusType;
 import com.zy.core.enums.SlaveType;
-import com.zy.core.model.command.ShuttleRedisCommand;
-import com.zy.core.model.protocol.ShuttleProtocol;
+import com.zy.core.model.protocol.CrnProtocol;
+import com.zy.core.model.protocol.StationProtocol;
 import com.zy.core.properties.SystemProperties;
-import com.zy.core.thread.ShuttleThread;
+import com.zy.core.thread.CrnThread;
+import com.zy.core.thread.StationThread;
+import com.zy.core.thread.RgvThread;
+import com.zy.core.model.protocol.RgvProtocol;
+
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
-import javax.servlet.http.HttpServletRequest;
 import java.util.*;
 
 /**
  * 涓绘帶鍥炬帴鍙�
- * Created by vincent on 2020-06-01
  */
 @Slf4j
 @RestController
@@ -43,39 +49,214 @@
 public class ConsoleController {
 
     @Autowired
+    private DeviceConfigService deviceConfigService;
+    @Autowired
+    private WrkMastService wrkMastService;
+    @Autowired
+    private BasCrnpErrService basCrnpErrService;
+    @Autowired
     private BasMapService basMapService;
     @Autowired
     private RedisUtil redisUtil;
     @Autowired
-    private NavigateMapData navigateMapData;
-    @Autowired
     private LocMastService locMastService;
-    @Autowired
-    private DeviceConfigService deviceConfigService;
 
     @PostMapping("/system/running/status")
     @ManagerAuth(memo = "绯荤粺杩愯鐘舵��")
-    public R systemRunningStatus(){
+    public R systemRunningStatus() {
         return R.ok().add(Cools.add("status", SystemProperties.WCS_RUNNING_STATUS.get()));
     }
 
     @PostMapping("/system/switch")
     @ManagerAuth(memo = "绯荤粺杩愯寮�鍏虫搷浣�")
     public R systemSwitch(SystemSwitchParam param) throws InterruptedException {
-        if (Cools.isEmpty(param.getOperatorType())){
+        if (Cools.isEmpty(param.getOperatorType())) {
             return R.error();
         }
         if (param.getOperatorType() == 0) {
-            if (Cools.isEmpty(param.getPassword())){
+            if (Cools.isEmpty(param.getPassword())) {
                 return R.error("璇疯緭鍏ュ彛浠�");
             }
-            if (!param.getPassword().equals(SystemProperties.WCS_PASSWORD)){
+            if (!param.getPassword().equals(SystemProperties.WCS_PASSWORD)) {
                 return R.error("鍙d护閿欒");
             }
         }
         Thread.sleep(200L);
-        SystemProperties.WCS_RUNNING_STATUS.set(param.getOperatorType()==1?Boolean.TRUE:Boolean.FALSE);
+        SystemProperties.WCS_RUNNING_STATUS.set(param.getOperatorType() == 1 ? Boolean.TRUE : Boolean.FALSE);
         return R.ok().add(Cools.add("status", SystemProperties.WCS_RUNNING_STATUS.get()));
+    }
+
+    @PostMapping("/latest/data/station")
+    @ManagerAuth(memo = "绔欑偣瀹炴椂鏁版嵁")
+    public R stationLatestData() {
+        List<StationLatestDataVo> vos = new ArrayList<>();
+
+        List<DeviceConfig> devpList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+                .eq("device_type", String.valueOf(SlaveType.Devp)));
+        for (DeviceConfig deviceConfig : devpList) {
+            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp,
+                    deviceConfig.getDeviceNo());
+            if (stationThread == null) {
+                continue;
+            }
+
+            List<StationProtocol> statusList = stationThread.getStatus();
+            if (statusList == null || statusList.isEmpty()) {
+                continue;
+            }
+            for (StationProtocol stationProtocol : statusList) {
+                StationLatestDataVo vo = new StationLatestDataVo();
+                vo.setStationId(stationProtocol.getStationId()); // 绔欑偣缂栧彿
+                vo.setTaskNo(stationProtocol.getTaskNo()); // 浠诲姟鍙�
+                vo.setTargetStaNo(stationProtocol.getTargetStaNo()); // 鐩爣绔欑偣
+                vo.setAutoing(stationProtocol.isAutoing()); // 鏄惁鑷姩
+                vo.setLoading(stationProtocol.isLoading()); // 鏄惁鏈夌墿
+                vo.setInEnable(stationProtocol.isInEnable()); // 鏄惁鍙叆
+                vo.setOutEnable(stationProtocol.isOutEnable()); // 鏄惁鍙嚭
+                vo.setEmptyMk(stationProtocol.isEmptyMk()); // 鏄惁绌烘澘
+                vo.setFullPlt(stationProtocol.isFullPlt()); // 鏄惁婊℃澘
+                vo.setPalletHeight(stationProtocol.getPalletHeight()); // 鎵樼洏楂樺害
+                vo.setError(stationProtocol.getError()); // 閿欒鐮�
+                vo.setBarcode(stationProtocol.getBarcode()); // 鏉$爜
+                String stationStatus = StationStatusType.process(stationProtocol).toString().toLowerCase().replaceAll("_", "-");
+                vo.setStationStatus(stationStatus);
+                vos.add(vo);
+            }
+
+        }
+        return R.ok().add(vos);
+    }
+
+    @PostMapping("/latest/data/crn")
+    @ManagerAuth(memo = "鍫嗗灈鏈哄疄鏃舵暟鎹�")
+    public R crnLatestData() {
+        List<CrnLatestDataVo> vos = new ArrayList<>();
+
+        List<DeviceConfig> crnList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+                .eq("device_type", String.valueOf(SlaveType.Crn)));
+        for (DeviceConfig deviceConfig : crnList) {
+            // 鑾峰彇鍫嗗灈鏈轰俊鎭�
+            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, deviceConfig.getDeviceNo());
+            if (crnThread == null) {
+                continue;
+            }
+
+            CrnProtocol crnProtocol = crnThread.getStatus();
+            if (crnProtocol == null) {
+                continue;
+            }
+            CrnLatestDataVo vo = new CrnLatestDataVo();
+            vo.setCrnId(crnProtocol.getCrnNo()); // 鍫嗗灈鏈虹紪鍙�
+
+            vo.setOffset((double) new Random().nextInt(560)); // 鍫嗗灈鏈哄亸绉婚噺
+            vo.setBay(crnProtocol.getBay()); // 褰撳墠鍒�
+            /**
+             * 鍫嗗灈鏈虹姸鎬佸垽鏂�
+             */
+            if (crnProtocol.getAlarm() > 0) {
+                vo.setCrnStatus(CrnStatusType.MACHINE_ERROR);
+            } else {
+                if (crnProtocol.getTaskNo() > 0) {
+                    WrkMast wrkMast = wrkMastService.selectById(crnProtocol.getTaskNo());
+                    if (wrkMast != null) {
+                        vo.setCrnStatus(CrnStatusType.process(wrkMast.getIoType()));
+                    } else {
+                        vo.setCrnStatus(crnProtocol.modeType.equals(CrnModeType.AUTO) ? CrnStatusType.MACHINE_AUTO
+                                : CrnStatusType.MACHINE_UN_AUTO);
+                    }
+                } else {
+                    vo.setCrnStatus(crnProtocol.modeType.equals(CrnModeType.AUTO) ? CrnStatusType.MACHINE_AUTO
+                            : CrnStatusType.MACHINE_UN_AUTO);
+                }
+            }
+            vos.add(vo);
+        }
+        return R.ok().add(vos);
+    }
+
+    @PostMapping("/latest/data/rgv")
+    @ManagerAuth(memo = "RGV瀹炴椂鏁版嵁")
+    public R rgvLatestData(){
+        List<RgvLatestDataVo> vos = new ArrayList<>();
+        List<DeviceConfig> rgvList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+                .eq("device_type", String.valueOf(SlaveType.Rgv)));
+        for (DeviceConfig deviceConfig : rgvList) {
+            RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, deviceConfig.getDeviceNo());
+            if (rgvThread == null) {
+                continue;
+            }
+            RgvProtocol rgvProtocol = rgvThread.getStatus();
+            if (rgvProtocol == null) {
+                continue;
+            }
+            RgvLatestDataVo vo = new RgvLatestDataVo();
+            vo.setRgvNo(rgvProtocol.getRgvNo());
+            vo.setTrackSiteNo(String.valueOf(rgvProtocol.getRgvPos()));
+            vo.setRgvStatus(RgvStatusType.get(rgvProtocol.getStatus()));
+            vos.add(vo);
+        }
+        return R.ok().add(vos);
+    }
+
+    // @PostMapping("/latest/data/barcode")
+    // @ManagerAuth(memo = "鏉$爜鎵弿浠疄鏃舵暟鎹�")
+    // public R barcodeLatestData(){
+    // List<BarcodeDataVo> list = new ArrayList<>();
+    // for (Slave barcode : slaveProperties.getBarcode()) {
+    // BarcodeThread barcodeThread = (BarcodeThread)
+    // SlaveConnection.get(SlaveType.Barcode, barcode.getId());
+    // if (null == barcodeThread) {
+    // continue;
+    // }
+    // BarcodeDataVo vo = new BarcodeDataVo();
+    // vo.setBarcodeId(barcode.getId());
+    // vo.setCodeValue(barcodeThread.getBarcode());
+    // list.add(vo);
+    // }
+    // return R.ok().add(list);
+    // }
+
+    @PostMapping("/crn/detail")
+    @ManagerAuth(memo = "鍫嗗灈鏈鸿澶囨暟鎹鎯�")
+    public R crnDetail(@RequestParam Integer crnNo) {
+        if (Cools.isEmpty(crnNo)) {
+            return R.parse(CodeRes.EMPTY);
+        }
+        CrnDetailVo vo = new CrnDetailVo();
+
+        DeviceConfig deviceConfig = deviceConfigService.selectOne(new EntityWrapper<DeviceConfig>()
+                .eq("device_type", String.valueOf(SlaveType.Crn))
+                .eq("device_no", crnNo));
+
+        if (deviceConfig == null) {
+            return R.error("璁惧涓嶅瓨鍦�");
+        }
+
+        CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crnNo);
+        CrnProtocol crnProtocol = crnThread.getStatus();
+        vo.setCrnNo(crnNo);
+        vo.setWorkNo(crnProtocol.getTaskNo());
+        vo.setCrnStatus(crnProtocol.getStatusType().desc);
+
+        if (crnProtocol.getAlarm() > 0) {
+            BasCrnpErr crnError = basCrnpErrService.selectById(crnProtocol.getAlarm());
+            vo.setError(crnError == null ? "鏈煡寮傚父" : crnError.getErrName());
+        }
+
+        if (crnProtocol.getTaskNo() > 0) {
+            WrkMast wrkMast = wrkMastService.selectById(crnProtocol.getTaskNo());
+            if (wrkMast != null) {
+                vo.setSourceStaNo(String.valueOf(wrkMast.getSourceStaNo()));
+                vo.setStaNo(String.valueOf(wrkMast.getStaNo()));
+                vo.setWrkSts(wrkMast.getWrkSts$()); // 宸ヤ綔鐘舵��
+                vo.setIoType(wrkMast.getIoType$()); // 鍏ュ嚭搴撶被鍨�
+                vo.setSourceLocNo(wrkMast.getSourceLocNo$());
+                vo.setLocNo(wrkMast.getLocNo$());
+                vo.setCrnStatus(crnProtocol.getStatusType().desc);
+                vo.setError(""); // todo
+            }
+        }
+        return R.ok().add(vo);
     }
 
     /**
@@ -84,11 +265,7 @@
     @GetMapping("/map/lev/list")
     @ManagerAuth
     public R getMapLevList() {
-        List<BasMap> basMaps = basMapService.selectList(new EntityWrapper<BasMap>().orderBy("lev", true));
-        ArrayList<Integer> levList = new ArrayList<>();
-        for (BasMap basMap : basMaps) {
-            levList.add(basMap.getLev());
-        }
+        List<Integer> levList = locMastService.getLevList();
         return R.ok().add(levList);
     }
 
@@ -96,174 +273,20 @@
      * 鑾峰彇鍦板浘鏁版嵁
      */
     @GetMapping("/map/{lev}/auth")
-    @ManagerAuth
-    public R getMapFromRedis(@PathVariable Integer lev) {
-        Object data = redisUtil.get(RedisKeyType.MAP.key + lev);
-        if (data == null) {
-            return R.error();
-        }
-
-        List<List<MapNode>> arrayList = (List<List<MapNode>>) data;
-        List<List<MapNode>> lists = navigateMapData.filterMap(NavigationMapType.getMapTypes(NavigationMapType.NONE, NavigationMapType.PATH_LOCK), arrayList, lev, null, null);//杩囨护鍦板浘鏁版嵁
-        return R.ok().add(lists);
-    }
-
-    /**
-     * 鑾峰彇搴撲綅鍦板浘鏁版嵁
-     */
-    @GetMapping("/locMap/{lev}/auth")
-    @ManagerAuth
     public R getLocMap(@PathVariable Integer lev) {
-        Object data = redisUtil.get(RedisKeyType.MAP.key + lev);
-        if (data == null) {
-            return R.error();
+        Object object = redisUtil.get(RedisKeyType.LOC_MAP_BASE.key);
+        if (object == null) {
+            return R.error("鍦板浘鏈垵濮嬪寲");
         }
-
-        List<List<MapNode>> arrayList = (List<List<MapNode>>) data;
-        List<List<MapNode>> lists = navigateMapData.filterMap(NavigationMapType.getMapTypes(NavigationMapType.NONE), arrayList, lev, null, null);//杩囨护鍦板浘鏁版嵁
-
-        //鑾峰彇褰撳墠妤煎眰搴撲綅鏁版嵁
-        List<LocMast> locMasts = locMastService.selectLocByLev(lev);
-        for (LocMast locMast : locMasts) {
-            Integer row = locMast.getRow1();
-            Integer bay = locMast.getBay1();
-
-            List<MapNode> list = lists.get(row);
-            MapNode mapNode = list.get(bay);
-
-            mapNode.setLocSts(locMast.getLocSts());
-            mapNode.setLocNo(locMast.getLocNo());
-
-            //鏇存柊list
-            list.set(bay, mapNode);
-            lists.set(row, list);
+        List<List<HashMap<String, Object>>> mapNodeList = (List<List<HashMap<String, Object>>>) object;
+        List<LocMast> locMastList = locMastService.selectLocByLev(lev);
+        for (LocMast locMast : locMastList) {
+            String[] locType = locMast.getLocType().split("-");
+            HashMap<String, Object> mapNode = mapNodeList.get(Integer.parseInt(locType[0])).get(Integer.parseInt(locType[1]));
+            mapNode.put("locSts", locMast.getLocSts());
+            mapNode.put("locNo", locMast.getLocNo());
         }
-        return R.ok().add(lists);
-    }
-
-    /**
-     * 閲嶇疆redis涓殑鍦板浘锛屽皢鍗犵敤鐨勫簱浣嶅叏閮ㄨВ闄�
-     */
-    @GetMapping("/map/resetMap/auth")
-    @ManagerAuth
-    public R resetMapToRedis() {
-        List<BasMap> basMaps = basMapService.selectList(new EntityWrapper<BasMap>().orderBy("lev", true));
-        for (BasMap basMap : basMaps) {
-            Integer lev = basMap.getLev();
-            redisUtil.del(RedisKeyType.MAP.key + lev);
-        }
-        return R.ok();
-    }
-
-    /**
-     * 閲嶇疆redis涓殑鍦板浘锛屽皢鍗犵敤鐨勫簱浣嶅叏閮ㄨВ闄�
-     */
-    @GetMapping("/map/resetMap/{lev}")
-    @ManagerAuth(memo = "閲嶇疆Redis鍦板浘")
-    public R resetMapToRedisByLev(@PathVariable Integer lev, HttpServletRequest request) {
-        redisUtil.del(RedisKeyType.MAP.key + lev);
-        return R.ok();
-    }
-
-    /**
-     * 鑾峰彇棰勮璺緞
-     */
-    @GetMapping("/getMoveAdvancePath/{lev}/auth")
-    @ManagerAuth
-    public R getMoveAdvancePath(@PathVariable Integer lev) {
-        HashMap<String, Object> pathMap = new HashMap<>();
-
-        List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
-                .eq("device_type", String.valueOf(SlaveType.Shuttle)));
-        for (DeviceConfig deviceConfig : shuttleList) {
-            // 鑾峰彇鍥涘悜绌挎杞︿俊鎭�
-            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, deviceConfig.getDeviceNo());
-            if (shuttleThread == null) {
-                continue;
-            }
-            ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
-            if (shuttleProtocol == null || shuttleProtocol.getShuttleNo()==null) {
-                continue;
-            }
-
-            if (shuttleProtocol.getCurrentLocNo() == null) {
-                continue;
-            }
-
-            if (Utils.getLev(shuttleProtocol.getCurrentLocNo()) != lev) {
-                continue;
-            }
-
-            if (shuttleProtocol.getTaskNo() == 0) {
-
-            }
-
-            //瀛樺湪浠诲姟锛岃幏鍙栨寚浠�
-            Object object = redisUtil.get(RedisKeyType.SHUTTLE_WORK_FLAG.key + shuttleProtocol.getTaskNo());
-            if (object != null) {
-                ShuttleRedisCommand redisCommand = JSON.parseObject(object.toString(), ShuttleRedisCommand.class);
-                List<NavigateNode> nodes = redisCommand.getAssignCommand().getNodes();//绌挎杞﹂璁¤矾寰�
-
-                for (NavigateNode node : nodes) {
-                    String locNo = Utils.getLocNo(node.getX(), node.getY(), node.getZ());
-
-                    List<Integer> shuttleNoList = new ArrayList<>();
-                    Object tmp = pathMap.get(locNo);
-                    if(tmp != null) {
-                        shuttleNoList = (List<Integer>) tmp;
-                    }
-
-                    if (!shuttleNoList.contains(shuttleProtocol.getShuttleNo())) {
-                        shuttleNoList.add(shuttleProtocol.getShuttleNo());
-                    }
-
-                    pathMap.put(locNo, shuttleNoList);
-                }
-            }
-        }
-
-        List<HashMap<String, Object>> pathList = new ArrayList<>();
-        for (Map.Entry<String, Object> entry : pathMap.entrySet()) {
-            String locNo = entry.getKey();
-            Object shuttleNoList = entry.getValue();
-
-            HashMap<String, Object> map = new HashMap<>();
-            map.put("locNo", locNo);
-            map.put("x", Utils.getRow(locNo));
-            map.put("y", Utils.getBay(locNo));
-            map.put("z", Utils.getLev(locNo));
-            map.put("shuttleNoList", shuttleNoList);
-            pathList.add(map);
-        }
-        return R.ok().add(pathList);
-    }
-
-    /**
-     * 鑾峰彇閿佸畾璺緞
-     */
-    @GetMapping("/getLockPath/{lev}/auth")
-    @ManagerAuth
-    public R getLockPath(@PathVariable Integer lev) {
-        HashMap<String, Object> lockMap = new HashMap<>();
-        Object o = redisUtil.get(RedisKeyType.LOCK_MAP_NODES.key + lev);
-        if (o != null) {
-            lockMap = (HashMap<String, Object>) o;
-        }
-
-        List<HashMap<String, Object>> lockList = new ArrayList<>();
-        for (Map.Entry<String, Object> entry : lockMap.entrySet()) {
-            String locNo = entry.getKey();
-            Object shuttleNo = entry.getValue();
-
-            HashMap<String, Object> map = new HashMap<>();
-            map.put("locNo", locNo);
-            map.put("x", Utils.getRow(locNo));
-            map.put("y", Utils.getBay(locNo));
-            map.put("z", Utils.getLev(locNo));
-            map.put("shuttleNo", shuttleNo);
-            lockList.add(map);
-        }
-        return R.ok().add(lockList);
+        return R.ok().add(mapNodeList);
     }
 
 }

--
Gitblit v1.9.1