From 73e42333948a8143c54218cd26435c2233daf279 Mon Sep 17 00:00:00 2001
From: chen.llin <1442464845@qq.comm>
Date: 星期五, 16 一月 2026 14:13:14 +0800
Subject: [PATCH] agv出入库逻辑
---
src/main/java/com/zy/asrs/task/AgvScheduler.java | 221 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 218 insertions(+), 3 deletions(-)
diff --git a/src/main/java/com/zy/asrs/task/AgvScheduler.java b/src/main/java/com/zy/asrs/task/AgvScheduler.java
index 1205b62..5eb5e6f 100644
--- a/src/main/java/com/zy/asrs/task/AgvScheduler.java
+++ b/src/main/java/com/zy/asrs/task/AgvScheduler.java
@@ -1,21 +1,27 @@
package com.zy.asrs.task;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.mapper.Wrapper;
import com.core.common.Cools;
import com.zy.asrs.entity.Task;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.mapper.WrkMastMapper;
+import com.zy.asrs.entity.WrkMastLog;
import com.zy.asrs.service.TaskService;
+import com.zy.asrs.service.WrkMastLogService;
+import com.zy.asrs.service.WrkMastService;
import com.zy.asrs.task.handler.AgvHandler;
+import com.zy.common.properties.SchedulerProperties;
import com.zy.system.entity.Config;
import com.zy.system.service.ConfigService;
-import org.springframework.scheduling.TaskScheduler;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Date;
import java.util.List;
/**
@@ -23,6 +29,7 @@
* @description AGV浜や簰鐩稿叧瀹氭椂浠诲姟
* @createDate 2025/11/18 14:18
*/
+@Slf4j
@Component
public class AgvScheduler {
@@ -38,13 +45,29 @@
@Resource
private WrkMastMapper wrkMastMapper;
+ @Resource
+ private WrkMastService wrkMastService;
+
+ @Resource
+ private WrkMastLogService wrkMastLogService;
+
+ @Resource
+ private SchedulerProperties schedulerProperties;
+
/**
* 鍛煎彨agv鎼繍
*/
@Scheduled(cron = "0/5 * * * * ? ")
private void callAgv() {
- // 鏌ヨ寰呭懠鍙玜gv浠诲姟
- List<Task> taskList = taskService.selectList(new EntityWrapper<Task>().eq("wrk_sts", 7));
+ if (!schedulerProperties.isEnabled()) {
+ return;
+ }
+ // 鏌ヨ寰呭懠鍙玜gv浠诲姟锛屾寜id鍗囧簭鎺掑簭锛坕d鏈�灏忕殑浼樺厛鍛煎彨锛�
+ List<Task> taskList = taskService.selectList(
+ new EntityWrapper<Task>()
+ .eq("wrk_sts", 7)
+ .orderBy("id", true) // 鎸塱d鍗囧簭锛宨d鏈�灏忕殑浼樺厛
+ );
if(taskList.isEmpty()) {
return;
}
@@ -56,6 +79,9 @@
*/
@Scheduled(cron = "0/3 * * * * ? ")
private void createAgvOutTasks() {
+ if (!schedulerProperties.isEnabled()) {
+ return;
+ }
// 鑾峰彇鍛煎彨agv閰嶇疆
List<Config> configs = configService.selectList(new EntityWrapper<Config>().in("code", "eastCallAgvControl", "westCallAgvControl").eq("status", 1));
@@ -86,6 +112,9 @@
*/
@Scheduled(cron = "0/10 * * * * ? ")
private void moveTaskToHistory() {
+ if (!schedulerProperties.isEnabled()) {
+ return;
+ }
List<Task> taskList = taskService.selectList(new EntityWrapper<Task>().eq("wrk_sts", 9));
if(taskList.isEmpty()) {
return;
@@ -93,5 +122,191 @@
agvHandler.moveTaskToHistory(taskList);
}
+ /**
+ * 妫�鏌ュ叆搴撴垚鍔熺殑浠诲姟锛屽畬缁撳搴旂殑AGV鍛煎彨鍗�
+ * 濡傛灉鍏ュ簱浠诲姟鍛煎彨AGV鍚庢病鏈夋敹鍒板洖璋冿紝浣嗗伐浣滄。宸茬粡鍏ュ簱鎴愬姛锛屽垯瀹岀粨AGV鍛煎彨鍗�
+ */
+ @Scheduled(cron = "0/10 * * * * ? ")
+ private void checkInboundCompletedTasks() {
+ if (!schedulerProperties.isEnabled()) {
+ return;
+ }
+ try {
+ // 鏌ヨ鍏ュ簱鎴愬姛鐨勫伐浣滄。锛堢姸鎬�4锛氬叆搴撳畬鎴愶紝鍏ュ簱绫诲瀷锛�1,10,53,57锛�
+ List<WrkMast> completedWrkMasts = wrkMastService.selectList(
+ new EntityWrapper<WrkMast>()
+ .eq("wrk_sts", 4L) // 鍏ュ簱瀹屾垚
+ .in("io_type", 1, 10, 53, 57) // 鍏ュ簱绫诲瀷
+ .isNotNull("wrk_no")
+ );
+
+ if (completedWrkMasts.isEmpty()) {
+ return;
+ }
+
+ Date now = new Date();
+ int completedCount = 0;
+
+ for (WrkMast wrkMast : completedWrkMasts) {
+ // 鏌ユ壘瀵瑰簲鐨凙GV浠诲姟锛堜紭鍏堥�氳繃wrk_no鏌ヨ锛�
+ Wrapper<Task> taskWrapper1 = new EntityWrapper<Task>()
+ .eq("task_type", "agv")
+ .eq("wrk_sts", 8L) // 宸插懠鍙獳GV鐘舵��
+ .eq("wrk_no", wrkMast.getWrkNo());
+ List<Task> agvTasks = taskService.selectList(taskWrapper1);
+
+ // 濡傛灉閫氳繃wrk_no娌℃壘鍒帮紝涓旀湁鏉$爜锛屽垯閫氳繃鏉$爜鏌ヨ
+ if (agvTasks.isEmpty() && !Cools.isEmpty(wrkMast.getBarcode())) {
+ Wrapper<Task> taskWrapper2 = new EntityWrapper<Task>()
+ .eq("task_type", "agv")
+ .eq("wrk_sts", 8L)
+ .eq("barcode", wrkMast.getBarcode());
+ agvTasks = taskService.selectList(taskWrapper2);
+ }
+
+ for (Task agvTask : agvTasks) {
+ // 纭繚鏄叆搴撲换鍔�
+ if (agvTask.getIoType() != null &&
+ (agvTask.getIoType() == 1 || agvTask.getIoType() == 10 ||
+ agvTask.getIoType() == 53 || agvTask.getIoType() == 57)) {
+ // 鏇存柊AGV浠诲姟鐘舵�佷负瀹屾垚
+ agvTask.setWrkSts(9L);
+ agvTask.setModiTime(now);
+ if (taskService.updateById(agvTask)) {
+ completedCount++;
+ log.info("鍏ュ簱浠诲姟宸ヤ綔妗e凡鍏ュ簱鎴愬姛锛屽畬缁揂GV鍛煎彨鍗曪紝taskId锛歿}锛寃rkNo锛歿}锛宐arcode锛歿}",
+ agvTask.getId(), wrkMast.getWrkNo(), wrkMast.getBarcode());
+ }
+ }
+ }
+ }
+
+ if (completedCount > 0) {
+ log.info("鏈妫�鏌ュ畬缁撲簡{}涓叆搴揂GV鍛煎彨鍗�", completedCount);
+ }
+ } catch (Exception e) {
+ log.error("妫�鏌ュ叆搴撴垚鍔熶换鍔″苟瀹岀粨AGV鍛煎彨鍗曞紓甯�", e);
+ }
+ }
+
+ /**
+ * 妫�鏌GV浠诲姟瀵瑰簲鐨勫伐浣滄。鏄惁宸插畬鎴愭垨宸茶浆鍘嗗彶妗e苟瀹岀粨
+ * 澶勭悊琚烦杩囩殑AGV浠诲姟锛氬鏋滃伐浣滄。宸插畬鎴愶紙wrk_sts=4,5,14,15锛夋垨宸茶浆鍘嗗彶妗e苟瀹岀粨锛屽垯瀹岀粨AGV浠诲姟
+ */
+ @Scheduled(cron = "0/10 * * * * ? ")
+ private void checkCompletedTasksInHistory() {
+ if (!schedulerProperties.isEnabled()) {
+ return;
+ }
+ try {
+ // 鏌ヨ鐘舵�佷负8锛堝凡鍛煎彨AGV锛夌殑AGV浠诲姟
+ List<Task> agvTasks = taskService.selectList(
+ new EntityWrapper<Task>()
+ .eq("task_type", "agv")
+ .eq("wrk_sts", 8L) // 宸插懠鍙獳GV鐘舵��
+ .isNotNull("wrk_no")
+ );
+
+ if (agvTasks.isEmpty()) {
+ return;
+ }
+
+ Date now = new Date();
+ int completedCount = 0;
+
+ for (Task agvTask : agvTasks) {
+ boolean isCompleted = false;
+ String reason = "";
+
+ // 妫�鏌ュ伐浣滄。鏄惁瀛樺湪
+ WrkMast wrkMast = null;
+ if (agvTask.getWrkNo() != null) {
+ wrkMast = wrkMastService.selectOne(
+ new EntityWrapper<WrkMast>().eq("wrk_no", agvTask.getWrkNo())
+ );
+ }
+
+ // 濡傛灉宸ヤ綔妗e瓨鍦紝妫�鏌ユ槸鍚﹀凡瀹屾垚
+ if (wrkMast != null) {
+ Long wrkSts = wrkMast.getWrkSts();
+ Integer ioType = agvTask.getIoType();
+
+ if (wrkSts != null && ioType != null) {
+ // 鍏ュ簱浠诲姟锛氱姸鎬�4锛堝叆搴撳畬鎴愶級鎴�5锛堝簱瀛樻洿鏂板畬鎴愶級
+ if ((ioType == 1 || ioType == 10 || ioType == 53 || ioType == 57) &&
+ (wrkSts == 4L || wrkSts == 5L)) {
+ isCompleted = true;
+ reason = String.format("宸ヤ綔妗e凡瀹屾垚锛岀姸鎬侊細%d", wrkSts);
+ }
+ // 鍑哄簱浠诲姟锛氱姸鎬�14锛堝凡鍑哄簱鏈‘璁わ級鎴�15锛堝嚭搴撴洿鏂板畬鎴愶級
+ else if ((ioType == 101 || ioType == 110 || ioType == 103 || ioType == 107) &&
+ (wrkSts == 14L || wrkSts == 15L)) {
+ isCompleted = true;
+ reason = String.format("宸ヤ綔妗e凡瀹屾垚锛岀姸鎬侊細%d", wrkSts);
+ }
+ }
+ } else {
+ // 濡傛灉宸ヤ綔妗d笉瀛樺湪锛屾鏌ュ巻鍙叉。
+ WrkMastLog wrkMastLog = null;
+
+ // 浼樺厛閫氳繃wrk_no鏌ヨ鍘嗗彶妗�
+ if (agvTask.getWrkNo() != null) {
+ wrkMastLog = wrkMastLogService.selectOne(
+ new EntityWrapper<WrkMastLog>().eq("wrk_no", agvTask.getWrkNo())
+ );
+ }
+
+ // 濡傛灉閫氳繃wrk_no娌℃壘鍒帮紝涓旀湁鏉$爜锛屽垯閫氳繃鏉$爜鏌ヨ
+ if (wrkMastLog == null && !Cools.isEmpty(agvTask.getBarcode())) {
+ List<WrkMastLog> logList = wrkMastLogService.selectList(
+ new EntityWrapper<WrkMastLog>().eq("barcode", agvTask.getBarcode())
+ );
+ if (!logList.isEmpty()) {
+ wrkMastLog = logList.get(0); // 鍙栫涓�涓�
+ }
+ }
+
+ // 濡傛灉鍘嗗彶妗e瓨鍦ㄤ笖宸插畬缁擄紝鍒欏畬缁揂GV浠诲姟
+ if (wrkMastLog != null) {
+ Integer ioType = agvTask.getIoType();
+ long logWrkSts = wrkMastLog.getWrkSts();
+
+ if (ioType != null) {
+ // 鍏ュ簱浠诲姟锛氱姸鎬�5锛堝簱瀛樻洿鏂板畬鎴愶級
+ if ((ioType == 1 || ioType == 10 || ioType == 53 || ioType == 57) &&
+ logWrkSts == 5L) {
+ isCompleted = true;
+ reason = String.format("宸ヤ綔妗e凡杞巻鍙叉。骞跺畬缁擄紝鍘嗗彶妗g姸鎬侊細%d", logWrkSts);
+ }
+ // 鍑哄簱浠诲姟锛氱姸鎬�15锛堝嚭搴撴洿鏂板畬鎴愶級
+ else if ((ioType == 101 || ioType == 110 || ioType == 103 || ioType == 107) &&
+ logWrkSts == 15L) {
+ isCompleted = true;
+ reason = String.format("宸ヤ綔妗e凡杞巻鍙叉。骞跺畬缁擄紝鍘嗗彶妗g姸鎬侊細%d", logWrkSts);
+ }
+ }
+ }
+ }
+
+ // 濡傛灉宸插畬鎴愶紝鏇存柊AGV浠诲姟鐘舵��
+ if (isCompleted) {
+ agvTask.setWrkSts(9L);
+ agvTask.setModiTime(now);
+ if (taskService.updateById(agvTask)) {
+ completedCount++;
+ log.info("{}锛屽畬缁揂GV鍛煎彨鍗曪紝taskId锛歿}锛寃rkNo锛歿}锛宐arcode锛歿}锛岀珯鐐癸細{}",
+ reason, agvTask.getId(), agvTask.getWrkNo(), agvTask.getBarcode(), agvTask.getStaNo());
+ }
+ }
+ }
+
+ if (completedCount > 0) {
+ log.info("鏈妫�鏌ュ畬缁撲簡{}涓狝GV鍛煎彨鍗曪紙宸ヤ綔妗e凡瀹屾垚鎴栧凡杞巻鍙叉。锛�", completedCount);
+ }
+ } catch (Exception e) {
+ log.error("妫�鏌ュ伐浣滄。宸插畬鎴愭垨鍘嗗彶妗e畬缁撲换鍔″苟瀹岀粨AGV鍛煎彨鍗曞紓甯�", e);
+ }
+ }
+
}
--
Gitblit v1.9.1