From 513f54c61991af2078c9098845df3e840ea5b863 Mon Sep 17 00:00:00 2001 From: zhang <zc857179121@qq.com> Date: 星期二, 17 六月 2025 14:29:48 +0800 Subject: [PATCH] 1 --- zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java | 284 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 221 insertions(+), 63 deletions(-) diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java index e14d05b..c18e9f1 100644 --- a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java +++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java @@ -35,7 +35,7 @@ import com.zy.acs.manager.system.service.ConfigService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.interceptor.TransactionAspectSupport; @@ -47,8 +47,8 @@ * Created by vincent on 2023/6/14 */ @Slf4j -@Component("mainService") -public class MainService { +@Service("mainService") +public class MainService implements IMainService { @Autowired private BusService busService; @@ -96,7 +96,6 @@ private LaneService laneService; @Autowired private ActionSorter actionSorter; - @SuppressWarnings("all") @Transactional @@ -175,8 +174,28 @@ if (!locService.updateById(oriLoc)) { throw new BusinessException("oriLoc锛�" + task.getOriLoc$() + " failed to update"); } + + destSta = staService.getById(task.getDestSta()); + if (!destSta.getStaSts().equals(StaStsType.IDLE.val())) { + throw new BusinessException("destSta锛�" + task.getDestSta$() + " is not in IDLE status"); + } + destSta.setStaSts(StaStsType.READY_RELEASE.val()); + destSta.setUpdateTime(now); + if (!staService.updateById(destSta)) { + throw new BusinessException("destSta锛�" + task.getDestSta$() + " failed to update"); + } break; case STA_TO_LOC: + oriSta = staService.getById(task.getOriSta()); + if (!oriSta.getStaSts().equals(StaStsType.STOCK.val())) { + throw new BusinessException("oriSta锛�" + task.getOriSta$() + " is not in STOCK status"); + } + oriSta.setStaSts(StaStsType.READY_TAKE.val()); + oriSta.setUpdateTime(now); + if (!staService.updateById(oriSta)) { + throw new BusinessException("oriSta锛�" + task.getOriSta$() + " failed to update"); + } + destLoc = locService.getById(task.getDestLoc()); if (!destLoc.getLocSts().equals(LocStsType.IDLE.val())) { throw new BusinessException("destLoc锛�" + task.getDestLoc$() + " is not in IDLE status"); @@ -188,6 +207,25 @@ } break; case STA_TO_STA: + oriSta = staService.getById(task.getOriSta()); + if (!oriSta.getStaSts().equals(StaStsType.STOCK.val())) { + throw new BusinessException("oriSta锛�" + task.getOriSta$() + " is not in STOCK status"); + } + oriSta.setStaSts(StaStsType.READY_TAKE.val()); + oriSta.setUpdateTime(now); + if (!staService.updateById(oriSta)) { + throw new BusinessException("oriSta锛�" + task.getOriSta$() + " failed to update"); + } + + destSta = staService.getById(task.getDestSta()); + if (!destSta.getStaSts().equals(StaStsType.IDLE.val())) { + throw new BusinessException("destSta锛�" + task.getDestSta$() + " is not in IDLE status"); + } + destSta.setStaSts(StaStsType.READY_RELEASE.val()); + destSta.setUpdateTime(now); + if (!staService.updateById(destSta)) { + throw new BusinessException("destSta锛�" + task.getDestSta$() + " failed to update"); + } break; default: break; @@ -223,7 +261,7 @@ for (Task task : taskList) { Agv agv = allocateService.execute(task); if (null == agv) { -// log.warn("Task[{}] has an issue锛� because it failed to checkout agv which is idle...", task.getSeqNum()); +// log.warn("Task[{}] has an issue锛� because it failed to check out agv which is idle...", task.getSeqNum()); continue; } task.setAgvId(agv.getId()); @@ -246,7 +284,9 @@ */ @Transactional(propagation = Propagation.REQUIRES_NEW) public void buildMajorTask(Long agvId, List<Task> taskList) { - if (Cools.isEmpty(agvId, taskList)) { return; } + if (Cools.isEmpty(agvId, taskList)) { + return; + } try { // valid ----------------------------------------------- Agv agv = agvService.getById(agvId); @@ -286,16 +326,18 @@ * val: new TaskPosDto(taskId, new Double[]{code.getX(), code.getY()}, posType) */ Map<String, List<TaskPosDto>> groups = new HashMap<>(); - final String sameGroupXy = configService.getVal( "sameGroupXy", String.class); + final String sameGroupXy = configService.getVal("sameGroupXy", String.class); int backpackLev = 0; for (Task task : taskList) { - backpackLev ++; + backpackLev++; Code startCode = null; Code endCode = null; - Loc oriLoc = null; Loc destLoc = null; - Sta oriSta = null; Sta destSta = null; + Loc oriLoc = null; + Loc destLoc = null; + Sta oriSta = null; + Sta destSta = null; switch (Objects.requireNonNull(TaskTypeType.get(task.getTaskTypeEl()))) { case LOC_TO_LOC: oriLoc = locService.getById(task.getOriLoc()); @@ -398,7 +440,7 @@ // re-order by agv current position Code currCode = codeService.getCacheById(agvDetail.getRecentCode()); - Double[] currPosition = new Double[] {currCode.getX(), currCode.getY()}; + Double[] currPosition = new Double[]{currCode.getX(), currCode.getY()}; List<List<TaskPosDto>> pickGroups = new ArrayList<>(); List<List<TaskPosDto>> dropGroups = new ArrayList<>(); @@ -444,7 +486,7 @@ List<Segment> segmentList = new ArrayList<>(); for (List<TaskPosDto> dtoList : list) { for (TaskPosDto taskPosDto : dtoList) { - segSerial ++; + segSerial++; AgvBackpackType backpackType = AgvBackpackDto.find(backpackDtoList, taskPosDto.getTaskId()); assert null != backpackType; @@ -492,9 +534,12 @@ /** * 鍏呯數 鍥炲緟鏈轰綅浠诲姟 */ - @Transactional(propagation = Propagation.REQUIRES_NEW) // although there is a Transactional here that the lock is isolated, but we can't join the caller's Transactional + @Transactional(propagation = Propagation.REQUIRES_NEW) + // although there is a Transactional here that the lock is isolated, but we can't join the caller's Transactional public boolean buildMinorTask(Long agvId, TaskTypeType taskType, String destination, Jam jam) { - if (Cools.isEmpty(agvId, taskType)) { return false; } + if (Cools.isEmpty(agvId, taskType)) { + return false; + } try { String agvNo = agvService.getAgvNo(agvId); if (!agvService.judgeEnable(agvId)) { @@ -541,7 +586,7 @@ task.setAgvId(agvId); task.setUuid(String.valueOf(snowflakeIdWorker.nextId()).substring(3)); List<Task> lastTasks = taskService.list(new LambdaQueryWrapper<Task>().orderByDesc(Task::getId)); - task.setSeqNum(Utils.generateSeqNum(Cools.isEmpty(lastTasks)?null:lastTasks.get(0).getSeqNum())); + task.setSeqNum(Utils.generateSeqNum(Cools.isEmpty(lastTasks) ? null : lastTasks.get(0).getSeqNum())); task.setOriCode(agvDetail.getCode()); task.setDestCode(endCode.getId()); // lane @@ -549,7 +594,7 @@ if (null != destLane) { task.setDestLaneHash(destLane.getHashCode()); } - task.setPriority(taskType.equals(TaskTypeType.TO_CHARGE)?2:1); + task.setPriority(taskType.equals(TaskTypeType.TO_CHARGE) ? 2 : 1); task.setTaskSts(TaskStsType.ASSIGN.val()); task.setTaskType(taskType.val()); task.setIoTime(now); @@ -571,11 +616,12 @@ } // generate segment - int segSerial = 0; segSerial ++; + int segSerial = 0; + segSerial++; List<Segment> segmentList = new ArrayList<>(); String posType = ""; - switch (taskType){ + switch (taskType) { case TO_CHARGE: posType = TaskPosDto.PosType.TO_CHARGE.toString(); break; @@ -647,7 +693,9 @@ @Transactional public synchronized void generateAction(Long agvId, List<Segment> segmentList, List<String> pathList, Date algoStartTime) { try { - if (Cools.isEmpty(agvId, segmentList)) { return; } + if (Cools.isEmpty(agvId, segmentList)) { + return; + } Date now = new Date(); long actionPrepareSts = ActionStsType.PREPARE.val(); // JSONObject storeDirection = configService.getVal("storeDirection", JSONObject.class); @@ -689,7 +737,9 @@ List<String> pathListPart = pathList.subList(pathList.indexOf(lastCode.getData()), pathList.indexOf(code.getData()) + 1); for (int i = 0; i < pathListPart.size(); i++) { - if (i == 0) { continue; } + if (i == 0) { + continue; + } String next = pathListPart.get(i); @@ -821,6 +871,7 @@ // 浣滀笟鐐瑰姩浣� AgvDirectionType agvDirectionType; + Double staWorkDirection; AgvBackpackType backpackType = AgvBackpackType.query(segment.getBackpack()); switch (Objects.requireNonNull(TaskPosDto.queryPosType(segment.getPosType()))) { case ORI_LOC: @@ -828,28 +879,11 @@ // 妫�楠屾柟鍚� if (!lastDirection.equals(workDirection)) { throw new CoolException(agvNo + "鍙峰皬杞︽柟鍚戦敊璇紝璇锋帹鑷宠浆寮偣鎵嬪姩璋冩暣"); - // turn -// actionList.add(new Action( -// null, // 缂栧彿 -// task.getBusId(), // 鎬荤嚎 -// task.getId(), // 浠诲姟 -// null, // 鍔ㄤ綔鍙� -// null, // 浼樺厛绾� -// ActionTypeType.TurnCorner.desc, // 鍚嶇О -// mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D, // 灞炴�у�� -// lastCode.getData(), // 鍦伴潰鐮� -// String.valueOf(workDirection), // 鍔ㄤ綔鍙傛暟 -// ActionTypeType.TurnCorner.val(), // 鍔ㄤ綔绫诲瀷 -// actionPrepareSts, // 鍔ㄤ綔杩涘害 -// agvId, // AGV -// now // 宸ヤ綔鏃堕棿 -// )); -// lastDirection = workDirection; } // 璐ф灦鍙栬揣 Loc oriLoc = locService.getById(task.getOriLoc()); // 璁$畻宸﹀彸鏂瑰悜 - agvDirectionType = mapService.calculateAgvWorkDirection(oriLoc, lastCode); + agvDirectionType = mapService.calculateAgvWorkDirectionByShelf(oriLoc, lastCode); actionList.add(new Action( null, // 缂栧彿 task.getBusId(), // 鎬荤嚎 @@ -887,23 +921,6 @@ // 妫�楠屾柟鍚� if (!lastDirection.equals(workDirection)) { throw new CoolException(agvNo + "鍙峰皬杞︽柟鍚戦敊璇紝璇锋帹鑷宠浆寮偣鎵嬪姩璋冩暣"); -// // turn -// actionList.add(new Action( -// null, // 缂栧彿 -// task.getBusId(), // 鎬荤嚎 -// task.getId(), // 浠诲姟 -// null, // 鍔ㄤ綔鍙� -// null, // 浼樺厛绾� -// ActionTypeType.TurnCorner.desc, // 鍚嶇О -// mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D, // 灞炴�у�� -// lastCode.getData(), // 鍦伴潰鐮� -// String.valueOf(workDirection), // 鍔ㄤ綔鍙傛暟 -// ActionTypeType.TurnCorner.val(), // 鍔ㄤ綔绫诲瀷 -// actionPrepareSts, // 鍔ㄤ綔杩涘害 -// agvId, // AGV -// now // 宸ヤ綔鏃堕棿 -// )); -// lastDirection = workDirection; } // 鏆傚瓨鐐瑰彇璐ц揣 actionList.add(new Action( @@ -925,13 +942,13 @@ // 璐ф灦鏀捐揣 Loc destLoc = locService.getById(task.getDestLoc()); // 璁$畻宸﹀彸鏂瑰悜 - agvDirectionType = mapService.calculateAgvWorkDirection(destLoc, lastCode); + agvDirectionType = mapService.calculateAgvWorkDirectionByShelf(destLoc, lastCode); actionList.add(new Action( null, // 缂栧彿 task.getBusId(), // 鎬荤嚎 task.getId(), // 浠诲姟 null, // 鍔ㄤ綔鍙� - null, // 浼樺厛绾� + null, // 浼樺厛绾� ActionTypeType.ReadyReleaseToShelvesLoc.desc, // 鍚嶇О (double) agvDirectionType.val, // 灞炴�у�� lastCode.getData(), // 鍦伴潰鐮� @@ -943,8 +960,128 @@ )); break; case ORI_STA: + // 绔欑偣鍙栬揣 + Sta oriSta = staService.getById(task.getOriSta()); + Double oriStaWorkDirection = mapService.getStaAngle(oriSta, workDirection); + // 妫�楠屾柟鍚� + if (!lastDirection.equals(oriStaWorkDirection)) { + if (!lastCode.getCornerBool()) { + throw new CoolException(agvNo + "鍙峰皬杞︽柟鍚戦敊璇紝璇锋帹鑷宠浆寮偣鎵嬪姩璋冩暣"); + } + // turn + actionList.add(new Action( + null, // 缂栧彿 + task.getBusId(), // 鎬荤嚎 + task.getId(), // 浠诲姟 + null, // 鍔ㄤ綔鍙� + null, // 浼樺厛绾� + ActionTypeType.TurnCorner.desc, // 鍚嶇О + mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D, // 灞炴�у�� + lastCode.getData(), // 鍦伴潰鐮� + String.valueOf(oriStaWorkDirection), // 鍔ㄤ綔鍙傛暟 + ActionTypeType.TurnCorner.val(), // 鍔ㄤ綔绫诲瀷 + actionPrepareSts, // 鍔ㄤ綔杩涘害 + agvId, // AGV + now // 宸ヤ綔鏃堕棿 + )); + lastDirection = oriStaWorkDirection; + } + // 璁$畻璐у弶宸ヤ綔鏂瑰悜 + staWorkDirection = mapService.calculateAgvWorkDirectionByStation(oriStaWorkDirection, lastDirection); + actionList.add(new Action( + null, // 缂栧彿 + task.getBusId(), // 鎬荤嚎 + task.getId(), // 浠诲姟 + null, // 鍔ㄤ綔鍙� + null, // 浼樺厛绾� + ActionTypeType.ReadyTakeFromConveyorSta.desc, // 鍚嶇О + staWorkDirection, // 灞炴�у�� + lastCode.getData(), // 鍦伴潰鐮� + String.valueOf(oriSta.getOffset()), // 鍔ㄤ綔鍙傛暟 + ActionTypeType.ReadyTakeFromConveyorSta.val(), // 鍔ㄤ綔绫诲瀷 + actionPrepareSts, // 鍔ㄤ綔杩涘害 + agvId, // AGV + now // 宸ヤ綔鏃堕棿 + )); + // 鏆傚瓨鐐规斁璐� + assert backpackType != null; + actionList.add(new Action( + null, // 缂栧彿 + task.getBusId(), // 鎬荤嚎 + task.getId(), // 浠诲姟 + null, // 鍔ㄤ綔鍙� + null, // 浼樺厛绾� + ActionTypeType.ReadyReleaseToAgvSite.desc, // 鍚嶇О + (double) backpackType.lev, // 灞炴�у�� + lastCode.getData(), // 鍦伴潰鐮� + String.valueOf(backpackType.height), // 鍔ㄤ綔鍙傛暟 + ActionTypeType.ReadyReleaseToAgvSite.val(), // 鍔ㄤ綔绫诲瀷 + actionPrepareSts, // 鍔ㄤ綔杩涘害 + agvId, // AGV + now // 宸ヤ綔鏃堕棿 + )); break; case DEST_STA: + // 绔欑偣鏀捐揣 + Sta destSta = staService.getById(task.getDestSta()); + Double destStaWorkDirection = mapService.getStaAngle(destSta, workDirection); + // 妫�楠屾柟鍚� + if (!lastDirection.equals(destStaWorkDirection)) { + if (!lastCode.getCornerBool()) { + throw new CoolException(agvNo + "鍙峰皬杞︽柟鍚戦敊璇紝璇锋帹鑷宠浆寮偣鎵嬪姩璋冩暣"); + } + // turn + actionList.add(new Action( + null, // 缂栧彿 + task.getBusId(), // 鎬荤嚎 + task.getId(), // 浠诲姟 + null, // 鍔ㄤ綔鍙� + null, // 浼樺厛绾� + ActionTypeType.TurnCorner.desc, // 鍚嶇О + mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D, // 灞炴�у�� + lastCode.getData(), // 鍦伴潰鐮� + String.valueOf(destStaWorkDirection), // 鍔ㄤ綔鍙傛暟 + ActionTypeType.TurnCorner.val(), // 鍔ㄤ綔绫诲瀷 + actionPrepareSts, // 鍔ㄤ綔杩涘害 + agvId, // AGV + now // 宸ヤ綔鏃堕棿 + )); + lastDirection = destStaWorkDirection; + } + // 鏆傚瓨鐐瑰彇璐� + assert backpackType != null; + actionList.add(new Action( + null, // 缂栧彿 + task.getBusId(), // 鎬荤嚎 + task.getId(), // 浠诲姟 + null, // 鍔ㄤ綔鍙� + null, // 浼樺厛绾� + ActionTypeType.ReadyTakeFromAgvSite.desc, // 鍚嶇О + (double) backpackType.lev, // 灞炴�у�� + lastCode.getData(), // 鍦伴潰鐮� + String.valueOf(backpackType.height), // 鍔ㄤ綔鍙傛暟 + ActionTypeType.ReadyTakeFromAgvSite.val(), // 鍔ㄤ綔绫诲瀷 + actionPrepareSts, // 鍔ㄤ綔杩涘害 + agvId, // AGV + now // 宸ヤ綔鏃堕棿 + )); + // 璁$畻璐у弶宸ヤ綔鏂瑰悜 + staWorkDirection = mapService.calculateAgvWorkDirectionByStation(destStaWorkDirection, lastDirection); + actionList.add(new Action( + null, // 缂栧彿 + task.getBusId(), // 鎬荤嚎 + task.getId(), // 浠诲姟 + null, // 鍔ㄤ綔鍙� + null, // 浼樺厛绾� + ActionTypeType.ReadyReleaseToConveyorSta.desc, // 鍚嶇О + staWorkDirection, // 灞炴�у�� + lastCode.getData(), // 鍦伴潰鐮� + String.valueOf(destSta.getOffset()), // 鍔ㄤ綔鍙傛暟 + ActionTypeType.ReadyReleaseToConveyorSta.val(), // 鍔ㄤ綔绫诲瀷 + actionPrepareSts, // 鍔ㄤ綔杩涘害 + agvId, // AGV + now // 宸ヤ綔鏃堕棿 + )); break; case TO_CHARGE: // 妫�楠屾柟鍚� @@ -1088,6 +1225,13 @@ if (Cools.isEmpty(actionList)) { return; } + + Long agvId = actionList.get(0).getAgvId(); + String agvNo = agvService.getAgvNo(agvId); + if (!agvService.judgeOnline(agvId)) { + return; + } + long actionIssuedSts = ActionStsType.ISSUED.val(); for (Action action : actionList) { action.setActionSts(actionIssuedSts); @@ -1114,10 +1258,8 @@ } } - String agvNo = agvService.getAgvNo(actionList.get(0).getAgvId()); AgvAction agvAction = new AgvAction(agvNo, actionGroupId); for (Action action : actionList) { - switch (Objects.requireNonNull(ActionTypeType.get(action.getActionTypeEl()))) { case TurnCorner: agvAction.add(new AgvActionItem<>(TurnCornerAction.class) @@ -1151,6 +1293,13 @@ .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams()))) ); break; + case ReadyTakeFromConveyorSta: + agvAction.add(new AgvActionItem<>(ReadyTakeFromConveyorSta.class) + .setVal(action.getVal().intValue()) + .setQrCode(action.getCode()) + .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams()))) + ); + break; case ReadyTakeFromAgvSite: agvAction.add(new AgvActionItem<>(ReadyTakeFromAgvSite.class) .setVal(action.getVal().intValue()) @@ -1160,6 +1309,13 @@ break; case ReadyReleaseToShelvesLoc: agvAction.add(new AgvActionItem<>(ReadyReleaseToShelvesLoc.class) + .setVal(action.getVal().intValue()) + .setQrCode(action.getCode()) + .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams()))) + ); + break; + case ReadyReleaseToConveyorSta: + agvAction.add(new AgvActionItem<>(ReadyReleaseToConveyorSta.class) .setVal(action.getVal().intValue()) .setQrCode(action.getCode()) .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams()))) @@ -1293,9 +1449,9 @@ // segment list List<Segment> segmentList = segmentService.list(new LambdaQueryWrapper<Segment>() - .eq(Segment::getGroupId, serialNo) + .eq(Segment::getGroupId, serialNo) // .eq(Segment::getState, SegmentStateType.RUNNING.toString()) - .orderByAsc(Segment::getSerial) + .orderByAsc(Segment::getSerial) ); // settlement @@ -1325,8 +1481,10 @@ for (Segment segment : segmentList) { boolean taskComplete = false; - Task task = taskService.getById(segment.getTaskId()); assert null != task; - TaskTypeType typeType = TaskTypeType.get(task.getTaskTypeEl()); assert null != typeType; + Task task = taskService.getById(segment.getTaskId()); + assert null != task; + TaskTypeType typeType = TaskTypeType.get(task.getTaskTypeEl()); + assert null != typeType; TaskPosDto.PosType posType = TaskPosDto.queryPosType(segment.getPosType()); switch (Objects.requireNonNull(posType)) { -- Gitblit v1.9.1