You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
195 lines
8.3 KiB
195 lines
8.3 KiB
package com.gaotao.modules.automatedWarehouse.task;
|
|
|
|
import com.gaotao.common.utils.ErrorLogUtils;
|
|
import com.gaotao.modules.api.entity.NeedPalletTask;
|
|
import com.gaotao.modules.automatedWarehouse.entity.AgvStation;
|
|
import com.gaotao.modules.automatedWarehouse.entity.WcsCallbackTask;
|
|
import com.gaotao.modules.automatedWarehouse.entity.WmsTransportTask;
|
|
import com.gaotao.modules.automatedWarehouse.mapper.WcsIntegrationMapper;
|
|
import com.gaotao.modules.automatedWarehouse.service.AgvTaskService;
|
|
import com.gaotao.modules.automatedWarehouse.service.AutoTaskService;
|
|
import com.gaotao.modules.automatedWarehouse.service.WcsTaskService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.util.List;
|
|
|
|
@Slf4j
|
|
@Component
|
|
public class AutoTaskScheduler {
|
|
@Autowired
|
|
private WcsTaskService wcsTaskService;
|
|
@Value("${scheduler.autoTask.enabled:true}")
|
|
private boolean enabled;
|
|
@Autowired
|
|
private AgvTaskService agvTaskService;
|
|
@Autowired
|
|
private AutoTaskService autoTaskService;
|
|
@Autowired
|
|
private WcsIntegrationMapper wcsIntegrationMapper;
|
|
|
|
/**
|
|
* 定时任务:10秒运行一次 自动化处理预约获取托盘任务
|
|
* cron表达式:0 * * * * ? 表示每分钟的第0秒执行
|
|
* 配置说明:通过 scheduler.wcs.enabled 控制是否启用
|
|
*/
|
|
@Scheduled(fixedDelay = 8800)
|
|
public void scheduleNeedPalletTask(){
|
|
// 检查定时任务开关
|
|
if (!enabled) {
|
|
return;
|
|
}
|
|
|
|
log.info("=== 开始处理预约获取托盘任务相关业务 ===");
|
|
|
|
try {
|
|
// 获取待处理的WCS回调任务
|
|
List<WmsTransportTask> list = agvTaskService.getNeedPalletTask();
|
|
|
|
|
|
log.info("获取到 {} 个待处理任务(正常: {}, 超时恢复: {})", list.size());
|
|
|
|
int successCount = 0;
|
|
int failCount = 0;
|
|
|
|
for (WmsTransportTask wmsTransportTask : list) {
|
|
try {
|
|
// 委托给业务服务处理
|
|
autoTaskService.processNeedPalletTask(wmsTransportTask);
|
|
successCount++;
|
|
} catch (Exception e) {
|
|
ErrorLogUtils.logException(wmsTransportTask.getSite(), "立库自动化", "处理获取栈板任务:"+wmsTransportTask.getSourceType(), wmsTransportTask.getTaskNo(), e);
|
|
|
|
log.error("处理预约获取托盘任务失败:TaskNo={}, error={}", wmsTransportTask.getTaskNo(), e.getMessage());
|
|
failCount++;
|
|
// 继续处理下一个数据
|
|
}
|
|
}
|
|
|
|
log.info("=== 预约获取托盘任务处理完成:总数={}, 成功={}, 失败={} ===", list.size(), successCount, failCount);
|
|
} catch (Exception e) {
|
|
log.error("=== 预约获取托盘任务定时任务执行失败 ===", e);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* @Description 定时任务:10秒运行一次 自动化处理预约运输栈板任务 - rqrq
|
|
* @Title scheduleTransportPalletTask
|
|
* @author rqrq
|
|
* @date 2025/10/18
|
|
*/
|
|
@Scheduled(fixedDelay = 7755)
|
|
public void scheduleTransportPalletTask(){
|
|
// 检查定时任务开关 - rqrq
|
|
if (!enabled) {
|
|
return;
|
|
}
|
|
|
|
log.info("=== 开始处理预约运输栈板任务 - rqrq ===");
|
|
|
|
try {
|
|
// 获取待处理的预约运输栈板任务 - rqrq
|
|
List<WmsTransportTask> list = agvTaskService.getScheduledTransportPalletTask();
|
|
|
|
log.info("获取到 {} 个待处理的预约运输栈板任务 - rqrq", list.size());
|
|
|
|
int successCount = 0;
|
|
int failCount = 0;
|
|
|
|
for (WmsTransportTask wmsTransportTask : list) {
|
|
try {
|
|
// 委托给业务服务处理 - rqrq
|
|
autoTaskService.processScheduledTransportPalletTask(wmsTransportTask);
|
|
successCount++;
|
|
} catch (Exception e) {
|
|
ErrorLogUtils.logException(wmsTransportTask.getSite(), "立库自动化", "处理运输栈板任务:"+wmsTransportTask.getSourceType(), wmsTransportTask.getTaskNo(), e);
|
|
|
|
log.error("处理预约运输栈板任务失败 - rqrq:TaskNo={}, error={}",
|
|
wmsTransportTask.getTaskNo(), e.getMessage(), e);
|
|
failCount++;
|
|
// 继续处理下一个任务 - rqrq
|
|
}
|
|
}
|
|
|
|
log.info("=== 预约运输栈板任务处理完成 - rqrq:总数={}, 成功={}, 失败={} ===",
|
|
list.size(), successCount, failCount);
|
|
} catch (Exception e) {
|
|
log.error("=== 预约运输栈板任务定时任务执行失败 - rqrq ===", e);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @Description 定时任务:30秒运行一次 自动续盘(为空闲站点自动调用空托盘)- rqrq
|
|
* @Title scheduleAutoCallBlankPallet
|
|
* @author rqrq
|
|
* @date 2025/10/19
|
|
*/
|
|
@Scheduled(fixedDelay = 8888)
|
|
public void scheduleAutoCallBlankPallet() {
|
|
// 检查定时任务开关 - rqrq
|
|
if (!enabled) {
|
|
return;
|
|
}
|
|
|
|
log.info("=== 开始自动续盘任务 - rqrq ===");
|
|
|
|
try {
|
|
// 查询需要自动续盘的站点 - rqrq
|
|
// 条件:auto_call_blank_pallet='Y', auto_call_blank_pallet_type有值, station_type='正式站点', status_db=0
|
|
List<AgvStation> stations = wcsIntegrationMapper.getAutoCallBlankPalletStations();
|
|
|
|
log.info("查询到 {} 个需要自动续盘的站点 - rqrq", stations.size());
|
|
|
|
int successCount = 0;
|
|
int failCount = 0;
|
|
|
|
|
|
for (AgvStation station : stations) {
|
|
NeedPalletTask needPalletTask=new NeedPalletTask();
|
|
try {
|
|
log.info("开始为站点 {} 自动调用空托盘 - rqrq,站点编码={}, 托盘类型={}, 等待站点={}",
|
|
station.getStationName(),
|
|
station.getStationCode(),
|
|
station.getAutoCallBlankPalletType(),
|
|
station.getWaitStationCode());
|
|
|
|
// 构建NeedPalletTask参数 - rqrq
|
|
needPalletTask.setSite("55"); // 固定站点为55 - rqrq
|
|
needPalletTask.setStationCode(station.getStationCode()); // 使用wait_station_code作为目标站点 - rqrq
|
|
needPalletTask.setPalletType(station.getAutoCallBlankPalletType()); // 使用auto_call_blank_pallet_type作为栈板类型 - rqrq
|
|
needPalletTask.setPalletId(null); // 不指定具体栈板,由WCS自动分配 - rqrq
|
|
needPalletTask.setUsername("SYS_WMS"); // 系统自动调用 - rqrq
|
|
needPalletTask.setSourceBillNo("自动续盘-" + station.getStationCode()); // 来源单号 - rqrq
|
|
|
|
// 调用autoNeedPalletTask创建预约任务 - rqrq
|
|
autoTaskService.autoNeedPalletTask(needPalletTask);
|
|
|
|
successCount++;
|
|
log.info("站点 {} 自动续盘成功 - rqrq", station.getStationCode());
|
|
|
|
} catch (Exception e) {
|
|
ErrorLogUtils.logException(needPalletTask.getSite(), "立库自动化", "站点自动续盘", needPalletTask.getStationCode(), e);
|
|
|
|
failCount++;
|
|
log.error("站点 {} 自动续盘失败 - rqrq:stationCode={}, error={}",
|
|
station.getStationName(),
|
|
station.getStationCode(),
|
|
e.getMessage(),
|
|
e);
|
|
// 继续处理下一个站点 - rqrq
|
|
}
|
|
}
|
|
|
|
log.info("=== 自动续盘任务处理完成 - rqrq:总数={}, 成功={}, 失败={} ===",
|
|
stations.size(), successCount, failCount);
|
|
|
|
} catch (Exception e) {
|
|
log.error("=== 自动续盘定时任务执行失败 - rqrq ===", e);
|
|
}
|
|
}
|
|
}
|