From f29b6c12f50891382a310bc313cb11c6747959fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=B1=9F=E7=8E=AE?= Date: Wed, 28 Sep 2022 10:49:38 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=BD=E8=BF=AA=E5=B8=8C=E4=BA=9AECN-ACS?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/nl/acs/agv/server/dto/AgvDto.java | 1 + .../hand/andxy/rest/NdxyHandController.java | 26 ++++ .../hand/andxy/service/NdxyHandService.java | 18 +++ .../service/impl/NdxyHandServiceImpl.java | 129 ++++++++++++++++++ .../auto/run/NDCSocketConnectionAutoRun.java | 29 +++- 5 files changed, 201 insertions(+), 2 deletions(-) diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/dto/AgvDto.java b/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/dto/AgvDto.java index eb2eec1..396cab8 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/dto/AgvDto.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/dto/AgvDto.java @@ -159,4 +159,5 @@ public class AgvDto implements Serializable { */ private String w; + private String errorBuf; } diff --git a/hd/nladmin-system/src/main/java/org/nl/hand/andxy/rest/NdxyHandController.java b/hd/nladmin-system/src/main/java/org/nl/hand/andxy/rest/NdxyHandController.java index d6d2d1f..bd141e5 100644 --- a/hd/nladmin-system/src/main/java/org/nl/hand/andxy/rest/NdxyHandController.java +++ b/hd/nladmin-system/src/main/java/org/nl/hand/andxy/rest/NdxyHandController.java @@ -6,6 +6,8 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; import org.nl.annotation.Log; import org.nl.annotation.rest.AnonymousPostMapping; import org.nl.hand.andxy.service.NdxyHandService; @@ -153,4 +155,28 @@ public class NdxyHandController { return new ResponseEntity<>(HandService.createTask2(whereJson), HttpStatus.OK); } + /** + * 根据区域查询灭菌前后状态 + * + * @param param String region 1灭菌前 \ 2灭菌后 + * @return 设备状态数组 + */ + @PostMapping("/point2") + @Log("根据区域查询灭菌前后状态") + @ApiOperation("根据区域查询灭菌前后状态") + public ResponseEntity point2(@RequestBody Map param) { + return new ResponseEntity<>(HandService.point2(param), HttpStatus.OK); + } + + /** + * 查询AGV状态 + * + * @return AGV状态数组 + */ + @PostMapping("/queryagvStatus") + @Log("查询AGV状态") + @ApiOperation("查询AGV状态") + public ResponseEntity queryagvStatus() { + return new ResponseEntity<>(HandService.queryagvStatus(), HttpStatus.OK); + } } diff --git a/hd/nladmin-system/src/main/java/org/nl/hand/andxy/service/NdxyHandService.java b/hd/nladmin-system/src/main/java/org/nl/hand/andxy/service/NdxyHandService.java index 2113fed..a07f3bd 100644 --- a/hd/nladmin-system/src/main/java/org/nl/hand/andxy/service/NdxyHandService.java +++ b/hd/nladmin-system/src/main/java/org/nl/hand/andxy/service/NdxyHandService.java @@ -2,6 +2,9 @@ package org.nl.hand.andxy.service; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + import java.util.Map; /** @@ -112,4 +115,19 @@ public interface NdxyHandService { Map queryMaterial(); Map createTask2(Map whereJson); + + /** + * 根据区域查询灭菌前后状态 + * + * @param param String region 1灭菌前 \ 2灭菌后 + * @return 设备状态数组 + */ + JSONObject point2(Map param); + + /** + * 查询AGV状态 + * + * @return AGV状态数组 + */ + JSONObject queryagvStatus(); } diff --git a/hd/nladmin-system/src/main/java/org/nl/hand/andxy/service/impl/NdxyHandServiceImpl.java b/hd/nladmin-system/src/main/java/org/nl/hand/andxy/service/impl/NdxyHandServiceImpl.java index 92bc5ab..046a194 100644 --- a/hd/nladmin-system/src/main/java/org/nl/hand/andxy/service/impl/NdxyHandServiceImpl.java +++ b/hd/nladmin-system/src/main/java/org/nl/hand/andxy/service/impl/NdxyHandServiceImpl.java @@ -13,6 +13,7 @@ import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.apache.commons.lang3.ObjectUtils; import org.nl.acs.agv.server.AgvService; +import org.nl.acs.agv.server.dto.AgvDto; import org.nl.acs.agv.server.impl.AgvServiceImpl; import org.nl.acs.device.service.DeviceService; import org.nl.acs.device.service.dto.DeviceDto; @@ -60,6 +61,7 @@ public class NdxyHandServiceImpl implements NdxyHandService { private final PasswordEncoder passwordEncoder; private final DeviceService deviceService; private final DeviceAppService deviceAppService; + private final AgvService agvService; InstructionService instructionService = null; @@ -853,5 +855,132 @@ public class NdxyHandServiceImpl implements NdxyHandService { return jo; } + @Override + public JSONObject point2(Map param) { + // 返回值 + JSONObject resultJSON = new JSONObject(); + + // 参数校验 + String region = param.get("region"); + if (StrUtil.isEmpty(region)) { + resultJSON.put("code", "0"); + resultJSON.put("desc", "所属区域不能为空"); + return resultJSON; + } + + // 设备数组 + JSONArray acsDevice; + + // 根据区域不同处理 + switch (region) { + case "1": + // 查询灭菌前设备 + acsDevice = WQLObject + .getWQLObject("acs_device") + .query("device_code IN ('F5', 'F4', 'F3', 'F6', '1041')", "seq_num, device_name") + .getResultJSONArray(0); + break; + case "2": + // 查询灭菌后设备 + acsDevice = WQLObject + .getWQLObject("acs_device") + .query("device_code IN ('B5', 'B4', 'B3', 'B6', '1042')", "seq_num, device_name") + .getResultJSONArray(0); + break; + default: + resultJSON.put("code", "0"); + resultJSON.put("desc", "所属区域错误"); + return resultJSON; + } + + // 返回数组 + JSONArray result = new JSONArray(); + + // 遍历设备数组获取设备状态 + for (Object o : acsDevice) { + // 根据设备编码查询缓存的设备实例 + JSONObject device = (JSONObject) o; + String deviceCode = device.getString("device_code"); + Device deviceObj = deviceAppService.findDeviceByCode(deviceCode); + + // 设备状态对象,默认为红灯 + JSONObject deviceStatus = new JSONObject(); + deviceStatus.put("device_id", device.getString("device_id")); + deviceStatus.put("device_code", deviceCode); + deviceStatus.put("device_name", device.getString("device_name")); + deviceStatus.put("status", "2"); + deviceStatus.put("seq_num", device.getString("seq_num")); + + if (ObjectUtil.isNotEmpty(deviceObj)) { + // 获取驱动 + NdxySpecialDeviceDriver driver = (NdxySpecialDeviceDriver) deviceObj.getDeviceDriver(); + + // 只有在设备为空且无故障无选择的情况下才是绿灯 + int hasGoods = driver.getHasGoods();// 是否有货 + int error = driver.getError();// 是否故障 + int actoin = driver.getActoin();// 是否允许取放 + if (hasGoods == 0 && error == 0 && actoin == 1) { + deviceStatus.put("status", "1"); + } + } + + // 添加进返回数组 + result.add(deviceStatus); + } + + // 返回 + resultJSON.put("code", "1"); + resultJSON.put("desc", "查询成功"); + resultJSON.put("result", result); + return resultJSON; + } + @Override + public JSONObject queryagvStatus() { + // 获取所有AGV对象 + Map agvMap = agvService.findAllAgvFromCache(); + + // 返回数组 + JSONArray result = new JSONArray(); + + // 遍历所有agv + for (AgvDto agv : agvMap.values()) { + // 状态对象 + JSONObject agvStatus = new JSONObject(); + agvStatus.put("car_no", agv.getName()); + String state = agv.getState(); + String status; + switch (state) { + case "UNAVAILABLE": + status = "通信超时或者已断开连接"; + break; + case "ERROR": + status = "错误状态"; + agvStatus.put("error", agv.getErrorBuf()); + break; + case "IDLE": + status = "空闲状态"; + break; + case "EXECUTING": + status = "正在执行运单"; + break; + case "CHARGING": + status = "正在充电"; + break; + default: + status = "未知状态"; + } + agvStatus.put("status", status); + agvStatus.put("electricity", agv.getEnergyLevel()); + + // 添加进返回数组 + result.add(agvStatus); + } + + JSONObject resultJSON = new JSONObject(); + resultJSON.put("code", "1"); + resultJSON.put("desc", "查询成功"); + resultJSON.put("result", result); + return resultJSON; + } } diff --git a/hd/nladmin-system/src/main/java/org/nl/start/auto/run/NDCSocketConnectionAutoRun.java b/hd/nladmin-system/src/main/java/org/nl/start/auto/run/NDCSocketConnectionAutoRun.java index ed6343f..b57960c 100644 --- a/hd/nladmin-system/src/main/java/org/nl/start/auto/run/NDCSocketConnectionAutoRun.java +++ b/hd/nladmin-system/src/main/java/org/nl/start/auto/run/NDCSocketConnectionAutoRun.java @@ -2465,11 +2465,35 @@ public class NDCSocketConnectionAutoRun extends AbstractAutoRunnable { } //上报异常 else if (phase == 0x67) { - if (arr[18] * 256 + arr[19] == 0) { + AgvDto dto = null; + Map map = AgvService.findAllAgvFromCache(); +// carno = arr[18] * 256 + arr[19]; + if (map.containsKey(String.valueOf(carno))) { + dto = map.get(String.valueOf(carno)); } else { - + dto = new AgvDto(); } + dto.setName(String.valueOf(carno)); + if (agvaddr == 0) { + dto.setState("IDLE"); + } else { + StringBuffer errbs = new StringBuffer(); + for (int i = 0; i < ERROR.length; i++) { + if (((agvaddr) & (1 << i)) > 0) + errbs.append("," + ERROR[i]); + //反馈故障 + } + String errorStr = errbs.toString(); + // 去除字符串头部逗号 + if (errorStr.length() > 0) { + errorStr = errorStr.substring(1); + } + dto.setState("ERROR"); + dto.setErrorBuf(errorStr); + AgvService.updateAgvFromCache(dto); + } + } else { @@ -3583,6 +3607,7 @@ public class NDCSocketConnectionAutoRun extends AbstractAutoRunnable { //反馈故障 } dto.setState("ERROR"); + dto.setErrorBuf(errbs.toString()); acsToWmsService.feedbackAgvStatus(String.valueOf(carno), String.valueOf(ikey), "error"); } }