From 0e78fa55ae248d22c4daf4b8c8b58e1f224e98e1 Mon Sep 17 00:00:00 2001 From: gengby <858962040@qq.com> Date: Wed, 18 Sep 2024 08:50:33 +0800 Subject: [PATCH] =?UTF-8?q?rev:=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/org/nl/AppRun.java | 2 +- .../src/main/java/org/nl/acs/bx06_demo.java | 82 ++- .../service/impl/DeviceServiceImpl.java | 1 + ...InspectionScannerConveyorDeviceDriver.java | 137 ++-- .../ItemProtocol.java | 1 + .../led_screen/LedScreenDeviceDriver.java | 228 ++++++- .../StandardStackerDeviceDriver.java | 646 ++++++++++++------ .../with_station/WithStationDeviceDriver.java | 21 +- .../wms/service/impl/WmsToAcsServiceImpl.java | 23 +- .../service/InstructionService.java | 44 +- .../service/impl/InstructionServiceImpl.java | 258 ++++++- .../org/nl/acs/task/service/TaskService.java | 7 + .../task/service/impl/TaskServiceImpl.java | 124 ++-- .../java/org/nl/config/mqtt2/MqttService.java | 78 ++- .../coderule/impl/SysCodeRuleServiceImpl.java | 2 + .../resources/config/application-prod.yml | 2 +- .../src/main/resources/config/application.yml | 2 +- ...nce_inspection_scanner_conveyor_device.vue | 70 +- .../views/acs/device/driver/led_screen.vue | 200 +++--- .../device/driver/standard_stacker_device.vue | 34 +- nladmin-ui/src/views/acs/task/index.vue | 10 +- 21 files changed, 1489 insertions(+), 483 deletions(-) diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/AppRun.java b/nladmin-system/nlsso-server/src/main/java/org/nl/AppRun.java index 2797c3d..15a6204 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/AppRun.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/AppRun.java @@ -40,7 +40,7 @@ public class AppRun { public static void main(String[] args) { SpringApplication.run(AppRun.class, args); - new HeartServer(new InetSocketAddress("127.0.0.1", 20889)); + new HeartServer(new InetSocketAddress("192.168.8.218", 20889)); System.out.println("项目启动成功"); } diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/bx06_demo.java b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/bx06_demo.java index ac92825..d94820a 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/bx06_demo.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/bx06_demo.java @@ -21,6 +21,7 @@ import onbon.bx06.utils.DisplayStyleFactory; import onbon.bx06.utils.TextBinary; import java.awt.*; +import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.List; @@ -31,7 +32,7 @@ import java.util.List; * @create: 2019-08-21 14:52 **/ public class bx06_demo { - private static String ip = "192.168.81.56"; + private static String ip = "192.168.8.148"; private static int port = 5005; public static void main(String[] args)throws Exception { @@ -260,15 +261,17 @@ public class bx06_demo { { DisplayStyle[] styles = DisplayStyleFactory.getStyles().toArray(new DisplayStyle[0]); - Bx6GScreenClient screen = new Bx6GScreenClient( "MyScreen",new Bx6E() ); + Bx6GScreenClient screen = new Bx6GScreenClient( "MyScreen1",new Bx6E() ); screen.connect( ip,port ); ProgramBxFile pf = new ProgramBxFile( 0,screen.getProfile() ); - TextCaptionBxArea area = new TextCaptionBxArea( 0,0,160,32,screen.getProfile() ); + TextCaptionBxArea area = new TextCaptionBxArea( 0,0,192,16,screen.getProfile() ); - TextBxPage page = new TextBxPage( "这是节目" ); + TextBxPage page = new TextBxPage( "入库模式148"); + + page.setForeground(Color.green); area.addPage( page ); @@ -276,8 +279,28 @@ public class bx06_demo { screen.writeProgram( pf ); + // 创建第一个动态区 + DynamicBxAreaRule rule_2 = new DynamicBxAreaRule(); + rule_2.setId( 0 ); + rule_2.setRunMode( (byte)0 ); + rule_2.setRelativeAllPrograms( false ); + rule_2.addRelativeProgram( 0 ); + DynamicBxArea area_2 = new DynamicBxArea( 0,22,192,22,screen.getProfile() ); + String errorMsg = "报警信息: 无报警!"; + TextBxPage page_2 = new TextBxPage( errorMsg); + if (errorMsg.length() > 10){ + page_2.setDisplayStyle( styles[4] ); + } else { + page_2.setDisplayStyle( styles[1] ); + } + page_2.setFont( new Font("Microsoft YaHei",Font.PLAIN,12) ); + page_2.setForeground(Color.green); + page_2.setLineHeight(12); + area_2.addPage( page_2 ); + screen.writeDynamic( rule_2,area_2 ); + DynamicBxAreaRule rule = new DynamicBxAreaRule(); - rule.setId(0); + rule.setId(1); rule.setRunMode( (byte)0 ); // 新增动态区关联异步节目 // 一旦关联了某个异步节目,则该节目和动态区一起播放 @@ -287,26 +310,43 @@ public class bx06_demo { // false:由规则来决定 rule.setRelativeAllPrograms( false ); rule.addRelativeProgram( 0 ); - - DynamicBxArea dArea = new DynamicBxArea( 0,32,160,32,screen.getProfile() ); - - TextBxPage dPage = new TextBxPage( "这是动态区" ); - dPage.setDisplayStyle( styles[2] ); - dPage.setFont( new Font( "宋体",Font.PLAIN,12 ) ); - - dArea.addPage( dPage ); - - screen.writeDynamic( rule,dArea ); - - List pfs = screen.readProgramList(); - for(String program : pfs) - { - System.out.println( program ); + DynamicBxArea dArea = new DynamicBxArea( 0,37,192,37,screen.getProfile() ); + String msg = "任务信息: 载具T00001由1120->T01-01-01,载具T00002由1120->T01-02-01,载具T00003由1120->T01-03-01"; + TextBxPage dPage = new TextBxPage(msg); + boolean stringWidth = getStringWidth(msg); + if (msg.length() > 20){ + dPage.setDisplayStyle( styles[4] ); + } else { + dPage.setDisplayStyle( styles[1] ); } - + dPage.setFont( new Font( "Microsoft YaHei",Font.PLAIN,12 ) ); + dPage.setForeground(Color.green); + dPage.setLineHeight(12); + dArea.addPage( dPage ); + screen.writeDynamic( rule,dArea ); screen.disconnect(); } + private static boolean getStringWidth(String msg) { + Font font = new Font("Microsoft YaHei", Font.PLAIN, 12); + + // 创建一个临时的 BufferedImage 来获取 Graphics 对象 + BufferedImage image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); + Graphics g = image.getGraphics(); + + // 设置字体 + g.setFont(font); + + // 获取 FontMetrics + FontMetrics metrics = g.getFontMetrics(); + + // 计算字符串的宽度 + int width = metrics.stringWidth(msg); + + // 判断宽度是否小于 192 + return width < 192; + } + // 关于语音播报区域 // 语音播放目前只有六代部分卡支持 public static void SendSound()throws Exception diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device/service/impl/DeviceServiceImpl.java b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device/service/impl/DeviceServiceImpl.java index 5710566..d16e1ab 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device/service/impl/DeviceServiceImpl.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device/service/impl/DeviceServiceImpl.java @@ -1458,6 +1458,7 @@ public class DeviceServiceImpl extends CommonServiceImpl i jo.put("maxZ", new LambdaQueryChainWrapper<>(deviceExtraMapper).eq(DeviceExtra::getDevice_id, device_id).eq(DeviceExtra::getExtra_code, "maxZ").one().getExtra_value()); jo.put("minZ", new LambdaQueryChainWrapper<>(deviceExtraMapper).eq(DeviceExtra::getDevice_id, device_id).eq(DeviceExtra::getExtra_code, "minZ").one().getExtra_value()); jo.put("tunnel", new LambdaQueryChainWrapper<>(deviceExtraMapper).eq(DeviceExtra::getDevice_id, device_id).eq(DeviceExtra::getExtra_code, "tunnel").one().getExtra_value()); + jo.put("x", new LambdaQueryChainWrapper<>(deviceExtraMapper).eq(DeviceExtra::getDevice_id, device_id).eq(DeviceExtra::getExtra_code, "x").one().getExtra_value()); return jo; } diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/appearance_inspection_scannner_conveyor/AppearanceInspectionScannerConveyorDeviceDriver.java b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/appearance_inspection_scannner_conveyor/AppearanceInspectionScannerConveyorDeviceDriver.java index 67bf544..3afa788 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/appearance_inspection_scannner_conveyor/AppearanceInspectionScannerConveyorDeviceDriver.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/appearance_inspection_scannner_conveyor/AppearanceInspectionScannerConveyorDeviceDriver.java @@ -18,7 +18,6 @@ import org.nl.acs.device.device.service.dto.DeviceAssignedDto; import org.nl.acs.device.driver.*; import org.nl.acs.device.driver.conveyor.appearance_inspection_scannner_conveyor.enums.*; import org.nl.acs.device.driver.conveyor.strip_conveyor.StripConveyorDeviceDriver; -import org.nl.acs.device.driver.storage.standard_storage.StandardStorageDeviceDriver; import org.nl.acs.ext.UnifiedResponse; import org.nl.acs.ext.socket.Online; import org.nl.acs.ext.wms.data.req.CommonRequest; @@ -41,6 +40,7 @@ import org.nl.config.lucene.service.dto.LuceneLogDto; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; +import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; @@ -71,6 +71,11 @@ public class AppearanceInspectionScannerConveyorDeviceDriver extends AbstractOpc */ private int heartbeat = 0; private int lastHeartbeat = 0; + /** + * 手自动状态 0手动 1自动 + */ + private int status = 0; + private int lastStatus = 0; /** * 工作模式 */ @@ -273,6 +278,8 @@ public class AppearanceInspectionScannerConveyorDeviceDriver extends AbstractOpc this.executeLogicBefore(); if (!this.online) { this.message = "设备离线"; + } else if (this.status == 0) { + this.message = "输送线为手动状态"; } else if (this.mode == 0) { this.message = "设备未联机"; } else if (this.error != 0) { @@ -588,6 +595,8 @@ public class AppearanceInspectionScannerConveyorDeviceDriver extends AbstractOpc } } + private static CopyOnWriteArrayList bindTaskCode = new CopyOnWriteArrayList<>(); + public void createOutInstruction(String deviceCode) { long currentTimeMillis = System.currentTimeMillis(); if (!isTimeValid(currentTimeMillis)) { @@ -602,6 +611,7 @@ public class AppearanceInspectionScannerConveyorDeviceDriver extends AbstractOpc AppearanceInspectionScannerConveyorDeviceDriver appearanceInspectionScannerConveyorDeviceDriver = (AppearanceInspectionScannerConveyorDeviceDriver) cacheDevice.getDeviceDriver(); checkoutStartDeviceCode = appearanceInspectionScannerConveyorDeviceDriver.getExtraDeviceCodes("checkoutStartDeviceCode"); } + List taskDtos = taskService.findReadyTasksByNextDeviceCode(deviceCode, checkoutStartDeviceCode); TaskDto taskDto = taskService.findReadyTaskByNextDeviceCode(deviceCode, checkoutStartDeviceCode); Instruction instDto = instructionService.findReadyInstByEnd(deviceCode); if (ObjectUtil.isNotEmpty(taskDto) && ObjectUtil.isEmpty(instDto)) { @@ -614,12 +624,74 @@ public class AppearanceInspectionScannerConveyorDeviceDriver extends AbstractOpc } DeviceAssignedDto assignedDto = null; if (assignedDtos.size() > 1) { - for (DeviceAssignedDto deviceAssignedDto : assignedDtos) { + Map> tempAss = new HashMap<>(); + for (int i = 0; i < assignedDtos.size(); i++) { + DeviceAssignedDto deviceAssignedDto = assignedDtos.get(i); String inst_nextDevice_code = deviceAssignedDto.getInst_nextDevice_code(); - Instruction inst = instructionService.findReadyInstByEnd(inst_nextDevice_code); - if (ObjectUtil.isEmpty(inst)) { - assignedDto = deviceAssignedDto; - break; + int num = instructionService.findReadyInstNumByEnd(inst_nextDevice_code); + List deviceAssignedDtos = tempAss.get(num); + if (CollectionUtil.isEmpty(deviceAssignedDtos)) { + deviceAssignedDtos = new ArrayList<>(); + tempAss.put(num, deviceAssignedDtos); + } + deviceAssignedDtos.add(deviceAssignedDto); + } + Integer from_y = Integer.parseInt(taskDto.getFrom_y()); + if (bindTaskCode.contains(taskDto.getTask_code())) { + for (DeviceAssignedDto dto : assignedDtos) { + String inst_nextDevice_code = dto.getInst_nextDevice_code(); + Device inst_nextDevice = deviceAppService.findDeviceByCode(inst_nextDevice_code); + if (inst_nextDevice != null) { + Boolean isFront = Optional.ofNullable(inst_nextDevice.getExtraValue().get("isFront")).map(Object::toString).map(Boolean::parseBoolean).orElse(false); + if (from_y % 4 == 1 || from_y % 4 == 2) { + //分配后叉 + if (!isFront) { + assignedDto = dto; + break; + } + } else if (from_y % 4 == 3 || from_y % 4 == 0) { + //分配前叉 + if (isFront) { + assignedDto = dto; + break; + } + } + } + } + } else { + TaskDto bindTaskDto = this.isBind(taskDtos, taskDto, taskDto.getTask_code()); + if (bindTaskDto != null) { + bindTaskCode.add(bindTaskDto.getTask_code()); + for (DeviceAssignedDto dto : assignedDtos) { + String inst_nextDevice_code = dto.getInst_nextDevice_code(); + Device inst_nextDevice = deviceAppService.findDeviceByCode(inst_nextDevice_code); + if (inst_nextDevice != null) { + Boolean isFront = Optional.ofNullable(inst_nextDevice.getExtraValue().get("isFront")).map(Object::toString).map(Boolean::parseBoolean).orElse(false); + if (from_y % 4 == 1 || from_y % 4 == 2) { + //分配后叉 + if (!isFront) { + assignedDto = dto; + break; + } + } else if (from_y % 4 == 3 || from_y % 4 == 0) { + //分配前叉 + if (isFront) { + assignedDto = dto; + break; + } + } + } + } + } else { + Set keys = tempAss.keySet(); + Integer minKey = Collections.min(keys); + Integer maxKey = Collections.max(keys); + List minList = tempAss.get(minKey); + List maxList = tempAss.get(maxKey); + if (minList.size() == maxList.size()) { + + } + assignedDto = minList.get(0); } } } else { @@ -726,6 +798,7 @@ public class AppearanceInspectionScannerConveyorDeviceDriver extends AbstractOpc logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "创建出库指令成功,指令号:" + instDto.getInstruction_code() + " , 任务号:" + instDto.getTask_code())); this.unExecutedMessage = ""; this.requireSuccess = true; + bindTaskCode.remove(taskDto.getTask_code()); } } else { this.unExecutedMessage = "未查找到对应的就绪状态任务或执行中出库指令信息"; @@ -736,36 +809,11 @@ public class AppearanceInspectionScannerConveyorDeviceDriver extends AbstractOpc } } - - private boolean isBind(TaskDto link_task, TaskDto taskDto) { - List taskDtos = Arrays.asList(link_task); - String from_x = taskDto.getFrom_x(); - String from_y = taskDto.getFrom_y(); - String from_z = taskDto.getFrom_z(); - TaskDto dto = taskDtos.stream() - .filter(dto1 -> taskDto.getFrom_x().equals(from_x) && taskDto.getFrom_z().equals(from_z)) - .filter(dto1 -> { - int frontFromY = Integer.parseInt(from_y); - int taskDtoFromY = Integer.parseInt(taskDto.getFrom_y()); - int frontGroup = (frontFromY - 1) / 4; - int taskDtoGroup = (taskDtoFromY - 1) / 4; - if (frontGroup != taskDtoGroup) { - return false; - } - int frontMod = frontFromY % 4; - int taskDtoMod = taskDtoFromY % 4; - return (frontMod + taskDtoMod == 2 || frontMod + taskDtoMod == 4); - }) - .findFirst() - .orElse(null); - return dto != null; - } - - private boolean isBind(List taskDtos, TaskDto link_task, String task_code) { + private TaskDto isBind(List taskDtos, TaskDto link_task, String task_code) { String from_x = link_task.getFrom_x(); String from_y = link_task.getFrom_y(); String from_z = link_task.getFrom_z(); - TaskDto dto = taskDtos.stream() + return taskDtos.stream() .filter(taskDto -> !taskDto.getTask_code().equals(task_code)) .filter(taskDto -> taskDto.getTask_status().equals(TaskStatusEnum.READY.getIndex())) .filter(taskDto -> taskDto.getFrom_x().equals(from_x) && taskDto.getFrom_z().equals(from_z)) @@ -785,7 +833,6 @@ public class AppearanceInspectionScannerConveyorDeviceDriver extends AbstractOpc .thenComparing(taskDto -> LocalDateTime.parse(taskDto.getCreate_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))) .findFirst() .orElse(null); - return dto != null; } /** @@ -804,10 +851,14 @@ public class AppearanceInspectionScannerConveyorDeviceDriver extends AbstractOpc if (next_device != null && next_device.getDeviceDriver() instanceof AppearanceInspectionScannerConveyorDeviceDriver) { List targetDeviceCode = this.getExtraDeviceCodes("targetDeviceCode"); if (targetDeviceCode != null && targetDeviceCode.contains(next_device_code)) { - Integer address = Optional.ofNullable(next_device.getExtraValue().get("address")).map(Object::toString).map(Integer::parseInt).orElse(0); - this.writing(Arrays.asList(ItemProtocol.TO_TASK.getKey()), Arrays.asList(inst.getInstruction_code())); - this.writing(Arrays.asList(ItemProtocol.TO_COMMAND.getKey(), ItemProtocol.TO_TARGET.getKey()), Arrays.asList(CommandEnum.COMMAND_1.getValue(), address)); - this.requireSuccess = true; +// if (StrUtil.equals(String.valueOf(this.task), inst.getInstruction_code())) { +// this.writing(Arrays.asList(ItemProtocol.TO_COMMAND.getKey()), Arrays.asList(CommandEnum.COMMAND_1.getValue())); +// this.requireSuccess = true; +// } else { + Integer address = Optional.ofNullable(next_device.getExtraValue().get("address")).map(Object::toString).map(Integer::parseInt).orElse(0); + this.writing(Arrays.asList(ItemProtocol.TO_TASK.getKey(),ItemProtocol.TO_TARGET.getKey()), Arrays.asList(inst.getInstruction_code(),address)); + //this.writing(Arrays.asList(ItemProtocol.TO_TARGET.getKey()), Arrays.asList(address)); +// } } } } @@ -829,6 +880,16 @@ public class AppearanceInspectionScannerConveyorDeviceDriver extends AbstractOpc @SneakyThrows private void update_inst_status(Instruction instruction) { if (InstructionStatusEnum.READY.getIndex().equals(instruction.getInstruction_status()) && this.currentDeviceCode.equals(instruction.getStart_device_code())) { + String next_device_code = instruction.getNext_device_code(); + Device next_device = deviceAppService.findDeviceByCode(next_device_code); + if (next_device != null && next_device.getDeviceDriver() instanceof AppearanceInspectionScannerConveyorDeviceDriver) { + List targetDeviceCode = this.getExtraDeviceCodes("targetDeviceCode"); + if (targetDeviceCode != null && targetDeviceCode.contains(next_device_code)) { + if (StrUtil.equals(String.valueOf(this.task), instruction.getInstruction_code())) { + this.writing(Arrays.asList(ItemProtocol.TO_COMMAND.getKey()), Arrays.asList(CommandEnum.COMMAND_1.getValue())); + } + } + } logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "指令号:" + instruction.getInstruction_code() + ", 修改指令状态为 " + InstructionStatusEnum.getName(instruction.getInstruction_status()) + " -> " + InstructionStatusEnum.BUSY.getName())); instruction.setInstruction_status(InstructionStatusEnum.BUSY.getIndex()); instruction.setExecute_device_code(this.currentDeviceCode); diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/appearance_inspection_scannner_conveyor/ItemProtocol.java b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/appearance_inspection_scannner_conveyor/ItemProtocol.java index 845ff0f..a41cb25 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/appearance_inspection_scannner_conveyor/ItemProtocol.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/conveyor/appearance_inspection_scannner_conveyor/ItemProtocol.java @@ -9,6 +9,7 @@ import java.util.ArrayList; public enum ItemProtocol implements DeviceDriverBaseReader.KeyProvider { HEARTBEAT("heartbeat", "心跳", "DB1000.B0"), + STATUS("status", "手自动", "DB1000.B1"), MODE("mode", "工作模式", "DB1101.B0"), MOVE("move", "光电信号", "DB1101.B1"), ACTION("action", "动作信号", "DB1101.B2"), diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/screen/led_screen/LedScreenDeviceDriver.java b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/screen/led_screen/LedScreenDeviceDriver.java index dc86789..a0dd60d 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/screen/led_screen/LedScreenDeviceDriver.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/screen/led_screen/LedScreenDeviceDriver.java @@ -1,26 +1,239 @@ package org.nl.acs.device.driver.screen.led_screen; +import cn.hutool.core.collection.CollectionUtil; +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 onbon.bx06.Bx6GEnv; +import onbon.bx06.Bx6GScreenClient; +import onbon.bx06.area.DynamicBxArea; +import onbon.bx06.area.TextCaptionBxArea; +import onbon.bx06.area.page.TextBxPage; +import onbon.bx06.cmd.dyn.DynamicBxAreaRule; +import onbon.bx06.file.ProgramBxFile; +import onbon.bx06.series.Bx6E; +import onbon.bx06.utils.DisplayStyleFactory; +import org.nl.acs.device.device.domain.Device; +import org.nl.acs.device.device.service.DeviceAppService; import org.nl.acs.device.driver.DeviceDriver; import org.nl.acs.device.driver.RouteableDeviceDriver; import org.nl.acs.device.driver.AbstractDeviceDriver; import org.nl.acs.device.driver.ExecutableDeviceDriver; +import org.nl.acs.device.driver.conveyor.appearance_inspection_scannner_conveyor.AppearanceInspectionScannerConveyorDeviceDriver; +import org.nl.acs.device.driver.conveyor.appearance_inspection_scannner_conveyor.enums.ErrorEnum; +import org.nl.acs.device.driver.conveyor.strip_conveyor.StripConveyorDeviceDriver; +import org.nl.acs.device.driver.stacker.double_stacker.StandardStackerDeviceDriver; import org.nl.acs.monitor.DeviceStageMonitor; +import onbon.bx06.utils.DisplayStyleFactory.DisplayStyle; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; +import org.nl.config.SpringContextHolder; +import org.nl.config.lucene.service.LuceneExecuteLogService; + +import java.awt.*; +import java.awt.image.BufferedImage; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicBoolean; /** * LED点阵屏 + * * @author 涂强 */ @Slf4j @Data @RequiredArgsConstructor public class LedScreenDeviceDriver extends AbstractDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor { - @Override - public void execute() { + private static AtomicBoolean isInitialized = new AtomicBoolean(false); + + private Bx6GScreenClient screen = null; + + private final LuceneExecuteLogService logService = SpringContextHolder.getBean(LuceneExecuteLogService.class); + private final TaskService taskService = SpringContextHolder.getBean(TaskService.class); + private final DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppService.class); + + + private final int screenWidth = 192; + + private String modeMsgInfo = ""; + private String errorMsgInfo = ""; + private String taskMsgInfo = ""; + + @Override + public void execute() throws Exception { + if (isInitialized.compareAndSet(false, true)) { + Bx6GEnv.initial(30000); + } + //建立连接 + if (this.screen == null) { + String ip = Optional.ofNullable(this.getDevice().getExtraValue().get("ip_address")).map(Object::toString).orElse(null); + int port = Optional.ofNullable(this.getDevice().getExtraValue().get("ip_port")).map(Object::toString).map(Integer::parseInt).orElse(0); + if (ip == null || port == 0) { + return; + } + this.screen = new Bx6GScreenClient(this.getDevice().getDevice_code(), new Bx6E()); + this.screen.connect(ip, port); + } + + //设置节目 + DisplayStyle[] styles = DisplayStyleFactory.getStyles().toArray(new DisplayStyle[0]); + ProgramBxFile pf = new ProgramBxFile(0, this.screen.getProfile()); + TextCaptionBxArea area = new TextCaptionBxArea(0, 0, 192, 16, this.screen.getProfile()); + StringBuilder sb = new StringBuilder(); + //判断是否关联出入库模式 + boolean inOutFlag = Optional.ofNullable(this.getDevice().getExtraValue().get("inOut")).map(Object::toString).map(Boolean::parseBoolean).orElse(false); + if (!inOutFlag) { + String inOutMode = Optional.ofNullable(this.getDevice().getExtraValue().get("inOutMode")).map(Object::toString).orElse(""); + sb.append(inOutMode); + } else { + String linkSSX = Optional.ofNullable(this.getDevice().getExtraValue().get("linkSSX")).map(Object::toString).orElse(null); + Device device = deviceAppService.findDeviceByCode(linkSSX); + if (device != null && device.getDeviceDriver() instanceof StripConveyorDeviceDriver) { + StripConveyorDeviceDriver stripConveyorDeviceDriver = (StripConveyorDeviceDriver) device.getDeviceDriver(); + if (stripConveyorDeviceDriver.getInOutMode() == 0) { + sb.append("入库模式"); + } else { + sb.append("出库模式"); + } + } + } + if (!StrUtil.equals(this.modeMsgInfo, sb.toString())) { + TextBxPage page = new TextBxPage(sb.toString()); + page.setForeground(Color.green); + area.addPage(page); + pf.addArea(area); + this.screen.writeProgram(pf); + this.modeMsgInfo = sb.toString(); + } + + //设置动态区1报警信息 + List errorDevices = this.getExtraDeviceCodes("errorDevices"); + StringBuilder sbMsg = new StringBuilder(); + if (CollectionUtil.isNotEmpty(errorDevices)) { + sbMsg.append("报警信息: "); + String errorMsg = ""; + for (int i = 0; i < errorDevices.size(); i++) { + String deviceCode = errorDevices.get(i); + Device device = deviceAppService.findDeviceByCode(deviceCode); + if (device != null && device.getDeviceDriver() instanceof AppearanceInspectionScannerConveyorDeviceDriver) { + AppearanceInspectionScannerConveyorDeviceDriver appearanceInspectionScannerConveyorDeviceDriver = (AppearanceInspectionScannerConveyorDeviceDriver) device.getDeviceDriver(); + if (appearanceInspectionScannerConveyorDeviceDriver.getError() > 0) { + String label = ErrorEnum.getLabel(appearanceInspectionScannerConveyorDeviceDriver.getError()); + errorMsg = "设备" + deviceCode + " " + label + ","; + } + } else if (device != null && device.getDeviceDriver() instanceof StandardStackerDeviceDriver) { + StandardStackerDeviceDriver standardStackerDeviceDriver = (StandardStackerDeviceDriver) device.getDeviceDriver(); + if (standardStackerDeviceDriver.getFront_Zerror() > 0 || standardStackerDeviceDriver.getBack_Zerror() > 0) { + errorMsg = deviceCode + " "; + if (standardStackerDeviceDriver.getFront_Zerror() > 0) { + errorMsg = "设备" + deviceCode + " 前叉报警 " + org.nl.acs.device.driver.stacker.double_stacker.enums.ErrorEnum.getDesc(standardStackerDeviceDriver.getFront_Zerror()) + ","; + } + if (standardStackerDeviceDriver.getBack_Zerror() > 0) { + errorMsg = "设备" + deviceCode + " 后叉报警 " + org.nl.acs.device.driver.stacker.double_stacker.enums.ErrorEnum.getDesc(standardStackerDeviceDriver.getFront_Zerror()) + ","; + } + } + } + } + if (StrUtil.isEmpty(errorMsg)) { + sbMsg.append("无报警!"); + } else { + sbMsg.append(errorMsg); + if (sbMsg.length() > 0 && sbMsg.charAt(sbMsg.length() - 1) == ',') { + sbMsg.deleteCharAt(sbMsg.length() - 1); + } + } + } + if (!StrUtil.equals(this.errorMsgInfo, sbMsg.toString())) { + DynamicBxAreaRule rule_2 = new DynamicBxAreaRule(); + rule_2.setId(0); + rule_2.setRunMode((byte) 0); + rule_2.setRelativeAllPrograms(false); + rule_2.addRelativeProgram(0); + DynamicBxArea area_2 = new DynamicBxArea(0, 22, 192, 22, screen.getProfile()); + TextBxPage page_2 = new TextBxPage(sbMsg.toString()); + boolean flag = getStringWidth(sbMsg.toString()); + if (flag) { + page_2.setDisplayStyle(styles[1]); + } else { + page_2.setDisplayStyle(styles[4]); + } + page_2.setFont(new Font("Microsoft YaHei", Font.PLAIN, 12)); + page_2.setForeground(Color.green); + page_2.setLineHeight(12); + area_2.addPage(page_2); + this.screen.writeDynamic(rule_2, area_2); + this.errorMsgInfo = sbMsg.toString(); + } + + //设置动态区2任务信息 + StringBuilder sb2 = new StringBuilder(); + sb2.append("任务信息: "); + List startDevices = this.getExtraDeviceCodes("startDevices"); + if (CollectionUtil.isNotEmpty(startDevices)) { + for (int i = 0; i < startDevices.size(); i++) { + String start_device_code = startDevices.get(i); + List taskDtos = taskService.findTasksByStartCode(start_device_code); + if (ObjectUtil.isNotEmpty(taskDtos)) { + for (TaskDto taskDto : taskDtos) { + sb2.append("载具" + taskDto.getVehicle_code() + "由" + taskDto.getStart_point_code() + "->" + taskDto.getNext_point_code() + ","); + } + } + } + } + List nextDevices = this.getExtraDeviceCodes("nextDevices"); + if (CollectionUtil.isNotEmpty(nextDevices)) { + for (int i = 0; i < nextDevices.size(); i++) { + String next_device_code = nextDevices.get(i); + List taskDtos = taskService.findTasksByNextCode(next_device_code); + if (ObjectUtil.isNotEmpty(taskDtos)) { + for (TaskDto taskDto : taskDtos) { + sb2.append("载具" + taskDto.getVehicle_code() + "由" + taskDto.getStart_point_code() + "->" + taskDto.getNext_point_code() + ","); + } + } + } + } + if (sb2.length() > 0 && sb2.charAt(sb2.length() - 1) == ',') { + sb2.deleteCharAt(sb2.length() - 1); + } else { + sb2.append("无任务!"); + } + if (!StrUtil.equals(this.taskMsgInfo, sb2.toString())) { + DynamicBxAreaRule rule = new DynamicBxAreaRule(); + rule.setId(1); + rule.setRunMode((byte) 0); + rule.setRelativeAllPrograms(false); + rule.addRelativeProgram(0); + DynamicBxArea dArea = new DynamicBxArea(0, 37, 192, 37, screen.getProfile()); + TextBxPage dPage = new TextBxPage(sb2.toString()); + boolean flag = getStringWidth(sb2.toString()); + if (flag) { + dPage.setDisplayStyle(styles[1]); + } else { + dPage.setDisplayStyle(styles[4]); + } + dPage.setFont(new Font("Microsoft YaHei", Font.PLAIN, 12)); + dPage.setForeground(Color.green); + dPage.setLineHeight(12); + dArea.addPage(dPage); + screen.writeDynamic(rule, dArea); + this.taskMsgInfo = sb2.toString(); + } + + Integer upTime = Optional.ofNullable(this.getDevice().getExtraValue().get("upTime")).map(Object::toString).map(Integer::parseInt).orElse(60); + Thread.sleep(upTime * 1000); + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + synchronized (this) { + if (this.screen != null && this.screen.isConnected()) { + this.screen.disconnect(); + System.out.println(this.getDevice().getDevice_code() + "关闭Screen连接!"); + } + } + })); } @Override @@ -32,4 +245,15 @@ public class LedScreenDeviceDriver extends AbstractDeviceDriver implements Devic public void setDeviceStatus(JSONObject data) { } + + + private boolean getStringWidth(String msg) { + Font font = new Font("Microsoft YaHei", Font.PLAIN, 12); + BufferedImage image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); + Graphics g = image.getGraphics(); + g.setFont(font); + FontMetrics metrics = g.getFontMetrics(); + int width = metrics.stringWidth(msg); + return width < screenWidth; + } } diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/stacker/double_stacker/StandardStackerDeviceDriver.java b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/stacker/double_stacker/StandardStackerDeviceDriver.java index a9cdcf3..da297e0 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/stacker/double_stacker/StandardStackerDeviceDriver.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/stacker/double_stacker/StandardStackerDeviceDriver.java @@ -39,6 +39,8 @@ import org.nl.config.lucene.service.dto.LuceneLogDto; import java.util.*; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Collectors; /** @@ -255,6 +257,11 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme private int to_back_task = 0; private int lastTo_back_task = 0; + /** + * false代表出库、true代表入库 + */ + private boolean inOutFlag = false; + /** * 当前设备编号 */ @@ -329,7 +336,7 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme /** * 默认一楼优先、其次二楼、最后三楼 */ - private String[] floorPriorities = {"1", "2", "3"}; + private String[] floorPriorities; /** * 堆垛机在出入库对接点时前叉行走的排列层 @@ -341,6 +348,16 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme */ private Map>> floorMappingPoint; + /** + * 探货信号原位无货时的信号值 + */ + private List NO_HAS_GOODS = Arrays.asList(0, 1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25, 28, 29); + + /** + * 探货信号原位有货时的信号值 + */ + private List HAS_GOODS = Arrays.asList(2, 3, 6, 7, 10, 11, 14, 15, 18, 19, 22, 23, 26, 27, 30, 31); + private Map>> createFloorMappingPoint() { List floorPoint = this.getExtraListValue("floorPoint"); @@ -472,9 +489,26 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme @SneakyThrows @Override public void executeLogic() { - this.stackerNum = Optional.ofNullable(this.getExtraValue().get("stackerNum")).map(Object::toString).map(Integer::parseInt).orElse(1); - this.floorPriorities = Optional.ofNullable(this.getExtraValue().get("floorPriority")).map(Object::toString).orElse("1,2,3").split(","); - this.originPoint = Arrays.stream(Optional.ofNullable(this.getExtraValue().get("originPoint")).map(Object::toString).orElse("000").split(",")).collect(Collectors.toList()); + if (this.front_task != 0 && this.back_task != 0) { + if (this.front_task == this.back_task) { + this.message = "前叉和后叉任务号相同,不执行后续命令."; + return; + } + } + this.stackerNum = Optional.ofNullable(this.getExtraValue().get("stackerNum")) + .map(Object::toString) + .map(Integer::parseInt) + .orElse(1); + this.floorPriorities = Optional.ofNullable(this.getExtraValue().get("floorPriority")) + .map(Object::toString) + .filter(s -> !s.isEmpty()) + .map(s -> s.split(",")) + .orElse(new String[0]); + this.originPoint = Arrays.stream(Optional.ofNullable(this.getExtraValue().get("originPoint")) + .map(Object::toString) + .orElse("000") + .split(",")) + .collect(Collectors.toList()); this.floorMappingPoint = this.createFloorMappingPoint(); if (this.back_command != this.lastBack_command || this.front_command != this.lastFront_command) { @@ -489,19 +523,16 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme if (!this.againRequireSuccess) { this.mR(this.front_task, ForkTypeEnum.FRONT.getCode()); } - return; } else if (this.back_Zerror == ErrorEnum.MR.getCode()) { if (!this.againRequireSuccess) { this.mR(this.back_task, ForkTypeEnum.BACK.getCode()); } - return; } if (this.front_Zerror == ErrorEnum.KC.getCode() && this.back_Zerror == ErrorEnum.KC.getCode()) { if (!this.againRequireSuccess) { this.kC(this.front_task); this.kC(this.back_task); } - return; } else if (this.front_Zerror == ErrorEnum.KC.getCode()) { if (!this.againRequireSuccess) { this.kC(this.front_task); @@ -510,7 +541,6 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme this.backWrite(back_inst); } } - return; } else if (this.back_Zerror == ErrorEnum.KC.getCode()) { if (!this.againRequireSuccess) { this.kC(this.back_task); @@ -519,10 +549,9 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme this.frontWrite(front_inst); } } - return; } if (this.front_Zerror == ErrorEnum.ZD.getCode() && this.back_Zerror == ErrorEnum.ZD.getCode() - && this.front_command == CommandEnum.PICKUP.getStatus() && this.back_command == CommandEnum.PICKUP.getStatus() + && NO_HAS_GOODS.contains(this.front_forkCargo) && NO_HAS_GOODS.contains(this.back_forkCargo) ) { if (!this.againRequireSuccess) { this.getzD(this.front_task); @@ -530,30 +559,32 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme } } else if (this.front_Zerror == ErrorEnum.ZD.getCode()) { if (!this.againRequireSuccess) { - if (this.front_command == CommandEnum.PICKUP.getStatus()) { + if (NO_HAS_GOODS.contains(this.front_forkCargo)) { this.getzD(this.front_task); Instruction back_inst = instructionService.findByCodeFromCache(String.valueOf(this.back_task)); - if (ObjectUtil.isNotEmpty(back_inst)) { + if (ObjectUtil.isNotEmpty(back_inst) && NO_HAS_GOODS.contains(this.back_forkCargo)) { this.backWrite(back_inst); + } else if (ObjectUtil.isNotEmpty(back_inst) && HAS_GOODS.contains(this.back_forkCargo)) { + this.sendPutInfoToPlc(null, back_inst); } - } else if (this.front_command == CommandEnum.RELEASE.getStatus()) { + } else if (HAS_GOODS.contains(this.front_forkCargo)) { this.putzD(this.front_task, ForkTypeEnum.FRONT.getCode()); } } - return; } else if (this.back_Zerror == ErrorEnum.ZD.getCode()) { if (!this.againRequireSuccess) { - if (this.back_command == CommandEnum.PICKUP.getStatus()) { + if (NO_HAS_GOODS.contains(this.back_forkCargo)) { this.getzD(this.back_task); Instruction front_inst = instructionService.findByCodeFromCache(String.valueOf(this.front_task)); - if (ObjectUtil.isNotEmpty(front_inst)) { + if (ObjectUtil.isNotEmpty(front_inst) && NO_HAS_GOODS.contains(this.front_forkCargo)) { this.frontWrite(front_inst); + } else if (ObjectUtil.isNotEmpty(front_inst) && HAS_GOODS.contains(this.front_forkCargo)) { + this.sendPutInfoToPlc(front_inst, null); } - } else if (this.back_command == CommandEnum.RELEASE.getStatus()) { + } else if (HAS_GOODS.contains(this.back_forkCargo)) { this.putzD(this.back_task, ForkTypeEnum.BACK.getCode()); } } - return; } this.updateInstStatus(); @@ -571,6 +602,7 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme } else { this.message = ""; this.isError = false; + //编写业务逻辑方法 //待机 if (this.mode == ModeEnum.MODE_3.getNum() && this.isStandby() && !this.requireSuccess) { @@ -587,34 +619,103 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme } this.applyTask(); } else { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机工作模式:" + this.mode + ", 前叉作业状态:" + this.front_command + ", 前叉任务号:" + this.front_task + "前叉任务是否为空:" + ObjectUtil.isEmpty(frontInst) + ", 前叉探货信号:" + this.front_forkCargo)); - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机工作模式:" + this.mode + ", 后叉作业状态:" + this.back_command + ", 后叉任务号:" + this.back_task + "后叉任务是否为空:" + ObjectUtil.isEmpty(backInst) + ", 后叉探货信号:" + this.back_forkCargo)); - if (this.front_forkCargo == 0 && this.back_forkCargo == 0 && ObjectUtil.isNotEmpty(frontInst) && ObjectUtil.isNotEmpty(backInst)) { + List getFrontDeviceCodeList = this.getExtraDeviceCodes("frontDeviceCodeList"); + List getBackDeviceCodeList = this.getExtraDeviceCodes("backDeviceCodeList"); + if (NO_HAS_GOODS.contains(this.front_forkCargo) && NO_HAS_GOODS.contains(this.back_forkCargo) && ObjectUtil.isNotEmpty(frontInst) && ObjectUtil.isNotEmpty(backInst)) { this.sendGetInfoToPlc(frontInst, backInst); this.requireSuccess = true; - } else if (this.front_forkCargo == 0 && this.back_forkCargo == 0 && ObjectUtil.isNotEmpty(frontInst) && ObjectUtil.isEmpty(backInst)) { + } else if (NO_HAS_GOODS.contains(this.front_forkCargo) && NO_HAS_GOODS.contains(this.back_forkCargo) && ObjectUtil.isNotEmpty(frontInst) && ObjectUtil.isEmpty(backInst)) { this.sendGetInfoToPlc(frontInst, backInst); this.requireSuccess = true; - } else if (this.front_forkCargo == 0 && this.back_forkCargo == 0 && ObjectUtil.isEmpty(frontInst) && ObjectUtil.isNotEmpty(backInst)) { + } else if (NO_HAS_GOODS.contains(this.front_forkCargo) && NO_HAS_GOODS.contains(this.back_forkCargo) && ObjectUtil.isEmpty(frontInst) && ObjectUtil.isNotEmpty(backInst)) { this.sendGetInfoToPlc(frontInst, backInst); this.requireSuccess = true; - } else if (this.front_forkCargo != 0 && this.back_forkCargo == 0 && ObjectUtil.isNotEmpty(frontInst) && ObjectUtil.isNotEmpty(backInst)) { + } else if (HAS_GOODS.contains(this.front_forkCargo) && NO_HAS_GOODS.contains(this.back_forkCargo) && ObjectUtil.isNotEmpty(frontInst) && ObjectUtil.isNotEmpty(backInst)) { this.sendGetInfoToPlc(frontInst, backInst); this.requireSuccess = true; - } else if (this.front_forkCargo == 0 && this.back_forkCargo != 0 && ObjectUtil.isNotEmpty(frontInst) && ObjectUtil.isNotEmpty(backInst)) { + } else if (NO_HAS_GOODS.contains(this.front_forkCargo) && HAS_GOODS.contains(this.back_forkCargo) && ObjectUtil.isNotEmpty(frontInst) && ObjectUtil.isNotEmpty(backInst)) { this.sendGetInfoToPlc(frontInst, backInst); this.requireSuccess = true; - } else if (this.front_forkCargo != 0 && this.back_forkCargo != 0 && ObjectUtil.isNotEmpty(frontInst) && ObjectUtil.isNotEmpty(backInst)) { - this.sendPutInfoToPlc(frontInst, backInst); - this.requireSuccess = true; - } else if (this.front_forkCargo == 0 && this.back_forkCargo != 0 && ObjectUtil.isEmpty(frontInst) && ObjectUtil.isNotEmpty(backInst)) { - this.sendPutInfoToPlc(frontInst, backInst); - this.requireSuccess = true; - } else if (this.front_forkCargo != 0 && this.back_forkCargo == 0 && ObjectUtil.isNotEmpty(frontInst) && ObjectUtil.isEmpty(backInst)) { + } else if (HAS_GOODS.contains(this.front_forkCargo) && HAS_GOODS.contains(this.back_forkCargo) && ObjectUtil.isNotEmpty(frontInst) && ObjectUtil.isNotEmpty(backInst)) { this.sendPutInfoToPlc(frontInst, backInst); this.requireSuccess = true; + } else if (NO_HAS_GOODS.contains(this.front_forkCargo) && HAS_GOODS.contains(this.back_forkCargo) && ObjectUtil.isEmpty(frontInst) && ObjectUtil.isNotEmpty(backInst)) { + String back_start_device_code = backInst.getStart_device_code(); + String back_next_device_code = backInst.getNext_device_code(); + Device back_start_device = deviceAppService.findDeviceByCode(back_start_device_code); + Device back_next_device = deviceAppService.findDeviceByCode(back_next_device_code); + //入库 + if (instanceAppearance(back_start_device) && instanceStorage(back_next_device)) { + String getLinkDeviceCode = this.handExtraStringValue(back_start_device, "getLinkDeviceCode"); + String frontNoY = this.handExtraStringValue(this.getDevice(), "frontNoY"); + if (ObjectUtil.isEmpty(frontInst)) { + frontInst = instructionService.findReadyInstByLinkDeviceCodeAndStartDeviceCode(getLinkDeviceCode, frontNoY, getFrontDeviceCodeList); + if (ObjectUtil.isNotEmpty(frontInst)) { + String front_start_device_code = frontInst.getStart_device_code(); + Device front_start_device = deviceAppService.findDeviceByCode(front_start_device_code); + this.frontWrite(front_start_device, frontInst); + } else { + this.sendPutInfoToPlc(frontInst, backInst); + } + } + this.requireSuccess = true; + } + //出库 + else if (instanceStorage(back_start_device) && instanceAppearance(back_next_device)) { + String getLinkDeviceCode = this.handExtraStringValue(back_next_device, "getLinkDeviceCode"); + String frontNoY = this.handExtraStringValue(this.getDevice(), "frontNoY"); + if (ObjectUtil.isEmpty(frontInst)) { + frontInst = instructionService.findReadyInstByLinkDeviceCodeAndNextDeviceCode(getLinkDeviceCode, frontNoY, getFrontDeviceCodeList); + if (ObjectUtil.isNotEmpty(frontInst)) { + this.frontWrite(frontInst); + } else { + this.sendPutInfoToPlc(frontInst, backInst); + } + } + this.requireSuccess = true; + } else { + this.sendPutInfoToPlc(frontInst, backInst); + this.requireSuccess = true; + } + } else if (HAS_GOODS.contains(this.front_forkCargo) && NO_HAS_GOODS.contains(this.back_forkCargo) && ObjectUtil.isNotEmpty(frontInst) && ObjectUtil.isEmpty(backInst)) { + String front_start_device_code = frontInst.getStart_device_code(); + String front_next_device_code = frontInst.getNext_device_code(); + Device front_start_device = deviceAppService.findDeviceByCode(front_start_device_code); + Device front_next_device = deviceAppService.findDeviceByCode(front_next_device_code); + //入库 + if (instanceAppearance(front_start_device) && instanceStorage(front_next_device)) { + String getLinkDeviceCode = this.handExtraStringValue(front_start_device, "getLinkDeviceCode"); + String backNoY = this.handExtraStringValue(this.getDevice(), "backNoY"); + if (ObjectUtil.isEmpty(backInst)) { + backInst = instructionService.findReadyInstByLinkDeviceCodeAndStartDeviceCode(getLinkDeviceCode, backNoY, getBackDeviceCodeList); + if (ObjectUtil.isNotEmpty(backInst)) { + String back_start_device_code = backInst.getStart_device_code(); + Device back_start_device = deviceAppService.findDeviceByCode(back_start_device_code); + this.backWrite(back_start_device, backInst); + } else { + this.sendPutInfoToPlc(frontInst, backInst); + } + this.requireSuccess = true; + } + } + //出库 + else if (instanceStorage(front_start_device) && instanceAppearance(front_next_device)) { + String getLinkDeviceCode = this.handExtraStringValue(front_next_device, "getLinkDeviceCode"); + String backNoY = this.handExtraStringValue(this.getDevice(), "backNoY"); + if (ObjectUtil.isEmpty(backInst)) { + backInst = instructionService.findReadyInstByLinkDeviceCodeAndNextDeviceCode(getLinkDeviceCode, backNoY, getBackDeviceCodeList); + if (ObjectUtil.isNotEmpty(backInst)) { + this.backWrite(backInst); + } else { + this.sendPutInfoToPlc(frontInst, backInst); + } + } + this.requireSuccess = true; + } else { + this.sendPutInfoToPlc(frontInst, backInst); + this.requireSuccess = true; + } } - } } //取货中 @@ -625,143 +726,147 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme //取货完成 else if (mode == ModeEnum.MODE_3.getNum() && this.isPickupComplete() && !requireSuccess) { logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 前叉作业状态:" + this.front_command + ", 后叉作业状态:" + this.back_command)); + List getFrontDeviceCodeList = this.getExtraDeviceCodes("frontDeviceCodeList"); + List getBackDeviceCodeList = this.getExtraDeviceCodes("backDeviceCodeList"); Instruction frontInst = instructionService.findByCodeFromCache(String.valueOf(this.front_task)); Instruction backInst = instructionService.findByCodeFromCache(String.valueOf(this.back_task)); if (this.front_command == CommandEnum.PICKUP_COMPLETE.getStatus() && this.back_command == CommandEnum.PICKUP_COMPLETE.getStatus()) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 前叉和后叉作业状态都是取货完成,下发放货信息")); this.sendPutInfoToPlc(frontInst, backInst); } else if (this.front_command == CommandEnum.PICKUP_COMPLETE.getStatus()) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 前叉作业状态是取货完成")); String front_start_device_code = frontInst.getStart_device_code(); String front_next_device_code = frontInst.getNext_device_code(); Device front_start_device = deviceAppService.findDeviceByCode(front_start_device_code); Device front_next_device = deviceAppService.findDeviceByCode(front_next_device_code); //入库 if (instanceAppearance(front_start_device) && instanceStorage(front_next_device)) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 前叉作业状态是取货完成, 是入库任务")); String getLinkDeviceCode = this.handExtraStringValue(front_start_device, "getLinkDeviceCode"); String backNoY = this.handExtraStringValue(this.getDevice(), "backNoY"); if (ObjectUtil.isEmpty(backInst)) { - backInst = instructionService.findReadyInstByLinkDeviceCodeAndStartDeviceCode(getLinkDeviceCode, backNoY); + backInst = instructionService.findReadyInstByLinkDeviceCodeAndStartDeviceCode(getLinkDeviceCode, backNoY, getBackDeviceCodeList); if (ObjectUtil.isNotEmpty(backInst)) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 前叉作业状态是取货完成, 是入库任务, 查询出后叉任务, 下发后叉取货信息")); - String back_start_device_code = backInst.getStart_device_code(); - Device back_start_device = deviceAppService.findDeviceByCode(back_start_device_code); - this.backWrite(back_start_device, backInst); + int numericPart = Integer.parseInt(getNumericPart(backInst.getNext_device_code())); + if (numericPart % 4 == 2 || numericPart % 4 == 3) { + String qPoint = getZdPoint(backInst.getNext_point_code()); + TaskDto taskDto = taskService.findByNextPointCode(qPoint); + if (ObjectUtil.isNotEmpty(taskDto)) { + this.sendPutInfoToPlc(frontInst, backInst); + } else { + String back_start_device_code = backInst.getStart_device_code(); + Device back_start_device = deviceAppService.findDeviceByCode(back_start_device_code); + this.backWrite(back_start_device, backInst); + } + } } else { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 前叉作业状态是取货完成, 是入库任务, 未查询出后叉任务, 下发放货信息")); this.sendPutInfoToPlc(frontInst, backInst); } } else { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 前叉作业状态是取货完成, 是入库任务, 已存在后叉任务, 下发放货信息")); this.sendPutInfoToPlc(frontInst, backInst); } } //出库 else if (instanceStorage(front_start_device) && instanceAppearance(front_next_device)) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 前叉作业状态是取货完成, 是出库任务")); String getLinkDeviceCode = this.handExtraStringValue(front_next_device, "getLinkDeviceCode"); String backNoY = this.handExtraStringValue(this.getDevice(), "backNoY"); if (ObjectUtil.isEmpty(backInst)) { - backInst = instructionService.findReadyInstByLinkDeviceCodeAndNextDeviceCode(getLinkDeviceCode, backNoY); + backInst = instructionService.findShallowReadyInstByLinkDeviceCodeAndNextDeviceCode(getLinkDeviceCode, backNoY, getBackDeviceCodeList); if (ObjectUtil.isNotEmpty(backInst)) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 前叉作业状态是取货完成, 是出库任务, 查询出后叉任务, 下发后叉取货信息")); this.backWrite(backInst); } else { - //下发前叉放货信息 - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 前叉作业状态是取货完成, 是出库任务, 未查询出后叉任务, 下发放货信息")); - this.sendPutInfoToPlc(frontInst, backInst); + backInst = instructionService.findDeepReadyInstByLinkDeviceCodeAndNextDeviceCode(getLinkDeviceCode, backNoY, getBackDeviceCodeList); + if (ObjectUtil.isNotEmpty(backInst)) { + String qPoint = getZdPoint(backInst.getStart_point_code()); + TaskDto taskDto = taskService.findByStartPointCode(qPoint); + if (ObjectUtil.isNotEmpty(taskDto)) { + this.sendPutInfoToPlc(frontInst, backInst); + } else { + this.backWrite(backInst); + } + } else { + //下发前叉放货信息 + this.sendPutInfoToPlc(frontInst, backInst); + } } } else { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 前叉作业状态是取货完成, 是出库任务, 已存在后叉任务, 下发放货信息")); this.sendPutInfoToPlc(frontInst, backInst); } } else if (instanceAppearance(front_start_device) && instanceAppearance(front_next_device)) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 前叉作业状态是取货完成, 是特殊任务输送线到输送线")); if (ObjectUtil.isEmpty(backInst)) { - List getBackDeviceCodeList = this.getExtraDeviceCodes("backDeviceCodeList"); + // List getBackDeviceCodeList = this.getExtraDeviceCodes("backDeviceCodeList"); List specialGetDevice = this.getExtraDeviceCodes("specialGetDevice"); List specialPutDevice = this.getExtraDeviceCodes("specialPutDevice"); backInst = instructionService.findReadyInstBySpecialDeviceAndStartDeviceCode(getBackDeviceCodeList, specialGetDevice, specialPutDevice, front_start_device_code); if (ObjectUtil.isNotEmpty(backInst)) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 前叉作业状态是取货完成, 是特殊任务输送线到输送线,查询到特殊任务后叉任务,下发后叉取货信息")); String back_start_device_code = backInst.getStart_device_code(); Device back_start_device = deviceAppService.findDeviceByCode(back_start_device_code); this.backWrite(back_start_device, backInst); } else { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 前叉作业状态是取货完成, 是特殊任务输送线到输送线,未查询到特殊任务后叉任务,下发放货信息")); this.sendPutInfoToPlc(frontInst, backInst); } } } else { //下发前叉放货信息 - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 前叉作业状态是取货完成, 是移库任务, 下发放货信息")); this.sendPutInfoToPlc(frontInst, backInst); } } else if (this.back_command == CommandEnum.PICKUP_COMPLETE.getStatus()) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 后叉作业状态是取货完成")); String back_start_device_code = backInst.getStart_device_code(); String back_next_device_code = backInst.getNext_device_code(); Device back_start_device = deviceAppService.findDeviceByCode(back_start_device_code); Device back_next_device = deviceAppService.findDeviceByCode(back_next_device_code); //入库 if (instanceAppearance(back_start_device) && instanceStorage(back_next_device)) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 后叉作业状态是取货完成, 是入库任务")); String getLinkDeviceCode = this.handExtraStringValue(back_start_device, "getLinkDeviceCode"); String frontNoY = this.handExtraStringValue(this.getDevice(), "frontNoY"); if (ObjectUtil.isEmpty(frontInst)) { - frontInst = instructionService.findReadyInstByLinkDeviceCodeAndStartDeviceCode(getLinkDeviceCode, frontNoY); + frontInst = instructionService.findReadyInstByLinkDeviceCodeAndStartDeviceCode(getLinkDeviceCode, frontNoY, getFrontDeviceCodeList); if (ObjectUtil.isNotEmpty(frontInst)) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 后叉作业状态是取货完成, 是入库任务, 查询出前叉任务, 下发前叉取货信息")); String front_start_device_code = frontInst.getStart_device_code(); Device front_start_device = deviceAppService.findDeviceByCode(front_start_device_code); this.frontWrite(front_start_device, frontInst); } else { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 后叉作业状态是取货完成, 是入库任务, 未查询出前叉任务, 下发放货信息")); this.sendPutInfoToPlc(frontInst, backInst); } } else { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 后叉作业状态是取货完成, 是入库任务, 已存在前叉任务, 下发放货信息")); this.sendPutInfoToPlc(frontInst, backInst); } } //出库 else if (instanceStorage(back_start_device) && instanceAppearance(back_next_device)) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 后叉作业状态是取货完成, 是出库任务")); String getLinkDeviceCode = this.handExtraStringValue(back_next_device, "getLinkDeviceCode"); String frontNoY = this.handExtraStringValue(this.getDevice(), "frontNoY"); if (ObjectUtil.isEmpty(frontInst)) { - frontInst = instructionService.findReadyInstByLinkDeviceCodeAndNextDeviceCode(getLinkDeviceCode, frontNoY); + frontInst = instructionService.findShallowReadyInstByLinkDeviceCodeAndNextDeviceCode(getLinkDeviceCode, frontNoY, getFrontDeviceCodeList); if (ObjectUtil.isNotEmpty(frontInst)) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 后叉作业状态是取货完成, 是出库任务, 查询出前叉任务, 下发前叉取货信息")); this.frontWrite(frontInst); } else { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 后叉作业状态是取货完成, 是出库任务, 未查询出前叉任务, 下发放货信息")); - this.sendPutInfoToPlc(frontInst, backInst); + frontInst = instructionService.findDeepReadyInstByLinkDeviceCodeAndNextDeviceCode(getLinkDeviceCode, frontNoY, getFrontDeviceCodeList); + if (ObjectUtil.isNotEmpty(frontInst)) { + String qPoint = getZdPoint(frontInst.getStart_point_code()); + TaskDto taskDto = taskService.findByStartPointCode(qPoint); + if (ObjectUtil.isNotEmpty(taskDto)) { + this.sendPutInfoToPlc(frontInst, backInst); + } else { + this.frontWrite(frontInst); + } + } } } else { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 后叉作业状态是取货完成, 是出库任务, 已存在前叉任务, 下发放货信息")); this.sendPutInfoToPlc(frontInst, backInst); } } else if (instanceAppearance(back_start_device) && instanceAppearance(back_next_device)) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 后叉作业状态是取货完成, 是特殊任务输送线到输送线")); if (ObjectUtil.isEmpty(backInst)) { - List getFrontDeviceCodeList = this.getExtraDeviceCodes("frontDeviceCodeList"); + //List getFrontDeviceCodeList = this.getExtraDeviceCodes("frontDeviceCodeList"); List specialGetDevice = this.getExtraDeviceCodes("specialGetDevice"); List specialPutDevice = this.getExtraDeviceCodes("specialPutDevice"); frontInst = instructionService.findReadyInstBySpecialDeviceAndStartDeviceCode(getFrontDeviceCodeList, specialGetDevice, specialPutDevice, back_start_device_code); if (ObjectUtil.isNotEmpty(frontInst)) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 后叉作业状态是取货完成, 是特殊任务输送线到输送线,查询到特殊任务前叉任务,下发前叉取货信息")); String front_start_device_code = frontInst.getStart_device_code(); Device front_start_device = deviceAppService.findDeviceByCode(front_start_device_code); this.frontWrite(front_start_device, frontInst); } else { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 后叉作业状态是取货完成, 是特殊任务输送线到输送线,未查询到特殊任务前叉任务,下发放货信息")); this.sendPutInfoToPlc(frontInst, backInst); } } } else { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 后叉作业状态是取货完成, 是移库任务, 下发放货信息")); this.sendPutInfoToPlc(frontInst, backInst); } } @@ -769,7 +874,6 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme } //放货中 else if (mode == ModeEnum.MODE_3.getNum() && this.isRelease() && !this.requireSuccess) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报放货中, 前叉作业状态:" + this.front_command + ", 后叉作业状态:" + this.back_command)); if (this.lastBack_command != CommandEnum.UNLOAD.getStatus() && this.lastFront_command != CommandEnum.UNLOAD.getStatus()) { this.clearInfoToPlc(); } else if (this.lastBack_command != CommandEnum.UNLOAD.getStatus() && this.back_command != CommandEnum.STANDY.getStatus()) { @@ -782,32 +886,25 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme } //请求卸货 else if (mode == ModeEnum.MODE_3.getNum() && this.isUnload() && !requireSuccess) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报请求卸货, 前叉作业状态:" + this.front_command + ", 后叉作业状态:" + this.back_command)); this.writing(ItemProtocol.TO_COMMAND.getKey(), SendSignalEnum.COMMAND_THREE.getSignalNum()); this.requireSuccess = true; } //卸货完成 else if (mode == ModeEnum.MODE_3.getNum() && this.isUnloadComplete() && !requireSuccess) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报卸货完成, 前叉作业状态:" + this.front_command + ", 后叉作业状态:" + this.back_command)); if (this.front_command == CommandEnum.UNLOAD_COMPLETE.getStatus() && this.back_command == CommandEnum.UNLOAD_COMPLETE.getStatus()) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报卸货完成, 前叉和后叉作业状态都是卸货完成,反馈确认卸货完成")); this.writing(ItemProtocol.TO_COMMAND.getKey(), SendSignalEnum.COMMAND_ELEVEN.getSignalNum()); } else if (this.front_command == CommandEnum.UNLOAD_COMPLETE.getStatus()) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报卸货完成, 前叉作业状态是卸货完成,反馈确认卸货完成")); this.writing(ItemProtocol.TO_COMMAND.getKey(), SendSignalEnum.COMMAND_ELEVEN.getSignalNum()); //根据后叉指令号,查询后叉指令,下发后叉放货指令信息 Instruction backTask = instructionService.findByCodeFromCache(String.valueOf(back_task)); if (ObjectUtil.isNotEmpty(backTask)) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报卸货完成, 前叉作业状态是卸货完成,查询到后叉信息还存在, 下发后叉放货信息")); this.sendPutInfoToPlc(null, backTask); } } else if (this.back_command == CommandEnum.UNLOAD_COMPLETE.getStatus()) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报卸货完成, 后叉作业状态是卸货完成,反馈确认卸货完成")); this.writing(ItemProtocol.TO_COMMAND.getKey(), SendSignalEnum.COMMAND_ELEVEN.getSignalNum()); //根据前叉指令号,查询前叉指令,下发前叉放货指令信息 Instruction frontTask = instructionService.findByCodeFromCache(String.valueOf(front_task)); if (ObjectUtil.isNotEmpty(frontTask)) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报卸货完成, 后叉作业状态是卸货完成,查询到前叉信息还存在, 下发前叉放货信息")); this.sendPutInfoToPlc(frontTask, null); } } @@ -816,6 +913,14 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme } } + private String getNumericPart(String device_c0de) { + Pattern pattern = Pattern.compile("\\d+"); + Matcher matcher = pattern.matcher(device_c0de); + if (matcher.find()) { + return matcher.group(); + } + return "0"; + } /** * 放货阻挡、满入更改任务指令终点信息 @@ -1064,7 +1169,7 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme front_start_device = deviceAppService.findDeviceByCode(front_start_device_code); if (front_start_device != null) { String getLinkDeviceCode = this.handExtraStringValue(front_start_device, "getLinkDeviceCode"); - backInst = instructionService.findReadyInstByLinkDeviceCodeAndStartDeviceCode(getLinkDeviceCode, backNoY); + backInst = instructionService.findReadyInstByLinkDeviceCodeAndStartDeviceCode(getLinkDeviceCode, backNoY, getBackDeviceCodeList); if (ObjectUtil.isEmpty(backInst)) { Instruction inst = instructionService.findBusyInstByNextDeviceCode(getLinkDeviceCode); if (ObjectUtil.isNotEmpty(inst)) { @@ -1084,11 +1189,14 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme back_start_device = deviceAppService.findDeviceByCode(back_start_device_code); if (back_start_device != null) { String getLinkDeviceCode = this.handExtraStringValue(back_start_device, "getLinkDeviceCode"); - frontInst = instructionService.findReadyInstByLinkDeviceCodeAndStartDeviceCode(getLinkDeviceCode, frontNoY); - if (ObjectUtil.isEmpty(frontInst)) { - Instruction inst = instructionService.findBusyInstByNextDeviceCode(getLinkDeviceCode); - if (ObjectUtil.isNotEmpty(inst)) { - return; + front_start_device = deviceAppService.findDeviceByCode(getLinkDeviceCode); + if (front_start_device != null) { + frontInst = instructionService.findReadyInstByLinkDeviceCodeAndStartDeviceCode(getLinkDeviceCode, frontNoY, getFrontDeviceCodeList); + if (ObjectUtil.isEmpty(frontInst)) { + Instruction inst = instructionService.findBusyInstByNextDeviceCode(getLinkDeviceCode); + if (ObjectUtil.isNotEmpty(inst)) { + return; + } } } } @@ -1264,8 +1372,7 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme */ private void applyTaskOneInOneOut() { if (!prohibitInWarehouse) { - String currentXYZ = this.front_z + "" + this.front_x + this.front_y; - if (this.originPoint.contains(currentXYZ)) { + if (!this.inOutFlag) { this.applyTaskOneIn(); } else { this.applyTaskOneOut(); @@ -1274,7 +1381,6 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme } private void applyTaskOneIn() { - String currentXYZ = this.front_z + "" + this.front_x + this.front_y; boolean flag = this.applySpecialTask(); if (flag) { this.unExecutedMessage = null; @@ -1284,62 +1390,92 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme Instruction backInst = null; Device front_start_device = null; Device back_start_device = null; - for (int i = 0; i < this.floorPriorities.length; i++) { - String floorPriority = this.floorPriorities[i]; - Map> floorPoint = this.floorMappingPoint.get(floorPriority); - if (ObjectUtil.isEmpty(floorPoint)) { - continue; - } - List points = floorPoint.get("in"); - if (CollectionUtil.isEmpty(points)) { - continue; + if (this.floorPriorities.length > 0) { + for (int i = 0; i < this.floorPriorities.length; i++) { + String floorPriority = this.floorPriorities[i]; + Map> floorPoint = this.floorMappingPoint.get(floorPriority); + if (ObjectUtil.isEmpty(floorPoint)) { + continue; + } + List points = floorPoint.get("in"); + if (CollectionUtil.isEmpty(points)) { + continue; + } + List getFrontDeviceCodeList = this.getExtraDeviceCodes("frontDeviceCodeList"); + String frontNoY = this.handExtraStringValue(this.getDevice(), "frontNoY"); + List getBackDeviceCodeList = this.getExtraDeviceCodes("backDeviceCodeList"); + String backNoY = this.handExtraStringValue(this.getDevice(), "backNoY"); + List frontInsts = instructionService.findReadyInstByStartDeviceCode(getFrontDeviceCodeList, frontNoY); + if (CollectionUtil.isNotEmpty(frontInsts)) { + for (int j = 0; j < frontInsts.size(); j++) { + Instruction instruction = frontInsts.get(j); + if (points.contains(instruction.getStart_device_code())) { + frontInst = instruction; + break; + } + } + if (ObjectUtil.isNotEmpty(frontInst)) { + String front_start_device_code = frontInst.getStart_device_code(); + front_start_device = deviceAppService.findDeviceByCode(front_start_device_code); + if (front_start_device != null) { + String getLinkDeviceCode = this.handExtraStringValue(front_start_device, "getLinkDeviceCode"); + backInst = instructionService.findReadyInstByLinkDeviceCodeAndStartDeviceCode(getLinkDeviceCode, backNoY, getBackDeviceCodeList); + if (ObjectUtil.isEmpty(backInst)) { + Instruction inst = instructionService.findBusyInstByNextDeviceCode(getLinkDeviceCode); + if (ObjectUtil.isNotEmpty(inst)) { + return; + } + } + } + } + } else { + if (this.stackerNum == 2) { + List backInsts = instructionService.findReadyInstByStartDeviceCode(getBackDeviceCodeList, backNoY); + if (CollectionUtil.isNotEmpty(backInsts)) { + for (int k = 0; k < backInsts.size(); k++) { + Instruction instruction = backInsts.get(k); + if (points.contains(instruction.getStart_device_code())) { + backInst = instruction; + break; + } + } + } + if (ObjectUtil.isNotEmpty(backInst)) { + String back_start_device_code = backInst.getStart_device_code(); + back_start_device = deviceAppService.findDeviceByCode(back_start_device_code); + if (back_start_device != null) { + String getLinkDeviceCode = this.handExtraStringValue(back_start_device, "getLinkDeviceCode"); + frontInst = instructionService.findReadyInstByLinkDeviceCodeAndStartDeviceCode(getLinkDeviceCode, frontNoY, getFrontDeviceCodeList); + if (ObjectUtil.isEmpty(frontInst)) { + Instruction inst = instructionService.findBusyInstByNextDeviceCode(getLinkDeviceCode); + if (ObjectUtil.isNotEmpty(inst)) { + return; + } + } + } + } + } + } + if (ObjectUtil.isNotEmpty(frontInst) || ObjectUtil.isNotEmpty(backInst)) { + break; + } } + } else { List getFrontDeviceCodeList = this.getExtraDeviceCodes("frontDeviceCodeList"); String frontNoY = this.handExtraStringValue(this.getDevice(), "frontNoY"); List getBackDeviceCodeList = this.getExtraDeviceCodes("backDeviceCodeList"); String backNoY = this.handExtraStringValue(this.getDevice(), "backNoY"); - List frontInsts = instructionService.findReadyInstByStartDeviceCode(getFrontDeviceCodeList, frontNoY); + List frontInsts = instructionService.findDeepReadyInstByStartDeviceCode(getFrontDeviceCodeList, frontNoY); if (CollectionUtil.isNotEmpty(frontInsts)) { - for (int j = 0; j < frontInsts.size(); j++) { - Instruction instruction = frontInsts.get(j); - if (points.contains(instruction.getStart_device_code())) { - frontInst = instruction; - break; - } - } + frontInst = frontInsts.get(0); if (ObjectUtil.isNotEmpty(frontInst)) { String front_start_device_code = frontInst.getStart_device_code(); front_start_device = deviceAppService.findDeviceByCode(front_start_device_code); if (front_start_device != null) { String getLinkDeviceCode = this.handExtraStringValue(front_start_device, "getLinkDeviceCode"); - backInst = instructionService.findReadyInstByLinkDeviceCodeAndStartDeviceCode(getLinkDeviceCode, backNoY); - if (ObjectUtil.isEmpty(backInst)) { - Instruction inst = instructionService.findBusyInstByNextDeviceCode(getLinkDeviceCode); - if (ObjectUtil.isNotEmpty(inst)) { - return; - } - } - } - } - } else { - if (this.stackerNum == 2) { - List backInsts = instructionService.findReadyInstByStartDeviceCode(getBackDeviceCodeList, backNoY); - if (CollectionUtil.isNotEmpty(backInsts)) { - for (int k = 0; k < backInsts.size(); k++) { - Instruction instruction = backInsts.get(k); - if (points.contains(instruction.getStart_device_code())) { - backInst = instruction; - break; - } - } - } - if (ObjectUtil.isNotEmpty(backInst)) { - String back_start_device_code = backInst.getStart_device_code(); - back_start_device = deviceAppService.findDeviceByCode(back_start_device_code); - if (back_start_device != null) { - String getLinkDeviceCode = this.handExtraStringValue(back_start_device, "getLinkDeviceCode"); - frontInst = instructionService.findReadyInstByLinkDeviceCodeAndStartDeviceCode(getLinkDeviceCode, frontNoY); - if (ObjectUtil.isEmpty(frontInst)) { + if (StrUtil.isNotEmpty(getLinkDeviceCode)) { + backInst = instructionService.findDeepReadyInstByLinkDeviceCodeAndStartDeviceCode(getLinkDeviceCode, backNoY, getBackDeviceCodeList); + if (ObjectUtil.isEmpty(backInst)) { Instruction inst = instructionService.findBusyInstByNextDeviceCode(getLinkDeviceCode); if (ObjectUtil.isNotEmpty(inst)) { return; @@ -1348,9 +1484,73 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme } } } - } - if (ObjectUtil.isNotEmpty(frontInst) || ObjectUtil.isNotEmpty(backInst)) { - break; + } else { + if (this.stackerNum == 2) { + List backInsts = instructionService.findDeepReadyInstByStartDeviceCode(getBackDeviceCodeList, backNoY); + if (CollectionUtil.isNotEmpty(backInsts)) { + backInst = backInsts.get(0); + } + if (ObjectUtil.isNotEmpty(backInst)) { + String back_start_device_code = backInst.getStart_device_code(); + back_start_device = deviceAppService.findDeviceByCode(back_start_device_code); + if (back_start_device != null) { + String getLinkDeviceCode = this.handExtraStringValue(back_start_device, "getLinkDeviceCode"); + front_start_device = deviceAppService.findDeviceByCode(getLinkDeviceCode); + if (front_start_device != null) { + frontInst = instructionService.findDeepReadyInstByLinkDeviceCodeAndStartDeviceCode(getLinkDeviceCode, frontNoY, getFrontDeviceCodeList); + if (ObjectUtil.isEmpty(frontInst)) { + Instruction inst = instructionService.findBusyInstByNextDeviceCode(getLinkDeviceCode); + if (ObjectUtil.isNotEmpty(inst)) { + return; + } + } + } + } + } else { + frontInsts = instructionService.findShallowReadyInstByStartDeviceCode(getFrontDeviceCodeList, frontNoY); + if (CollectionUtil.isNotEmpty(frontInsts)) { + frontInst = frontInsts.get(0); + if (ObjectUtil.isNotEmpty(frontInst)) { + String front_start_device_code = frontInst.getStart_device_code(); + front_start_device = deviceAppService.findDeviceByCode(front_start_device_code); + if (front_start_device != null) { + String getLinkDeviceCode = this.handExtraStringValue(front_start_device, "getLinkDeviceCode"); + if (StrUtil.isNotEmpty(getLinkDeviceCode)) { + backInst = instructionService.findShallowReadyInstByLinkDeviceCodeAndStartDeviceCode(getLinkDeviceCode, backNoY, getBackDeviceCodeList); + if (ObjectUtil.isEmpty(backInst)) { + Instruction inst = instructionService.findBusyInstByNextDeviceCode(getLinkDeviceCode); + if (ObjectUtil.isNotEmpty(inst)) { + return; + } + } + } + } + } + } else { + backInsts = instructionService.findShallowReadyInstByStartDeviceCode(getBackDeviceCodeList, backNoY); + if (CollectionUtil.isNotEmpty(backInsts)) { + backInst = backInsts.get(0); + } + if (ObjectUtil.isNotEmpty(backInst)) { + String back_start_device_code = backInst.getStart_device_code(); + back_start_device = deviceAppService.findDeviceByCode(back_start_device_code); + if (back_start_device != null) { + String getLinkDeviceCode = this.handExtraStringValue(back_start_device, "getLinkDeviceCode"); + front_start_device = deviceAppService.findDeviceByCode(getLinkDeviceCode); + if (front_start_device != null) { + frontInst = instructionService.findShallowReadyInstByLinkDeviceCodeAndStartDeviceCode(getLinkDeviceCode, frontNoY, getFrontDeviceCodeList); + if (ObjectUtil.isEmpty(frontInst)) { + Instruction inst = instructionService.findBusyInstByNextDeviceCode(getLinkDeviceCode); + if (ObjectUtil.isNotEmpty(inst)) { + return; + } + } + } + } + } + } + } + } } } if (ObjectUtil.isNotEmpty(frontInst) && ObjectUtil.isNotEmpty(backInst)) { @@ -1366,56 +1566,103 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme this.unExecutedMessage = null; this.requireSuccess = true; } else { - if (this.originPoint.contains(currentXYZ)) { + if (!this.inOutFlag) { this.applyTaskOneOut(); } } } private void applyTaskOneOut() { - String currentXYZ = this.front_z + "" + this.front_x + this.front_y; Instruction frontInst = null; Instruction backInst = null; - for (int i = 0; i < this.floorPriorities.length; i++) { - String floorPriority = this.floorPriorities[i]; - Map> floorPoint = this.floorMappingPoint.get(floorPriority); - if (ObjectUtil.isEmpty(floorPoint)) { - continue; - } - List points = floorPoint.get("out"); - if (CollectionUtil.isEmpty(points)) { - continue; + if (this.floorPriorities.length > 0) { + for (int i = 0; i < this.floorPriorities.length; i++) { + String floorPriority = this.floorPriorities[i]; + Map> floorPoint = this.floorMappingPoint.get(floorPriority); + if (ObjectUtil.isEmpty(floorPoint)) { + continue; + } + List points = floorPoint.get("out"); + if (CollectionUtil.isEmpty(points)) { + continue; + } + List getFrontDeviceCodeList = this.getExtraDeviceCodes("frontDeviceCodeList"); + List getBackDeviceCodeList = this.getExtraDeviceCodes("backDeviceCodeList"); + String frontNoY = this.handExtraStringValue(this.getDevice(), "frontNoY"); + String backNoY = this.handExtraStringValue(this.getDevice(), "backNoY"); + List frontInsts = instructionService.findReadyInstByNextDeviceCode(getFrontDeviceCodeList, frontNoY); + if (CollectionUtil.isNotEmpty(frontInsts)) { + for (int j = 0; j < frontInsts.size(); j++) { + Instruction instruction = frontInsts.get(j); + if (points.contains(instruction.getNext_device_code())) { + frontInst = instruction; + break; + } + } + if (ObjectUtil.isNotEmpty(frontInst) && this.stackerNum == 2) { + String front_next_device_code = frontInst.getNext_device_code(); + Device front_next_device = deviceAppService.findDeviceByCode(front_next_device_code); + if (front_next_device != null) { + String getLinkDeviceCode = this.handExtraStringValue(front_next_device, "getLinkDeviceCode"); + backInst = instructionService.findReadyInstByNextDeviceCode(frontInst, getLinkDeviceCode, backNoY); + } + } + } else { + if (this.stackerNum == 2) { + List backInsts = instructionService.findReadyInstByNextDeviceCode(getBackDeviceCodeList, backNoY); + if (CollectionUtil.isNotEmpty(backInsts)) { + for (int k = 0; k < backInsts.size(); k++) { + Instruction instruction = backInsts.get(k); + if (points.contains(instruction.getNext_device_code())) { + backInst = instruction; + break; + } + } + } + } + } } + } else { List getFrontDeviceCodeList = this.getExtraDeviceCodes("frontDeviceCodeList"); List getBackDeviceCodeList = this.getExtraDeviceCodes("backDeviceCodeList"); String frontNoY = this.handExtraStringValue(this.getDevice(), "frontNoY"); String backNoY = this.handExtraStringValue(this.getDevice(), "backNoY"); - List frontInsts = instructionService.findReadyInstByNextDeviceCode(getFrontDeviceCodeList, frontNoY); + List frontInsts = instructionService.findShallowReadyInstByNextDeviceCode(getFrontDeviceCodeList, frontNoY); if (CollectionUtil.isNotEmpty(frontInsts)) { - for (int j = 0; j < frontInsts.size(); j++) { - Instruction instruction = frontInsts.get(j); - if (points.contains(instruction.getNext_device_code())) { - frontInst = instruction; - break; - } - } + frontInst = frontInsts.get(0); if (ObjectUtil.isNotEmpty(frontInst) && this.stackerNum == 2) { String front_next_device_code = frontInst.getNext_device_code(); Device front_next_device = deviceAppService.findDeviceByCode(front_next_device_code); if (front_next_device != null) { String getLinkDeviceCode = this.handExtraStringValue(front_next_device, "getLinkDeviceCode"); - backInst = instructionService.findReadyInstByNextDeviceCode(frontInst, getLinkDeviceCode, backNoY); + if (StrUtil.isNotEmpty(getLinkDeviceCode)) { + backInst = instructionService.findShallowReadyInstByNextDeviceCode(frontInst, getLinkDeviceCode, backNoY, getBackDeviceCodeList); + } } } } else { if (this.stackerNum == 2) { - List backInsts = instructionService.findReadyInstByNextDeviceCode(getBackDeviceCodeList, backNoY); + List backInsts = instructionService.findShallowReadyInstByNextDeviceCode(getBackDeviceCodeList, backNoY); if (CollectionUtil.isNotEmpty(backInsts)) { - for (int k = 0; k < backInsts.size(); k++) { - Instruction instruction = backInsts.get(k); - if (points.contains(instruction.getNext_device_code())) { - backInst = instruction; - break; + backInst = backInsts.get(0); + } else { + frontInsts = instructionService.findDeepReadyInstByNextDeviceCode(getFrontDeviceCodeList, frontNoY); + if (CollectionUtil.isNotEmpty(frontInsts)) { + frontInst = frontInsts.get(0); + if (ObjectUtil.isNotEmpty(frontInst) && this.stackerNum == 2) { + String front_next_device_code = frontInst.getNext_device_code(); + Device front_next_device = deviceAppService.findDeviceByCode(front_next_device_code); + if (front_next_device != null) { + String getLinkDeviceCode = this.handExtraStringValue(front_next_device, "getLinkDeviceCode"); + if (StrUtil.isNotEmpty(getLinkDeviceCode)) { + backInst = instructionService.findDeepReadyInstByNextDeviceCode(frontInst, getLinkDeviceCode, backNoY, getBackDeviceCodeList); + } + } + } + } else { + backInsts = instructionService.findDeepReadyInstByNextDeviceCode(getBackDeviceCodeList, backNoY); + if (CollectionUtil.isNotEmpty(backInsts)) { + backInst = backInsts.get(0); } } } @@ -1435,14 +1682,14 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme this.unExecutedMessage = null; this.requireSuccess = true; } else { - if (!this.originPoint.contains(currentXYZ)) { + if (this.inOutFlag) { this.applyTaskOneIn(); } } } /** - * 下发前叉取货信息(取货位是输送线) + * 下发前叉取货信息(取货位是货架) * * @param frontInst */ @@ -1548,6 +1795,13 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme private void updateInstStatusFinish(int instCode) { Instruction instruction = instructionService.findByCodeFromCache(String.valueOf(instCode)); if (ObjectUtil.isNotEmpty(instruction) && (InstructionStatusEnum.BUSY.getIndex().equals(instruction.getInstruction_status()) || InstructionStatusEnum.READY.getIndex().equals(instruction.getInstruction_status()))) { + String next_device_code = instruction.getNext_device_code(); + Device nextDevice = deviceAppService.findDeviceByCode(next_device_code); + if (nextDevice != null && nextDevice.getDeviceDriver() instanceof AppearanceInspectionScannerConveyorDeviceDriver) { + this.inOutFlag = false; + } else if (nextDevice != null && nextDevice.getDeviceDriver() instanceof StandardStorageDeviceDriver) { + this.inOutFlag = true; + } instruction.setInstruction_status(InstructionStatusEnum.FINISHED.getIndex()); instruction.setExecute_device_code(this.currentDeviceCode); instructionService.finish(instruction); @@ -1628,8 +1882,7 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme private void sendGetInfoToPlc(Instruction frontInst, Instruction backInst) { if (ObjectUtil.isNotEmpty(frontInst) && ObjectUtil.isNotEmpty(backInst)) { - if (this.front_forkCargo == 0 && this.back_forkCargo == 0 && isBindGet(frontInst, backInst)) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机待机状态下, 前叉和后叉任务都存在,并且前工位和后工位原位都无货, 可以绑定双任务,下发取货信息")); + if (NO_HAS_GOODS.contains(this.front_forkCargo) && NO_HAS_GOODS.contains(this.back_forkCargo) && isBindGet(frontInst, backInst)) { String start_device_code = frontInst.getStart_device_code(); Device start_device = deviceAppService.findDeviceByCode(start_device_code); if (start_device != null && start_device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { @@ -1640,33 +1893,30 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme Integer z = this.handExtraIntValue(start_device, "currentZ"); this.writing(this.getFBKeys(), Arrays.asList(x, y, z, frontInst.getInstruction_code(), backInst.getInstruction_code(), SendSignalEnum.CHOOSE_FORK_THREE.getSignalNum(), SendSignalEnum.COMMAND_ONE.getSignalNum())); } - } else if (this.front_forkCargo == 0) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机待机状态下, 前叉和后叉任务都存在,并且前工位原位无货,下发取货信息")); + } else if (NO_HAS_GOODS.contains(this.front_forkCargo)) { String start_device_code = frontInst.getStart_device_code(); Device start_device = deviceAppService.findDeviceByCode(start_device_code); if (start_device != null && start_device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { - this.writing(this.getFBKeys(), Arrays.asList(Integer.parseInt(StringUtil.handleString(frontInst.getFrom_x())), Integer.parseInt(frontInst.getFrom_y()), Integer.parseInt(frontInst.getFrom_z()), frontInst.getInstruction_code(), backInst.getInstruction_code(), SendSignalEnum.CHOOSE_FORK_ONE.getSignalNum(), SendSignalEnum.COMMAND_ONE.getSignalNum())); + this.writing(this.getFrontKeys(), Arrays.asList(Integer.parseInt(StringUtil.handleString(frontInst.getFrom_x())), Integer.parseInt(frontInst.getFrom_y()), Integer.parseInt(frontInst.getFrom_z()), frontInst.getInstruction_code(), SendSignalEnum.CHOOSE_FORK_ONE.getSignalNum(), SendSignalEnum.COMMAND_ONE.getSignalNum())); } else if (start_device != null && start_device.getDeviceDriver() instanceof AppearanceInspectionScannerConveyorDeviceDriver) { Integer x = this.handExtraIntValue(start_device, "currentX"); Integer y = this.handExtraIntValue(start_device, "currentY"); Integer z = this.handExtraIntValue(start_device, "currentZ"); - this.writing(this.getFBKeys(), Arrays.asList(x, y, z, frontInst.getInstruction_code(), backInst.getInstruction_code(), SendSignalEnum.CHOOSE_FORK_ONE.getSignalNum(), SendSignalEnum.COMMAND_ONE.getSignalNum())); + this.writing(this.getFrontKeys(), Arrays.asList(x, y, z, frontInst.getInstruction_code(), SendSignalEnum.CHOOSE_FORK_ONE.getSignalNum(), SendSignalEnum.COMMAND_ONE.getSignalNum())); } - } else if (this.back_forkCargo == 0) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机待机状态下, 前叉和后叉任务都存在,并且后工位原位无货,下发取货信息")); + } else if (NO_HAS_GOODS.contains(this.back_forkCargo)) { String start_device_code = backInst.getStart_device_code(); Device start_device = deviceAppService.findDeviceByCode(start_device_code); if (start_device != null && start_device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { - this.writing(this.getFBKeys(), Arrays.asList(Integer.parseInt(StringUtil.handleString(frontInst.getFrom_x())), Integer.parseInt(frontInst.getFrom_y()), Integer.parseInt(frontInst.getFrom_z()), frontInst.getInstruction_code(), backInst.getInstruction_code(), SendSignalEnum.CHOOSE_FORK_TWO.getSignalNum(), SendSignalEnum.COMMAND_ONE.getSignalNum())); + this.writing(this.getBackKeys(), Arrays.asList(Integer.parseInt(StringUtil.handleString(frontInst.getFrom_x())), Integer.parseInt(frontInst.getFrom_y()), Integer.parseInt(frontInst.getFrom_z()), backInst.getInstruction_code(), SendSignalEnum.CHOOSE_FORK_TWO.getSignalNum(), SendSignalEnum.COMMAND_ONE.getSignalNum())); } else if (start_device != null && start_device.getDeviceDriver() instanceof AppearanceInspectionScannerConveyorDeviceDriver) { Integer x = this.handExtraIntValue(start_device, "currentX"); Integer y = this.handExtraIntValue(start_device, "currentY"); Integer z = this.handExtraIntValue(start_device, "currentZ"); - this.writing(this.getFBKeys(), Arrays.asList(x, y, z, frontInst.getInstruction_code(), backInst.getInstruction_code(), SendSignalEnum.CHOOSE_FORK_TWO.getSignalNum(), SendSignalEnum.COMMAND_ONE.getSignalNum())); + this.writing(this.getBackKeys(), Arrays.asList(x, y, z, backInst.getInstruction_code(), SendSignalEnum.CHOOSE_FORK_TWO.getSignalNum(), SendSignalEnum.COMMAND_ONE.getSignalNum())); } } } else if (ObjectUtil.isNotEmpty(frontInst) && !isBindGet(frontInst, backInst)) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机待机状态下, 前叉任务存在,下发取货信息")); String start_device_code = frontInst.getStart_device_code(); Device start_device = deviceAppService.findDeviceByCode(start_device_code); if (start_device != null && start_device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { @@ -1678,7 +1928,6 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme this.writing(this.getFrontKeys(), Arrays.asList(x, y, z, frontInst.getInstruction_code(), SendSignalEnum.CHOOSE_FORK_ONE.getSignalNum(), SendSignalEnum.COMMAND_ONE.getSignalNum())); } } else if (ObjectUtil.isNotEmpty(backInst) && !isBindGet(frontInst, backInst)) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机待机状态下, 后叉任务存在,下发取货信息")); String start_device_code = backInst.getStart_device_code(); Device start_device = deviceAppService.findDeviceByCode(start_device_code); if (start_device != null && start_device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { @@ -1690,11 +1939,11 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme this.writing(this.getBackKeys(), Arrays.asList(x, y, z, backInst.getInstruction_code(), SendSignalEnum.CHOOSE_FORK_TWO.getSignalNum(), SendSignalEnum.COMMAND_ONE.getSignalNum())); } } else { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 前叉和后叉任务都不存在,不下发取货信息")); this.unExecutedMessage = "未执行放货原因, 堆垛机上报任务号不存在"; } } + private boolean isBindGet(Instruction frontInst, Instruction backInst) { if (ObjectUtil.isNotEmpty(frontInst) && ObjectUtil.isNotEmpty(backInst)) { String front_start_device_code = frontInst.getStart_device_code(); @@ -1712,24 +1961,28 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme String back_from_y = backInst.getFrom_y(); String back_from_z = backInst.getFrom_z(); boolean flagX = StrUtil.equals(front_from_x, back_from_x); - boolean flagY = ((Integer.parseInt(front_from_y) - 1) / 4 == (Integer.parseInt(back_from_y) - 1) / 4) && (((Integer.parseInt(front_from_y) % 4) + (Integer.parseInt(back_from_y) % 4) == 2) || (Integer.parseInt(front_from_y) % 4) + (Integer.parseInt(back_from_z) % 4) == 4); + boolean flagY = ((Integer.parseInt(front_from_y) - 1) / 4 == (Integer.parseInt(back_from_y) - 1) / 4) && (((Integer.parseInt(front_from_y) % 4) + (Integer.parseInt(back_from_y) % 4) == 2) || (Integer.parseInt(front_from_y) % 4) + (Integer.parseInt(back_from_y) % 4) == 4); boolean flagZ = StrUtil.equals(front_from_z, back_from_z); if (flagX && flagY && flagZ) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上待机状态下,前叉任务号:" + frontInst.getInstruction_code() + ", 后叉任务号:" + backInst.getInstruction_code() + ", 能组成双叉取货任务")); - return true; + if (Integer.parseInt(front_from_y) > Integer.parseInt(back_from_y)) { + return true; + } + return false; } } else if (StrUtil.equals(back_start_device_code, back_device_code)) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上待机状态下,前叉任务号:" + frontInst.getInstruction_code() + ", 后叉任务号:" + backInst.getInstruction_code() + ", 能组成双叉取货任务")); - return true; + Boolean frontIsFront = Optional.ofNullable(front_device.getExtraValue().get("isFront")).map(Object::toString).map(Boolean::parseBoolean).orElse(false); + Boolean backIsFront = Optional.ofNullable(back_device.getExtraValue().get("isFront")).map(Object::toString).map(Boolean::parseBoolean).orElse(false); + if (frontIsFront && !backIsFront){ + return true; + } + return false; } } - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上待机状态下,前叉任务号:" + frontInst.getInstruction_code() + ", 后叉任务号:" + backInst.getInstruction_code() + ", 不能组成双叉取货任务")); return false; } private void sendPutInfoToPlc(Instruction frontInst, Instruction backInst) { if (ObjectUtil.isNotEmpty(frontInst) && ObjectUtil.isNotEmpty(backInst) && isBindPut(frontInst, backInst)) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 前叉和后叉任务都存在,并且可以绑定双任务,下发放货信息")); String next_device_code = frontInst.getNext_device_code(); Device next_device = deviceAppService.findDeviceByCode(next_device_code); if (next_device != null && next_device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { @@ -1741,7 +1994,6 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme this.writing(this.getFBKeys(), Arrays.asList(x, y, z, frontInst.getInstruction_code(), backInst.getInstruction_code(), SendSignalEnum.CHOOSE_FORK_THREE.getSignalNum(), SendSignalEnum.COMMAND_TWO.getSignalNum())); } } else if (ObjectUtil.isNotEmpty(frontInst) && !isBindPut(frontInst, backInst)) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 前叉任务存在,不可以绑定双任务,下发放货信息")); String next_device_code = frontInst.getNext_device_code(); Device next_device = deviceAppService.findDeviceByCode(next_device_code); if (next_device != null && next_device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { @@ -1753,7 +2005,6 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme this.writing(this.getFrontKeys(), Arrays.asList(x, y, z, frontInst.getInstruction_code(), SendSignalEnum.CHOOSE_FORK_ONE.getSignalNum(), SendSignalEnum.COMMAND_TWO.getSignalNum())); } } else if (ObjectUtil.isNotEmpty(backInst) && !isBindPut(frontInst, backInst)) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 后叉任务存在,不可以绑定双任务,下发放货信息")); String next_device_code = backInst.getNext_device_code(); Device next_device = deviceAppService.findDeviceByCode(next_device_code); if (next_device != null && next_device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { @@ -1765,7 +2016,6 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme this.writing(this.getBackKeys(), Arrays.asList(x, y, z, backInst.getInstruction_code(), SendSignalEnum.CHOOSE_FORK_TWO.getSignalNum(), SendSignalEnum.COMMAND_TWO.getSignalNum())); } } else { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成, 前叉和后叉任务都不存在,不下发放货信息")); this.unExecutedMessage = "未执行放货原因, 堆垛机上报任务号不存在"; } } @@ -1788,19 +2038,23 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme String back_to_y = backInst.getTo_y(); String back_to_z = backInst.getTo_z(); boolean flagX = StrUtil.equals(front_to_x, back_to_x); - // TODO 需要验证规则是否生效 - boolean flagY = ((Integer.parseInt(front_to_y) - 1) / 4 == (Integer.parseInt(back_to_y) - 1) / 4) && (((Integer.parseInt(front_to_y) % 4) + (Integer.parseInt(back_to_y) % 4) == 2) || (Integer.parseInt(front_to_y) % 4) + (Integer.parseInt(back_to_z) % 4) == 4); + boolean flagY = ((Integer.parseInt(front_to_y) - 1) / 4 == (Integer.parseInt(back_to_y) - 1) / 4) && (((Integer.parseInt(front_to_y) % 4) + (Integer.parseInt(back_to_y) % 4) == 2) || (Integer.parseInt(front_to_y) % 4) + (Integer.parseInt(back_to_y) % 4) == 4); boolean flagZ = StrUtil.equals(front_to_z, back_to_z); if (flagX && flagY && flagZ) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成,前叉任务号:" + frontInst.getInstruction_code() + ", 后叉任务号:" + backInst.getInstruction_code() + ", 能组成双叉放货任务")); - return true; + if (Integer.parseInt(front_to_y) > Integer.parseInt(back_to_y)) { + return true; + } + return false; } } else if (StrUtil.equals(back_next_device_code, back_device_code)) { - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成,前叉任务号:" + frontInst.getInstruction_code() + ", 后叉任务号:" + backInst.getInstruction_code() + ", 能组成双叉放货任务")); - return true; + Boolean frontIsFront = Optional.ofNullable(front_device.getExtraValue().get("isFront")).map(Object::toString).map(Boolean::parseBoolean).orElse(false); + Boolean backIsFront = Optional.ofNullable(back_device.getExtraValue().get("isFront")).map(Object::toString).map(Boolean::parseBoolean).orElse(false); + if (frontIsFront && !backIsFront){ + return true; + } + return false; } } - logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "堆垛机上报取货完成,前叉任务号:" + frontInst.getInstruction_code() + ", 后叉任务号:" + backInst.getInstruction_code() + ", 不能组成双叉放货任务")); return false; } @@ -1975,7 +2229,7 @@ public class StandardStackerDeviceDriver extends AbstractOpcDeviceDriver impleme private String getZdPoint(String point_code) { - if (point_code == null || point_code.length() != 9) { + if (point_code == null || point_code.chars().filter(ch -> ch == '-').count() != 2) { return null; } String type = point_code.substring(0, 1); diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/station/with_station/WithStationDeviceDriver.java b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/station/with_station/WithStationDeviceDriver.java index c4435ab..007abf9 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/station/with_station/WithStationDeviceDriver.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/driver/station/with_station/WithStationDeviceDriver.java @@ -73,6 +73,20 @@ public class WithStationDeviceDriver extends AbstractOpcDeviceDriver implements if (!applyTaskFlag) return; long currentTimeMillis = System.currentTimeMillis(); if (!isTimeValid(currentTimeMillis)) { + List linkDeviceCodeList = this.getExtraDeviceCodes("link_device_code"); + for (int i = 0; i < linkDeviceCodeList.size(); i++) { + String deviceCode = linkDeviceCodeList.get(i); + Device device = deviceAppservice.findDeviceByCode(deviceCode); + AppearanceInspectionScannerConveyorDeviceDriver appearanceInspectionScannerConveyorDeviceDriver; + if (ObjectUtil.isNotEmpty(device) && device.getDeviceDriver() instanceof AppearanceInspectionScannerConveyorDeviceDriver) { + appearanceInspectionScannerConveyorDeviceDriver = (AppearanceInspectionScannerConveyorDeviceDriver) device.getDeviceDriver(); + if (appearanceInspectionScannerConveyorDeviceDriver.getMove() == 0 && this.requireSuccess) { + this.requireSuccess = false; + logServer.deviceExecuteLog(new LuceneLogDto(this.device_code, "标记复位:" + this.requireSuccess)); + continue; + } + } + } log.trace("触发时间因为小于{}毫秒,而被无视", this.requireTimeOut); } else { this.requireTime = currentTimeMillis; @@ -84,11 +98,12 @@ public class WithStationDeviceDriver extends AbstractOpcDeviceDriver implements AppearanceInspectionScannerConveyorDeviceDriver appearanceInspectionScannerConveyorDeviceDriver; if (ObjectUtil.isNotEmpty(device) && device.getDeviceDriver() instanceof AppearanceInspectionScannerConveyorDeviceDriver) { appearanceInspectionScannerConveyorDeviceDriver = (AppearanceInspectionScannerConveyorDeviceDriver) device.getDeviceDriver(); - if (appearanceInspectionScannerConveyorDeviceDriver.getMove() == 0) { - requireSuccess = false; + if (appearanceInspectionScannerConveyorDeviceDriver.getMove() == 0 && this.requireSuccess) { + this.requireSuccess = false; + logServer.deviceExecuteLog(new LuceneLogDto(this.device_code, "标记复位:" + this.requireSuccess)); continue; } - if (!requireSuccess && StrUtil.isNotEmpty(appearanceInspectionScannerConveyorDeviceDriver.getBarcode()) + if (!this.requireSuccess && StrUtil.isNotEmpty(appearanceInspectionScannerConveyorDeviceDriver.getBarcode()) && !appearanceInspectionScannerConveyorDeviceDriver.isWithStationRequireSuccess()) { TaskDto taskDto = taskServer.findByContainer(appearanceInspectionScannerConveyorDeviceDriver.getBarcode()); if (ObjectUtil.isEmpty(taskDto)) { diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java index b8626e0..64ca584 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java @@ -145,17 +145,17 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { errArr.add(json); continue; } - if (!StrUtil.isEmpty(vehicle_code)) { - TaskDto vehicle_dto = taskService.findByContainer(vehicle_code); - if (vehicle_dto != null) { - JSONObject json = new JSONObject(); - json.put("task_code", task_code); - json.put("ext_task_id", ext_task_id); - json.put("msg", "已存在任务编号为" + vehicle_dto.getTask_code() + "托盘号:" + vehicle_code); - errArr.add(json); - continue; - } - } +// if (!StrUtil.isEmpty(vehicle_code)) { +// TaskDto vehicle_dto = taskService.findByContainer(vehicle_code); +// if (vehicle_dto != null) { +// JSONObject json = new JSONObject(); +// json.put("task_code", task_code); +// json.put("ext_task_id", ext_task_id); +// json.put("msg", "已存在任务编号为" + vehicle_dto.getTask_code() + "托盘号:" + vehicle_code); +// errArr.add(json); +// continue; +// } +// } if (StrUtil.isEmpty(start_point_code)) { JSONObject json = new JSONObject(); @@ -348,6 +348,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { if (toHeight != null) { appearanceInspectionScannerConveyorDeviceDriver.writing("toHeight", toHeight); } + appearanceInspectionScannerConveyorDeviceDriver.writing("toTarget", 0); appearanceInspectionScannerConveyorDeviceDriver.writing("toCommand", toCommand); } JSONObject resp = new JSONObject(); diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/InstructionService.java b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/InstructionService.java index 1a397ca..6dc962d 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/InstructionService.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/InstructionService.java @@ -461,6 +461,24 @@ public interface InstructionService extends CommonService { */ List findReadyInstByStartDeviceCode(List start_device_code_list, String noY); + /** + * 入库时,根据起点查询就绪指令,并且放货位是深货位 + * + * @param start_device_code_list + * @param noY + * @return + */ + List findDeepReadyInstByStartDeviceCode(List start_device_code_list, String noY); + + /** + * 入库时,根据起点查询就绪指令,并且放货位是深货位 + * + * @param start_device_code_list + * @param noY + * @return + */ + List findShallowReadyInstByStartDeviceCode(List start_device_code_list, String noY); + /** * 用于优先出库策略 @@ -473,6 +491,8 @@ public interface InstructionService extends CommonService { * @return */ List findReadyInstByNextDeviceCode(List next_device_code_list, String noY); + List findDeepReadyInstByNextDeviceCode(List next_device_code_list, String noY); + List findShallowReadyInstByNextDeviceCode(List next_device_code_list, String noY); /** * 用于时间顺序出入库策略 @@ -503,9 +523,25 @@ public interface InstructionService extends CommonService { * @param noY * @return */ - Instruction findReadyInstByLinkDeviceCodeAndStartDeviceCode(String linkDeviceCode, String noY); + Instruction findReadyInstByLinkDeviceCodeAndStartDeviceCode(String linkDeviceCode, String noY, List getDeviceCodeList); - Instruction findReadyInstByLinkDeviceCodeAndNextDeviceCode(String linkDeviceCode, String noY); + /** + * @param linkDeviceCode + * @param noY + * @return + */ + Instruction findDeepReadyInstByLinkDeviceCodeAndStartDeviceCode(String linkDeviceCode, String noY, List getDeviceCodeList); + + /** + * @param linkDeviceCode + * @param noY + * @return + */ + Instruction findShallowReadyInstByLinkDeviceCodeAndStartDeviceCode(String linkDeviceCode, String noY, List getDeviceCodeList); + + Instruction findReadyInstByLinkDeviceCodeAndNextDeviceCode(String linkDeviceCode, String noY, List getDeviceCodeList); + Instruction findDeepReadyInstByLinkDeviceCodeAndNextDeviceCode(String linkDeviceCode, String noY,List getDeviceCodeList); + Instruction findShallowReadyInstByLinkDeviceCodeAndNextDeviceCode(String linkDeviceCode, String noY,List getDeviceCodeList); /** * 用于优先出库策略和时间顺序策略 -出库 @@ -518,6 +554,8 @@ public interface InstructionService extends CommonService { * @return */ Instruction findReadyInstByNextDeviceCode(Instruction frontInst, String link_device_code, String noY); + Instruction findDeepReadyInstByNextDeviceCode(Instruction frontInst, String link_device_code, String noY, List getDeviceCodeList); + Instruction findShallowReadyInstByNextDeviceCode(Instruction frontInst, String link_device_code, String noY, List getDeviceCodeList); /** @@ -532,6 +570,8 @@ public interface InstructionService extends CommonService { Instruction findReadyInstByEnd(String next_device_code); + int findReadyInstNumByEnd(String next_device_code); + Instruction findReadyInstByVehicleCode(String vehicleCode); Instruction findBusyInstByNextDeviceCode(String getLinkDeviceCode); diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java index bf94293..bbbcd5e 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java @@ -76,6 +76,7 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -381,7 +382,8 @@ public class InstructionServiceImpl extends CommonServiceImpl inst.getStart_device_code() .equals(start_device_code))) { - return; +// throw new BadRequestException("已经存在相同任务号的起点!"); + //return; } } String currentUsername = SecurityUtils.getCurrentNickName(); @@ -505,7 +507,7 @@ public class InstructionServiceImpl extends CommonServiceImpl inst.getInstruction_status().equals(InstructionStatusEnum.READY.getIndex())) .filter(inst -> start_device_code_list.contains(inst.getStart_device_code())) .filter(inst -> (ObjectUtil.isNotEmpty(inst.getTo_y()) && !currentNoY.contains(String.valueOf(Integer.parseInt(inst.getTo_y()))))) - .sorted(Comparator.comparing(Instruction::getPriority) + //.sorted(Comparator.comparing(Instruction::getPriority) + .sorted(Comparator.comparingInt((Instruction inst) -> Integer.parseInt(getNumericPart(inst.getNext_device_code())) % 4) + .thenComparing(inst -> Integer.parseInt(ObjectUtil.isEmpty(inst.getTo_z()) ? "0" : inst.getTo_z())) + .thenComparing(inst -> Integer.parseInt(ObjectUtil.isEmpty(inst.getTo_y()) ? "0" : inst.getTo_y())) + .thenComparing(Comparator.comparing(Instruction::getPriority)) + .thenComparing(inst -> LocalDateTime.parse(inst.getCreate_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))) + .collect(Collectors.toList()); + } + + @Override + public List findDeepReadyInstByStartDeviceCode(List start_device_code_list, String noY) { +// String currentNoY = noY == null ? "" : noY; + Set currentNoY = noY == null ? Collections.emptySet() : new HashSet<>(Arrays.asList(noY.split(","))); + return Optional.ofNullable(this.instructions) + .orElse(new CopyOnWriteArrayList<>()) + .stream() + .filter(inst -> inst.getInstruction_status().equals(InstructionStatusEnum.READY.getIndex())) + .filter(inst -> start_device_code_list.contains(inst.getStart_device_code())) + .filter(inst -> (ObjectUtil.isNotEmpty(inst.getTo_y()) && !currentNoY.contains(String.valueOf(Integer.parseInt(inst.getTo_y()))))) + .filter(inst -> Integer.parseInt(getNumericPart(inst.getNext_device_code())) % 4 == 1 || Integer.parseInt(getNumericPart(inst.getNext_device_code())) % 4 == 0) + //.sorted(Comparator.comparing(Instruction::getPriority) + .sorted(Comparator.comparingInt((Instruction inst) -> Integer.parseInt(getNumericPart(inst.getNext_device_code())) % 4) + .thenComparing(inst -> Integer.parseInt(ObjectUtil.isEmpty(inst.getTo_z()) ? "0" : inst.getTo_z())) + .thenComparing(inst -> Integer.parseInt(ObjectUtil.isEmpty(inst.getTo_y()) ? "0" : inst.getTo_y())) + .thenComparing(Comparator.comparing(Instruction::getPriority)).reversed() + .thenComparing(inst -> LocalDateTime.parse(inst.getCreate_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))) + .collect(Collectors.toList()); + } + + @Override + public List findShallowReadyInstByStartDeviceCode(List start_device_code_list, String noY) { + Set currentNoY = noY == null ? Collections.emptySet() : new HashSet<>(Arrays.asList(noY.split(","))); + return Optional.ofNullable(this.instructions) + .orElse(new CopyOnWriteArrayList<>()) + .stream() + .filter(inst -> inst.getInstruction_status().equals(InstructionStatusEnum.READY.getIndex())) + .filter(inst -> start_device_code_list.contains(inst.getStart_device_code())) + .filter(inst -> (ObjectUtil.isNotEmpty(inst.getTo_y()) && !currentNoY.contains(String.valueOf(Integer.parseInt(inst.getTo_y()))))) + .filter(inst -> Integer.parseInt(getNumericPart(inst.getNext_device_code())) % 4 == 2 || Integer.parseInt(getNumericPart(inst.getNext_device_code())) % 4 == 3) + .sorted(Comparator.comparingInt((Instruction inst) -> Integer.parseInt(getNumericPart(inst.getNext_device_code())) % 4) + .thenComparing(inst -> Integer.parseInt(ObjectUtil.isEmpty(inst.getTo_z()) ? "0" : inst.getTo_z())) + .thenComparing(inst -> Integer.parseInt(ObjectUtil.isEmpty(inst.getTo_y()) ? "0" : inst.getTo_y())) + .thenComparing(Comparator.comparing(Instruction::getPriority)).reversed() .thenComparing(inst -> LocalDateTime.parse(inst.getCreate_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))) .collect(Collectors.toList()); } @@ -1770,11 +1814,60 @@ public class InstructionServiceImpl extends CommonServiceImpl inst.getInstruction_status().equals(InstructionStatusEnum.READY.getIndex())) .filter(inst -> next_device_code_list.contains(inst.getNext_device_code())) .filter(inst -> ObjectUtil.isNotEmpty(inst.getFrom_y()) && !currentNoY.contains(String.valueOf(Integer.parseInt(inst.getFrom_y())))) - .sorted(Comparator.comparing(Instruction::getPriority) + // .sorted(Comparator.comparing(Instruction::getPriority) + .sorted(Comparator.comparingInt((Instruction inst) -> Integer.parseInt(getNumericPart(inst.getStart_device_code())) % 4).reversed() + .thenComparing(inst -> Integer.parseInt(ObjectUtil.isEmpty(inst.getFrom_z()) ? "0" : inst.getFrom_z())) + .thenComparing(inst -> Integer.parseInt(ObjectUtil.isEmpty(inst.getFrom_y()) ? "0" : inst.getFrom_y())) + .thenComparing(Comparator.comparing(Instruction::getPriority)) .thenComparing(inst -> LocalDateTime.parse(inst.getCreate_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))) .collect(Collectors.toList()); } + @Override + public List findDeepReadyInstByNextDeviceCode(List next_device_code_list, String noY) { + Set currentNoY = noY == null ? Collections.emptySet() : new HashSet<>(Arrays.asList(noY.split(","))); + return Optional.ofNullable(this.instructions) + .orElse(new CopyOnWriteArrayList<>()) + .stream() + .filter(inst -> inst.getInstruction_status().equals(InstructionStatusEnum.READY.getIndex())) + .filter(inst -> next_device_code_list.contains(inst.getNext_device_code())) + .filter(inst -> ObjectUtil.isNotEmpty(inst.getFrom_y()) && !currentNoY.contains(String.valueOf(Integer.parseInt(inst.getFrom_y())))) + .filter(inst -> Integer.parseInt(getNumericPart(inst.getStart_device_code())) % 4 == 1 || Integer.parseInt(getNumericPart(inst.getStart_device_code())) % 4 == 0) + .sorted(Comparator.comparingInt((Instruction inst) -> Integer.parseInt(getNumericPart(inst.getStart_device_code())) % 4).reversed() + .thenComparing(inst -> Integer.parseInt(ObjectUtil.isEmpty(inst.getFrom_z()) ? "0" : inst.getFrom_z())) + .thenComparing(inst -> Integer.parseInt(ObjectUtil.isEmpty(inst.getFrom_y()) ? "0" : inst.getFrom_y())) + .thenComparing(Comparator.comparing(Instruction::getPriority)).reversed() + .thenComparing(inst -> LocalDateTime.parse(inst.getCreate_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))) + .collect(Collectors.toList()); + } + + @Override + public List findShallowReadyInstByNextDeviceCode(List next_device_code_list, String noY) { + Set currentNoY = noY == null ? Collections.emptySet() : new HashSet<>(Arrays.asList(noY.split(","))); + return Optional.ofNullable(this.instructions) + .orElse(new CopyOnWriteArrayList<>()) + .stream() + .filter(inst -> inst.getInstruction_status().equals(InstructionStatusEnum.READY.getIndex())) + .filter(inst -> next_device_code_list.contains(inst.getNext_device_code())) + .filter(inst -> ObjectUtil.isNotEmpty(inst.getFrom_y()) && !currentNoY.contains(String.valueOf(Integer.parseInt(inst.getFrom_y())))) + .filter(inst -> Integer.parseInt(getNumericPart(inst.getStart_device_code())) % 4 == 2 || Integer.parseInt(getNumericPart(inst.getStart_device_code())) % 3 == 0) + .sorted(Comparator.comparingInt((Instruction inst) -> Integer.parseInt(getNumericPart(inst.getStart_device_code())) % 4).reversed() + .thenComparing(inst -> Integer.parseInt(ObjectUtil.isEmpty(inst.getFrom_z()) ? "0" : inst.getFrom_z())) + .thenComparing(inst -> Integer.parseInt(ObjectUtil.isEmpty(inst.getFrom_y()) ? "0" : inst.getFrom_y())) + .thenComparing(Comparator.comparing(Instruction::getPriority)) + .thenComparing(inst -> LocalDateTime.parse(inst.getCreate_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))) + .collect(Collectors.toList()); + } + + private String getNumericPart(String device_c0de) { + Pattern pattern = Pattern.compile("\\d+"); + Matcher matcher = pattern.matcher(device_c0de); + if (matcher.find()) { + return matcher.group(); + } + return "0"; + } + @Override public List findReadyInstByDeviceCode(List device_code_list, String noY) { //String currentNoY = noY == null ? "" : noY; @@ -1820,7 +1913,7 @@ public class InstructionServiceImpl extends CommonServiceImpl getDeviceCodeList) { // String currentNoY = noY == null ? "" : noY; Set currentNoY = noY == null ? Collections.emptySet() : new HashSet<>(Arrays.asList(noY.split(","))); return Optional.ofNullable(this.instructions) @@ -1828,6 +1921,7 @@ public class InstructionServiceImpl extends CommonServiceImpl inst.getInstruction_status().equals(InstructionStatusEnum.READY.getIndex())) .filter(inst -> inst.getStart_device_code().equals(linkDeviceCode)) + .filter(inst -> getDeviceCodeList.contains(inst.getStart_device_code())) .filter(inst -> StrUtil.isNotBlank(inst.getTo_y()) && !currentNoY.contains(String.valueOf(Integer.parseInt(inst.getTo_y())))) .sorted(Comparator.comparing(Instruction::getPriority) .thenComparing(inst -> LocalDateTime.parse(inst.getCreate_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))) @@ -1836,16 +1930,93 @@ public class InstructionServiceImpl extends CommonServiceImpl getDeviceCodeList) { + Set currentNoY = noY == null ? Collections.emptySet() : new HashSet<>(Arrays.asList(noY.split(","))); + return Optional.ofNullable(this.instructions) + .orElse(new CopyOnWriteArrayList<>()) + .stream() + .filter(inst -> inst.getInstruction_status().equals(InstructionStatusEnum.READY.getIndex())) + .filter(inst -> inst.getStart_device_code().equals(linkDeviceCode)) + .filter(inst -> getDeviceCodeList.contains(inst.getStart_device_code())) + .filter(inst -> StrUtil.isNotBlank(inst.getTo_y()) && !currentNoY.contains(String.valueOf(Integer.parseInt(inst.getTo_y())))) + .filter(inst -> Integer.parseInt(getNumericPart(inst.getNext_device_code())) % 4 == 1 || Integer.parseInt(getNumericPart(inst.getNext_device_code())) % 4 == 0) + .sorted(Comparator.comparing(Instruction::getPriority) + .thenComparing(inst -> LocalDateTime.parse(inst.getCreate_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))) + .findFirst() + .orElse(null); + } + + @Override + public Instruction findShallowReadyInstByLinkDeviceCodeAndStartDeviceCode(String linkDeviceCode, String noY, List getDeviceCodeList) { + Set currentNoY = noY == null ? Collections.emptySet() : new HashSet<>(Arrays.asList(noY.split(","))); + return Optional.ofNullable(this.instructions) + .orElse(new CopyOnWriteArrayList<>()) + .stream() + .filter(inst -> inst.getInstruction_status().equals(InstructionStatusEnum.READY.getIndex())) + .filter(inst -> inst.getStart_device_code().equals(linkDeviceCode)) + .filter(inst -> getDeviceCodeList.contains(inst.getStart_device_code())) + .filter(inst -> StrUtil.isNotBlank(inst.getTo_y()) && !currentNoY.contains(String.valueOf(Integer.parseInt(inst.getTo_y())))) + .filter(inst -> Integer.parseInt(getNumericPart(inst.getNext_device_code())) % 4 == 2 || Integer.parseInt(getNumericPart(inst.getNext_device_code())) % 4 == 3) + .sorted(Comparator.comparing(Instruction::getPriority).reversed() + .thenComparing(inst -> LocalDateTime.parse(inst.getCreate_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))) + .findFirst() + .orElse(null); + } + + @Override + public Instruction findReadyInstByLinkDeviceCodeAndNextDeviceCode(String linkDeviceCode, String noY, List getDeviceCodeList) { Set currentNoY = noY == null ? Collections.emptySet() : new HashSet<>(Arrays.asList(noY.split(","))); return Optional.ofNullable(this.instructions) .orElse(new CopyOnWriteArrayList<>()) .stream() .filter(inst -> inst.getInstruction_status().equals(InstructionStatusEnum.READY.getIndex())) .filter(inst -> inst.getNext_device_code().equals(linkDeviceCode)) + .filter(inst -> getDeviceCodeList.contains(inst.getNext_device_code())) .filter(inst -> StrUtil.isNotBlank(inst.getFrom_y()) && !currentNoY.contains(String.valueOf(Integer.parseInt(inst.getFrom_y())))) - .sorted(Comparator.comparing(Instruction::getPriority) + .sorted(Comparator.comparingInt((Instruction inst) -> Integer.parseInt(getNumericPart(inst.getStart_device_code())) % 4).reversed() + .thenComparing(inst -> Integer.parseInt(ObjectUtil.isEmpty(inst.getFrom_z()) ? "0" : inst.getFrom_z())) + .thenComparing(inst -> Integer.parseInt(ObjectUtil.isEmpty(inst.getFrom_y()) ? "0" : inst.getFrom_y())) + .thenComparing(Comparator.comparing(Instruction::getPriority)) + .thenComparing(inst -> LocalDateTime.parse(inst.getCreate_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))) + .findFirst() + .orElse(null); + } + + @Override + public Instruction findDeepReadyInstByLinkDeviceCodeAndNextDeviceCode(String linkDeviceCode, String noY, List getDeviceCodeList) { + Set currentNoY = noY == null ? Collections.emptySet() : new HashSet<>(Arrays.asList(noY.split(","))); + return Optional.ofNullable(this.instructions) + .orElse(new CopyOnWriteArrayList<>()) + .stream() + .filter(inst -> inst.getInstruction_status().equals(InstructionStatusEnum.READY.getIndex())) + .filter(inst -> inst.getNext_device_code().equals(linkDeviceCode)) + .filter(inst -> getDeviceCodeList.contains(inst.getNext_device_code())) + .filter(inst -> StrUtil.isNotBlank(inst.getFrom_y()) && !currentNoY.contains(String.valueOf(Integer.parseInt(inst.getFrom_y())))) + .filter(inst -> Integer.parseInt(getNumericPart(inst.getStart_device_code())) % 4 == 1 || Integer.parseInt(getNumericPart(inst.getStart_device_code())) % 4 == 0) + .sorted(Comparator.comparingInt((Instruction inst) -> Integer.parseInt(getNumericPart(inst.getStart_device_code())) % 4).reversed() + .thenComparing(inst -> Integer.parseInt(ObjectUtil.isEmpty(inst.getFrom_z()) ? "0" : inst.getFrom_z())) + .thenComparing(inst -> Integer.parseInt(ObjectUtil.isEmpty(inst.getFrom_y()) ? "0" : inst.getFrom_y())) + .thenComparing(Comparator.comparing(Instruction::getPriority)) + .thenComparing(inst -> LocalDateTime.parse(inst.getCreate_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))) + .findFirst() + .orElse(null); + } + + @Override + public Instruction findShallowReadyInstByLinkDeviceCodeAndNextDeviceCode(String linkDeviceCode, String noY, List getDeviceCodeList) { + Set currentNoY = noY == null ? Collections.emptySet() : new HashSet<>(Arrays.asList(noY.split(","))); + return Optional.ofNullable(this.instructions) + .orElse(new CopyOnWriteArrayList<>()) + .stream() + .filter(inst -> inst.getInstruction_status().equals(InstructionStatusEnum.READY.getIndex())) + .filter(inst -> inst.getNext_device_code().equals(linkDeviceCode)) + .filter(inst -> getDeviceCodeList.contains(inst.getNext_device_code())) + .filter(inst -> StrUtil.isNotBlank(inst.getFrom_y()) && !currentNoY.contains(String.valueOf(Integer.parseInt(inst.getFrom_y())))) + .filter(inst -> Integer.parseInt(getNumericPart(inst.getStart_device_code())) % 4 == 2 || Integer.parseInt(getNumericPart(inst.getStart_device_code())) % 4 == 3) + .sorted(Comparator.comparingInt((Instruction inst) -> Integer.parseInt(getNumericPart(inst.getStart_device_code())) % 4).reversed() + .thenComparing(inst -> Integer.parseInt(ObjectUtil.isEmpty(inst.getFrom_z()) ? "0" : inst.getFrom_z())) + .thenComparing(inst -> Integer.parseInt(ObjectUtil.isEmpty(inst.getFrom_y()) ? "0" : inst.getFrom_y())) + .thenComparing(Comparator.comparing(Instruction::getPriority)) .thenComparing(inst -> LocalDateTime.parse(inst.getCreate_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))) .findFirst() .orElse(null); @@ -1882,6 +2053,66 @@ public class InstructionServiceImpl extends CommonServiceImpl getDeviceCodeList) { + Set currentNoY = noY == null ? Collections.emptySet() : new HashSet<>(Arrays.asList(noY.split(","))); + return Optional.ofNullable(this.instructions) + .orElse(new CopyOnWriteArrayList<>()) + .stream() + .filter(inst -> inst.getInstruction_status().equals(InstructionStatusEnum.READY.getIndex())) + .filter(inst -> inst.getNext_device_code().equals(link_device_code)) + .filter(inst -> ObjectUtil.isNotEmpty(inst.getFrom_y()) && !currentNoY.contains(inst.getFrom_y())) + .filter(inst -> Integer.parseInt(StringUtil.handleString(inst.getFrom_x())) == Integer.parseInt(StringUtil.handleString(frontInst.getFrom_x()))) + .filter(inst -> getDeviceCodeList.contains(inst.getNext_device_code())) + .filter(inst -> { + int frontY = Integer.parseInt(frontInst.getFrom_y()); + int instY = Integer.parseInt(inst.getFrom_y()); + int frontGroup = (frontY - 1) / 4; + int instGroup = (instY - 1) / 4; + if (frontGroup != instGroup) { + return false; + } + int frontMod = frontY % 4; + int instMod = instY % 4; + return (frontMod + instMod == 2 || frontMod + instMod == 4); + }) + .filter(inst -> Integer.parseInt(inst.getFrom_z()) == Integer.parseInt(frontInst.getFrom_z())) + .filter(inst -> Integer.parseInt(getNumericPart(inst.getStart_device_code())) % 4 == 0 || Integer.parseInt(getNumericPart(inst.getStart_device_code())) % 4 == 1) + .sorted(Comparator.comparing(Instruction::getPriority).reversed() + .thenComparing(inst -> LocalDateTime.parse(inst.getCreate_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))) + .findFirst().orElse(null); + } + + @Override + public Instruction findShallowReadyInstByNextDeviceCode(Instruction frontInst, String link_device_code, String noY, List getDeviceCodeList) { + Set currentNoY = noY == null ? Collections.emptySet() : new HashSet<>(Arrays.asList(noY.split(","))); + return Optional.ofNullable(this.instructions) + .orElse(new CopyOnWriteArrayList<>()) + .stream() + .filter(inst -> inst.getInstruction_status().equals(InstructionStatusEnum.READY.getIndex())) + .filter(inst -> inst.getNext_device_code().equals(link_device_code)) + .filter(inst -> ObjectUtil.isNotEmpty(inst.getFrom_y()) && !currentNoY.contains(inst.getFrom_y())) + .filter(inst -> Integer.parseInt(StringUtil.handleString(inst.getFrom_x())) == Integer.parseInt(StringUtil.handleString(frontInst.getFrom_x()))) + .filter(inst -> getDeviceCodeList.contains(inst.getNext_device_code())) + .filter(inst -> { + int frontY = Integer.parseInt(frontInst.getFrom_y()); + int instY = Integer.parseInt(inst.getFrom_y()); + int frontGroup = (frontY - 1) / 4; + int instGroup = (instY - 1) / 4; + if (frontGroup != instGroup) { + return false; + } + int frontMod = frontY % 4; + int instMod = instY % 4; + return (frontMod + instMod == 2 || frontMod + instMod == 4); + }) + .filter(inst -> Integer.parseInt(inst.getFrom_z()) == Integer.parseInt(frontInst.getFrom_z())) + .filter(inst -> Integer.parseInt(getNumericPart(inst.getStart_device_code())) % 4 == 2 || Integer.parseInt(getNumericPart(inst.getStart_device_code())) % 4 == 3) + .sorted(Comparator.comparing(Instruction::getPriority).reversed() + .thenComparing(inst -> LocalDateTime.parse(inst.getCreate_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))) + .findFirst().orElse(null); + } + @Override public Instruction findReadyInst(String start_device_code) { return Optional.ofNullable(this.instructions) @@ -1902,6 +2133,17 @@ public class InstructionServiceImpl extends CommonServiceImpl()) + .stream() + .filter(inst -> inst.getInstruction_status().equals(InstructionStatusEnum.READY.getIndex())) + .filter(inst -> inst.getNext_device_code().equals(next_device_code)) + .collect(Collectors.toList()) + .size(); + } + @Override public Instruction findReadyInstByVehicleCode(String vehicleCode) { return Optional.ofNullable(this.instructions) diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/TaskService.java b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/TaskService.java index cd08d6d..7d23dd3 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/TaskService.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/TaskService.java @@ -265,6 +265,7 @@ public interface TaskService extends CommonService { * @return */ TaskDto findByNextCode(String device_code); + TaskDto findByNextPointCode(String device_code); /** @@ -275,6 +276,12 @@ public interface TaskService extends CommonService { */ TaskDto findByStartCode(String device_code); + List findTasksByStartCode(String device_code); + + List findTasksByNextCode(String device_code); + + TaskDto findByStartPointCode(String device_code); + TaskDto findReadyByVehicleCode(String vehicleCode); diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java index 2cab14a..2300ab7 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java @@ -103,8 +103,8 @@ public class TaskServiceImpl extends CommonServiceImpl impleme private XianGongAgvService agvService; @Autowired private RouteLineService routeLineService; - @Autowired - private DeviceAssignedService deviceAssignedService; + // @Autowired +// private DeviceAssignedService deviceAssignedService; @Autowired private InstructionService instructionService; @Autowired @@ -842,6 +842,14 @@ public class TaskServiceImpl extends CommonServiceImpl impleme return optionalTask.orElse(null); } + @Override + public TaskDto findByNextPointCode(String device_code) { + Optional optionalTask = tasks.stream() + .filter(task -> StrUtil.equals(task.getNext_point_code(), device_code)) + .findFirst(); + return optionalTask.orElse(null); + } + @Override public TaskDto findReadyByVehicleCode(String vehicleCode) { @@ -864,6 +872,39 @@ public class TaskServiceImpl extends CommonServiceImpl impleme .orElse(null); } + @Override + public List findTasksByStartCode(String device_code) { + return Optional + .ofNullable(this.tasks) + .orElse(new CopyOnWriteArrayList<>()) + .stream() + .filter(task -> StrUtil.equals(task.getStart_device_code(), device_code)) + .filter(task -> StrUtil.equals(task.getTask_status(),TaskStatusEnum.BUSY.getIndex())) + .collect(Collectors.toList()); + } + + @Override + public List findTasksByNextCode(String device_code) { + return Optional + .ofNullable(this.tasks) + .orElse(new CopyOnWriteArrayList<>()) + .stream() + .filter(task -> StrUtil.equals(task.getNext_device_code(), device_code)) + .filter(task -> StrUtil.equals(task.getTask_status(),TaskStatusEnum.BUSY.getIndex())) + .collect(Collectors.toList()); + } + + @Override + public TaskDto findByStartPointCode(String device_code) { + return Optional + .ofNullable(this.tasks) + .orElse(new CopyOnWriteArrayList<>()) + .stream() + .filter(task -> StrUtil.equals(task.getStart_point_code(), device_code)) + .findFirst() + .orElse(null); + } + @Override public TaskDto foramte(TaskDto task) { String start_point_code = task.getStart_point_code(); @@ -1011,42 +1052,42 @@ public class TaskServiceImpl extends CommonServiceImpl impleme @Override public String queryAssignedByDevice(String device_code, String task_nextdeice_code) { - List list = - deviceAssignedService.queryAssignedByDevice(device_code, task_nextdeice_code); - int flag1 = 0; - String flag2 = null; - for (int i = 0; i < list.size(); i++) { - DeviceAssignedDto dto = list.get(i); - String inst_nextDevice_code = dto.getInst_nextDevice_code(); - String task_nextDevice_code = dto.getTask_nextDevice_code(); - String param = dto.getParam(); - JSONObject jo = JSON.parseObject(param); - String regEx = "[`~!@#$%^&*()+=|{}':;'\\[\\].<>/?~!@#¥%……&*()——+|{}【】':”“’。、?]"; - Pattern p = Pattern.compile(regEx); - Matcher m = p.matcher(inst_nextDevice_code); - String toSpeechText = m.replaceAll("").trim(); - - String[] str = toSpeechText.split(","); - List pathlist = Arrays.asList(str); - for (int j = 0; j < pathlist.size(); j++) { - String this_device_code = pathlist.get(j).toString(); - JSONObject data = JSON.parseObject(jo.getString(this_device_code)); - String limit = data.getString("limit"); - int num = instructionService.querySameDestinationInst(this_device_code); - if (num >= Integer.parseInt(limit)) { - continue; - } - if (j == 0) { - flag1 = num; - } - if (num <= flag1) { - flag2 = this_device_code; - } - } - } - if (!StrUtil.isEmpty(flag2)) { - return flag2; - } +// List list = +// deviceAssignedService.queryAssignedByDevice(device_code, task_nextdeice_code); +// int flag1 = 0; +// String flag2 = null; +// for (int i = 0; i < list.size(); i++) { +// DeviceAssignedDto dto = list.get(i); +// String inst_nextDevice_code = dto.getInst_nextDevice_code(); +// String task_nextDevice_code = dto.getTask_nextDevice_code(); +// String param = dto.getParam(); +// JSONObject jo = JSON.parseObject(param); +// String regEx = "[`~!@#$%^&*()+=|{}':;'\\[\\].<>/?~!@#¥%……&*()——+|{}【】':”“’。、?]"; +// Pattern p = Pattern.compile(regEx); +// Matcher m = p.matcher(inst_nextDevice_code); +// String toSpeechText = m.replaceAll("").trim(); +// +// String[] str = toSpeechText.split(","); +// List pathlist = Arrays.asList(str); +// for (int j = 0; j < pathlist.size(); j++) { +// String this_device_code = pathlist.get(j).toString(); +// JSONObject data = JSON.parseObject(jo.getString(this_device_code)); +// String limit = data.getString("limit"); +// int num = instructionService.querySameDestinationInst(this_device_code); +// if (num >= Integer.parseInt(limit)) { +// continue; +// } +// if (j == 0) { +// flag1 = num; +// } +// if (num <= flag1) { +// flag2 = this_device_code; +// } +// } +// } +// if (!StrUtil.isEmpty(flag2)) { +// return flag2; +// } return null; } @@ -1357,7 +1398,12 @@ public class TaskServiceImpl extends CommonServiceImpl impleme .filter(taskDto -> StrUtil.isNotBlank(taskDto.getFrom_y()) && StrUtil.isNotBlank(taskDto.getTo_y()) && !currentNoY.contains(String.valueOf(Integer.parseInt(taskDto.getFrom_y()))) && !currentNoY.contains(String.valueOf(Integer.parseInt(taskDto.getTo_y())))) // .sorted(Comparator.comparing(TaskDto::getPriority) // .thenComparing(taskDto -> LocalDateTime.parse(taskDto.getCreate_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))) - .sorted(Comparator.comparing((TaskDto taskDto) -> !taskDto.getVehicle_code().contains("YCZJ")) + //.sorted(Comparator.comparing((TaskDto taskDto) -> !taskDto.getVehicle_code().contains("YCZJ")) + .sorted(Comparator.comparingInt((TaskDto taskDto) -> Integer.parseInt(getNumericPart(taskDto.getStart_device_code())) % 4).reversed() + .thenComparing(taskDto -> Integer.parseInt(getNumericPart(taskDto.getNext_device_code())) % 4) + .thenComparing(taskDto -> Integer.parseInt(ObjectUtil.isEmpty(taskDto.getFrom_z()) ? "0" : taskDto.getFrom_z())) + .thenComparing(taskDto -> Integer.parseInt(ObjectUtil.isEmpty(taskDto.getFrom_y()) ? "0" : taskDto.getFrom_y())) + .thenComparing((TaskDto taskDto) -> !taskDto.getVehicle_code().contains("YCZJ")) .thenComparing(TaskDto::getPriority) .thenComparing(taskDto -> LocalDateTime.parse(taskDto.getCreate_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))) .collect(Collectors.toList()); diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/config/mqtt2/MqttService.java b/nladmin-system/nlsso-server/src/main/java/org/nl/config/mqtt2/MqttService.java index 53a5d2f..85d0539 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/config/mqtt2/MqttService.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/config/mqtt2/MqttService.java @@ -24,7 +24,7 @@ import org.nl.config.lucene.service.LuceneExecuteLogService; import org.nl.config.lucene.service.dto.LuceneLogDto; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.context.annotation.DependsOn; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; @@ -39,8 +39,7 @@ import java.util.stream.Collectors; * @author onepiece */ @Component -//@ConditionalOnProperty(name = "spring.mqtt.active", havingValue = "true") -@ConditionalOnBean({LuceneExecuteLogService.class, DeviceAppService.class, RedisTemplate.class}) +@DependsOn({"luceneExecuteLogServiceImpl", "deviceAppServiceImpl", "redisTemplate"}) @Slf4j public class MqttService { @@ -137,16 +136,11 @@ public class MqttService { (r, executor) -> MSG_QUEUE.add(r) ); - - /** - * 不需要记录日志的点位 - */ - private static final List NO_SET_LOG_KEYS = Arrays.asList("heartbeat"); - + private final CountDownLatch latch = new CountDownLatch(1); @PostConstruct public void init() { - log.info("执行MQTT初始化"); + log.info("[MQTT 初始化]"); initTopicMap(); loadTags(); initMqttClient(); @@ -175,7 +169,7 @@ public class MqttService { .serverHost(mqttConfig.getUrl()) .addDisconnectedListener((context -> { Throwable cause = context.getCause(); - log.error("mqtt client disconnected , {}", cause.getMessage()); + log.error("[MQTT 断开连接, {}]", cause.getMessage()); MqttClientReconnector reconnect = context.getReconnector(); reconnect.reconnect(true); reconnect.delay(RECONNECT_DELAY, TimeUnit.MILLISECONDS); @@ -194,11 +188,11 @@ public class MqttService { .cleanSession(mqttConfig.getCleanSession()) .send() .thenAccept(connAck -> { - log.info("mqtt client connection success."); + log.info("[MQTT 连接成功]"); subscribeToTopics(Arrays.asList(mqttConfig.getTopics())); }) .exceptionally(throwable -> { - log.error("mqtt client connection failed: " + throwable.getMessage(), throwable); + log.error("[MQTT 连接失败, {}]", throwable.getMessage()); return null; }); @@ -207,6 +201,17 @@ public class MqttService { String payload = new String(publish.getPayloadAsBytes(), StandardCharsets.UTF_8); messageArrived(topic, payload); }); + + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + try { + latch.await(); + log.info("[MQTT 关闭程序]"); + System.out.println("[关闭程序]"); + } catch (InterruptedException e) { + e.printStackTrace(); + } + })); + } private void subscribeToTopics(List topics) { @@ -216,9 +221,9 @@ public class MqttService { .send() .whenComplete((subAck, throwable) -> { if (throwable != null) { - log.error("mqtt subscript failed Topic {}, error reason {} ", topic, throwable.getMessage()); + log.error("[MQTT 订阅失败, {}, {}]", topic, throwable.getMessage()); } else { - log.info("mqtt subscript success Topic {}", topic); + log.info("[MQTT 订阅成功, {}]", topic); } })); } @@ -227,9 +232,9 @@ public class MqttService { //接收到消息:先放队列,根据不同topic处理不同处理dd逻辑 if (topicMap.containsKey(topic)) { topicMap.get(topic).add(payload); - System.out.println("接收到消息---" + topic + "内容:" + payload); + System.out.println("接收到消息---" + topic); } else { - log.info("topic---{} , payload----{} ", topic, payload); + log.info("[MQTT 订阅主题不存在, {}]", topic); } } @@ -240,10 +245,10 @@ public class MqttService { .qos(MqttQos.EXACTLY_ONCE) .send() .thenAccept(pubAck -> { - log.info("mqtt client publish success Topic {} , Payload: {}", PUBLISH_TOPIC, payload); + log.info("[MQTT 发布成功, {}, {}]", PUBLISH_TOPIC, payload); }) .exceptionally(throwable -> { - log.error("mqtt client publish Topic {} ,Payload {} , failed reason {}", PUBLISH_TOPIC, payload, throwable.getMessage()); + log.error("[MQTT 发布成功, {}, {}, {}]", PUBLISH_TOPIC, payload, throwable.getMessage()); return null; }); } @@ -253,12 +258,12 @@ public class MqttService { */ private void run() { topicMap.forEach((topic, values) -> threadPool.execute(() -> { - log.info("mqtt create Topic thread:{}", topic); + log.info("[MQTT 创建订阅主题线程 {}]", topic); while (true) { try { execute(topic, values.take()); } catch (Exception e) { - log.error("mqtt execute handler failed Topic {} , reason {}", topic, e.getMessage()); + log.error("[MQTT {}, 执行处理失败 {}]", topic, e.getMessage()); } } })); @@ -276,7 +281,7 @@ public class MqttService { List tagList = msgValues.toJavaList(Tag.class); Map> groupTags = tagList.stream().collect(Collectors.groupingBy(tag -> tag.getId().substring(0, TagsUtil.nthIndexOf(tag.getId(), ".", 3)))); groupTags.forEach((tagId, tags) -> updateDeviceStatus(tagId.substring(TagsUtil.nthIndexOf(tagId, ".", 2) + 1), tags)); - System.out.println("线程名称:'" + Thread.currentThread() + "',接收到消息" + topic + "-" + body + "-"); + System.out.println("线程名称:'" + Thread.currentThread() + "',接收到消息 topic: " + topic); } /** @@ -307,7 +312,7 @@ public class MqttService { AbstractDeviceDriver deviceDriver = (AbstractDeviceDriver) device.getDeviceDriver(); if (!Objects.equals(deviceDriver.online, q)) { deviceDriver.setOnline(q); - log.info("device : {}, online status: {} ", deviceCode, q); + log.info("[MQTT 设备在线状态 {}, {}]", deviceCode, q); } } }); @@ -338,19 +343,36 @@ public class MqttService { @PreDestroy public void cleanup() { - if (mqttClient != null) { - mqttClient.disconnect().thenAccept(disconnectAck -> log.info("Application Close, So MQTT client disconnected.")); - } - unloadTags(); - threadPool.shutdown(); + CompletableFuture mqttDisconnectFuture = CompletableFuture.runAsync(() -> { + if (mqttClient != null) { + mqttClient.disconnect().thenAccept(disconnectAck -> System.out.println("[关闭MQTT Client]")); + log.info("[关闭MQTT Client]"); + } + }); + mqttDisconnectFuture.thenRun(() -> { + this.unloadTags(); + log.info("[加载Tags到Redis]"); + System.out.println("[加载Tags到Redis]"); + }).thenRun(() -> { + threadPool.shutdown(); + log.info("[关闭线程池]"); + System.out.println("[关闭线程池]"); + }).exceptionally(throwable -> { + log.error("[关闭异常 {}]", throwable.getMessage()); + System.out.println("[关闭异常]" + throwable.getMessage()); + return null; + }).join(); + latch.countDown(); } + private void loadTags() { Map entries = redisTemplateHash.opsForHash().entries(KEY); entries.forEach((key, value) -> ACCESSOR_VALUE.setValue((String) key, value)); redisTemplateHash.delete(KEY); } + private void unloadTags() { List allKey = ACCESSOR_VALUE.getAllKey(); Map map = new HashMap<>(); diff --git a/nladmin-system/nlsso-server/src/main/java/org/nl/system/service/coderule/impl/SysCodeRuleServiceImpl.java b/nladmin-system/nlsso-server/src/main/java/org/nl/system/service/coderule/impl/SysCodeRuleServiceImpl.java index 58d44fd..88e862e 100644 --- a/nladmin-system/nlsso-server/src/main/java/org/nl/system/service/coderule/impl/SysCodeRuleServiceImpl.java +++ b/nladmin-system/nlsso-server/src/main/java/org/nl/system/service/coderule/impl/SysCodeRuleServiceImpl.java @@ -21,6 +21,7 @@ import org.nl.system.service.coderule.dao.mapper.SysCodeRuleMapper; import org.nl.system.service.coderule.utils.CodeRuleTypeEnum; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import java.util.Date; @@ -57,6 +58,7 @@ public class SysCodeRuleServiceImpl extends ServiceImpl().eq(SysCodeRule::getCode, code)).getId(); diff --git a/nladmin-system/nlsso-server/src/main/resources/config/application-prod.yml b/nladmin-system/nlsso-server/src/main/resources/config/application-prod.yml index 2069d93..61d70c4 100644 --- a/nladmin-system/nlsso-server/src/main/resources/config/application-prod.yml +++ b/nladmin-system/nlsso-server/src/main/resources/config/application-prod.yml @@ -77,7 +77,7 @@ spring: active: true username: root password: 123456 - url: 192.168.1.218 + url: 192.168.8.218 clientId: hs_mqtt_prod cleanSession: false topics: diff --git a/nladmin-system/nlsso-server/src/main/resources/config/application.yml b/nladmin-system/nlsso-server/src/main/resources/config/application.yml index bb16737..149d9ba 100644 --- a/nladmin-system/nlsso-server/src/main/resources/config/application.yml +++ b/nladmin-system/nlsso-server/src/main/resources/config/application.yml @@ -7,7 +7,7 @@ spring: freemarker: check-template-location: false profiles: - active: dev2 + active: prod jackson: time-zone: GMT+8 data: diff --git a/nladmin-ui/src/views/acs/device/driver/appearance_inspection_scanner_conveyor_device.vue b/nladmin-ui/src/views/acs/device/driver/appearance_inspection_scanner_conveyor_device.vue index 775188b..5528f09 100644 --- a/nladmin-ui/src/views/acs/device/driver/appearance_inspection_scanner_conveyor_device.vue +++ b/nladmin-ui/src/views/acs/device/driver/appearance_inspection_scanner_conveyor_device.vue @@ -52,7 +52,7 @@ - + @@ -67,23 +67,23 @@ - + - + - + - + @@ -91,7 +91,7 @@ - + @@ -119,7 +119,7 @@ - + @@ -145,7 +145,7 @@ - + @@ -174,7 +174,7 @@ - + @@ -200,12 +200,12 @@ - + - + @@ -213,7 +213,7 @@ - + @@ -241,7 +241,7 @@ - + @@ -269,7 +269,7 @@ - + @@ -295,7 +295,7 @@ - + @@ -320,13 +320,13 @@ - - - - - - - + + + + + + + @@ -338,12 +338,12 @@ - + - + @@ -362,8 +362,8 @@ size="small" style="width: 100%;margin-bottom: 15px" > - - + + @@ -399,8 +399,8 @@ style="width: 100%;margin-bottom: 15px" > - - + + @@ -424,7 +424,7 @@ 测试写 @@ -433,7 +433,7 @@
- +
- 设备协议: + 指令相关:
- - - - OpcServer: - - - - - - PLC: - - - - - - -
- - -
- 输送系统: -
- + - - - + + + + + + + + - -
- - -
- 指令相关: -
- - - + + + + + + + + + @@ -84,11 +64,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
- + - + @@ -157,12 +157,12 @@ - + - + @@ -245,7 +245,7 @@ - + @@ -259,7 +259,7 @@
- + - - + +