From 1b4fbdb92537036aed4d648967ef7e7ab8842aec Mon Sep 17 00:00:00 2001
From: Junjie <540245094@qq.com>
Date: 星期四, 13 十一月 2025 16:37:11 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/controller/ConsoleController.java |  194 +++++++++++++++++++++++++++---------------------
 1 files changed, 108 insertions(+), 86 deletions(-)

diff --git a/src/main/java/com/zy/asrs/controller/ConsoleController.java b/src/main/java/com/zy/asrs/controller/ConsoleController.java
index 5509d4b..60d31e8 100644
--- a/src/main/java/com/zy/asrs/controller/ConsoleController.java
+++ b/src/main/java/com/zy/asrs/controller/ConsoleController.java
@@ -1,15 +1,15 @@
 package com.zy.asrs.controller;
 
-import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.core.annotations.ManagerAuth;
 import com.core.common.Cools;
 import com.core.common.R;
-import com.core.exception.CoolException;
 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.domain.vo.CrnDetailVo;
 import com.zy.asrs.domain.vo.CrnLatestDataVo;
+import com.zy.asrs.domain.vo.StationLatestDataVo;
 import com.zy.asrs.entity.BasCrnpErr;
 import com.zy.asrs.entity.DeviceConfig;
 import com.zy.asrs.entity.WrkMast;
@@ -17,15 +17,15 @@
 import com.zy.asrs.service.DeviceConfigService;
 import com.zy.asrs.service.WrkMastService;
 import com.zy.common.CodeRes;
-import com.zy.core.Slave;
-import com.zy.core.ThreadHandler;
 import com.zy.core.cache.SlaveConnection;
 import com.zy.core.enums.CrnModeType;
 import com.zy.core.enums.SlaveType;
 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.CrnThread;
-import com.zy.core.thread.impl.ZySiemensCrnThread;
+import com.zy.core.thread.StationThread;
+
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -50,54 +50,73 @@
 
     @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/site")
-//    @ManagerAuth(memo = "绔欑偣瀹炴椂鏁版嵁")
-//    public R siteLatestData(){
-//        List<SiteLatestDataVo> vos = new ArrayList<>();
-//        Map<Integer, StaProtocol> stations = new HashMap<>();
-//        for (DevpSlave devp : slaveProperties.getDevp()) {
-//            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
-//            if (null != devpThread) {
-//                stations.putAll(devpThread.getStation());
-//            }
-//        }
-//        for (Map.Entry<Integer, StaProtocol> entry : stations.entrySet()) {
-//            SiteLatestDataVo vo = new SiteLatestDataVo();
-//            StaProtocol staProtocol = entry.getValue();
-//            vo.setSiteId(String.valueOf(entry.getKey())); // 绔欑偣缂栧彿
-//            vo.setWorkNo(staProtocol.getWorkNo()); // 宸ヤ綔鍙�
-//            vo.setSiteStatus(SiteStatusType.process(staProtocol));  // 鐘舵��
-//            vos.add(vo);
-//        }
-//        return R.ok().add(vos);
-//    }
+    @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(){
+    public R crnLatestData() {
         List<CrnLatestDataVo> vos = new ArrayList<>();
 
         List<DeviceConfig> crnList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
@@ -114,25 +133,27 @@
                 continue;
             }
             CrnLatestDataVo vo = new CrnLatestDataVo();
-            vo.setCrnId(crnProtocol.getCrnNo());   //  鍫嗗灈鏈虹紪鍙�
+            vo.setCrnId(crnProtocol.getCrnNo()); // 鍫嗗灈鏈虹紪鍙�
 
-            vo.setOffset((double) new Random().nextInt(560));     //  鍫嗗灈鏈哄亸绉婚噺
-            vo.setBay(crnProtocol.getBay());    //  褰撳墠鍒�
+            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) {
+                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);
+                        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);
+                    vo.setCrnStatus(crnProtocol.modeType.equals(CrnModeType.AUTO) ? CrnStatusType.MACHINE_AUTO
+                            : CrnStatusType.MACHINE_UN_AUTO);
                 }
             }
             vos.add(vo);
@@ -140,61 +161,62 @@
         return R.ok().add(vos);
     }
 
-//    @PostMapping("/latest/data/rgv")
-//    @ManagerAuth(memo = "RGV瀹炴椂鏁版嵁")
-//    public R rgvLatestData(){
-//        List<RgvLatestDataVo> vos = new ArrayList<>();
-//        for (RgvSlave rgvSlave : slaveProperties.getRgv()) {
-//            // 鑾峰彇鍫嗗灈鏈轰俊鎭�
-//            RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgvSlave.getId());
-//            if (rgvThread == null) {
-//                continue;
-//            }
-//            RgvProtocol rgvProtocol = rgvThread.getRgvProtocol();
-//            if (rgvProtocol == null) {
-//                continue;
-//            }
-//            RgvLatestDataVo vo = new RgvLatestDataVo();
-//            vo.setRgvId(rgvProtocol.getRgvNo());   //  RGV缂栧彿
-//            vo.setTrackSiteNo(String.valueOf(rgvProtocol.getRgvPos()));
-//            vo.setRgvStatus(rgvProtocol.getStatusType());
-//            vos.add(vo);
-//
-//        }
-//        Object object = redisUtil.get("rgvLatestData");
-//        List<Object> siteLatestDataVos = JSON.parseArray(object.toString());
-//        return R.ok().add(siteLatestDataVos);
-//    }
+    // @PostMapping("/latest/data/rgv")
+    // @ManagerAuth(memo = "RGV瀹炴椂鏁版嵁")
+    // public R rgvLatestData(){
+    // List<RgvLatestDataVo> vos = new ArrayList<>();
+    // for (RgvSlave rgvSlave : slaveProperties.getRgv()) {
+    // // 鑾峰彇鍫嗗灈鏈轰俊鎭�
+    // RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv,
+    // rgvSlave.getId());
+    // if (rgvThread == null) {
+    // continue;
+    // }
+    // RgvProtocol rgvProtocol = rgvThread.getRgvProtocol();
+    // if (rgvProtocol == null) {
+    // continue;
+    // }
+    // RgvLatestDataVo vo = new RgvLatestDataVo();
+    // vo.setRgvId(rgvProtocol.getRgvNo()); // RGV缂栧彿
+    // vo.setTrackSiteNo(String.valueOf(rgvProtocol.getRgvPos()));
+    // vo.setRgvStatus(rgvProtocol.getStatusType());
+    // vos.add(vo);
+    //
+    // }
+    // Object object = redisUtil.get("rgvLatestData");
+    // List<Object> siteLatestDataVos = JSON.parseArray(object.toString());
+    // return R.ok().add(siteLatestDataVos);
+    // }
 
-//    @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("/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)){
+    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)
-        );
+                .eq("device_no", crnNo));
 
         if (deviceConfig == null) {
             return R.error("璁惧涓嶅瓨鍦�");
@@ -216,12 +238,12 @@
             if (wrkMast != null) {
                 vo.setSourceStaNo(String.valueOf(wrkMast.getSourceStaNo()));
                 vo.setStaNo(String.valueOf(wrkMast.getStaNo()));
-                vo.setWrkSts(wrkMast.getWrkSts$());   // 宸ヤ綔鐘舵��
-                vo.setIoType(wrkMast.getIoType$());   //  鍏ュ嚭搴撶被鍨�
+                vo.setWrkSts(wrkMast.getWrkSts$()); // 宸ヤ綔鐘舵��
+                vo.setIoType(wrkMast.getIoType$()); // 鍏ュ嚭搴撶被鍨�
                 vo.setSourceLocNo(wrkMast.getSourceLocNo$());
                 vo.setLocNo(wrkMast.getLocNo$());
                 vo.setCrnStatus(crnProtocol.getStatusType().desc);
-                vo.setError("");    // todo
+                vo.setError(""); // todo
             }
         }
         return R.ok().add(vo);

--
Gitblit v1.9.1