From 5b5bf0d3fb08926b700b9d9ef127eb86d3241725 Mon Sep 17 00:00:00 2001
From: TQS <56479841@qq.com>
Date: 星期三, 16 四月 2025 15:09:12 +0800
Subject: [PATCH] 添加小车定位失败日志打印
---
src/main/java/com/zy/asrs/controller/SiteController.java | 220 ++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 187 insertions(+), 33 deletions(-)
diff --git a/src/main/java/com/zy/asrs/controller/SiteController.java b/src/main/java/com/zy/asrs/controller/SiteController.java
index 5679e8f..043cfcc 100644
--- a/src/main/java/com/zy/asrs/controller/SiteController.java
+++ b/src/main/java/com/zy/asrs/controller/SiteController.java
@@ -1,52 +1,125 @@
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.R;
import com.zy.asrs.domain.vo.PlcErrorTableVo;
import com.zy.asrs.domain.vo.SiteTableVo;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import com.zy.asrs.entity.BasDevp;
+import com.zy.asrs.service.BasDevpService;
+import com.zy.common.utils.News;
+import com.zy.core.DevpThread;
+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.enums.SteTaskModeType;
+import com.zy.core.model.DevpSlave;
+import com.zy.core.model.Task;
+import com.zy.core.model.command.SteCommand;
+import com.zy.core.model.protocol.StaProtocol;
+import com.zy.core.properties.SlaveProperties;
+import com.zy.core.thread.SiemensDevpThread;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
-import java.util.Date;
+import java.util.HashMap;
import java.util.List;
-import java.util.Random;
-import java.util.concurrent.atomic.AtomicInteger;
+import java.util.Map;
/**
* 杈撻�佽澶囨帴鍙�
* Created by vincent on 2020-06-01
*/
+@Slf4j
@RestController
@RequestMapping("/site")
public class SiteController {
- private AtomicInteger integer = new AtomicInteger();
+ @Autowired
+ private SlaveProperties slaveProperties;
+ @Autowired
+ private BasDevpService basDevpService;
+
+ @GetMapping("/io/mode/info/site")
+ @ManagerAuth(memo = "鍏呯數妯″紡")
+ public R ioMode(){
+ List<Map<String, Object>> res = new ArrayList<>();
+ for (DevpSlave devp : slaveProperties.getDevp()) {
+ if (devp.getId()!=1) continue;
+ SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
+ Map<String, Object> map1 = new HashMap<>();
+ map1.put("floor", 1);
+ map1.put("modeVal", devpThread.charge0);
+ map1.put("modeDesc", devpThread.charge0?"鍏呯數涓�":"鍏抽棴");
+ res.add(map1);
+ Map<String, Object> map2 = new HashMap<>();
+ map2.put("floor", 2);
+ map2.put("modeVal", devpThread.charge1);
+ map2.put("modeDesc", devpThread.charge1?"鍏呯數涓�":"鍏抽棴");
+ res.add(map2);
+ Map<String, Object> map3 = new HashMap<>();
+ map3.put("floor", 3);
+ map3.put("modeVal", devpThread.charge2);
+ map3.put("modeDesc", devpThread.charge2?"鍏呯數涓�":"鍏抽棴");
+ res.add(map3);
+ }
+ return R.ok().add(res);
+ }
+
+ @PostMapping("/io/mode/action/site")
+ @ManagerAuth(memo = "鍏呯數鎺у埗")
+ public R ioModeAction(@RequestParam("floor") Integer floor, @RequestParam("charge") Boolean charge){
+ for (DevpSlave devp : slaveProperties.getDevp()) {
+ // 杈撻�佺嚎鍏呯數鍛戒护涓嬪彂鍖� --------------------------------------------------------------------------
+ SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
+ boolean res = devpThread.charge(floor - 1, charge);
+ if (!charge && res) {
+ // 绌挎杞﹀厖鐢靛懡浠や笅鍙戝尯 --------------------------------------------------------------------------
+ int steNo = floor;
+ SteCommand steCommand = new SteCommand();
+ steCommand.setSteNo(steNo); // 绌挎杞︾紪鍙�
+ steCommand.setTaskNo(9999); // 宸ヤ綔鍙�
+ steCommand.setTaskMode(SteTaskModeType.CLOSE_CHARGE);
+ if (!MessageQueue.offer(SlaveType.Ste, steNo, new Task(2, steCommand))) {
+ News.error("绌挎杞﹀懡浠や笅鍙戝け璐ワ紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", steNo, JSON.toJSON(steCommand));
+ }
+ }
+ return res?R.ok():R.error();
+ }
+ return R.ok();
+ }
@PostMapping("/table/site")
@ManagerAuth(memo = "绔欑偣淇℃伅琛�")
public R siteTable(){
List<SiteTableVo> list = new ArrayList<>();
- for (int i=0;i<32;i++){
- SiteTableVo vo = new SiteTableVo();
- vo.setDevNo(String.valueOf(i));
- vo.setWorkNo("1204");
- vo.setAutoing("Y");
- vo.setCanining("Y");
- vo.setCanouting("N");
- vo.setHighLow("1");
- vo.setInreqIn("Y");
- vo.setInreqOut("N");
- vo.setLoading("Y");
- if (integer.get()%5 == 0) {
- vo.setStaNo("0000");
- } else {
- vo.setStaNo("9998");
- }
- list.add(vo);
+ // 鍐呭瓨鏁版嵁
+ Map<Integer, StaProtocol> station = new HashMap<>();
+ for (DevpSlave devp : slaveProperties.getDevp()) {
+ DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
+ station.putAll(devpThread.getStation());
}
- integer.getAndIncrement();
+ // 鎸佷箙鏁版嵁
+ 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.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"); // 鍏ュ簱鏍囪
+ vo.setEmptyMk(staProtocol.isEmptyMk()?"Y":"N"); // 绌烘澘淇″彿
+ vo.setStaNo(staProtocol.getStaNo()); // 鐩爣绔�
+ }
return R.ok().add(list);
}
@@ -54,13 +127,24 @@
@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);
+ 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();
+// if (staProtocol) {
+// PlcErrorTableVo vo = new PlcErrorTableVo();
+// vo.setNo(entry.getKey()); // 搴忓彿
+//
+// vo.setPlcDesc(""); // todo:luxiaotao plc閿欒鎻忚堪
+// vo.setError(""); // todo:luxiaotao 寮傚父淇℃伅
+// list.add(vo);
+// }
+ }
+
}
+
list.sort((o1, o2) -> {
if (o1.getNo().compareTo(o2.getNo()) > 0){
return 1;
@@ -77,8 +161,78 @@
@PostMapping("/output/site")
@ManagerAuth(memo = "绔欑偣璁惧鎶ユ枃鏃ュ織杈撳嚭")
public R siteOutput(){
- String str = "\n" +new Date().toLocaleString() + "銆�2020-5-29 13:14:22銆戞壂鎻弍lcA 鐩爣绔�--27328372372832763643234323432342";
- return R.ok().add(str);
+ StringBuilder str = new StringBuilder();
+ String s;
+ int i = 0;
+ while((s = OutputQueue.DEVP.poll()) != null && i <=10) {
+ str.append("\n").append(s);
+ i++;
+ }
+ 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()); // 鐩爣绔�
+ return R.ok().add(vo);
+ }
+ }
+ }
+ return R.error("plc宸叉帀绾�");
+ }
+
+ @PostMapping("/detl/update")
+ @ManagerAuth(memo = "淇敼绔欑偣鏁版嵁")
+ public R siteDetlUpdate(@RequestParam Integer siteId,
+ @RequestParam Short 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();
+ 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宸叉帀绾�");
+ }
+
+
}
--
Gitblit v1.9.1