From 4c9169967a879b54c04b0754ab9830a5a6baa708 Mon Sep 17 00:00:00 2001
From: vincentlu <t1341870251@gmail.com>
Date: 星期二, 18 三月 2025 14:30:48 +0800
Subject: [PATCH] #
---
zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java | 211 ++++++++++++++++++++++++++++++++--------------------
1 files changed, 128 insertions(+), 83 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 aa06289..7cf12fb 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
@@ -1,7 +1,6 @@
package com.zy.acs.manager.core.service;
import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.acs.common.domain.AgvAction;
import com.zy.acs.common.domain.AgvActionItem;
@@ -32,6 +31,7 @@
import com.zy.acs.manager.manager.enums.*;
import com.zy.acs.manager.manager.service.*;
import com.zy.acs.manager.manager.service.impl.WebsocketServiceImpl;
+import com.zy.acs.manager.manager.utils.ActionSorter;
import com.zy.acs.manager.system.service.ConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -94,6 +94,8 @@
private AgvModelService agvModelService;
@Autowired
private LaneService laneService;
+ @Autowired
+ private ActionSorter actionSorter;
@SuppressWarnings("all")
@@ -248,9 +250,8 @@
try {
// valid -----------------------------------------------
Agv agv = agvService.getById(agvId);
- if (!agvService.judgeEnable(agv.getId(), true)) {
+ if (!agvService.judgeEnable(agv.getId(), false)) {
return;
-// throw new CoolException("AGV[" + agv.getUuid() + "]褰撳墠涓嶅彲鐢�...");
}
if (!Cools.isEmpty(taskService.selectInSts(agvId, TaskStsType.ASSIGN, TaskStsType.PROGRESS))) {
throw new CoolException("AGV[" + agv.getUuid() + "]鍒嗛厤浠诲姟澶辫触锛屽凡瀛樺湪鎵ц浠诲姟...");
@@ -300,8 +301,8 @@
oriLoc = locService.getById(task.getOriLoc());
destLoc = locService.getById(task.getDestLoc());
- startCode = codeService.getById(oriLoc.getCode());
- endCode = codeService.getById(destLoc.getCode());
+ startCode = codeService.getCacheById(oriLoc.getCode());
+ endCode = codeService.getCacheById(destLoc.getCode());
TaskPosDto.packagePosGroup(groups, task, startCode, TaskPosDto.PosType.ORI_LOC, sameGroupXy);
TaskPosDto.packagePosGroup(groups, task, endCode, TaskPosDto.PosType.DEST_LOC, sameGroupXy);
@@ -310,8 +311,8 @@
oriLoc = locService.getById(task.getOriLoc());
destSta = staService.getById(task.getDestSta());
- startCode = codeService.getById(oriLoc.getCode());
- endCode = codeService.getById(destSta.getCode());
+ startCode = codeService.getCacheById(oriLoc.getCode());
+ endCode = codeService.getCacheById(destSta.getCode());
TaskPosDto.packagePosGroup(groups, task, startCode, TaskPosDto.PosType.ORI_LOC, sameGroupXy);
TaskPosDto.packagePosGroup(groups, task, endCode, TaskPosDto.PosType.DEST_STA, sameGroupXy);
@@ -320,8 +321,8 @@
oriSta = staService.getById(task.getOriSta());
destLoc = locService.getById(task.getDestLoc());
- startCode = codeService.getById(oriSta.getCode());
- endCode = codeService.getById(destLoc.getCode());
+ startCode = codeService.getCacheById(oriSta.getCode());
+ endCode = codeService.getCacheById(destLoc.getCode());
TaskPosDto.packagePosGroup(groups, task, startCode, TaskPosDto.PosType.ORI_STA, sameGroupXy);
TaskPosDto.packagePosGroup(groups, task, endCode, TaskPosDto.PosType.DEST_LOC, sameGroupXy);
@@ -330,8 +331,8 @@
oriSta = staService.getById(task.getOriSta());
destSta = staService.getById(task.getDestSta());
- startCode = codeService.getById(oriSta.getCode());
- endCode = codeService.getById(destSta.getCode());
+ startCode = codeService.getCacheById(oriSta.getCode());
+ endCode = codeService.getCacheById(destSta.getCode());
TaskPosDto.packagePosGroup(groups, task, startCode, TaskPosDto.PosType.ORI_STA, sameGroupXy);
TaskPosDto.packagePosGroup(groups, task, endCode, TaskPosDto.PosType.DEST_STA, sameGroupXy);
@@ -396,7 +397,7 @@
}
// re-order by agv current position
- Code currCode = codeService.getById(agvDetail.getRecentCode());
+ Code currCode = codeService.getCacheById(agvDetail.getRecentCode());
Double[] currPosition = new Double[] {currCode.getX(), currCode.getY()};
List<List<TaskPosDto>> pickGroups = new ArrayList<>();
@@ -473,6 +474,7 @@
// task
for (Task task : taskList) {
task.setTaskSts(TaskStsType.ASSIGN.val());
+ task.setStartTime(now);
task.setUpdateTime(now);
if (!taskService.updateById(task)) {
throw new BusinessException(task.getUuid() + "浠诲姟鏇存柊澶辫触");
@@ -491,37 +493,38 @@
* 鍏呯數 鍥炲緟鏈轰綅浠诲姟
*/
@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(Agv agv, TaskTypeType taskType, String destination, Jam jam) {
- if (Cools.isEmpty(agv, taskType)) { return false; }
+ public boolean buildMinorTask(Long agvId, TaskTypeType taskType, String destination, Jam jam) {
+ if (Cools.isEmpty(agvId, taskType)) { return false; }
try {
- AgvDetail agvDetail = agvDetailService.selectByAgvId(agv.getId());
- if (!agvService.judgeEnable(agv.getId())) {
+ String agvNo = agvService.getAgvNo(agvId);
+ if (!agvService.judgeEnable(agvId)) {
return false;
}
- if (!Cools.isEmpty(taskService.selectInSts(agv.getId(), TaskStsType.ASSIGN, TaskStsType.PROGRESS))) {
- throw new CoolException("AGV[" + agv.getUuid() + "] failed to assign锛宐ecause already has the task in running...");
+ if (!Cools.isEmpty(taskService.selectInSts(agvId, TaskStsType.ASSIGN, TaskStsType.PROGRESS))) {
+ throw new CoolException("AGV[" + agvNo + "] failed to assign锛宐ecause already has the task in running...");
}
- if (!Cools.isEmpty(segmentService.getByAgvAndState(agv.getId(), SegmentStateType.WAITING.toString()))
- || !Cools.isEmpty(segmentService.getByAgvAndState(agv.getId(), SegmentStateType.RUNNING.toString()))) {
- throw new CoolException("AGV[" + agv.getUuid() + "] failed to assign锛宐ecause already has the segment in running...");
+ if (!Cools.isEmpty(segmentService.getByAgvAndState(agvId, SegmentStateType.WAITING.toString()))
+ || !Cools.isEmpty(segmentService.getByAgvAndState(agvId, SegmentStateType.RUNNING.toString()))) {
+ throw new CoolException("AGV[" + agvNo + "] failed to assign锛宐ecause already has the segment in running...");
}
Date now = new Date();
+ AgvDetail agvDetail = agvDetailService.selectMajorByAgvId(agvId);
Code endCode = null;
switch (taskType) {
case TO_CHARGE:
case TO_STANDBY:
- List<FuncSta> idleFunStaList = funcStaService.findInIdleStatus(FuncStaType.query(taskType), agv.getId());
+ List<FuncSta> idleFunStaList = funcStaService.findInIdleStatus(FuncStaType.query(taskType), agvId);
if (!Cools.isEmpty(idleFunStaList)) {
FuncSta funcSta = funcStaService.checkoutClosestFunSta(agvDetail.getRecentCode(), idleFunStaList);
- endCode = codeService.getById(funcSta.getCode());
+ endCode = codeService.getCacheById(funcSta.getCode());
}
if (null == endCode) {
- log.warn("AGV[{}] failed to search destination锛宼here hadn't any idle funSta锛孴askTypeType锛歿}", agv.getUuid(), taskType.toString());
+ log.warn("AGV[{}] failed to search destination锛宼here hadn't any idle funSta锛孴askTypeType锛歿}", agvNo, taskType.toString());
}
break;
case MOVE:
- endCode = codeService.selectByData(destination);
+ endCode = codeService.getCacheByData(destination);
break;
default:
return false;
@@ -530,12 +533,12 @@
if (null == endCode) {
return false;
}
- if (!allocateService.validCapacityOfLane(agv, endCode)) {
- throw new BusinessException("the lane with code:" + endCode.getData() + " is full of AGV[" + agv.getUuid() + "]!!!");
+ if (!allocateService.validCapacityOfLane(agvNo, endCode)) {
+ throw new BusinessException("the lane with code:" + endCode.getData() + " is full of AGV[" + agvNo + "]!!!");
}
Task task = new Task();
- task.setAgvId(agv.getId());
+ 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()));
@@ -559,7 +562,7 @@
Travel travel = new Travel();
travel.setUuid(String.valueOf(snowflakeIdWorker.nextId()).substring(3));
travel.setTravelId(String.valueOf(snowflakeIdWorker.nextId()).substring(3));
- travel.setAgvId(agv.getId());
+ travel.setAgvId(agvId);
// travel.setTaskContent(JSON.toJSONString(list));
travel.setTaskIds(GsonUtils.toJson(Utils.singletonList(task.getId())));
travel.setState(TravelStateType.RUNNING.toString());
@@ -589,7 +592,7 @@
Segment segment = new Segment();
segment.setUuid(String.valueOf(snowflakeIdWorker.nextId()).substring(3));
segment.setTravelId(travel.getId());
- segment.setAgvId(agv.getId());
+ segment.setAgvId(agvId);
segment.setTaskId(task.getId());
segment.setSerial(segSerial);
segment.setEndNode(endCode.getId());
@@ -642,30 +645,31 @@
* 鏍规嵁鍒嗙墖鐢熸垚鍔ㄤ綔 ( 杞﹁締鍙兘宸茬粡鍋氳繃涓�浜涗换鍔′簡,姝e湪绛夊緟涓嬩竴娈典换鍔� )
*/
@Transactional
- public synchronized void generateAction(Long agvId, List<Segment> segmentList, List<String> pathList) {
+ public synchronized void generateAction(Long agvId, List<Segment> segmentList, List<String> pathList, Date algoStartTime) {
try {
if (Cools.isEmpty(agvId, segmentList)) { return; }
Date now = new Date();
- JSONObject storeDirection = configService.getVal("storeDirection", JSONObject.class);
- Agv agv = agvService.getById(agvId);
- if (!agvService.judgeEnable(agv.getId())) {
- throw new CoolException("AGV[" + agv.getUuid() + "]褰撳墠涓嶅彲鐢�...");
- }
+ long actionPrepareSts = ActionStsType.PREPARE.val();
+// JSONObject storeDirection = configService.getVal("storeDirection", JSONObject.class);
+ int angleOffsetVal = configService.getVal("mapAngleOffsetVal", Integer.class);
+ String agvNo = agvService.getAgvNo(agvId);
+// if (!agvService.judgeEnable(agvId)) {
+// throw new CoolException("AGV[" + agvNo + "]褰撳墠涓嶅彲鐢�...");
+// }
- AgvModel agvModel = agvModelService.getById(agv.getAgvModel());
+ AgvModel agvModel = agvModelService.getByAgvId(agvId);
Double workDirection = agvModel.getWorkDirection();
AgvSpeedType agvSpeedType = AgvSpeedType.query(agvModel.getTravelSpeed());
assert agvSpeedType != null;
- AgvDetail agvDetail = agvDetailService.selectByAgvId(agvId);
- assert agvDetail != null;
+ AgvDetail agvDetail = agvDetailService.selectMajorByAgvId(agvId);
List<Action> actionList = new ArrayList<>();
// start node
- Code lastCode = codeService.getById(agvDetail.getRecentCode());
+ Code lastCode = codeService.getCacheById(agvDetail.getRecentCode());
Double lastDirection = agvDetail.getAgvAngle();
if (!lastCode.getData().equals(pathList.get(0))) {
- throw new CoolException("AGV[" + agv.getUuid() + "]瀹氫綅鍋忕Щ...");
+ throw new CoolException("AGV[" + agvNo + "]瀹氫綅鍋忕Щ...");
}
boolean first = true;
@@ -675,7 +679,7 @@
Task task = taskService.getById(segment.getTaskId());
// 鑺傜偣鏉$爜
- Code code = codeService.getById(segment.getEndNode());
+ Code code = codeService.getCacheById(segment.getEndNode());
// 闇�瑕佽蛋琛�
if (!lastCode.getData().equals(code.getData())) {
@@ -689,15 +693,57 @@
String next = pathListPart.get(i);
- Code nextCode = codeService.selectByData(next);
- Double nextDirection = mapService.calculateDirection(lastCode, nextCode);
+ Code nextCode = codeService.getCacheByData(next);
+ Double nextDirection = mapService.calculateDirection(lastCode, nextCode, angleOffsetVal);
+ // 绗竴姝ワ細濡傛灉涓嬩竴涓柟鍚戞濂芥槸浣滀笟鏂瑰悜鐨勭浉鍙嶆柟鍚戯紝鍒欓噸缃笅涓�涓柟鍚戜负浣滀笟鏂瑰悜锛屾爣璁皉everse
boolean reverse = false;
if (nextDirection.equals((workDirection + 180) % 360)) {
nextDirection = workDirection;
reverse = true;
}
- if (!lastDirection.equals(nextDirection) || actionList.size() == 0) {
+
+ // 绗簩姝ワ細鍒ゆ柇褰撳墠鑺傜偣鏄惁鍙互鏃嬭浆
+ if (!lastCode.getCornerBool()) {
+ // 濡傛灉鏄綔涓氭柟鍚戯紝浣嗘槸灏忚溅鍦ㄥ贩閬撳唴鏂瑰悜閿欒锛屽垯鍋滄
+ if (reverse && !lastDirection.equals(nextDirection)) {
+ throw new CoolException(agvNo + "鍙峰皬杞︽柟鍚戦敊璇紝璇锋帹鑷宠浆寮偣鎵嬪姩璋冩暣");
+ }
+ // 濡傛灉涓嶆槸浣滀笟鏂瑰悜锛屽垽鏂槸鍚︾浉鍙嶆柟鍚戯紝濡傛灉鍙嶆柟鍚戝垯鍊掗��琛岃蛋
+ if (nextDirection.equals((lastDirection + 180) % 360)) {
+ nextDirection = lastDirection;
+ reverse = true;
+ }
+ } else {
+ if (!lastDirection.equals(nextDirection)) {
+ if (nextDirection.equals((lastDirection + 180) % 360)) {
+ nextDirection = lastDirection;
+ reverse = true;
+ } else {
+ // turn
+ actionList.add(new Action(
+ null, // 缂栧彿s
+ task.getBusId(), // 鎬荤嚎
+ task.getId(), // 浠诲姟
+ null, // 鍔ㄤ綔鍙�
+ null, // 浼樺厛绾�
+ ActionTypeType.TurnCorner.desc, // 鍚嶇О
+ mapService.isTurnCorner(lastCode.getData()) ? 1D : 0D, // 灞炴�у��
+ lastCode.getData(), // 鍦伴潰鐮�
+ String.valueOf(nextDirection), // 鍔ㄤ綔鍙傛暟
+ ActionTypeType.TurnCorner.val(), // 鍔ㄤ綔绫诲瀷
+ actionPrepareSts, // 鍔ㄤ綔杩涘害
+ agvId, // AGV
+ now // 宸ヤ綔鏃堕棿
+ ));
+
+ lastDirection = nextDirection;
+ }
+ }
+ }
+
+ // 绗竴涓姩浣滀竴瀹氭槸 turn
+ if (actionList.isEmpty()) {
// turn
actionList.add(new Action(
null, // 缂栧彿
@@ -710,13 +756,12 @@
lastCode.getData(), // 鍦伴潰鐮�
String.valueOf(nextDirection), // 鍔ㄤ綔鍙傛暟
ActionTypeType.TurnCorner.val(), // 鍔ㄤ綔绫诲瀷
- ActionStsType.PREPARE.val(), // 鍔ㄤ綔杩涘害
+ actionPrepareSts, // 鍔ㄤ綔杩涘害
agvId, // AGV
now // 宸ヤ綔鏃堕棿
));
lastDirection = nextDirection;
-
}
// run
@@ -736,7 +781,7 @@
lastCode.getData(), // 鍦伴潰鐮�
String.valueOf(gap.getDistance()), // 鍔ㄤ綔鍙傛暟
actionType.val(), // 鍔ㄤ綔绫诲瀷
- ActionStsType.PREPARE.val(), // 鍔ㄤ綔杩涘害
+ actionPrepareSts, // 鍔ㄤ綔杩涘害
agvId, // AGV
now // 宸ヤ綔鏃堕棿
));
@@ -762,7 +807,7 @@
lastCode.getData(), // 鍦伴潰鐮�
String.valueOf(workDirection), // 鍔ㄤ綔鍙傛暟
ActionTypeType.TurnCorner.val(), // 鍔ㄤ綔绫诲瀷
- ActionStsType.PREPARE.val(), // 鍔ㄤ綔杩涘害
+ actionPrepareSts, // 鍔ㄤ綔杩涘害
agvId, // AGV
now // 宸ヤ綔鏃堕棿
));
@@ -793,7 +838,7 @@
lastCode.getData(), // 鍦伴潰鐮�
String.valueOf(workDirection), // 鍔ㄤ綔鍙傛暟
ActionTypeType.TurnCorner.val(), // 鍔ㄤ綔绫诲瀷
- ActionStsType.PREPARE.val(), // 鍔ㄤ綔杩涘害
+ actionPrepareSts, // 鍔ㄤ綔杩涘害
agvId, // AGV
now // 宸ヤ綔鏃堕棿
));
@@ -802,7 +847,7 @@
// 璐ф灦鍙栬揣
Loc oriLoc = locService.getById(task.getOriLoc());
// 璁$畻宸﹀彸鏂瑰悜
- agvDirectionType = mapService.calculateAgvWorkDirection(storeDirection, oriLoc, lastCode);
+ agvDirectionType = mapService.calculateAgvWorkDirection(oriLoc, lastCode);
actionList.add(new Action(
null, // 缂栧彿
task.getBusId(), // 鎬荤嚎
@@ -814,7 +859,7 @@
lastCode.getData(), // 鍦伴潰鐮�
String.valueOf(oriLoc.getOffset()), // 鍔ㄤ綔鍙傛暟
ActionTypeType.ReadyTakeFromShelvesLoc.val(), // 鍔ㄤ綔绫诲瀷
- ActionStsType.PREPARE.val(), // 鍔ㄤ綔杩涘害
+ actionPrepareSts, // 鍔ㄤ綔杩涘害
agvId, // AGV
now // 宸ヤ綔鏃堕棿
));
@@ -830,7 +875,7 @@
lastCode.getData(), // 鍦伴潰鐮�
String.valueOf(backpackType.height), // 鍔ㄤ綔鍙傛暟
ActionTypeType.ReadyReleaseToAgvSite.val(), // 鍔ㄤ綔绫诲瀷
- ActionStsType.PREPARE.val(), // 鍔ㄤ綔杩涘害
+ actionPrepareSts, // 鍔ㄤ綔杩涘害
agvId, // AGV
now // 宸ヤ綔鏃堕棿
));
@@ -851,7 +896,7 @@
lastCode.getData(), // 鍦伴潰鐮�
String.valueOf(workDirection), // 鍔ㄤ綔鍙傛暟
ActionTypeType.TurnCorner.val(), // 鍔ㄤ綔绫诲瀷
- ActionStsType.PREPARE.val(), // 鍔ㄤ綔杩涘害
+ actionPrepareSts, // 鍔ㄤ綔杩涘害
agvId, // AGV
now // 宸ヤ綔鏃堕棿
));
@@ -869,7 +914,7 @@
lastCode.getData(), // 鍦伴潰鐮�
String.valueOf(backpackType.height), // 鍔ㄤ綔鍙傛暟
ActionTypeType.ReadyTakeFromAgvSite.val(), // 鍔ㄤ綔绫诲瀷
- ActionStsType.PREPARE.val(), // 鍔ㄤ綔杩涘害
+ actionPrepareSts, // 鍔ㄤ綔杩涘害
agvId, // AGV
now // 宸ヤ綔鏃堕棿
));
@@ -877,7 +922,7 @@
// 璐ф灦鏀捐揣
Loc destLoc = locService.getById(task.getDestLoc());
// 璁$畻宸﹀彸鏂瑰悜
- agvDirectionType = mapService.calculateAgvWorkDirection(storeDirection, destLoc, lastCode);
+ agvDirectionType = mapService.calculateAgvWorkDirection(destLoc, lastCode);
actionList.add(new Action(
null, // 缂栧彿
task.getBusId(), // 鎬荤嚎
@@ -889,7 +934,7 @@
lastCode.getData(), // 鍦伴潰鐮�
String.valueOf(destLoc.getOffset()), // 鍔ㄤ綔鍙傛暟
ActionTypeType.ReadyReleaseToShelvesLoc.val(), // 鍔ㄤ綔绫诲瀷
- ActionStsType.PREPARE.val(), // 鍔ㄤ綔杩涘害
+ actionPrepareSts, // 鍔ㄤ綔杩涘害
agvId, // AGV
now // 宸ヤ綔鏃堕棿
));
@@ -914,7 +959,7 @@
lastCode.getData(), // 鍦伴潰鐮�
String.valueOf(chargeDirection), // 鍔ㄤ綔鍙傛暟
ActionTypeType.TurnCorner.val(), // 鍔ㄤ綔绫诲瀷
- ActionStsType.PREPARE.val(), // 鍔ㄤ綔杩涘害
+ actionPrepareSts, // 鍔ㄤ綔杩涘害
agvId, // AGV
now // 宸ヤ綔鏃堕棿
));
@@ -933,7 +978,7 @@
lastCode.getData(), // 鍦伴潰鐮�
null, // 鍔ㄤ綔鍙傛暟
ActionTypeType.DockingCharge.val(), // 鍔ㄤ綔绫诲瀷
- ActionStsType.PREPARE.val(), // 鍔ㄤ綔杩涘害
+ actionPrepareSts, // 鍔ㄤ綔杩涘害
agvId, // AGV
now // 宸ヤ綔鏃堕棿
));
@@ -953,7 +998,7 @@
// lastCode.getData(), // 鍦伴潰鐮�
// String.valueOf(standByDirection), // 鍔ㄤ綔鍙傛暟
// ActionTypeType.TurnCorner.val(), // 鍔ㄤ綔绫诲瀷
-// ActionStsType.PREPARE.val(), // 鍔ㄤ綔杩涘害
+// actionPrepareSts, // 鍔ㄤ綔杩涘害
// agvId, // AGV
// now // 宸ヤ綔鏃堕棿
// ));
@@ -980,30 +1025,24 @@
lastCode.getData(), // 鍦伴潰鐮�
null, // 鍔ㄤ綔鍙傛暟
ActionTypeType.FinishPath.val(), // 鍔ㄤ綔绫诲瀷
- ActionStsType.PREPARE.val(), // 鍔ㄤ綔杩涘害
+ actionPrepareSts, // 鍔ㄤ綔杩涘害
agvId, // AGV
now // 宸ヤ綔鏃堕棿
));
- List<Action> newActionList = new ArrayList<>(actionList);
-
-// List<Action> optimizeList = actionService.optimizeSort(actionList);
-
-// List<Action> newActionList = new ArrayList<>(optimizeList);
-
-
+ List<Action> newActionList = actionSorter.optimizeSort(actionList);
String groupId = String.valueOf(snowflakeIdWorker.nextId()).substring(3);
// save action
int i = newActionList.size();
for (Action action : newActionList) {
- action.setUuid(String.valueOf(snowflakeIdWorker.nextId()).substring(3));
+// action.setUuid(String.valueOf(snowflakeIdWorker.nextId()).substring(3));
action.setGroupId(groupId);
action.setPriority(i);
- if (!actionService.save(action)) {
- throw new BusinessException(action.getName() + "鍔ㄤ綔淇濆瓨澶辫触");
- }
i -= 1;
+ }
+ if (!actionService.saveBatch(newActionList)) {
+ throw new BusinessException("group[" + groupId + "] 鍔ㄤ綔淇濆瓨澶辫触");
}
// update segment
@@ -1011,19 +1050,23 @@
item.setGroupId(groupId);
item.setState(SegmentStateType.RUNNING.toString());
item.setUpdateTime(now);
+ if (null != algoStartTime) {
+ item.setAlgoTime((int) (now.getTime() - algoStartTime.getTime()));
+ }
if (!segmentService.updateById(item)) {
throw new CoolException("鏇存柊Segment澶辫触");
}
}
- log.info(agv.getUuid() + "鍙稟gv鍔ㄤ綔缁勮瀹屾垚锛屾寚浠ゆ暟閲忥細" + newActionList.size());
+ log.info("{}鍙稟gv鍔ㄤ綔缁勮瀹屾垚锛屾寚浠ゆ暟閲忥細{}", agvNo, newActionList.size());
} catch (Exception e) {
log.error("mainService.generateAction", e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
if (!Cools.isEmpty(pathList)) {
pathList.remove(0);
- mapDataDispatcher.clearDynamicMatrixByCodeList(null, pathList);
+ List<int[]> codeMatrixIdxList = mapDataDispatcher.getCodeMatrixIdxList(null, pathList);
+ mapDataDispatcher.clearDynamicMatrixByCodeList(null, codeMatrixIdxList);
}
throw new RuntimeException("generateAction method caught an exception, rolling back transaction.", e);
@@ -1042,22 +1085,25 @@
if (Cools.isEmpty(actionList)) {
return;
}
+ long actionIssuedSts = ActionStsType.ISSUED.val();
for (Action action : actionList) {
- action.setActionSts(ActionStsType.ISSUED.val());
+ action.setActionSts(actionIssuedSts);
action.setStartTime(now);
action.setIoTime(now);
action.setUpdateTime(now);
- if (!actionService.updateById(action)) {
- throw new BusinessException(action.getPriority() + " - " + action.getName() + "鍔ㄤ綔鏇存柊澶辫触");
- }
+ }
+ if (!actionService.updateBatchById(actionList)) {
+ throw new BusinessException("failed to update action batch !!!");
}
// task
List<Long> taskIds = actionService.selectTaskIdsByGroupId(actionGroupId);
+ long taskAssignSts = TaskStsType.ASSIGN.val();
+ long taskProgressSts = TaskStsType.PROGRESS.val();
for (Long taskId : taskIds) {
Task task = taskService.getById(taskId);
- if (task.getTaskSts().equals(TaskStsType.ASSIGN.val())) {
- task.setTaskSts(TaskStsType.PROGRESS.val());
+ if (task.getTaskSts().equals(taskAssignSts)) {
+ task.setTaskSts(taskProgressSts);
task.setUpdateTime(now);
if (!taskService.updateById(task)) {
throw new BusinessException(task.getSeqNum() + "浠诲姟鏇存柊澶辫触");
@@ -1065,9 +1111,8 @@
}
}
-
- Agv agv = agvService.getById(actionList.get(0).getAgvId());
- AgvAction agvAction = new AgvAction(agv.getUuid(), actionGroupId);
+ 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()))) {
--
Gitblit v1.9.1