diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/XianGongAgvServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/XianGongAgvServiceImpl.java index 42830f3..a72b31e 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/XianGongAgvServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/XianGongAgvServiceImpl.java @@ -13,6 +13,7 @@ import org.nl.acs.AcsConfig; import org.nl.acs.agv.AgvUtil; import org.nl.acs.agv.server.XianGongAgvService; import org.nl.acs.agv.server.dto.AgvDto; +import org.nl.acs.device_driver.RouteUtil; import org.nl.acs.ext.wms.service.AcsToWmsService; import org.nl.acs.instruction.service.dto.Instruction; import org.nl.acs.log.LokiLog; @@ -22,12 +23,10 @@ import org.nl.acs.opc.DeviceAppService; import org.nl.acs.opc.DeviceType; import org.nl.modules.common.exception.BadRequestException; import org.nl.modules.system.service.ParamService; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; @Slf4j @Service @@ -38,6 +37,9 @@ public class XianGongAgvServiceImpl implements XianGongAgvService { private final AcsToWmsService acsToWmsService; Map AGVDeviceStatus = new HashMap(); + @Value("${agvToAcs.addr}") + private String addr; + @LokiLog(type = LokiLogType.AGV) @Override public String waitPointRequest(String param) { @@ -236,17 +238,157 @@ public class XianGongAgvServiceImpl implements XianGongAgvService { @Override public JSONArray createBlocksData(Instruction inst) { JSONArray ja = new JSONArray(); + //取货前等待 JSONObject jo = new JSONObject(); jo.put("blockId", IdUtil.simpleUUID()); - jo.put("location",inst.getStart_point_code()); - jo.put("operation","JackLoad"); + jo.put("location", inst.getStart_point_code() + "INGET"); + jo.put("operation", "script"); + jo.put("id", inst.getStart_point_code() + "INGET"); + jo.put("script_name", "userpy/interact.py"); + JSONObject script_args = new JSONObject(); + script_args.put("addr", addr); + JSONObject data = new JSONObject(); + JSONObject reach = new JSONObject(); + reach.put("task_code", inst.getInstruction_code()); + reach.put("address", inst.getStart_point_code() + "INGET"); + data.put("reach", reach); + script_args.put("data", data); + script_args.put("protocol", "HTTP"); + jo.put("script_args", script_args); ja.add(jo); + JSONObject jo1 = new JSONObject(); - jo1.put("blockId",IdUtil.simpleUUID()); - jo1.put("location",inst.getNext_point_code()); - jo1.put("operation","JackUnload"); + jo1.put("blockId", IdUtil.simpleUUID()); + jo1.put("location", inst.getStart_point_code()); + jo1.put("operation", "Jackload"); ja.add(jo1); - return ja; + + //取货完成等待 + JSONObject jo2 = new JSONObject(); + jo2.put("blockId", IdUtil.simpleUUID()); + jo2.put("location", inst.getStart_point_code() + "OUTGET"); + jo2.put("operation", "script"); + jo2.put("id", inst.getStart_point_code() + "OUTGET"); + jo2.put("script_name", "userpy/interact.py"); + JSONObject script_args2 = new JSONObject(); + script_args2.put("addr", addr); + JSONObject data2 = new JSONObject(); + JSONObject reach2 = new JSONObject(); + reach2.put("task_code", inst.getInstruction_code()); + reach2.put("address", inst.getStart_point_code() + "OUTGET"); + data2.put("reach", reach2); + script_args2.put("data", data2); + script_args2.put("protocol", "HTTP"); + jo2.put("script_args", script_args2); + ja.add(jo2); + + //放货前等待 + JSONObject jo3 = new JSONObject(); + jo3.put("blockId", IdUtil.simpleUUID()); + jo3.put("location", inst.getNext_point_code() + "INPUT"); + jo3.put("operation", "script"); + jo3.put("id", inst.getNext_point_code() + "INPUT"); + jo3.put("script_name", "userpy/interact.py"); + JSONObject script_args3 = new JSONObject(); + script_args3.put("addr", addr); + JSONObject data3 = new JSONObject(); + JSONObject reach3 = new JSONObject(); + reach3.put("task_code", inst.getInstruction_code()); + reach3.put("address", inst.getNext_point_code() + "INPUT"); + data3.put("reach", reach3); + script_args3.put("data", data3); + script_args3.put("protocol", "HTTP"); + jo3.put("script_args", script_args3); + ja.add(jo3); + + JSONObject jo4 = new JSONObject(); + jo4.put("blockId", IdUtil.simpleUUID()); + jo4.put("location", inst.getNext_point_code()); + jo4.put("operation", "JackUnload"); + ja.add(jo4); + + //放货完成等待 + JSONObject jo5 = new JSONObject(); + jo5.put("blockId", IdUtil.simpleUUID()); + jo5.put("location", inst.getNext_point_code() + "OUTPUT"); + jo5.put("operation", "script"); + jo5.put("id", inst.getNext_point_code() + "OUTPUT"); + jo5.put("script_name", "userpy/interact.py"); + JSONObject script_args5 = new JSONObject(); + script_args5.put("addr", addr); + JSONObject data5 = new JSONObject(); + JSONObject reach5 = new JSONObject(); + reach5.put("task_code", inst.getInstruction_code()); + reach5.put("address", inst.getNext_point_code() + "OUTPUT"); + data5.put("reach", reach5); + script_args5.put("data", data5); + script_args5.put("protocol", "HTTP"); + jo5.put("script_args", script_args5); + ja.add(jo5); + + //根据任务起点终点获取后续的路线 + List routeList = RouteUtil.getRouteList(inst.getStart_device_code(), inst.getNext_device_code()); + if (ObjectUtil.isNotEmpty(routeList)) { + for (int i = 0; i < routeList.size(); i++) { + String loadStyle = ""; + String getOrPut = ""; + if (i % 2 == 0) { + //取货 + loadStyle = "JackLoad"; + getOrPut = "GET"; + } else { + //放货 + loadStyle = "JackUnload"; + getOrPut = "PUT"; + } + + //取/放货前等待 + JSONObject joi1 = new JSONObject(); + joi1.put("blockId", IdUtil.simpleUUID()); + joi1.put("location", routeList.get(i) + "IN" + getOrPut); + joi1.put("operation", "script"); + joi1.put("id", routeList.get(i) + "IN" + getOrPut); + joi1.put("script_name", "userpy/interact.py"); + JSONObject script_argsi1 = new JSONObject(); + script_argsi1.put("addr", addr); + JSONObject datai1 = new JSONObject(); + JSONObject reachi1 = new JSONObject(); + reachi1.put("task_code", inst.getInstruction_code()); + reachi1.put("address", routeList.get(i) + "IN" + getOrPut); + data.put("reach", reachi1); + script_argsi1.put("data", datai1); + script_argsi1.put("protocol", "HTTP"); + joi1.put("script_args", script_argsi1); + ja.add(joi1); + + JSONObject joi2 = new JSONObject(); + joi2.put("blockId", IdUtil.simpleUUID()); + joi2.put("location", routeList.get(i)); + joi2.put("operation", loadStyle); + ja.add(joi2); + + //取/放货后等待 + JSONObject joi3 = new JSONObject(); + joi3.put("blockId", IdUtil.simpleUUID()); + joi3.put("location", routeList.get(i) + "OUT" + getOrPut); + joi3.put("operation", "script"); + joi3.put("id", routeList.get(i) + "OUT" + getOrPut); + joi3.put("script_name", "userpy/interact.py"); + JSONObject script_argsi3 = new JSONObject(); + script_argsi3.put("addr", addr); + JSONObject datai3 = new JSONObject(); + JSONObject reachi3 = new JSONObject(); + reachi3.put("task_code", inst.getInstruction_code()); + reachi3.put("address", routeList.get(i) + "OUT" + getOrPut); + datai3.put("reach", reachi3); + script_argsi3.put("data", datai3); + script_argsi3.put("protocol", "HTTP"); + joi3.put("script_args", script_argsi3); + ja.add(joi3); + } + } + System.out.println(ja.toString()); + return ja; } @LokiLog(type = LokiLogType.AGV) diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java b/acs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java index 6f46ade..770f157 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java @@ -21,18 +21,7 @@ public enum DriverTypeEnum { INSPECT_CONVEYOR_MONITOR(6, "standard_conveyor_monitor", "标准版-输送机-监控点", "conveyor"), - HAILIANG_SMART_PLC_TEST(7, "hailiang_smart_plc_test", "永裕共挤线-西门子SMART200PLC", "conveyor"), - - EMPTY_VEHICLE_STACKING_POSITION(8, "empty_vehicle_stacking_position", "永裕叠盘位-西门子SMART200PLC", "conveyor"), - - CARGO_LIFT_CONVEYOR(9, "cargo_lift_conveyor", "货梯对接线", "conveyor"), - - INSPECT_CONVEYOR_CONTROL_WITH_SCANNER(10, "standard_conveyor_control_with_scanner", "货梯对接线-关联扫码", "conveyor"), - - HAOKAI_AUTO_CONVEYOR(11, "haokai_auto_conveyor", "豪恺自动线对接位", "conveyor"), - - PAINT_CONVEYOR(12, "paint_conveyor", "油漆线", "conveyor"); - + MAGANG_CONVEYOR_CONTROL(7, "magang_conveyor_control", "马钢-输送机", "conveyor"); //驱动索引 private int index; diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/RouteUtil.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/RouteUtil.java new file mode 100644 index 0000000..33de260 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/RouteUtil.java @@ -0,0 +1,69 @@ +package org.nl.acs.device_driver; + +import cn.hutool.core.util.StrUtil; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author: geng by + * @createDate: 2022/11/17 + */ +public class RouteUtil { + + public static List getRouteList(String start_device_code, String next_device_code) { + Map> listMap = getRouteByCode(start_device_code, next_device_code); + return listMap.get(start_device_code); + } + + public static Map> getRouteByCode(String start_device_code, String next_device_code) { + String first_device_code = start_device_code.substring(0, 1); + Map> map = new HashMap<>(); + List list = new ArrayList<>(); + if (!StrUtil.equals(first_device_code, "D")) { + list.add(first_device_code + "03"); + list.add(first_device_code + "04"); + list.add(first_device_code + "02"); + list.add(first_device_code + "03"); + list.add(first_device_code + "04"); + list.add(first_device_code + "01"); + map.put(first_device_code + "01", list); + list = new ArrayList<>(); + list.add(first_device_code + "02"); + list.add(first_device_code + "03"); + list.add(first_device_code + "04"); + list.add(first_device_code + "01"); + map.put(first_device_code + "03", list); + list = new ArrayList<>(); + list.add(first_device_code + "04"); + list.add(first_device_code + "01"); + map.put(first_device_code + "02", list); + } else { + if (StrUtil.equals(next_device_code, "D02")) { + list = new ArrayList<>(); + list.add(first_device_code + "03"); + list.add(first_device_code + "01"); + map.put(first_device_code + "01", list); + } else if (StrUtil.equals(next_device_code, "D03")) { + list = new ArrayList<>(); + list.add(first_device_code + "02"); + list.add(first_device_code + "01"); + map.put(first_device_code + "01", list); + } + } + return map; + } + + public static String getDeviceCode(String address) { + String device_code = ""; + if (address.contains("INGET") || address.contains("INPUT")) { + device_code = address.substring(0, address.length() - 5); + } else if (address.contains("OUTGET") || address.contains("OUTPUT")) { + device_code = address.substring(0, address.length() - 6); + } + return device_code; + } + +} diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/maGang/ItemProtocol.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/maGang/ItemProtocol.java new file mode 100644 index 0000000..5864b42 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/maGang/ItemProtocol.java @@ -0,0 +1,82 @@ +package org.nl.acs.device_driver.maGang; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + + public static String item_heartbeat = "heartbeat"; + public static String item_mode = "mode"; + public static String item_move = "move"; + public static String item_action = "action"; + public static String item_error = "error"; + + + public static String item_to_command = "to_command"; + + + private MaGangConveyorDeviceDriver driver; + + public ItemProtocol(MaGangConveyorDeviceDriver driver) { + this.driver = driver; + } + + public int getItem_heartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getItem_mode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getItem_move() { + return this.getOpcIntegerValue(item_move); + } + + public int getItem_error() { + return this.getOpcIntegerValue(item_error); + } + + public int getItem_action() { + return this.getOpcIntegerValue(item_action); + } + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(item_mode, "工作模式", "DB600.B2")); + list.add(new ItemDto(item_move, "光电信号", "DB600.B3")); + list.add(new ItemDto(item_action, "取放信号", "DB600.B4")); + list.add(new ItemDto(item_error, "故障", "DB600.B5")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "下发命令", "DB601.W2")); + return list; + } + + +} + diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/maGang/MaGangConveyorDefination.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/maGang/MaGangConveyorDefination.java new file mode 100644 index 0000000..63d825f --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/maGang/MaGangConveyorDefination.java @@ -0,0 +1,60 @@ +package org.nl.acs.device_driver.maGang; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceType; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +/** + * 马钢输送站点 + */ +@Service +public class MaGangConveyorDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "magang_conveyor_control"; + } + + @Override + public String getDriverName() { + return "马钢输送站点"; + } + + @Override + public String getDriverDescription() { + return "马钢输送站点"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new MaGangConveyorDeviceDriver()).setDevice(device).setDriverDefination(this); + } + + @Override + public Class getDeviceDriverType() { + return MaGangConveyorDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return ItemProtocol.getReadableItemDtos(); + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/maGang/MaGangConveyorDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/maGang/MaGangConveyorDeviceDriver.java new file mode 100644 index 0000000..5c987bf --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/maGang/MaGangConveyorDeviceDriver.java @@ -0,0 +1,305 @@ +package org.nl.acs.device_driver.maGang; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.agv.server.AgvService; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; +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.monitor.DeviceStageMonitor; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; +import org.nl.modules.system.service.ParamService; +import org.nl.modules.system.util.CodeUtil; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +/** + * 马钢输送站点 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class MaGangConveyorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor { + + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); + @Autowired + TaskService taskserver = SpringContextHolder.getBean(TaskService.class); + @Autowired + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + @Autowired + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); + @Autowired + ParamService paramService = SpringContextHolder.getBean(ParamService.class); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class); + @Autowired + AgvService agvService = SpringContextHolder.getBean(AgvService.class); + + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + private Date instruction_apply_time = new Date(); + private int instruction_require_time_out = 3000; + + int heartbeat = 0; + //工作模式 + int mode = 0; + int last_mode = 0; + + //光电信号 + int move = 0; + int last_move = 0; + + //动作信号 + int action = 0; + int last_action = 0; + + //报警信号 + int error = 0; + int last_error = 0; + + Boolean isonline = true; + Boolean iserror = false; + + //1-执行任务;2-取货完成;3-放货完成; + int flag; + + + + String device_code; + + @Override + public Device getDevice() { + return this.device; + } + + //请求成功标记 + Boolean requireSucess = false; + + @Override + public void execute() throws Exception { + String message = null; + device_code = this.getDeviceCode(); + heartbeat = this.itemProtocol.getItem_heartbeat(); + mode = this.itemProtocol.getItem_mode(); + move = this.itemProtocol.getItem_move(); + action = this.itemProtocol.getItem_action(); + error = this.itemProtocol.getItem_error(); + if (mode != last_mode) { + if (mode == 3){ + this.setRequireSucess(false); + } + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); + } + if (move != last_move) { + logServer.deviceItemValue(this.device_code, "move", String.valueOf(move)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_move + "->" + move); + } + if (action != last_action) { + logServer.deviceItemValue(this.device_code, "action", String.valueOf(action)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号action:" + last_action + "->" + action); + } + if (error != last_error) { + logServer.deviceItemValue(this.device_code, "error", String.valueOf(error)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号error:" + last_error + "->" + error); + } + if (!this.itemProtocol.getIsonline()) { + this.setIsonline(false); + this.setIserror(true); + message = "信号量同步异常"; + //未联机 + } else if (mode == 0) { + this.setIsonline(false); + this.setIserror(true); + message = "未联机"; + //有报警 + } else if (error != 0) { + this.setIsonline(false); + this.setIserror(true); + message = "有报警"; + //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + message = ""; + Instruction instruction = null; + List toInstructions; + if (mode == 3 && !requireSucess){ + instruction_require(); + } + } + + last_mode = mode; + last_move = move; + last_error = error; + last_action = action; + } + + public synchronized boolean instruction_require() throws Exception { + Date date = new Date(); + if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return false; + } else { + this.instruction_require_time = date; + List link_device_codes = this.getExtraDeviceCodes("link_device_code"); + String next_device_code = ""; + MaGangConveyorDeviceDriver maGangConveyorDeviceDriver; + for (int i = 0; i < link_device_codes.size(); i++) { + String link_device_code = link_device_codes.get(i); + Device device = deviceAppservice.findDeviceByCode(link_device_code); + if (device.getDeviceDriver() instanceof MaGangConveyorDeviceDriver){ + maGangConveyorDeviceDriver = (MaGangConveyorDeviceDriver) device.getDeviceDriver(); + if (maGangConveyorDeviceDriver.getMove() == 0){ + next_device_code = link_device_code; + break; + } + } + } + if (StrUtil.isEmpty(next_device_code)){ + return false; + } + TaskDto taskDto = new TaskDto(); + String now = DateUtil.now(); + taskDto.setTask_id(IdUtil.simpleUUID()); + taskDto.setTask_code(CodeUtil.getNewCode("TASK_NO")); + taskDto.setTask_type("1"); + taskDto.setRoute_plan_code("normal"); + taskDto.setTask_status("0"); + taskDto.setPriority("101"); + taskDto.setAgv_system_type("1"); + taskDto.setStart_device_code(this.getDevice().getDevice_code()); + taskDto.setStart_point_code(this.getDevice().getDevice_code()); + taskDto.setNext_point_code(next_device_code); + taskDto.setNext_point_code(next_device_code); + taskDto.setCreate_by(this.getDevice().getDevice_code()); + taskDto.setUpdate_by(this.getDevice().getDevice_code()); + taskDto.setUpdate_time(now); + taskDto.setCreate_time(now); + try { + taskserver.create(taskDto); + } catch (Exception e) { + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":创建任务失败," + String.valueOf(e.getMessage())); + } + logServer.deviceExecuteLog(this.device_code, "", "", device_code + ":创建任务成功"); + this.writing(1); + this.setRequireSucess(true); + return true; + } + } + + protected void thingToNothing() { + + } + + //将扩展表中的字符串数据转换成集合 + public List getExtraDeviceCodes(String extraName) { + String extraValue = (String) this.getDevice().getExtraValue().get(extraName); + String devicesString = extraValue.substring(1, extraValue.length() - 1); + List devicesList = new ArrayList<>(); + String[] devices = devicesString.split(","); + for (int i = 0; i < devices.length; i++) { + String s = devices[i].replace("\"", "").replace("\"", ""); + devicesList.add(s); + } + return devicesList; + } + + public void writing(int command) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_command; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, command); + ReadUtil.write(itemMap, server); + } + + public void writing(int type, int command) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_command; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + if (type == 1) { + itemMap.put(to_command, command); + log.info("设备:" + device_code + ",下发PLC信号" + to_command + ",value:" + command); + } + ReadUtil.write(itemMap, server); + } + + @Override + public JSONObject getDeviceStatusName() { + JSONObject jo = new JSONObject(); + String mode = ""; + String action = ""; + String move = ""; + if (this.getMode() == 0) { + mode = "未联机"; + } else if (this.getMode() == 1) { + mode = "单机"; + } else if (this.getMode() == 2) { + mode = "联机"; + } else if (this.getMode() == 3) { + mode = "运行中"; + } + + if (this.getAction() == 0) { + action = "禁止取放"; + } else if (this.getAction() == 1) { + action = "允许取货"; + } else if (this.getAction() == 2) { + action = "允许放货"; + } else if (this.getAction() == 3) { + action = "允许取放"; + } + + + if (this.getMove() == 0) { + move = "无货"; + } else if (this.getMove() == 1) { + move = "有货"; + } else if (this.getMove() == 2) { + move = "有托盘有货"; + } + jo.put("device_name", this.getDevice().getDevice_name()); + jo.put("mode", mode); + jo.put("move", move); + jo.put("action", action); + jo.put("isOnline", this.getIsonline()); + jo.put("error", this.getError()); + jo.put("isError", this.getIserror()); + return jo; + } + + @Override + public void setDeviceStatus(JSONObject data) { + + } +} diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AgvToAcsController.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AgvToAcsController.java new file mode 100644 index 0000000..c929928 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AgvToAcsController.java @@ -0,0 +1,37 @@ + +package org.nl.acs.ext.wms.rest; + + +import cn.dev33.satoken.annotation.SaIgnore; +import com.alibaba.fastjson.JSONObject; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.ext.wms.service.AgvToAcsService; +import org.nl.modules.logging.annotation.Log; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +/** + * + */ +@RestController +@RequiredArgsConstructor +@Api(tags = "wms接口") +@RequestMapping("api/agv") +@Slf4j +@CrossOrigin +public class AgvToAcsController { + private final AgvToAcsService agvToAcsService; + + @PostMapping("/waitpointRequest") + @Log("AGV到等待点请求继续执行") + @ApiOperation("AGV到等待点请求继续执行") + @SaIgnore + public ResponseEntity createFromWms(@RequestBody JSONObject param) { + return new ResponseEntity<>(agvToAcsService.waitpointRequest(param), HttpStatus.OK); + } + +} diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AgvToAcsService.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AgvToAcsService.java new file mode 100644 index 0000000..9939f39 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AgvToAcsService.java @@ -0,0 +1,17 @@ +package org.nl.acs.ext.wms.service; + + +import com.alibaba.fastjson.JSONObject; + +import java.util.Map; + +public interface AgvToAcsService { + /** + * 创建任务 + * + * @param jsonObject 条件 + * @return + */ + Map waitpointRequest(JSONObject jsonObject); + +} diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AgvToAcsServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AgvToAcsServiceImpl.java new file mode 100644 index 0000000..625a7ad --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AgvToAcsServiceImpl.java @@ -0,0 +1,87 @@ +package org.nl.acs.ext.wms.service.impl; + +import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device_driver.RouteUtil; +import org.nl.acs.device_driver.maGang.MaGangConveyorDeviceDriver; +import org.nl.acs.ext.wms.service.AgvToAcsService; +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.modules.common.exception.BadRequestException; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.Map; + +@Service +@RequiredArgsConstructor +@Slf4j +public class AgvToAcsServiceImpl implements AgvToAcsService { + + private final DeviceAppService deviceAppService; + private final InstructionService instructionService; + private final DeviceExecuteLogService logService; + + @Override + public Map waitpointRequest(JSONObject param) { + //指令号 + String inst_code = param.getString("task_code"); + //站点 + String address = param.getString("address"); + //车号 + String vehicle_code = param.getString("device_code"); + String deviceCode = RouteUtil.getDeviceCode(address); + Instruction instructionDto = instructionService.findByCode(inst_code); + if (ObjectUtil.isEmpty(instructionDto)) { + logService.deviceExecuteLog(deviceCode, vehicle_code, inst_code, "请求路径:api/agv/waitpointRequest,请求参数:" + param.toString() + ",请求失败-原因:指令任务号不存在! 指令号:" + inst_code); + throw new BadRequestException("请求失败,指令任务号不存在!"); + } + Device device = deviceAppService.findDeviceByCode(deviceCode); + MaGangConveyorDeviceDriver maGangConveyorDeviceDriver = (MaGangConveyorDeviceDriver) device.getDeviceDriver(); + Map map = new HashMap<>(); + map.put("status", 200); + map.put("message", "操作成功"); + if (address.contains("INGET")) { + if (maGangConveyorDeviceDriver.getMove() == 1) { + logService.deviceExecuteLog(deviceCode, vehicle_code, inst_code, "请求路径:api/agv/waitpointRequest,请求参数:" + param.toString() + ",请求成功-响应参数:" + map.toString()); + return map; + } else { + logService.deviceExecuteLog(deviceCode, vehicle_code, inst_code, "请求路径:api/agv/waitpointRequest,请求参数:" + param.toString() + ",请求失败-原因:取货前-取货点无货!"); + throw new BadRequestException("请求失败,取货前-取货点无货!"); + } + } else if (address.contains("OUTGET")) { + if (maGangConveyorDeviceDriver.getMove() == 0) { + maGangConveyorDeviceDriver.writing(2); + logService.deviceExecuteLog(deviceCode, vehicle_code, inst_code, "请求路径:api/agv/waitpointRequest,请求参数:" + param.toString() + ",请求成功-响应参数:" + map.toString()); + return map; + } else { + logService.deviceExecuteLog(deviceCode, vehicle_code, inst_code, "请求路径:api/agv/waitpointRequest,请求参数:" + param.toString() + ",请求失败-原因:取货完成后-取货点有货!"); + throw new BadRequestException("请求失败,取货完成后-取货点有货!"); + } + } else if (address.contains("INPUT")) { + if (maGangConveyorDeviceDriver.getMove() == 0) { + logService.deviceExecuteLog(deviceCode, vehicle_code, inst_code, "请求路径:api/agv/waitpointRequest,请求参数:" + param.toString() + ",请求成功-响应参数:" + map.toString()); + return map; + } else { + logService.deviceExecuteLog(deviceCode, vehicle_code, inst_code, "请求路径:api/agv/waitpointRequest,请求参数:" + param.toString() + ",请求失败-原因:放货前-放货点有货!"); + throw new BadRequestException("请求失败,放货前-放货点有货!"); + } + } else if (address.contains("OUTPUT")) { + if (maGangConveyorDeviceDriver.getMove() == 1) { + maGangConveyorDeviceDriver.writing(3); + logService.deviceExecuteLog(deviceCode, vehicle_code, inst_code, "请求路径:api/agv/waitpointRequest,请求参数:" + param.toString() + ",请求成功-响应参数:" + map.toString()); + return map; + } else { + logService.deviceExecuteLog(deviceCode, vehicle_code, inst_code, "请求路径:api/agv/waitpointRequest,请求参数:" + param.toString() + ",请求失败-原因:放货完成后-放货点无货!"); + throw new BadRequestException("请求失败,放货完成后-放货点无货!"); + } + } + logService.deviceExecuteLog(deviceCode, vehicle_code, inst_code, "请求路径:api/agv/waitpointRequest,请求参数:" + param.toString() + ",请求失败-原因:请求失败,地址有误! 地址:" + address); + throw new BadRequestException("请求失败,地址有误!"); + } +} diff --git a/acs/nladmin-system/src/main/java/org/nl/hand/amb/rest/HFHandController.java b/acs/nladmin-system/src/main/java/org/nl/hand/amb/rest/HFHandController.java index 65bf004..a199274 100644 --- a/acs/nladmin-system/src/main/java/org/nl/hand/amb/rest/HFHandController.java +++ b/acs/nladmin-system/src/main/java/org/nl/hand/amb/rest/HFHandController.java @@ -50,6 +50,16 @@ public class HFHandController { return new ResponseEntity<>(HandService.queryPointByArea(region), HttpStatus.OK); } + @PostMapping("/queryDevice") + @Log("查询设备起点和终点") + @ApiOperation("查询设备起点和终点") + @SaIgnore + //@PreAuthorize("@el.check('sect:list')") + //@RequestBody JSONObject json + public ResponseEntity queryDevice() { + return new ResponseEntity<>(HandService.queryDevice(), HttpStatus.OK); + } + @PostMapping("/point/storage") @Log("查询设备扩展属性") @ApiOperation("查询设备扩展属性") diff --git a/acs/nladmin-system/src/main/java/org/nl/hand/amb/service/HFHandService.java b/acs/nladmin-system/src/main/java/org/nl/hand/amb/service/HFHandService.java index b9f60d4..9fb9388 100644 --- a/acs/nladmin-system/src/main/java/org/nl/hand/amb/service/HFHandService.java +++ b/acs/nladmin-system/src/main/java/org/nl/hand/amb/service/HFHandService.java @@ -112,4 +112,11 @@ public interface HFHandService { Map queryMaterial(); Map createTask2(Map whereJson); + + /** + * 查询物料 + * + * @return Map + */ + Map queryDevice(); } diff --git a/acs/nladmin-system/src/main/java/org/nl/hand/amb/service/impl/HFHandServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/hand/amb/service/impl/HFHandServiceImpl.java index 7299687..9d94d1c 100644 --- a/acs/nladmin-system/src/main/java/org/nl/hand/amb/service/impl/HFHandServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/hand/amb/service/impl/HFHandServiceImpl.java @@ -11,8 +11,7 @@ import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; -import org.nl.acs.agv.server.MagicAgvService; -import org.nl.acs.agv.server.impl.MagicAgvServiceImpl; +import org.nl.acs.agv.server.XianGongAgvService; import org.nl.acs.device.service.DeviceService; import org.nl.acs.device.service.dto.DeviceDto; import org.nl.acs.device.service.impl.DeviceServiceImpl; @@ -318,24 +317,24 @@ public class HFHandServiceImpl implements HFHandService { // return resultJson; // } //判断起点有货,终点为空 - if (ObjectUtil.isEmpty(startDevice.getMaterial_type()) || Integer.parseInt(startDevice.getMaterial_type()) == 0) { - resultJson.put("code", "0"); - resultJson.put("desc", "起点必须有货"); - resultJson.put("result", ""); - return resultJson; - } - if (!ObjectUtil.isEmpty(nextDevice.getMaterial_type()) && !StrUtil.equals(nextDevice.getMaterial_type(), "0")) { - resultJson.put("code", "0"); - resultJson.put("desc", "终点必须为空"); - resultJson.put("result", ""); - return resultJson; - } - if(Boolean.parseBoolean(startDevice.getIslock()) || Boolean.parseBoolean(nextDevice.getIslock())){ - resultJson.put("code", "0"); - resultJson.put("desc", "起点或终点设备已被锁定"); - resultJson.put("result", ""); - return resultJson; - } +// if (ObjectUtil.isEmpty(startDevice.getMaterial_type()) || Integer.parseInt(startDevice.getMaterial_type()) == 0) { +// resultJson.put("code", "0"); +// resultJson.put("desc", "起点必须有货"); +// resultJson.put("result", ""); +// return resultJson; +// } +// if (!ObjectUtil.isEmpty(nextDevice.getMaterial_type()) && !StrUtil.equals(nextDevice.getMaterial_type(), "0")) { +// resultJson.put("code", "0"); +// resultJson.put("desc", "终点必须为空"); +// resultJson.put("result", ""); +// return resultJson; +// } +// if (Boolean.parseBoolean(startDevice.getIslock()) || Boolean.parseBoolean(nextDevice.getIslock())) { +// resultJson.put("code", "0"); +// resultJson.put("desc", "起点或终点设备已被锁定"); +// resultJson.put("result", ""); +// return resultJson; +// } if (StrUtil.isEmpty(priority)) { priority = "1"; } @@ -353,15 +352,17 @@ public class HFHandServiceImpl implements HFHandService { dto.setIs_delete("0"); dto.setMaterial(material_type); dto.setStart_point_code(start_devicecode); + dto.setStart_device_code(start_devicecode); dto.setNext_point_code(next_devicecode); + dto.setNext_device_code(next_devicecode); dto.setMaterial(material_type); dto.setTask_type(task_type); dto.setPriority(priority); dto.setVehicle_code(carrier); try { taskService.create(dto); - startDevice.setIslock("true"); - nextDevice.setIslock("true"); +// startDevice.setIslock("true"); +// nextDevice.setIslock("true"); } catch (Exception e) { resultJson.put("code", "2"); resultJson.put("desc", e.getMessage()); @@ -542,7 +543,7 @@ public class HFHandServiceImpl implements HFHandService { } String task_id = instwo.getString("task_id"); Instruction instdto = (Instruction) instwo.toJavaObject(Instruction.class); - MagicAgvService agvService = SpringContextHolder.getBean(MagicAgvServiceImpl.class); + XianGongAgvService agvService = SpringContextHolder.getBean(XianGongAgvService.class); InstructionService instructionService = SpringContextHolder.getBean(InstructionServiceImpl.class); /* 1 指令撤销 @@ -553,11 +554,8 @@ public class HFHandServiceImpl implements HFHandService { try { //agvService.deleteAgvInst(instwo.getString("instruction_code")); - if (StrUtil.isEmpty(instdto.getAgv_jobno())) { - instructionService.cancelNOSendAgv(inst_uuid); - } else { - agvService.deleteAgvInst(instdto.getInstruction_code()); - } + instructionService.cancel(inst_uuid); + agvService.deleteXZAgvInst(instdto.getInstruction_code()); } catch (Exception e) { jo.put("code", "2"); @@ -568,7 +566,7 @@ public class HFHandServiceImpl implements HFHandService { } if (type.equals("2")) { try { - agvService.sendAgvInstToMagic(instdto); + agvService.sendOrderSequencesToXZ(instdto); } catch (Exception e) { jo.put("code", "2"); jo.put("desc", "下发agv失败"); @@ -677,7 +675,7 @@ public class HFHandServiceImpl implements HFHandService { TaskDto acsTask = taskjo.toJavaObject(TaskDto.class); InstructionService instructionservice = SpringContextHolder.getBean(InstructionServiceImpl.class); InstructionDto instdto = instructionservice.findByTaskid(acsTask.getTask_id(), "instruction_status <2 "); - if (instdto != null){ + if (instdto != null) { jo.put("code", "0"); jo.put("desc", "有指令未完成!"); jo.put("result", new JSONObject()); @@ -764,5 +762,16 @@ public class HFHandServiceImpl implements HFHandService { return jo; } + @Override + public Map queryDevice() { + WQLObject wo = WQLObject.getWQLObject("acs_device"); + JSONArray resultJSONArray = wo.query("1 = 1", "device_code").getResultJSONArray(0); + JSONObject jo = new JSONObject(); + jo.put("code", "1"); + jo.put("desc", "查询成功"); + jo.put("result", resultJSONArray); + return jo; + } + } diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java b/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java index 760924e..c43e860 100644 --- a/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java +++ b/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java @@ -55,10 +55,10 @@ public class AutoCreateInst { String next_point_code = acsTask.getNext_point_code(); - if(StrUtil.equals(is_send,"0")){ + if (StrUtil.equals(is_send, "0")) { continue; } - if(StrUtil.equals(acsTask.getTask_type(),"1") || StrUtil.equals(acsTask.getTask_type(),"2")){ + if (StrUtil.equals(acsTask.getTask_type(), "1") || StrUtil.equals(acsTask.getTask_type(), "2")) { //校验路由关系 List shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); if (ObjectUtils.isEmpty(shortPathsList)) { diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvTaskStatus.java b/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvTaskStatus.java index c1e7d16..b4ca41f 100644 --- a/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvTaskStatus.java +++ b/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvTaskStatus.java @@ -43,16 +43,16 @@ public class QueryXZAgvTaskStatus { JSONObject one = (JSONObject) ja.get(i); String inst_code = one.getString("id"); Instruction inst = instructionService.findByInstCodeFromCache(inst_code); - if (ObjectUtil.isEmpty(inst)) - continue; + + if (ObjectUtil.isEmpty(inst)) continue; + //子任务状态 待以后处理 JSONArray blocks = JSONArray.parseArray(one.getString("blocks")); - for(int j=0;j + +
+ +
+ 设备协议: +
+ + + + OpcServer: + + + + + + PLC: + + + + + + +
+ + +
+ 输送系统: +
+ + + + + + + + + +
+ + +
+ 指令相关: +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ AGV相关: +
+ + + + + + + + + + + + + + +
+ + +
+ PLC读取字段: +
+ + + + + + + + + + + + + + +
+ + +
+ PLC写入字段: +
+ + + + + + + + + + + + + + +
+ + +
+ + 保存 + +
+
+ +
+ + + + + diff --git a/acs/nladmin-ui/src/views/login.vue b/acs/nladmin-ui/src/views/login.vue index 976355e..b27799f 100644 --- a/acs/nladmin-ui/src/views/login.vue +++ b/acs/nladmin-ui/src/views/login.vue @@ -2,7 +2,7 @@