diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/AgvController.java b/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/AgvController.java deleted file mode 100644 index b2c1d4f..0000000 --- a/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/AgvController.java +++ /dev/null @@ -1,103 +0,0 @@ -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 org.apache.commons.lang3.StringUtils; -import org.nl.acs.agv.server.AgvService; -import org.nl.acs.device.service.DeviceService; -import org.nl.annotation.Log; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import javax.servlet.http.HttpServletRequest; -import java.util.Enumeration; - -@RestController -@RequiredArgsConstructor -@Api(tags = "AGV任务") -@RequestMapping("/api") -@Slf4j -public class AgvController { - @Autowired - AgvService agvService; - @Autowired - DeviceService deviceService; - - - @PostMapping("/agvack/{device}") - @Log("AGV请求离开") - @ApiOperation("AGV请求离开") - //@PreAuthorize("@el.check('routePlan:list')") - public ResponseEntity requestAck(@PathVariable String device) { -// String device= MapUtil.getStr(param,"device"); - return new ResponseEntity<>(agvService.requestAck(device), HttpStatus.OK); - } - - @GetMapping("/autodoor/doors/{device}") - @Log("查询自动门状态") - @ApiOperation("查询自动门状态") - public ResponseEntity queryDoorStatus(HttpServletRequest req) { - String serviceName = req.getRequestURI(); - String param = StringUtils.substringAfterLast(serviceName, "/"); - return new ResponseEntity<>(agvService.queryDoorStatus(param), HttpStatus.OK); - } - - @GetMapping("/autodoor/doors") - @Log("查询自动门状态") - @ApiOperation("查询自动门状态") - public ResponseEntity queryAllDoorStatus(HttpServletRequest req) { - return new ResponseEntity<>(agvService.queryAllDoorStatus(), HttpStatus.OK); - } - - @PostMapping("/autodoor/doors/{device}") - @Log("请求自动门开门关门") - @ApiOperation("请求自动门开门关门") - public ResponseEntity requestOpenOrCloseDoor(@PathVariable String device, HttpServletRequest req) { - Enumeration parameterNames = req.getParameterNames(); - String paramName = (String) parameterNames.nextElement(); - String parameterValue = req.getParameter(paramName); - return new ResponseEntity<>(agvService.requestOpenOrCloseDoor(device, parameterValue), HttpStatus.OK); - - } - - @GetMapping("/agvInst/{instcode}") - @Log("下发agv任务") - @ApiOperation("下发agv任务") - //@PreAuthorize("@el.check('routePlan:list')") - public ResponseEntity sendAgvInst(@PathVariable String instcode) throws Exception { - 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); - } - - @GetMapping("/findAllAgvFromCache") - @Log("查询内存AGV设备状态") - @ApiOperation("查询内存AGV设备状态") - //@PreAuthorize("@el.check('routePlan:list')") - public ResponseEntity findAllAgvFromCache() throws Exception { - return new ResponseEntity<>(agvService.findAllAgvFromCache(), HttpStatus.OK); - } - - - @GetMapping("/queryDeviceStation") - @Log("查询库位同步") - @ApiOperation("查询库位同步") - //@PreAuthorize("@el.check('routePlan:list')") - public ResponseEntity queryDevice() throws Exception { - return new ResponseEntity<>(agvService.queryDeviceStation(), HttpStatus.OK); - } - - -} diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/MagicAgvController.java b/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/MagicAgvController.java new file mode 100644 index 0000000..c874452 --- /dev/null +++ b/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/MagicAgvController.java @@ -0,0 +1,31 @@ +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 org.nl.acs.agv.server.MagicAgvService; +import org.nl.annotation.Log; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@Api(tags = "AGV任务") +@RequestMapping("/api/magic") +@Slf4j +public class MagicAgvController { + private final MagicAgvService magicAgvService; + + @PostMapping("/agvack/{device}") + @Log("AGV请求离开") + @ApiOperation("AGV请求离开") + //@PreAuthorize("@el.check('routePlan:list')") + public ResponseEntity requestAck(@PathVariable String device) { + return new ResponseEntity<>(magicAgvService.requestAck(device), HttpStatus.OK); + } +} diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/NDCAgvController.java b/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/NDCAgvController.java new file mode 100644 index 0000000..39e5192 --- /dev/null +++ b/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/NDCAgvController.java @@ -0,0 +1,4 @@ +package org.nl.acs.agv.rest; + +public class NDCAgvController { +} diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/XianGongAgvController.java b/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/XianGongAgvController.java new file mode 100644 index 0000000..fb4c1b7 --- /dev/null +++ b/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/XianGongAgvController.java @@ -0,0 +1,4 @@ +package org.nl.acs.agv.rest; + +public class XianGongAgvController { +} diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/ZheDaAgvController.java b/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/ZheDaAgvController.java new file mode 100644 index 0000000..e9e2b8f --- /dev/null +++ b/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/rest/ZheDaAgvController.java @@ -0,0 +1,4 @@ +package org.nl.acs.agv.rest; + +public class ZheDaAgvController { +} diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvService.java b/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvService.java index 904240e..7837fd1 100644 --- a/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvService.java +++ b/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvService.java @@ -1,94 +1,14 @@ package org.nl.acs.agv.server; -import cn.hutool.http.HttpResponse; -import com.alibaba.fastjson.JSONObject; import org.nl.acs.agv.server.dto.AgvDto; -import org.nl.acs.instruction.service.dto.Instruction; import java.util.Map; public interface AgvService { - - /** - * 下发agv任务 - * - * @param inst 指令对象 - */ - public HttpResponse sendAgvInstToMagic(Instruction inst) throws Exception; - - public HttpResponse markComplete(String code) throws Exception; - - public HttpResponse sendAgvInstToMagic(String code) throws Exception; - - public void sendAgvInstToNDC(Instruction inst) throws Exception; - - public void sendAgvInstToNDC(String code) throws Exception; - - public HttpResponse queryAgvInstStatus(String instCode); - - public HttpResponse queryMagicAgvDeviceStatus(); - - public HttpResponse queryXZAgvDeviceStatus(); - - public HttpResponse queryXZAgvInstStatus(String instCode); - + //公用 Map findAllAgvFromCache(); - + //公用 void updateAgvFromCache(AgvDto dto); - - /** - * 删除magic任务 - * - * @param instCode - * @return - */ - public HttpResponse deleteAgvInst(String instCode); - - /** - * 删除先知任务 - * - * @param instCode - * @return - */ - public HttpResponse deleteXZAgvInst(String instCode); - - /** - * 删除NDC任务 - * - * @param inst - * @throws Exception - */ - public void deleteAgvInstToNDC(Instruction inst) throws Exception; - - - /** - * 查询Magic AGV任务状态调用 - * - * @param jobno - * @param type - * @param address - * @param action - * @param processingVehicle - * @return - */ - public String process(String jobno, String type, String address, String action, String processingVehicle); - - /** - * Magic AGV 请求离开调用 - * - * @param device - * @return - */ - public String requestAck(String device); - - /** - * 先工agv 等待点请求 - * - * @param - * @return - */ - public String waitPointRequest(String param); - /** * 请求开门、关门 * @@ -97,86 +17,10 @@ public interface AgvService { */ public String requestOpenOrCloseDoor(String device, String param); - /** - * 查询自动门状态 - * - * @param device - * @return - */ - public String queryDoorStatus(String device); + + // public String queryAllDoorStatus(); - /** - * 下发NDC agv单工动作指令 - * - * @param phase - * @param index - * @param result1 - * @param result2 - */ - public byte[] sendAgvOneModeInst(int phase, int index, int result1, int result2); - - /** - * 下发agv单工动作指令 - * - * @param phase - * @param index - */ - public byte[] sendAgvOneModeInst(int phase, int index); - - /** - * 反馈agv单工动作指令 - * - * @param phase - * @param index - */ - public byte[] sendAgvOneModeInst(int phase, int index, int result); - - - /** - * 下发运单序列 - * - * @param inst - * @return - * @throws Exception - */ - public HttpResponse sendOrderSequencesToXZ(Instruction inst) throws Exception; - - public HttpResponse addOrderSequences(Instruction inst) throws Exception; - - /** - * 组织json数据 - * - * @param - * @return - * @throws Exception - */ - public String sendOrderSequencesParam(Instruction inst) throws Exception; - - public JSONObject createOrederData(Instruction inst, String type); - - /** - * magic 全部暂停车辆 - */ - public HttpResponse pause() throws Exception; - - /** - * magic 暂停指定车辆 - */ - public HttpResponse pause(String device_code) throws Exception; - - /** - * magic 全部恢复车辆 - */ - public HttpResponse resume() throws Exception; - - /** - * magic 恢复指定车辆 - */ - public HttpResponse resume(String device_code) throws Exception; - - - String queryDeviceStation(); } diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/MagicAgvService.java b/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/MagicAgvService.java index 1b9f0e2..165359c 100644 --- a/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/MagicAgvService.java +++ b/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/MagicAgvService.java @@ -1,9 +1,98 @@ package org.nl.acs.agv.server; +import cn.hutool.http.HttpResponse; +import org.nl.acs.agv.server.dto.AgvDto; +import org.nl.acs.instruction.service.dto.Instruction; + +import java.util.Map; + /** * @Author: lyd * @Description: * @Date: 2022-08-15 */ public interface MagicAgvService { + + Map findAllAgvFromCache(); + /** + * 查询自动门状态 + * + * @param device + * @return + */ + public String queryDoorStatus(String device); + + /** + * 根据指令号查询AGV指令状态 + * @param instCode + * @return + */ + public HttpResponse queryAgvInstStatus(String instCode); + + /** + * 下发agv任务 + * + * @param inst 指令对象 + */ + public HttpResponse sendAgvInstToMagic(Instruction inst) throws Exception; + + + public HttpResponse sendAgvInstToMagic(String code) throws Exception; + + + //查询AGV状态,故障、充电等 + public HttpResponse queryMagicAgvDeviceStatus(); + + /** + * 删除magic任务 + * + * @param instCode + * @return + */ + public HttpResponse deleteAgvInst(String instCode); + + + /** + * 查询Magic AGV任务状态调用 + * + * @param jobno + * @param type + * @param address + * @param action + * @param processingVehicle + * @return + */ + public String process(String jobno, String type, String address, String action, String processingVehicle); + + + /** + * Magic AGV 请求离开调用 + * + * @param device + * @return + */ + public String requestAck(String device); + + + /** + * magic 全部暂停车辆 + */ + public HttpResponse pause() throws Exception; + + /** + * magic 暂停指定车辆 + */ + public HttpResponse pause(String device_code) throws Exception; + + /** + * magic 全部恢复车辆 + */ + public HttpResponse resume() throws Exception; + + /** + * magic 恢复指定车辆 + */ + public HttpResponse resume(String device_code) throws Exception; + + } diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/NDCAgvService.java b/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/NDCAgvService.java index 4b7ff47..8118215 100644 --- a/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/NDCAgvService.java +++ b/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/NDCAgvService.java @@ -1,9 +1,69 @@ package org.nl.acs.agv.server; +import org.nl.acs.agv.server.dto.AgvDto; +import org.nl.acs.instruction.service.dto.Instruction; + +import java.util.Map; + /** * @Author: lyd * @Description: * @Date: 2022-08-15 */ public interface NDCAgvService { + Map findAllAgvFromCache(); + + /** + * 查询自动门状态 + * + * @param device + * @return + */ + public String queryDoorStatus(String device); + + /** + * 删除NDC任务 + * + * @param inst + * @throws Exception + */ + public void deleteAgvInstToNDC(Instruction inst) throws Exception; + + /** + * 下发NDC agv单工动作指令,反馈信号,如能否进、能否出。 + * 告诉AGV能否进,能否出 + * + * @param phase + * @param index + * @param result1 + * @param result2 + */ + public byte[] sendAgvOneModeInst(int phase, int index, int result1, int result2); + + /** + * 下发任务 + * @param inst + * @throws Exception + */ + public void sendAgvInstToNDC(Instruction inst) throws Exception; + + public void sendAgvInstToNDC(String code) throws Exception; + + /** + * 下发agv单工动作指令 + * + * @param phase + * @param index + */ + public byte[] sendAgvOneModeInst(int phase, int index); + + /** + * 反馈agv单工动作指令 + * AGV调用ACS,告诉AGV是否允许进,允许出等操作. + * + * @param phase + * @param index + */ + public byte[] sendAgvOneModeInst(int phase, int index, int result); + } diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/XianGongAgvService.java b/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/XianGongAgvService.java index f1a84ee..fb91d9c 100644 --- a/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/XianGongAgvService.java +++ b/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/XianGongAgvService.java @@ -1,9 +1,82 @@ package org.nl.acs.agv.server; +import cn.hutool.http.HttpResponse; +import com.alibaba.fastjson.JSONObject; +import org.nl.acs.agv.server.dto.AgvDto; +import org.nl.acs.instruction.service.dto.Instruction; + +import java.util.Map; + /** * @Author: lyd * @Description: * @Date: 2022-08-15 */ public interface XianGongAgvService { + Map findAllAgvFromCache(); + /** + * 查询自动门状态 + * + * @param device + * @return + */ + public String queryDoorStatus(String device); + + /** + * 先工agv 等待点请求 + *AGV->ACS + * @param + * @return + */ + public String waitPointRequest(String param); + + /** + * acs->agv + * 关闭运单系列 + * @param code + * @return + * @throws Exception + */ + public HttpResponse markComplete(String code) throws Exception; + + /** + * 查询AGV状态 + * @return + */ + public HttpResponse queryXZAgvDeviceStatus(); + + public HttpResponse queryXZAgvInstStatus(String instCode); + + /** + * 删除先知任务 + * + * @param instCode + * @return + */ + public HttpResponse deleteXZAgvInst(String instCode); + + + /** + * 下发运单序列 + * + * @param inst + * @return + * @throws Exception + */ + public HttpResponse sendOrderSequencesToXZ(Instruction inst) throws Exception; + + public HttpResponse addOrderSequences(Instruction inst) throws Exception; + + /** + * 组织json数据 + * + * @param + * @return + * @throws Exception + */ + public String sendOrderSequencesParam(Instruction inst) throws Exception; + + + public JSONObject createOrederData(Instruction inst, String type); + } diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java b/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java index fd5a136..48f8502 100644 --- a/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java +++ b/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java @@ -2,8 +2,6 @@ package org.nl.acs.agv.server.impl; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; -import cn.hutool.http.HttpRequest; -import cn.hutool.http.HttpResponse; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; @@ -12,27 +10,17 @@ import org.nl.acs.agv.server.AgvService; import org.nl.acs.agv.server.dto.AgvDto; import org.nl.acs.config.AcsConfig; import org.nl.acs.config.server.AcsConfigService; -import org.nl.acs.device.service.DeviceService; -import org.nl.acs.device.service.impl.DeviceServiceImpl; import org.nl.acs.device_driver.lnsh.lnsh_station.LnshStationDeviceDriver; -import org.nl.acs.device_driver.special_ordinary_site.SpecialOrdinarySiteDeviceDriver; import org.nl.acs.device_driver.standard_autodoor.StandardAutodoorDeviceDriver; -import org.nl.acs.device_driver.standard_inspect_site.StandardInspectSiteDeviceDriver; -import org.nl.acs.device_driver.standard_ordinary_site.StandardOrdinarySiteDeviceDriver; -import org.nl.acs.device_driver.standard_storage.StandardStorageDeviceDriver; import org.nl.acs.ext.erp.service.AcsToErpService; 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.log.service.DeviceExecuteLogService; import org.nl.acs.opc.Device; 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.exception.BadRequestException; -import org.nl.start.auto.run.NDCSocketConnectionAutoRun; -import org.nl.utils.SpringContextHolder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -79,523 +67,6 @@ public class AgvServiceImpl implements AgvService { return nowAsISO; } - /** - * 返回一个点位操作子任务 - * - * @param locationName 点位 - * @param operation 点位操作 - * @param propertiesType 子任务类型 - * @param pro 子任务参数 - * 调用demo:destination("sh15p", "Spin", "2", "3.14") - * demo:destination("cz14", "JackUnload", "3", "") - * @return - */ - public static JSONObject destination(String locationName, String operation, String propertiesType, String pro) { - //新增业务订单 - JSONObject destinationOrder = new JSONObject(); - //目标工作站 - destinationOrder.put("locationName", locationName); - //机器人在工作站要执行的操作 - destinationOrder.put("operation", operation); - if (propertiesType.equals("1")) {//取货前等待、取货后等待 - - //pro 1 进入离开等待 - if ("1".equals(pro)) { - JSONArray properties = new JSONArray(); - JSONObject pro1 = new JSONObject(); - pro1.put("key", "EntryRequired"); - pro1.put("value", "True"); - properties.add(pro1); - JSONObject pro2 = new JSONObject(); - pro2.put("key", "PauseOnStation"); - pro2.put("value", "True"); - properties.add(pro2); - destinationOrder.put("properties", properties); - //进入等待 离开不等待 - } else if ("2".equals(pro)) { - JSONArray properties = new JSONArray(); - JSONObject pro1 = new JSONObject(); - pro1.put("key", "EntryRequired"); - pro1.put("value", "True"); - properties.add(pro1); - JSONObject pro2 = new JSONObject(); - pro2.put("key", "PauseOnStation"); - pro2.put("value", "False"); - properties.add(pro2); - destinationOrder.put("properties", properties); - //进入不等待 离开等待 - } else if ("3".equals(pro)) { - JSONArray properties = new JSONArray(); - JSONObject pro1 = new JSONObject(); - pro1.put("key", "EntryRequired"); - pro1.put("value", "False"); - properties.add(pro1); - JSONObject pro2 = new JSONObject(); - pro2.put("key", "PauseOnStation"); - pro2.put("value", "True"); - properties.add(pro2); - destinationOrder.put("properties", properties); - //不等待 - } else if ("4".equals(pro)){ - JSONArray properties = new JSONArray(); - JSONObject pro1 = new JSONObject(); - pro1.put("key", "EntryRequired"); - pro1.put("value", "False"); - properties.add(pro1); - JSONObject pro2 = new JSONObject(); - pro2.put("key", "PauseOnStation"); - pro2.put("value", "False"); - properties.add(pro2); - destinationOrder.put("properties", properties); - } else if ("5".equals(pro)){ - JSONArray properties = new JSONArray(); - JSONObject pro2 = new JSONObject(); - pro2.put("key", "PauseOnStation"); - pro2.put("value", "True"); - properties.add(pro2); - destinationOrder.put("properties", properties); - } - - } else if (propertiesType.equals("2")) {//Spin转动 - JSONArray properties = new JSONArray(); - JSONObject pro1 = new JSONObject(); - pro1.put("key", "global_spin_angle");//坐标系类型,global_spin_angle为全局坐标系 - pro1.put("value", pro);//弧度值,如3.14 - properties.add(pro1); - JSONObject pro2 = new JSONObject(); - pro2.put("key", "spin_direction");//固定值 - pro2.put("value", "0");//弧度值,如0 - properties.add(pro2); - destinationOrder.put("properties", properties); - } else if (propertiesType.equals("3")) {//JackUnload,Jackload不操作 - JSONArray properties = new JSONArray(); - JSONObject pro1 = new JSONObject(); - pro1.put("key", "recognize");//固定值 - pro1.put("value", "false");//固定值 - properties.add(pro1); - destinationOrder.put("properties", properties); - } else if (propertiesType.equals("4")) { - JSONArray properties = new JSONArray(); - JSONObject pro1 = new JSONObject(); - pro1.put("key", "robot_spin_angle");//坐标系类型,robot_spin_angle为机器人坐标系 - pro1.put("value", pro);//弧度值,如3.14 - properties.add(pro1); - JSONObject pro2 = new JSONObject(); - pro2.put("key", "spin_direction");//固定值 - pro2.put("value", "0");//弧度值,如0 - properties.add(pro2); - destinationOrder.put("properties", properties); - } - return destinationOrder; - } - - /** - * 返回一个点位操作子任务 先知使用 - * - * @param locationName 点位 - * @param operation 点位操作 - * @param propertiesType 子任务类型 - * @param pro 子任务参数 - * 调用demo:destination("sh15p", "Spin", "2", "3.14") - * demo:destination("cz14", "JackUnload", "3", "") - * @return - */ - public static JSONObject destination2(String locationName, String operation, String propertiesType, String pro) { - //新增业务订单 - JSONObject destinationOrder = new JSONObject(); - //目标工作站 - destinationOrder.put("locationName", locationName); - //机器人在工作站要执行的操作 - destinationOrder.put("operation", operation); - if (propertiesType.equals("1")) {//Wait请求是否继续 - JSONArray properties = new JSONArray(); - JSONObject pro2 = new JSONObject(); - pro2.put("key", "device:queryAtExecuted");//固定值 - pro2.put("value", pro + ":wait");//pro为wait请求的标识,一般用点位拼接的字符串 - properties.add(pro2); - destinationOrder.put("properties", properties); - } else if (propertiesType.equals("2")) {//Spin转动 - JSONArray properties = new JSONArray(); - JSONObject pro1 = new JSONObject(); - pro1.put("key", "global_spin_angle");//坐标系类型,global_spin_angle为全局坐标系 - pro1.put("value", pro);//弧度值,如3.14 - properties.add(pro1); - JSONObject pro2 = new JSONObject(); - pro2.put("key", "spin_direction");//固定值 - pro2.put("value", "0");//弧度值,如0 - properties.add(pro2); - destinationOrder.put("properties", properties); - } else if (propertiesType.equals("3")) {//JackUnload,Jackload不操作 - JSONArray properties = new JSONArray(); - JSONObject pro1 = new JSONObject(); - pro1.put("key", "recognize");//固定值 - pro1.put("value", "false");//固定值 - properties.add(pro1); - destinationOrder.put("properties", properties); - } else if (propertiesType.equals("4")) { - JSONArray properties = new JSONArray(); - JSONObject pro1 = new JSONObject(); - pro1.put("key", "robot_spin_angle");//坐标系类型,robot_spin_angle为机器人坐标系 - pro1.put("value", pro);//弧度值,如3.14 - properties.add(pro1); - JSONObject pro2 = new JSONObject(); - pro2.put("key", "spin_direction");//固定值 - pro2.put("value", "0");//弧度值,如0 - properties.add(pro2); - destinationOrder.put("properties", properties); - } else if (propertiesType.equals("5")) {//Wait请求是否继续 - JSONArray properties = new JSONArray(); - JSONObject pro2 = new JSONObject(); - - destinationOrder.put("properties", "[]"); - } - return destinationOrder; - } - - @Override - public HttpResponse sendAgvInstToMagic(Instruction inst) throws Exception { - JSONArray ja = new JSONArray(); - JSONObject orderjo = new JSONObject(); - String instno = inst.getInstruction_code(); - String compound_inst_data = inst.getCompound_inst_data(); - String[] str = null; - List pathlist = null; - - if (StrUtil.equals("2", inst.getInstruction_type()) && !StrUtil.isEmpty(compound_inst_data)) { - str = compound_inst_data.split("->"); - pathlist = Arrays.asList(str); - - for (int i = 0; i < pathlist.size(); i++) { - String device_code = pathlist.get(i); - Device device = deviceAppService.findDeviceByCode(device_code); - if (ObjectUtil.isEmpty(device)) { - throw new BadRequestException("未找到该设备【" + device_code + "】"); - } - if (i == 0) { - ja.add(destination(device_code, "Load", "1", "1")); - } else if (i == pathlist.size() - 1) { - ja.add(destination(device_code, "Unload", "1", "1")); - } else { - ja.add(destination(device_code, "NOP", "1", "5")); - } - - } - - //指定agv车号 暂时不用 - //orderjo.put("intendedVehicle", ""); - //设置任务最终时间 - orderjo.put("deadline", getNextDay(1)); - - orderjo.put("destinations", ja); - - JSONObject prijo = new JSONObject(); - prijo.put("key", "priority"); - prijo.put("value", inst.getPriority()); - - JSONArray prija = new JSONArray(); - prija.add(prijo); - orderjo.put("properties", prija); - - - } else { - - String startAddress = inst.getStart_point_code(); - String nextAddress = inst.getNext_point_code(); - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - Device nextdevice = appService.findDeviceByCode(nextAddress); - Device startdevice = appService.findDeviceByCode(startAddress); - //指定agv车号 暂时不用 - //orderjo.put("intendedVehicle", ""); - //设置任务最终时间 - orderjo.put("deadline", getNextDay(1)); - //拼接起点子任务动作,待完善,动作码需要从数据库取值 - ja.add(destination(startAddress, "Load", "1", "1")); - //拼接终点子任务动作,待完善,动作码需要从数据库取值 - ja.add(destination(nextAddress, "Unload", "1", "1")); - - orderjo.put("destinations", ja); - - JSONObject prijo = new JSONObject(); - prijo.put("key", "priority"); - prijo.put("value", inst.getPriority()); - - JSONArray prija = new JSONArray(); - prija.add(prijo); - orderjo.put("properties", prija); - - } - - 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 + "/v1/transportOrders/" + instno; - - log.info("下发agv指令参数:{}", orderjo.toString()); - - HttpResponse result = null; - try { - result = HttpRequest.post(agvurl) - .body(String.valueOf(orderjo))//表单内容 - .timeout(20000)//超时,毫秒 - .execute(); - } catch (Exception e) { - throw new RuntimeException("下发agv失败!"); - } - return result; - } else { - return null; - } - - - } - - @Override - public HttpResponse markComplete(String code) throws Exception { - - 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/orderSequences/" + code + "/markComplete"; - log.info("关闭agv运单序列请求:{}", agvurl); - - HttpResponse result = HttpRequest.post(agvurl) - //.body(String.valueOf(orderjo))//表单内容 - .timeout(20000)//超时,毫秒 - .execute(); - log.info("关闭agv运单序列请求反馈:{}", result); - - return result; - } else { - return null; - } - - } - - @Override - public HttpResponse sendAgvInstToMagic(String instcode) throws Exception { - InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); - Instruction inst = instructionService.findByCodeFromCache(instcode); - HttpResponse result = this.sendAgvInstToMagic(inst); - return result; - } - - @Override - public void sendAgvInstToNDC(Instruction inst) { - if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.FORKAGV).toString(), "1")) { - String instcode = inst.getInstruction_code(); - int type = Integer.parseInt(inst.getInstruction_type()); - int priority = Integer.parseInt(inst.getPriority()) + 128; - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); - int startAddress = deviceService.queryAddressBydeviceCode(inst.getStart_point_code()); - int nextAddress = deviceService.queryAddressBydeviceCode(inst.getNext_point_code()); - - byte ikeyhigh = (byte) IntToHexHigh(Integer.parseInt(instcode)); - byte ikeylow = (byte) IntToHexLow(Integer.parseInt(instcode)); - byte typehigh = (byte) IntToHexHigh(type); - byte typelow = (byte) IntToHexLow(type); - byte qhdhigh = (byte) IntToHexHigh(startAddress); - byte qhdlow = (byte) IntToHexLow(startAddress); - byte fhdhigh = (byte) IntToHexHigh(nextAddress); - byte fhdlow = (byte) IntToHexLow(nextAddress); - byte prioritylow = (byte) IntToHexLow(priority); - - String str = "十进制下发:"; - String str1 = "十六进制下发:"; - str += "ikey:" + (Integer.parseInt(instcode)); - str1 += "ikey:" + hexToString(ikeyhigh & 0xFF) + hexToString(ikeylow & 0xFF); - - str += "/type:" + (type); - str1 += "/type:" + hexToString(typehigh & 0xFF) + hexToString(typelow & 0xFF); - - str += "/qhd:" + (startAddress); - str1 += "/qhd:" + hexToString(qhdhigh & 0xFF) + hexToString(qhdlow & 0xFF); - str += "/fhd:" + (nextAddress); - str1 += "/fhd:" + hexToString(fhdhigh & 0xFF) + hexToString(fhdlow & 0xFF); - - str += "/priority:" + (priority); - str1 += "/priority:" + hexToString(prioritylow & 0xFF); - - System.out.println(str); - System.out.println(str1); - - byte[] b = new byte[]{(byte) 0X87, (byte) 0XCD, - (byte) 0X00, (byte) 0X08, - (byte) 0X00, (byte) 0X12, - (byte) 0X00, (byte) 0X01, - (byte) 0X00, (byte) 0X71, - (byte) 0X00, (byte) 0X0E, - (byte) 0X01, prioritylow, - (byte) 0X00, (byte) 0X01, - (byte) ikeyhigh, (byte) ikeylow, - (byte) ikeyhigh, (byte) ikeylow, - (byte) typehigh, (byte) typelow, - (byte) qhdhigh, (byte) qhdlow, - (byte) fhdhigh, (byte) fhdlow - }; - log.info("下发AGV作业指令--{}", str1); - - NDCSocketConnectionAutoRun.write(b); - System.out.println("下发agv指令数据:" + Bytes2HexString(b)); - } - } - - @Override - public void sendAgvInstToNDC(String instcode) throws Exception { - InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); - Instruction inst = instructionService.findByCodeFromCache(instcode); - sendAgvInstToNDC(inst); - } - - - @Override - public HttpResponse queryAgvInstStatus(String instCode) { - - 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 + "/v1/transportOrders/" + instCode; - - HttpResponse result = HttpRequest.get(agvurl) - .timeout(20000)//超时,毫秒 - .execute(); - System.out.println("查询agv指令数据:" + result.body()); - - return result; - } else { - - return null; - } - } - - @Override - public HttpResponse queryMagicAgvDeviceStatus() { - 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 + "/v1/vehicles"; - - HttpResponse result = HttpRequest.get(agvurl) - .timeout(20000)//超时,毫秒 - .execute(); - System.out.println("查询agv状态数据:" + result.body()); - if (result.getStatus() == 200) { - JSONArray ja = (JSONArray)JSONArray.parse(result.body()); - for (int i = 0; i < ja.size(); i++) { - JSONObject jo = (JSONObject) ja.get(i); - String name = jo.getString("name"); - String state = jo.getString("state"); - String energyLevel = jo.getString("energyLevel"); - String transportOrder = jo.getString("transportOrder"); - String positionAngle = jo.getString("positionAngle"); - String positionX = jo.getString("positionX"); - String positionY = jo.getString("positionY"); - AgvDto dto = new AgvDto(); - dto.setName(name); - dto.setEnergyLevel(energyLevel); - dto.setState(state); - dto.setPositionAngle(positionAngle); - dto.setPositionX(positionX); - dto.setPositionY(positionY); - dto.setTransportOrder(transportOrder); - - if (AGVDeviceStatus.containsKey(name)) { - AGVDeviceStatus.remove(name); - AGVDeviceStatus.put(name, dto); - } else { - AGVDeviceStatus.put(name, dto); - } - } - } - return result; - } else { - return null; - } - } - - @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"; - - HttpResponse result = HttpRequest.get(agvurl1) - .timeout(20000)//超时,毫秒 - .execute(); - - - HttpResponse result2 = HttpRequest.get(agvurl2) - .timeout(20000)//超时,毫秒 - .execute(); - - System.out.println("查询agv状态数据:" + result.body()); - if (result.getStatus() == 200) { - JSONArray ja = (JSONArray)JSONArray.parse(result.body()); - - for (int i = 0; i < ja.size(); i++) { - JSONObject jo = (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)JSONObject.parse(result2.body()); - JSONObject item = (JSONObject) detailjo.get(name); - String x = item.getString("x"); - String y = item.getString("y"); - String angle = item.getString("angle"); - AgvDto dto = new AgvDto(); - dto.setName(name); - dto.setEnergyLevel(energyLevel); - dto.setState(state); - dto.setTransportOrder(transportOrder); - dto.setPositionAngle(angle); - dto.setPositionX(x); - dto.setPositionY(y); - if (AGVDeviceStatus.containsKey(name)) { - AGVDeviceStatus.remove(name); - AGVDeviceStatus.put(name, dto); - } else { - AGVDeviceStatus.put(name, dto); - } - } - } - return result; - } else { - return null; - } - } - - - - @Override - public HttpResponse queryXZAgvInstStatus(String instCode) { - - 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; - - HttpResponse result = HttpRequest.get(agvurl) - .timeout(20000)//超时,毫秒 - .execute(); - System.out.println("查询agv指令数据:" + result.body()); - - return result; - } else { - - return null; - } - - - } @Override public Map findAllAgvFromCache() { @@ -610,505 +81,14 @@ public class AgvServiceImpl implements AgvService { AGVDeviceStatus.put(dto.getName(), dto); } - @Override - public HttpResponse deleteAgvInst(String instCode) { - - 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 + "/v1/transportOrders/" + instCode + "/withdrawal"; - log.info("删除agv指令请求agvurl:{}", agvurl); - - HttpResponse result = null; - try { - result = HttpRequest.post(agvurl) - .timeout(20000)//超时,毫秒 - .execute(); - log.info("删除agv指令请求反馈:{}", result); - } catch (Exception e) { - throw new RuntimeException("下发agv失败!"); - } - - return result; - - } else { - - return null; - } - - } - - @Override - public HttpResponse deleteXZAgvInst(String instCode) { - - 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 + "/withdrawal"; - log.info("删除agv指令请求agvurl:{}", agvurl); - HttpResponse result = HttpRequest.post(agvurl) - .timeout(20000)//超时,毫秒 - .execute(); - log.info("删除agv指令请求反馈:{}", result); - - return result; - - } else { - - return null; - } - - } - - @Override - public void deleteAgvInstToNDC(Instruction inst) throws Exception { - if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.FORKAGV).toString(), "1")) { - int index = Integer.parseInt(inst.getAgv_jobno()); - - byte indexhigh = (byte) IntToHexHigh(index); - byte indexlow = (byte) IntToHexLow(index); - - String str = "十进制下发:"; - String str1 = "十六进制下发:"; - str += "index:" + index; - str1 += "ikey:" + hexToString(indexhigh & 0xFF) + hexToString(indexlow & 0xFF); - System.out.println(str); - System.out.println(str1); - - byte[] b = new byte[]{(byte) 0X87, (byte) 0XCD, - (byte) 0X00, (byte) 0X08, - (byte) 0X00, (byte) 0X06, - (byte) 0X00, (byte) 0X01, - (byte) 0X00, (byte) 0X6E, - (byte) 0X00, (byte) 0X02, - (byte) indexhigh, (byte) indexlow, - }; - log.info("下发删除AGV指令--{}", Bytes2HexString(b)); - - NDCSocketConnectionAutoRun.write(b); - System.out.println("下发删除agv指令数据:" + Bytes2HexString(b)); - } - } - - //1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 - @Override - public synchronized String process(String jobno, String type, String address, String action, String processingVehicle) { - log.info("查询到AGV请求参数,jobno:{},address:{}", jobno + ",address:" + address + ",type:" + type + ",action:" + action); - boolean is_feedback = false; - String str = ""; - String backaddress = address; - if (address.indexOf(".") > 0) { - str = address.substring(address.indexOf("."), address.length()); - address = address.substring(0, address.indexOf(".")); - } else if (address.indexOf("-") > 0) { - address = address.substring(0, address.indexOf("-")); - } - InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); - Instruction inst = instructionService.findByCodeFromCache(jobno); - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - Device addressdevice = appService.findDeviceByCode(address); - StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; - StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; - SpecialOrdinarySiteDeviceDriver specialOrdinarySiteDeviceDriver; - LnshStationDeviceDriver lnshStationDeviceDriver; - //请求进入 - if ("onEntry".equals(type)) { - if (addressdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { - standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) addressdevice.getDeviceDriver(); - //请求取货 - if ("Load".equals(action)) { - if (standardInspectSiteDeviceDriver.getMode() == 2 && standardInspectSiteDeviceDriver.getMove() > 0) { - inst.setExecute_status("1"); - is_feedback = true; - } - //请求放货 - } else if ("Unload".equals(action)) { - if (standardInspectSiteDeviceDriver.getMode() == 2 && standardInspectSiteDeviceDriver.getMove() == 0) { - inst.setExecute_status("3"); - is_feedback = true; - } - } - } - //晟华工位模板 - if (addressdevice.getDeviceDriver() instanceof LnshStationDeviceDriver) { - lnshStationDeviceDriver = (LnshStationDeviceDriver) addressdevice.getDeviceDriver(); - //请求取货 - if ("Load".equals(action)) { - if (lnshStationDeviceDriver.getMode() == 2 && lnshStationDeviceDriver.getMove() > 0) { - inst.setExecute_status("1"); - lnshStationDeviceDriver.setFlag(1); - is_feedback = true; - } - //请求放货 - } else if ("Unload".equals(action)) { - if (lnshStationDeviceDriver.getMode() == 2 && lnshStationDeviceDriver.getMove() == 0) { - inst.setExecute_status("3"); - lnshStationDeviceDriver.setFlag(3); - is_feedback = true; - } - } - } - if (addressdevice.getDeviceDriver() instanceof SpecialOrdinarySiteDeviceDriver) { - specialOrdinarySiteDeviceDriver = (SpecialOrdinarySiteDeviceDriver) addressdevice.getDeviceDriver(); - //请求取货 - if ("Load".equals(action)) { - if (addressdevice.getHas_goods() > 0) { - inst.setExecute_status("1"); - is_feedback = true; - } - //请求放货 - } else if ("Unload".equals(action)) { - if (addressdevice.getHas_goods() == 0) { - inst.setExecute_status("3"); - is_feedback = true; - } - } - } - if (addressdevice.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) addressdevice.getDeviceDriver(); - //请求取货 - if ("Load".equals(action)) { - if (addressdevice.getHas_goods() > 0) { - inst.setExecute_status("1"); - is_feedback = true; - } - //请求放货 - } else if ("Unload".equals(action)) { - if (addressdevice.getHas_goods() == 0) { - inst.setExecute_status("3"); - is_feedback = true; - } - } - } - if (addressdevice.getDeviceDriver() instanceof StandardStorageDeviceDriver) { - //请求取货 - if ("Load".equals(action)) { - inst.setExecute_status("1"); - is_feedback = true; - //请求放货 - } else if ("Unload".equals(action)) { - inst.setExecute_status("3"); - is_feedback = true; - } - } - //取放货完成 - } else if ("onStation".equals(type)) { - System.out.println("取放货完成"); - if (addressdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { - standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) addressdevice.getDeviceDriver(); - //取货完成 - if ("Load".equals(action)) { - if (standardInspectSiteDeviceDriver.getMode() == 2 && standardInspectSiteDeviceDriver.getMove() == 0) { - inst.setExecute_device_code(processingVehicle); - inst.setExecute_status("2"); - is_feedback = true; - } - //放货完成 - } else if ("Unload".equals(action)) { - if (standardInspectSiteDeviceDriver.getMode() == 2 && standardInspectSiteDeviceDriver.getMove() > 0) { - inst.setExecute_device_code(address); - inst.setExecute_status("4"); - is_feedback = true; - } - } - } - //晟华工位模板 - if (addressdevice.getDeviceDriver() instanceof LnshStationDeviceDriver) { - lnshStationDeviceDriver = (LnshStationDeviceDriver) addressdevice.getDeviceDriver(); - //取货完成 - if ("Load".equals(action)) { - if (lnshStationDeviceDriver.getMode() == 2 && lnshStationDeviceDriver.getMove() == 0) { - inst.setExecute_device_code(processingVehicle); - inst.setExecute_status("2"); - lnshStationDeviceDriver.setFlag(2); - is_feedback = true; - } - //放货完成 - } else if ("Unload".equals(action)) { - if (lnshStationDeviceDriver.getMode() == 2 && lnshStationDeviceDriver.getMove() > 0) { - inst.setExecute_device_code(address); - inst.setExecute_status("4"); - lnshStationDeviceDriver.setFlag(4); - is_feedback = true; - } - } - } - if (addressdevice.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) addressdevice.getDeviceDriver(); - //取货完成 - if ("Load".equals(action)) { - inst.setExecute_device_code(processingVehicle); - inst.setExecute_status("2"); - is_feedback = true; - //放货完成 - } else if ("Unload".equals(action)) { - inst.setExecute_device_code(address); - inst.setExecute_status("4"); - is_feedback = true; - } - - } - if (addressdevice.getDeviceDriver() instanceof SpecialOrdinarySiteDeviceDriver) { - specialOrdinarySiteDeviceDriver = (SpecialOrdinarySiteDeviceDriver) addressdevice.getDeviceDriver(); - //取货完成 - if ("Load".equals(action)) { - inst.setExecute_device_code(processingVehicle); - inst.setExecute_status("2"); - is_feedback = true; - //放货完成 - } else if ("Unload".equals(action)) { - inst.setExecute_device_code(processingVehicle); - inst.setExecute_status("4"); - is_feedback = true; - } - } - if (addressdevice.getDeviceDriver() instanceof StandardStorageDeviceDriver) { - //取货完成 - if ("Load".equals(action)) { - inst.setExecute_device_code(processingVehicle); - inst.setExecute_status("2"); - is_feedback = true; - //放货完成 - } else if ("Unload".equals(action)) { - inst.setExecute_device_code(processingVehicle); - inst.setExecute_status("4"); - is_feedback = true; - } - } - } - - JSONObject requestjo = new JSONObject(); - JSONArray ja = new JSONArray(); - if (is_feedback) { - String param = ""; - JSONObject jo = new JSONObject(); - if (str.length() > 0) { - backaddress = backaddress + str; - } - if ("onEntry".equals(type)) { - param = "EntryPermitted-" + backaddress + action; - } else if ("onStation".equals(type)) { - param = "ContinueOnStation-" + backaddress + action; - } - - jo.put("key", param); - jo.put("value", "False"); - ja.add(jo); - requestjo.put("properties", ja); - log.info("反馈AGV请求数据:{}", requestjo); - System.out.println("back agv:" + requestjo); - - String agvurl = acsConfigService.findConfigFromCache().get(AcsConfig.AGVURL); - String agvport = acsConfigService.findConfigFromCache().get(AcsConfig.AGVPORT); - - agvurl = agvurl + ":" + agvport + "/v1/transportOrders/" + jobno + "/interact"; - - HttpResponse result = HttpRequest.post(agvurl) - .body(String.valueOf(requestjo)) - .timeout(20000)//超时,毫秒 - .execute(); - } - is_feedback = false; - - return requestjo.toString(); - - } - - @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; - } - boolean is_feedback = false; - - Device device = deviceAppService.findDeviceByCode(newaddress); - StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; - StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; - 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); - } - } - 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; - } - } - 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(); - } - - @Override - public String requestAck(String address) { - log.info("AGV请求离开参数:{}", address); - boolean flag = false; - - if (address.indexOf(".") > 0) { - address = address.substring(0, address.indexOf(".")); - } - if (address.indexOf("-") > 0) { - address = address.substring(0, address.indexOf("-")); - } - InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); - - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - Device addressdevice = appService.findDeviceByCode(address); - StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; - StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; - StandardStorageDeviceDriver standardStorageDeviceDriver; - LnshStationDeviceDriver lnshStationDeviceDriver; - - //mes = AgvClientXZ.mes(zlbh, device, type); - //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 - if ((addressdevice.getDeviceDriver() instanceof StandardStorageDeviceDriver)) { - flag = true; - } - - if (addressdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { - standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) addressdevice.getDeviceDriver(); - flag = true; - log.info("agvstatus:" + standardInspectSiteDeviceDriver.getFlag() + ""); - //取货完成离开 - if (standardInspectSiteDeviceDriver.getFlag() == 2) { - if (standardInspectSiteDeviceDriver.getMove() == 0) { - flag = true; - standardInspectSiteDeviceDriver.setFlag(5); - } - } - //放货完成离开 - if (standardInspectSiteDeviceDriver.getFlag() == 4) { - if (standardInspectSiteDeviceDriver.getMove() == 1) { - flag = true; - standardInspectSiteDeviceDriver.setFlag(6); - } - } - } - - if (addressdevice.getDeviceDriver() instanceof LnshStationDeviceDriver) { - lnshStationDeviceDriver = (LnshStationDeviceDriver) addressdevice.getDeviceDriver(); - flag = true; - log.info("agvstatus:" + lnshStationDeviceDriver.getFlag() + ""); - //取货完成离开 - if (lnshStationDeviceDriver.getFlag() == 2) { - if (lnshStationDeviceDriver.getMove() == 0) { - flag = true; - lnshStationDeviceDriver.setFlag(5); - } - } - //放货完成离开 - if (lnshStationDeviceDriver.getFlag() == 4) { - if (lnshStationDeviceDriver.getMove() == 1) { - flag = true; - lnshStationDeviceDriver.setFlag(6); - } - } - } - - if (addressdevice.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) addressdevice.getDeviceDriver(); - flag = true; - log.info("agvstatus:" + standardOrdinarySiteDeviceDriver.getFlag() + ""); - - //取货完成离开 - if (standardOrdinarySiteDeviceDriver.getFlag() == 2) { - flag = true; - standardOrdinarySiteDeviceDriver.setFlag(5); - } - //放货完成离开 - if (standardOrdinarySiteDeviceDriver.getFlag() == 4) { - flag = true; - standardOrdinarySiteDeviceDriver.setFlag(6); - } - } - - if (flag) { - log.info("AGV请求离开,反馈成功:{}", address); - System.out.println("AGV请求离开,反馈成功 " + address); - return "OK"; - } else { - log.info("AGV请求离开,反馈失败{}", address); - System.out.println("AGV请求离开,反馈失败 " + address); - throw new RuntimeException("AGV请求离开,反馈失败 " + address); - } - } @Override public String requestOpenOrCloseDoor(String device_code, String param) { @@ -1153,57 +133,6 @@ public class AgvServiceImpl implements AgvService { return null; } - @Override - public String queryDoorStatus(String device) { - log.info("AGV查询自动门状态,参数:{}", device); - int type = Integer.parseInt(acsConfigService.findConfigFromCache().get(AcsConfig.BUSINESSTYPE)); - switch (type) { - case 4: - if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.HASOTHERSYSTEM).toString(), "1")) { - String result = acsToWmsService.queryDoorsStatus().body(); - JSONArray ja = JSONArray.parseArray(result); - log.info("AGV查询自动门状态,反馈:{}", ja.toString()); - return ja.toString(); - } - return null; - default: - if (StrUtil.equals("doors", device)) { - List list = deviceAppService.findDevice(DeviceType.autodoor); - JSONArray ja = new JSONArray(); - for (int i = 0; i < list.size(); i++) { - Device doordevice = deviceAppService.findDeviceByCode(list.get(i).getDevice_code()); - if (ObjectUtil.isEmpty(doordevice)) { - throw new BadRequestException("未找到对应设备"); - } - String mes = null; - StandardAutodoorDeviceDriver autodoor; - if (doordevice.getDeviceDriver() instanceof StandardAutodoorDeviceDriver) { - autodoor = (StandardAutodoorDeviceDriver) doordevice.getDeviceDriver(); - mes = autodoor.getStatus(); - } - JSONObject jo = JSONObject.parseObject(mes); - ja.add(jo); - } - log.info("AGV查询自动门状态,反馈:{}", ja.toString()); - return ja.toString(); - - } else { - Device doordevice = deviceAppService.findDeviceByCode(device); - if (ObjectUtil.isEmpty(doordevice)) { - throw new BadRequestException("未找到对应设备"); - } - String mes = null; - StandardAutodoorDeviceDriver autodoor; - if (doordevice.getDeviceDriver() instanceof StandardAutodoorDeviceDriver) { - autodoor = (StandardAutodoorDeviceDriver) doordevice.getDeviceDriver(); - mes = autodoor.getStatus(); - } - JSONObject jo = JSONObject.parseObject(mes); - log.info("AGV查询自动门状态,反馈:{}", jo.toString()); - return jo.toString(); - } - } - } @Override public String queryAllDoorStatus() { @@ -1229,421 +158,23 @@ public class AgvServiceImpl implements AgvService { } - @Override - public byte[] sendAgvOneModeInst(int phase, int index, int result1, int result2) { - if (phase < 0 || index < 0) - return null; - byte indexhigh = (byte) IntToHexHigh(index); - byte indexlow = (byte) IntToHexLow(index); - byte phasehigh = (byte) IntToHexHigh(phase); - byte phaselow = (byte) IntToHexLow(phase); - byte resulthigh1 = (byte) IntToHexHigh(result1); - byte resultlow1 = (byte) IntToHexLow(result1); - byte resulthigh2 = (byte) IntToHexHigh(result2); - byte resultlow2 = (byte) IntToHexLow(result2); - - byte[] b = new byte[]{(byte) 0X87, (byte) 0XCD, - (byte) 0X00, (byte) 0X08, - (byte) 0X00, (byte) 0X0D, - (byte) 0X00, (byte) 0X01, - (byte) 0X00, (byte) 0X6D, - (byte) 0X00, (byte) 0X08, - (byte) indexhigh, (byte) indexlow, - (byte) 0X01, (byte) 0X12, - (byte) phasehigh, (byte) phaselow, - (byte) resulthigh1, (byte) resultlow1, - (byte) resulthigh2, (byte) resultlow2 - }; - - log.info("反馈agv动作数据--index:" + hexToString(indexhigh & 0xFF) + hexToString(indexlow & 0xFF) + ",phase:" + hexToString(phasehigh & 0xFF) + hexToString(phaselow & 0xFF)); - //87CD 0008 000C 0001 006D 0008 0000 0114 000E 0000 - //87CD 0008 000C 0001 006D 0008 0003 0114 008F 0000 - System.out.println("反馈agv动作数据:" + Bytes2HexString(b)); - return b; - } - - @Override - public byte[] sendAgvOneModeInst(int phase, int index) { - return new byte[0]; - } - - @Override - public byte[] sendAgvOneModeInst(int phase, int index, int result) { - if (phase < 0 || index < 0) - return null; - byte indexhigh = (byte) IntToHexHigh(index); - byte indexlow = (byte) IntToHexLow(index); - byte phasehigh = (byte) IntToHexHigh(phase); - byte phaselow = (byte) IntToHexLow(phase); - byte resulthigh = (byte) IntToHexHigh(result); - byte resultlow = (byte) IntToHexLow(result); - - int type = Integer.parseInt(acsConfigService.findConfigFromCache().get(AcsConfig.BUSINESSTYPE)); - byte[] b = new byte[]{}; - switch (type) { - case 0: - b = new byte[]{(byte) 0X87, (byte) 0XCD, - (byte) 0X00, (byte) 0X08, - (byte) 0X00, (byte) 0X0A, - (byte) 0X00, (byte) 0X01, - (byte) 0X00, (byte) 0X6D, - (byte) 0X00, (byte) 0X06, - (byte) indexhigh, (byte) indexlow, - (byte) 0X01, (byte) 0X12, - (byte) phasehigh, (byte) phaselow - }; - break; - case 1: - b = new byte[]{(byte) 0X87, (byte) 0XCD, - (byte) 0X00, (byte) 0X08, - (byte) 0X00, (byte) 0X0D, - (byte) 0X00, (byte) 0X01, - (byte) 0X00, (byte) 0X6D, - (byte) 0X00, (byte) 0X08, - (byte) indexhigh, (byte) indexlow, - (byte) 0X01, (byte) 0X12, - (byte) phasehigh, (byte) phaselow, - (byte) resulthigh, (byte) resultlow - }; - break; - case 2: - b = new byte[]{(byte) 0X87, (byte) 0XCD, - (byte) 0X00, (byte) 0X08, - (byte) 0X00, (byte) 0X0A, - (byte) 0X00, (byte) 0X01, - (byte) 0X00, (byte) 0X6D, - (byte) 0X00, (byte) 0X06, - (byte) indexhigh, (byte) indexlow, - (byte) 0X01, (byte) 0X12, - (byte) phasehigh, (byte) phaselow - }; - break; - case 5: - b = new byte[]{(byte) 0X87, (byte) 0XCD, - (byte) 0X00, (byte) 0X08, - (byte) 0X00, (byte) 0X0A, - (byte) 0X00, (byte) 0X01, - (byte) 0X00, (byte) 0X6D, - (byte) 0X00, (byte) 0X06, - (byte) indexhigh, (byte) indexlow, - (byte) 0X01, (byte) 0X12, - (byte) phasehigh, (byte) phaselow - }; - break; - case 7: - b = new byte[]{(byte) 0X87, (byte) 0XCD, - (byte) 0X00, (byte) 0X08, - (byte) 0X00, (byte) 0X0A, - (byte) 0X00, (byte) 0X01, - (byte) 0X00, (byte) 0X6D, - (byte) 0X00, (byte) 0X06, - (byte) indexhigh, (byte) indexlow, - (byte) 0X01, (byte) 0X12, - (byte) phasehigh, (byte) phaselow - }; - break; - } - log.info("反馈agv动作数据--index:" + hexToString(indexhigh & 0xFF) + hexToString(indexlow & 0xFF) + ",phase:" + hexToString(phasehigh & 0xFF) + hexToString(phaselow & 0xFF)); - - System.out.println("反馈agv动作数据:" + Bytes2HexString(b)); - return b; - } - - @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); - - log.info("任务号:{},指令号{},下发agv订单序列参数:{}", inst.getTask_code(), inst.getInstruction_code(), jo.toString()); - - 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/orderSequences/" + inst.getTask_code(); - - HttpResponse result = HttpRequest.post(agvurl) - .body(String.valueOf(jo))//表单内容 - .timeout(20000)//超时,毫秒 - .execute(); - log.info(agvurl); - log.info("任务号:{},指令号{},状态{},下发agv订单序列反馈:{}", inst.getTask_code(), inst.getInstruction_code(), result.getStatus(), result.body()); - - return result; - } else { - return null; - } - } - - @Override - public HttpResponse addOrderSequences(Instruction inst) throws Exception { - JSONObject orderjo = createOrederData(inst, "1"); - log.info("指令号:{},追加agv订单序列参数:{}", inst.getInstruction_code(), orderjo.toString()); - - 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/" + inst.getInstruction_code(); - - HttpResponse result = HttpRequest.post(agvurl) - .body(String.valueOf(orderjo))//表单内容 - .timeout(20000)//超时,毫秒 - .execute(); - log.info(agvurl); - log.info("任务号:{},指令号{},状态{},追加agv订单序列参数:{}", inst.getTask_code(), inst.getInstruction_code(), result.getStatus(), result.body()); - - return result; - } else { - return null; - } - } - - @Override - public String sendOrderSequencesParam(Instruction inst) throws Exception { - JSONObject jo = new JSONObject(); - jo.put("intendedVehicle", ""); - jo.put("category", "Park"); - jo.put("failureFatal", true); - jo.put("complete", false); - JSONArray transports = new JSONArray(); - JSONObject orderjo = createOrederData(inst, "0"); - JSONObject order = new JSONObject(); - orderjo.put("order", order); - orderjo.put("name", inst.getInstruction_code()); - transports.add(orderjo); - jo.put("transports", transports); - return jo.toString(); - } - - @Override - public JSONObject createOrederData(Instruction inst, String inst_type) { - String inst_code = inst.getInstruction_code(); - String task_code = inst.getTask_code(); - String compound_inst_data = inst.getCompound_inst_data(); - String[] str = null; - List pathlist = null; - if (!StrUtil.isEmpty(compound_inst_data)) { - str = compound_inst_data.split("->"); - pathlist = Arrays.asList(str); - } - JSONArray ja = new JSONArray(); - JSONObject orderjo = new JSONObject(); - - //1表示追加任务,需将task_code赋值给wrappingSequence - if (StrUtil.equals("1", inst_type)) { - orderjo.put("wrappingSequence", task_code); - } - String instno = inst.getInstruction_code(); - //指定agv车号 暂时不用 - //orderjo.put("intendedVehicle", ""); - //设置任务最终时间 - orderjo.put("deadline", getNextDay(1)); - orderjo.put("category", ""); - //拼接起点子任务动作,待完善,动作码需要从数据库取值 - int type = Integer.parseInt(acsConfigService.findConfigFromCache().get(AcsConfig.BUSINESSTYPE)); - - switch (type) { - case 3: - break; - case 4: - break; - case 6: - String startAddress = inst.getStart_device_code(); - String nextAddress = inst.getNext_device_code(); - Device startdevice = deviceAppService.findDeviceByCode(startAddress); - Device nextdevice = deviceAppService.findDeviceByCode(nextAddress); - StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; - //起点 - if (startdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { - - ja.add(destination2(startAddress + "IN", "Wait", "1", startAddress + "IN" - + "-" + inst_code + "-" + "01")); - ja.add(destination2(startAddress, "Load", "3", startAddress - + "-" + inst_code + "-" + "02")); - ja.add(destination2(startAddress + "OUT", "Wait", "1", startAddress + "OUT" - + "-" + inst_code + "-" + "05")); - - } else { - ja.add(destination2(nextAddress, "Wait", "1", startAddress - + "-" + inst_code + "-" + "01")); - ja.add(destination2(startAddress, "Load", "3", startAddress - + "-" + inst_code + "-" + "01")); - } - - if (nextdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { - ja.add(destination2(nextAddress + "IN", "Wait", "1", nextAddress + "IN" - + "-" + inst_code + "-" + "03")); - ja.add(destination2(nextAddress, "ForkLoad", "3", nextAddress - + "-" + inst_code + "-" + "04")); - ja.add(destination2(nextAddress + "OUT", "Wait", "1", nextAddress + "OUT" - + "-" + inst_code + "-" + "06")); - } else { - ja.add(destination2(nextAddress, "Wait", "1", nextAddress - + "-" + inst_code + "-" + "01")); - ja.add(destination2(nextAddress, "ForkLoad", "3", nextAddress - + "-" + inst_code + "-" + "01")); - } - break; - } - - orderjo.put("destinations", ja); - JSONObject prijo = new JSONObject(); - prijo.put("key", "duration"); - prijo.put("value", "101"); - - JSONArray prija = new JSONArray(); - prija.add(prijo); - orderjo.put("properties", prija); - - return orderjo; - } - - @Override - public HttpResponse pause() throws Exception { - - 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 + "/v1/vehicles/pause"; - log.info("暂停所有agv请求:{}", agvurl); - - HttpResponse result = HttpRequest.post(agvurl) - .timeout(20000)//超时,毫秒 - .execute(); - log.info("暂停所有agv请求反馈:{}", result); - String type = ""; - if (result.getStatus() == 200) { - type = "info"; - } else { - type = "error"; - } -// logServer.log("", "pause", type, "", result.body(), String.valueOf(result.getStatus()), agvurl, ""); - return result; - } else { - return null; - } - } - - @Override - public HttpResponse pause(String device_code) throws Exception { - 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 + "/v1/vehicles/" + device_code + "/pause"; - log.info("暂停{} agv请求:{}", device_code, agvurl); - - HttpResponse result = HttpRequest.post(agvurl) - .timeout(20000)//超时,毫秒 - .execute(); - log.info("暂停{} agv请求反馈:{}", device_code, result); - String type = ""; - return result; - } else { - return null; - } - } - - @Override - public HttpResponse resume() throws Exception { - - 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 + "/v1/vehicles/resume"; - log.info("恢复所有agv请求:{}", agvurl); - - HttpResponse result = HttpRequest.post(agvurl) - .timeout(20000)//超时,毫秒 - .execute(); - log.info("恢复所有agv请求反馈:{}", result); - String type = ""; - if (result.getStatus() == 200) { - type = "info"; - } else { - type = "error"; - } -// logServer.log("", "resume", type, "", result.body(), String.valueOf(result.getStatus()), agvurl, ""); - return result; - } else { - return null; - } - } - - @Override - public HttpResponse resume(String device_code) throws Exception { - 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 + "/v1/vehicles/" + device_code + "/resume"; - log.info("恢复{} agv请求:{}", device_code, agvurl); - - HttpResponse result = HttpRequest.post(agvurl) - .timeout(20000)//超时,毫秒 - .execute(); - log.info("恢复{} agv请求反馈:{}", device_code, result); - - return result; - } else { - return null; - } - } - - @Override - public String queryDeviceStation() { - return null; - } - - String hexToString(int i) { - return (i < 16 ? "0" + Integer.toHexString(i) : Integer.toHexString(i)).toUpperCase(); - } - public static int IntToHexHigh(int b) { - int big = (b & 0xFF00) >> 8; - return big; - } - - public static int IntToHexLow(int b) { - int little = b & 0xFF; - return little; - } - public static String Bytes2HexString(byte[] b) { - String ret = ""; - for (int i = 0; i < b.length; i++) { - String hex = Integer.toHexString(b[i] & 0xFF); - if (hex.length() == 1) { - hex = '0' + hex; - } - ret += hex.toUpperCase(); - } - return ret; - } + + + + + + + + + + + public static void main(String[] args) { String address = "L1-01-01"; diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/MagicAgvServiceImpl.java b/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/MagicAgvServiceImpl.java new file mode 100644 index 0000000..0ca215a --- /dev/null +++ b/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/MagicAgvServiceImpl.java @@ -0,0 +1,924 @@ +package org.nl.acs.agv.server.impl; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.agv.server.MagicAgvService; +import org.nl.acs.agv.server.dto.AgvDto; +import org.nl.acs.config.AcsConfig; +import org.nl.acs.config.server.AcsConfigService; +import org.nl.acs.device_driver.lnsh.lnsh_station.LnshStationDeviceDriver; +import org.nl.acs.device_driver.special_ordinary_site.SpecialOrdinarySiteDeviceDriver; +import org.nl.acs.device_driver.standard_autodoor.StandardAutodoorDeviceDriver; +import org.nl.acs.device_driver.standard_inspect_site.StandardInspectSiteDeviceDriver; +import org.nl.acs.device_driver.standard_ordinary_site.StandardOrdinarySiteDeviceDriver; +import org.nl.acs.device_driver.standard_storage.StandardStorageDeviceDriver; +import org.nl.acs.ext.erp.service.AcsToErpService; +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.log.service.DeviceExecuteLogService; +import org.nl.acs.opc.Device; +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.exception.BadRequestException; +import org.nl.utils.SpringContextHolder; +import org.slf4j.MDC; +import org.springframework.stereotype.Service; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.*; + +@Slf4j +@Service +@RequiredArgsConstructor +public class MagicAgvServiceImpl implements MagicAgvService { + private final DeviceAppService deviceAppService; + private final TaskService taskService; + private final InstructionService instructionService; + private final AcsConfigService acsConfigService; + private final AcsToErpService acsToErpService; + private final AcsToWmsService acsToWmsService; + + private final DeviceExecuteLogService logServer; + + Map AGVDeviceStatus = new HashMap(); + + private String log_file_type = "log_file_type"; + private String log_type = "agv接口日志"; + + /** + * 获得之后num个天的时间 + * + * @param num + * @return + */ + public static String getNextDay(int num) { + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.DAY_OF_MONTH, num); + Date date = calendar.getTime(); + TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai"); + DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + df.setTimeZone(tz); + String nowAsISO = df.format(date); + return nowAsISO; + } + + @Override + public HttpResponse sendAgvInstToMagic(String instcode) throws Exception { + InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); + Instruction inst = instructionService.findByCodeFromCache(instcode); + HttpResponse result = this.sendAgvInstToMagic(inst); + return result; + } + + @Override + public HttpResponse queryAgvInstStatus(String instCode) { + try { + MDC.put(log_file_type, log_type); + 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 + "/v1/transportOrders/" + instCode; + + HttpResponse result = HttpRequest.get(agvurl) + .timeout(20000)//超时,毫秒 + .execute(); + System.out.println("查询agv指令数据:" + result.body()); + + return result; + } else { + return null; + } + } finally { + MDC.remove(log_file_type); + } + + } + + @Override + public HttpResponse sendAgvInstToMagic(Instruction inst) throws Exception { + try { + MDC.put(log_file_type, log_type); + + JSONArray ja = new JSONArray(); + JSONObject orderjo = new JSONObject(); + String instno = inst.getInstruction_code(); + String compound_inst_data = inst.getCompound_inst_data(); + String[] str = null; + List pathlist = null; + + if (StrUtil.equals("2", inst.getInstruction_type()) && !StrUtil.isEmpty(compound_inst_data)) { + str = compound_inst_data.split("->"); + pathlist = Arrays.asList(str); + + for (int i = 0; i < pathlist.size(); i++) { + String device_code = pathlist.get(i); + Device device = deviceAppService.findDeviceByCode(device_code); + if (ObjectUtil.isEmpty(device)) { + throw new BadRequestException("未找到该设备【" + device_code + "】"); + } + if (i == 0) { + ja.add(destination(device_code, "Load", "1", "1")); + } else if (i == pathlist.size() - 1) { + ja.add(destination(device_code, "Unload", "1", "1")); + } else { + ja.add(destination(device_code, "NOP", "1", "5")); + } + + } + + //指定agv车号 暂时不用 + //orderjo.put("intendedVehicle", ""); + //设置任务最终时间 + orderjo.put("deadline", getNextDay(1)); + + orderjo.put("destinations", ja); + + JSONObject prijo = new JSONObject(); + prijo.put("key", "priority"); + prijo.put("value", inst.getPriority()); + + JSONArray prija = new JSONArray(); + prija.add(prijo); + orderjo.put("properties", prija); + + + } else { + + String startAddress = inst.getStart_point_code(); + String nextAddress = inst.getNext_point_code(); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + Device nextdevice = appService.findDeviceByCode(nextAddress); + Device startdevice = appService.findDeviceByCode(startAddress); + //指定agv车号 暂时不用 + //orderjo.put("intendedVehicle", ""); + //设置任务最终时间 + orderjo.put("deadline", getNextDay(1)); + //拼接起点子任务动作,待完善,动作码需要从数据库取值 + ja.add(destination(startAddress, "Load", "1", "1")); + //拼接终点子任务动作,待完善,动作码需要从数据库取值 + ja.add(destination(nextAddress, "Unload", "1", "1")); + + orderjo.put("destinations", ja); + + JSONObject prijo = new JSONObject(); + prijo.put("key", "priority"); + prijo.put("value", inst.getPriority()); + + JSONArray prija = new JSONArray(); + prija.add(prijo); + orderjo.put("properties", prija); + + } + + 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 + "/v1/transportOrders/" + instno; + + log.info("下发agv指令参数:{}", orderjo.toString()); + + HttpResponse result = null; + try { + result = HttpRequest.post(agvurl) + .body(String.valueOf(orderjo))//表单内容 + .timeout(20000)//超时,毫秒 + .execute(); + } catch (Exception e) { + throw new RuntimeException("下发agv失败!"); + } + return result; + } else { + return null; + } + + } finally { + MDC.remove(log_file_type); + } + + } + + /** + * 返回一个点位操作子任务 + * + * @param locationName 点位 + * @param operation 点位操作 + * @param propertiesType 子任务类型 + * @param pro 子任务参数 + * 调用demo:destination("sh15p", "Spin", "2", "3.14") + * demo:destination("cz14", "JackUnload", "3", "") + * @return + */ + public static JSONObject destination(String locationName, String operation, String propertiesType, String pro) { + //新增业务订单 + JSONObject destinationOrder = new JSONObject(); + //目标工作站 + destinationOrder.put("locationName", locationName); + //机器人在工作站要执行的操作 + destinationOrder.put("operation", operation); + if (propertiesType.equals("1")) {//取货前等待、取货后等待 + + //pro 1 进入离开等待 + if ("1".equals(pro)) { + JSONArray properties = new JSONArray(); + JSONObject pro1 = new JSONObject(); + pro1.put("key", "EntryRequired"); + pro1.put("value", "True"); + properties.add(pro1); + JSONObject pro2 = new JSONObject(); + pro2.put("key", "PauseOnStation"); + pro2.put("value", "True"); + properties.add(pro2); + destinationOrder.put("properties", properties); + //进入等待 离开不等待 + } else if ("2".equals(pro)) { + JSONArray properties = new JSONArray(); + JSONObject pro1 = new JSONObject(); + pro1.put("key", "EntryRequired"); + pro1.put("value", "True"); + properties.add(pro1); + JSONObject pro2 = new JSONObject(); + pro2.put("key", "PauseOnStation"); + pro2.put("value", "False"); + properties.add(pro2); + destinationOrder.put("properties", properties); + //进入不等待 离开等待 + } else if ("3".equals(pro)) { + JSONArray properties = new JSONArray(); + JSONObject pro1 = new JSONObject(); + pro1.put("key", "EntryRequired"); + pro1.put("value", "False"); + properties.add(pro1); + JSONObject pro2 = new JSONObject(); + pro2.put("key", "PauseOnStation"); + pro2.put("value", "True"); + properties.add(pro2); + destinationOrder.put("properties", properties); + //不等待 + } else if ("4".equals(pro)) { + JSONArray properties = new JSONArray(); + JSONObject pro1 = new JSONObject(); + pro1.put("key", "EntryRequired"); + pro1.put("value", "False"); + properties.add(pro1); + JSONObject pro2 = new JSONObject(); + pro2.put("key", "PauseOnStation"); + pro2.put("value", "False"); + properties.add(pro2); + destinationOrder.put("properties", properties); + } else if ("5".equals(pro)) { + JSONArray properties = new JSONArray(); + JSONObject pro2 = new JSONObject(); + pro2.put("key", "PauseOnStation"); + pro2.put("value", "True"); + properties.add(pro2); + destinationOrder.put("properties", properties); + } + + } else if (propertiesType.equals("2")) {//Spin转动 + JSONArray properties = new JSONArray(); + JSONObject pro1 = new JSONObject(); + pro1.put("key", "global_spin_angle");//坐标系类型,global_spin_angle为全局坐标系 + pro1.put("value", pro);//弧度值,如3.14 + properties.add(pro1); + JSONObject pro2 = new JSONObject(); + pro2.put("key", "spin_direction");//固定值 + pro2.put("value", "0");//弧度值,如0 + properties.add(pro2); + destinationOrder.put("properties", properties); + } else if (propertiesType.equals("3")) {//JackUnload,Jackload不操作 + JSONArray properties = new JSONArray(); + JSONObject pro1 = new JSONObject(); + pro1.put("key", "recognize");//固定值 + pro1.put("value", "false");//固定值 + properties.add(pro1); + destinationOrder.put("properties", properties); + } else if (propertiesType.equals("4")) { + JSONArray properties = new JSONArray(); + JSONObject pro1 = new JSONObject(); + pro1.put("key", "robot_spin_angle");//坐标系类型,robot_spin_angle为机器人坐标系 + pro1.put("value", pro);//弧度值,如3.14 + properties.add(pro1); + JSONObject pro2 = new JSONObject(); + pro2.put("key", "spin_direction");//固定值 + pro2.put("value", "0");//弧度值,如0 + properties.add(pro2); + destinationOrder.put("properties", properties); + } + return destinationOrder; + } + + + @Override + public HttpResponse queryMagicAgvDeviceStatus() { + try { + MDC.put(log_file_type, log_type); + 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 + "/v1/vehicles"; + HttpResponse result = HttpRequest.get(agvurl) + .timeout(20000)//超时,毫秒 + .execute(); + log.info("查询agv状态数据:{}", result.body()); + if (result.getStatus() == 200) { + JSONArray ja = (JSONArray) JSONArray.parse(result.body()); + for (int i = 0; i < ja.size(); i++) { + JSONObject jo = (JSONObject) ja.get(i); + String name = jo.getString("name"); + String state = jo.getString("state"); + String energyLevel = jo.getString("energyLevel"); + String transportOrder = jo.getString("transportOrder"); + String positionAngle = jo.getString("positionAngle"); + String positionX = jo.getString("positionX"); + String positionY = jo.getString("positionY"); + AgvDto dto = new AgvDto(); + dto.setName(name); + dto.setEnergyLevel(energyLevel); + dto.setState(state); + dto.setPositionAngle(positionAngle); + dto.setPositionX(positionX); + dto.setPositionY(positionY); + dto.setTransportOrder(transportOrder); + + if (AGVDeviceStatus.containsKey(name)) { + AGVDeviceStatus.remove(name); + AGVDeviceStatus.put(name, dto); + } else { + AGVDeviceStatus.put(name, dto); + } + } + } + return result; + } else { + return null; + } + } finally { + MDC.remove(log_file_type); + } + + + } + + @Override + public HttpResponse deleteAgvInst(String instCode) { + try { + MDC.put(log_file_type, log_type); + 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 + "/v1/transportOrders/" + instCode + "/withdrawal"; + log.info("删除agv指令请求agvurl:{}", agvurl); + + HttpResponse result = null; + try { + result = HttpRequest.post(agvurl) + .timeout(20000)//超时,毫秒 + .execute(); + log.info("删除agv指令请求反馈:{}", result); + } catch (Exception e) { + throw new RuntimeException("下发agv失败!"); + } + return result; + } else { + return null; + } + } finally { + MDC.remove(log_file_type); + } + + } + + //1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + @Override + public synchronized String process(String jobno, String type, String address, String action, String processingVehicle) { + + try { + MDC.put(log_file_type, log_type); + log.info("查询到AGV请求参数,jobno:{},address:{}", jobno + ",address:" + address + ",type:" + type + ",action:" + action); + boolean is_feedback = false; + String str = ""; + String backaddress = address; + if (address.indexOf(".") > 0) { + str = address.substring(address.indexOf("."), address.length()); + address = address.substring(0, address.indexOf(".")); + } else if (address.indexOf("-") > 0) { + address = address.substring(0, address.indexOf("-")); + } + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + Instruction inst = instructionService.findByCodeFromCache(jobno); + + + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + Device addressdevice = appService.findDeviceByCode(address); + StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; + StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; + SpecialOrdinarySiteDeviceDriver specialOrdinarySiteDeviceDriver; + LnshStationDeviceDriver lnshStationDeviceDriver; + + //请求进入 + if ("onEntry".equals(type)) { + + if (addressdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { + standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) addressdevice.getDeviceDriver(); + //请求取货 + if ("Load".equals(action)) { + if (standardInspectSiteDeviceDriver.getMode() == 2 && standardInspectSiteDeviceDriver.getMove() > 0) { + inst.setExecute_status("1"); + is_feedback = true; + } + //请求放货 + } else if ("Unload".equals(action)) { + if (standardInspectSiteDeviceDriver.getMode() == 2 && standardInspectSiteDeviceDriver.getMove() == 0) { + inst.setExecute_status("3"); + is_feedback = true; + } + } + } + //晟华工位模板 + if (addressdevice.getDeviceDriver() instanceof LnshStationDeviceDriver) { + lnshStationDeviceDriver = (LnshStationDeviceDriver) addressdevice.getDeviceDriver(); + //请求取货 + if ("Load".equals(action)) { + if (lnshStationDeviceDriver.getMode() == 2 && lnshStationDeviceDriver.getMove() > 0) { + inst.setExecute_status("1"); + lnshStationDeviceDriver.setFlag(1); + is_feedback = true; + } + //请求放货 + } else if ("Unload".equals(action)) { + if (lnshStationDeviceDriver.getMode() == 2 && lnshStationDeviceDriver.getMove() == 0) { + inst.setExecute_status("3"); + lnshStationDeviceDriver.setFlag(3); + is_feedback = true; + } + } + } + if (addressdevice.getDeviceDriver() instanceof SpecialOrdinarySiteDeviceDriver) { + specialOrdinarySiteDeviceDriver = (SpecialOrdinarySiteDeviceDriver) addressdevice.getDeviceDriver(); + //请求取货 + if ("Load".equals(action)) { + if (addressdevice.getHas_goods() > 0) { + inst.setExecute_status("1"); + is_feedback = true; + } + //请求放货 + } else if ("Unload".equals(action)) { + if (addressdevice.getHas_goods() == 0) { + inst.setExecute_status("3"); + is_feedback = true; + } + } + + } + if (addressdevice.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { + standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) addressdevice.getDeviceDriver(); + //请求取货 + if ("Load".equals(action)) { + if (addressdevice.getHas_goods() > 0) { + inst.setExecute_status("1"); + is_feedback = true; + } + //请求放货 + } else if ("Unload".equals(action)) { + if (addressdevice.getHas_goods() == 0) { + inst.setExecute_status("3"); + is_feedback = true; + } + } + } + + if (addressdevice.getDeviceDriver() instanceof StandardStorageDeviceDriver) { + //请求取货 + if ("Load".equals(action)) { + inst.setExecute_status("1"); + is_feedback = true; + //请求放货 + } else if ("Unload".equals(action)) { + inst.setExecute_status("3"); + is_feedback = true; + } + } + + //取放货完成 + } else if ("onStation".equals(type)) { + System.out.println("取放货完成"); + if (addressdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { + standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) addressdevice.getDeviceDriver(); + //取货完成 + if ("Load".equals(action)) { + if (standardInspectSiteDeviceDriver.getMode() == 2 && standardInspectSiteDeviceDriver.getMove() == 0) { + inst.setExecute_device_code(processingVehicle); + inst.setExecute_status("2"); + is_feedback = true; + } + //放货完成 + } else if ("Unload".equals(action)) { + if (standardInspectSiteDeviceDriver.getMode() == 2 && standardInspectSiteDeviceDriver.getMove() > 0) { + inst.setExecute_device_code(address); + inst.setExecute_status("4"); + is_feedback = true; + } + } + } + //晟华工位模板 + if (addressdevice.getDeviceDriver() instanceof LnshStationDeviceDriver) { + lnshStationDeviceDriver = (LnshStationDeviceDriver) addressdevice.getDeviceDriver(); + //取货完成 + if ("Load".equals(action)) { + if (lnshStationDeviceDriver.getMode() == 2 && lnshStationDeviceDriver.getMove() == 0) { + inst.setExecute_device_code(processingVehicle); + inst.setExecute_status("2"); + lnshStationDeviceDriver.setFlag(2); + is_feedback = true; + } + //放货完成 + } else if ("Unload".equals(action)) { + if (lnshStationDeviceDriver.getMode() == 2 && lnshStationDeviceDriver.getMove() > 0) { + inst.setExecute_device_code(address); + inst.setExecute_status("4"); + lnshStationDeviceDriver.setFlag(4); + is_feedback = true; + } + } + } + if (addressdevice.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { + standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) addressdevice.getDeviceDriver(); + //取货完成 + if ("Load".equals(action)) { + inst.setExecute_device_code(processingVehicle); + inst.setExecute_status("2"); + is_feedback = true; + //放货完成 + } else if ("Unload".equals(action)) { + inst.setExecute_device_code(address); + inst.setExecute_status("4"); + is_feedback = true; + } + + } + if (addressdevice.getDeviceDriver() instanceof SpecialOrdinarySiteDeviceDriver) { + specialOrdinarySiteDeviceDriver = (SpecialOrdinarySiteDeviceDriver) addressdevice.getDeviceDriver(); + //取货完成 + if ("Load".equals(action)) { + inst.setExecute_device_code(processingVehicle); + inst.setExecute_status("2"); + is_feedback = true; + //放货完成 + } else if ("Unload".equals(action)) { + inst.setExecute_device_code(processingVehicle); + inst.setExecute_status("4"); + is_feedback = true; + } + } + if (addressdevice.getDeviceDriver() instanceof StandardStorageDeviceDriver) { + //取货完成 + if ("Load".equals(action)) { + inst.setExecute_device_code(processingVehicle); + inst.setExecute_status("2"); + is_feedback = true; + //放货完成 + } else if ("Unload".equals(action)) { + inst.setExecute_device_code(processingVehicle); + inst.setExecute_status("4"); + is_feedback = true; + } + } + } + + JSONObject requestjo = new JSONObject(); + JSONArray ja = new JSONArray(); + if (is_feedback) { + String param = ""; + JSONObject jo = new JSONObject(); + if (str.length() > 0) { + backaddress = backaddress + str; + } + if ("onEntry".equals(type)) { + param = "EntryPermitted-" + backaddress + action; + } else if ("onStation".equals(type)) { + param = "ContinueOnStation-" + backaddress + action; + } + + jo.put("key", param); + jo.put("value", "False"); + ja.add(jo); + requestjo.put("properties", ja); + log.info("反馈AGV请求数据:{}", requestjo); + System.out.println("back agv:" + requestjo); + + String agvurl = acsConfigService.findConfigFromCache().get(AcsConfig.AGVURL); + String agvport = acsConfigService.findConfigFromCache().get(AcsConfig.AGVPORT); + + agvurl = agvurl + ":" + agvport + "/v1/transportOrders/" + jobno + "/interact"; + + HttpResponse result = HttpRequest.post(agvurl) + .body(String.valueOf(requestjo)) + .timeout(20000)//超时,毫秒 + .execute(); + } + is_feedback = false; + + return requestjo.toString(); + } finally { + MDC.remove(log_file_type); + } + + } + + + @Override + public String requestAck(String address) { + try { + MDC.put(log_file_type, log_type); + log.info("AGV请求离开参数:{}", address); + boolean flag = false; + + if (address.indexOf(".") > 0) { + address = address.substring(0, address.indexOf(".")); + } + if (address.indexOf("-") > 0) { + address = address.substring(0, address.indexOf("-")); + } + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + Device addressdevice = appService.findDeviceByCode(address); + StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; + StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; + StandardStorageDeviceDriver standardStorageDeviceDriver; + LnshStationDeviceDriver lnshStationDeviceDriver; + + //mes = AgvClientXZ.mes(zlbh, device, type); + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + if ((addressdevice.getDeviceDriver() instanceof StandardStorageDeviceDriver)) { + flag = true; + } + + if (addressdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { + standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) addressdevice.getDeviceDriver(); + flag = true; + log.info("agvstatus:" + standardInspectSiteDeviceDriver.getFlag() + ""); + //取货完成离开 + if (standardInspectSiteDeviceDriver.getFlag() == 2) { + if (standardInspectSiteDeviceDriver.getMove() == 0) { + flag = true; + standardInspectSiteDeviceDriver.setFlag(5); + } + } + //放货完成离开 + if (standardInspectSiteDeviceDriver.getFlag() == 4) { + if (standardInspectSiteDeviceDriver.getMove() == 1) { + flag = true; + standardInspectSiteDeviceDriver.setFlag(6); + } + } + } + + if (addressdevice.getDeviceDriver() instanceof LnshStationDeviceDriver) { + lnshStationDeviceDriver = (LnshStationDeviceDriver) addressdevice.getDeviceDriver(); + flag = true; + log.info("agvstatus:" + lnshStationDeviceDriver.getFlag() + ""); + //取货完成离开 + if (lnshStationDeviceDriver.getFlag() == 2) { + if (lnshStationDeviceDriver.getMove() == 0) { + flag = true; + lnshStationDeviceDriver.setFlag(5); + } + } + //放货完成离开 + if (lnshStationDeviceDriver.getFlag() == 4) { + if (lnshStationDeviceDriver.getMove() == 1) { + flag = true; + lnshStationDeviceDriver.setFlag(6); + } + } + } + + if (addressdevice.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { + standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) addressdevice.getDeviceDriver(); + flag = true; + log.info("agvstatus:" + standardOrdinarySiteDeviceDriver.getFlag() + ""); + + //取货完成离开 + if (standardOrdinarySiteDeviceDriver.getFlag() == 2) { + flag = true; + standardOrdinarySiteDeviceDriver.setFlag(5); + } + //放货完成离开 + if (standardOrdinarySiteDeviceDriver.getFlag() == 4) { + flag = true; + standardOrdinarySiteDeviceDriver.setFlag(6); + } + } + + if (flag) { + log.info("AGV请求离开,反馈成功:{}", address); + System.out.println("AGV请求离开,反馈成功 " + address); + return "OK"; + } else { + log.info("AGV请求离开,反馈失败{}", address); + System.out.println("AGV请求离开,反馈失败 " + address); + throw new RuntimeException("AGV请求离开,反馈失败 " + address); + } + } finally { + MDC.remove(log_file_type); + } + + } + + @Override + public HttpResponse pause() throws Exception { + try { + MDC.put(log_file_type, log_type); + 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 + "/v1/vehicles/pause"; + log.info("暂停所有agv请求:{}", agvurl); + + HttpResponse result = HttpRequest.post(agvurl) + .timeout(20000)//超时,毫秒 + .execute(); + log.info("暂停所有agv请求反馈:{}", result); + String type = ""; + if (result.getStatus() == 200) { + type = "info"; + } else { + type = "error"; + } + return result; + } else { + return null; + } + + } finally { + MDC.remove(log_file_type); + } + + } + + + @Override + public HttpResponse pause(String device_code) throws Exception { + try { + MDC.put(log_file_type, log_type); + 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 + "/v1/vehicles/" + device_code + "/pause"; + log.info("暂停{} agv请求:{}", device_code, agvurl); + + HttpResponse result = HttpRequest.post(agvurl) + .timeout(20000)//超时,毫秒 + .execute(); + log.info("暂停{} agv请求反馈:{}", device_code, result); + String type = ""; + return result; + } else { + return null; + } + } finally { + MDC.remove(log_file_type); + } + + } + + + @Override + public HttpResponse resume() throws Exception { + try { + MDC.put(log_file_type, log_type); + 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 + "/v1/vehicles/resume"; + log.info("恢复所有agv请求:{}", agvurl); + + HttpResponse result = HttpRequest.post(agvurl) + .timeout(20000)//超时,毫秒 + .execute(); + log.info("恢复所有agv请求反馈:{}", result); + String type = ""; + if (result.getStatus() == 200) { + type = "info"; + } else { + type = "error"; + } + return result; + } else { + return null; + } + + } finally { + MDC.remove(log_file_type); + } + + + } + + @Override + public HttpResponse resume(String device_code) throws Exception { + try { + MDC.put(log_file_type, log_type); + 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 + "/v1/vehicles/" + device_code + "/resume"; + log.info("恢复{} agv请求:{}", device_code, agvurl); + + HttpResponse result = HttpRequest.post(agvurl) + .timeout(20000)//超时,毫秒 + .execute(); + log.info("恢复{} agv请求反馈:{}", device_code, result); + + return result; + } else { + return null; + } + } finally { + MDC.remove(log_file_type); + } + + + } + + + @Override + public String queryDoorStatus(String device) { + try { + MDC.put(log_file_type, log_type); + log.info("AGV查询自动门状态,参数:{}", device); + int type = Integer.parseInt(acsConfigService.findConfigFromCache().get(AcsConfig.BUSINESSTYPE)); + switch (type) { + case 4: + if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.HASOTHERSYSTEM).toString(), "1")) { + String result = acsToWmsService.queryDoorsStatus().body(); + JSONArray ja = JSONArray.parseArray(result); + log.info("AGV查询自动门状态,反馈:{}", ja.toString()); + return ja.toString(); + } + return null; + default: + if (StrUtil.equals("doors", device)) { + List list = deviceAppService.findDevice(DeviceType.autodoor); + JSONArray ja = new JSONArray(); + for (int i = 0; i < list.size(); i++) { + Device doordevice = deviceAppService.findDeviceByCode(list.get(i).getDevice_code()); + if (ObjectUtil.isEmpty(doordevice)) { + throw new BadRequestException("未找到对应设备"); + } + String mes = null; + StandardAutodoorDeviceDriver autodoor; + if (doordevice.getDeviceDriver() instanceof StandardAutodoorDeviceDriver) { + autodoor = (StandardAutodoorDeviceDriver) doordevice.getDeviceDriver(); + mes = autodoor.getStatus(); + } + JSONObject jo = JSONObject.parseObject(mes); + ja.add(jo); + } + log.info("AGV查询自动门状态,反馈:{}", ja.toString()); + return ja.toString(); + + } else { + Device doordevice = deviceAppService.findDeviceByCode(device); + if (ObjectUtil.isEmpty(doordevice)) { + throw new BadRequestException("未找到对应设备"); + } + String mes = null; + StandardAutodoorDeviceDriver autodoor; + if (doordevice.getDeviceDriver() instanceof StandardAutodoorDeviceDriver) { + autodoor = (StandardAutodoorDeviceDriver) doordevice.getDeviceDriver(); + mes = autodoor.getStatus(); + } + JSONObject jo = JSONObject.parseObject(mes); + log.info("AGV查询自动门状态,反馈:{}", jo.toString()); + return jo.toString(); + } + } + } finally { + MDC.remove(log_file_type); + } + } + + @Override + public Map findAllAgvFromCache() { + return AGVDeviceStatus; + } +} diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/NDCAgvServiceImpl.java b/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/NDCAgvServiceImpl.java new file mode 100644 index 0000000..832379a --- /dev/null +++ b/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/NDCAgvServiceImpl.java @@ -0,0 +1,391 @@ +package org.nl.acs.agv.server.impl; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.agv.server.NDCAgvService; +import org.nl.acs.agv.server.dto.AgvDto; +import org.nl.acs.config.AcsConfig; +import org.nl.acs.config.server.AcsConfigService; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device.service.impl.DeviceServiceImpl; +import org.nl.acs.device_driver.standard_autodoor.StandardAutodoorDeviceDriver; +import org.nl.acs.ext.erp.service.AcsToErpService; +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.log.service.DeviceExecuteLogService; +import org.nl.acs.opc.Device; +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.exception.BadRequestException; +import org.nl.start.auto.run.NDCSocketConnectionAutoRun; +import org.nl.utils.SpringContextHolder; +import org.slf4j.MDC; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Slf4j +@Service +@RequiredArgsConstructor +public class NDCAgvServiceImpl implements NDCAgvService { + + private final DeviceAppService deviceAppService; + private final TaskService taskService; + private final InstructionService instructionService; + private final AcsConfigService acsConfigService; + private final AcsToErpService acsToErpService; + private final AcsToWmsService acsToWmsService; + + private final DeviceExecuteLogService logServer; + + Map AGVDeviceStatus = new HashMap(); + + private String log_file_type = "log_file_type"; + private String log_type = "agv接口日志"; + + @Override + public void deleteAgvInstToNDC(Instruction inst) throws Exception { + try { + MDC.put(log_file_type, log_type); + if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.FORKAGV).toString(), "1")) { + int index = Integer.parseInt(inst.getAgv_jobno()); + + byte indexhigh = (byte) IntToHexHigh(index); + byte indexlow = (byte) IntToHexLow(index); + + String str = "十进制下发:"; + String str1 = "十六进制下发:"; + str += "index:" + index; + str1 += "ikey:" + hexToString(indexhigh & 0xFF) + hexToString(indexlow & 0xFF); + System.out.println(str); + System.out.println(str1); + + byte[] b = new byte[]{(byte) 0X87, (byte) 0XCD, + (byte) 0X00, (byte) 0X08, + (byte) 0X00, (byte) 0X06, + (byte) 0X00, (byte) 0X01, + (byte) 0X00, (byte) 0X6E, + (byte) 0X00, (byte) 0X02, + (byte) indexhigh, (byte) indexlow, + }; + log.info("下发删除AGV指令--{}", Bytes2HexString(b)); + + NDCSocketConnectionAutoRun.write(b); + System.out.println("下发删除agv指令数据:" + Bytes2HexString(b)); + } + } finally { + MDC.remove(log_file_type); + } + + } + + @Override + public byte[] sendAgvOneModeInst(int phase, int index, int result1, int result2) { + try { + MDC.put(log_file_type, log_type); + if (phase < 0 || index < 0) + return null; + byte indexhigh = (byte) IntToHexHigh(index); + byte indexlow = (byte) IntToHexLow(index); + byte phasehigh = (byte) IntToHexHigh(phase); + byte phaselow = (byte) IntToHexLow(phase); + byte resulthigh1 = (byte) IntToHexHigh(result1); + byte resultlow1 = (byte) IntToHexLow(result1); + byte resulthigh2 = (byte) IntToHexHigh(result2); + byte resultlow2 = (byte) IntToHexLow(result2); + + byte[] b = new byte[]{(byte) 0X87, (byte) 0XCD, + (byte) 0X00, (byte) 0X08, + (byte) 0X00, (byte) 0X0D, + (byte) 0X00, (byte) 0X01, + (byte) 0X00, (byte) 0X6D, + (byte) 0X00, (byte) 0X08, + (byte) indexhigh, (byte) indexlow, + (byte) 0X01, (byte) 0X12, + (byte) phasehigh, (byte) phaselow, + (byte) resulthigh1, (byte) resultlow1, + (byte) resulthigh2, (byte) resultlow2 + }; + + log.info("反馈agv动作数据--index:" + hexToString(indexhigh & 0xFF) + hexToString(indexlow & 0xFF) + ",phase:" + hexToString(phasehigh & 0xFF) + hexToString(phaselow & 0xFF)); + //87CD 0008 000C 0001 006D 0008 0000 0114 000E 0000 + //87CD 0008 000C 0001 006D 0008 0003 0114 008F 0000 + System.out.println("反馈agv动作数据:" + Bytes2HexString(b)); + return b; + } finally { + MDC.remove(log_file_type); + } + + + } + + + @Override + public void sendAgvInstToNDC(Instruction inst) { + try { + MDC.put(log_file_type, log_type); + if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.FORKAGV).toString(), "1")) { + String instcode = inst.getInstruction_code(); + int type = Integer.parseInt(inst.getInstruction_type()); + int priority = Integer.parseInt(inst.getPriority()) + 128; + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); + int startAddress = deviceService.queryAddressBydeviceCode(inst.getStart_point_code()); + int nextAddress = deviceService.queryAddressBydeviceCode(inst.getNext_point_code()); + + byte ikeyhigh = (byte) IntToHexHigh(Integer.parseInt(instcode)); + byte ikeylow = (byte) IntToHexLow(Integer.parseInt(instcode)); + byte typehigh = (byte) IntToHexHigh(type); + byte typelow = (byte) IntToHexLow(type); + byte qhdhigh = (byte) IntToHexHigh(startAddress); + byte qhdlow = (byte) IntToHexLow(startAddress); + byte fhdhigh = (byte) IntToHexHigh(nextAddress); + byte fhdlow = (byte) IntToHexLow(nextAddress); + byte prioritylow = (byte) IntToHexLow(priority); + + String str = "十进制下发:"; + String str1 = "十六进制下发:"; + str += "ikey:" + (Integer.parseInt(instcode)); + str1 += "ikey:" + hexToString(ikeyhigh & 0xFF) + hexToString(ikeylow & 0xFF); + + str += "/type:" + (type); + str1 += "/type:" + hexToString(typehigh & 0xFF) + hexToString(typelow & 0xFF); + + str += "/qhd:" + (startAddress); + str1 += "/qhd:" + hexToString(qhdhigh & 0xFF) + hexToString(qhdlow & 0xFF); + str += "/fhd:" + (nextAddress); + str1 += "/fhd:" + hexToString(fhdhigh & 0xFF) + hexToString(fhdlow & 0xFF); + + str += "/priority:" + (priority); + str1 += "/priority:" + hexToString(prioritylow & 0xFF); + + System.out.println(str); + System.out.println(str1); + + byte[] b = new byte[]{(byte) 0X87, (byte) 0XCD, + (byte) 0X00, (byte) 0X08, + (byte) 0X00, (byte) 0X12, + (byte) 0X00, (byte) 0X01, + (byte) 0X00, (byte) 0X71, + (byte) 0X00, (byte) 0X0E, + (byte) 0X01, prioritylow, + (byte) 0X00, (byte) 0X01, + (byte) ikeyhigh, (byte) ikeylow, + (byte) ikeyhigh, (byte) ikeylow, + (byte) typehigh, (byte) typelow, + (byte) qhdhigh, (byte) qhdlow, + (byte) fhdhigh, (byte) fhdlow + }; + log.info("下发AGV作业指令--{}", str1); + + NDCSocketConnectionAutoRun.write(b); + System.out.println("下发agv指令数据:" + Bytes2HexString(b)); + } + } finally { + MDC.remove(log_file_type); + } + } + + @Override + public void sendAgvInstToNDC(String instcode) throws Exception { + InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); + Instruction inst = instructionService.findByCodeFromCache(instcode); + sendAgvInstToNDC(inst); + } + + + String hexToString(int i) { + return (i < 16 ? "0" + Integer.toHexString(i) : Integer.toHexString(i)).toUpperCase(); + } + + + public static int IntToHexHigh(int b) { + int big = (b & 0xFF00) >> 8; + return big; + } + + public static int IntToHexLow(int b) { + int little = b & 0xFF; + return little; + } + + + public static String Bytes2HexString(byte[] b) { + String ret = ""; + for (int i = 0; i < b.length; i++) { + String hex = Integer.toHexString(b[i] & 0xFF); + if (hex.length() == 1) { + hex = '0' + hex; + } + ret += hex.toUpperCase(); + } + return ret; + } + + @Override + public byte[] sendAgvOneModeInst(int phase, int index) { + return new byte[0]; + } + + @Override + public byte[] sendAgvOneModeInst(int phase, int index, int result) { + try { + MDC.put(log_file_type, log_type); + if (phase < 0 || index < 0) + return null; + byte indexhigh = (byte) IntToHexHigh(index); + byte indexlow = (byte) IntToHexLow(index); + byte phasehigh = (byte) IntToHexHigh(phase); + byte phaselow = (byte) IntToHexLow(phase); + byte resulthigh = (byte) IntToHexHigh(result); + byte resultlow = (byte) IntToHexLow(result); + + int type = Integer.parseInt(acsConfigService.findConfigFromCache().get(AcsConfig.BUSINESSTYPE)); + byte[] b = new byte[]{}; + switch (type) { + case 0: + b = new byte[]{(byte) 0X87, (byte) 0XCD, + (byte) 0X00, (byte) 0X08, + (byte) 0X00, (byte) 0X0A, + (byte) 0X00, (byte) 0X01, + (byte) 0X00, (byte) 0X6D, + (byte) 0X00, (byte) 0X06, + (byte) indexhigh, (byte) indexlow, + (byte) 0X01, (byte) 0X12, + (byte) phasehigh, (byte) phaselow + }; + break; + case 1: + b = new byte[]{(byte) 0X87, (byte) 0XCD, + (byte) 0X00, (byte) 0X08, + (byte) 0X00, (byte) 0X0D, + (byte) 0X00, (byte) 0X01, + (byte) 0X00, (byte) 0X6D, + (byte) 0X00, (byte) 0X08, + (byte) indexhigh, (byte) indexlow, + (byte) 0X01, (byte) 0X12, + (byte) phasehigh, (byte) phaselow, + (byte) resulthigh, (byte) resultlow + }; + break; + case 2: + b = new byte[]{(byte) 0X87, (byte) 0XCD, + (byte) 0X00, (byte) 0X08, + (byte) 0X00, (byte) 0X0A, + (byte) 0X00, (byte) 0X01, + (byte) 0X00, (byte) 0X6D, + (byte) 0X00, (byte) 0X06, + (byte) indexhigh, (byte) indexlow, + (byte) 0X01, (byte) 0X12, + (byte) phasehigh, (byte) phaselow + }; + break; + case 5: + b = new byte[]{(byte) 0X87, (byte) 0XCD, + (byte) 0X00, (byte) 0X08, + (byte) 0X00, (byte) 0X0A, + (byte) 0X00, (byte) 0X01, + (byte) 0X00, (byte) 0X6D, + (byte) 0X00, (byte) 0X06, + (byte) indexhigh, (byte) indexlow, + (byte) 0X01, (byte) 0X12, + (byte) phasehigh, (byte) phaselow + }; + break; + case 7: + b = new byte[]{(byte) 0X87, (byte) 0XCD, + (byte) 0X00, (byte) 0X08, + (byte) 0X00, (byte) 0X0A, + (byte) 0X00, (byte) 0X01, + (byte) 0X00, (byte) 0X6D, + (byte) 0X00, (byte) 0X06, + (byte) indexhigh, (byte) indexlow, + (byte) 0X01, (byte) 0X12, + (byte) phasehigh, (byte) phaselow + }; + break; + } + log.info("反馈agv动作数据--index:" + hexToString(indexhigh & 0xFF) + hexToString(indexlow & 0xFF) + ",phase:" + hexToString(phasehigh & 0xFF) + hexToString(phaselow & 0xFF)); + + System.out.println("反馈agv动作数据:" + Bytes2HexString(b)); + return b; + } finally { + MDC.remove(log_file_type); + } + + } + + + @Override + public String queryDoorStatus(String device) { + try { + MDC.put(log_file_type, log_type); + log.info("AGV查询自动门状态,参数:{}", device); + int type = Integer.parseInt(acsConfigService.findConfigFromCache().get(AcsConfig.BUSINESSTYPE)); + switch (type) { + case 4: + if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.HASOTHERSYSTEM).toString(), "1")) { + String result = acsToWmsService.queryDoorsStatus().body(); + JSONArray ja = JSONArray.parseArray(result); + log.info("AGV查询自动门状态,反馈:{}", ja.toString()); + return ja.toString(); + } + return null; + default: + if (StrUtil.equals("doors", device)) { + List list = deviceAppService.findDevice(DeviceType.autodoor); + JSONArray ja = new JSONArray(); + for (int i = 0; i < list.size(); i++) { + Device doordevice = deviceAppService.findDeviceByCode(list.get(i).getDevice_code()); + if (ObjectUtil.isEmpty(doordevice)) { + throw new BadRequestException("未找到对应设备"); + } + String mes = null; + StandardAutodoorDeviceDriver autodoor; + if (doordevice.getDeviceDriver() instanceof StandardAutodoorDeviceDriver) { + autodoor = (StandardAutodoorDeviceDriver) doordevice.getDeviceDriver(); + mes = autodoor.getStatus(); + } + JSONObject jo = JSONObject.parseObject(mes); + ja.add(jo); + } + log.info("AGV查询自动门状态,反馈:{}", ja.toString()); + return ja.toString(); + + } else { + Device doordevice = deviceAppService.findDeviceByCode(device); + if (ObjectUtil.isEmpty(doordevice)) { + throw new BadRequestException("未找到对应设备"); + } + String mes = null; + StandardAutodoorDeviceDriver autodoor; + if (doordevice.getDeviceDriver() instanceof StandardAutodoorDeviceDriver) { + autodoor = (StandardAutodoorDeviceDriver) doordevice.getDeviceDriver(); + mes = autodoor.getStatus(); + } + JSONObject jo = JSONObject.parseObject(mes); + log.info("AGV查询自动门状态,反馈:{}", jo.toString()); + return jo.toString(); + } + } + } finally { + MDC.remove(log_file_type); + } + + } + + @Override + public Map findAllAgvFromCache() { + return AGVDeviceStatus; + } + +} diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/XianGongAgvServiceImpl.java b/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/XianGongAgvServiceImpl.java new file mode 100644 index 0000000..10c8193 --- /dev/null +++ b/acs/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/XianGongAgvServiceImpl.java @@ -0,0 +1,634 @@ +package org.nl.acs.agv.server.impl; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.agv.server.XianGongAgvService; +import org.nl.acs.agv.server.dto.AgvDto; +import org.nl.acs.config.AcsConfig; +import org.nl.acs.config.server.AcsConfigService; +import org.nl.acs.device_driver.standard_autodoor.StandardAutodoorDeviceDriver; +import org.nl.acs.device_driver.standard_inspect_site.StandardInspectSiteDeviceDriver; +import org.nl.acs.device_driver.standard_ordinary_site.StandardOrdinarySiteDeviceDriver; +import org.nl.acs.ext.erp.service.AcsToErpService; +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.log.service.DeviceExecuteLogService; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.opc.DeviceType; +import org.nl.acs.task.service.TaskService; +import org.nl.exception.BadRequestException; +import org.slf4j.MDC; +import org.springframework.stereotype.Service; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.*; + +@Slf4j +@Service +@RequiredArgsConstructor +public class XianGongAgvServiceImpl implements XianGongAgvService { + private final DeviceAppService deviceAppService; + private final TaskService taskService; + private final InstructionService instructionService; + private final AcsConfigService acsConfigService; + private final AcsToErpService acsToErpService; + private final AcsToWmsService acsToWmsService; + + private final DeviceExecuteLogService logServer; + + Map AGVDeviceStatus = new HashMap(); + + private String log_file_type = "log_file_type"; + private String log_type = "agv接口日志"; + + @Override + public String waitPointRequest(String param) { + try { + MDC.put(log_file_type, log_type); + 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; + } + boolean is_feedback = false; + + Device device = deviceAppService.findDeviceByCode(newaddress); + StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; + StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; + 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); + } + } + 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; + } + } + 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(); + } finally { + MDC.remove(log_file_type); + } + + + } + + @Override + public HttpResponse markComplete(String code) throws Exception { + try { + MDC.put(log_file_type, log_type); + 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/orderSequences/" + code + "/markComplete"; + log.info("关闭agv运单序列请求:{}", agvurl); + + HttpResponse result = HttpRequest.post(agvurl) + //.body(String.valueOf(orderjo))//表单内容 + .timeout(20000)//超时,毫秒 + .execute(); + log.info("关闭agv运单序列请求反馈:{}", result); + + return result; + } else { + return null; + } + } finally { + MDC.remove(log_file_type); + } + + + } + + @Override + public HttpResponse queryXZAgvDeviceStatus() { + try { + MDC.put(log_file_type, log_type); + 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"; + + HttpResponse result = HttpRequest.get(agvurl1) + .timeout(20000)//超时,毫秒 + .execute(); + + + HttpResponse result2 = HttpRequest.get(agvurl2) + .timeout(20000)//超时,毫秒 + .execute(); + + System.out.println("查询agv状态数据:" + result.body()); + if (result.getStatus() == 200) { + JSONArray ja = (JSONArray) JSONArray.parse(result.body()); + + for (int i = 0; i < ja.size(); i++) { + JSONObject jo = (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) JSONObject.parse(result2.body()); + JSONObject item = (JSONObject) detailjo.get(name); + String x = item.getString("x"); + String y = item.getString("y"); + String angle = item.getString("angle"); + AgvDto dto = new AgvDto(); + dto.setName(name); + dto.setEnergyLevel(energyLevel); + dto.setState(state); + dto.setTransportOrder(transportOrder); + dto.setPositionAngle(angle); + dto.setPositionX(x); + dto.setPositionY(y); + if (AGVDeviceStatus.containsKey(name)) { + AGVDeviceStatus.remove(name); + AGVDeviceStatus.put(name, dto); + } else { + AGVDeviceStatus.put(name, dto); + } + } + } + return result; + } else { + return null; + } + + } finally { + MDC.remove(log_file_type); + } + + } + + + @Override + public HttpResponse queryXZAgvInstStatus(String instCode) { + try { + MDC.put(log_file_type, log_type); + 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; + + HttpResponse result = HttpRequest.get(agvurl) + .timeout(20000)//超时,毫秒 + .execute(); + System.out.println("查询agv指令数据:" + result.body()); + + return result; + } else { + + return null; + } + + } finally { + MDC.remove(log_file_type); + } + + } + + + @Override + public HttpResponse deleteXZAgvInst(String instCode) { + try { + MDC.put(log_file_type, log_type); + 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 + "/withdrawal"; + log.info("删除agv指令请求agvurl:{}", agvurl); + HttpResponse result = HttpRequest.post(agvurl) + .timeout(20000)//超时,毫秒 + .execute(); + log.info("删除agv指令请求反馈:{}", result); + return result; + } else { + return null; + } + + } finally { + MDC.remove(log_file_type); + } + + } + + @Override + public HttpResponse sendOrderSequencesToXZ(Instruction inst) throws Exception { + try { + MDC.put(log_file_type, log_type); + + 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); + + log.info("任务号:{},指令号{},下发agv订单序列参数:{}", inst.getTask_code(), inst.getInstruction_code(), jo.toString()); + + 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/orderSequences/" + inst.getTask_code(); + + HttpResponse result = HttpRequest.post(agvurl) + .body(String.valueOf(jo))//表单内容 + .timeout(20000)//超时,毫秒 + .execute(); + log.info(agvurl); + log.info("任务号:{},指令号{},状态{},下发agv订单序列反馈:{}", inst.getTask_code(), inst.getInstruction_code(), result.getStatus(), result.body()); + + return result; + } else { + return null; + } + } finally { + MDC.remove(log_file_type); + } + + } + + + @Override + public HttpResponse addOrderSequences(Instruction inst) throws Exception { + try { + MDC.put(log_file_type, log_type); + JSONObject orderjo = createOrederData(inst, "1"); + log.info("指令号:{},追加agv订单序列参数:{}", inst.getInstruction_code(), orderjo.toString()); + + 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/" + inst.getInstruction_code(); + + HttpResponse result = HttpRequest.post(agvurl) + .body(String.valueOf(orderjo))//表单内容 + .timeout(20000)//超时,毫秒 + .execute(); + log.info(agvurl); + log.info("任务号:{},指令号{},状态{},追加agv订单序列参数:{}", inst.getTask_code(), inst.getInstruction_code(), result.getStatus(), result.body()); + + return result; + } else { + return null; + } + } finally { + MDC.remove(log_file_type); + } + + } + + + @Override + public String sendOrderSequencesParam(Instruction inst) throws Exception { + try { + MDC.put(log_file_type, log_type); + JSONObject jo = new JSONObject(); + jo.put("intendedVehicle", ""); + jo.put("category", "Park"); + jo.put("failureFatal", true); + jo.put("complete", false); + JSONArray transports = new JSONArray(); + JSONObject orderjo = createOrederData(inst, "0"); + JSONObject order = new JSONObject(); + orderjo.put("order", order); + orderjo.put("name", inst.getInstruction_code()); + transports.add(orderjo); + jo.put("transports", transports); + return jo.toString(); + } finally { + MDC.remove(log_file_type); + } + + } + + @Override + public JSONObject createOrederData(Instruction inst, String inst_type) { + try { + MDC.put(log_file_type, log_type); + String inst_code = inst.getInstruction_code(); + String task_code = inst.getTask_code(); + String compound_inst_data = inst.getCompound_inst_data(); + String[] str = null; + List pathlist = null; + if (!StrUtil.isEmpty(compound_inst_data)) { + str = compound_inst_data.split("->"); + pathlist = Arrays.asList(str); + } + JSONArray ja = new JSONArray(); + JSONObject orderjo = new JSONObject(); + + //1表示追加任务,需将task_code赋值给wrappingSequence + if (StrUtil.equals("1", inst_type)) { + orderjo.put("wrappingSequence", task_code); + } + String instno = inst.getInstruction_code(); + //指定agv车号 暂时不用 + //orderjo.put("intendedVehicle", ""); + //设置任务最终时间 + orderjo.put("deadline", getNextDay(1)); + orderjo.put("category", ""); + //拼接起点子任务动作,待完善,动作码需要从数据库取值 + int type = Integer.parseInt(acsConfigService.findConfigFromCache().get(AcsConfig.BUSINESSTYPE)); + + switch (type) { + case 3: + break; + case 4: + break; + case 6: + String startAddress = inst.getStart_device_code(); + String nextAddress = inst.getNext_device_code(); + Device startdevice = deviceAppService.findDeviceByCode(startAddress); + Device nextdevice = deviceAppService.findDeviceByCode(nextAddress); + StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; + //起点 + if (startdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { + + ja.add(destination2(startAddress + "IN", "Wait", "1", startAddress + "IN" + + "-" + inst_code + "-" + "01")); + ja.add(destination2(startAddress, "Load", "3", startAddress + + "-" + inst_code + "-" + "02")); + ja.add(destination2(startAddress + "OUT", "Wait", "1", startAddress + "OUT" + + "-" + inst_code + "-" + "05")); + + } else { + ja.add(destination2(nextAddress, "Wait", "1", startAddress + + "-" + inst_code + "-" + "01")); + ja.add(destination2(startAddress, "Load", "3", startAddress + + "-" + inst_code + "-" + "01")); + } + + if (nextdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { + ja.add(destination2(nextAddress + "IN", "Wait", "1", nextAddress + "IN" + + "-" + inst_code + "-" + "03")); + ja.add(destination2(nextAddress, "ForkLoad", "3", nextAddress + + "-" + inst_code + "-" + "04")); + ja.add(destination2(nextAddress + "OUT", "Wait", "1", nextAddress + "OUT" + + "-" + inst_code + "-" + "06")); + } else { + ja.add(destination2(nextAddress, "Wait", "1", nextAddress + + "-" + inst_code + "-" + "01")); + ja.add(destination2(nextAddress, "ForkLoad", "3", nextAddress + + "-" + inst_code + "-" + "01")); + } + break; + } + + orderjo.put("destinations", ja); + JSONObject prijo = new JSONObject(); + prijo.put("key", "duration"); + prijo.put("value", "101"); + + JSONArray prija = new JSONArray(); + prija.add(prijo); + orderjo.put("properties", prija); + + return orderjo; + + } finally { + MDC.remove(log_file_type); + } + + } + + /** + * 获得之后num个天的时间 + * + * @param num + * @return + */ + public static String getNextDay(int num) { + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.DAY_OF_MONTH, num); + Date date = calendar.getTime(); + TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai"); + DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + df.setTimeZone(tz); + String nowAsISO = df.format(date); + return nowAsISO; + } + + /** + * 返回一个点位操作子任务 先知使用 + * + * @param locationName 点位 + * @param operation 点位操作 + * @param propertiesType 子任务类型 + * @param pro 子任务参数 + * 调用demo:destination("sh15p", "Spin", "2", "3.14") + * demo:destination("cz14", "JackUnload", "3", "") + * @return + */ + public static JSONObject destination2(String locationName, String operation, String propertiesType, String pro) { + + //新增业务订单 + JSONObject destinationOrder = new JSONObject(); + //目标工作站 + destinationOrder.put("locationName", locationName); + //机器人在工作站要执行的操作 + destinationOrder.put("operation", operation); + if (propertiesType.equals("1")) {//Wait请求是否继续 + JSONArray properties = new JSONArray(); + JSONObject pro2 = new JSONObject(); + pro2.put("key", "device:queryAtExecuted");//固定值 + pro2.put("value", pro + ":wait");//pro为wait请求的标识,一般用点位拼接的字符串 + properties.add(pro2); + destinationOrder.put("properties", properties); + } else if (propertiesType.equals("2")) {//Spin转动 + JSONArray properties = new JSONArray(); + JSONObject pro1 = new JSONObject(); + pro1.put("key", "global_spin_angle");//坐标系类型,global_spin_angle为全局坐标系 + pro1.put("value", pro);//弧度值,如3.14 + properties.add(pro1); + JSONObject pro2 = new JSONObject(); + pro2.put("key", "spin_direction");//固定值 + pro2.put("value", "0");//弧度值,如0 + properties.add(pro2); + destinationOrder.put("properties", properties); + } else if (propertiesType.equals("3")) {//JackUnload,Jackload不操作 + JSONArray properties = new JSONArray(); + JSONObject pro1 = new JSONObject(); + pro1.put("key", "recognize");//固定值 + pro1.put("value", "false");//固定值 + properties.add(pro1); + destinationOrder.put("properties", properties); + } else if (propertiesType.equals("4")) { + JSONArray properties = new JSONArray(); + JSONObject pro1 = new JSONObject(); + pro1.put("key", "robot_spin_angle");//坐标系类型,robot_spin_angle为机器人坐标系 + pro1.put("value", pro);//弧度值,如3.14 + properties.add(pro1); + JSONObject pro2 = new JSONObject(); + pro2.put("key", "spin_direction");//固定值 + pro2.put("value", "0");//弧度值,如0 + properties.add(pro2); + destinationOrder.put("properties", properties); + } else if (propertiesType.equals("5")) {//Wait请求是否继续 + JSONArray properties = new JSONArray(); + JSONObject pro2 = new JSONObject(); + + destinationOrder.put("properties", "[]"); + } + return destinationOrder; + } + + + @Override + public String queryDoorStatus(String device) { + try { + MDC.put(log_file_type, log_type); + log.info("AGV查询自动门状态,参数:{}", device); + int type = Integer.parseInt(acsConfigService.findConfigFromCache().get(AcsConfig.BUSINESSTYPE)); + switch (type) { + case 4: + if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.HASOTHERSYSTEM).toString(), "1")) { + String result = acsToWmsService.queryDoorsStatus().body(); + JSONArray ja = JSONArray.parseArray(result); + log.info("AGV查询自动门状态,反馈:{}", ja.toString()); + return ja.toString(); + } + return null; + default: + if (StrUtil.equals("doors", device)) { + List list = deviceAppService.findDevice(DeviceType.autodoor); + JSONArray ja = new JSONArray(); + for (int i = 0; i < list.size(); i++) { + Device doordevice = deviceAppService.findDeviceByCode(list.get(i).getDevice_code()); + if (ObjectUtil.isEmpty(doordevice)) { + throw new BadRequestException("未找到对应设备"); + } + String mes = null; + StandardAutodoorDeviceDriver autodoor; + if (doordevice.getDeviceDriver() instanceof StandardAutodoorDeviceDriver) { + autodoor = (StandardAutodoorDeviceDriver) doordevice.getDeviceDriver(); + mes = autodoor.getStatus(); + } + JSONObject jo = JSONObject.parseObject(mes); + ja.add(jo); + } + log.info("AGV查询自动门状态,反馈:{}", ja.toString()); + return ja.toString(); + + } else { + Device doordevice = deviceAppService.findDeviceByCode(device); + if (ObjectUtil.isEmpty(doordevice)) { + throw new BadRequestException("未找到对应设备"); + } + String mes = null; + StandardAutodoorDeviceDriver autodoor; + if (doordevice.getDeviceDriver() instanceof StandardAutodoorDeviceDriver) { + autodoor = (StandardAutodoorDeviceDriver) doordevice.getDeviceDriver(); + mes = autodoor.getStatus(); + } + JSONObject jo = JSONObject.parseObject(mes); + log.info("AGV查询自动门状态,反馈:{}", jo.toString()); + return jo.toString(); + } + } + } finally { + MDC.remove(log_file_type); + } + } + + @Override + public Map findAllAgvFromCache() { + return AGVDeviceStatus; + } + +} diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/acs/device/service/impl/ConveyorDevice.java b/acs/hd/nladmin-system/src/main/java/org/nl/acs/device/service/impl/ConveyorDevice.java index 9a685f3..f7bebe8 100644 --- a/acs/hd/nladmin-system/src/main/java/org/nl/acs/device/service/impl/ConveyorDevice.java +++ b/acs/hd/nladmin-system/src/main/java/org/nl/acs/device/service/impl/ConveyorDevice.java @@ -7,6 +7,7 @@ import org.nl.acs.opc.OpcUtl; import org.nl.acs.task.service.TaskService; import org.nl.acs.task.service.dto.TaskDto; import org.nl.acs.task.service.impl.TaskServiceImpl; +import org.nl.utils.SpringContextHolder; @Data public class ConveyorDevice { @@ -47,7 +48,7 @@ public class ConveyorDevice { String MODE = "RD1.RD1." + id + ".mode"; String code = OpcUtl.read(MODE); if ("2".equals(code)) { - TaskService taskserver = new TaskServiceImpl(); + TaskService taskserver = SpringContextHolder.getBean(TaskServiceImpl.class); TaskDto dto = new TaskDto(); dto.setStart_point_code(id); dto.setNext_point_code("1002"); diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/standard_ordinary_site/StandardOrdinarySiteDeviceDriver.java b/acs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/standard_ordinary_site/StandardOrdinarySiteDeviceDriver.java index 45a4683..3620868 100644 --- a/acs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/standard_ordinary_site/StandardOrdinarySiteDeviceDriver.java +++ b/acs/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/standard_ordinary_site/StandardOrdinarySiteDeviceDriver.java @@ -15,6 +15,7 @@ import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; import org.nl.acs.device_driver.special_ordinary_site.SpecialOrdinarySiteDeviceDriver; import org.nl.acs.device_driver.standard_inspect_site.StandardInspectSiteDeviceDriver; import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.monitor.DeviceStageMonitor; import org.nl.acs.opc.Device; import org.nl.acs.opc.DeviceAppService; import org.nl.acs.opc.DeviceAppServiceImpl; @@ -24,6 +25,7 @@ import org.nl.acs.route.service.dto.RouteLineDto; import org.nl.acs.task.service.TaskService; import org.nl.acs.task.service.dto.TaskDto; import org.nl.modules.system.util.CodeUtil; +import org.nl.utils.RedisUtils; import org.nl.utils.SpringContextHolder; import org.nl.wql.core.bean.WQLObject; import org.springframework.beans.factory.annotation.Autowired; @@ -38,7 +40,7 @@ import java.util.Date; @Slf4j @Data @RequiredArgsConstructor -public class StandardOrdinarySiteDeviceDriver extends AbstractDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { +public class StandardOrdinarySiteDeviceDriver extends AbstractDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor { @Autowired RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); @Autowired @@ -385,5 +387,23 @@ public class StandardOrdinarySiteDeviceDriver extends AbstractDeviceDriver imple } } + @Override + public JSONObject getDeviceStatusName() { + JSONObject data = new JSONObject(); + data.put("device_name", this.getDevice().getDevice_name()); + if (mode == 1) { + + data.put("mode", "单机"); + } + if (mode == 2) { + data.put("mode", "联机"); + } + return data; + } + + @Override + public void setDeviceStatus(JSONObject data) { + + } } diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java b/acs/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java index 3342ef3..aab9050 100644 --- a/acs/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java +++ b/acs/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java @@ -232,13 +232,7 @@ public interface InstructionService { */ Integer querySameOriginInst(String code); - /** - * 查询相同起点、终点指令的数量 - * - * @param code - * @return - */ - //Integer querySameOriginInst(String code); + boolean removeByCodeFromCache(String code); diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java b/acs/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java index d8bea1e..bbaa3ee 100644 --- a/acs/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java +++ b/acs/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java @@ -12,18 +12,17 @@ import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; -import org.nl.acs.agv.server.AgvService; +import org.nl.acs.agv.server.impl.MagicAgvServiceImpl; +import org.nl.acs.agv.server.impl.NDCAgvServiceImpl; +import org.nl.acs.agv.server.impl.XianGongAgvServiceImpl; import org.nl.acs.config.AcsConfig; import org.nl.acs.config.server.AcsConfigService; import org.nl.acs.device.service.DeviceService; import org.nl.acs.device.service.impl.DeviceServiceImpl; import org.nl.acs.device_driver.lamp_three_color.LampThreecolorDeviceDriver; import org.nl.acs.device_driver.lnsh.lnsh_station.LnshStationDeviceDriver; -import org.nl.acs.device_driver.standard_conveyor_control.StandardCoveyorControlDeviceDriver; -import org.nl.acs.device_driver.standard_conveyor_control_with_plcscanner.StandardCoveyorControlWithPlcScannerDeviceDriver; import org.nl.acs.device_driver.standard_conveyor_control_with_scanner.StandardCoveyorControlWithScannerDeviceDriver; import org.nl.acs.device_driver.standard_inspect_site.StandardInspectSiteDeviceDriver; -import org.nl.acs.device_driver.standard_storage.StandardStorageDeviceDriver; import org.nl.acs.instruction.service.InstructionService; import org.nl.acs.instruction.service.dto.Instruction; import org.nl.acs.opc.Device; @@ -32,7 +31,6 @@ import org.nl.acs.opc.DeviceAppServiceImpl; import org.nl.acs.route.service.RouteLineService; import org.nl.acs.route.service.dto.RouteLineDto; import org.nl.acs.route.service.impl.RouteLineServiceImpl; -import org.nl.acs.task.enums.TaskTypeEnum; import org.nl.acs.task.service.TaskService; import org.nl.acs.task.service.dto.TaskDto; import org.nl.exception.BadRequestException; @@ -45,7 +43,6 @@ import org.nl.utils.SpringContextHolder; import org.nl.wql.WQL; import org.nl.wql.core.bean.WQLObject; import org.nl.wql.util.WqlUtil; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -67,16 +64,11 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu List instructions = new ArrayList(); - @Autowired - DeviceAppService deviceAppService; - @Autowired - AgvService agvService; - @Autowired - AcsConfigService acsConfigService; - @Autowired - RouteLineService routeLineService; - @Autowired - TaskService taskService; + private final DeviceAppService deviceAppService; + + private final AcsConfigService acsConfigService; + private final RouteLineService routeLineService; + private final TaskService taskService; @Override @@ -84,15 +76,13 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu this.reload(); } + @Override public synchronized void reload() { this.instructions = this.queryAll("instruction_status <2 and is_delete =0"); } @Override public Map queryAll(Map whereJson, Pageable page) { - /*WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "instruction_status < 2 and is_delete =0 ", "update_time desc"); - */ this.reload(); HashMap map = new HashMap<>(); map.put("flag", "1"); @@ -301,28 +291,32 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu // != 0 为agv任务 if (!StrUtil.equals(type, "0")) { if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.AGVTYPE).toString(), "1")) { - HttpResponse result = agvService.sendAgvInstToMagic(dto); + MagicAgvServiceImpl magicAgvService = SpringContextHolder.getBean(MagicAgvServiceImpl.class); + HttpResponse result = magicAgvService.sendAgvInstToMagic(dto); if (ObjectUtils.isEmpty(result) || result.getStatus() != 200) { dto.setSend_status("2"); } else { dto.setSend_status("1"); } } else if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.AGVTYPE).toString(), "2")) { - agvService.sendAgvInstToNDC(dto); + NDCAgvServiceImpl ndcAgvService = SpringContextHolder.getBean(NDCAgvServiceImpl.class); + ndcAgvService.sendAgvInstToNDC(dto); dto.setSend_status("1"); } else if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.AGVTYPE).toString(), "3")) { if (StrUtil.equals(task.getRequest_again_success(), "1")) { + XianGongAgvServiceImpl xianGongAgv = SpringContextHolder.getBean(XianGongAgvServiceImpl.class); //追加订单 - HttpResponse result = agvService.addOrderSequences(dto); + HttpResponse result = xianGongAgv.addOrderSequences(dto); if (ObjectUtils.isEmpty(result) || result.getStatus() != 200) { dto.setSend_status("2"); } else { dto.setSend_status("1"); } } else { + XianGongAgvServiceImpl xianGongAgv = SpringContextHolder.getBean(XianGongAgvServiceImpl.class); //创建订单序列 - HttpResponse result = agvService.sendOrderSequencesToXZ(dto); + HttpResponse result = xianGongAgv.sendOrderSequencesToXZ(dto); if (ObjectUtils.isEmpty(result) || result.getStatus() != 200) { dto.setSend_status("2"); } else { @@ -420,17 +414,6 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu } } - - // != 0 为agv任务 -// if(!StrUtil.equals(type,"0")){ -// if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.AGVTYPE).toString(), "1")) { -// agvService.sendAgvInstToMagic(dto); -// } else if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.AGVTYPE).toString(), "2")) { -// agvService.sendAgvInstToNDC(dto); -// } else if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.AGVTYPE).toString(), "3")) { -// agvService.addOrderSequences(dto); -// } -// } instructions.add(dto); } @@ -653,11 +636,10 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu LampThreecolorDeviceDriver lampThreecolorDeviceDriver; - LnshStationDeviceDriver lnshStationDeviceDriver; - if(device.getDeviceDriver() instanceof LnshStationDeviceDriver ){ + if (device.getDeviceDriver() instanceof LnshStationDeviceDriver) { lnshStationDeviceDriver = (LnshStationDeviceDriver) device.getDeviceDriver(); - lnshStationDeviceDriver.writing(3,Integer.parseInt(dto.getInstruction_code())); + lnshStationDeviceDriver.writing(3, Integer.parseInt(dto.getInstruction_code())); } //变更三色灯状态 @@ -753,19 +735,22 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu if (!StrUtil.equals(type, "0")) { if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.AGVTYPE).toString(), "1") && !StrUtil.equals(entity.getSend_status(), "2")) { - agvService.deleteAgvInst(entity.getInstruction_code()); + MagicAgvServiceImpl magicAgvService = SpringContextHolder.getBean(MagicAgvServiceImpl.class); + magicAgvService.deleteAgvInst(entity.getInstruction_code()); flag = true; } else if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.AGVTYPE).toString(), "2")) { //NDC agv指令不当场取消指令,需要等agv上报 if (!StrUtil.isEmpty(entity.getAgv_jobno())) { - agvService.deleteAgvInstToNDC(entity); + NDCAgvServiceImpl ndcAgv = SpringContextHolder.getBean(NDCAgvServiceImpl.class); + ndcAgv.deleteAgvInstToNDC(entity); } else { flag = true; } } else if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.AGVTYPE).toString(), "3") && !StrUtil.equals(entity.getSend_status(), "2")) { - agvService.deleteXZAgvInst(entity.getInstruction_code()); + XianGongAgvServiceImpl xianGongAgvService = SpringContextHolder.getBean(XianGongAgvServiceImpl.class); + xianGongAgvService.deleteXZAgvInst(entity.getInstruction_code()); flag = true; } else { flag = true; diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/acs/monitor/DeviceStageMonitor.java b/acs/hd/nladmin-system/src/main/java/org/nl/acs/monitor/DeviceStageMonitor.java new file mode 100644 index 0000000..23c0357 --- /dev/null +++ b/acs/hd/nladmin-system/src/main/java/org/nl/acs/monitor/DeviceStageMonitor.java @@ -0,0 +1,20 @@ +package org.nl.acs.monitor; + +import com.alibaba.fastjson.JSONObject; + +/** + * 设备监控服务 + */ +public interface DeviceStageMonitor { + /** + * 根据设备获取设备状态(中文名:如故障、联机等) + * @return + */ + public JSONObject getDeviceStatusName(); + + /** + * 根据舞台数据修改设备驱动状态 + * @param data + */ + public void setDeviceStatus(JSONObject data); +} diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/acs/monitor/rest/DeviceStageMonitorController.java b/acs/hd/nladmin-system/src/main/java/org/nl/acs/monitor/rest/DeviceStageMonitorController.java new file mode 100644 index 0000000..b8e2a14 --- /dev/null +++ b/acs/hd/nladmin-system/src/main/java/org/nl/acs/monitor/rest/DeviceStageMonitorController.java @@ -0,0 +1,4 @@ +package org.nl.acs.monitor.rest; + +public class DeviceStageMonitorController { +} diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/acs/monitor/service/Device.java b/acs/hd/nladmin-system/src/main/java/org/nl/acs/monitor/service/Device.java deleted file mode 100644 index 111f9a8..0000000 --- a/acs/hd/nladmin-system/src/main/java/org/nl/acs/monitor/service/Device.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.nl.acs.monitor.service; - -public interface Device { - -} diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/acs/monitor/service/DeviceStageMonitorService.java b/acs/hd/nladmin-system/src/main/java/org/nl/acs/monitor/service/DeviceStageMonitorService.java new file mode 100644 index 0000000..78ede04 --- /dev/null +++ b/acs/hd/nladmin-system/src/main/java/org/nl/acs/monitor/service/DeviceStageMonitorService.java @@ -0,0 +1,16 @@ +package org.nl.acs.monitor.service; + +import com.alibaba.fastjson.JSONArray; + +/** + * 设备舞台监控服务 + */ +public interface DeviceStageMonitorService { + /** + * 取设备舞台监控数据 + * + * @param jsonArray 前端传来设备编号和节点的id + * @return + */ + public JSONArray getData(JSONArray jsonArray); +} diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/acs/monitor/service/impl/DeviceStageMonitorServiceImpl.java b/acs/hd/nladmin-system/src/main/java/org/nl/acs/monitor/service/impl/DeviceStageMonitorServiceImpl.java new file mode 100644 index 0000000..fcea861 --- /dev/null +++ b/acs/hd/nladmin-system/src/main/java/org/nl/acs/monitor/service/impl/DeviceStageMonitorServiceImpl.java @@ -0,0 +1,49 @@ +package org.nl.acs.monitor.service.impl; + +import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.monitor.DeviceStageMonitor; +import org.nl.acs.monitor.service.DeviceStageMonitorService; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +@RequiredArgsConstructor +public class DeviceStageMonitorServiceImpl implements DeviceStageMonitorService { + private final DeviceAppService deviceAppService; + + + @Override + public JSONArray getData(JSONArray jsonArray) { + JSONArray arr = new JSONArray(); + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject obj = new JSONObject(); + JSONObject js = jsonArray.getJSONObject(i); + String device_code = js.getString("device_code"); + + if (ObjectUtil.isEmpty(device_code)) continue; + + Device device = deviceAppService.findDeviceByCode(device_code); + if (ObjectUtil.isNull(device)) continue; + + + JSONObject json = new JSONObject(); + if (device.getDeviceDriver() instanceof DeviceStageMonitor) { + DeviceStageMonitor monitorService = (DeviceStageMonitor) device.getDeviceDriver(); + json = monitorService.getDeviceStatusName(); + } + + obj.put("data", json); + obj.put("device_code", js.get("device_code")); + obj.put("id", js.getString("id")); // 设备不存在就只保留id,方便前端查看 + arr.add(obj); + } + + return arr; + } +} diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java b/acs/hd/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java index e4e5af3..ce5d3aa 100644 --- a/acs/hd/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java +++ b/acs/hd/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java @@ -1,7 +1,6 @@ package org.nl.acs.task.service.impl; - import cn.hutool.core.date.DateUtil; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.IdUtil; @@ -13,7 +12,7 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.nl.acs.agv.server.AgvService; +import org.nl.acs.agv.server.impl.XianGongAgvServiceImpl; import org.nl.acs.config.AcsConfig; import org.nl.acs.config.server.AcsConfigService; import org.nl.acs.device.service.DeviceAssignedService; @@ -48,7 +47,6 @@ import org.nl.utils.SpringContextHolder; import org.nl.wql.WQL; import org.nl.wql.core.bean.WQLObject; import org.nl.wql.util.WqlUtil; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -69,34 +67,34 @@ import java.util.regex.Pattern; @RequiredArgsConstructor @Slf4j public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { + List tasks = new ArrayList(); - @Autowired - DeviceAppService deviceAppService; - @Autowired - RouteLineService routelineserver; - @Autowired - AcsToWmsService acstowmsService; - @Autowired - TaskFeedbackService taskFeedbackService; - @Autowired - AcsConfigService acsConfigService; - @Autowired - AgvService agvService; - @Autowired - RouteLineService routeLineService; - @Autowired - DeviceAssignedService deviceAssignedService; - @Autowired - InstructionService instructionService; - @Autowired - StorageCellService storageCellService; + private final DeviceAppService deviceAppService; + + private final RouteLineService routelineserver; + + private final AcsToWmsService acstowmsService; + + private final TaskFeedbackService taskFeedbackService; + + private final AcsConfigService acsConfigService; + + + private final RouteLineService routeLineService; + + private final DeviceAssignedService deviceAssignedService; + + private final InstructionService instructionService; + + private final StorageCellService storageCellService; @Override public void autoInitial() throws Exception { this.reload(); } + @Override public synchronized void reload() { this.tasks = this.queryAll("task_status <2 and is_delete =0"); } @@ -252,7 +250,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { public List queryAllUnfinished(Map whereJson) { WQLObject wo = WQLObject.getWQLObject("acs_task"); JSONArray arr = wo.query("task_status < 2 ").getResultJSONArray(0); - List list =arr.toJavaList(TaskDto.class); + List list = arr.toJavaList(TaskDto.class); return list; } @@ -453,7 +451,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { } } WQLObject wo = WQLObject.getWQLObject("acs_task"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); wo.insert(json); tasks.add(dto); @@ -556,7 +554,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { } if (ObjectUtil.isNotEmpty(this.findByStartCode(start_device_code)) - || ObjectUtil.isNotEmpty(this.findByNextCode(next_device_code))) { + || ObjectUtil.isNotEmpty(this.findByNextCode(next_device_code))) { throw new WDKException("已存在该起点或终点的任务!"); } if (StrUtil.equals(material_type, "") || StrUtil.equals(quantity, "")) { @@ -586,7 +584,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { dto.setUpdate_by(currentUsername); WQLObject wo = WQLObject.getWQLObject("acs_task"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); wo.update(json); @@ -810,7 +808,8 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { //如果属于先知AGV,关闭运单序列 if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.AGVTYPE).toString(), "3")) { try { - agvService.markComplete(entity.getTask_code()); + XianGongAgvServiceImpl xianGongAgv = SpringContextHolder.getBean(XianGongAgvServiceImpl.class); + xianGongAgv.markComplete(entity.getTask_code()); } catch (Exception e) { e.printStackTrace(); } @@ -856,7 +855,8 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { // != 0 为agv任务 if (!StrUtil.equals(type, "0")) { if (StrUtil.equals(acsConfigService.findConfigFromCache().get(AcsConfig.AGVTYPE).toString(), "3")) { - agvService.markComplete(entity.getTask_code()); + XianGongAgvServiceImpl xianGongAgv = SpringContextHolder.getBean(XianGongAgvServiceImpl.class); + xianGongAgv.markComplete(entity.getTask_code()); } } } diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/logicflow/service/impl/StageServiceImpl.java b/acs/hd/nladmin-system/src/main/java/org/nl/logicflow/service/impl/StageServiceImpl.java index d9504d0..8852382 100644 --- a/acs/hd/nladmin-system/src/main/java/org/nl/logicflow/service/impl/StageServiceImpl.java +++ b/acs/hd/nladmin-system/src/main/java/org/nl/logicflow/service/impl/StageServiceImpl.java @@ -30,6 +30,7 @@ import org.nl.acs.device_driver.standard_inspect_site.StandardInspectSiteDeviceD import org.nl.acs.device_driver.standard_ordinary_site.StandardOrdinarySiteDeviceDriver; import org.nl.acs.device_driver.standard_rgv.StandardRGVDeviceDriver; import org.nl.acs.device_driver.standard_scanner.StandardScannerDeviceDriver; +import org.nl.acs.monitor.DeviceStageMonitor; import org.nl.acs.opc.Device; import org.nl.acs.opc.DeviceAppService; import org.nl.acs.opc.DeviceAppServiceImpl; @@ -160,7 +161,7 @@ public class StageServiceImpl implements StageService { public JSONArray getDeviceByCodes(JSONArray jsonArray) throws Exception { // 前端传来设备编号和节点的id DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); JSONArray arr = new JSONArray(); - for (int i=0; i agv_map = agvService.findAllAgvFromCache(); + //1、magic 2、ndc 3、先工 + String agvType = acsConfigService.findConfigFromCache().get(AcsConfig.AGVTYPE).toString(); + Map agv_map=null; + if (StrUtil.equals(agvType,"1")){ + MagicAgvService agvService = SpringContextHolder.getBean(MagicAgvServiceImpl.class); + agv_map = agvService.findAllAgvFromCache(); + } + if (StrUtil.equals(agvType,"2")){ + NDCAgvService agvService = SpringContextHolder.getBean(NDCAgvServiceImpl.class); + agv_map = agvService.findAllAgvFromCache(); + } + if (StrUtil.equals(agvType,"3")){ + XianGongAgvService agvService = SpringContextHolder.getBean(XianGongAgvServiceImpl.class); + agv_map = agvService.findAllAgvFromCache(); + } + + + AgvDto agv1 = new AgvDto(); agv1.setName("agv1"); agv1.setEnergyLevel("70"); diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryMagicAgvTaskStatus.java b/acs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryMagicAgvTaskStatus.java index b0854de..e3de69a 100644 --- a/acs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryMagicAgvTaskStatus.java +++ b/acs/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryMagicAgvTaskStatus.java @@ -5,11 +5,11 @@ import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpResponse; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.nl.acs.agv.server.AgvService; +import org.nl.acs.agv.server.MagicAgvService; import org.nl.acs.instruction.service.InstructionService; import org.nl.acs.instruction.service.dto.Instruction; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; @@ -19,13 +19,11 @@ import java.util.List; */ @Slf4j @Component +@RequiredArgsConstructor public class QueryMagicAgvTaskStatus { + private final InstructionService instructionService; - @Autowired - InstructionService instructionService; - - @Autowired - AgvService agvService; + MagicAgvService magicAgvService; public void run() throws Exception { @@ -34,7 +32,7 @@ public class QueryMagicAgvTaskStatus { for (int i = 0; i < instList.size(); i++) { Instruction inst = instList.get(i); String instcode = inst.getInstruction_code(); - HttpResponse response = agvService.queryAgvInstStatus(instcode); + HttpResponse response = magicAgvService.queryAgvInstStatus(instcode); JSONObject jo = JSONObject.parseObject(response.body()); if (MapUtil.isEmpty(jo)) continue; //反馈结果状态 @@ -100,7 +98,7 @@ public class QueryMagicAgvTaskStatus { String mes = ""; - agvService.process(instcode, type, device, action, processingVehicle); + magicAgvService.process(instcode, type, device, action, processingVehicle); } } diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/modules/system/service/impl/JobServiceImpl.java b/acs/hd/nladmin-system/src/main/java/org/nl/modules/system/service/impl/JobServiceImpl.java index 1fa586d..3955903 100644 --- a/acs/hd/nladmin-system/src/main/java/org/nl/modules/system/service/impl/JobServiceImpl.java +++ b/acs/hd/nladmin-system/src/main/java/org/nl/modules/system/service/impl/JobServiceImpl.java @@ -99,6 +99,7 @@ public class JobServiceImpl implements JobService { @Override @Transactional(rollbackFor = Exception.class) public void delete(Set ids) { + jobRepository.deleteAllByIdIn(ids); // 删除缓存 redisUtils.delByKeys("job::id:", ids); diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/start/auto/run/NDCSocketConnectionAutoRun.java b/acs/hd/nladmin-system/src/main/java/org/nl/start/auto/run/NDCSocketConnectionAutoRun.java index d1fe4c6..09170a7 100644 --- a/acs/hd/nladmin-system/src/main/java/org/nl/start/auto/run/NDCSocketConnectionAutoRun.java +++ b/acs/hd/nladmin-system/src/main/java/org/nl/start/auto/run/NDCSocketConnectionAutoRun.java @@ -3,7 +3,8 @@ package org.nl.start.auto.run; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import lombok.extern.slf4j.Slf4j; -import org.nl.acs.agv.server.AgvService; +import org.nl.acs.agv.server.NDCAgvService; +import org.nl.acs.agv.server.impl.NDCAgvServiceImpl; import org.nl.acs.config.AcsConfig; import org.nl.acs.config.server.AcsConfigService; import org.nl.acs.config.server.impl.AcsConfigServiceImpl; @@ -26,7 +27,6 @@ import java.io.IOException; import java.net.Socket; import java.util.Date; -import static org.nl.acs.agv.server.impl.AgvServiceImpl.Bytes2HexString; @Slf4j @Component @@ -57,21 +57,24 @@ public class NDCSocketConnectionAutoRun extends AbstractAutoRunnable { this.recordTime = new Date((new Date()).getTime() - (long) this.recordTimeOut); } + @Override public String getCode() { return NDCSocketConnectionAutoRun.class.getSimpleName(); } + @Override public String getName() { return "NDC在线连接"; } + @Override public void autoRun() { try { AcsConfigService acsConfigService = SpringContextHolder.getBean(AcsConfigServiceImpl.class); InstructionService instructionService = SpringContextHolder.getBean(InstructionServiceImpl.class); AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); - AgvService AgvService = SpringContextHolder.getBean(AgvService.class); + NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvServiceImpl.class); DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppService.class); DeviceService deviceService = SpringContextHolder.getBean(DeviceService.class); AcsToXrlkService acsToXrlkService = SpringContextHolder.getBean(AcsToXrlkService.class); @@ -184,4 +187,16 @@ public class NDCSocketConnectionAutoRun extends AbstractAutoRunnable { } } + + public static String Bytes2HexString(byte[] b) { + String ret = ""; + for (int i = 0; i < b.length; i++) { + String hex = Integer.toHexString(b[i] & 0xFF); + if (hex.length() == 1) { + hex = '0' + hex; + } + ret += hex.toUpperCase(); + } + return ret; + } } diff --git a/acs/qd/.env.development b/acs/qd/.env.development index 7bab6fd..d3d2806 100644 --- a/acs/qd/.env.development +++ b/acs/qd/.env.development @@ -1,7 +1,7 @@ ENV = 'development' # 接口地址 -VUE_APP_BASE_API = 'http://192.168.81.140:8013' +VUE_APP_BASE_API = 'http://192.168.81.140:8010' VUE_APP_WS_API = 'ws://127.0.0.1:8010' # 是否启用 babel-plugin-dynamic-import-node插件