From 0d04bc5d8080b82338302fba0a59fccff2eaedfc Mon Sep 17 00:00:00 2001 From: Junjie <fallin.jie@qq.com> Date: 星期日, 06 七月 2025 11:28:29 +0800 Subject: [PATCH] # --- zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/Utils.java | 174 +++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 147 insertions(+), 27 deletions(-) diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/Utils.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/Utils.java index d8f7718..a982931 100644 --- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/Utils.java +++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/Utils.java @@ -1,6 +1,24 @@ package com.zy.asrs.wcs.core.utils; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.zy.asrs.framework.common.Cools; +import com.zy.asrs.framework.common.SpringUtils; +import com.zy.asrs.framework.exception.CoolException; +import com.zy.asrs.wcs.core.entity.BasLift; +import com.zy.asrs.wcs.core.entity.Task; +import com.zy.asrs.wcs.core.entity.TaskSerialNo; +import com.zy.asrs.wcs.core.model.NavigateNode; +import com.zy.asrs.wcs.core.model.enums.DeviceCtgType; +import com.zy.asrs.wcs.core.model.enums.NavigationMapType; +import com.zy.asrs.wcs.core.service.BasLiftService; +import com.zy.asrs.wcs.core.service.TaskSerialNoService; +import com.zy.asrs.wcs.core.service.TaskService; +import com.zy.asrs.wcs.rcs.cache.SlaveConnection; +import com.zy.asrs.wcs.rcs.entity.Device; +import com.zy.asrs.wcs.rcs.model.enums.SlaveType; +import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol; +import com.zy.asrs.wcs.rcs.service.DeviceService; +import com.zy.asrs.wcs.rcs.thread.ShuttleThread; import java.util.ArrayList; import java.util.List; @@ -63,35 +81,137 @@ //鑾峰彇闄ょ櫧鍚嶅崟澶栫殑鎸囧畾妤煎眰鍏ㄩ儴绌挎杞y鍧愭爣鐐� public static List<int[]> getShuttlePoints(Integer whiteShuttle, Integer lev) { -// SlaveProperties slaveProperties = SpringUtils.getBean(SlaveProperties.class); + DeviceService deviceService = SpringUtils.getBean(DeviceService.class); ArrayList<int[]> list = new ArrayList<>(); -// for (ShuttleSlave slave : slaveProperties.getShuttle()) { -// if (slave.getId().intValue() == whiteShuttle) { -// continue;//璺宠繃鐧藉悕鍗� -// } -// -// //鑾峰彇绌挎杞︽墍鍦ㄨ妭鐐逛綅缃� -// ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, slave.getId()); -// if (shuttleThread == null) { -// continue; -// } -// ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); -// if (shuttleProtocol == null) { -// continue; -// } -// -// if (shuttleProtocol.getCurrentLocNo() == null) { -// continue; -// } -// -// if (lev != Utils.getLev(shuttleProtocol.getCurrentLocNo())) { -// continue;//妤煎眰涓嶅悓 -// } -// -// int[] xyPosition = NavigatePositionConvert.positionToXY(shuttleProtocol.getCurrentLocNo());//閫氳繃搴撲綅鍙疯幏鍙杧y鍧愭爣 -// list.add(xyPosition); -// } + + List<Device> devices = deviceService.list(new LambdaQueryWrapper<Device>() + .eq(Device::getDeviceType, DeviceCtgType.SHUTTLE.val()) + .eq(Device::getStatus, 1)); + for (Device device : devices) { + if (Integer.parseInt(device.getDeviceNo()) == whiteShuttle) { + continue;//璺宠繃鐧藉悕鍗� + } + + //鑾峰彇绌挎杞︽墍鍦ㄨ妭鐐逛綅缃� + ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue()); + if (shuttleThread == null) { + continue; + } + ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); + if (shuttleProtocol == null) { + continue; + } + + if (shuttleProtocol.getCurrentLocNo() == null) { + continue; + } + + if (lev != Utils.getLev(shuttleProtocol.getCurrentLocNo())) { + continue;//妤煎眰涓嶅悓 + } + + int[] xyPosition = NavigatePositionConvert.positionToXY(shuttleProtocol.getCurrentLocNo());//閫氳繃搴撲綅鍙疯幏鍙杧y鍧愭爣 + list.add(xyPosition); + } return list; } + public static boolean hasShuttleInLoc(String locNo, Long deviceId) { + DeviceService deviceService = SpringUtils.getBean(DeviceService.class); + + List<Device> list = deviceService.list(new LambdaQueryWrapper<Device>() + .eq(Device::getDeviceType, DeviceCtgType.SHUTTLE.val()) + .eq(Device::getStatus, 1)); + + for (Device device : list) { + if (deviceId.equals(device.getId())) { + continue; + } + + //鑾峰彇鍥涘悜绌挎杞︾嚎绋� + ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue()); + if (shuttleThread == null) { + continue; + } + + ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); + if (shuttleProtocol == null) { + continue; + } + + if (shuttleProtocol.getCurrentLocNo().equals(locNo)) { + return true; + } + } + + return false; + } + + /** + * 鐢熸垚宸ヤ綔鍙� + * @return taskNo(宸ヤ綔鍙�) + */ + public static int getTaskNo(String flag) { + TaskSerialNoService taskSerialNoService = SpringUtils.getBean(TaskSerialNoService.class); + TaskService taskService = SpringUtils.getBean(TaskService.class); + TaskSerialNo taskSerialNo = taskSerialNoService.getOne(new LambdaQueryWrapper<TaskSerialNo>() + .eq(TaskSerialNo::getFlag, flag) + .eq(TaskSerialNo::getStatus, 1)); + if (Cools.isEmpty(taskSerialNo)) { + throw new CoolException("鏁版嵁寮傚父锛岃鑱旂郴绠$悊鍛�"); + } + + int taskNo = taskSerialNo.getTaskNo(); + int sNo = taskSerialNo.getStartNo(); + int eNo = taskSerialNo.getTargetNo(); + taskNo = taskNo >= eNo ? sNo : taskNo + 1; + while (true) { + Task task = taskService.getOne(new LambdaQueryWrapper<Task>() + .eq(Task::getTaskNo, taskNo)); + if (null != task) { + taskNo = taskNo >= eNo ? sNo : taskNo + 1; + } else { + break; + } + } + // 淇敼搴忓彿璁板綍 + if (taskNo > 0){ + taskSerialNo.setTaskNo(taskNo); + taskSerialNoService.updateById(taskSerialNo); + return taskNo; + } + throw new CoolException("宸ヤ綔鍙风敓鎴愬け璐�"); + } + + /** + * 妫�娴嬬┛姊溅鏄惁鏈変换鍔$粦瀹� + */ + public static boolean checkShuttleHasBinding(Device device, String taskNo) { + TaskService taskService = SpringUtils.getBean(TaskService.class); + List<Task> tasks = taskService.selectWorkingByShuttle(Integer.parseInt(device.getDeviceNo()), taskNo); + if (tasks.isEmpty()) { + return false;//鏃犱换鍔$粦瀹� + } + return true;//鏈変换鍔$粦瀹� + } + + /** + * 妫�娴嬫彁鍗囨満鏄惁鏈変换鍔$粦瀹� + */ + public static boolean checkLiftHasBinding(Integer liftNo) { + return checkLiftHasBinding(liftNo, null); + } + + /** + * 妫�娴嬫彁鍗囨満鏄惁鏈変换鍔$粦瀹� + */ + public static boolean checkLiftHasBinding(Integer liftNo, String taskNo) { + TaskService taskService = SpringUtils.getBean(TaskService.class); + List<Task> tasks = taskService.selectWorkingByLift(liftNo, taskNo); + if (tasks.isEmpty()) { + return false;//鏃犱换鍔$粦瀹� + } + return true;//鏈変换鍔$粦瀹� + } + } -- Gitblit v1.9.1