From fff70e3796fb2287a3b0a5083498bf25f0d9280c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=B1=9F=E7=8E=AE?= Date: Wed, 13 Sep 2023 14:11:37 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E4=BB=99=E5=B7=A5AGV=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E5=8F=96=E6=94=BE=E8=B4=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/nl/acs/agv/rest/AgvController.java | 14 - .../org/nl/acs/agv/rest/XGAGVController.java | 49 +++ .../org/nl/acs/agv/server/AgvService.java | 4 +- .../org/nl/acs/agv/server/AgvWaitUtil.java | 136 ++++++++ .../acs/agv/server/impl/AgvServiceImpl.java | 296 ++++++++++++------ .../acs/ext/wms/service/AcsToWmsService.java | 15 + .../wms/service/impl/AcsToWmsServiceImpl.java | 23 ++ .../service/InstructionService.java | 1 + .../service/impl/InstructionServiceImpl.java | 11 + .../task/service/impl/TaskServiceImpl.java | 24 +- .../org/nl/acs/test/rest/TestController.java | 11 +- .../org/nl/acs/test/service/TestService.java | 4 +- .../test/service/impl/TestServiceImpl.java | 48 +-- .../quartz/task/QueryXZAgvTaskStatus.java | 114 ++++--- .../main/resources/config/application-dev.yml | 5 +- .../resources/config/application-prod.yml | 3 + qd/.env.production | 4 +- 17 files changed, 561 insertions(+), 201 deletions(-) create mode 100644 hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/XGAGVController.java create mode 100644 hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvWaitUtil.java diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/AgvController.java b/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/AgvController.java index f96af5f..19f0b9a 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/AgvController.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/AgvController.java @@ -96,18 +96,4 @@ public class AgvController { public ResponseEntity queryDevice() throws Exception { return new ResponseEntity<>(agvService.queryDeviceStation(), HttpStatus.OK); } - - @PostMapping("/xgAGVControlDoorSwitch") - @Log("仙工AGV控制门开关") - @ApiOperation("仙工AGV控制门开关") - public ResponseEntity xgAGVControlDoorSwitch(@RequestBody JSONObject requestParam) { - return new ResponseEntity<>(agvService.xgAGVControlDoorSwitch(requestParam), HttpStatus.OK); - } - - @PostMapping("/xgAGVQueryDoorStatus") - @Log("仙工AGV查询门状态") - @ApiOperation("仙工AGV查询门状态") - public ResponseEntity xgAGVQueryDoorStatus(@RequestBody JSONObject requestParam) { - return new ResponseEntity<>(agvService.xgAGVQueryDoorStatus(requestParam), HttpStatus.OK); - } } 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 new file mode 100644 index 0000000..936c878 --- /dev/null +++ b/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/XGAGVController.java @@ -0,0 +1,49 @@ +package org.nl.acs.agv.rest; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import net.sf.json.JSONObject; +import org.nl.acs.agv.server.AgvService; +import org.nl.annotation.Log; +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 +public class XGAGVController { + + private final AgvService agvService; + + @PostMapping("/controlDoor") + @Log("仙工AGV控制门开关") + @ApiOperation("仙工AGV控制门开关") + public ResponseEntity xgAGVControlDoorSwitch(@RequestBody JSONObject requestParam) { + return new ResponseEntity<>(agvService.xgAGVControlDoorSwitch(requestParam), HttpStatus.OK); + } + + @PostMapping("/doorStateList") + @Log("仙工AGV查询门状态") + @ApiOperation("仙工AGV查询门状态") + public ResponseEntity xgAGVQueryDoorStatus(@RequestBody JSONObject requestParam) { + return new ResponseEntity<>(agvService.xgAGVQueryDoorStatus(requestParam), HttpStatus.OK); + } + + @PostMapping("/waitPointRequest") + @Log("仙工AGV请求取放货") + @ApiOperation("仙工AGV请求取放货") + public ResponseEntity xgAGVWaitPointRequest(@RequestBody JSONObject requestParam) { + return new ResponseEntity<>(agvService.xgAGVWaitPointRequest(requestParam), HttpStatus.OK); + } +} diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvService.java b/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvService.java index 234f960..5208bec 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvService.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvService.java @@ -33,7 +33,7 @@ public interface AgvService { public HttpResponse queryXZAgvDeviceStatus(); - public HttpResponse queryXZAgvInstStatus(String instCode); + public HttpResponse queryXZAgvInstStatus(); Map findAllAgvFromCache(); @@ -216,4 +216,6 @@ public interface AgvService { * } */ JSONObject xgAGVQueryDoorStatus(JSONObject requestParam); + + JSONObject xgAGVWaitPointRequest(JSONObject requestParam); } 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 new file mode 100644 index 0000000..81f911b --- /dev/null +++ b/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvWaitUtil.java @@ -0,0 +1,136 @@ +package org.nl.acs.agv.server; + +import cn.hutool.core.util.ObjectUtil; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import net.sf.json.JSONArray; +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.log.service.LogServer; +import org.nl.acs.opc.DeviceAppService; +import org.nl.exception.BadRequestException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * @author: geng by + * @createDate: 2022/12/5 + */ +@Service +@RequiredArgsConstructor +@Slf4j +public class AgvWaitUtil { + private final DeviceAppService deviceAppService; + private final AcsToWmsZDServiceImpl acsToWmsZDService; + private final InstructionService instructionService; + private final AcsToWmsService acsToWmsService; + @Autowired + LogServer logServer; + + //取货前等待 + public JSONObject waitInGet(String startDeviceCode) { + log.info("仙工AGV请求取货,设备号 - {}", startDeviceCode); + + JSONObject requestWMSParam = new JSONObject(); + requestWMSParam.put("StartStationCode", startDeviceCode); + JSONObject responseBody = acsToWmsService.gccQueryStationState(requestWMSParam); + + if (ObjectUtil.isNotEmpty(responseBody) && 200 == responseBody.optInt("status")) { + JSONArray data = responseBody.optJSONArray("data"); + for (int i = 0; i < data.size(); i++) { + JSONObject datum = data.getJSONObject(i); + if (startDeviceCode.equals(datum.optString("Station_Code")) + && datum.optBoolean("IsHasGoods")) { + JSONObject map = new JSONObject(); + map.put("status", 200); + map.put("message", "允许取货!"); + log.info("允许仙工AGV取货,设备号 - {}", startDeviceCode); + return map; + } + } + } + + throw new BadRequestException("请求失败!"); + } + + //取货完成等待 + public JSONObject waitOutGet(String startDeviceCode) { + log.info("仙工AGV取货完成后请求离开,设备号 - {}", startDeviceCode); + + JSONObject requestWMSParam = new JSONObject(); + requestWMSParam.put("StartStationCode", startDeviceCode); + JSONObject responseBody = acsToWmsService.gccQueryStationState(requestWMSParam); + + if (ObjectUtil.isNotEmpty(responseBody) && 200 == responseBody.optInt("status")) { + JSONArray data = responseBody.optJSONArray("data"); + for (int i = 0; i < data.size(); i++) { + JSONObject datum = data.getJSONObject(i); + if (startDeviceCode.equals(datum.optString("Station_Code")) + && !datum.optBoolean("IsHasGoods", true)) { + JSONObject map = new JSONObject(); + map.put("status", 200); + map.put("message", "允许离开!"); + log.info("允许仙工AGV取货完成后请求离开,设备号 - {}", startDeviceCode); + return map; + } + } + } + + throw new BadRequestException("请求失败!"); + } + + //放货前等待 + public JSONObject waitInPut(String endDeviceCode) { + log.info("仙工AGV请求放货,设备号 - {}", endDeviceCode); + + JSONObject requestWMSParam = new JSONObject(); + requestWMSParam.put("EndStationCode", endDeviceCode); + JSONObject responseBody = acsToWmsService.gccQueryStationState(requestWMSParam); + + if (ObjectUtil.isNotEmpty(responseBody) && 200 == responseBody.optInt("status")) { + JSONArray data = responseBody.optJSONArray("data"); + for (int i = 0; i < data.size(); i++) { + JSONObject datum = data.getJSONObject(i); + if (endDeviceCode.equals(datum.optString("Station_Code")) + && !datum.optBoolean("IsHasGoods", true)) { + JSONObject map = new JSONObject(); + map.put("status", 200); + map.put("message", "允许放货!"); + log.info("允许仙工AGV放货,设备号 - {}", endDeviceCode); + return map; + } + } + } + + throw new BadRequestException("请求失败!"); + } + + + //放货完成等待 + public JSONObject waitOutPut(String endDeviceCode) { + log.info("仙工AGV放货完成后请求离开,设备号 - {}", endDeviceCode); + + JSONObject requestWMSParam = new JSONObject(); + requestWMSParam.put("EndStationCode", endDeviceCode); + JSONObject responseBody = acsToWmsService.gccQueryStationState(requestWMSParam); + + if (ObjectUtil.isNotEmpty(responseBody) && 200 == responseBody.optInt("status")) { + JSONArray data = responseBody.optJSONArray("data"); + for (int i = 0; i < data.size(); i++) { + JSONObject datum = data.getJSONObject(i); + if (endDeviceCode.equals(datum.optString("Station_Code")) + && datum.optBoolean("IsHasGoods")) { + JSONObject map = new JSONObject(); + map.put("status", 200); + map.put("message", "允许离开!"); + log.info("允许仙工AGV放货完成后请求离开,设备号 - {}", endDeviceCode); + return map; + } + } + } + + throw new BadRequestException("请求失败!"); + } +} 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 1694f16..6fc20c1 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 @@ -1,5 +1,6 @@ package org.nl.acs.agv.server.impl; +import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpRequest; @@ -9,6 +10,7 @@ import lombok.extern.slf4j.Slf4j; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.nl.acs.agv.server.AgvService; +import org.nl.acs.agv.server.AgvWaitUtil; import org.nl.acs.agv.server.dto.AgvDto; import org.nl.acs.config.AcsConfig; import org.nl.acs.config.server.AcsConfigService; @@ -44,6 +46,7 @@ import org.nl.logger.BusinessLogger; import org.nl.start.auto.run.NDCSocketConnectionAutoRun; import org.nl.utils.SpringContextHolder; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; @@ -78,6 +81,12 @@ public class AgvServiceImpl implements AgvService { private final LogServer logServer; + @Autowired + AgvWaitUtil agvWaitUtil; + + @Value("${agvToAcs.addr}") + private String addr; + Map AGVDeviceStatus = new HashMap(); /** @@ -589,10 +598,12 @@ public class AgvServiceImpl implements AgvService { @Override public HttpResponse queryXZAgvDeviceStatus() { + if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.FORKAGV).toString(), "1")) { String agvurl = acsConfigService.findConfigFromCache().get(AcsConfig.AGVURL); String agvport = acsConfigService.findConfigFromCache().get(AcsConfig.AGVPORT); + String agvurl1 = agvurl + ":" + agvport + "/api/route/vehicles"; String agvurl2 = agvurl + ":" + agvport + "/api/route/vehicleDetails"; @@ -604,44 +615,22 @@ public class AgvServiceImpl implements AgvService { HttpResponse result2 = HttpRequest.get(agvurl2) .timeout(20000)//超时,毫秒 .execute(); - log.info("查询agv状态数据 vehicles:" + result.body()); - log.info("查询agv状态数据 vehicleDetails:" + result2.body()); + System.out.println("查询agv状态数据:" + result.body()); if (result.getStatus() == 200) { - JSONArray ja = JSONArray.fromObject(result.body()); + com.alibaba.fastjson.JSONArray ja = (com.alibaba.fastjson.JSONArray) com.alibaba.fastjson.JSONArray.parse(result.body()); + for (int i = 0; i < ja.size(); i++) { - JSONObject jo = (JSONObject) ja.get(i); + com.alibaba.fastjson.JSONObject jo = (com.alibaba.fastjson.JSONObject) ja.get(i); String name = jo.getString("name"); String state = jo.getString("state"); String energyLevel = jo.getString("energyLevel"); String transportOrder = jo.getString("transportOrder"); - JSONObject detailjo = JSONObject.fromObject(result2.body()); - JSONObject item = (JSONObject) detailjo.get(name); - if (ObjectUtil.isEmpty(detailjo.get(name))) { - continue; - } + com.alibaba.fastjson.JSONObject detailjo = (com.alibaba.fastjson.JSONObject) com.alibaba.fastjson.JSONObject.parse(result2.body()); + com.alibaba.fastjson.JSONObject item = (com.alibaba.fastjson.JSONObject) detailjo.get(name); String x = item.getString("x"); String y = item.getString("y"); String angle = item.getString("angle"); - String battery_temp = item.getString("battery_temp"); - String blocked = item.getString("blocked"); - String brake = item.getString("brake"); - String charging = item.getString("charging"); - String controller_temp = item.getString("controller_temp"); - String current_map = item.getString("current_map"); - String current_station = item.getString("current_station"); - String emergency = item.getString("emergency"); - String odo = item.getString("odo"); - String requestCurrent = item.getString("requestCurrent"); - String requestVoltage = item.getString("requestVoltage"); - String soft_emc = item.getString("soft_emc"); - String today_odo = item.getString("today_odo"); - String voltage = item.getString("voltage"); - String vx = item.getString("vx"); - String vy = item.getString("vy"); - String w = item.getString("w"); - - AgvDto dto = new AgvDto(); dto.setName(name); dto.setEnergyLevel(energyLevel); @@ -650,21 +639,6 @@ public class AgvServiceImpl implements AgvService { dto.setPositionAngle(angle); dto.setPositionX(x); dto.setPositionY(y); - dto.setBattery_temp(battery_temp); - dto.setBlocked(blocked); - dto.setBrake(brake); - dto.setCharging(charging); - dto.setController_temp(controller_temp); - dto.setCurrent_station(current_station); - dto.setEmergency(emergency); - dto.setOdo(odo); - dto.setRequestCurrent(requestCurrent); - dto.setRequestVoltage(requestVoltage); - dto.setVoltage(voltage); - dto.setSoft_emc(soft_emc); - dto.setVx(vx); - dto.setVy(vy); - dto.setW(w); if (AGVDeviceStatus.containsKey(name)) { AGVDeviceStatus.remove(name); AGVDeviceStatus.put(name, dto); @@ -677,30 +651,28 @@ public class AgvServiceImpl implements AgvService { } else { return null; } + + } @Override - public HttpResponse queryXZAgvInstStatus(String instCode) { - + public HttpResponse queryXZAgvInstStatus() { if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.FORKAGV).toString(), "1")) { String agvurl = acsConfigService.findConfigFromCache().get(AcsConfig.AGVURL); String agvport = acsConfigService.findConfigFromCache().get(AcsConfig.AGVPORT); - agvurl = agvurl + ":" + agvport + "/api/route/transportOrders/" + instCode; + agvurl = agvurl + ":" + agvport + "/orders?page=1&size=9999"; HttpResponse result = HttpRequest.get(agvurl) .timeout(20000)//超时,毫秒 .execute(); - System.out.println("查询agv指令数据:" + result.body()); - + log.info("queryXZAgvInstStatus----查询agv指令数据:{}" + result.body()); return result; } else { return null; } - - } @Override @@ -747,25 +719,24 @@ public class AgvServiceImpl implements AgvService { @Override public HttpResponse deleteXZAgvInst(String instCode) { - - if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.FORKAGV).toString(), "1")) { + if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.FORKAGV), "1")) { String agvurl = acsConfigService.findConfigFromCache().get(AcsConfig.AGVURL); String agvport = acsConfigService.findConfigFromCache().get(AcsConfig.AGVPORT); - agvurl = agvurl + ":" + agvport + "/api/route/transportOrders/" + instCode + "/withdrawal"; + com.alibaba.fastjson.JSONObject param = new com.alibaba.fastjson.JSONObject(); + param.put("id", instCode); + param.put("disableVehicle", false); + agvurl = agvurl + ":" + agvport + "/terminate"; log.info("删除agv指令请求agvurl:{}", agvurl); HttpResponse result = HttpRequest.post(agvurl) + .body(param.toJSONString()) .timeout(20000)//超时,毫秒 .execute(); log.info("删除agv指令请求反馈:{}", result); - return result; - } else { - return null; } - } @Override @@ -1680,33 +1651,17 @@ public class AgvServiceImpl implements AgvService { @Override public HttpResponse sendOrderSequencesToXZ(Instruction inst) throws Exception { - - JSONObject jo = new JSONObject(); - jo.put("intendedVehicle", ""); - jo.put("category", ""); - jo.put("failureFatal", false); - jo.put("complete", false); - JSONArray transports = new JSONArray(); - JSONObject orderjo = new JSONObject(); - orderjo.put("name", inst.getInstruction_code()); - orderjo.put("order", createOrederData(inst, "1")); - transports.add(orderjo); - jo.put("transports", transports); - - JSONArray ja1 = new JSONArray(); - JSONObject jo1 = new JSONObject(); - jo1.put("key", ""); - jo1.put("value", ""); - ja1.add(jo1); - jo.put("properties", ja1); - + com.alibaba.fastjson.JSONObject jo = new com.alibaba.fastjson.JSONObject(); + jo.put("id", inst.getInstruction_code()); + jo.put("complete", true); + jo.put("blocks", createBlocksData(inst)); + jo.put("priority", inst.getPriority()); log.info("任务号:{},指令号{},下发agv订单序列参数:{}", inst.getTask_code(), inst.getInstruction_code(), jo.toString()); - if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.FORKAGV).toString(), "1")) { + if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.FORKAGV), "1")) { String agvurl = acsConfigService.findConfigFromCache().get(AcsConfig.AGVURL); String agvport = acsConfigService.findConfigFromCache().get(AcsConfig.AGVPORT); - - agvurl = agvurl + ":" + agvport + "/api/route/orderSequences/" + inst.getTask_code(); + agvurl = agvurl + ":" + agvport + "/setOrder"; HttpResponse result = HttpRequest.post(agvurl) .body(String.valueOf(jo))//表单内容 @@ -1714,7 +1669,6 @@ public class AgvServiceImpl implements AgvService { .execute(); log.info(agvurl); log.info("任务号:{},指令号{},状态{},下发agv订单序列反馈:{}", inst.getTask_code(), inst.getInstruction_code(), result.getStatus(), result.body()); - return result; } else { return null; @@ -2068,7 +2022,7 @@ public class AgvServiceImpl implements AgvService { public JSONObject xgAGVControlDoorSwitch(JSONObject requestParam) { try { JSONObject requestWMSParam = new JSONObject(); - requestWMSParam.put("device_code", requestParam.optString("deviceID")); + requestWMSParam.put("device_code", requestParam.optString("doorName")); requestWMSParam.put("device_status", "1".equals(requestParam.optString("state")) ? "open" : "close"); JSONObject wmsResult = acsToWmsService.gccControlDoorSwitch(requestWMSParam); @@ -2091,9 +2045,9 @@ public class AgvServiceImpl implements AgvService { @Override public JSONObject xgAGVQueryDoorStatus(JSONObject requestParam) { - String[] deviceIDs = requestParam.optString("deviceIDs").split(","); + String[] doorNameList = requestParam.optJSONArray("doorNameList").optString(0).split(","); - if (deviceIDs.length == 1 && StrUtil.isBlank(deviceIDs[0])) { + if (doorNameList.length == 1 && StrUtil.isBlank(doorNameList[0])) { JSONObject result = new JSONObject(); result.put("result", 0); result.put("message", "操作成功"); @@ -2107,28 +2061,34 @@ public class AgvServiceImpl implements AgvService { JSONObject result = new JSONObject(); result.put("result", 0); result.put("message", "操作成功"); - result.put("data", Arrays.stream(deviceIDs) - .map(id -> { + result.put("data", Arrays.stream(doorNameList) + .map(doorName -> { JSONObject door = new JSONObject(); - door.put("deviceID", id); - door.put("doorState", -1); - door.put("timePoke", System.currentTimeMillis()); + door.put("doorName", doorName); + door.put("state", -1); + door.put("timestamp", System.currentTimeMillis()); return door; }).collect(Collectors.toList())); return result; } - List data = Arrays.stream(deviceIDs).map(id -> { + List data = Arrays.stream(doorNameList).map(doorName -> { JSONObject door = new JSONObject(); - door.put("deviceID", id); - List list = wmsResult.stream().filter(o -> id.equals(((com.alibaba.fastjson.JSONObject) o).getString("device_code"))).collect(Collectors.toList()); + 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("doorState", -1); + door.put("state", -1); } else { com.alibaba.fastjson.JSONObject row = (com.alibaba.fastjson.JSONObject) list.get(0); - door.put("doorState", "close".equals(row.getString("device_status")) ? 0 : 1); + 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("timePoke", System.currentTimeMillis()); + door.put("timestamp", System.currentTimeMillis()); return door; }).collect(Collectors.toList()); @@ -2144,4 +2104,150 @@ public class AgvServiceImpl implements AgvService { return result; } } + + public com.alibaba.fastjson.JSONArray createBlocksData(Instruction inst) { + com.alibaba.fastjson.JSONArray ja = new com.alibaba.fastjson.JSONArray(); + + Device startDevice = deviceAppService.findDeviceByCode(inst.getStart_device_code()); + if ("true".equals(startDevice.getExtraValue().get("ignore_pickup_check"))) { + //取货前等待 + com.alibaba.fastjson.JSONObject jo = new com.alibaba.fastjson.JSONObject(); + jo.put("blockId", IdUtil.simpleUUID()); + jo.put("location", inst.getStart_point_code() + "INGET"); + jo.put("operation", "script"); + jo.put("id", inst.getStart_point_code() + "INGET"); + jo.put("script_name", "userpy/interact.py"); + com.alibaba.fastjson.JSONObject script_args = new com.alibaba.fastjson.JSONObject(); + script_args.put("addr", addr); + com.alibaba.fastjson.JSONObject data = new com.alibaba.fastjson.JSONObject(); + com.alibaba.fastjson.JSONObject reach = new com.alibaba.fastjson.JSONObject(); + reach.put("task_code", inst.getInstruction_code()); + reach.put("address", inst.getStart_point_code() + "INGET"); + data.put("reach", reach); + script_args.put("data", data); + script_args.put("protocol", "HTTP"); + jo.put("script_args", script_args); + ja.add(jo); + } + + com.alibaba.fastjson.JSONObject jo1 = new com.alibaba.fastjson.JSONObject(); + jo1.put("blockId", IdUtil.simpleUUID()); + jo1.put("location", inst.getStart_point_code()); + jo1.put("operation", "JackLoad"); + ja.add(jo1); + +// if ("true".equals(startDevice.getExtraValue().get("ignore_pickup_check"))) { +// //取货完成等待 +// com.alibaba.fastjson.JSONObject jo2 = new com.alibaba.fastjson.JSONObject(); +// jo2.put("blockId", IdUtil.simpleUUID()); +// jo2.put("location", inst.getStart_point_code() + "OUTGET"); +// jo2.put("operation", "script"); +// jo2.put("id", inst.getStart_point_code() + "OUTGET"); +// jo2.put("script_name", "userpy/interact.py"); +// com.alibaba.fastjson.JSONObject script_args2 = new com.alibaba.fastjson.JSONObject(); +// script_args2.put("addr", addr); +// com.alibaba.fastjson.JSONObject data2 = new com.alibaba.fastjson.JSONObject(); +// com.alibaba.fastjson.JSONObject reach2 = new com.alibaba.fastjson.JSONObject(); +// reach2.put("task_code", inst.getInstruction_code()); +// reach2.put("address", inst.getStart_point_code() + "OUTGET"); +// data2.put("reach", reach2); +// script_args2.put("data", data2); +// script_args2.put("protocol", "HTTP"); +// jo2.put("script_args", script_args2); +// ja.add(jo2); +// } + + Device nextDevice = deviceAppService.findDeviceByCode(inst.getNext_device_code()); + if ("true".equals(nextDevice.getExtraValue().get("ignore_release_check"))) { + //放货前等待 + com.alibaba.fastjson.JSONObject jo3 = new com.alibaba.fastjson.JSONObject(); + jo3.put("blockId", IdUtil.simpleUUID()); + jo3.put("location", inst.getNext_point_code() + "INPUT"); + jo3.put("operation", "script"); + jo3.put("id", inst.getNext_point_code() + "INPUT"); + jo3.put("script_name", "userpy/interact.py"); + com.alibaba.fastjson.JSONObject script_args3 = new com.alibaba.fastjson.JSONObject(); + script_args3.put("addr", addr); + com.alibaba.fastjson.JSONObject data3 = new com.alibaba.fastjson.JSONObject(); + com.alibaba.fastjson.JSONObject reach3 = new com.alibaba.fastjson.JSONObject(); + reach3.put("task_code", inst.getInstruction_code()); + reach3.put("address", inst.getNext_point_code() + "INPUT"); + data3.put("reach", reach3); + script_args3.put("data", data3); + script_args3.put("protocol", "HTTP"); + jo3.put("script_args", script_args3); + ja.add(jo3); + } + + com.alibaba.fastjson.JSONObject jo4 = new com.alibaba.fastjson.JSONObject(); + jo4.put("blockId", IdUtil.simpleUUID()); + jo4.put("location", inst.getNext_point_code()); + jo4.put("operation", "JackUnload"); + ja.add(jo4); + +// if ("true".equals(nextDevice.getExtraValue().get("ignore_release_check"))) { +// //放货完成等待 +// com.alibaba.fastjson.JSONObject jo5 = new com.alibaba.fastjson.JSONObject(); +// jo5.put("blockId", IdUtil.simpleUUID()); +// jo5.put("location", inst.getNext_point_code() + "OUTPUT"); +// jo5.put("operation", "script"); +// jo5.put("id", inst.getNext_point_code() + "OUTPUT"); +// jo5.put("script_name", "userpy/interact.py"); +// com.alibaba.fastjson.JSONObject script_args5 = new com.alibaba.fastjson.JSONObject(); +// script_args5.put("addr", addr); +// com.alibaba.fastjson.JSONObject data5 = new com.alibaba.fastjson.JSONObject(); +// com.alibaba.fastjson.JSONObject reach5 = new com.alibaba.fastjson.JSONObject(); +// reach5.put("task_code", inst.getInstruction_code()); +// reach5.put("address", inst.getNext_point_code() + "OUTPUT"); +// data5.put("reach", reach5); +// script_args5.put("data", data5); +// script_args5.put("protocol", "HTTP"); +// jo5.put("script_args", script_args5); +// ja.add(jo5); +// } + + return ja; + } + + @Override + public JSONObject xgAGVWaitPointRequest(JSONObject requestParam) { + log.info("仙工AGV请求取放货,请求参数 - {}", requestParam); + String inst_code = requestParam.getString("task_code"); + Instruction instructionDto = instructionService.findByCodeFromCache(inst_code); + if (ObjectUtil.isEmpty(instructionDto)) { + throw new BadRequestException("请求失败,未找到指令!"); + } + String address = requestParam.getString("address"); + if (StrUtil.isBlank(address)) { + throw new BadRequestException("请求失败,地址为空!"); + } + + + if (address.contains("IN")) { + String deviceCodeNow = address.substring(0, address.length() - 5); + if (ObjectUtil.isEmpty(deviceAppService.findDeviceByCode(deviceCodeNow))) { + throw new BadRequestException("设备号 " + deviceCodeNow + " 不存在!"); + } + + if (address.contains("GET")) { + return agvWaitUtil.waitInGet(deviceCodeNow); + } else if (address.contains("PUT")) { + return agvWaitUtil.waitInPut(deviceCodeNow); + } + } + if (address.contains("OUT")) { + String deviceCodeNow = address.substring(0, address.length() - 6); + if (ObjectUtil.isEmpty(deviceAppService.findDeviceByCode(deviceCodeNow))) { + throw new BadRequestException("设备号 " + deviceCodeNow + " 不存在!"); + } + + if (address.contains("GET")) { + return agvWaitUtil.waitOutGet(deviceCodeNow); + } else if (address.contains("PUT")) { + return agvWaitUtil.waitOutPut(deviceCodeNow); + } + } + + throw new BadRequestException("请求失败,IN OUT 站点错误!"); + } } 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 574bcaf..44f9217 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 @@ -139,4 +139,19 @@ public interface AcsToWmsService { * ] */ com.alibaba.fastjson.JSONArray gccQueryDoorStatus(); + + /** + * 六维广钞厂查询站点有无货状态 + * @param requestWMSParam 示例:{ + * "StartStationCode":"111", + * "EndStationCode":"222" + * } + * @return 示例:{ + * "errArr":null, + * "data":[{"Station_Code":"1170","IsHasGoods":true},{"Station_Code":"1030","IsHasGoods":true}], + * "status":"200", + * "message":"获取站点相关信息成功" + * } + */ + JSONObject gccQueryStationState(JSONObject requestWMSParam); } 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 006c3da..041dbee 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 @@ -559,4 +559,27 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { return new com.alibaba.fastjson.JSONArray(); } } + + @Override + public JSONObject gccQueryStationState(JSONObject requestWMSParam) { + try { + String wmsurl = acsConfigService.findConfigFromCache().get(AcsConfig.WMSURL); + AddressDto addressDto = addressService.findByCode("gccQueryStationState"); + + log.info("gccQueryStationState - 请求参数{}", requestWMSParam); + String responseBody = HttpRequest + .post(wmsurl + addressDto.getMethods_url()) + .body(requestWMSParam.toString()) + .execute() + .body(); + log.info("gccQueryStationState - 响应参数{}", responseBody); + + return JSONObject.fromObject(responseBody); + } catch (Exception e) { + JSONObject result = new JSONObject(); + result.put("status", HttpStatus.BAD_REQUEST.value()); + result.put("message", e.getMessage()); + return result; + } + } } diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java b/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java index 3342ef3..6a05b0b 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java @@ -242,4 +242,5 @@ public interface InstructionService { boolean removeByCodeFromCache(String code); + public Instruction findByInstCodeFromCache(String inst_code); } diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java b/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java index 7eefe4f..9304df6 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java @@ -1209,4 +1209,15 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$"); return pattern.matcher(str).matches(); } + + @Override + public Instruction findByInstCodeFromCache(String inst_code) { + for (int i = 0; i < this.instructions.size(); i++) { + Instruction inst = instructions.get(i); + if (StrUtil.equals(inst_code, inst.getInstruction_code())) { + return inst; + } + } + return null; + } } diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java b/hd/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java index 2ad1f12..62cac7f 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java @@ -1069,13 +1069,13 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { } //如果属于先知AGV,关闭运单序列 - if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.AGVTYPE).toString(), "3")) { - try { - agvService.markComplete(entity.getTask_code()); - } catch (Exception e) { - e.printStackTrace(); - } - } +// if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.AGVTYPE).toString(), "3")) { +// try { +// agvService.markComplete(entity.getTask_code()); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } } @Override @@ -1121,11 +1121,11 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { List shortPathsList = routeLineService.getShortPathLines(entity.getStart_device_code(), entity.getNext_device_code(), entity.getRoute_plan_code()); String type = shortPathsList.get(0).getType(); // != 0 为agv任务 - if (!StrUtil.equals(type, "0")) { - if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.AGVTYPE).toString(), "3")) { - agvService.markComplete(entity.getTask_code()); - } - } +// if (!StrUtil.equals(type, "0")) { +// if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.AGVTYPE).toString(), "3")) { +// agvService.markComplete(entity.getTask_code()); +// } +// } } @Override diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/test/rest/TestController.java b/hd/nladmin-system/src/main/java/org/nl/acs/test/rest/TestController.java index 6d65380..f3a1fda 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/test/rest/TestController.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/test/rest/TestController.java @@ -6,6 +6,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import net.sf.json.JSONObject; import org.nl.acs.test.service.TestService; import org.nl.annotation.Log; import org.springframework.http.HttpStatus; @@ -35,18 +36,16 @@ public class TestController { @ApiOperation("test1") @PostMapping("/test1") //@PreAuthorize("@el.check('task:add')") - public ResponseEntity test1() throws IOException { - testService.test1(); - return new ResponseEntity<>(HttpStatus.CREATED); + public ResponseEntity test1(@RequestBody JSONObject requestParam) { + return new ResponseEntity<>(testService.test1(requestParam), HttpStatus.OK); } @Log("test2") @ApiOperation("test2") @PostMapping("/test2") //@PreAuthorize("@el.check('task:add')") - public ResponseEntity test2() throws IOException { - testService.test2(); - return new ResponseEntity<>(HttpStatus.CREATED); + public ResponseEntity test2(@RequestBody JSONObject requestParam) { + return new ResponseEntity<>(testService.test2(requestParam), HttpStatus.OK); } @Log("test3") diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/test/service/TestService.java b/hd/nladmin-system/src/main/java/org/nl/acs/test/service/TestService.java index bef5f7a..83870fb 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/test/service/TestService.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/test/service/TestService.java @@ -17,14 +17,14 @@ public interface TestService { * * @throws IOException */ - void test1() throws IOException; + JSONObject test1(JSONObject requestParam); /** * 触发打印 * * @throws IOException */ - void test2() throws IOException; + JSONObject test2(JSONObject requestParam); /** * 加载模板 diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/test/service/impl/TestServiceImpl.java b/hd/nladmin-system/src/main/java/org/nl/acs/test/service/impl/TestServiceImpl.java index b7cce46..f7b36ef 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/test/service/impl/TestServiceImpl.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/test/service/impl/TestServiceImpl.java @@ -4,12 +4,14 @@ package org.nl.acs.test.service.impl; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.nl.acs.test.service.TestService; import org.nl.start.auto.run.LetteringSocketConnectionAutoRun; import org.springframework.stereotype.Service; import java.io.IOException; +import java.util.HashMap; import java.util.Map; /** @@ -22,32 +24,42 @@ import java.util.Map; @Slf4j public class TestServiceImpl implements TestService { + private final HashMap doors = new HashMap<>(); + @Override - public void test1() throws IOException { + public JSONObject test1(JSONObject requestParam) { + log.info("AGV控制门开关 - 请求参数{}", requestParam); - try { - //返回编译完成信号 - LetteringSocketConnectionAutoRun.write("SETMSG 26 1" + "\r\n"); - //返回打印开始信号 - LetteringSocketConnectionAutoRun.write("SETMSG 2 1" + "\r\n"); - //返回打印完成信号 - LetteringSocketConnectionAutoRun.write("SETMSG 3 1" + "\r\n"); - //返回每次打印的内容 - LetteringSocketConnectionAutoRun.write("SETMSG 24 1" + "\r\n"); + doors.put(requestParam.optString("deviceID"), requestParam.optInt("state") == 0 ? 0 : 1); - } catch (Exception e) { - e.printStackTrace(); - } + JSONObject result = new JSONObject(); + result.put("result", 0); + result.put("message", "操作成功"); + log.info("AGV控制门开关 - 响应参数{}", result); + return result; } @Override - public void test2() throws IOException { - try { - LetteringSocketConnectionAutoRun.write("BUFFERCLEAR" + "\r\n"); - } catch (Exception e) { - e.printStackTrace(); + public JSONObject test2(JSONObject requestParam) { + log.info("AGV查询门状态 - 请求参数{}", requestParam); + + String[] deviceIDs = requestParam.optString("deviceIDs").split(","); + JSONArray data = new JSONArray(); + JSONObject row = new JSONObject(); + for (String deviceID : deviceIDs) { + row.put("deviceID", deviceID); + row.put("doorState", doors.get(deviceID) == null ? -1 : doors.get(deviceID)); + row.put("timePoke", System.currentTimeMillis()); + data.add(row); } + + JSONObject result = new JSONObject(); + result.put("result", 0); + result.put("message", "操作成功"); + result.put("data", data); + log.info("AGV查询门状态 - 响应参数{}", result); + return result; } @Override diff --git a/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvTaskStatus.java b/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvTaskStatus.java index 1ee2a61..1a0d644 100644 --- a/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvTaskStatus.java +++ b/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvTaskStatus.java @@ -1,13 +1,17 @@ package org.nl.modules.quartz.task; import cn.hutool.core.map.MapUtil; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpResponse; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; -import net.sf.json.JSONObject; import org.nl.acs.agv.server.AgvService; +import org.nl.acs.ext.wms.service.AcsToWmsService; import org.nl.acs.instruction.service.InstructionService; import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.task.service.TaskService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -26,59 +30,75 @@ public class QueryXZAgvTaskStatus { @Autowired AgvService agvService; + @Autowired + AcsToWmsService acsToWmsService; + + @Autowired + TaskService taskService; public void run() throws Exception { - List instList = instructionService.findAllInstFromCache(); - if (instList.size() > 0) { - for (int i = 0; i < instList.size(); i++) { - Instruction inst = instList.get(i); - if (!StrUtil.equals(inst.getSend_status(), "1")) continue; - String instcode = inst.getInstruction_code(); - HttpResponse response = agvService.queryXZAgvInstStatus(instcode); - JSONObject jo = JSONObject.fromObject(response.body()); - if (MapUtil.isEmpty(jo)) continue; - //反馈结果状态 - log.info("instcode:" + instcode + "," + jo.toString()); - //指令执行状态 - String state = jo.getString("state"); - String processingVehicle = ""; - //正在执行指令agv车号 - if (!StrUtil.isEmpty(jo.getString("processingVehicle"))) { - processingVehicle = jo.getString("processingVehicle"); - inst.setCarno(processingVehicle); - } -// RAW:初始状态 -// ACTIVE:业务订单已激活 -// DISPATCHABLE:业务订单已通过系统验证,等待被调度执行 -// BEING_PROCESSED:业务订单正在被执行 -// WITHDRAWN:业务订单已被撤销 -// FINISHED:业务订单已完成 -// FAILED:业务订单已失败 -// UNROUTABLE:无法规划该业务订单的执行路线 + HttpResponse response = agvService.queryXZAgvInstStatus(); + com.alibaba.fastjson.JSONObject jo = JSONArray.parseObject(response.body()); - //执行中 - if ("BEING_PROCESSED".equals(state)) { - if (inst != null) { - inst.setInstruction_status("1"); - instructionService.update(inst); - } - } else if ("FINISHED".equals(state)) { - if (inst != null) { - inst.setInstruction_status("2"); - instructionService.finish(inst); - } - } else if ("WITHDRAWN".equals(state) || "FAILED".equals(state)) { - if (inst != null) { - inst.setInstruction_status("4"); - instructionService.update(inst); - //instructionService.removeByCodeFromCache(instcode); - } - } else { + JSONArray ja = JSONArray.parseArray(jo.getString("list")); + for (int i = 0; i < ja.size(); i++) { + com.alibaba.fastjson.JSONObject one = (com.alibaba.fastjson.JSONObject) ja.get(i); + String inst_code = one.getString("id"); + Instruction inst = instructionService.findByInstCodeFromCache(inst_code); + if (ObjectUtil.isEmpty(inst)) + continue; + //子任务状态 待以后处理 + JSONArray blocks = JSONArray.parseArray(one.getString("blocks")); + for(int j=0;j