From bc729b420fc0db8db80fc4d2b8e67f56edada33e Mon Sep 17 00:00:00 2001
From: vincentlu <t1341870251@gmail.com>
Date: 星期一, 13 四月 2026 10:23:35 +0800
Subject: [PATCH] #
---
zy-acs-manager/src/main/java/com/zy/acs/manager/core/HandlerController.java | 133 ++++++++++++++++++++++++++++++++++----------
1 files changed, 102 insertions(+), 31 deletions(-)
diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/HandlerController.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/HandlerController.java
index 34b83ff..77fec31 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/HandlerController.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/HandlerController.java
@@ -3,21 +3,24 @@
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.acs.common.constant.RedisConstant;
+import com.zy.acs.common.utils.Base62;
import com.zy.acs.common.utils.RedisSupport;
-import com.zy.acs.common.utils.Utils;
import com.zy.acs.framework.common.Cools;
import com.zy.acs.framework.common.R;
import com.zy.acs.framework.common.SnowflakeIdWorker;
import com.zy.acs.manager.common.annotation.OperationLog;
+import com.zy.acs.manager.common.config.UplinkProperties;
import com.zy.acs.manager.common.domain.param.HandlerPublishParam;
import com.zy.acs.manager.common.exception.BusinessException;
import com.zy.acs.manager.core.service.*;
+import com.zy.acs.manager.core.service.hik.HikInstantActionPublishService;
import com.zy.acs.manager.core.service.astart.MapDataDispatcher;
import com.zy.acs.manager.core.service.astart.domain.DynamicNode;
import com.zy.acs.manager.manager.entity.*;
import com.zy.acs.manager.manager.enums.*;
import com.zy.acs.manager.manager.service.*;
import com.zy.acs.manager.system.controller.BaseController;
+import com.zy.acs.manager.system.service.ConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -64,7 +67,7 @@
@Autowired
private StaService staService;
@Autowired
- private TrafficService trafficService;
+ private UplinkProperties uplinkProperties;
@Autowired
private ThreadPoolRegulator threadPoolRegulator;
@Autowired
@@ -75,6 +78,12 @@
private PatrolService patrolService;
@Autowired
private StaReserveService staReserveService;
+ @Autowired
+ private AgvAreaDispatcher agvAreaDispatcher;
+ @Autowired
+ private ConfigService configService;
+ @Autowired
+ private HikInstantActionPublishService hikInstantActionPublishService;
@PreAuthorize("hasAuthority('manager:agv:update')")
@OperationLog("Locate All Agv")
@@ -138,6 +147,7 @@
return R.error();
}
+ Boolean maintainLocSts = configService.getVal("maintainLocSts", Boolean.class);
Date now = new Date();
Agv agv = agvService.selectByUuid(param.getAgvNo());
AgvDetail agvDetail = agvDetailService.selectByAgvId(agv.getId());
@@ -162,16 +172,17 @@
Task task = new Task();
task.setAgvId(agv.getId());
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()));
+// 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(Base62.encode(snowflakeIdWorker.nextId()));
task.setTaskType(param.getTaskMode().val());
task.setTaskSts(TaskStsType.WAITING.val());
-
+ task.setUplinkSts(uplinkProperties.getEnabled() ? TaskUplinkStateType.PENDING.toString() : TaskUplinkStateType.SKIPPED.toString());
task.setPriority(999);
task.setIoTime(now);
task.setStartTime(now);
- task.setMemo("HANDLE");
+ task.setMemo("AUTO");
if (!taskService.save(task)) {
throw new BusinessException(task.getSeqNum() + "浠诲姟淇濆瓨澶辫触");
}
@@ -192,6 +203,9 @@
}
if (null == endCode) {
return R.error();
+ }
+ if (!agvAreaDispatcher.match(agv.getId(), endCode.getId())) {
+ throw new BusinessException("AGV " + agv.getUuid() + " failed to reach target code " + endCode.getData());
}
if (!taskService.removeById(task.getId())) {
throw new BusinessException("failed to remove task");
@@ -222,13 +236,19 @@
if (null == oriLoc) {
return R.error();
}
- if (!oriLoc.getLocSts().equals(LocStsType.STOCK.val())) {
- throw new BusinessException("oriLoc锛�" + oriLoc.getLocNo() + " 涓嶆槸鍦ㄥ簱鐘舵��");
+ if (!agvAreaDispatcher.match(agv.getId(), oriLoc.getCode())) {
+// throw new BusinessException("AGV " + agv.getUuid() + " failed to reach target code " + oriLoc.getCode$());
+ throw new BusinessException("AGV銆�" + agv.getUuid() + "銆戞棤娉曞埌杈捐捣濮嬪簱浣嶃��" + oriLoc.getLocNo() + "銆�");
}
- oriLoc.setLocSts(LocStsType.PAKOUT.val());
- oriLoc.setUpdateTime(now);
- if (!locService.updateById(oriLoc)) {
- throw new BusinessException("oriLoc锛�" + oriLoc.getLocNo() + " 淇敼搴撲綅鐘舵�佸け璐�");
+ if (maintainLocSts) {
+ if (!oriLoc.getLocSts().equals(LocStsType.STOCK.val())) {
+ throw new BusinessException("oriLoc锛�" + oriLoc.getLocNo() + " 涓嶆槸鍦ㄥ簱鐘舵��");
+ }
+ oriLoc.setLocSts(LocStsType.PAKOUT.val());
+ oriLoc.setUpdateTime(now);
+ if (!locService.updateById(oriLoc)) {
+ throw new BusinessException("oriLoc锛�" + oriLoc.getLocNo() + " 淇敼搴撲綅鐘舵�佸け璐�");
+ }
}
// destLoc
@@ -241,13 +261,19 @@
if (null == destLoc) {
return R.error();
}
- if (!destLoc.getLocSts().equals(LocStsType.IDLE.val())) {
- throw new BusinessException("destLoc锛�" + destLoc.getLocNo() + " 涓嶆槸绌洪棽鐘舵��");
+ if (!agvAreaDispatcher.match(agv.getId(), destLoc.getCode())) {
+// throw new BusinessException("AGV " + agv.getUuid() + " failed to reach target code " + destLoc.getCode$());
+ throw new BusinessException("AGV銆�" + agv.getUuid() + "銆戞棤娉曞埌杈剧洰鏍囧簱浣嶃��" + destLoc.getLocNo() + "銆�");
}
- destLoc.setLocSts(LocStsType.PAKIN.val());
- destLoc.setUpdateTime(now);
- if (!locService.updateById(destLoc)) {
- throw new BusinessException("destLoc锛�" + destLoc.getLocNo() + " 淇敼搴撲綅鐘舵�佸け璐�");
+ if (maintainLocSts) {
+ if (!destLoc.getLocSts().equals(LocStsType.IDLE.val())) {
+ throw new BusinessException("destLoc锛�" + destLoc.getLocNo() + " 涓嶆槸绌洪棽鐘舵��");
+ }
+ destLoc.setLocSts(LocStsType.PAKIN.val());
+ destLoc.setUpdateTime(now);
+ if (!locService.updateById(destLoc)) {
+ throw new BusinessException("destLoc锛�" + destLoc.getLocNo() + " 淇敼搴撲綅鐘舵�佸け璐�");
+ }
}
// task
@@ -267,13 +293,19 @@
if (null == oriLoc) {
return R.error();
}
- if (!oriLoc.getLocSts().equals(LocStsType.STOCK.val())) {
- throw new BusinessException("oriLoc锛�" + oriLoc.getLocNo() + " 涓嶆槸鍦ㄥ簱鐘舵��");
+ if (!agvAreaDispatcher.match(agv.getId(), oriLoc.getCode())) {
+// throw new BusinessException("AGV " + agv.getUuid() + " failed to reach target code " + oriLoc.getCode$());
+ throw new BusinessException("AGV銆�" + agv.getUuid() + "銆戞棤娉曞埌杈捐捣濮嬪簱浣嶃��" + oriLoc.getLocNo() + "銆�");
}
- oriLoc.setLocSts(LocStsType.PAKOUT.val());
- oriLoc.setUpdateTime(now);
- if (!locService.updateById(oriLoc)) {
- throw new BusinessException("oriLoc锛�" + oriLoc.getLocNo() + " 淇敼搴撲綅鐘舵�佸け璐�");
+ if (maintainLocSts) {
+ if (!oriLoc.getLocSts().equals(LocStsType.STOCK.val())) {
+ throw new BusinessException("oriLoc锛�" + oriLoc.getLocNo() + " 涓嶆槸鍦ㄥ簱鐘舵��");
+ }
+ oriLoc.setLocSts(LocStsType.PAKOUT.val());
+ oriLoc.setUpdateTime(now);
+ if (!locService.updateById(oriLoc)) {
+ throw new BusinessException("oriLoc锛�" + oriLoc.getLocNo() + " 淇敼搴撲綅鐘舵�佸け璐�");
+ }
}
// destSta
@@ -286,15 +318,20 @@
if (null == destSta) {
return R.error();
}
+ if (!agvAreaDispatcher.match(agv.getId(), destSta.getCode())) {
+// throw new BusinessException("AGV " + agv.getUuid() + " failed to reach target code " + destSta.getCode$());
+ throw new BusinessException("AGV銆�" + agv.getUuid() + "銆戞棤娉曞埌杈剧洰鏍囩珯鐐广��" + destSta.getStaNo() + "銆�");
+ }
if (null == staReserveService.reserveStaIn(destSta, task, 1)) {
throw new BusinessException("destSta锛�" + destSta.getStaNo() + " 棰勭害澶辫触");
}
-
// task
task.setOriLoc(oriLoc.getId());
task.setOriCode(oriLoc.getCode());
task.setDestSta(destSta.getId());
task.setDestCode(destSta.getCode());
+
+ staReserveService.allocateCallBack(task, agv.getId());
break;
case STA_TO_LOC:
// oriSta
@@ -306,6 +343,10 @@
}
if (null == oriSta) {
return R.error();
+ }
+ if (!agvAreaDispatcher.match(agv.getId(), oriSta.getCode())) {
+// throw new BusinessException("AGV " + agv.getUuid() + " failed to reach target code " + oriSta.getCode$());
+ throw new BusinessException("AGV銆�" + agv.getUuid() + "銆戞棤娉曞埌杈捐捣濮嬬珯鐐广��" + oriSta.getStaNo() + "銆�");
}
if (null == staReserveService.reserveStaOut(oriSta, task, 1)) {
throw new BusinessException("oriSta锛�" + oriSta.getStaNo() + " 棰勭害澶辫触");
@@ -321,13 +362,19 @@
if (null == destLoc) {
return R.error();
}
- if (!destLoc.getLocSts().equals(LocStsType.IDLE.val())) {
- throw new BusinessException("destLoc锛�" + destLoc.getLocNo() + " 涓嶆槸绌洪棽鐘舵��");
+ if (!agvAreaDispatcher.match(agv.getId(), destLoc.getCode())) {
+// throw new BusinessException("AGV " + agv.getUuid() + " failed to reach target code " + destLoc.getCode$());
+ throw new BusinessException("AGV銆�" + agv.getUuid() + "銆戞棤娉曞埌杈剧洰鏍囧簱浣嶃��" + destLoc.getLocNo() + "銆�");
}
- destLoc.setLocSts(LocStsType.PAKIN.val());
- destLoc.setUpdateTime(now);
- if (!locService.updateById(destLoc)) {
- throw new BusinessException("destLoc锛�" + destLoc.getLocNo() + " 淇敼搴撲綅鐘舵�佸け璐�");
+ if (maintainLocSts) {
+ if (!destLoc.getLocSts().equals(LocStsType.IDLE.val())) {
+ throw new BusinessException("destLoc锛�" + destLoc.getLocNo() + " 涓嶆槸绌洪棽鐘舵��");
+ }
+ destLoc.setLocSts(LocStsType.PAKIN.val());
+ destLoc.setUpdateTime(now);
+ if (!locService.updateById(destLoc)) {
+ throw new BusinessException("destLoc锛�" + destLoc.getLocNo() + " 淇敼搴撲綅鐘舵�佸け璐�");
+ }
}
// task
@@ -335,6 +382,8 @@
task.setOriCode(oriSta.getCode());
task.setDestLoc(destLoc.getId());
task.setDestCode(destLoc.getCode());
+
+ staReserveService.allocateCallBack(task, agv.getId());
break;
case STA_TO_STA:
// oriSta
@@ -347,9 +396,14 @@
if (null == oriSta) {
return R.error();
}
+ if (!agvAreaDispatcher.match(agv.getId(), oriSta.getCode())) {
+// throw new BusinessException("AGV " + agv.getUuid() + " failed to reach target code " + oriSta.getCode$());
+ throw new BusinessException("AGV銆�" + agv.getUuid() + "銆戞棤娉曞埌杈捐捣濮嬬珯鐐广��" + oriSta.getStaNo() + "銆�");
+ }
if (null == staReserveService.reserveStaOut(oriSta, task, 1)) {
throw new BusinessException("oriSta锛�" + oriSta.getStaNo() + " 棰勭害澶辫触");
}
+
// destSta
if (!Cools.isEmpty(param.getEndStaNo())) {
@@ -361,6 +415,10 @@
if (null == destSta) {
return R.error();
}
+ if (!agvAreaDispatcher.match(agv.getId(), destSta.getCode())) {
+// throw new BusinessException("AGV " + agv.getUuid() + " failed to reach target code " + destSta.getCode$());
+ throw new BusinessException("AGV銆�" + agv.getUuid() + "銆戞棤娉曞埌杈剧洰鏍囩珯鐐广��" + destSta.getStaNo() + "銆�");
+ }
if (null == staReserveService.reserveStaIn(destSta, task, 1)) {
throw new BusinessException("destSta锛�" + destSta.getStaNo() + " 棰勭害澶辫触");
}
@@ -370,6 +428,8 @@
task.setOriCode(oriSta.getCode());
task.setDestSta(destSta.getId());
task.setDestCode(destSta.getCode());
+
+ staReserveService.allocateCallBack(task, agv.getId());
break;
default:
break;
@@ -410,6 +470,7 @@
}
if (null != agv) {
+ publishRestoreCancelIfNeeded(agv);
mapDataDispatcher.modifyDynamicMatrix(null, null, agv.getUuid(), true);
avoidWaveCalculator.calcDynamicNodeByVehicle(agv, null);
@@ -420,6 +481,7 @@
} else {
List<Agv> agvList = agvService.list(new LambdaQueryWrapper<Agv>());
for (Agv one : agvList) {
+ publishRestoreCancelIfNeeded(one);
mapDataDispatcher.modifyDynamicMatrix(null, null, one.getUuid(), true);
avoidWaveCalculator.calcDynamicNodeByVehicle(one, null);
}
@@ -433,6 +495,15 @@
return R.ok();
}
+ private void publishRestoreCancelIfNeeded(Agv agv) {
+ if (agv == null) {
+ return;
+ }
+ if (hikInstantActionPublishService.support(agv.getId())) {
+ hikInstantActionPublishService.publishCancelOrder(agv.getUuid());
+ }
+ }
+
@RequestMapping(value = "/unlock", method = {RequestMethod.GET, RequestMethod.POST})
public R unlockPath(@RequestHeader String appKey,
@RequestBody HandlerPublishParam param) throws ExecutionException, InterruptedException {
--
Gitblit v1.9.1