From 1f7deafbf493aaf8bedb891cbcbe6fe5a2f597bd Mon Sep 17 00:00:00 2001 From: yanps Date: Thu, 23 Nov 2023 17:13:52 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E5=A2=9E=E5=8A=A0=E8=BE=93=E9=80=81?= =?UTF-8?q?=E6=9C=BA=E5=92=8C=E6=A0=87=E5=87=86-=E5=8D=95=E5=B7=A5?= =?UTF-8?q?=E4=BD=8D=E5=A0=86=E5=9E=9B=E6=9C=BA=E9=A9=B1=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../agv/server/impl/NDCAgvServiceImpl.java | 39 +- .../DequeCustomerDeviceStrategy.java | 4 +- .../DequeDefaultDeviceStrategy.java | 6 +- .../device/device_driver/DriverTypeEnum.java | 11 +- .../nl/acs/device/rest/DeviceController.java | 6 + .../service/impl/DeviceServiceImpl.java | 1 + .../device/service/mapper/DeviceMappers.java | 10 + .../belt_conveyor/BeltConveyorDefination.java | 61 ++ .../BeltConveyorDeviceDriver.java | 629 +++++++++++++++ .../belt_conveyor/ItemProtocol.java | 181 +++++ .../basedriver/belt_conveyor/Paper.java | 19 + .../plug_pull_device_site/ItemProtocol.java | 2 - .../standard_stacker/ItemProtocol.java | 352 ++++++++ .../StandardStackerDefination.java | 57 ++ .../StandardStackerDeviceDriver.java | 762 ++++++++++++++++++ .../device_driver/driver/OpcDeviceDriver.java | 18 +- .../service/InstructionService.java | 10 +- .../service/dto/InstructionDto.java | 5 + .../service/impl/InstructionServiceImpl.java | 200 ++--- .../nl/acs/opc/DeviceManageServiceImpl.java | 9 +- .../acs/route/service/RouteLineService.java | 2 + .../service/impl/RouteLineServiceImpl.java | 21 + .../src/views/acs/device/config.vue | 16 + .../views/acs/device/driver/belt_conveyor.vue | 539 +++++++++++++ .../acs/device/driver/standard_stacker.vue | 546 +++++++++++++ 25 files changed, 3356 insertions(+), 150 deletions(-) create mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/service/mapper/DeviceMappers.java create mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_conveyor/BeltConveyorDefination.java create mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_conveyor/BeltConveyorDeviceDriver.java create mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_conveyor/ItemProtocol.java create mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_conveyor/Paper.java create mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/standard_stacker/ItemProtocol.java create mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/standard_stacker/StandardStackerDefination.java create mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/standard_stacker/StandardStackerDeviceDriver.java create mode 100644 acs/nladmin-ui/src/views/acs/device/driver/belt_conveyor.vue create mode 100644 acs/nladmin-ui/src/views/acs/device/driver/standard_stacker.vue diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/impl/NDCAgvServiceImpl.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/impl/NDCAgvServiceImpl.java index 7159f25..d847644 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/impl/NDCAgvServiceImpl.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/impl/NDCAgvServiceImpl.java @@ -164,8 +164,41 @@ public class NDCAgvServiceImpl implements NDCAgvService { } + @Override + public byte[] sendAgvTwoModeInst(int phase, int index, int result) { + 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[] 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) 0X10, + (byte) phasehigh, (byte) phaselow + }; + + + 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 byte[] sendAgvTwoModeInst(int phase, int index, int result) { if (phase < 0 || index < 0) @@ -191,12 +224,12 @@ public class NDCAgvServiceImpl implements NDCAgvService { System.out.println("反馈agv动作数据:" + Bytes2HexString(b)); return b; - } + }*/ - @Override + /*@Override public byte[] sendAgvOneModeInst(int phase, int index, int result) { return new byte[0]; - } + }*/ @Override public boolean createChargingTaskToNDC(String carno) { diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/custompolicy/DequeCustomerDeviceStrategy.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/custompolicy/DequeCustomerDeviceStrategy.java index 6723a36..f7d1770 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/custompolicy/DequeCustomerDeviceStrategy.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/custompolicy/DequeCustomerDeviceStrategy.java @@ -37,8 +37,8 @@ public class DequeCustomerDeviceStrategy implements DeviceStrategy { } public WaitingInstructionDeque strategy(List instructions, String device_code) { - WaitingInstructionDeque deque = this.instructionService.findWaitingInstructionDequeByDeviceCode(device_code); + //WaitingInstructionDeque deque = this.instructionService.findWaitingInstructionDequeByDeviceCode(device_code); StackerStrategyDto cacheStragety = this.customerStragetyCacheService.getStragety(device_code); - return deque; + return null; } } diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/custompolicy/DequeDefaultDeviceStrategy.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/custompolicy/DequeDefaultDeviceStrategy.java index 68c9f86..b42f5ff 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/custompolicy/DequeDefaultDeviceStrategy.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/custompolicy/DequeDefaultDeviceStrategy.java @@ -26,7 +26,7 @@ public class DequeDefaultDeviceStrategy implements DeviceStrategy { } public WaitingInstructionDeque strategy(List instructions, String device_code) { - WaitingInstructionDeque deque = this.instructionService.findWaitingInstructionDequeByDeviceCode(device_code); + //WaitingInstructionDeque deque = this.instructionService.findWaitingInstructionDequeByDeviceCode(device_code); Map> factory = new HashMap(); Instruction instruction; @@ -52,11 +52,11 @@ public class DequeDefaultDeviceStrategy implements DeviceStrategy { String string = (String)var12.next(); List list2 = (List)factory.get(string); if (list2 != null && list2.size() > 0) { - deque.offerIfNotExists((Instruction)list2.get(0)); + //deque.offerIfNotExists((Instruction)list2.get(0)); } } - return deque; + return null; } } diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java index 171c793..217cfd6 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java @@ -27,7 +27,16 @@ public enum DriverTypeEnum { XGAGV(9, "xg_agv", "xg_agv", "agv"), - AUTODOOR(10, "standard_autodoor", "标准版-自动门", "autodoor"); + AUTODOOR(10, "standard_autodoor", "标准版-自动门", "autodoor"), + + STANDARD_STACKER(11,"standard_stacker","标准版-单工位堆垛机","stacker"), + + SIEMENS_CONVEYOR_LABELING(12,"siemens_conveyor_labeling","西门子-输送机驱动-贴标","conveyor"), + + SIEMENS_CONVEYOR(14,"siemens_conveyor","西门子-输送机驱动","conveyor"), + + BELT_CONVEYOR(13,"belt_conveyor","输送线","conveyor") + ; //驱动索引 private int index; diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/rest/DeviceController.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/rest/DeviceController.java index 03dd37c..4e4fa4f 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/rest/DeviceController.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/rest/DeviceController.java @@ -4,11 +4,14 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import org.nl.acs.device.device_driver.DriverTypeEnum; import org.nl.acs.device.device_driver.standard_inspect.OpcPlcDto; +import org.nl.acs.device.service.mapper.DeviceMapper; +import org.nl.acs.device.service.mapper.DeviceMappers; import org.nl.common.logging.annotation.Log; import org.nl.acs.device.domain.Device; import org.nl.acs.device.service.DeviceService; import org.nl.acs.device.service.dto.DeviceDto; import org.nl.acs.device.service.dto.DeviceQueryParam; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Pageable; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -38,6 +41,9 @@ public class DeviceController { private final DeviceService deviceService; + @Autowired + private DeviceMappers deviceMappers; + /* @Log("导出设备服务") @ApiOperation("导出设备服务") diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java index 890cf9d..b5cbffa 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java @@ -302,6 +302,7 @@ public class DeviceServiceImpl extends CommonServiceImpl i dto.setCreate_time(now); Device entity = ConvertUtil.convert(dto, Device.class); + deviceMapper.insert(entity); } diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/service/mapper/DeviceMappers.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/service/mapper/DeviceMappers.java new file mode 100644 index 0000000..b3610d3 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/service/mapper/DeviceMappers.java @@ -0,0 +1,10 @@ +package org.nl.acs.device.service.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.mybatis.spring.annotation.MapperScan; +import org.nl.acs.device.domain.Device; + +@Mapper +public interface DeviceMappers extends BaseMapper { +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_conveyor/BeltConveyorDefination.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_conveyor/BeltConveyorDefination.java new file mode 100644 index 0000000..bf9778d --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_conveyor/BeltConveyorDefination.java @@ -0,0 +1,61 @@ +package org.nl.acs.device_driver.basedriver.belt_conveyor; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device.domain.Device; +import org.nl.acs.device.enums.DeviceType; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +/** + * 油漆线 + */ +@Service +public class BeltConveyorDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "belt_conveyor"; + } + + @Override + public String getDriverName() { + return "标准版-输送机"; + } + + @Override + public String getDriverDescription() { + return "标准版-输送机"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new BeltConveyorDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return BeltConveyorDeviceDriver.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/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_conveyor/BeltConveyorDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_conveyor/BeltConveyorDeviceDriver.java new file mode 100644 index 0000000..ccac75e --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_conveyor/BeltConveyorDeviceDriver.java @@ -0,0 +1,629 @@ +package org.nl.acs.device_driver.basedriver.belt_conveyor; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +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.device.domain.Device; +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.domain.Instruction; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.monitor.DeviceStageMonitor; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.route.service.RouteLineService; +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.config.SpringContextHolder; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +/** + * 输送线 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class BeltConveyorDeviceDriver 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 + DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class); + @Autowired + AgvService agvService = SpringContextHolder.getBean(AgvService.class); + + private Date instruction_update_time = new Date(); + private Date require_apply_strangulation_time = new Date(); + private int instruction_update_time_out = 500; + 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 last_heartbeat = 0; + //工作模式 + int mode = 0; + int last_mode = 0; + //光电信号 + int move = 0; + int last_move = 0; + //托盘方向 + int container_direction = 0; + int last_container_direction = 0; + //报警 + int error = 0; + int last_error = 0; + //动作信号 + int action = 0; + int last_action = 0; + //任务号 + int task = 0; + int last_task = 0; + //托盘类型 + int container_type = 0; + int last_container_type = 0; + //纯数字托盘号 + int container_no = 0; + int last_container_no = 0; + + int inventory_qty = 0; + int out_finish = 0; + //下发命令 + int to_command = 0; + int last_to_command = 0; + //下发目标站 + int to_target = 0; + int last_to_target = 0; + //下发任务号 + int to_task = 0; + int last_to_task = 0; + //下发接纯数字托盘号 + int to_container_no = 0; + int last_to_container_no = 0; + //下发托盘类型 + int to_container_type = 0; + int last_to_container_type = 0; + + + + + //当前指令 + Instruction inst = null; + + String material = null; + + Boolean isonline = true; + + Boolean iserror = false; + + //1-执行任务;2-取货完成;3-放货完成; + int flag; + + + int last_inventory_qty = 0; + int last_out_finish = 0; + + String last_material = null; + String message = null; + String device_code; + String task_code = null; + String vehicle_code; + String inst_message; + + @Override + public Device getDevice() { + return this.device; + } + + //请求成功标记 + Boolean requireSucess = false; + + @Override + public void execute() { + try { + device_code = this.getDeviceCode(); + heartbeat = this.itemProtocol.getHeartbeat(); + mode = this.itemProtocol.getMode(); + move = this.itemProtocol.getMove(); + action = this.itemProtocol.getAction(); + container_direction = this.itemProtocol.getContainer_direction(); + container_type = this.itemProtocol.getContainer_type(); + error = this.itemProtocol.getError(); + task = this.itemProtocol.getTask(); + container_no = this.itemProtocol.getContainer_no(); + to_command = this.itemProtocol.getTo_command(); + to_target = this.itemProtocol.getTotarget(); + to_task = this.itemProtocol.getTo_task(); + to_container_no = this.itemProtocol.getContainer_direction(); + to_container_type = this.itemProtocol.getContainer_no(); + + if (mode != last_mode) { + JSONObject param = new JSONObject(); + param.put("device_code", this.device_code); + param.put("mode", Math.min(mode, 3)); + param.put("device_name", this.getDevice().getDevice_name()); + param.put("device_type", "1"); + requireSucess = false; + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode + "复位请求标记:" + requireSucess); + 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 (container_direction != last_container_direction) { + logServer.deviceItemValue(this.device_code, "carrier_direction", String.valueOf(container_direction)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号container_direction:" + last_container_direction + "->" + container_direction); + } + if (container_type != last_container_type) { + logServer.deviceItemValue(this.device_code, "carrier_direction", String.valueOf(container_type)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号container_type:" + last_container_type + "->" + container_type); + } + if (container_no != last_container_no) { + logServer.deviceItemValue(this.device_code, "carrier_direction", String.valueOf(container_no)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号container_no:" + last_container_no + "->" + container_no); + } + if (action != last_action) { + logServer.deviceItemValue(this.device_code, "carrier_direction", String.valueOf(action)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号action:" + last_action + "->" + action); + } + if (to_command != last_to_command) { + logServer.deviceItemValue(this.device_code, "carrier_direction", String.valueOf(to_command)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_command:" + last_to_command + "->" + to_command); + } + if (to_target != last_to_target) { + logServer.deviceItemValue(this.device_code, "carrier_direction", String.valueOf(to_target)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_target:" + last_to_target + "->" + to_target); + } + if (to_task != last_to_task) { + logServer.deviceItemValue(this.device_code, "carrier_direction", String.valueOf(to_task)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_task:" + last_to_task + "->" + to_task); + } + if (to_container_no != last_to_container_no) { + logServer.deviceItemValue(this.device_code, "carrier_direction", String.valueOf(to_container_no)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_task:" + last_to_container_no + "->" + to_container_no); + } + if (to_container_type != last_to_container_type) { + logServer.deviceItemValue(this.device_code, "carrier_direction", String.valueOf(to_container_type)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号to_task:" + last_to_container_type + "->" + to_container_type); + } + if (error != last_error) { + if (error != 0) { + + } + logServer.deviceItemValue(this.device_code, "error", String.valueOf(error)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号error:" + last_error + "->" + error); + } + if (task != last_task) { + logServer.deviceItemValue(this.device_code, "task", String.valueOf(task)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号task:" + last_task + "->" + task); + } + + + if (move != 0 && task > 0) { + update_instruction_status(); + } + + } catch (Exception var17) { + var17.printStackTrace(); + logServer.deviceExecuteLog(this.device_code, "", "", "读取信号值时出现异常:" + var17.getMessage() + ",this.itemProtocol is null:" + ObjectUtil.isEmpty(this.itemProtocol)); + } + + + if (mode == 0) { + this.setIsonline(false); + message = "未联机"; + } else if (error != 0) { + this.setIserror(true); + message = "有报警"; + } else { + this.setIsonline(true); + this.setIserror(false); + message = ""; + Instruction instruction = null; + List toInstructions; + + //纸管库申请任务 + switch (mode) { + case 1: + log.debug("弃用(留作兼容)"); + break; + case 2: + //申请任务 + if (task == 0 && !requireSucess) { + instruction_require(); + } + break; + case 3: + log.info("运行中"); + break; + case 4: + //申请出货 + if (move == 1 && !requireSucess) { + //request_for_shipment(String.valueOf(mode), item_out_seq_arr, item_out_qty_arr); + } + break; + default: + break; + } + } + last_heartbeat = heartbeat; + last_mode = mode; + last_move = move; + last_error = error; + last_container_direction = container_direction; + last_container_no = container_no; + last_container_type = container_type; + last_action = action; + last_task = task; + last_to_command = to_command; + last_to_target = to_target; + last_to_task = to_task; + last_to_container_no = to_container_no; + last_to_container_type = to_container_type; + + } + + + 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; + + Map itemMap = new HashMap(); + this.control(itemMap); + } + + + public void writing(Map map) { + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + Map itemMap = new LinkedHashMap<>(); + map.forEach((key, value) -> { + if (ObjectUtil.isNotEmpty(value)) { + itemMap.put(getToParam() + key, value); + } + }); + if (ObjectUtil.isNotEmpty(itemMap)) { + this.control(itemMap); + logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); + } + } + + + /*public synchronized void request_for_shipment(String mode, String item_out_seq_arr, int[] item_out_qty_arr) { + Date date = new Date(); + if (date.getTime() - this.require_apply_strangulation_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + } else { + this.require_apply_strangulation_time = date; + ApplyPaperActionRequest applyPaperActionRequest = new ApplyPaperActionRequest(); + applyPaperActionRequest.setDevice_code(this.device_code); + applyPaperActionRequest.setType("1"); + applyPaperActionRequest.setTask_code(String.valueOf(task)); + //获取出库顺序 + boolean contains = item_out_seq_arr.contains(","); + boolean contains1 = item_out_seq_arr.contains(","); + + if (contains) { + String[] split = item_out_seq_arr.split(","); + applyPaperActionRequest.setMaterial1(split[0]); + applyPaperActionRequest.setMaterial1(split[1]); + } else if (contains1) { + String[] split = item_out_seq_arr.split(","); + applyPaperActionRequest.setMaterial1(split[0]); + applyPaperActionRequest.setMaterial1(split[1]); + } else { + applyPaperActionRequest.setMaterial1(item_out_seq_arr); + } + if (item_out_qty_arr.length >= 1 && item_out_qty_arr.length < 4) { + applyPaperActionRequest.setQty1(String.valueOf(item_out_qty_arr[0])); + applyPaperActionRequest.setQty2(String.valueOf(item_out_qty_arr[1])); + } + ApplyPaperActionResponse applyPaperActionResponse = acsToWmsService.applyPaperActionRequest(applyPaperActionRequest); + if (ObjectUtil.isNull(applyPaperActionResponse)) { + message = "请求失败"; + requireSucess = false; + return; + } + Map map3 = new HashMap(); + if (applyPaperActionResponse.getstatus() == 200) { + map3.put("to_command", "4"); + this.writing(map3); + requireSucess = true; + logServer.deviceExecuteLog(this.device_code, "", "", "申请出纸管,返回参数:" + applyPaperActionResponse); + message = "申请出货成功"; + } else { + message = applyPaperActionResponse.getMessage(); + map3.put("to_command", "5"); + this.writing(map3); + requireSucess = false; + message = "出库顺序错误"; + logServer.deviceExecuteLog(this.device_code, "", "", "申请出纸管,返回参数:" + applyPaperActionResponse); + } + } + } +*/ + + /** + * 申请任务 + */ + public synchronized Boolean instruction_require() { + 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; + //查找有没有对应的指令 + //找指令类型是10的 + Instruction inst = instructionService.findByDeviceCodeFromCache(this.device_code); + if (ObjectUtil.isNotNull(inst) && "10".equals(inst.getInstruction_type())) { + Device nextdevice = deviceAppservice.findDeviceByCode(inst.getNext_device_code()); + String next_addr = nextdevice.getExtraValue().get("address").toString(); + TaskDto taskDto = taskserver.findByCodeFromCache(inst.getTask_code()); + //List paperArray = getPaperArray(null); + if (ObjectUtil.isEmpty(inst)) { + return false; + } + Map map = new HashMap(); + map.put("to_target", next_addr); + map.put("to_task", inst.getInstruction_code()); + map.put("to_command", "1"); + map.put("to_container_type", "1"); + map.put("to_container_no", "1"); + this.writing(map); + requireSucess = true; + return true; + } else { + //判断是否有相同起点的,任务状态就绪的任务 + //任务类型是10 + TaskDto taskdto = taskserver.findByStartCodeAndReady(device_code); + if (ObjectUtil.isNull(taskdto)) { + return false; + } + if (ObjectUtil.isNotNull(taskdto) && "1".equals(taskdto.getTask_type())) { + //判断指令的起点和当前的设备号相同 + if (!taskdto.getStart_device_code().equals(device_code)) { + return false; + } + //判断当前任务号是否存在指令 + String taskid = taskdto.getTask_id(); + String taskcode = taskdto.getTask_code(); + String priority = taskdto.getPriority(); + String start_point_code = taskdto.getStart_point_code(); + String start_device_code = taskdto.getStart_device_code(); + String route_plan_code = taskdto.getRoute_plan_code(); + String next_device_code = ""; + /** + * 开始平均分配 + */ + String this_coevice_code = taskserver.queryAssignedByDevice(device_code, taskdto.getNext_device_code()); + if (StrUtil.isEmpty(this_coevice_code)) { + List shortPathsList = routeLineService.getShortPathLines(start_device_code, taskdto.getNext_device_code(), route_plan_code); + RouteLineDto routeLineDto = shortPathsList.get(0); + + String path = routeLineDto.getPath(); + String type = routeLineDto.getType(); + String[] str = path.split("->"); + + List pathlist = Arrays.asList(str); + int index = 0; + for (int m = 0; m < pathlist.size(); m++) { + if (pathlist.get(m).equals(start_device_code)) { + index = m + 1; + break; + } + } + next_device_code = pathlist.get(index); + } else { + next_device_code = this_coevice_code; + } + //校验路由关系 + List shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); + if (ObjectUtils.isEmpty(shortPathsList) || shortPathsList.size()<1) { + throw new RuntimeException("路由不通!"); + } + Device startdevice = deviceAppservice.findDeviceByCode(start_device_code); + Device nextdevice = deviceAppservice.findDeviceByCode(next_device_code); + String next_point_code; + if (StrUtil.equals(deviceAppservice.findDeviceTypeByCode(next_device_code), "storage")) { + next_point_code = taskdto.getTo_x() + "-" + taskdto.getTo_y() + "-" + taskdto.getTo_z(); + } else { + next_point_code = next_device_code; + } + Instruction instdto = new Instruction(); + instdto.setInstruction_id(IdUtil.simpleUUID()); + instdto.setRoute_plan_code(route_plan_code); + instdto.setRemark(taskdto.getRemark()); + instdto.setMaterial(taskdto.getMaterial()); + instdto.setQuantity(taskdto.getQuantity()); + instdto.setTask_id(taskid); + instdto.setTask_code(taskcode); + String now = DateUtil.now(); + instdto.setCreate_time(now); + instdto.setCreate_by("auto"); + instdto.setStart_device_code(start_device_code); + instdto.setNext_device_code(next_device_code); + instdto.setStart_point_code(start_point_code); + instdto.setNext_point_code(next_point_code); + instdto.setPriority(priority); + instdto.setInstruction_status("0"); + instdto.setExecute_device_code(start_point_code); + log.error("=================================,{}",instdto.getCreate_by()); + try { + instructionService.create(instdto); + } catch (Exception e) { + e.printStackTrace(); + log.error("指令创建失败!", e.getMessage()); + return false; + } + taskdto.setTask_status("1"); + taskserver.update(taskdto); + requireSucess = true; + Map map = new HashMap(); + String next_addr = nextdevice.getExtraValue().get("address").toString(); + map.put("to_target", next_addr); + map.put("to_task", instdto.getInstruction_code()); + map.put("to_command", "1"); + map.put("to_container_type", "1"); + map.put("to_container_no", "1"); + this.writing(map); + requireSucess = true; + return true; + } + } + return false; + } + } + + public void writeData(String next_addr, Instruction instdto, Map map) { + + } + + public String getToParam() { + return this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "."; + } + + + + public void writing(String key, String param) { + + String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + param; + //String opcservcerid = this.getDevice().getOpc_server_id(); + //Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + + itemMap.put(to_param, Integer.parseInt(param)); + //itemMap.put(to_param, Integer.parseInt(value)); + this.control(itemMap); + logServer.deviceExecuteLog(device_code, "", "", "下发电气信号设备号:" + device_code + ",下发电气:" + to_param + ",下发电气值:" + param); + } + + public synchronized boolean finish_instruction() throws Exception { + instructionService.finish(inst); + return true; + } + + @Override + public JSONObject getDeviceStatusName() { + JSONObject jo = new JSONObject(); + String mode = ""; + + if (this.getMode() == 0) { + mode = "未联机"; + } else if (this.getMode() == 1) { + mode = "单机"; + } else if (this.getMode() == 2) { + mode = "联机"; + } else if (this.getMode() == 3) { + mode = "入库中"; + } else if (this.getMode() == 4) { + mode = "出库中"; + } + jo.put("device_name", this.getDevice().getDevice_name()); + jo.put("mode", mode); + //jo.put("error", ErrorUtil.getDictDetail("ssx_error_type", String.valueOf(this.getError()))); + jo.put("inventory_qty", inventory_qty); + jo.put("out_finish", out_finish); + jo.put("material", material); + jo.put("isOnline", this.getIsonline()); + + return jo; + } + + + + /** + * 更新指令状态 + */ + public synchronized void update_instruction_status() throws Exception { + Date date = new Date(); + if (date.getTime() - this.instruction_update_time.getTime() < (long) this.instruction_update_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_update_time_out); + } else { + this.instruction_update_time = date; + inst = checkInst(); + if (inst != null) { + //a点到b点,给状态说允许取货 + if (StrUtil.equals(inst.getInstruction_status(), "0") && StrUtil.equals(this.getDeviceCode(), inst.getStart_device_code())) { + inst.setInstruction_status("1"); + inst.setExecute_device_code(this.device_code); + instructionService.update(inst); + logServer.deviceExecuteLog(device_code, "", "", "入库输送线任务开始反馈执行中状态,反馈成功,指令号:" + task); + } + //当货物到达b点,实现完成指令 + if (StrUtil.equals(inst.getInstruction_status(), "1") || StrUtil.equals(inst.getInstruction_status(), "0")) { + if (StrUtil.equals(this.getDeviceCode(), inst.getNext_device_code())) { + inst.setExecute_device_code(this.device_code); + finish_instruction(); + logServer.deviceExecuteLog(device_code, "", "", "入库输送线任务开始反馈完成状态,反馈成功,指令号:" + task); + } + } + } + } + } + + public Instruction checkInst() { + if (ObjectUtil.isNotEmpty(this.inst)) { + if (this.task > 0) { + if (this.inst.getInstruction_code().equals(String.valueOf(this.task))) { + return this.inst; + } else { + inst = instructionService.findByCodeFromCache(String.valueOf(task)); + return inst; + } + } + } else { + inst = instructionService.findByCodeFromCache(String.valueOf(task)); + return inst; + } + return null; + } + + + @Override + public void setDeviceStatus(JSONObject data) { + + } + + public static boolean arrayEquals(int[] a, int[] b) { + // 判断两个数组长度是否相等 + if (a.length != b.length) { + return false; + } + // 判断两个数组对应位置上的元素是否相同 + for (int i = 0; i < a.length; i++) { + if (a[i] != b[i]) { + return false; + } + } + return true; + } +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_conveyor/ItemProtocol.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_conveyor/ItemProtocol.java new file mode 100644 index 0000000..a9a0f75 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_conveyor/ItemProtocol.java @@ -0,0 +1,181 @@ +package org.nl.acs.device_driver.basedriver.belt_conveyor; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +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_container_direction = "container_direction"; + //托盘类型 + public static String item_container_type = "container_type"; + //任务号 + public static String item_task = "task"; + //出数字托盘号 + public static String item_container_no = "container_no"; + + //下发命令 + public static String item_to_command = "to_command"; + //下发托盘类型 + public static String item_to_container_type = "to_container_type"; + //下发接纯数字托盘号 + public static String item_to_container_no = "to_container_no"; + //下发任务号 + public static String item_to_task = "to_task"; + //下发目标站 + public static String item_to_target = "to_target"; + + + + private BeltConveyorDeviceDriver driver; + + public ItemProtocol(BeltConveyorDeviceDriver driver) { + this.driver = driver; + } + + + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getMove() { + return this.getOpcIntegerValue(item_move); + } + + public int getContainer_direction() { + return this.getOpcIntegerValue(item_container_direction); + } + + public int getContainer_type() { + return this.getOpcIntegerValue(item_container_type); + } + + public int getAction() { + return this.getOpcIntegerValue(item_action); + } + + public int getContainer_no() { + return this.getOpcIntegerValue(item_container_no); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getTask() { + return this.getOpcIntegerValue(item_task); + } + + public int getTo_task() { + return this.getOpcIntegerValue(item_to_task); + } + + + public int getTotarget() { + return this.getOpcIntegerValue(item_to_target); + } + + public int getTo_command() { + return this.getOpcIntegerValue(item_to_command); + } + + public int getTo_container_type() { + return this.getOpcIntegerValue(item_to_container_type); + } + + public int getTo_container_no() { + return this.getOpcIntegerValue(item_to_container_no); + } + + 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 String getOpcStringValue(String protocol) { + String value = this.driver.getStringValue(protocol); + if (StrUtil.isBlank(value)) { + + } else { + return value; + } + return "0"; + } + + public int[] getOpcArrayValue(String protocol) { + int[] arrayValue = this.driver.getIntegeregerArrayValue(protocol); + if (ObjectUtil.isNull(arrayValue)) { + + } else { + return arrayValue; + } + return new int[3]; + } + + + + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB101.B0")); + list.add(new ItemDto(item_mode, "工作模式", "DB101.B2")); + list.add(new ItemDto(item_move, "光电信号", "DB101.B3")); + list.add(new ItemDto(item_container_direction, "托盘方向", "DB101.B4")); + list.add(new ItemDto(item_container_type, "托盘类型", "DB101.B5")); + list.add(new ItemDto(item_container_no, "纯数字托盘号", "DB101.D7")); + list.add(new ItemDto(item_action, "动作类型", "DB101.B6")); + list.add(new ItemDto(item_error, "报警", "DB101.B58")); + list.add(new ItemDto(item_task, "任务号", "DB101.D68")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_target , "下发仓位号", "DB102.W2")); + list.add(new ItemDto(item_to_command, "下发命令", "DB102.W4")); + list.add(new ItemDto(item_to_task, "下发任务号", "DB102.D1")); + list.add(new ItemDto(item_to_container_no, "下发接纯数字托盘号", "DB102.D3")); + list.add(new ItemDto(item_to_container_type, "下发托盘类型", "DB102.B5")); + return list; + } + + @Override + public String toString() { + return ""; + } + +} + diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_conveyor/Paper.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_conveyor/Paper.java new file mode 100644 index 0000000..9e6f9b2 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/belt_conveyor/Paper.java @@ -0,0 +1,19 @@ +package org.nl.acs.device_driver.basedriver.belt_conveyor; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class Paper implements Serializable { + //设备号 + private String device_code; + // + private String material_code; + private String qty; + +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/ItemProtocol.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/ItemProtocol.java index 68656c2..a0bc28f 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/ItemProtocol.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/plug_pull_device_site/ItemProtocol.java @@ -139,7 +139,6 @@ public class ItemProtocol { list.add(new ItemDto(item_6pull_times, "6寸轴拔轴次数", "30237")); list.add(new ItemDto(item_plug_alltimes, "穿轴总次数", "30239")); list.add(new ItemDto(item_pull_alltimes, "拔轴总次数", "30241")); - return list; } @@ -148,7 +147,6 @@ public class ItemProtocol { list.add(new ItemDto(item_to_command, "下发命令", "40246")); list.add(new ItemDto(item_to_type, "类型", "40244")); list.add(new ItemDto(item_to_size, "尺寸", "40247")); - return list; } diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/standard_stacker/ItemProtocol.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/standard_stacker/ItemProtocol.java new file mode 100644 index 0000000..b6a6f35 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/standard_stacker/ItemProtocol.java @@ -0,0 +1,352 @@ +package org.nl.acs.device_driver.basedriver.standard_stacker; + +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_deviceCode = "deviceCode"; + + //工作模式 + public static String item_mode = "mode"; + + //作业状态 + public static String item_command = "command"; + + //任务号 + public static String item_task = "task"; + + //y轴报警(载货台) + public static String item_error = "error"; + + //行走排号 + public static String item_z = "z"; + + //行走列号 + public static String item_x = "x"; + + //行走层号 + public static String item_y = "y"; + + //行走开关信号 + public static String item_move = "move"; + + //载货台开关信号 + public static String item_cargoMove = "cargoMove"; + + //行走动作信号 + public static String item_action = "action"; + + //行走激光数值 + public static String item_distancex = "distancex"; + + //起升激光数值 + public static String item_distancey = "distancey"; + + //载货台超限信号 + public static String item_cargoError = "cargoError"; + + //货叉探货信号 + public static String item_forkCargo = "forkCargo"; + + //货叉位置信号 + public static String item_forkLocation = "forkLocation"; + + //货叉动作信号 + public static String item_forkAction = "forkAction"; + //特殊开关量1 + public static String item_special1 = "special1"; + //特殊开关量2 + public static String item_special2 = "special2"; + //托盘条码 + public static String item_trayCode = "trayCode"; + //水箱和消防缓存位有无货 + public static String item_storage_cache = "storage_cache"; + //速度(转/分钟) + public static String item_stacker_rpm = "stacker_rpm"; + //电流 + public static String item_stacker_electricCurrent = "stacker_electric Current"; + + //轴运行次数 + public static String item_stacker_runing_time = "stacker_runing time"; + //轴工作时间(小时) + public static String item_stacker_workingHours = "stacker_workingHours"; + //载货台速度(转/分钟) + public static String item_cargo_rpm = "cargo_rpm"; + //载货台电流 + public static String item_cargo_electric_Current = "cargo_electric Current"; + //载货台轴工作小时数 + public static String item_cargo_workingHours = "cargo_workingHours"; + //载货台轴运行次数 + public static String item_cargo_runingTimes = "cargo_runingTimes"; + //货叉速度(转/分钟) + public static String item_fork_rpm = "fork_rpm"; + //货叉电流 + public static String item_fork_electric_Current = "fork_electric Current"; + + //货叉轴工作时间(小时) + public static String item_fork_workingHours = "fork_workingHours"; + //货叉轴运行次数 + public static String item_fork_runingTimes = "fork_runingTimes"; + + //心跳 + public static String item_to_heartbeat = "to_heartbeat"; + + //堆垛机号 + public static String item_to_device_code = "to_device_code"; + //作业命令 + public static String item_to_command = "to_command"; + //物料类型 + public static String item_to_type = "to_type"; + //任务号 + public static String item_to_task = "to_task"; + //作业排 + public static String item_to_z = "to_z"; + //作业列 + public static String item_to_x = "to_x"; + //作业层 + public static String item_to_y = "to_y"; + //托盘号 + public static String item_to_trayCode = "to_trayCode"; + + + Boolean isonline; + + private StandardStackerDeviceDriver driver; + + public ItemProtocol(StandardStackerDeviceDriver driver) { + this.driver = driver; + } + + public Integer getItem_heartbeat(){ + return this.getOpcIntegerValue(item_heartbeat); + } + public Integer getItem_deviceCode(){ + return this.getOpcIntegerValue(item_deviceCode); + } + public Integer getItem_mode(){ + return this.getOpcIntegerValue(item_mode); + } ; + public Integer getItem_command(){ + return this.getOpcIntegerValue(item_command); + } + public Integer getItem_task(){ + return this.getOpcIntegerValue(item_task); + } + public Integer getItem_error(){ + return this.getOpcIntegerValue(item_error); + } + public Integer getItem_z(){ + return this.getOpcIntegerValue(item_z); + } + public Integer getItem_x(){ + return this.getOpcIntegerValue(item_x); + } + public Integer getItem_y(){ + return this.getOpcIntegerValue(item_y); + } + public float getItem_move(){ + return this.getOpcFloatValue(item_move); + } + public float getItem_cargoMove(){ + return this.getOpcFloatValue(item_cargoMove); + } + public float getItem_action(){ + return this.getOpcFloatValue(item_action); + } + public Integer getItem_distancex(){ + return this.getOpcIntegerValue(item_distancex); + } + public Integer getItem_distancey(){ + return this.getOpcIntegerValue(item_distancey); + } + public float getItem_cargoError(){ + return this.getOpcFloatValue(item_cargoError); + } + public float getItem_forkCargo(){ + return this.getOpcFloatValue(item_forkCargo); + } + public float getItem_forkLocation(){ + return this.getOpcFloatValue(item_forkLocation); + } + public float getItem_forkAction(){ + return this.getOpcFloatValue(item_forkAction); + } + public float getItem_special1(){ + return this.getOpcFloatValue(item_special1); + } + public float getItem_special2(){ + return this.getOpcFloatValue(item_special2); + } + public int[] getItem_trayCode(){ + return this.getOpcIntegerArrayValue(item_trayCode); + } + public float getItem_storage_cache(){ + return this.getOpcFloatValue(item_storage_cache); + } + public Integer getItem_stacker_rpm(){ + return this.getOpcIntegerValue(item_stacker_rpm); + } + public Integer getItem_stacker_electricCurrent(){ + return this.getOpcIntegerValue(item_stacker_electricCurrent); + } + public Integer getItem_stacker_workingHours(){ + return this.getOpcIntegerValue(item_stacker_workingHours); + } + public Integer getItem_stacker_runing_time(){ + return this.getOpcIntegerValue(item_stacker_runing_time); + } + public Integer getItem_cargo_rpm(){ + return this.getOpcIntegerValue(item_cargo_rpm); + } + public Integer getItem_cargo_electric_Current(){ + return this.getOpcIntegerValue(item_cargo_electric_Current); + } + public Integer getItem_cargo_workingHours(){ + return this.getOpcIntegerValue(item_cargo_workingHours); + } + public Integer getItem_cargo_runingTimes(){ + return this.getOpcIntegerValue(item_cargo_runingTimes); + } + public Integer getItem_fork_rpm(){ + return this.getOpcIntegerValue(item_fork_rpm); + } + public Integer getItem_fork_electric_Current(){ + return this.getOpcIntegerValue(item_fork_electric_Current); + } + public Integer getItem_fork_workingHours(){ + return this.getOpcIntegerValue(item_fork_workingHours); + } + public Integer getItem_fork_runingTimes(){ + return this.getOpcIntegerValue(item_fork_runingTimes); + } + + + + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + } + + public String getOpcStringValue(String protocol) { + String value = this.driver.getStringValue(protocol); + if (value == null) { + setIsonline(false); + return "0"; + } else { + setIsonline(true); + return value; + } + } + + public int[] getOpcIntegerArrayValue(String protocol) { + int[] value = this.driver.getIntegerArrayValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return new int[20]; + } + + public float getOpcFloatValue(String protocol) { + Float value = this.driver.getDoubleValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + } + + + public Long getOpcLongValue(String protocol) { + Long value = this.driver.getLongValue(protocol); + if (value == null) { + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0L; + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB101.BO")); + list.add(new ItemDto(item_deviceCode, "堆垛机号", "DB101.B1")); + list.add(new ItemDto(item_mode, "工作模式", "DB101.B2")); + list.add(new ItemDto(item_command, "作业状态", "DB101.B3")); + list.add(new ItemDto(item_task, "任务号", "DB101.D4")); + list.add(new ItemDto(item_error, "Y轴报警(载货台)", "DB101.B8")); + list.add(new ItemDto(item_z, "行走排号", "DB101.B9")); + list.add(new ItemDto(item_x, "行走列号", "DB101.B10")); + list.add(new ItemDto(item_y, "行走层号", "DB101.B11")); + list.add(new ItemDto(item_move, "行走开关信号", "DB101.B12")); + list.add(new ItemDto(item_cargoMove, "载货台开关信号", "DB101.B13")); + list.add(new ItemDto(item_action, "行走动作信号", "DB101.B14")); + list.add(new ItemDto(item_distancex, "行走激光数值", "DB101.D16")); + list.add(new ItemDto(item_distancey, "起升激光数值", "DB101.D20")); + list.add(new ItemDto(item_cargoError, "载货台超限信号", "DB101.B24")); + list.add(new ItemDto(item_forkCargo, "货叉探货信号", "DB101.B25")); + list.add(new ItemDto(item_forkLocation, "货叉位置信号", "DB101.B26")); + list.add(new ItemDto(item_forkAction, "货叉动作信号", "DB101.B27")); + list.add(new ItemDto(item_special1, "特殊开关量1", "DB101.B28")); + list.add(new ItemDto(item_special2, "特殊开关量2", "DB101.B29")); + list.add(new ItemDto(item_trayCode, "托盘条码", "DB101.B30.20")); + list.add(new ItemDto(item_storage_cache, "水箱和消防缓存位有无货", "DB101.B50")); + list.add(new ItemDto(item_stacker_rpm, "速度(转/分钟)", "DB101.W52")); + list.add(new ItemDto(item_stacker_electricCurrent, "电流", "DB101.W54")); + list.add(new ItemDto(item_stacker_workingHours, "轴工作时间(小时)", "DB101.D56")); + list.add(new ItemDto(item_stacker_runing_time, "轴运行次数", "DB101.D60")); + list.add(new ItemDto(item_cargo_rpm, "载货台速度(转/分钟)", "DB101.W64")); + list.add(new ItemDto(item_cargo_electric_Current, "载货台电流", "DB101.W66")); + list.add(new ItemDto(item_cargo_workingHours, "载货台轴工作小时数", "DB101.D68")); + list.add(new ItemDto(item_cargo_runingTimes, "载货台轴运行次数", "DB101.D72")); + list.add(new ItemDto(item_fork_rpm, "货叉速度(转/分钟)", "DB101.W76")); + list.add(new ItemDto(item_fork_electric_Current, "货叉电流", "DB101.W78")); + list.add(new ItemDto(item_fork_workingHours, "货叉轴工作时间(小时)", "DB101.D80")); + list.add(new ItemDto(item_fork_runingTimes, "货叉轴运行次数", "DB101.D84")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_heartbeat, "心跳", "DB100.B0")); + list.add(new ItemDto(item_to_device_code, "堆垛机号", "DB100.B1")); + list.add(new ItemDto(item_to_command, "作业命令", "DB100.B2")); + list.add(new ItemDto(item_to_type, "物料类型", "DB100.B3")); + list.add(new ItemDto(item_to_task, "任务号", "DB100.D4")); + list.add(new ItemDto(item_to_z, "作业排", "DB100.B8")); + list.add(new ItemDto(item_to_x, "作业列", "DN100.B9")); + list.add(new ItemDto(item_to_y, "作业层", "DB100.B10")); + list.add(new ItemDto(item_to_trayCode, "托盘号", "DB100.B11.20")); + return list; + } + + + @Override + public String toString() { + return ""; + } + +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/standard_stacker/StandardStackerDefination.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/standard_stacker/StandardStackerDefination.java new file mode 100644 index 0000000..a5956d5 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/standard_stacker/StandardStackerDefination.java @@ -0,0 +1,57 @@ +package org.nl.acs.device_driver.basedriver.standard_stacker; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device.domain.Device; +import org.nl.acs.device.enums.DeviceType; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +@Service +public class StandardStackerDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "standard_stacker"; + } + + @Override + public String getDriverName() { + return "标准版-单工位堆垛机"; + } + + @Override + public String getDriverDescription() { + return "标准版-单工位堆垛机"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new StandardStackerDeviceDriver()).setDevice(device).setDriverDefination(this); + } + + @Override + public Class getDeviceDriverType() { + return StandardStackerDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.stacker); + return types; + } + + @Override + public List getReadableItemDtos() { + return ItemProtocol.getReadableItemDtos(); + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/standard_stacker/StandardStackerDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/standard_stacker/StandardStackerDeviceDriver.java new file mode 100644 index 0000000..32d9323 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/standard_stacker/StandardStackerDeviceDriver.java @@ -0,0 +1,762 @@ +package org.nl.acs.device_driver.basedriver.standard_stacker; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; +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.device.domain.Device; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.basedriver.belt_conveyor.BeltConveyorDeviceDriver; +import org.nl.acs.device_driver.basedriver.siemens_conveyor.SiemensConveyorDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.instruction.domain.Instruction; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.monitor.DeviceStageMonitor; +import org.nl.acs.opc.DeviceAppService; +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.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; +import org.nl.config.SpringContextHolder; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +/** + * 单工位堆垛机驱动 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + @Autowired + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineServiceImpl.class); + + + //心跳 + Integer heartbeat = 0; + Integer last_heartbeat = 0; + //堆垛机号 + Integer item_deviceCode = 0; + Integer last_item_deviceCode = 0; + //工作模式 + Integer mode = 0; + Integer last_mode = 0; + //作业状态 + Integer command = 0; + Integer last_command = 0; + //任务号 + Integer task = 0; + Integer last_task = 0; + //y轴报警(载货台) + Integer error = 0; + Integer last_error = 0; + //行走排号 + Integer z = 0; + Integer last_z = 0; + //行走列号 + Integer x = null; + Integer last_x = null; + //行走层号 + Integer y = 0; + Integer last_y = 0; + //行走开关信号 + Float move = 0F; + Float last_move = 0F; + //载货台开关信号 + Float cargoMove = 0F; + Float last_cargoMove = 0F; + //行走动作信号 + Float action = 0F; + Float last_action = 0F; + //行走激光数值 + Integer distancex = 0; + Integer last_distancex = 0; + //起升激光数值 + Integer distancey = 0; + Integer last_distancey = 0; + //载货台超限信号 + Float cargoError = 0F; + Float last_cargoError = 0F; + //货叉探货信号 + Float forkCargo = 0F; + Float last_forkCargo = 0F; + //货叉位置信号 + Float forkLocation = 0F; + Float last_forkLocation = 0F; + //货叉动作信号 + Float forkAction = 0F; + Float last_forkAction = 0F; + //特殊开关量1 + Float special1 = 0F; + Float last_special1 = 0F; + //特殊开关量2 + Float special2 = 0F; + Float last_special2 = 0F; + //托盘条码 + int[] trayCode; + int[] last_trayCode; + //水箱和消防缓存位有无货 + Float storage_cache = 0F; + Float last_storage_cache = 0F; + /*//速度(转/分钟) + Integer stacker_rpm = 0; + Integer last_stacker_rpm = 0; + //电流 + Integer stacker_electricCurrent = 0; + Integer last_stacker_electricCurrent = 0; + //轴运行次数 + Integer stacker_runing_time = 0; + Integer last_stacker_runing_time = 0; + //轴工作时间(小时) + Integer stacker_workingHours = 0; + Integer last_stacker_workingHours = 0; + //载货台速度(转/分钟) + Integer cargo_rpm = 0; + Integer last_cargo_rpm = 0; + //载货台电流 + Integer cargo_electric_Current = 0; + Integer last_cargo_electric_Current = 0; + //载货台轴工作小时数 + Integer cargo_workingHour = 0; + Integer last_cargo_workingHour = 0; + //载货台轴运行次数 + Integer cargo_runingTimes = 0; + Integer last_cargo_runingTimes = 0; + //货叉速度(转/分钟) + Integer fork_rpm = 0; + Integer last_fork_rpm = 0; + //货叉电流 + Integer fork_electric_Current = 0; + Integer last_fork_electric_Current = 0; + //货叉轴工作时间(小时) + Integer fork_workingHours = 0; + Integer last_fork_workingHours = 0; + //货叉轴运行次数 + Integer fork_runingTimes = 0; + Integer last_fork_runingTimes = 0;*/ + + String message = null; + + String device_code = null; + + String notCreateInstMessage = null; + + private int instruction_require_time_out = 3000; + private int instruction_update_time_out = 3000; + private Date instruction_require_time = new Date(); + private Date instruction_update_time = new Date(); + List getDeviceCodeList = null; + List putDeviceCodeList = null; + + //请求成功标记 + Boolean requireSucess = false; + + //当前指令 + Instruction inst = null; + + + @Override + public Device getDevice() { + return this.device; + } + + @Override + public void execute() throws Exception { + try { + device_code = this.getDeviceCode(); + heartbeat = this.itemProtocol.getItem_heartbeat(); + item_deviceCode = this.itemProtocol.getItem_deviceCode(); + mode = this.itemProtocol.getItem_mode(); + command = this.itemProtocol.getItem_command(); + task = this.itemProtocol.getItem_task(); + error = this.itemProtocol.getItem_error(); + z = this.itemProtocol.getItem_z(); + x = this.itemProtocol.getItem_x(); + y = this.itemProtocol.getItem_y(); + move = this.itemProtocol.getItem_move(); + cargoMove = this.itemProtocol.getItem_cargoMove(); + action = this.itemProtocol.getItem_action(); + distancex = this.itemProtocol.getItem_distancex(); + distancey = this.itemProtocol.getItem_distancey(); + cargoError = this.itemProtocol.getItem_cargoError(); + forkCargo = this.itemProtocol.getItem_forkCargo(); + forkLocation = this.itemProtocol.getItem_forkLocation(); + forkAction = this.itemProtocol.getItem_forkAction(); + special1 = this.itemProtocol.getItem_special1(); + special2 = this.itemProtocol.getItem_special2(); + trayCode = this.itemProtocol.getItem_trayCode(); + storage_cache = this.itemProtocol.getItem_storage_cache(); + /*stacker_rpm = this.itemProtocol.getstacker_rpm(); + stacker_electricCurrent = this.itemProtocol.getstacker_electricCurrent(); + stacker_runing_time = this.itemProtocol.getstacker_runing_time(); + stacker_workingHours = this.itemProtocol.getstacker_workingHours(); + cargo_rpm = this.itemProtocol.getcargo_rpm(); + cargo_electric_Current = this.itemProtocol.getcargo_electric_Current(); + cargo_workingHour = this.itemProtocol.getcargo_workingHours(); + cargo_runingTimes = this.itemProtocol.getcargo_runingTimes(); + fork_rpm = this.itemProtocol.getfork_rpm(); + fork_electric_Current = this.itemProtocol.getfork_electric_Current(); + fork_workingHours = this.itemProtocol.getfork_workingHours(); + fork_runingTimes = this.itemProtocol.getfork_runingTimes();*/ + + if (!item_deviceCode.equals(last_item_deviceCode)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(item_deviceCode)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_item_deviceCode + "->" + item_deviceCode); + } + if (!mode.equals(last_mode)) { + requireSucess = false; + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); + } + if (!command.equals(last_command)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(command)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_command + "->" + command); + } + if (!task.equals(last_task)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_task + "->" + task); + } + if (!error.equals(last_error)) { + if (0 != error) { + } + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(error)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_error + "->" + error); + } + if (!z.equals(last_z)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(z)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_z + "->" + z); + } + if (!x.equals(last_x)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(x)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_x + "->" + x); + } + if (!y.equals(last_y)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(y)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_y + "->" + y); + } + if (!move.equals(last_move)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(move)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_move + "->" + move); + } + if (!cargoMove.equals(last_cargoMove)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(cargoMove)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_cargoMove + "->" + cargoMove); + } + if (!action.equals(last_action)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(action)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_action + "->" + action); + } + if (!distancex.equals(last_distancex)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(distancex)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_distancex + "->" + distancex); + } + if (!distancey.equals(last_distancey)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(distancey)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_distancey + "->" + distancey); + } + if (!cargoError.equals(last_cargoError)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(cargoError)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_cargoError + "->" + cargoError); + } + if (!forkCargo.equals(last_forkCargo)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(forkCargo)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_forkCargo + "->" + forkCargo); + } + if (!forkLocation.equals(last_forkLocation)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(forkLocation)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_forkLocation + "->" + forkLocation); + } + if (!forkAction.equals(last_forkAction)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(forkAction)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_forkAction + "->" + forkAction); + } + if (!special1.equals(last_special1)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(special1)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_special1 + "->" + special1); + } + if (!special2.equals(last_special2)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(special2)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_special2 + "->" + special2); + } + if (!Arrays.equals(trayCode, last_trayCode)) { + logServer.deviceItemValue(this.device_code, "mode", Arrays.toString(trayCode)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + Arrays.toString(last_trayCode) + "->" + Arrays.toString(trayCode)); + } + if (!storage_cache.equals(last_storage_cache)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(storage_cache)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_storage_cache + "->" + storage_cache); + } + /*if (!stacker_rpm.equals(last_stacker_rpm)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(stacker_rpm)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_stacker_rpm + "->" + stacker_rpm); + } + if (!stacker_electricCurrent.equals(last_stacker_electricCurrent)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(stacker_electricCurrent)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_stacker_electricCurrent + "->" + stacker_electricCurrent); + } + if (!stacker_runing_time.equals(last_stacker_runing_time)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(stacker_runing_time)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_stacker_runing_time + "->" + stacker_runing_time); + } + if (!stacker_workingHours.equals(last_stacker_workingHours)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(stacker_workingHours)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_stacker_workingHours + "->" + stacker_workingHours); + } + if (!cargo_rpm.equals(last_cargo_rpm)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(stacker_workingHours)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_cargo_rpm + "->" + cargo_rpm); + } + if (!cargo_electric_Current.equals(last_cargo_electric_Current)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(cargo_electric_Current)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_cargo_electric_Current + "->" + cargo_electric_Current); + } + if (!cargo_workingHour.equals(last_cargo_workingHour)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(cargo_workingHour)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_cargo_workingHour + "->" + cargo_workingHour); + } + if (!cargo_runingTimes.equals(last_cargo_runingTimes)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(cargo_runingTimes)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_cargo_runingTimes + "->" + cargo_runingTimes); + } + if (!fork_rpm.equals(last_fork_rpm)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(fork_rpm)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_fork_rpm + "->" + fork_rpm); + } + if (!fork_electric_Current.equals(last_fork_electric_Current)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(fork_electric_Current)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_fork_electric_Current + "->" + fork_electric_Current); + } + if (!fork_workingHours.equals(last_fork_workingHours)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(fork_workingHours)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_fork_workingHours + "->" + fork_workingHours); + } + if (!fork_runingTimes.equals(last_fork_runingTimes)) { + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(fork_runingTimes)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_fork_runingTimes + "->" + fork_runingTimes); + }*/ + + // 更新指令状态 + if (mode == 3 && task > 0) { + Date date = new Date(); + if (date.getTime() - this.instruction_update_time.getTime() < (long) this.instruction_update_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_update_time_out); + + } else { + this.instruction_update_time = date; + //更改指令状态 + if (task > 0) { + Instruction inst = checkInst(); + if (inst != null) { + if (StrUtil.equals(inst.getInstruction_status(), "0")) { + inst.setInstruction_status("1"); + inst.setExecute_device_code(this.device_code); + instructionService.update(inst); + } + } + } + } + } + + } catch (Exception var17) { + var17.printStackTrace(); + logServer.deviceExecuteLog(this.device_code, "", "", "读取信号值时出现异常:" + var17.getMessage() + ",this.itemProtocol is null:" + ObjectUtil.isEmpty(this.itemProtocol)); + } + + + if (mode != 3) { + message = "未联机"; + + } else if (error != 0) { + message = "有报警"; + + } else { + HashMap map = new HashMap(); + switch (command) { + case 0: + if (task == 0) { + applyTask(); + } + break; + case 1: + message = "取货中"; + break; + case 2: + message = "取货完成"; + map.put("to_command", 2); + break; + case 3: + message = "放货中"; + break; + case 4: + message = "请求卸货(申请卸货)"; + Instruction instruction = checkInst(); + if (ObjectUtil.isNotNull(instruction)) { + //指令为执行 + String next_device_code = instruction.getNext_device_code(); + Device startDevice = deviceAppService.findDeviceByCode(next_device_code); + SiemensConveyorDeviceDriver siemensConveyorDeviceDriver; + if (startDevice.getDeviceDriver() instanceof SiemensConveyorDeviceDriver) { + siemensConveyorDeviceDriver = (SiemensConveyorDeviceDriver) startDevice.getDeviceDriver(); + if (siemensConveyorDeviceDriver.getMode() != 2 || siemensConveyorDeviceDriver.getMove() == 1) { + notCreateInstMessage = "未下发电气信号原因->输送线-货架对接位:" + siemensConveyorDeviceDriver.getDevice_code() + + "有货或未联机,无法下发指令!指令号:" + inst.getInstruction_code(); + return; + } + } + map.put("to_command", 3); + } + break; + case 5: + message = "放货完成"; + map.put("to_command", 5); + try { + finish_instruction(inst); + } catch (Exception e) { + e.printStackTrace(); + } + break; + case 6: + message = "取货准备(会库位台)"; + map.put("to_command", 6); + break; + case 7: + message = "召回"; + map.put("to_command", 7); + break; + case 8: + message = "急停"; + map.put("to_command", 8); + break; + default: + message = "不明"; + break; + } + if (ObjectUtil.isNotNull(map)) { + this.writing(map); + } + + } + last_heartbeat = heartbeat; + last_item_deviceCode = item_deviceCode; + last_mode = mode; + last_command = command; + last_task = task; + last_error = error; + last_z = z; + last_x = x; + last_y = y; + last_move = move; + last_cargoMove = cargoMove; + last_action = action; + last_distancex = distancex; + last_distancey = distancey; + last_cargoError = cargoError; + last_forkCargo = forkCargo; + last_forkLocation = forkLocation; + last_forkAction = forkAction; + last_special1 = special1; + last_special2 = special2; + last_trayCode = trayCode; + last_storage_cache = storage_cache; + /*last_stacker_rpm = stacker_rpm; + last_stacker_electricCurrent = stacker_electricCurrent; + last_stacker_runing_time = stacker_runing_time; + last_stacker_workingHours = stacker_workingHours; + last_cargo_rpm = cargo_rpm; + last_cargo_electric_Current = cargo_electric_Current; + last_cargo_workingHour = cargo_workingHour; + last_cargo_runingTimes = cargo_runingTimes; + last_fork_rpm = fork_rpm; + last_fork_electric_Current = fork_electric_Current; + last_fork_workingHours = fork_workingHours; + last_fork_runingTimes = fork_runingTimes;*/ + } + + + /** + * 申请任务 + * + * @param + */ + + public synchronized boolean applyTask() { + 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; + //输入:指令类型多种\ 指令状态多种\ + Instruction instruction1 = new Instruction(); + instruction1.setInstruction_status("0"); + List instructions = instructionService.findByDeviceCodes(instruction1); + if (CollUtil.isEmpty(instructions) || instructions.size() < 1) { + return false; + } + List instructionList = new ArrayList<>(); + for (Instruction instruction : instructions) { + List routeLineDtos = routeLineService.selectDeviceCodeList(instruction.getStart_device_code()); + if (CollUtil.isEmpty(routeLineDtos) || routeLineDtos.size() < 1) { + message = "没有输送线到堆垛机的路由"; + logServer.deviceExecuteLog(this.device_code, "", "", "没有" + instruction.getStart_device_code() + "->" + + this.device_code + "的路由"); + continue; + } + for (RouteLineDto routeLineDto : routeLineDtos) { + if (this.getDeviceCode().equals(routeLineDto.getNext_device_code())) { + List routeLineDtoList = routeLineService.selectDeviceCodeList(this.getDeviceCode()); + if (CollUtil.isEmpty(routeLineDtos) || routeLineDtos.size() < 1) { + message = "没有输送线到堆垛机的路由"; + logServer.deviceExecuteLog(this.device_code, "", "", "没有" + instruction.getStart_device_code() + "->" + + this.device_code + "的路由"); + continue; + } + for (RouteLineDto routeLinedto : routeLineDtoList) { + if (instruction.getNext_device_code().equals(routeLinedto.getNext_device_code())) { + instructionList.add(instruction); + } + } + } + } + } + if (CollUtil.isEmpty(instructionList) || instructionList.size() < 1) { + return false; + } + instructionList = this.sortInst(instructionList); + inst = instructionList.get(0); + //指令未执行 + if (StrUtil.equals(inst.getInstruction_status(), "0")) { + String start_device_code = inst.getStart_device_code(); + Device startDevice = deviceAppService.findDeviceByCode(start_device_code); + BeltConveyorDeviceDriver beltConveyorDeviceDriver; + if (startDevice.getDeviceDriver() instanceof BeltConveyorDeviceDriver) { + beltConveyorDeviceDriver = (BeltConveyorDeviceDriver) startDevice.getDeviceDriver(); + if (beltConveyorDeviceDriver.getMode() != 2 || beltConveyorDeviceDriver.getMove() == 0) { + notCreateInstMessage = "未下发电气信号原因->输送线-货架对接位:" + beltConveyorDeviceDriver.getDevice_code() + + "无货或未联机,无法下发指令!指令号:" + inst.getInstruction_code(); + return false; + } + } + HashMap map = new HashMap(); + map.put("to_device_code", this.getDevice().getAddress()); + map.put("to_command", 1); +// map.put("to_type", inst.getMaterial()); + map.put("to_task", inst.getInstruction_code()); + map.put("to_z", inst.getTo_z()); + if(inst.getTo_x().length()>1){ + String substring = inst.getTo_x().substring(1); + map.put("to_x", substring); + }else { + map.put("to_x", inst.getTo_x()); + } + map.put("to_y", inst.getTo_y()); + this.writing(map); + } + } + return false; + } + + /** + * 将指令根据优先级和创建时间排序 + * + * @param instructions + * @return + */ + private List sortInst(List instructions) { + Collections.sort(instructions, (t1, t2) -> { + //优先级从大到小 + int i = t2.getPriority().compareTo(t1.getPriority()); + //如果优先级相等 + if (i == 0) { + //时间从早到晚 + i = t1.getCreate_time().compareTo(t2.getCreate_time()); + } + return i; + }); + return instructions; + } + + /** + * 更新指令状态 + */ + public synchronized void update_instruction_status() throws Exception { + Date date = new Date(); + if (date.getTime() - this.instruction_update_time.getTime() < (long) this.instruction_update_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_update_time_out); + + } else { + this.instruction_update_time = date; + //更改指令状态 + if (task > 0) { + //inst_message + Instruction inst = checkInst(); + if (inst != null) { + if (StrUtil.equals(inst.getInstruction_status(), "0")) { + inst.setInstruction_status("1"); + inst.setExecute_device_code(this.device_code); + instructionService.update(inst); + } + } + } + HashMap map = new HashMap(); + //取货完成 + if (command == 2) { + map.put("to_command", 2); + } + //请求卸货(申请卸货) + if (command == 4) { + Instruction instruction = checkInst(); + if (ObjectUtil.isNotNull(instruction)) { + //指令为执行 + String next_device_code = instruction.getNext_device_code(); + Device startDevice = deviceAppService.findDeviceByCode(next_device_code); + SiemensConveyorDeviceDriver siemensConveyorDeviceDriver; + if (startDevice.getDeviceDriver() instanceof SiemensConveyorDeviceDriver) { + siemensConveyorDeviceDriver = (SiemensConveyorDeviceDriver) startDevice.getDeviceDriver(); + if (siemensConveyorDeviceDriver.getMode() != 2 || siemensConveyorDeviceDriver.getMove() == 1) { + notCreateInstMessage = "未下发电气信号原因->输送线-货架对接位:" + siemensConveyorDeviceDriver.getDevice_code() + + "有货或未联机,无法下发指令!指令号:" + inst.getInstruction_code(); + return; + } + } + map.put("to_command", 3); + } + } + //放货完成 + if (command == 5) { + map.put("to_command", 5); + try { + finish_instruction(inst); + } catch (Exception e) { + e.printStackTrace(); + } + } + //取货准备(回库台位) + if (command == 6) { + map.put("to_command", 6); + } + //召回 + if (command == 7) { + map.put("to_command", 7); + } + //急停 + if (command == 8) { + map.put("to_command", 8); + } + this.writing(map); + } + + } + + + @Override + public JSONObject getDeviceStatusName() throws Exception { + return null; + } + + @Override + public void setDeviceStatus(JSONObject data) { + + } + + /** + * 完成指令 + * + * @param inst + * @return + * @throws Exception + */ + public synchronized boolean finish_instruction(Instruction inst) throws Exception { + instructionService.finish(inst); + return true; + } + + public String getToParam() { + return this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "."; + } + + public void writing(Map map) { + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + Map itemMap = new LinkedHashMap<>(); + map.forEach((key, value) -> { + if (ObjectUtil.isNotEmpty(value)) { + itemMap.put(getToParam() + key, value); + } + }); + if (ObjectUtil.isNotEmpty(itemMap)) { + this.control(itemMap); + logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); + } + } + + public List sortTask(List taskDtos) { + Collections.sort(taskDtos, new Comparator() { + @Override + public int compare(TaskDto t1, TaskDto t2) { + //优先级从大到小 + int i = t2.getPriority().compareTo(t1.getPriority()); + //如果优先级相等 + if (i == 0) { + //时间从早到晚 + i = t1.getCreate_time().compareTo(t2.getCreate_time()); + } + return i; + } + }); + return taskDtos; + } + + + //将扩展表中的字符串数据转换成集合 + @Override + public List getExtraDeviceCodes(String extraName) { + String extraValue = (String) this.getDevice().getExtraValue().get(extraName); + if (StrUtil.isEmpty(extraValue)) { + return new ArrayList<>(); + } + 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 Instruction checkInst() { + if (ObjectUtil.isNotEmpty(this.inst)) { + if (this.task > 0) { + if (this.inst.getInstruction_code().equals(String.valueOf(this.task))) { + return this.inst; + } else { + inst = instructionService.findByCodeFromCache(String.valueOf(task)); + return inst; + } + } + } else { + inst = instructionService.findByCodeFromCache(String.valueOf(task)); + return inst; + } + return null; + } + +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/driver/OpcDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/driver/OpcDeviceDriver.java index 3860aa8..8bb322c 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/driver/OpcDeviceDriver.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/driver/OpcDeviceDriver.java @@ -72,6 +72,22 @@ public interface OpcDeviceDriver extends DeviceDriver { return (Integer) this.getValue(protocol); } + default String getStringgerValue(String protocol) { + return (String) this.getValue(protocol); + } + + default Long getLongValue(String protocol) { + return (Long) this.getValue(protocol); + } + + default Byte[] getByteArrayValue(String protocol) { + return (Byte[]) this.getValue(protocol); + } + + default int[] getIntegerArrayValue(String protocol) { + return (int[]) this.getValue(protocol); + } + default Float getDoubleValue(String protocol) { if(ObjectUtil.isEmpty(this.getValue(protocol))){ return null; @@ -99,7 +115,7 @@ public interface OpcDeviceDriver extends DeviceDriver { } default String getStringValue(String protocol) { - return (String) this.getOpcValueAccessor().getValue(this.getItem(protocol)); + return this.getOpcValueAccessor().getValue(this.getItem(protocol)).toString(); } default Object getValue(String protocol) { diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/InstructionService.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/InstructionService.java index 2eb2108..7f5e01f 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/InstructionService.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/InstructionService.java @@ -1,6 +1,5 @@ package org.nl.acs.instruction.service; -import org.nl.acs.custompolicy.WaitingInstructionDeque; import org.nl.acs.instruction.domain.InstructionMybatis; import org.nl.acs.instruction.service.dto.InstructionDto; import org.nl.acs.instruction.service.dto.InstructionQueryParam; @@ -317,7 +316,10 @@ public interface InstructionService extends CommonService { void init(String id); - WaitingInstructionDeque findByStategy(String device_code, String strategy_code); - - WaitingInstructionDeque findWaitingInstructionDequeByDeviceCode(String device_code); + /** + * 根据指令某个参数查找指令集合 + * @param instruction1 + * @return + */ + List findByDeviceCodes(Instruction instruction1); } diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/dto/InstructionDto.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/dto/InstructionDto.java index 8a53e61..626ff8f 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/dto/InstructionDto.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/dto/InstructionDto.java @@ -348,4 +348,9 @@ public class InstructionDto implements Serializable { */ private String agv_system_type; + /** + * 单工位堆垛机101-199 双工位堆垛机201-255 + */ + private String to_device_code; + } diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java index 08c97ff..177d9e4 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java @@ -19,9 +19,6 @@ import org.nl.acs.agv.server.MagicAgvService; import org.nl.acs.agv.server.NDCAgvService; import org.nl.acs.agv.server.XianGongAgvService; import org.nl.acs.auto.initial.ApplicationAutoInitial; -import org.nl.acs.custompolicy.DeviceStrategy; -import org.nl.acs.custompolicy.WaitingInstructionDeque; -import org.nl.acs.custompolicy.server.CustomPolicyService; import org.nl.acs.device.domain.Device; import org.nl.acs.device.service.DeviceService; import org.nl.acs.device.service.impl.DeviceServiceImpl; @@ -32,9 +29,7 @@ import org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanne import org.nl.acs.device_driver.basedriver.standard_inspect_site.StandardInspectSiteDeviceDriver; import org.nl.acs.ext.wms.liKuData.*; import org.nl.acs.ext.wms.service.AcsToLiKuService; -import org.nl.acs.instruction.InstructionComparator; import org.nl.acs.instruction.domain.InstructionMybatis; -import org.nl.acs.instruction.service.SortUtlEx; import org.nl.acs.instruction.service.dto.InstructionDto; import org.nl.acs.instruction.service.dto.InstructionQueryParam; import org.nl.acs.opc.DeviceAppService; @@ -93,7 +88,7 @@ public class InstructionServiceImpl extends CommonServiceImpl instructions = new CopyOnWriteArrayList(); - // List instructions_mybatis = new CopyOnWriteArrayList(); +// List instructions_mybatis = new CopyOnWriteArrayList(); @Autowired DeviceAppService deviceAppService; @Autowired @@ -106,14 +101,6 @@ public class InstructionServiceImpl extends CommonServiceImpl deques; - - private InstructionComparator instructionComparator = new InstructionComparator(); - @Override public PageInfo queryAll(InstructionQueryParam query, Pageable pageable) { @@ -123,7 +110,7 @@ public class InstructionServiceImpl extends CommonServiceImpl queryAll(InstructionQueryParam query) { + public List queryAll(InstructionQueryParam query){ return ConvertUtil.convertList(instructionMapper.selectList(QueryHelpMybatisPlus.getPredicate(query)), InstructionDto.class); } @@ -140,7 +127,7 @@ public class InstructionServiceImpl extends CommonServiceImpl ids) { + public int removeByIds(Set ids){ // delCaches(ids); return instructionMapper.deleteBatchIds(ids); } @Override @Transactional(rollbackFor = Exception.class) - public int removeById(String id) { + public int removeById(String id){ Set set = new HashSet<>(1); set.add(id); return this.removeByIds(set); @@ -188,7 +175,7 @@ public class InstructionServiceImpl extends CommonServiceImpl(ConvertUtil.convertList(list, Instruction.class)); + this.instructions = new CopyOnWriteArrayList<>(ConvertUtil.convertList(list,Instruction.class)); } @Override @@ -204,20 +191,20 @@ public class InstructionServiceImpl extends CommonServiceImpl queryPage = PageUtil.toMybatisPage(page); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); // wrapper.eq(InstructionMybatis::getIs_delete,0); - wrapper.and(StringUtils.isNotBlank(code), instructionMybatis -> instructionMybatis.like(InstructionMybatis::getInstruction_code, code).or().like(InstructionMybatis::getTask_code, code)); - wrapper.like(StringUtils.isNotBlank(vehicle_code), InstructionMybatis::getVehicle_code, vehicle_code); - wrapper.eq(StringUtils.isNotBlank(material_type), InstructionMybatis::getMaterial, material_type); - wrapper.eq(StringUtils.isNotBlank(status), InstructionMybatis::getInstruction_status, status); - wrapper.and(StringUtils.isNotBlank(point_code), instructionMybatis -> instructionMybatis.like(InstructionMybatis::getStart_point_code, point_code).or().like(InstructionMybatis::getNext_point_code, point_code)); - wrapper.eq(StringUtils.isNotBlank(instruction_type), InstructionMybatis::getInstruction_type, instruction_type); + wrapper.and(StringUtils.isNotBlank(code), instructionMybatis -> instructionMybatis.like(InstructionMybatis::getInstruction_code,code).or().like(InstructionMybatis::getTask_code,code)); + wrapper.like(StringUtils.isNotBlank(vehicle_code),InstructionMybatis::getVehicle_code,vehicle_code); + wrapper.eq(StringUtils.isNotBlank(material_type),InstructionMybatis::getMaterial,material_type); + wrapper.eq(StringUtils.isNotBlank(status),InstructionMybatis::getInstruction_status,status); + wrapper.and(StringUtils.isNotBlank(point_code),instructionMybatis -> instructionMybatis.like(InstructionMybatis::getStart_point_code,point_code).or().like(InstructionMybatis::getNext_point_code,point_code)); + wrapper.eq(StringUtils.isNotBlank(instruction_type),InstructionMybatis::getInstruction_type,instruction_type); if (!StrUtil.isEmpty(is_over)) { - if (StrUtil.equals(is_over, "1")) { - wrapper.ge(InstructionMybatis::getInstruction_status, 2); - } else { - wrapper.lt(InstructionMybatis::getInstruction_status, 2); + if (StrUtil.equals(is_over,"1")){ + wrapper.ge(InstructionMybatis::getInstruction_status,2); + }else{ + wrapper.lt(InstructionMybatis::getInstruction_status,2); } } - IPage insPage = instructionMapper.selectPage(queryPage, wrapper); + IPage insPage = instructionMapper.selectPage(queryPage,wrapper); final JSONObject json = (JSONObject) JSON.toJSON(ConvertUtil.convertPage(insPage, InstructionDto.class)); return json; } @@ -236,31 +223,31 @@ public class InstructionServiceImpl extends CommonServiceImpl wrapper = new LambdaQueryWrapper<>(); // wrapper.eq(InstructionMybatis::getIs_delete,"0"); if (!StrUtil.isEmpty(code)) { - wrapper.and(instructionMybatis -> instructionMybatis.like(InstructionMybatis::getInstruction_code, code).or().like(InstructionMybatis::getTask_code, code)); + wrapper.and(instructionMybatis -> instructionMybatis.like(InstructionMybatis::getInstruction_code,code).or().like(InstructionMybatis::getTask_code,code)); } if (!StrUtil.isEmpty(vehicle_code)) { - wrapper.like(InstructionMybatis::getVehicle_code, vehicle_code); + wrapper.like(InstructionMybatis::getVehicle_code,vehicle_code); } if (!StrUtil.isEmpty(material_type)) { - wrapper.eq(InstructionMybatis::getMaterial, material_type); + wrapper.eq(InstructionMybatis::getMaterial,material_type); } if (!StrUtil.isEmpty(status)) { - wrapper.eq(InstructionMybatis::getInstruction_status, status); + wrapper.eq(InstructionMybatis::getInstruction_status,status); } if (!StrUtil.isEmpty(point_code)) { - wrapper.and(instructionMybatis -> instructionMybatis.like(InstructionMybatis::getStart_point_code, point_code).or().like(InstructionMybatis::getNext_point_code, point_code)); + wrapper.and(instructionMybatis -> instructionMybatis.like(InstructionMybatis::getStart_point_code,point_code).or().like(InstructionMybatis::getNext_point_code,point_code)); } if (!StrUtil.isEmpty(create_time) && !StrUtil.isEmpty(end_time)) { - wrapper.between(InstructionMybatis::getCreate_time, create_time, end_time); + wrapper.between(InstructionMybatis::getCreate_time,create_time,end_time); } - IPage insPage = instructionMapper.selectPage(queryPage, wrapper); + IPage insPage = instructionMapper.selectPage(queryPage,wrapper); final JSONObject json = (JSONObject) JSON.toJSON(ConvertUtil.convertPage(insPage, InstructionDto.class)); return json; } @Override public Map getByTaskId(String id) { - List insList = new LambdaQueryChainWrapper<>(instructionMapper) + List insList= new LambdaQueryChainWrapper<>(instructionMapper) .eq(InstructionMybatis::getTask_id, id) .list(); JSONObject jsonObject = new JSONObject(); @@ -286,9 +273,9 @@ public class InstructionServiceImpl extends CommonServiceImpl queryAll(Map whereJson) { - List insList = new LambdaQueryChainWrapper<>(instructionMapper) + List insList= new LambdaQueryChainWrapper<>(instructionMapper) .list(); - return ConvertUtil.convertList(insList, Instruction.class); + return ConvertUtil.convertList(insList,Instruction.class); } @Override @@ -296,10 +283,10 @@ public class InstructionServiceImpl extends CommonServiceImpl list = arr.toJavaList(Instruction.class); - List insList = new LambdaQueryChainWrapper<>(instructionMapper) + List insList= new LambdaQueryChainWrapper<>(instructionMapper) .lt(InstructionMybatis::getInstruction_status, "2") .list(); - return ConvertUtil.convertList(insList, Instruction.class); + return ConvertUtil.convertList(insList,Instruction.class); } @@ -313,13 +300,13 @@ public class InstructionServiceImpl extends CommonServiceImpl(instructionMapper) + InstructionMybatis ins= new LambdaQueryChainWrapper<>(instructionMapper) .eq(InstructionMybatis::getInstruction_code, code) .one(); - if (ObjectUtil.isEmpty(ins)) { + if(ObjectUtil.isEmpty(ins)){ return null; } - return ConvertUtil.convert(ins, Instruction.class); + return ConvertUtil.convert(ins,Instruction.class); } @Override @@ -328,13 +315,13 @@ public class InstructionServiceImpl extends CommonServiceImpl(instructionMapper) + InstructionMybatis ins= new LambdaQueryChainWrapper<>(instructionMapper) .eq(InstructionMybatis::getTask_code, code) .one(); - if (ObjectUtil.isEmpty(ins)) { + if(ObjectUtil.isEmpty(ins)){ return null; } - return ConvertUtil.convert(ins, Instruction.class); + return ConvertUtil.convert(ins,Instruction.class); } @Override @@ -363,11 +350,11 @@ public class InstructionServiceImpl extends CommonServiceImpl wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(InstructionMybatis::getTask_id, id); - wrapper.apply(StringUtils.isNotBlank(wherecaluse), wherecaluse); + wrapper.eq(InstructionMybatis::getTask_id,id); + wrapper.apply(StringUtils.isNotBlank(wherecaluse),wherecaluse); InstructionMybatis ins = instructionMapper.selectOne(wrapper); if (ObjectUtil.isNotEmpty(ins)) { - return ConvertUtil.convert(ins, Instruction.class); + return ConvertUtil.convert(ins,Instruction.class); } return null; } @@ -399,7 +386,7 @@ public class InstructionServiceImpl extends CommonServiceImpl(instructionMapper) + InstructionMybatis ins= new LambdaQueryChainWrapper<>(instructionMapper) .lt(InstructionMybatis::getInstruction_status, 3) - .eq(InstructionMybatis::getNext_point_code, dto.getNext_point_code()) - .eq(InstructionMybatis::getStart_point_code, dto.getStart_point_code()) - .eq(InstructionMybatis::getTask_id, dto.getTask_id()) + .eq(InstructionMybatis::getNext_point_code,dto.getNext_point_code()) + .eq(InstructionMybatis::getStart_point_code,dto.getStart_point_code()) + .eq(InstructionMybatis::getTask_id,dto.getTask_id()) .one(); @@ -808,7 +801,7 @@ public class InstructionServiceImpl extends CommonServiceImpl(taskMapper) - .eq(Task::getTask_id, insttaskid) + .eq(Task::getTask_id,insttaskid) .one(); // =0 则不用再次请求 if (StrUtil.equals(task.getRequest_again(), "0")) { @@ -843,7 +836,7 @@ public class InstructionServiceImpl extends CommonServiceImpl(taskMapper) - .eq(Task::getTask_id, insttaskid) + .eq(Task::getTask_id,insttaskid) .one(); // =0 则不用再次请求 if (StrUtil.equals(task.getRequest_again(), "0")) { @@ -897,7 +890,7 @@ public class InstructionServiceImpl extends CommonServiceImpl(taskMapper) - .eq(Task::getTask_id, dto.getTask_id()) + .eq(Task::getTask_id,dto.getTask_id()) .one(); RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineServiceImpl.class); @@ -995,7 +988,7 @@ public class InstructionServiceImpl extends CommonServiceImpl findByDeviceCodes(Instruction instruction1) { + if(ObjectUtil.isNull(instruction1)){ + return null; } - - return deque; + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(StrUtil.isNotBlank(instruction1.getInstruction_status()),InstructionMybatis::getInstruction_status,instruction1.getInstruction_status()); + wrapper.eq(StrUtil.isNotBlank(instruction1.getStart_device_code()),InstructionMybatis::getStart_device_code,instruction1.getStart_device_code()); + wrapper.eq(StrUtil.isNotBlank(instruction1.getNext_device_code()),InstructionMybatis::getNext_device_code,instruction1.getNext_device_code()); + List instructionMybatis = instructionMapper.selectList(wrapper); + List instructions = ConvertUtil.convertList(instructionMybatis, Instruction.class); + return instructions; } - - - public List findAllWithSort() { - List list = this.findAllInstFromCache(); - SortUtlEx.sort(list, this.instructionComparator); - return list; - } - - - @Override - public WaitingInstructionDeque findByStategy(String device_code, String strategy_code) { - DeviceStrategy strategy = customPolicyService.findByCode(strategy_code); - if (strategy == null) { - throw new RuntimeException("设备 " + device_code+ "策略" + strategy_code + "不存在"); - } else { - ArrayList instructions = new ArrayList(); - ArrayList instructions_level_up = new ArrayList(); - Iterator var6 = this.findAllWithSort().iterator(); - - while(true) { - while(true) { - Instruction instruction; - do { - do { - if (!var6.hasNext()) { - WaitingInstructionDeque deque = strategy.strategy(instructions, device_code); - ArrayList instructions_level_up2 = new ArrayList(); - Iterator var13 = instructions_level_up.iterator(); - - while(var13.hasNext()) { - Instruction is2 = (Instruction)var13.next(); - if (!deque.contains(is2)) { - instructions_level_up2.add(is2); - } - } - - if (instructions_level_up2.size() > 0) { - deque.getQueue().addAll(0, instructions_level_up2); - } - - return deque; - } - - instruction = (Instruction)var6.next(); - } while(!StrUtil.equals(instruction.getExecute_device_code(), device_code)); - } while(StrUtil.equals(instruction.getStart_device_code(), device_code)); - - if (Integer.parseInt(instruction.getPriority()) > 0) { - instructions_level_up.add(instruction); - } else if (Integer.parseInt(instruction.getInstruction_status()) == 0) { - instructions.add(instruction); - } - } - } - } - } - -} \ No newline at end of file +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/DeviceManageServiceImpl.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/DeviceManageServiceImpl.java index 4505b3d..a0156fd 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/DeviceManageServiceImpl.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/DeviceManageServiceImpl.java @@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import org.nl.acs.device.domain.Device; import org.nl.acs.device.domain.DeviceExtra; @@ -68,7 +69,13 @@ public class DeviceManageServiceImpl implements DeviceManageService { if (StrUtil.isNotEmpty(opc_plc_id) && StrUtil.isNotEmpty(opc_server_id)) { //OPC表【acs_opc】 // String opc_code = opcTab.query("is_delete= '0' AND is_active= '1' AND opc_id = '" + opc_server_id + "'").uniqueResult(0).getString("opc_code"); - String opc_code = new LambdaQueryChainWrapper<>(opcMapper).apply("is_delete= '0' AND is_active= '1' AND opc_id = '" + opc_server_id + "'").one().getOpc_code(); + String opc_code = new LambdaQueryChainWrapper<>(opcMapper).apply("is_delete= '0' AND is_active= '1' AND opc_id = '" + opc_server_id + "'") + .one().getOpc_code(); + /*Opc opc = opcMapper.selectOne(Wrappers.lambdaQuery(Opc.class).eq(Opc::getIs_delete, "0").eq(Opc::getIs_active, "1").eq(Opc::getOpc_id, opc_server_id)); + String opc_code = ""; + if(ObjectUtil.isNotNull(opc)){ + opc_code = opc.getOpc_code(); + }*/ device.setOpc_server_code(opc_code); // if(ObjectUtil.isEmpty(plcTab.query("is_delete= '0' AND is_active= '1' AND plc_id = '" + opc_plc_id + "'").uniqueResult(0))) if(ObjectUtil.isEmpty(new LambdaQueryChainWrapper<>(opcPlcMapper).apply("is_delete= '0' AND is_active= '1' AND plc_id = '" + opc_plc_id + "'").one())) diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/route/service/RouteLineService.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/route/service/RouteLineService.java index b069d64..49d881c 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/route/service/RouteLineService.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/route/service/RouteLineService.java @@ -224,4 +224,6 @@ public interface RouteLineService extends CommonService { public List getSuperiorShortPathLinesByCode(String device_code, String plan_code); public JSONArray getActivePathLine(String device_code, String next_device_code, String plan_code); + + List selectDeviceCodeList(String start_device_code); } diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/route/service/impl/RouteLineServiceImpl.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/route/service/impl/RouteLineServiceImpl.java index ca3a094..25c0dbc 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/route/service/impl/RouteLineServiceImpl.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/route/service/impl/RouteLineServiceImpl.java @@ -10,6 +10,7 @@ import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import lombok.AllArgsConstructor; import org.nl.acs.auto.initial.ApplicationAutoInitial; @@ -708,4 +709,24 @@ public class RouteLineServiceImpl extends CommonServiceImpl selectDeviceCodeList(String device_code) { + if(StrUtil.isEmpty(device_code)){ + return null; + } + List routeLines = routeLineMapper.selectList(Wrappers.lambdaQuery(RouteLine.class). + eq(RouteLine::getDevice_code, device_code)); + List routeLineDtos = new ArrayList<>(); + for (RouteLine routeLine : routeLines) { + RouteLineDto convert = ConvertUtil.convert(routeLine, RouteLineDto.class); + routeLineDtos.add(convert); + } + return routeLineDtos; + } } diff --git a/acs/nladmin-ui/src/views/acs/device/config.vue b/acs/nladmin-ui/src/views/acs/device/config.vue index a70d3f6..aa7e49d 100644 --- a/acs/nladmin-ui/src/views/acs/device/config.vue +++ b/acs/nladmin-ui/src/views/acs/device/config.vue @@ -81,9 +81,17 @@ import standard_scanner from '@/views/acs/device/driver/standard_scanner' import standard_conveyor_control_with_scanner from '@/views/acs/device/driver/standard_conveyor_control_with_scanner' import standard_conveyor_control from '@/views/acs/device/driver/standard_conveyor_control' import standard_conveyor_monitor from '@/views/acs/device/driver/standard_conveyor_monitor' +// import hailiang_smart_plc_test from '@/views/acs/device/driver/hailiang_smart_plc_test' +// import paint_conveyor from '@/views/acs/device/driver/paint_conveyor' +import standard_stacker from '@/views/acs/device/driver/standard_stacker' +import siemens_conveyor_labeling from '@/views/acs/device/driver/siemens_conveyor_labeling' +import siemens_conveyor from '@/views/acs/device/driver/siemens_conveyor' +import belt_conveyor from '@/views/acs/device/driver/belt_conveyor' +// import empty_vehicle_stacking_position from '@/views/acs/device/driver/empty_vehicle_stacking_position' import agv_ndc_one from '@/views/acs/device/driver/agv/agv_ndc_one' import agv_ndc_two from '@/views/acs/device/driver/agv/agv_ndc_two' import xg_agv from '@/views/acs/device/driver/agv/xg_agv' +// import standard_station from '@/views/acs/device/driver/standard_station' export default { name: 'DeviceConfig', @@ -96,9 +104,17 @@ export default { standard_conveyor_control_with_scanner, standard_conveyor_control, standard_conveyor_monitor, + // hailiang_smart_plc_test, + // paint_conveyor, + // empty_vehicle_stacking_position, agv_ndc_two, agv_ndc_one, + standard_stacker, + siemens_conveyor_labeling, + siemens_conveyor, + belt_conveyor, xg_agv + // standard_station }, dicts: ['device_type'], mixins: [crud], diff --git a/acs/nladmin-ui/src/views/acs/device/driver/belt_conveyor.vue b/acs/nladmin-ui/src/views/acs/device/driver/belt_conveyor.vue new file mode 100644 index 0000000..7ecfb7d --- /dev/null +++ b/acs/nladmin-ui/src/views/acs/device/driver/belt_conveyor.vue @@ -0,0 +1,539 @@ + + + + + diff --git a/acs/nladmin-ui/src/views/acs/device/driver/standard_stacker.vue b/acs/nladmin-ui/src/views/acs/device/driver/standard_stacker.vue new file mode 100644 index 0000000..592e6d0 --- /dev/null +++ b/acs/nladmin-ui/src/views/acs/device/driver/standard_stacker.vue @@ -0,0 +1,546 @@ + + + + +