From 6f569a1e2deb06e5e8c43ceb07094ddf58c96938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=B1=9F=E7=8E=AE?= Date: Sun, 17 Sep 2023 16:55:34 +0800 Subject: [PATCH] rev --- .../org/nl/acs/agv/rest/XGAGVController.java | 2 - .../org/nl/acs/agv/server/AgvWaitUtil.java | 25 +++--- .../acs/agv/server/impl/AgvServiceImpl.java | 80 +++++++++---------- .../acs/ext/wms/service/AcsToWmsService.java | 11 ++- .../wms/service/impl/AcsToWmsServiceImpl.java | 24 +++--- 5 files changed, 66 insertions(+), 76 deletions(-) diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/XGAGVController.java b/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/XGAGVController.java index 936c878..c5b1ec1 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/XGAGVController.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/XGAGVController.java @@ -11,14 +11,12 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * @author zhangjiangwei */ @RestController -@RequestMapping("/api/agv/xg") @RequiredArgsConstructor @Api(tags = "仙工AGV") @Slf4j diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvWaitUtil.java b/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvWaitUtil.java index 81f911b..d5a1275 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvWaitUtil.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvWaitUtil.java @@ -8,6 +8,7 @@ import net.sf.json.JSONObject; import org.nl.acs.ext.wms.service.AcsToWmsService; import org.nl.acs.ext.wms.service.impl.AcsToWmsZDServiceImpl; import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; import org.nl.acs.log.service.LogServer; import org.nl.acs.opc.DeviceAppService; import org.nl.exception.BadRequestException; @@ -30,12 +31,10 @@ public class AgvWaitUtil { LogServer logServer; //取货前等待 - public JSONObject waitInGet(String startDeviceCode) { + public JSONObject waitInGet(String startDeviceCode, Instruction inst) { log.info("仙工AGV请求取货,设备号 - {}", startDeviceCode); - JSONObject requestWMSParam = new JSONObject(); - requestWMSParam.put("StartStationCode", startDeviceCode); - JSONObject responseBody = acsToWmsService.gccQueryStationState(requestWMSParam); + JSONObject responseBody = acsToWmsService.gccQueryStationState(inst); if (ObjectUtil.isNotEmpty(responseBody) && 200 == responseBody.optInt("status")) { JSONArray data = responseBody.optJSONArray("data"); @@ -56,12 +55,10 @@ public class AgvWaitUtil { } //取货完成等待 - public JSONObject waitOutGet(String startDeviceCode) { + public JSONObject waitOutGet(String startDeviceCode, Instruction inst) { log.info("仙工AGV取货完成后请求离开,设备号 - {}", startDeviceCode); - JSONObject requestWMSParam = new JSONObject(); - requestWMSParam.put("StartStationCode", startDeviceCode); - JSONObject responseBody = acsToWmsService.gccQueryStationState(requestWMSParam); + JSONObject responseBody = acsToWmsService.gccQueryStationState(inst); if (ObjectUtil.isNotEmpty(responseBody) && 200 == responseBody.optInt("status")) { JSONArray data = responseBody.optJSONArray("data"); @@ -82,12 +79,10 @@ public class AgvWaitUtil { } //放货前等待 - public JSONObject waitInPut(String endDeviceCode) { + public JSONObject waitInPut(String endDeviceCode, Instruction inst) { log.info("仙工AGV请求放货,设备号 - {}", endDeviceCode); - JSONObject requestWMSParam = new JSONObject(); - requestWMSParam.put("EndStationCode", endDeviceCode); - JSONObject responseBody = acsToWmsService.gccQueryStationState(requestWMSParam); + JSONObject responseBody = acsToWmsService.gccQueryStationState(inst); if (ObjectUtil.isNotEmpty(responseBody) && 200 == responseBody.optInt("status")) { JSONArray data = responseBody.optJSONArray("data"); @@ -109,12 +104,10 @@ public class AgvWaitUtil { //放货完成等待 - public JSONObject waitOutPut(String endDeviceCode) { + public JSONObject waitOutPut(String endDeviceCode, Instruction inst) { log.info("仙工AGV放货完成后请求离开,设备号 - {}", endDeviceCode); - JSONObject requestWMSParam = new JSONObject(); - requestWMSParam.put("EndStationCode", endDeviceCode); - JSONObject responseBody = acsToWmsService.gccQueryStationState(requestWMSParam); + JSONObject responseBody = acsToWmsService.gccQueryStationState(inst); if (ObjectUtil.isNotEmpty(responseBody) && 200 == responseBody.optInt("status")) { JSONArray data = responseBody.optJSONArray("data"); diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java b/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java index 6fc20c1..16cf76e 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java @@ -2020,9 +2020,15 @@ public class AgvServiceImpl implements AgvService { @Override public JSONObject xgAGVControlDoorSwitch(JSONObject requestParam) { + log.info("仙工AGV控制门开关,请求参数 - {}", requestParam); try { + String doorName = requestParam.optString("doorName"); + if (doorName.startsWith("D")) { + doorName = doorName.substring(1); + } + JSONObject requestWMSParam = new JSONObject(); - requestWMSParam.put("device_code", requestParam.optString("doorName")); + requestWMSParam.put("device_code", doorName); requestWMSParam.put("device_status", "1".equals(requestParam.optString("state")) ? "open" : "close"); JSONObject wmsResult = acsToWmsService.gccControlDoorSwitch(requestWMSParam); @@ -2034,8 +2040,10 @@ public class AgvServiceImpl implements AgvService { result.put("result", -1); result.put("message", wmsResult.optString("message")); } + log.info("仙工AGV控制门开关,响应参数 - {}", result); return result; } catch (Exception e) { + log.error("仙工AGV控制门开关错误!", e); JSONObject result = new JSONObject(); result.put("result", -1); result.put("message", e.getMessage()); @@ -2045,6 +2053,7 @@ public class AgvServiceImpl implements AgvService { @Override public JSONObject xgAGVQueryDoorStatus(JSONObject requestParam) { + log.info("仙工AGV查询门状态,请求参数 - {}", requestParam); String[] doorNameList = requestParam.optJSONArray("doorNameList").optString(0).split(","); if (doorNameList.length == 1 && StrUtil.isBlank(doorNameList[0])) { @@ -2055,49 +2064,36 @@ public class AgvServiceImpl implements AgvService { } try { - com.alibaba.fastjson.JSONArray wmsResult = acsToWmsService.gccQueryDoorStatus(); - - if (ObjectUtil.isEmpty(wmsResult)) { - JSONObject result = new JSONObject(); - result.put("result", 0); - result.put("message", "操作成功"); - result.put("data", Arrays.stream(doorNameList) - .map(doorName -> { - JSONObject door = new JSONObject(); - door.put("doorName", doorName); - door.put("state", -1); - door.put("timestamp", System.currentTimeMillis()); - return door; - }).collect(Collectors.toList())); - return result; - } - - List data = Arrays.stream(doorNameList).map(doorName -> { - JSONObject door = new JSONObject(); - door.put("doorName", doorName); - List list = wmsResult.stream().filter(o -> doorName.equals(((com.alibaba.fastjson.JSONObject) o).getString("device_code"))).collect(Collectors.toList()); - if (list.isEmpty()) { - door.put("state", -1); - } else { - com.alibaba.fastjson.JSONObject row = (com.alibaba.fastjson.JSONObject) list.get(0); - int state = 1; - if ("close".equals(row.getString("device_status"))) { - state = 0; - } else if ("open".equals(row.getString("device_status"))) { - state = 2; - } - door.put("state", state); - } - door.put("timestamp", System.currentTimeMillis()); - return door; - }).collect(Collectors.toList()); - JSONObject result = new JSONObject(); result.put("result", 0); result.put("message", "操作成功"); + + JSONArray data = new JSONArray(); + JSONObject datum = new JSONObject(); + for (String doorName : doorNameList) { + String requestWMSDeviceCode = doorName; + if (doorName.startsWith("D")) { + requestWMSDeviceCode = doorName.substring(1); + } + + JSONObject responseBody = acsToWmsService.gccQueryDoorStatus(requestWMSDeviceCode); + datum.put("doorName", doorName); + String deviceStatus = responseBody.optString("device_status"); + if ("open".equals(deviceStatus)) { + datum.put("state", 2); + } else if ("close".equals(deviceStatus)) { + datum.put("state", 0); + } else { + datum.put("state", -1); + } + data.add(datum); + } result.put("data", data); + + log.info("仙工AGV查询门状态,响应参数 - {}", result); return result; } catch (Exception e) { + log.error("仙工AGV查询们状态错误!", e); JSONObject result = new JSONObject(); result.put("result", 0); result.put("message", e.getMessage()); @@ -2230,9 +2226,9 @@ public class AgvServiceImpl implements AgvService { } if (address.contains("GET")) { - return agvWaitUtil.waitInGet(deviceCodeNow); + return agvWaitUtil.waitInGet(deviceCodeNow, instructionDto); } else if (address.contains("PUT")) { - return agvWaitUtil.waitInPut(deviceCodeNow); + return agvWaitUtil.waitInPut(deviceCodeNow, instructionDto); } } if (address.contains("OUT")) { @@ -2242,9 +2238,9 @@ public class AgvServiceImpl implements AgvService { } if (address.contains("GET")) { - return agvWaitUtil.waitOutGet(deviceCodeNow); + return agvWaitUtil.waitOutGet(deviceCodeNow, instructionDto); } else if (address.contains("PUT")) { - return agvWaitUtil.waitOutPut(deviceCodeNow); + return agvWaitUtil.waitOutPut(deviceCodeNow, instructionDto); } } diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java index 44f9217..c9e5e05 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java @@ -3,6 +3,7 @@ package org.nl.acs.ext.wms.service; import cn.hutool.http.HttpResponse; import net.sf.json.JSONArray; import net.sf.json.JSONObject; +import org.nl.acs.instruction.service.dto.Instruction; import java.util.Map; @@ -127,6 +128,7 @@ public interface AcsToWmsService { /** * 六维广钞厂查询自动门状态 * + * @param deviceCode 自动门编码(不带首字母D) * @return 示例:[ * { * "device_code":"AD1", @@ -138,14 +140,11 @@ public interface AcsToWmsService { * } * ] */ - com.alibaba.fastjson.JSONArray gccQueryDoorStatus(); + JSONObject gccQueryDoorStatus(String deviceCode); /** * 六维广钞厂查询站点有无货状态 - * @param requestWMSParam 示例:{ - * "StartStationCode":"111", - * "EndStationCode":"222" - * } + * @param inst 指令对象 * @return 示例:{ * "errArr":null, * "data":[{"Station_Code":"1170","IsHasGoods":true},{"Station_Code":"1030","IsHasGoods":true}], @@ -153,5 +152,5 @@ public interface AcsToWmsService { * "message":"获取站点相关信息成功" * } */ - JSONObject gccQueryStationState(JSONObject requestWMSParam); + JSONObject gccQueryStationState(Instruction inst); } diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java index 041dbee..3a74fe4 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java @@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; +import cn.hutool.http.HttpUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import net.sf.json.JSONArray; @@ -14,6 +15,7 @@ import org.nl.acs.device.address.service.AddressService; import org.nl.acs.device.address.service.dto.AddressDto; import org.nl.acs.device.service.DeviceService; import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.instruction.service.dto.Instruction; import org.nl.acs.log.service.LogServer; import org.nl.acs.task.service.TaskService; import org.nl.acs.task.service.dto.TaskDto; @@ -25,6 +27,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; +import java.util.HashMap; import java.util.Map; @Service @@ -542,34 +545,35 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { } @Override - public com.alibaba.fastjson.JSONArray gccQueryDoorStatus() { + public JSONObject gccQueryDoorStatus(String deviceCode) { try { String wmsurl = acsConfigService.findConfigFromCache().get(AcsConfig.WMSURL); AddressDto addressDto = addressService.findByCode("gccQueryDoorStatus"); + String uri = wmsurl + addressDto.getMethods_url() + "?deviceCode=" + deviceCode; - log.info("gccQueryDoorStatus - 请求"); + log.info("gccQueryDoorStatus - 请求路径{}", uri); String responseBody = HttpRequest - .get(wmsurl + addressDto.getMethods_url()) + .get(uri) .execute() .body(); - log.info("gccControlDoorSwitch - 响应参数{}", responseBody); + log.info("gccQueryDoorStatus - 响应参数{}", responseBody); - return com.alibaba.fastjson.JSONArray.parseArray(responseBody); + return JSONObject.fromObject(responseBody); } catch (Exception e) { - return new com.alibaba.fastjson.JSONArray(); + return new JSONObject(); } } @Override - public JSONObject gccQueryStationState(JSONObject requestWMSParam) { + public JSONObject gccQueryStationState(Instruction inst) { try { String wmsurl = acsConfigService.findConfigFromCache().get(AcsConfig.WMSURL); AddressDto addressDto = addressService.findByCode("gccQueryStationState"); + String uri = wmsurl + addressDto.getMethods_url() + "?StartStationCode=" + inst.getStart_point_code() + "&EndStationCode=" + inst.getNext_point_code(); - log.info("gccQueryStationState - 请求参数{}", requestWMSParam); + log.info("gccQueryStationState - 请求路径{}", uri); String responseBody = HttpRequest - .post(wmsurl + addressDto.getMethods_url()) - .body(requestWMSParam.toString()) + .get(uri) .execute() .body(); log.info("gccQueryStationState - 响应参数{}", responseBody);