From 82c36e2b434fa7a1c16b0448aa4cf1483107f79c Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期二, 02 十二月 2025 16:28:20 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/controller/ConsoleController.java |  534 +++++++++++++++++++++++-----------------------------------
 1 files changed, 213 insertions(+), 321 deletions(-)

diff --git a/src/main/java/com/zy/asrs/controller/ConsoleController.java b/src/main/java/com/zy/asrs/controller/ConsoleController.java
index 617e48c..a775f51 100644
--- a/src/main/java/com/zy/asrs/controller/ConsoleController.java
+++ b/src/main/java/com/zy/asrs/controller/ConsoleController.java
@@ -1,56 +1,46 @@
 package com.zy.asrs.controller;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.plugins.Page;
 import com.core.annotations.ManagerAuth;
-import com.core.common.Arith;
 import com.core.common.Cools;
 import com.core.common.R;
 import com.zy.asrs.domain.enums.CrnStatusType;
-import com.zy.asrs.domain.enums.SiteStatusType;
+import com.zy.asrs.domain.enums.StationStatusType;
 import com.zy.asrs.domain.param.SystemSwitchParam;
-import com.zy.asrs.domain.vo.*;
-import com.zy.asrs.entity.BasDevp;
-import com.zy.asrs.entity.BasMap;
-import com.zy.asrs.entity.WrkMast;
-import com.zy.asrs.mapper.LocMastMapper;
-import com.zy.asrs.service.BasDevpService;
-import com.zy.asrs.service.BasMapService;
-import com.zy.asrs.service.WrkMastService;
+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.common.CodeRes;
-import com.zy.common.model.MapNode;
-import com.zy.common.model.enums.NavigationMapType;
-import com.zy.common.utils.NavigateMapData;
 import com.zy.common.utils.RedisUtil;
-import com.zy.core.CrnThread;
-import com.zy.core.DevpThread;
-import com.zy.core.Slave;
-import com.zy.core.cache.OutputQueue;
 import com.zy.core.cache.SlaveConnection;
 import com.zy.core.enums.CrnModeType;
 import com.zy.core.enums.RedisKeyType;
+import com.zy.core.enums.RgvStatusType;
 import com.zy.core.enums.SlaveType;
-import com.zy.core.model.CrnSlave;
-import com.zy.core.model.DevpSlave;
+import com.zy.core.enums.WrkIoType;
 import com.zy.core.model.protocol.CrnProtocol;
-import com.zy.core.model.protocol.StaProtocol;
-import com.zy.core.properties.SlaveProperties;
+import com.zy.core.model.protocol.StationProtocol;
 import com.zy.core.properties.SystemProperties;
-import com.zy.core.thread.BarcodeThread;
-import com.zy.core.thread.ScaleThread;
-import com.zy.core.thread.SiemensCrnThread;
+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 java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStreamReader;
 import java.util.*;
 
 /**
  * 涓绘帶鍥炬帴鍙�
- * Created by vincent on 2020-06-01
  */
 @Slf4j
 @RestController
@@ -58,388 +48,290 @@
 public class ConsoleController {
 
     @Autowired
-    private SlaveProperties slaveProperties;
+    private DeviceConfigService deviceConfigService;
     @Autowired
     private WrkMastService wrkMastService;
     @Autowired
-    private BasDevpService basDevpService;
+    private BasCrnpErrService basCrnpErrService;
     @Autowired
-    private BasMapService basMapService;
-    @Autowired
-    private LocMastMapper locMastMapper;
+    private WrkLastnoService wrkLastnoService;
     @Autowired
     private RedisUtil redisUtil;
+    @Autowired
+    private LocMastService locMastService;
 
     @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")
+    @PostMapping("/latest/data/station")
     @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());
+    public R stationLatestData() {
+        List<StationLatestDataVo> vos = new ArrayList<>();
+
+        WrkLastno inTaskRange = wrkLastnoService.selectById(WrkIoType.IN.id);
+        WrkLastno outTaskRange = wrkLastnoService.selectById(WrkIoType.OUT.id);
+
+        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;
             }
-        }
-        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);
+
+            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("_", "-");
+                if (stationProtocol.isAutoing() && stationProtocol.isLoading() && stationProtocol.getTaskNo() > 0) {
+                    String taskClass = getStationTaskClass(stationProtocol.getTaskNo(), inTaskRange, outTaskRange);
+                    if (taskClass != null) {
+                        stationStatus = taskClass;
+                    }
+                }
+                vo.setStationStatus(stationStatus);
+                vos.add(vo);
+            }
+
         }
         return R.ok().add(vos);
+    }
+
+    private String getStationTaskClass(Integer taskNo, WrkLastno inTaskRange, WrkLastno outTaskRange) {
+        if (taskNo == null || taskNo <= 0) {
+            return null;
+        }
+        if (isInRange(taskNo, inTaskRange)) {
+            return "machine-pakin";
+        }
+        if (isInRange(taskNo, outTaskRange)) {
+            return "machine-pakout";
+        }
+        return null;
+    }
+
+    private boolean isInRange(Integer taskNo, WrkLastno taskRange) {
+        if (taskRange == null || taskRange.getSNo() == null || taskRange.getENo() == null) {
+            return false;
+        }
+        return taskNo >= taskRange.getSNo() && taskNo <= taskRange.getENo();
     }
 
     @PostMapping("/latest/data/crn")
     @ManagerAuth(memo = "鍫嗗灈鏈哄疄鏃舵暟鎹�")
-    public R crnLatestData(){
+    public R crnLatestData() {
         List<CrnLatestDataVo> vos = new ArrayList<>();
-        for (CrnSlave crn : slaveProperties.getCrn()) {
+
+        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, crn.getId());
+            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, deviceConfig.getDeviceNo());
             if (crnThread == null) {
                 continue;
             }
-            CrnProtocol crnProtocol = crnThread.getCrnProtocol();
+
+            CrnProtocol crnProtocol = crnThread.getStatus();
             if (crnProtocol == null) {
                 continue;
             }
             CrnLatestDataVo vo = new CrnLatestDataVo();
-            vo.setCrnId(crn.getId());   //  鍫嗗灈鏈虹紪鍙�
+            vo.setCrnId(crnProtocol.getCrnNo()); // 鍫嗗灈鏈虹紪鍙�
 
-//            Short totalBay = locMastMapper.selectTotalBay();
-
-            vo.setOffset((double) new Random().nextInt(560));     //  鍫嗗灈鏈哄亸绉婚噺
-            vo.setBay((short) (crnProtocol.getBay() - crn.getOffset()));    //  褰撳墠鍒�
+            // 浣跨敤瀹為檯鍒楀�间綔涓哄亸绉诲弬鑰冿紝閬垮厤闅忔満鍧愭爣瀵艰嚧鐣岄潰婕傜Щ
+            vo.setOffset(Double.valueOf(crnProtocol.getBay()));
+            vo.setBay(crnProtocol.getBay()); // 褰撳墠鍒�
+            vo.setTaskNo(crnProtocol.getTaskNo());
             /**
              * 鍫嗗灈鏈虹姸鎬佸垽鏂�
              */
-            if (crn.getId() == 1 && crnProtocol.getAlarm() > 0) {
+            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);
-
         }
         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) {
+    @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;
             }
-            BarcodeDataVo vo = new BarcodeDataVo();
-            vo.setBarcodeId(barcode.getId());
-            vo.setCodeValue(barcodeThread.getBarcode());
-            list.add(vo);
-        }
-        return R.ok().add(list);
-    }
-
-    @PostMapping("/latest/data/scale")
-    @ManagerAuth(memo = "纾呯Г瀹炴椂鏁版嵁")
-    public R scaleLatestData(){
-        List<ScaleDataVo> list = new ArrayList<>();
-        for (Slave scale : slaveProperties.getScale()) {
-            ScaleThread scaleThread = (ScaleThread) SlaveConnection.get(SlaveType.Scale, scale.getId());
-            if (null == scaleThread) {
+            RgvProtocol rgvProtocol = rgvThread.getStatus();
+            if (rgvProtocol == null) {
                 continue;
             }
-            ScaleDataVo vo = new ScaleDataVo();
-            vo.setScaleId(scale.getId());
-            vo.setValue(String.valueOf(Arith.multiplys(1, scaleThread.getScale(), 1)));
-            list.add(vo);
+            RgvLatestDataVo vo = new RgvLatestDataVo();
+            vo.setRgvNo(rgvProtocol.getRgvNo());
+            vo.setTaskNo(rgvProtocol.getTaskNo());
+            vo.setTrackSiteNo(String.valueOf(rgvProtocol.getRgvPos()));
+            vo.setRgvStatus(RgvStatusType.get(rgvProtocol.getStatus()));
+            vos.add(vo);
         }
-        return R.ok().add(list);
+        return R.ok().add(vos);
     }
 
-    /****************************************************************/
-    /************************** 璇︽儏鎿嶄綔 ******************************/
-    /****************************************************************/
-
-    @PostMapping("/site/detail")
-    @ManagerAuth(memo = "杈撻�佽澶囨暟鎹鎯�")
-    public R siteDetail(@RequestParam Integer siteId){
-        if (Cools.isEmpty(siteId)){
-            return R.parse(CodeRes.EMPTY);
-        }
-        SiteDetailVo vo = new SiteDetailVo();
-        for (DevpSlave devp : slaveProperties.getDevp()) {
-            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
-            if (null != devpThread) {
-                StaProtocol staProtocol = devpThread.getStation().get(siteId);
-                if (staProtocol != null) {
-                    BasDevp basDevp = basDevpService.selectById(siteId);
-                    if (basDevp == null) {
-                        return R.error("鏁版嵁搴撶淮鎶ゅ紓甯�");
-                    }
-                    vo.setSiteId(siteId);   // 绔欑偣缂栧彿
-                    vo.setWorkNo(staProtocol.getWorkNo());   // 宸ヤ綔鍙�
-
-                    if (staProtocol.getWorkNo() > 0) {
-                        WrkMast wrkMast = wrkMastService.selectById(staProtocol.getWorkNo());
-                        if (wrkMast != null) {
-                            vo.setWrkSts(wrkMast.getWrkSts$());   // 宸ヤ綔鐘舵��
-                            vo.setIoType(wrkMast.getIoType$());   //  鍏ュ嚭搴撶被鍨�
-                            vo.setSourceStaNo(wrkMast.getSourceStaNo$());
-                            vo.setStaNo(wrkMast.getStaNo$());
-                            vo.setSourceLocNo(wrkMast.getSourceLocNo$());
-                            vo.setLocNo(wrkMast.getLocNo$());
-                        }
-                    }
-
-                    vo.setAutoing(staProtocol.isAutoing()?"Y":"N"); //  鑷姩
-                    vo.setLoading(staProtocol.isLoading()?"Y":"N"); //  鏈夌墿
-
-                    vo.setCanining(basDevp.getCanining());  //  鑳藉叆
-                    vo.setCanouting(basDevp.getCanouting());    //  鑳藉嚭
-
-                    return R.ok().add(vo);
-                }
-            }
-        }
-        return R.error();
-
-    }
+    // @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();
-        for (CrnSlave crnSlave : slaveProperties.getCrn()) {
-            if (crnSlave.getId().equals(crnNo)) {
-                SiemensCrnThread crnThread = (SiemensCrnThread) SlaveConnection.get(SlaveType.Crn, crnSlave.getId());
-                CrnProtocol crnProtocol = crnThread.getCrnProtocol();
-                vo.setCrnNo(crnNo);
-                vo.setWorkNo(crnProtocol.getTaskNo());
-                if (crnProtocol.getTaskNo() > 0) {
-                    WrkMast wrkMast = wrkMastService.selectById(crnProtocol.getTaskNo());
-                    if (wrkMast != null) {
-                        vo.setSourceStaNo(wrkMast.getSourceStaNo$());
-                        vo.setStaNo(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);
+
+        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.error();
+        return R.ok().add(vo);
     }
 
-    @Deprecated
-    @PostMapping("/site/update")
-    @ManagerAuth(memo = "杈撻�佽澶囨暟鎹慨鏀�")
-    public R updateSite(){
-        return R.ok();
-    }
-
-    @Deprecated
-    @PostMapping("/crn/update")
-    @ManagerAuth(memo = "鍫嗗灈鏈烘暟鎹慨鏀�")
-    public R updateCrn(){
-        return R.ok();
-    }
-
-    @GetMapping("/barcode/output/site")
-    public R crnOutput(){
-//        StringBuilder str = new StringBuilder();
-//        String s;
-//        int i = 0;
-//        while((s = OutputQueue.CRN.poll()) != null && i <=32) {
-//            str.append("\n").append(s);
-//            i++;
-//        }
-//        return R.ok().add(str.toString());
-        return R.ok().add(JSON.toJSONString(new ArrayList<>(OutputQueue.BARCODE)));
+    /**
+     * 鑾峰彇鍦板浘妤煎眰鏁版嵁
+     */
+    @GetMapping("/map/lev/list")
+    @ManagerAuth
+    public R getMapLevList() {
+        List<Integer> levList = locMastService.getLevList();
+        return R.ok().add(levList);
     }
 
     /**
      * 鑾峰彇鍦板浘鏁版嵁
      */
     @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();
+    public R getLocMap(@PathVariable Integer lev) {
+        Object object = redisUtil.get(RedisKeyType.LOC_MAP_BASE.key);
+        if (object == null) {
+            return R.error("鍦板浘鏈垵濮嬪寲");
         }
-
-        BasMap basMap = JSON.parseObject(data.toString(), BasMap.class);
-        //瑙f瀽json鍦板浘鏁版嵁
-        ArrayList arrayList = JSON.parseObject(basMap.getData(), ArrayList.class);
-        NavigateMapData navigateMapData = new NavigateMapData(lev);
-        List<List<MapNode>> lists = navigateMapData.filterMap(NavigationMapType.NONE.id, arrayList, lev, null, null);//杩囨护鍦板浘鏁版嵁
-        return R.ok().add(lists);
+        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(mapNodeList);
     }
 
-    /**
-     * 鑾峰彇PLC2鏁版嵁
-     */
-    @GetMapping("/plc2/auth")
-    @ManagerAuth
-    public R getMapFromPlc2() {
-        try {
-            String mapFilename = "plc2.json";
-            String fileName = this.getClass().getClassLoader().getResource(mapFilename).getPath();//鑾峰彇鏂囦欢璺緞
-            File file = new File(fileName);
-            StringBuffer stringBuffer = new StringBuffer();
-            if (file.isFile() && file.exists()) {
-                InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "GBK");
-                BufferedReader br = new BufferedReader(isr);
-                String lineTxt = null;
-                while ((lineTxt = br.readLine()) != null) {
-                    stringBuffer.append(lineTxt);
-                }
-                br.close();
-            }
-
-            NavigateMapData navigateMapData = new NavigateMapData();
-
-            //瑙f瀽json鍦板浘鏁版嵁
-            ArrayList arrayList = JSON.parseObject(stringBuffer.toString(), ArrayList.class);
-            List<List<MapNode>> lists = new ArrayList<>();
-            //閲嶅缓鏁版嵁鏍煎紡
-            for (int i = 0; i < arrayList.size(); i++) {
-                Object obj = arrayList.get(i);
-                List<MapNode> list = JSON.parseArray(obj.toString(), MapNode.class);
-                for (int j = 0; j < list.size(); j++) {
-                    MapNode mapNode = list.get(j);
-                    list.set(j, mapNode);
-                }
-                lists.add(list);
-            }
-            return R.ok().add(lists);
-        } catch (Exception e) {
-            e.printStackTrace();
+    @RequestMapping(value = "/map/locList")
+    public R mapLocList() {
+        Object object = redisUtil.get(RedisKeyType.LOC_MAST_MAP_LIST.key);
+        if (object != null) {
+            JSONArray data = JSON.parseArray(object.toString());
+            return R.ok().add(data);
         }
-
-        return R.error();
-    }
-
-    /**
-     * 閲嶇疆redis涓殑鍦板浘锛屽皢鍗犵敤鐨勫簱浣嶅叏閮ㄨВ闄�
-     */
-    @GetMapping("/map/resetMap/auth")
-    @ManagerAuth
-    public R resetMapToRedis() {
-        for (int i = 1; i <= 10; i++) {//鎬诲叡10灞傛ゼ
-            BasMap basMap = basMapService.selectLatestMap(i);
-            //杞藉叆鍦板浘
-            NavigateMapData mapData = new NavigateMapData(i);
-            List<List<MapNode>> lists = mapData.getJsonData(-1, null, null);//鑾峰彇瀹屾暣鍦板浘(鍖呮嫭鍏ュ簱鍑哄簱)
-            if (basMap == null) {
-                //鏁版嵁搴撲腑涔熶笉瀛樺湪鍦板浘鏁版嵁锛屼粠鍦板浘鏂囦欢涓幏鍙�
-                //瀛樺叆鏁版嵁搴�
-                basMap = new BasMap();
-                basMap.setData(JSON.toJSONString(lists));
-                basMap.setCreateTime(new Date());
-                basMap.setUpdateTime(new Date());
-                basMap.setLev(i);
-
-                if (!basMapService.insert(basMap)) {
-                    log.info("鍦板浘鏁版嵁瀛樺偍澶辫触");
-                }
-            }else {
-                basMap.setData(JSON.toJSONString(lists));
-                basMap.setUpdateTime(new Date());
-                if (!basMapService.updateById(basMap)) {
-                    log.info("鍦板浘鏁版嵁瀛樺偍澶辫触");
-                }
-            }
-
-            //灏嗘暟鎹簱鍦板浘鏁版嵁瀛樺叆redis
-            redisUtil.set(RedisKeyType.MAP.key + i, JSON.toJSONString(basMap));
-        }
-        return R.ok();
-    }
-
-    /**
-     * 閲嶇疆redis涓殑鍦板浘锛屽皢鍗犵敤鐨勫簱浣嶅叏閮ㄨВ闄�
-     */
-    @GetMapping("/map/resetMap/{lev}")
-    @ManagerAuth(memo = "閲嶇疆Redis鍦板浘")
-    public R resetMapToRedisByLev(@PathVariable Integer lev) {
-        BasMap basMap = basMapService.selectLatestMap(lev);
-        //杞藉叆鍦板浘
-        NavigateMapData mapData = new NavigateMapData(lev);
-        List<List<MapNode>> lists = mapData.getJsonData(-1, null, null);//鑾峰彇瀹屾暣鍦板浘(鍖呮嫭鍏ュ簱鍑哄簱)
-        if (basMap == null) {
-            //鏁版嵁搴撲腑涔熶笉瀛樺湪鍦板浘鏁版嵁锛屼粠鍦板浘鏂囦欢涓幏鍙�
-            //瀛樺叆鏁版嵁搴�
-            basMap = new BasMap();
-            basMap.setData(JSON.toJSONString(lists));
-            basMap.setCreateTime(new Date());
-            basMap.setUpdateTime(new Date());
-            basMap.setLev(lev);
-
-            if (!basMapService.insert(basMap)) {
-                log.info("鍦板浘鏁版嵁瀛樺偍澶辫触");
-            }
-        }else {
-            basMap.setData(JSON.toJSONString(lists));
-            basMap.setUpdateTime(new Date());
-            if (!basMapService.updateById(basMap)) {
-                log.info("鍦板浘鏁版嵁瀛樺偍澶辫触");
-            }
-        }
-
-        //灏嗘暟鎹簱鍦板浘鏁版嵁瀛樺叆redis
-        redisUtil.set(RedisKeyType.MAP.key + lev, JSON.toJSONString(basMap));
-        return R.ok();
+        EntityWrapper<LocMast> wrapper = new EntityWrapper<>();
+        wrapper.eq("lev1", 1);
+        List<LocMast> locMasts = locMastService.selectList(wrapper);
+        redisUtil.set(RedisKeyType.LOC_MAST_MAP_LIST.key, JSON.toJSONString(locMasts), 60 * 60 * 24);
+        return R.ok().add(locMasts);
     }
 
 }

--
Gitblit v1.9.1