From 75f964bc9ffad348dc3204229fb08a1bafb33254 Mon Sep 17 00:00:00 2001 From: gengby <858962040@qq.com> Date: Mon, 8 Apr 2024 15:34:48 +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 --- .../agv/server/impl/NDCAgvServiceImpl.java | 4 +-- .../run/OneNDCSocketConnectionAutoRun.java | 11 +++++-- .../service/InstructionService.java | 2 ++ .../service/impl/InstructionServiceImpl.java | 30 +++++++++++++++---- .../modules/quartz/task/AutoCreateInst.java | 6 ++-- .../service/impl/GenCodeServiceImpl.java | 3 ++ .../src/main/resources/logback-spring.xml | 1 + 7 files changed, 43 insertions(+), 14 deletions(-) diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/NDCAgvServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/NDCAgvServiceImpl.java index f1bc4cf..945a337 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/NDCAgvServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/NDCAgvServiceImpl.java @@ -233,10 +233,10 @@ public class NDCAgvServiceImpl implements NDCAgvService { public boolean deviceOption(String option) { byte high; byte low; - if (option.equals("1")) { + if ("1".equals(option)) { high = (byte) IntToHexHigh(00); low = (byte) IntToHexHigh(01); - } else if (option.equals("2")) { + } else if ("2".equals(option)) { high = (byte) IntToHexHigh(00); low = (byte) IntToHexHigh(00); } else { diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java b/acs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java index 0176048..d28e270 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java @@ -16,6 +16,7 @@ import org.nl.acs.instruction.service.impl.InstructionServiceImpl; import org.nl.acs.log.service.DeviceExecuteLogService; import org.nl.acs.opc.Device; import org.nl.acs.opc.DeviceAppService; +import org.nl.modules.common.exception.BadRequestException; import org.nl.modules.system.service.ParamService; import org.nl.modules.system.service.impl.ParamServiceImpl; import org.nl.modules.wql.util.SpringContextHolder; @@ -254,7 +255,7 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable { // } else { // device = deviceAppService.findDeviceByCode(Integer.toString(arr[20])); // } - if (phase == 0x67 || phase == 0x70 || phase == 0x71 || phase == 0x72 || phase == 0x73 || phase == 0x74 ) { + if (phase == 0x67 || phase == 0x70 || phase == 0x71 || phase == 0x72 || phase == 0x73 || phase == 0x74) { device = deviceAppService.findDeviceByCode(Integer.toString(arr[18] * 256 + arr[19])); } else { device = deviceAppService.findDeviceByCode(Integer.toString(arr[20])); @@ -319,8 +320,12 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable { try { log.info("下发agv数据:" + Bytes2HexString(b)); System.out.println("下发agv数据:" + Bytes2HexString(b)); - dos.write(b); - dos.flush(); + if (dos != null) { + dos.write(b); + dos.flush(); + } else { + throw new BadRequestException("未连接NDC!"); + } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java index 203e45e..2b31dde 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java @@ -276,4 +276,6 @@ public interface InstructionService { void init(String id); + + List findByTaskcodeFromCache(String task_code); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java index 356b91d..4e58646 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java @@ -278,6 +278,10 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu public void create(Instruction dto) { dto = foramte(dto); String task_code = dto.getTask_code(); + List list = this.findByTaskcodeFromCache(task_code); + if (ObjectUtil.isNotEmpty(list)) { + throw new BadRequestException("已存在该任务的指令信息"); + } TaskDto task = taskService.findByCodeFromCache(task_code); String currentUsername = SecurityUtils.getCurrentUsername(); @@ -362,14 +366,19 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu if (ObjectUtil.isEmpty(route)) { throw new BadRequestException("未查询到相关路由!"); } - if (StrUtil.equals(shortPathsList.get(0).getType(), "1")) { - NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvService.class); - ndcAgvService.sendAgvInstToNDC(task.getAgv_system_type(), dto); + try { + if (StrUtil.equals(shortPathsList.get(0).getType(), "1")) { + NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvService.class); + ndcAgvService.sendAgvInstToNDC(task.getAgv_system_type(), dto); + } + } catch (Exception e) { + throw new BadRequestException("下发调度失败,NDC未连接!"); } } catch (Exception e) { - dto.setSend_status("2"); - e.printStackTrace(); - log.error(""); + throw new BadRequestException(e.getMessage()); +// dto.setSend_status("2"); +// e.printStackTrace(); +// log.error(""); } WQLObject wo = WQLObject.getWQLObject("acs_instruction"); @@ -1438,4 +1447,13 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu ((SiemensConveyorDeviceDriver) startDeviceDriver).writing(list); } } + + @Override + public List findByTaskcodeFromCache(String task_code) { + return Optional.ofNullable(this.instructions) + .orElse(new CopyOnWriteArrayList<>()) + .stream() + .filter(instruction -> instruction.getTask_code().equals(task_code)) + .collect(Collectors.toList()); + } } diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java b/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java index 48994d2..5990fc1 100644 --- a/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java +++ b/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java @@ -33,7 +33,6 @@ import java.util.stream.Collectors; public class AutoCreateInst { - /** * 根据任务状态创建指令、生成下一条指令 * 创建指令前需要判断是否条件具备:起始位置是否有货、目标位置是否有货 @@ -56,7 +55,7 @@ public class AutoCreateInst { treeMap.putAll(collect); for (List value : treeMap.values()) { list = value; - if(CollUtil.isNotEmpty(list)){ + if (CollUtil.isNotEmpty(list)) { break; } } @@ -136,7 +135,7 @@ public class AutoCreateInst { if (s.equals(taskDto.getNext_device_code())) { Instruction instruction = instructionService.findByTaskid(taskDto.getTask_id(), "instruction_status < 2"); if (ObjectUtil.isEmpty(instruction) || (Integer.parseInt(StrUtil.isNotBlank - (instruction.getExecute_status()) ? instruction.getExecute_status() : "0") <4)) { + (instruction.getExecute_status()) ? instruction.getExecute_status() : "0") < 4)) { flag = true; log.error("当前任务号{},已创建同列起点导致创建指令失败,起点为{},终点为{}", acsTask.getTask_code(), acsTask.getStart_device_code(), acsTask.getNext_device_code()); break; @@ -262,6 +261,7 @@ public class AutoCreateInst { } catch (Exception e) { acsTask.setRemark(e.getMessage()); taskserver.updateByCodeFromCache(acsTask); + log.info("自动创建指令失败{}", e.getMessage()); continue; } //创建指令后修改任务状态 diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/system/service/impl/GenCodeServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/modules/system/service/impl/GenCodeServiceImpl.java index 32ff1df..609975a 100644 --- a/acs/nladmin-system/src/main/java/org/nl/modules/system/service/impl/GenCodeServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/modules/system/service/impl/GenCodeServiceImpl.java @@ -15,6 +15,8 @@ import org.nl.modules.wql.util.WqlUtil; import org.springframework.cache.annotation.CacheConfig; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import java.util.Date; import java.util.HashMap; @@ -98,6 +100,7 @@ public class GenCodeServiceImpl implements GenCodeService { } @Override + @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class) public String codeDemo(Map form) { String code = (String) form.get("code"); String id = this.queryIdByCode(code); diff --git a/acs/nladmin-system/src/main/resources/logback-spring.xml b/acs/nladmin-system/src/main/resources/logback-spring.xml index 8748d8c..1fdaaf7 100644 --- a/acs/nladmin-system/src/main/resources/logback-spring.xml +++ b/acs/nladmin-system/src/main/resources/logback-spring.xml @@ -20,6 +20,7 @@ https://juejin.cn/post/6844903775631572999 +