From d58a5160d46bd0f83fdd73e9e49061b33e1d241b Mon Sep 17 00:00:00 2001
From: vincentlu <t1341870251@gmail.com>
Date: 星期四, 15 一月 2026 15:21:50 +0800
Subject: [PATCH] #
---
zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/MissionServiceImpl.java | 108 +++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 95 insertions(+), 13 deletions(-)
diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/MissionServiceImpl.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/MissionServiceImpl.java
index 6634b81..25c6b9b 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/MissionServiceImpl.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/MissionServiceImpl.java
@@ -2,14 +2,14 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.acs.framework.common.Cools;
+import com.zy.acs.framework.exception.CoolException;
import com.zy.acs.manager.common.exception.BusinessException;
+import com.zy.acs.manager.core.service.MapService;
import com.zy.acs.manager.manager.controller.result.MissionVo;
import com.zy.acs.manager.manager.entity.*;
-import com.zy.acs.manager.manager.enums.ActionStsType;
-import com.zy.acs.manager.manager.enums.BusStsType;
-import com.zy.acs.manager.manager.enums.SegmentStateType;
-import com.zy.acs.manager.manager.enums.TaskStsType;
+import com.zy.acs.manager.manager.enums.*;
import com.zy.acs.manager.manager.service.*;
+import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -35,6 +35,8 @@
private TaskService taskService;
@Autowired
private BusService busService;
+ @Autowired
+ private SqlSession sqlSession;
@Override
public List<MissionVo> getList(Long agvId, String groupNo) {
@@ -67,12 +69,18 @@
Long recentCode = agvDetail.getRecentCode();
String currCode = null;
if (null != recentCode) {
- currCode = codeService.getById(recentCode).getData();
+ Code cacheById = codeService.getCacheById(recentCode);
+ if (cacheById != null) {
+ currCode = cacheById.getData();
+ } else {
+ throw new CoolException(segment.getAgvId() + "灏忚溅杩樺湪鍒犻櫎鐨勭偣浣嶄腑");
+ }
+
}
// action -------------------------------
List<Action> actionList = actionService.list(new LambdaQueryWrapper<Action>()
- .eq(Action::getGroupId, groupNo).orderByDesc(Action::getPriority));
+ .eq(Action::getGroupId, groupNo).ne(Action::getActionSts, ActionStsType.EXPIRED.val()).orderByDesc(Action::getPriority));
if (Cools.isEmpty(actionList)) {
return null;
}
@@ -101,7 +109,7 @@
return null;
}
List<Action> actionList = actionService.list(new LambdaQueryWrapper<Action>()
- .eq(Action::getGroupId, groupNo).orderByDesc(Action::getPriority));
+ .eq(Action::getGroupId, groupNo).ne(Action::getActionSts, ActionStsType.EXPIRED.val()).orderByDesc(Action::getPriority));
if (Cools.isEmpty(actionList)) {
return null;
}
@@ -124,12 +132,85 @@
if (Cools.isEmpty(actionList)) {
return Boolean.FALSE;
}
- String actionGroupId = actionService.getById(actionList.get(0).getId()).getGroupId();
- actionService.updateStsByGroupId(actionGroupId, ActionStsType.EXPIRED.val());
- List<Action> newActionList = new ArrayList<>();
Date now = new Date();
- for (Action item : actionList) {
- Action action = actionService.getById(item.getId());
+
+ List<Long> actionIds = actionList.stream().map(Action::getId).collect(Collectors.toList());
+ Action firstAction = actionService.getById(actionIds.get(0));
+ if (firstAction == null) {
+ return Boolean.FALSE;
+ }
+
+ String actionGroupId = firstAction.getGroupId();
+ actionService.updateStsByGroupId(actionGroupId, ActionStsType.EXPIRED.val());
+
+ // if firstAction is not turn, insert a new turn action
+ Action prependTurn = null;
+ if (!firstAction.getActionType().equals(ActionTypeType.TurnCorner.val())) {
+ String codeData = firstAction.getCode();
+ Code code = codeService.getCacheByData(codeData);
+ AgvDetail agvDetail = agvDetailService.selectMajorByAgvId(firstAction.getAgvId());
+ Double lastDirection = MapService.mapToNearest(agvDetail.getAgvAngle());
+
+ List<Action> fullActionList = actionService.list(new LambdaQueryWrapper<Action>()
+ .eq(Action::getGroupId, actionGroupId)
+ .select(Action::getId, Action::getActionType, Action::getPriority)
+ .orderByDesc(Action::getPriority)
+ );
+
+ int idx = -1;
+ for (int k = 0; k < fullActionList.size(); k++) {
+ if (fullActionList.get(k).getId().equals(firstAction.getId())) {
+ idx = k;
+ break;
+ }
+ }
+
+ if (idx > 0) {
+ Long turnActionId = null;
+ // find out turn action
+ for (int k = idx - 1; k >= 0; k--) {
+ Action a = fullActionList.get(k);
+ if (a.getActionType().equals(ActionTypeType.TurnCorner.val())) {
+ turnActionId = a.getId();
+ break;
+ }
+ }
+
+
+ if (null != turnActionId) {
+ Action turn = actionService.getById(turnActionId);
+ Double direction = Double.parseDouble(turn.getParams());
+ // new turn action
+ prependTurn = new Action(
+ null, // 缂栧彿
+ firstAction.getBusId(), // 鎬荤嚎
+ firstAction.getTaskId(), // 浠诲姟
+ null, // 鍔ㄤ綔鍙�
+ null, // 浼樺厛绾�
+ ActionTypeType.TurnCorner.desc, // 鍚嶇О
+ (double) MapService.calcSpinDirection(code, lastDirection, direction).val, // 灞炴�у��
+ code.getData(), // 鍦伴潰鐮�
+ String.valueOf(direction), // 鍔ㄤ綔鍙傛暟
+ ActionTypeType.TurnCorner.val(), // 鍔ㄤ綔绫诲瀷
+ ActionStsType.PREPARE.val(), // 鍔ㄤ綔杩涘害
+ firstAction.getAgvId(), // AGV
+ now // 宸ヤ綔鏃堕棿
+ );
+ }
+
+ }
+ }
+
+ List<Action> newActionList = new ArrayList<>();
+ if (prependTurn != null) {
+ prependTurn.setGroupId(actionGroupId);
+ prependTurn.setCreateTime(now);
+ prependTurn.setUpdateTime(now);
+ newActionList.add(prependTurn);
+ }
+ for (Long actionId : actionIds) {
+ sqlSession.clearCache();
+ Action action = actionService.getById(actionId);
action.setActionSts(ActionStsType.PREPARE.val());
action.setIoTime(now);
action.setUpdateTime(now);
@@ -137,9 +218,10 @@
}
int i = newActionList.size();
for (Action action : newActionList) {
+ action.setId(null);
action.setPriority(i);
if (!actionService.save(action)) {
- throw new BusinessException(action.getName() + " Action Update Fail!");
+ throw new BusinessException(action.getName() + " Action Save Fail!");
}
i -= 1;
}
--
Gitblit v1.9.1