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 8e5ed8a..dd6ef7b 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 @@ -4,6 +4,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.apache.commons.lang3.StringUtils; import org.nl.acs.agv.server.AgvService; import org.nl.acs.device.service.DeviceService; @@ -69,14 +70,11 @@ public class AgvController { return new ResponseEntity<>(agvService.sendAgvInstToMagic(instcode), HttpStatus.OK); } - @GetMapping("/waitPointRequest/locationDevices/{param}") - @Log("agv等待点请求") - @ApiOperation("下发agv任务") - //@PreAuthorize("@el.check('routePlan:list')") - public ResponseEntity waitPointRequest(HttpServletRequest req) throws Exception { - String serviceName = req.getRequestURI(); - String param = StringUtils.substringAfterLast(serviceName, "/"); - return new ResponseEntity<>(agvService.waitPointRequest(param), HttpStatus.OK); + @PostMapping ("/agv/xg/waitPointRequest") + @Log("仙工AGV请求取放货") + @ApiOperation("仙工AGV请求取放货") + public ResponseEntity xgAGVWaitPointRequest(@RequestBody JSONObject requestParam) { + return new ResponseEntity<>(agvService.xgAGVWaitPointRequest(requestParam), HttpStatus.OK); } @GetMapping("/findAllAgvFromCache") 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 5d789c8..002dab8 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 @@ -64,7 +64,7 @@ public interface AgvService { public void deleteAgvInstToNDC(Instruction inst) throws Exception; - /** + /*VV* * 查询Magic AGV任务状态调用 * * @param jobno @@ -90,7 +90,7 @@ public interface AgvService { * @param * @return */ - public String waitPointRequest(String param); + JSONObject xgAGVWaitPointRequest(JSONObject requestParam); /** * 请求开门、关门 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 9d8a244..503702e 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; @@ -39,13 +40,16 @@ import org.nl.acs.opc.DeviceAppService; import org.nl.acs.opc.DeviceAppServiceImpl; import org.nl.acs.opc.DeviceType; import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; import org.nl.exception.BadRequestException; 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.stereotype.Service; +import java.math.BigDecimal; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; @@ -76,6 +80,8 @@ public class AgvServiceImpl implements AgvService { Map AGVDeviceStatus = new HashMap(); + @Value("${agvToAcs.addr}") + private String addr; /** * 获得之后num个天的时间 * @@ -589,19 +595,12 @@ public class AgvServiceImpl implements AgvService { 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"; + agvurl = agvurl + ":" + agvport + "/robotsStatus"; - HttpResponse result = HttpRequest.get(agvurl1) + HttpResponse result = HttpRequest.get(agvurl) .timeout(20000)//超时,毫秒 .execute(); - - 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()); @@ -611,7 +610,7 @@ public class AgvServiceImpl implements AgvService { String state = jo.getString("state"); String energyLevel = jo.getString("energyLevel"); String transportOrder = jo.getString("transportOrder"); - JSONObject detailjo = JSONObject.fromObject(result2.body()); + JSONObject detailjo = JSONObject.fromObject(result.body()); JSONObject item = (JSONObject) detailjo.get(name); if(ObjectUtil.isEmpty(detailjo.get(name))){ continue; @@ -1067,250 +1066,108 @@ public class AgvServiceImpl implements AgvService { } @Override - public String waitPointRequest(String param) { - log.info("收到AGV请求参数:{}", param); - String[] strs = param.split("-"); - String address = strs[0]; - String inst_code = strs[1]; - String type = strs[2]; - String newaddress = null; - // 前置点会加上p - if (address.endsWith("IN")) { - newaddress = address.substring(0, address.length() - 2); - } else if (address.endsWith("OUT")) { - newaddress = address.substring(0, address.length() - 3); - } else if (address.endsWith("P") || address.endsWith("L") || address.endsWith("R")) { - newaddress = address.substring(0, address.length() - 1); - } else if (address.endsWith("CZ")) { - newaddress = address.substring(0, address.length() - 2); - } else if (address.endsWith("IQ") || address.endsWith("OQ")) { - newaddress = address.substring(0, address.length() - 2); - } else { - newaddress = address; + public JSONObject xgAGVWaitPointRequest(JSONObject requestParam) { + log.info("仙工AGV请求取放货,请求参数 - {}", requestParam); + String instCode = requestParam.getString("task_code"); + Instruction inst = instructionService.findByCodeFromCache(instCode); + if (ObjectUtil.isEmpty(inst)) { + throw new BadRequestException("请求失败,未找到指令!"); } - boolean is_feedback = false; - - Device device = deviceAppService.findDeviceByCode(newaddress); - StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; - MachinesSiteDeviceDriver machinesSiteDeviceDriver; - WeighingSiteDeviceDriver weighingSiteDeviceDriver; - StandardManipulatorInspectSiteDeviceDriver sandardManipulatorInspectSiteDeviceDriver; - StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; - NdxySpecialTwoDeviceDriver ndxySpecialTwoDeviceDriver; - YkbkSpecialDeviceDriver ykbkSpecialDeviceDriver; - YzjaSpecialDeviceDriver yzjaSpecialDeviceDriver; - if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); - //人工确认信号 - if (standardOrdinarySiteDeviceDriver.getManua_confirm() == 2) { - is_feedback = true; - standardOrdinarySiteDeviceDriver.setManua_confirm(0); - } else { - standardOrdinarySiteDeviceDriver.setManua_confirm(1); - } + TaskDto task = taskService.findByCodeFromCache(inst.getTask_code()); + if (ObjectUtil.isEmpty(task)) { + throw new BadRequestException("请求失败,未找到指令对应任务!"); } - if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { - standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver(); - //请求取货 - if (StrUtil.equals(type, "01") && address.endsWith("IN") - && standardInspectSiteDeviceDriver.getMove() != 0) { - standardInspectSiteDeviceDriver.writing(1, 1); - is_feedback = true; - } - //取货完成 - else if (StrUtil.equals(type, "02")) { - standardInspectSiteDeviceDriver.writing(1, 2); - is_feedback = true; - } - //取货完成离开 - else if (StrUtil.equals(type, "05") && address.endsWith("OUT") - && standardInspectSiteDeviceDriver.getMove() == 0) { - standardInspectSiteDeviceDriver.writing(1, 5); - is_feedback = true; - } - //请求放货 - else if (StrUtil.equals(type, "03") && address.endsWith("IN") - && standardInspectSiteDeviceDriver.getMove() == 0) { - standardInspectSiteDeviceDriver.writing(1, 3); - is_feedback = true; - } - //放货完成 - else if (StrUtil.equals(type, "04")) { - standardInspectSiteDeviceDriver.writing(1, 4); - is_feedback = true; - } - //放货完成离开 - else if (StrUtil.equals(type, "06") && address.endsWith("OUT") - && standardInspectSiteDeviceDriver.getMove() != 0) { - standardInspectSiteDeviceDriver.writing(1, 6); - is_feedback = true; - } - + String address = requestParam.getString("address"); + if (StrUtil.isBlank(address)) { + throw new BadRequestException("请求失败,地址为空!"); } - if (device.getDeviceDriver() instanceof StandardManipulatorInspectSiteDeviceDriver) { - sandardManipulatorInspectSiteDeviceDriver = (StandardManipulatorInspectSiteDeviceDriver) device.getDeviceDriver(); - //请求进 - if (StrUtil.equals(type, "07") && address.endsWith("IQ")) { - sandardManipulatorInspectSiteDeviceDriver.writing(1, 7); - if ( sandardManipulatorInspectSiteDeviceDriver.getIo_action() == 1 - || sandardManipulatorInspectSiteDeviceDriver.getIo_action() == 3) { - is_feedback = true; - } - } + //请求取货 - else if (StrUtil.equals(type, "01") && address.endsWith("IN")) { - sandardManipulatorInspectSiteDeviceDriver.writing(1, 1); - if ((sandardManipulatorInspectSiteDeviceDriver.getActoin() == 1 || sandardManipulatorInspectSiteDeviceDriver.getActoin() == 3) - && sandardManipulatorInspectSiteDeviceDriver.getMove() != 0) { - is_feedback = true; + if (address.contains("INGET")) { + JSONObject jo=new JSONObject(); + jo.put("device_code",inst.getStart_device_code()); + jo.put("device_status","enter"); + log.info("请求参数:{}", jo); + JSONArray ja=new JSONArray(); + for(Object key:jo.keySet()){ + JSONObject jo1=new JSONObject(); + jo1.put(key,jo.get(key)); + ja.add(jo1); + } + HttpResponse result=acsToWmsService.vehicle(ja); + com.alibaba.fastjson.JSONObject response = com.alibaba.fastjson.JSONObject.parseObject(result.body()); + int responseCode = response.getInteger("status"); + if (responseCode == 200) { + log.info("上位允许取货 请求结果{}", responseCode); + }else{ + throw new BadRequestException("上位系统不允许取货"); } - } - //取货完成 - else if (StrUtil.equals(type, "02")) { - sandardManipulatorInspectSiteDeviceDriver.writing(1, 2); - is_feedback = true; } //取货完成离开 - else if (StrUtil.equals(type, "05") && address.endsWith("OUT")) { - sandardManipulatorInspectSiteDeviceDriver.writing(1, 5); - if ((sandardManipulatorInspectSiteDeviceDriver.getIo_action() == 2 - || sandardManipulatorInspectSiteDeviceDriver.getIo_action() == 3) && sandardManipulatorInspectSiteDeviceDriver.getMove() == 0) { - is_feedback = true; + if (address.contains("OUTGET")) { + JSONObject jo=new JSONObject(); + jo.put("device_code",inst.getStart_device_code()); + jo.put("device_status","left"); + log.info("请求参数:{}", jo); + JSONArray ja=new JSONArray(); + for(Object key:jo.keySet()){ + JSONObject jo1=new JSONObject(); + jo1.put(key,jo.get(key)); + ja.add(jo1); } - } - //请求离开 - else if (StrUtil.equals(type, "08") && address.endsWith("OQ")) { - sandardManipulatorInspectSiteDeviceDriver.writing(1, 8); - if (sandardManipulatorInspectSiteDeviceDriver.getIo_action() == 2 - || sandardManipulatorInspectSiteDeviceDriver.getIo_action() == 3) { - is_feedback = true; + HttpResponse result=acsToWmsService.vehicle(ja); + com.alibaba.fastjson.JSONObject response = com.alibaba.fastjson.JSONObject.parseObject(result.body()); + int responseCode = response.getInteger("status"); + if (responseCode == 200) { + log.info("上位允许取货离开 请求结果{}", responseCode); + }else{ + throw new BadRequestException("上位系统不允许取货完成离开"); } } //请求放货 - else if (StrUtil.equals(type, "03") && address.endsWith("IN")) { - sandardManipulatorInspectSiteDeviceDriver.writing(1, 3); - if ((sandardManipulatorInspectSiteDeviceDriver.getActoin() == 2 || sandardManipulatorInspectSiteDeviceDriver.getActoin() == 3) - && sandardManipulatorInspectSiteDeviceDriver.getMove() == 0) { - is_feedback = true; + if (address.contains("INPUT")) { + JSONObject jo=new JSONObject(); + jo.put("device_code",inst.getNext_device_code()); + jo.put("device_status","enter"); + log.info("请求参数:{}", jo); + JSONArray ja=new JSONArray(); + for(Object key:jo.keySet()){ + JSONObject jo1=new JSONObject(); + jo1.put(key,jo.get(key)); + ja.add(jo1); } - } - //放货完成 - else if (StrUtil.equals(type, "04")) { - sandardManipulatorInspectSiteDeviceDriver.writing(1, 4); - is_feedback = true; - } - //放货完成离开 - else if (StrUtil.equals(type, "06") && address.endsWith("OUT")) { - sandardManipulatorInspectSiteDeviceDriver.writing(1, 6); - if ((sandardManipulatorInspectSiteDeviceDriver.getIo_action() == 2 - || sandardManipulatorInspectSiteDeviceDriver.getIo_action() == 3) && sandardManipulatorInspectSiteDeviceDriver.getMove() != 0) { - is_feedback = true; + HttpResponse result=acsToWmsService.vehicle(ja); + com.alibaba.fastjson.JSONObject response = com.alibaba.fastjson.JSONObject.parseObject(result.body()); + int responseCode = response.getInteger("status"); + if (responseCode == 200) { + log.info("上位允许放货 请求结果{}", responseCode); + }else{ + throw new BadRequestException("上位系统不允许请求放货"); } } - } - if (device.getDeviceDriver() instanceof WeighingSiteDeviceDriver) { - weighingSiteDeviceDriver = (WeighingSiteDeviceDriver) device.getDeviceDriver(); - Instruction inst = instructionService.findByCodeFromCache(inst_code); - weighingSiteDeviceDriver.setInst(inst); - //调用erp接口 - if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.HASOTHERSYSTEM).toString(), "1")) { - log.info("请求ERP接口参数:{}", inst.getStart_device_code()); - JSONObject jo = acsToErpService.sendDeviceToWms(inst.getStart_device_code()); - log.info("ERP接口反馈:{}", jo); - } - is_feedback = true; - } - if (device.getDeviceDriver() instanceof MachinesSiteDeviceDriver) { - machinesSiteDeviceDriver = (MachinesSiteDeviceDriver) device.getDeviceDriver(); - //请求进 - if (address.endsWith("IN")) { - if (machinesSiteDeviceDriver.getIoaction() == 1 || machinesSiteDeviceDriver.getIoaction() == 3) { - is_feedback = true; - } else { - machinesSiteDeviceDriver.writing(6); + //放货完成离开 + if (address.contains("OUTPUT")) { + JSONObject jo=new JSONObject(); + jo.put("device_code",inst.getNext_device_code()); + jo.put("device_status","left"); + log.info("请求参数:{}", jo); + JSONArray ja=new JSONArray(); + for(Object key:jo.keySet()){ + JSONObject jo1=new JSONObject(); + jo1.put(key,jo.get(key)); + ja.add(jo1); } - } - //请求离开 - else if (address.endsWith("OUT")) { - machinesSiteDeviceDriver.writing(6); - machinesSiteDeviceDriver.writing(6); - is_feedback = true; - - } else { - - if (machinesSiteDeviceDriver.getIoaction() == 2 || machinesSiteDeviceDriver.getIoaction() == 3) { - is_feedback = true; - } else { - machinesSiteDeviceDriver.writing(5); - machinesSiteDeviceDriver.writing(2, device.getAddress() == null ? 0 : Integer.parseInt(device.getAddress())); + HttpResponse result=acsToWmsService.vehicle(ja); + com.alibaba.fastjson.JSONObject response = com.alibaba.fastjson.JSONObject.parseObject(result.body()); + int responseCode = response.getInteger("status"); + if (responseCode == 200) { + log.info("上位允许放货离开 请求结果{}", responseCode); + }else{ + throw new BadRequestException("上位系统不允许放货完成离开"); } } - } - if (device.getDeviceDriver() instanceof NdxySpecialTwoDeviceDriver) { - ndxySpecialTwoDeviceDriver = (NdxySpecialTwoDeviceDriver) device.getDeviceDriver(); - //请求取货 - if (StrUtil.equals(type, "01") && ndxySpecialTwoDeviceDriver.getMove() != 0) { - ndxySpecialTwoDeviceDriver.writing(1, 1); - is_feedback = true; - } - //取货完成 - else if (StrUtil.equals(type, "02")) { - ndxySpecialTwoDeviceDriver.writing(1, 2); - is_feedback = true; - } - - //请求放货 - else if (StrUtil.equals(type, "03") && ndxySpecialTwoDeviceDriver.getMove() == 0) { - ndxySpecialTwoDeviceDriver.writing(1, 3); - is_feedback = true; - } - //放货完成 - else if (StrUtil.equals(type, "04")) { - ndxySpecialTwoDeviceDriver.writing(1, 4); - is_feedback = true; - } - } - if (device.getDeviceDriver() instanceof YkbkSpecialDeviceDriver) { - ykbkSpecialDeviceDriver = (YkbkSpecialDeviceDriver) device.getDeviceDriver(); - //请求取货 - if (StrUtil.equals(type, "01") && ykbkSpecialDeviceDriver.getMove() != 0) { - ykbkSpecialDeviceDriver.writing(1, 1); - is_feedback = true; - } - //取货完成 - else if (StrUtil.equals(type, "02")) { - ykbkSpecialDeviceDriver.writing(1, 2); - is_feedback = true; - } - - //请求放货 - else if (StrUtil.equals(type, "03") && ykbkSpecialDeviceDriver.getMove() == 0) { - ykbkSpecialDeviceDriver.writing(1, 3); - is_feedback = true; - } - //放货完成 - else if (StrUtil.equals(type, "04")) { - ykbkSpecialDeviceDriver.writing(1, 4); - is_feedback = true; - } - } - JSONObject jo = new JSONObject(); - if (is_feedback) { - jo.put("name", param); - jo.put("lastAction", "wait"); - jo.put("lastActionStatus", "DONE"); - jo.put("status", "IDLE"); - } else { - jo.put("name", param); - jo.put("lastAction", "wait"); - jo.put("lastActionStatus", "FAILED"); - jo.put("status", "IDLE"); - } - is_feedback = false; - log.info("反馈AGV请求参数:{}", jo.toString()); - - return jo.toString(); + throw new BadRequestException("请求失败,IN OUT 站点错误!"); } @Override @@ -1677,32 +1534,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))//表单内容 @@ -1710,13 +1552,126 @@ 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; } } + 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); + + //取货完成等待 + 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 json1 = new com.alibaba.fastjson.JSONObject(); +// AcsPointAngleDto acsPointAngleDto = acsPointAngleService.findByCode(inst.getStart_device_code(),inst.getNext_device_code()); +// if (ObjectUtil.isNotEmpty(acsPointAngleDto)){ +// log.info("acsPointAngleDto----參數,{}", acsPointAngleDto.toString()); +// com.alibaba.fastjson.JSONObject operation_args = new com.alibaba.fastjson.JSONObject(); +// BigDecimal next_point_angle = acsPointAngleDto.getNext_point_angle(); +// operation_args.put("increase_spin_angle",next_point_angle);//弧度值,如3.14 +// operation_args.put("skill_name","GoByOdometer"); +// json1.put("blockId", IdUtil.simpleUUID()); +// json1.put("location", inst.getNext_point_code() + "INPUT"); +// json1.put("operation_args",operation_args); +// ja.add(json1); +// } + + 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 HttpResponse addOrderSequences(Instruction inst) throws Exception { JSONObject orderjo = createOrederData(inst, "1"); diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/device/rest/DeviceController.java b/hd/nladmin-system/src/main/java/org/nl/acs/device/rest/DeviceController.java index 08404a5..a1e63d0 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/device/rest/DeviceController.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/device/rest/DeviceController.java @@ -340,8 +340,6 @@ public class DeviceController { //@PreAuthorize("@el.check('routePlan:list')") public ResponseEntity selectDriverCodeList(@PathVariable String device_code) { DeviceDto device = deviceService.findByCode(device_code); - //System.out.println(device.getDevice_type()); - //return new ResponseEntity<>(DriverTypeEnum.getList(), HttpStatus.OK); return new ResponseEntity<>(DriverTypeEnum.getListByType(device.getDevice_type()), HttpStatus.OK); } diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToWmsController.java b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToWmsController.java index f52f5bc..9be320d 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToWmsController.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToWmsController.java @@ -26,7 +26,7 @@ import java.util.Map; @RestController @RequiredArgsConstructor @Api(tags = "wms接口") -@RequestMapping("/api/wms") +@RequestMapping("/api/agv") @Slf4j public class AcsToWmsController { private final AcsToWmsService acstowmsService; @@ -38,7 +38,7 @@ public class AcsToWmsController { return new ResponseEntity<>(acstowmsService.applyTaskToWms(device_code, container_code, height, weight), HttpStatus.OK); } - @PostMapping("/taskStatusFeedback") + @PostMapping("/task") @Log("向WMS反馈任务状态") @ApiOperation("向WMS反馈任务状态") public ResponseEntity feedbackTaskStatusToWms(@RequestBody Map whereJson) { @@ -60,7 +60,7 @@ public class AcsToWmsController { return new ResponseEntity<>(acstowmsService.feedbackAgvStatus(device_code, error, error_message), HttpStatus.OK); } - @PostMapping("/feedbackAgv") + @PostMapping("/device") @Log("反馈AGV设备信息") @ApiOperation("反馈AGV设备信息") public ResponseEntity feedbackAgv(@RequestBody String from) { @@ -81,4 +81,13 @@ public class AcsToWmsController { public ResponseEntity feedbackDeviceStatus(@RequestBody String device_code, String code, String value) { return new ResponseEntity<>(acstowmsService.feedbackDeviceStatus(device_code, code, value), HttpStatus.OK); } + + @PostMapping("/vehicle") + @Log("动作请求") + @ApiOperation("动作请求") + public ResponseEntity vehicle(@RequestBody String from) { + JSONArray array = JSONArray.fromObject(from); + return new ResponseEntity<>(acstowmsService.vehicle(array), HttpStatus.OK); + } + } diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/XGToAcsController.java b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/XGToAcsController.java new file mode 100644 index 0000000..00c9223 --- /dev/null +++ b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/XGToAcsController.java @@ -0,0 +1,29 @@ +package org.nl.acs.ext.wms.rest; + +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.acs.ext.wms.service.XGToAcsService; +import org.nl.annotation.Log; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +@RestController +@RequiredArgsConstructor +@Api(tags = "XGToacs接口") +@Slf4j +public class XGToAcsController { + private final XGToAcsService XGToAcsService; + @PostMapping ("/xgAGVQueryWlsStatus") + @Log("是否允许进入离开") + @ApiOperation("是否允许进入离开") + public ResponseEntity xgAGVQueryWlsStatus(@RequestBody JSONObject requestParam) { + return new ResponseEntity<>(XGToAcsService.xgAGVQueryWlsStatus(requestParam), HttpStatus.OK); + } +} 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 3f2ff6c..b18fbda 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 @@ -82,6 +82,14 @@ public interface AcsToWmsService { */ HttpResponse feedbackAgv(JSONArray from); + /** + * 动作请求 + * + * @param from + * @return + */ + HttpResponse vehicle(JSONArray from); + /** * 称重确认回传 * diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/XGToAcsService.java b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/XGToAcsService.java new file mode 100644 index 0000000..82c69ed --- /dev/null +++ b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/XGToAcsService.java @@ -0,0 +1,12 @@ +package org.nl.acs.ext.wms.service; + +import net.sf.json.JSONObject; + +public interface XGToAcsService { + /** + * 查询外部互斥组请求历史 + * + * @return Map + */ + public JSONObject xgAGVQueryWlsStatus(JSONObject from); +} 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 9cb6efa..49f2a62 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 @@ -446,6 +446,31 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { return result; } + @Override + public HttpResponse vehicle(JSONArray from) { + String wmsUrl = acsConfigService.findConfigFromCache().get(AcsConfig.WMSURL); + + AddressDto addressDto = addressService.findByCode("vehicle"); + String methods_url = addressDto.getMethods_url(); + String url = wmsUrl + methods_url; + HttpResponse result = null; + log.info("feedbackAgv----请求参数{}", from); + + try { + result = HttpRequest.post(url) + .body(String.valueOf(from)) + .execute(); + System.out.println(result); + log.info("feedbackAgv----返回参数{}", result); + } catch (Exception e) { + String msg = e.getMessage(); + //网络不通 + System.out.println(msg); + log.info("feedbackAgv----异常{}", msg); + } + return result; + } + @Override public HttpResponse feedWeighing(JSONObject from) { String wmsUrl = acsConfigService.findConfigFromCache().get(AcsConfig.WMSURL); diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java index 2f0fc58..33ba4b8 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java @@ -217,14 +217,15 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { errArr.add(json); } } -// if (ObjectUtil.isEmpty(errArr)) { -// resultJson.put("status", 200); -// } else { -// resultJson.put("status", 400); -// } - resultJson.put("status", 200); - resultJson.put("errArr", errArr); - resultJson.put("message", "操作成功"); + if (ObjectUtil.isEmpty(errArr)) { + resultJson.put("status", 200); + resultJson.put("message", "操作成功"); + resultJson.put("errArr", errArr); + } else { + resultJson.put("status", 400); + resultJson.put("message", "操作失败"); + resultJson.put("errArr", errArr); + } resultJson.put("data", new JSONObject()); log.info("createFromWms--------------:输出参数:" + resultJson.toString()); logServer.log("", "createFromWms", "info",tasks.toString(), resultJson.toString(), "200", "", ""); diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/XGToAcsImpl.java b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/XGToAcsImpl.java new file mode 100644 index 0000000..cb30879 --- /dev/null +++ b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/XGToAcsImpl.java @@ -0,0 +1,55 @@ +package org.nl.acs.ext.wms.service.impl; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; +import org.nl.acs.config.server.AcsConfigService; +import org.nl.acs.device.address.service.AddressService; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.ext.wms.service.XGToAcsService; +import org.nl.acs.log.service.LogServer; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +@Slf4j +public class XGToAcsImpl implements XGToAcsService { + @Autowired + AcsConfigService acsConfigService; + + @Autowired + LogServer logServer; + + @Autowired + AddressService addressService; + + @Autowired + AcsToWmsService acsToWmsService; + @Override + public JSONObject xgAGVQueryWlsStatus(JSONObject from) { + JSONArray datas = JSONArray.fromObject(from); + log.info("xgAGVQueryWlsStatus--------------:输入参数" + datas.toString()); + for (int i = 0; i < datas.size(); i++) { + JSONObject data = datas.getJSONObject(i); + String robot_name = data.optString("robot_name"); + String block_group_id = data.optString("block_group_id"); + + JSONObject jo = new JSONObject(); + jo.put("robot_name", robot_name); + jo.put("block_group_id", block_group_id); + //暂时没定先用,之后是请求进入离开区域 + acsToWmsService.feedWeighing(jo); + + } + JSONObject resultJson = new JSONObject(); + resultJson.put("status", HttpStatus.OK); + resultJson.put("message", "操作成功"); + resultJson.put("data", new JSONObject()); + log.info("updateDeviceGoodsFromWms--------------:输出参数" + resultJson.toString()); + return resultJson; + } +} + diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/route/service/impl/RouteLineServiceImpl.java b/hd/nladmin-system/src/main/java/org/nl/acs/route/service/impl/RouteLineServiceImpl.java index 13f702e..eed2e4f 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/route/service/impl/RouteLineServiceImpl.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/route/service/impl/RouteLineServiceImpl.java @@ -260,7 +260,7 @@ public class RouteLineServiceImpl implements RouteLineService, ApplicationAutoIn } } } -// reload(); + reload(); } @Override @@ -425,28 +425,8 @@ public class RouteLineServiceImpl implements RouteLineService, ApplicationAutoIn RoutePlanDto routePlan = (RoutePlanDto) var2.next(); Map map1 = new HashMap(); map1.put("route_plan_id", routePlan.getPlan_uuid()); - //List allRouteLines = Db.use().query(initsql,param); - - /*long l = System.currentTimeMillis(); - List allRouteLines = Db.use((DataSource) SpringContextHolder.getBean("dataSource")).query(initsql,param); - long l1 = System.currentTimeMillis(); - System.out.println("加载时间"+(l1-l));*/ - replaceAccess(routePlan.getPlan_uuid()); this.routePlans.put(routePlan.getPlan_code(), routePlan); - - /*List routeDaoList = allRouteLines.stream().map(entity -> { - RouteLineDto routeLineDto = new RouteLineDto(); - routeLineDto.setDevice_code(entity.get("device_code").toString()); - routeLineDto.setNext_device_code(entity.get("next_device_code").toString()); - routeLineDto.setRoute_plan_id(entity.get("route_plan_id").toString()); - routeLineDto.setType(entity.get("type").toString()); - routeLineDto.setPath(entity.get("path").toString()); - routeLineDto.setWeights(Integer.parseInt(entity.get("weights").toString())); - return routeLineDto; - }).collect(Collectors.toList());*/ - - List routeDaoList = routePlansList.stream().map(entity -> { RouteLineDto routeLineDto = new RouteLineDto(); routeLineDto.setDevice_code(entity.get("device_code").toString()); @@ -459,7 +439,6 @@ public class RouteLineServiceImpl implements RouteLineService, ApplicationAutoIn }).collect(Collectors.toList()); Iterator var = routeDaoList.iterator(); List list = new ArrayList<>(); - while (var.hasNext()) { RouteLineDto routeLine = (RouteLineDto) var.next(); @@ -469,8 +448,6 @@ public class RouteLineServiceImpl implements RouteLineService, ApplicationAutoIn } routeLines.put(routePlan.getPlan_code(), list); } - - } @Override 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..5e56904 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 @@ -14,6 +14,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.impl.AgvServiceImpl; import org.nl.acs.config.AcsConfig; import org.nl.acs.config.server.AcsConfigService; import org.nl.acs.device.service.DeviceAssignedService; @@ -1122,8 +1123,9 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { 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(acsConfigService.findByCode(AcsConfig.AGVTYPE).getValue(), "3")) { + AgvServiceImpl xianGongAgv = SpringContextHolder.getBean(AgvServiceImpl.class); + xianGongAgv.markComplete(entity.getTask_code()); } } }