From 883e4b48dc603b74867269cea4e913313788ac3b Mon Sep 17 00:00:00 2001 From: tuqiang <437016993@qq.com> Date: Fri, 5 Dec 2025 18:01:22 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E8=A7=A3=E5=86=B3=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E9=98=BB=E5=A1=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/org/nl/acs/agv/AgvWaitUtil.java | 97 ++++++++++++++++++- .../acs/agv/rest/XianGongAgvController.java | 7 ++ .../nl/acs/agv/server/XianGongAgvService.java | 1 + .../server/impl/XianGongAgvServiceImpl.java | 29 +++++- .../agv/ndctwo/AgvNdcTwoDeviceDriver.java | 1 + .../org/nl/acs/opc/OpcServerServiceImpl.java | 7 +- .../src/main/java/org/nl/acs/opc/OpcUtl.java | 2 +- .../org/nl/acs/task/service/TaskService.java | 7 ++ .../task/service/impl/TaskServiceImpl.java | 22 +++++ .../main/java/org/nl/acs/utils/ReadUtil.java | 32 ++++++ 10 files changed, 195 insertions(+), 10 deletions(-) diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/AgvWaitUtil.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/AgvWaitUtil.java index 625af55da..6ac8ff474 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/AgvWaitUtil.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/AgvWaitUtil.java @@ -8,27 +8,38 @@ import lombok.extern.slf4j.Slf4j; import org.nl.acs.AcsConfig; import org.nl.acs.common.base.CommonFinalParam; import org.nl.acs.device.domain.Device; +import org.nl.acs.device_driver.conveyor.standard_conveyor_control_with_plcscanner.ItemProtocol; import org.nl.acs.device_driver.one_conveyor.box_subvolumes_conveyor.BoxSubvolumesConveyorDeviceDriver; import org.nl.acs.device_driver.two_conveyor.manipulator_agv_station.ManipulatorAgvStationDeviceDriver; import org.nl.acs.ext.wms.service.AcsToWmsService; import org.nl.acs.instruction.domain.Instruction; import org.nl.acs.instruction.service.InstructionService; import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.opc.OpcServerService; import org.nl.acs.task.enums.ActionTypeEnum; import org.nl.acs.task.enums.AgvActionTypeEnum; import org.nl.acs.task.enums.AgvSystemTypeEnum; +import org.nl.acs.utils.CurrentLock; +import org.nl.acs.utils.ReadUtil; import org.nl.common.exception.BadRequestException; import org.nl.config.SpringContextHolder; import org.nl.config.lucene.service.LuceneExecuteLogService; import org.nl.config.lucene.service.dto.LuceneLogDto; import org.nl.system.service.param.ISysParamService; +import org.openscada.opc.lib.da.Group; +import org.openscada.opc.lib.da.Server; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Semaphore; +import java.util.concurrent.locks.ReentrantLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; /** * @author zhangjiangwei @@ -48,6 +59,8 @@ public class AgvWaitUtil { @Autowired private DeviceAppService deviceAppService; + @Autowired + private OpcServerService opcServerService; @Autowired private LuceneExecuteLogService luceneExecuteLogService; @@ -64,7 +77,27 @@ public class AgvWaitUtil { if (startDevice.getDeviceDriver() instanceof ManipulatorAgvStationDeviceDriver) { manipulatorAgvStationDeviceDriver = (ManipulatorAgvStationDeviceDriver) startDevice.getDeviceDriver(); if (manipulatorAgvStationDeviceDriver.getTo_command() != 2) { - manipulatorAgvStationDeviceDriver.writing(2); + if (CurrentLock.tryLock(startDeviceCode)){ + try { + Map itemMap = new HashMap(); + String to_command = startDevice.getOpc_server_code() + "." + startDevice.getOpc_plc_code() + "." + startDevice.getDevice_code() + + "." + "to_command"; + itemMap.put(to_command, 2); + ReadUtil.writeAndCheck(itemMap, startDevice.getOpc_server_code()); + LuceneLogDto logDto1 = LuceneLogDto.builder() + .device_code(startDeviceCode) + .content("诺宝agv允许取货" + "给点位" + startDeviceCode+"下发电气值2") + .build(); + logDto1.setLog_level(4); + luceneExecuteLogService.deviceExecuteLog(logDto1); + }finally { + CurrentLock.unLock(startDeviceCode); + } + }else { + throw new BadRequestException(startDeviceCode+"当前点位正在执行写操作"); + } + +// manipulatorAgvStationDeviceDriver.writing(2); } int i = 0; while (true){ @@ -167,7 +200,25 @@ public class AgvWaitUtil { if (startDevice.getDeviceDriver() instanceof ManipulatorAgvStationDeviceDriver) { manipulatorAgvStationDeviceDriver = (ManipulatorAgvStationDeviceDriver) startDevice.getDeviceDriver(); if (manipulatorAgvStationDeviceDriver.getTo_command() != 3) { - manipulatorAgvStationDeviceDriver.writing(3); + if (CurrentLock.tryLock(startDeviceCode)){ + try { + Map itemMap = new HashMap(); + String to_command = startDevice.getOpc_server_code() + "." + startDevice.getOpc_plc_code() + "." + startDevice.getDevice_code() + + "." + "to_command"; + itemMap.put(to_command, 3); + ReadUtil.writeAndCheck(itemMap, startDevice.getOpc_server_code()); + LuceneLogDto logDto1 = LuceneLogDto.builder() + .device_code(startDeviceCode) + .content("诺宝agv允许取货" + "给点位" + startDeviceCode+"下发电气值3") + .build(); + logDto1.setLog_level(4); + luceneExecuteLogService.deviceExecuteLog(logDto1); + }finally { + CurrentLock.unLock(startDeviceCode); + } + }else { + throw new BadRequestException(startDeviceCode+"当前点位正在执行写操作"); + } } int i = 0; while (true){ @@ -269,7 +320,26 @@ public class AgvWaitUtil { if (endDevice.getDeviceDriver() instanceof ManipulatorAgvStationDeviceDriver) { manipulatorAgvStationDeviceDriver = (ManipulatorAgvStationDeviceDriver) endDevice.getDeviceDriver(); if (manipulatorAgvStationDeviceDriver.getTo_command() != 4) { - manipulatorAgvStationDeviceDriver.writing(4); + if (CurrentLock.tryLock(endDeviceCode)){ + try { + Map itemMap = new HashMap(); + String to_command = endDevice.getOpc_server_code() + "." + endDevice.getOpc_plc_code() + "." + endDevice.getDevice_code() + + "." + "to_command"; + itemMap.put(to_command, 4); + ReadUtil.writeAndCheck(itemMap, endDevice.getOpc_server_code()); + LuceneLogDto logDto1 = LuceneLogDto.builder() + .device_code(endDeviceCode) + .content("诺宝agv允许取货" + "给点位" + endDeviceCode+"下发电气值4") + .build(); + logDto1.setLog_level(4); + luceneExecuteLogService.deviceExecuteLog(logDto1); + }finally { + CurrentLock.unLock(endDeviceCode); + } + }else { + throw new BadRequestException(endDeviceCode+"当前点位正在执行写操作"); + } +// manipulatorAgvStationDeviceDriver.writing(4); } int i = 0; while (true){ @@ -326,7 +396,26 @@ public class AgvWaitUtil { if (nextDevice.getDeviceDriver() instanceof ManipulatorAgvStationDeviceDriver) { manipulatorAgvStationDeviceDriver = (ManipulatorAgvStationDeviceDriver) nextDevice.getDeviceDriver(); if (manipulatorAgvStationDeviceDriver.getTo_command() != 5) { - manipulatorAgvStationDeviceDriver.writing(5); + if (CurrentLock.tryLock(endDeviceCode)){ + try { + Map itemMap = new HashMap(); + String to_command = nextDevice.getOpc_server_code() + "." + nextDevice.getOpc_plc_code() + "." + nextDevice.getDevice_code() + + "." + "to_command"; + itemMap.put(to_command, 5); + ReadUtil.writeAndCheck(itemMap, nextDevice.getOpc_server_code()); + LuceneLogDto logDto1 = LuceneLogDto.builder() + .device_code(endDeviceCode) + .content("诺宝agv允许取货" + "给点位" + endDeviceCode+"下发电气值5") + .build(); + logDto1.setLog_level(4); + luceneExecuteLogService.deviceExecuteLog(logDto1); + }finally { + CurrentLock.unLock(endDeviceCode); + } + }else { + throw new BadRequestException(endDeviceCode+"当前点位正在执行写操作"); + } +// manipulatorAgvStationDeviceDriver.writing(5); } int i = 0; while (true){ diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/rest/XianGongAgvController.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/rest/XianGongAgvController.java index b1b998064..817d17fc4 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/rest/XianGongAgvController.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/rest/XianGongAgvController.java @@ -30,4 +30,11 @@ public class XianGongAgvController { return new ResponseEntity<>(xianGongAgentService.xgAGVWaitPointRequest(requestParam), HttpStatus.OK); } + + @PostMapping("/api/agv/test") + @Log("仙工AGV请求取放货") + @SaIgnore + public ResponseEntity test() { + return new ResponseEntity<>(xianGongAgentService.test(), HttpStatus.OK); + } } diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/XianGongAgvService.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/XianGongAgvService.java index f08a75b5c..b38c811b8 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/XianGongAgvService.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/XianGongAgvService.java @@ -128,4 +128,5 @@ public interface XianGongAgvService { HttpResponse sendOrderSequencesToForklift(Instruction dto, InteractionJsonDTO interactionJsonDTO); + JSONObject test(); } diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/impl/XianGongAgvServiceImpl.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/impl/XianGongAgvServiceImpl.java index 36049d689..a5b9db269 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/impl/XianGongAgvServiceImpl.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/agv/server/impl/XianGongAgvServiceImpl.java @@ -26,16 +26,21 @@ import org.nl.acs.instruction.service.InstructionService; import org.nl.acs.instruction.service.dto.InteractionJsonDTO; import org.nl.acs.opc.DeviceAppService; import org.nl.acs.device.enums.DeviceType; +import org.nl.acs.opc.OpcServerService; import org.nl.acs.task.enums.ActionTypeEnum; import org.nl.acs.task.enums.AgvActionTypeEnum; import org.nl.acs.task.enums.AgvSystemTypeEnum; import org.nl.acs.task.service.TaskService; import org.nl.acs.task.service.dto.TaskDto; +import org.nl.acs.utils.CurrentLock; +import org.nl.acs.utils.ReadUtil; import org.nl.common.exception.BadRequestException; import org.nl.config.language.LangProcess; import org.nl.config.lucene.service.LuceneExecuteLogService; import org.nl.config.lucene.service.dto.LuceneLogDto; import org.nl.system.service.param.ISysParamService; +import org.openscada.opc.lib.da.Group; +import org.openscada.opc.lib.da.Server; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Lazy; @@ -69,6 +74,8 @@ public class XianGongAgvServiceImpl implements XianGongAgvService { private LuceneExecuteLogService luceneExecuteLogService; @Autowired private DeviceAppService deviceAppservice; + @Autowired + private OpcServerService opcServerService; @Autowired @@ -1091,7 +1098,7 @@ public class XianGongAgvServiceImpl implements XianGongAgvService { } taskUpdate.setTask_id(instructionDto.getTask_id()); instructionService.update(instructionDto); - taskserver.update(taskUpdate); + taskserver.update1(taskUpdate); } @@ -1143,6 +1150,26 @@ public class XianGongAgvServiceImpl implements XianGongAgvService { } } + @Override + public JSONObject test() { + if (CurrentLock.tryLock("CK2037")){ + try { + Device startDevice = deviceAppService.findDeviceByCode("CK2037"); + Map itemMap = new HashMap(); + String to_command = startDevice.getOpc_server_code() + "." + startDevice.getOpc_plc_code() + "." + startDevice.getDevice_code() + + "." + "to_command"; + itemMap.put(to_command, 3); + ReadUtil.writeAndCheck(itemMap, startDevice.getOpc_server_code()); + }finally { + CurrentLock.unLock("CK2037"); + } + }else { + throw new BadRequestException("当前设备正在写"); + } + + return null; + } + /** * 追加动作块 diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/agv/ndctwo/AgvNdcTwoDeviceDriver.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/agv/ndctwo/AgvNdcTwoDeviceDriver.java index c971cedd1..6484a0472 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/agv/ndctwo/AgvNdcTwoDeviceDriver.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/agv/ndctwo/AgvNdcTwoDeviceDriver.java @@ -2248,6 +2248,7 @@ public class AgvNdcTwoDeviceDriver extends AbstractDeviceDriver implements Devic logDto.setLog_level(4); luceneExecuteLogService.deviceExecuteLog(logDto); } + this.setPhase(phase); } //上传AGV电量 else if (phase == 0x70) { diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/OpcServerServiceImpl.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/OpcServerServiceImpl.java index 1695b1c95..87059a076 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/OpcServerServiceImpl.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/OpcServerServiceImpl.java @@ -74,7 +74,7 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn } @Override - public synchronized Group getServer(String code) { + public Group getServer(String code) { synchronized (this.buildLock(code)) { Group group = null; group = (Group) this.groups.get(code); @@ -86,7 +86,6 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn if (!group.isActive()) { break label68; } - var10000 = group; } catch (JIException var14) { log.error(code, var14); @@ -132,7 +131,7 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn group = server.addGroup(groupName); } catch (Exception var12) { this.clearServer(code); - ThreadUtl.sleep(5000L); + ThreadUtl.sleep(1500L); log.warn("获取opc出错重新获取", code, var12); // server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain())); server = OpcUtl.getServer(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain())); @@ -239,7 +238,7 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn } catch (Exception var4) { this.clearServer(code); log.warn("写入出错opc server {} 重新加载", code, var4); - ThreadUtl.sleep(3000L); + ThreadUtl.sleep(1500L); throw var4; } } diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/OpcUtl.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/OpcUtl.java index 321be2500..682ce260f 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/OpcUtl.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/OpcUtl.java @@ -27,7 +27,7 @@ import java.util.concurrent.*; */ @Slf4j public class OpcUtl { - private static int timeout = 1 * 60 * 1000; + private static int timeout = 1 * 10 * 1000; private static String key = "rpc.socketTimeout"; static { diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/TaskService.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/TaskService.java index 11d00b722..cd98aabea 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/TaskService.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/TaskService.java @@ -298,6 +298,13 @@ public interface TaskService extends CommonService { */ void update(TaskDto dto); + /** + * 编辑 + * + * @param dto / + */ + void update1(TaskDto dto); + /** * 多选删除 * diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java index eefc43750..57639c283 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java @@ -877,6 +877,28 @@ public class TaskServiceImpl extends CommonServiceImpl impleme } + @Override + public void update1(TaskDto dto) { + TaskDto entity = this.findById(dto.getTask_id()); + if (entity == null) { + throw new BadRequestException(LangProcess.msg("error_sysAuth")); + } + + String currentUsername = SecurityUtils.getCurrentNickName(); + String now = DateUtil.now(); + dto.setUpdate_time(now); + dto.setUpdate_by(currentUsername); + + Task task = ConvertUtil.convert(dto, Task.class); + taskMapper.updateById(task); + + //从缓存中移除任务信息 + this.removeByCodeFromCache(entity.getTask_code()); + //向缓存添加任务信息 + this.addTaskToCache(dto); + + } + @Override @Transactional(rollbackFor = Exception.class) public void deleteAll(String[] ids) throws Exception { diff --git a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/utils/ReadUtil.java b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/utils/ReadUtil.java index e6b3e4714..45c28bdd2 100644 --- a/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/utils/ReadUtil.java +++ b/acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/utils/ReadUtil.java @@ -10,7 +10,10 @@ import org.jinterop.dcom.common.JIException; import org.jinterop.dcom.core.JIVariant; import org.nl.acs.device.device_driver.standard_inspect.ItemDto; import org.nl.acs.device.device_driver.standard_inspect.ItemProtocol; +import org.nl.acs.opc.ObjectUtl; +import org.nl.acs.opc.OpcServerService; import org.nl.acs.opc.OpcUtl; +import org.nl.acs.opc.ThreadUtl; import org.nl.acs.opc.domain.Opc; import org.nl.acs.opc.service.mapper.OpcMapper; import org.nl.common.exception.BadRequestException; @@ -87,6 +90,35 @@ public class ReadUtil { } } + public static void writeAndCheck(Map strings, String opcServer) { + OpcServerService server =SpringContextHolder.getBean(OpcServerService.class); + Group group = server.getServer( opcServer); + if (group ==null){ + throw new BadRequestException("write group not has"); + } + System.out.println("-----server对象地址-----"+group.getServer()); + try { + if (!group.isActive()){ + throw new BadRequestException("write group is not active"); + } + Iterator it = strings.keySet().iterator(); + while (it.hasNext()) { + String key = (String) it.next(); + Item byteItem = group.addItem(key); + Object o = strings.get(key); + if (o == null || "".equals(o)) { + break; + } + WriteRequest write1 = new WriteRequest(byteItem, new JIVariant(o.toString())); + List list = new ArrayList(); + list.add(write1); + OpcUtl.writeValue(group, (WriteRequest[]) list.toArray(new WriteRequest[0])); + } + } catch (Exception e) { + server.clearServer(opcServer); + throw new BadRequestException("group write error:"+e.getMessage()); + } + } public static JSONArray getReadableItemDtos() { List list = ItemProtocol.getReadableItemDtos();