From 6ba157825d34078a75fee36cb66ead17327f5b32 Mon Sep 17 00:00:00 2001
From: zjj <3272660260@qq.com>
Date: 星期二, 29 四月 2025 14:32:55 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/controller/SiteController.java |  291 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 252 insertions(+), 39 deletions(-)

diff --git a/src/main/java/com/zy/asrs/controller/SiteController.java b/src/main/java/com/zy/asrs/controller/SiteController.java
index 9c6ae40..acdda6d 100644
--- a/src/main/java/com/zy/asrs/controller/SiteController.java
+++ b/src/main/java/com/zy/asrs/controller/SiteController.java
@@ -1,25 +1,32 @@
 package com.zy.asrs.controller;
 
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.core.annotations.ManagerAuth;
+import com.core.common.Cools;
 import com.core.common.R;
 import com.zy.asrs.domain.vo.PlcErrorTableVo;
 import com.zy.asrs.domain.vo.SiteTableVo;
+import com.zy.asrs.entity.BasDevp;
+import com.zy.asrs.entity.BasRgv;
+import com.zy.asrs.service.BasDevpService;
+import com.zy.asrs.service.BasRgvService;
+import com.zy.core.cache.MessageQueue;
 import com.zy.core.cache.OutputQueue;
 import com.zy.core.cache.SlaveConnection;
 import com.zy.core.enums.SlaveType;
 import com.zy.core.model.DevpSlave;
+import com.zy.core.model.Task;
 import com.zy.core.model.protocol.StaProtocol;
 import com.zy.core.properties.SlaveProperties;
-import com.zy.core.thread.DevpThread;
+import com.zy.core.DevpThread;
+import com.zy.core.thread.SiemensDevpThread;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Random;
 
 /**
  * 杈撻�佽澶囨帴鍙�
@@ -31,32 +38,56 @@
 
     @Autowired
     private SlaveProperties slaveProperties;
+    @Autowired
+    private BasDevpService basDevpService;
+    @Autowired
+    private BasRgvService basRgvService;
+
+    @GetMapping("/io/mode/info/site")
+    @ManagerAuth(memo = "鍏ュ嚭搴撴ā寮�")
+    public R ioMode(){
+        List<Map<String, Object>> res = new ArrayList<>();
+        for (DevpSlave devp : slaveProperties.getDevp()) {
+            SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
+            Map<String, Object> map2 = new HashMap<>();
+            map2.put("floor", 2);
+            map2.put("modeVal", devpThread.ioModeOf2F.id);
+            map2.put("modeDesc", devpThread.ioModeOf2F.desc);
+            res.add(map2);
+        }
+        return R.ok().add(res);
+    }
 
     @PostMapping("/table/site")
     @ManagerAuth(memo = "绔欑偣淇℃伅琛�")
     public R siteTable(){
         List<SiteTableVo> list = new ArrayList<>();
-
+        // 鍐呭瓨鏁版嵁
+        Map<Integer, StaProtocol> station = new HashMap<>();
         for (DevpSlave devp : slaveProperties.getDevp()) {
             DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
-            Map<Integer, StaProtocol> station = devpThread.getStation();
-            for (Map.Entry<Integer, StaProtocol> entry : station.entrySet()) {
-                StaProtocol staProtocol = entry.getValue();
-                SiteTableVo vo = new SiteTableVo();
-
-                vo.setDevNo(entry.getKey());    // 绔欑偣缂栧彿
-                vo.setWorkNo(staProtocol.getWorkNo());   //  宸ヤ綔鍙�
-                vo.setAutoing(staProtocol.isAutoing()?"Y":"N");     //  鑷姩
-                vo.setLoading(staProtocol.isLoading()?"Y":"N");     // 鏈夌墿
-                vo.setInEnable(staProtocol.isInEnable()?"Y":"N");   // 鍙叆
-                vo.setOutEnable(staProtocol.isOutEnable()?"Y":"N"); // 鍙嚭
-                vo.setInreq1(staProtocol.isInreq1()?"Y":"N");       // 闇�姹�1
-                vo.setEmptyMk(staProtocol.isEmptyMk()?"Y":"N");     // 绌烘澘淇″彿
-                vo.setStaNo(staProtocol.getStaNo());                // 鐩爣绔�
-
-                list.add(vo);
-            }
+            station.putAll(devpThread.getStation());
         }
+        // 鎸佷箙鏁版嵁
+        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<BasDevp>().orderBy("dev_no"));
+        for (BasDevp devp : basDevps) {
+            SiteTableVo vo = new SiteTableVo();
+            vo.setDevNo(devp.getDevNo());    // 绔欑偣缂栧彿
+
+            list.add(vo);
+            StaProtocol staProtocol = station.get(devp.getDevNo());
+            if (null == staProtocol) { continue; }
+            vo.setAutoing(staProtocol.isAutoing()?"Y":"N");     //  鑷姩
+            vo.setLoading(staProtocol.isLoading()?"Y":"N");     // 鏈夌墿
+            vo.setInEnable(staProtocol.isInEnable()?"Y":"N");   // 鍙叆
+            vo.setOutEnable(staProtocol.isOutEnable()?"Y":"N"); // 鍙嚭
+            vo.setPakMk(staProtocol.isPakMk()?"Y":"N");       // 鍏ュ簱鏍囪
+            vo.setEmptyMk(staProtocol.isEmptyMk()?"Y":"N");     // 绌烘澘淇″彿
+            vo.setStaNo(staProtocol.getStaNo());                // 鐩爣绔�
+//            vo.setLocType1(staProtocol.isHigh() != staProtocol.isLow() && staProtocol.isLow() ? "浣�" : "楂�");     //楂樹綆搴撲綅
+            vo.setLocType1(devp.getDevNo()==102 ? "楂�" : "浣�");
+        }
+
         return R.ok().add(list);
     }
 
@@ -64,23 +95,17 @@
     @ManagerAuth(memo = "杈撻�佽澶噋lc寮傚父淇℃伅琛�")
     public R plcErrorTable(){
         List<PlcErrorTableVo> list = new ArrayList<>();
-        for (int i = 0; i<new Random().nextInt(13); i++){
-            PlcErrorTableVo table = new PlcErrorTableVo();
-            table.setNo(String.valueOf(i));
-            table.setError("寮傚父淇℃伅");
-            table.setPlcDesc("plc寮傚父鎻忚堪");
-            list.add(table);
-        }
-        list.sort((o1, o2) -> {
-            if (o1.getNo().compareTo(o2.getNo()) > 0){
-                return 1;
-            }else if (o1.getNo().compareTo(o2.getNo()) < 0){
-                return 0;
-            }else{
-                return -1;
-            }
+        for (DevpSlave devp : slaveProperties.getDevp()) {
+            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
+            Map<Integer, StaProtocol> station = devpThread.getStation();
 
-        });
+            for(Map.Entry<Integer, StaProtocol> entry : station.entrySet()) {
+                if (!Cools.isEmpty(staPlcErr(entry))){
+                    list.add(staPlcErr(entry).get(0)) ;
+                }
+
+            }
+        }
         return R.ok().add(list);
     }
 
@@ -97,4 +122,192 @@
         return R.ok().add(str.toString());
     }
 
+    /****************************************************************/
+    /************************** 璇︽儏鎿嶄綔 ******************************/
+    /****************************************************************/
+
+    @GetMapping("/detl/{siteId}")
+    public R siteDetl(@PathVariable("siteId") Integer siteId){
+        SiteTableVo vo = new SiteTableVo();
+        for (DevpSlave devp : slaveProperties.getDevp()) {
+            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
+            Map<Integer, StaProtocol> station = devpThread.getStation();
+            for (Map.Entry<Integer, StaProtocol> entry : station.entrySet()) {
+                if (siteId.equals(entry.getKey())) {
+                    StaProtocol staProtocol = entry.getValue();
+                    vo.setDevNo(entry.getKey());    // 绔欑偣缂栧彿
+                    vo.setWorkNo(staProtocol.getWorkNo());   //  宸ヤ綔鍙�
+                    vo.setAutoing(staProtocol.isAutoing()?"Y":"N");     //  鑷姩
+                    vo.setLoading(staProtocol.isLoading()?"Y":"N");     // 鏈夌墿
+                    vo.setInEnable(staProtocol.isInEnable()?"Y":"N");   // 鍙叆
+                    vo.setOutEnable(staProtocol.isOutEnable()?"Y":"N"); // 鍙嚭
+                    vo.setPakMk(staProtocol.isPakMk()?"Y":"N");       // 闇�姹�1
+                    vo.setEmptyMk(staProtocol.isEmptyMk()?"Y":"N");     // 绌烘澘淇″彿
+                    vo.setStaNo(staProtocol.getStaNo());                // 鐩爣绔�
+                    vo.setLocType1(staProtocol.isHigh() != staProtocol.isLow() && staProtocol.isLow() ? "浣�" : "楂�");     //楂樹綆搴撲綅
+                    return R.ok().add(vo);
+                }
+            }
+        }
+        return R.error("plc宸叉帀绾�");
+    }
+
+    @PostMapping("/detl/update")
+    @ManagerAuth(memo = "淇敼绔欑偣鏁版嵁")
+    public R siteDetlUpdate(@RequestParam Integer siteId,
+                            @RequestParam Integer workNo,
+                            @RequestParam Short staNo,
+                            @RequestParam String pakMk){
+        for (DevpSlave devp : slaveProperties.getDevp()) {
+            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
+            Map<Integer, StaProtocol> station = devpThread.getStation();
+            for (Map.Entry<Integer, StaProtocol> entry : station.entrySet()) {
+                if (siteId.equals(entry.getKey())) {
+                    StaProtocol staProtocol = entry.getValue();
+                    if (staProtocol == null) {
+                        continue;
+                    } else {
+                        staProtocol = staProtocol.clone();
+                    }
+                    if (workNo != null) {
+                        staProtocol.setWorkNo(workNo);
+                    }
+                    if (staNo != null) {
+                        staProtocol.setStaNo(staNo);
+                    }
+                    if (pakMk != null) {
+                        staProtocol.setPakMk(pakMk.equals("Y"));
+                    }
+                    boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
+                    if (result) {
+                        return R.ok();
+                    } else {
+                        return R.error("涓嬪彂鍛戒护澶辫触");
+                    }
+                }
+            }
+        }
+        return R.error("plc宸叉帀绾�");
+    }
+
+    public List<PlcErrorTableVo> staPlcErr(Map.Entry<Integer, StaProtocol> entry){
+        List<PlcErrorTableVo> list = new ArrayList<>();
+        StaProtocol staProtocol = entry.getValue();
+        if (staProtocol.getBreakerErr()){
+            PlcErrorTableVo vo = new PlcErrorTableVo();
+            vo.setNo(entry.getKey());   //  搴忓彿
+            vo.setPlcDesc("鏂矾鍣ㄦ晠闅�");
+            vo.setError("鏂矾鍣ㄦ晠闅�");
+            list.add(vo);
+        }
+        if (staProtocol.getInfraredErr()){
+            PlcErrorTableVo vo = new PlcErrorTableVo();
+            vo.setNo(entry.getKey());   //  搴忓彿
+            vo.setPlcDesc("鍏夌數寮傚父");
+            vo.setError("鍏夌數寮傚父");
+            list.add(vo);
+        }
+        if (staProtocol.getOutTimeErr()){
+            PlcErrorTableVo vo = new PlcErrorTableVo();
+            vo.setNo(entry.getKey());   //  搴忓彿
+
+            vo.setPlcDesc("杩愯瓒呮椂");
+            vo.setError("杩愯瓒呮椂");
+            list.add(vo);
+        }
+        if (staProtocol.getSeizeSeatErr()){
+            PlcErrorTableVo vo = new PlcErrorTableVo();
+            vo.setNo(entry.getKey());   //  搴忓彿
+
+            vo.setPlcDesc("鍗犱綅瓒呮椂");
+            vo.setError("鍗犱綅瓒呮椂");
+            list.add(vo);
+        }
+        if (staProtocol.getWrkYgoodsN()){
+            PlcErrorTableVo vo = new PlcErrorTableVo();
+            vo.setNo(entry.getKey());   //  搴忓彿
+
+            vo.setPlcDesc("鏈変换鍔℃棤璐ф晠闅�");
+            vo.setError("鏈変换鍔℃棤璐ф晠闅�");
+            list.add(vo);
+        }
+        if (staProtocol.getInverterErr()){
+            PlcErrorTableVo vo = new PlcErrorTableVo();
+            vo.setNo(entry.getKey());   //  搴忓彿
+
+            vo.setPlcDesc("鍙橀鍣ㄦ晠闅�");
+            vo.setError("鍙橀鍣ㄦ晠闅�");
+            list.add(vo);
+        }
+        if (staProtocol.getContactErr()){
+            PlcErrorTableVo vo = new PlcErrorTableVo();
+            vo.setNo(entry.getKey());   //  搴忓彿
+
+            vo.setPlcDesc("鐢垫満鎺ヨЕ鍣ㄦ晠闅�");
+            vo.setError("鐢垫満鎺ヨЕ鍣ㄦ晠闅�");
+            list.add(vo);
+        }
+        if (staProtocol.getUpcontactErr()){
+            PlcErrorTableVo vo = new PlcErrorTableVo();
+            vo.setNo(entry.getKey());   //  搴忓彿
+
+            vo.setPlcDesc("椤跺崌鐢垫満鎺ヨЕ鍣ㄦ晠闅�");
+            vo.setError("椤跺崌鐢垫満鎺ヨЕ鍣ㄦ晠闅�");
+            /*
+             * 瀹滅瀹氬埗  150绔欑偣寮傚父淇℃伅锛氬ぇ鎵樼洏鐩殑绔欓敊璇�
+             * */
+            if (entry.getKey()==150){
+                vo.setPlcDesc("150绔欑偣澶ф墭鐩樼洰鐨勭珯閿欒");
+                vo.setError("150绔欑偣澶ф墭鐩樼洰鐨勭珯閿欒");
+            }
+            list.add(vo);
+        }
+        if (staProtocol.isFrontErr()){
+            PlcErrorTableVo vo = new PlcErrorTableVo();
+            vo.setNo(entry.getKey());   //  搴忓彿
+            vo.setPlcDesc("鍓嶈秴闄�");
+            vo.setError("鍓嶈秴闄�");
+            list.add(vo);
+        }
+        if (staProtocol.isBackErr()){
+            PlcErrorTableVo vo = new PlcErrorTableVo();
+            vo.setNo(entry.getKey());   //  搴忓彿
+            vo.setPlcDesc("鍚庤秴闄�");
+            vo.setError("鍚庤秴闄�");
+            list.add(vo);
+        }
+        if (staProtocol.isHighErr()){
+            PlcErrorTableVo vo = new PlcErrorTableVo();
+            vo.setNo(entry.getKey());   //  搴忓彿
+            vo.setPlcDesc("楂樿秴闄�");
+            vo.setError("楂樿秴闄�");
+            list.add(vo);
+        }
+        if (staProtocol.isLeftErr()){
+            PlcErrorTableVo vo = new PlcErrorTableVo();
+            vo.setNo(entry.getKey());   //  搴忓彿
+            vo.setPlcDesc("宸﹁秴闄�");
+            vo.setError("宸﹁秴闄�");
+            list.add(vo);
+        }
+        if (staProtocol.isRightErr()){
+            PlcErrorTableVo vo = new PlcErrorTableVo();
+            vo.setNo(entry.getKey());   //  搴忓彿
+            vo.setPlcDesc("鍙宠秴闄�");
+            vo.setError("鍙宠秴闄�");
+            list.add(vo);
+        }
+        if (staProtocol.isBarcodeErr()){
+            PlcErrorTableVo vo = new PlcErrorTableVo();
+            vo.setNo(entry.getKey());   //  搴忓彿
+            vo.setPlcDesc("鎵爜澶辫触");
+            vo.setError("鎵爜澶辫触");
+            list.add(vo);
+        }
+
+
+        return list;
+    }
+
+
 }

--
Gitblit v1.9.1