定时任务测试优化

This commit is contained in:
lsymicc
2025-07-01 15:25:46 +08:00
parent eef6f9fe06
commit f3a7bf26d1
8 changed files with 120 additions and 31 deletions

View File

@@ -4,6 +4,8 @@ import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
/**
* 启动程序
@@ -12,6 +14,8 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
*/
@MapperScan("com.**.mapper")
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
@EnableScheduling
@EnableAsync
public class RuoYiApplication
{
public static void main(String[] args)

View File

@@ -6,7 +6,7 @@ package com.ruoyi.common;
public class TaskStatusCode {
/**
* 任务状态-待请求下发
* 任务状态-待执行
*/
public static final String TASK_READY = "0";

View File

@@ -1,5 +1,6 @@
package com.ruoyi.device.agv.domain.queryTaskStatus;
import com.ruoyi.common.utils.uuid.UUID;
import lombok.Data;
import java.util.List;
@@ -14,7 +15,7 @@ public class QueryTaskStatusRequest {
/**
* 请求编号,每个请求都要一个唯一编号,同一个请求重复提交,使用同一编号。
*/
private String reqCode;
private String reqCode = UUID.randomUUID().toString();
/**
* 请求时间戳,格式: "yyyy-MM-dd HH:mm:ss"

View File

@@ -52,9 +52,9 @@ public class Execution {
}
/**
* 获取所有wcs任务
* 获取所有wcs任务并请求下发
*/
public void getAllTask(){
public void executeTask(){
//查询实时任务表获取所有【待执行】任务
LambdaQueryWrapper<WcsTask> queryWrapper = new LambdaQueryWrapper<>();

View File

@@ -12,6 +12,7 @@ import com.ruoyi.schedule.plc.domain.ConvPTLInRead;
import com.ruoyi.schedule.plc.domain.ConvPTLOutRead;
import com.ruoyi.schedule.task.domain.WcsTask;
import com.ruoyi.schedule.task.service.IWcsTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -22,6 +23,7 @@ import java.util.List;
* 获取任务生成AGV指令
*/
@Component
@Slf4j
public class Generation {
@Autowired
@@ -30,29 +32,63 @@ public class Generation {
@Autowired
Execution execution;
@Autowired
IWcsTaskService iWcsTaskService;
//获取PTL拣选工位入口状态
public List<ConvPTLInRead> getConvPTLInRead() {
public void generateTask() {
//=========================CTU入库(PTL拣选出口到位)=========================
List<ConvPTLOutRead> convPTLOutReads=conv.getConvPTLOut();
//轮询输送机状态
for (int i = 0; i < convPTLOutReads.size(); i++) {
//PTL出口输送机到位
//条码不为空 && 存在任务号 && 设备占用(非空闲)
if (StringUtils.isBlank(convPTLOutReads.get(i).getPalletId()) &&
StringUtils.isBlank(convPTLOutReads.get(i).getTaskId()) &&
convPTLOutReads.get(i).getFree() == 0) {
//todo 请求wms获取调度任务 或 wms推送调度任务(请求wcs接口)
//todo 有无其他任务字段校验
// HttpResponse response = HttpRequest.get(Constant.BASEURL + "/job/inmydoJob/getTaskCount").execute();
// Integer count = JSON.parseObject(response.body(), Integer.class);
//
// WcsTask task = new WcsTask();
//
// iWcsTaskService.insertWcsTask(task);
}
}
//=========================CTU出库(PTL拣选入口空)=========================
List<ConvPTLInRead> convPTLInReads=conv.getConvPTLIn();
for (int i = 0; i < convPTLInReads.size(); i++) {
//PTL入口输送机空位
//设备空闲 && 输送机任务号空
if (convPTLInReads.get(i).getFree() == 1 && StringUtils.isBlank(convPTLInReads.get(i).getTaskId())){
//todo 请求wms获取调度任务 或 wms推送调度任务(请求wcs接口)
}
}
return convPTLInReads;
}
//=========================获取PTL拣选工位出口状态---【CTU入库】=========================
// @Scheduled(cron = "*/2 * * * * *")
public List<ConvPTLOutRead> getConvPTLOutRead() {
List<ConvPTLOutRead> convPTLOutReads = conv.getConvPTLOut();
@@ -72,22 +108,6 @@ public class Generation {
iWcsTaskService.insertWcsTask(task);
//存在当前托盘条码的任务
if (count > 0){
//生成请求数据
GenAgvSchedulingTaskRequest request = new GenAgvSchedulingTaskRequest();
request.setTaskTyp("F12");
//添加路径测试
List<PositionCodeData> path = new ArrayList<PositionCodeData>(2);
path.add(new PositionCodeData("G1001","05"));
path.add(new PositionCodeData("010101","05"));
request.setPositionCodePath(path);
execution.sendCommand(request);
}
}

View File

@@ -6,11 +6,14 @@ import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.Constant;
import com.ruoyi.common.TaskStatusCode;
import com.ruoyi.device.agv.domain.queryTaskStatus.QueryTaskStatusRequest;
import com.ruoyi.device.agv.domain.queryTaskStatus.QueryTaskStatusResponse;
import com.ruoyi.device.agv.domain.queryTaskStatus.TaskStatusData;
import com.ruoyi.schedule.task.domain.WcsTask;
import com.ruoyi.schedule.task.mapper.WcsTaskMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
@@ -26,18 +29,26 @@ public class StatusUpdate {
@Autowired
WcsTaskMapper wcsTaskMapper;
public void statusUpdate() {
//查询实时任务表获取所有【下发成功】任务
LambdaQueryWrapper<WcsTask> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(WcsTask::getTaskStatus, TaskStatusCode.TASK_SEND_SUCCESS);
queryWrapper.ne(WcsTask::getTaskStatus, TaskStatusCode.TASK_READY);
List<WcsTask> tasks = wcsTaskMapper.selectList(queryWrapper);
if (tasks.size() == 0 || tasks == null) return;
//wcs本地任务轮询
for (int i = 0; i < tasks.size(); i++) {
//查询【设备任务状态】接口是否有该任务号已
HttpResponse response = HttpRequest.post(Constant.BASEURL + "/queryTaskStatus").execute();
List<TaskStatusData> deviceTasks = JSON.parseArray(response.body(), TaskStatusData.class);
//查询【设备任务状态】接口是否已有该任务号
HttpResponse response = HttpRequest.post(Constant.BASEURL + "/queryTaskStatus")
.body(JSON.toJSONString(new QueryTaskStatusRequest()))
.execute();
QueryTaskStatusResponse queryTaskStatusResponse = JSON.parseObject(response.body(), QueryTaskStatusResponse.class);
List<TaskStatusData> deviceTasks = queryTaskStatusResponse.getData();
if (deviceTasks.size() == 0 || deviceTasks == null) return;
//接口查询的AGV/CTU设备任务轮询
for (int j = 0; j < deviceTasks.size(); j++) {
@@ -76,7 +87,7 @@ public class StatusUpdate {
}
break;
case "10"://【任务状态】更新为被中断
if (tasks.get(j).getTaskStatus() != TaskStatusCode.TASK_FINISH) {
if (tasks.get(j).getTaskStatus() != TaskStatusCode.TASK_INTERUPTED) {
tasks.get(j).setTaskStatus(TaskStatusCode.TASK_INTERUPTED);
wcsTaskMapper.updateWcsTask(tasks.get(j));
}

View File

@@ -17,7 +17,7 @@ import java.util.List;
@Component
@Slf4j
public class Finish {
public class TaskFinish {
@Autowired
WcsTaskMapper wcsTaskMapper;
@@ -41,6 +41,8 @@ public class Finish {
for (int i = 0; i < tasks.size(); i++) {
//todo 任务完成/取消请求wms
//todo 任务完成/取消请求wms
//todo 任务完成/取消请求wms

View File

@@ -0,0 +1,51 @@
package com.ruoyi.schedule.scheduleTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class Timer {
@Autowired
Generation generation;
@Autowired
Execution execution;
@Autowired
StatusUpdate statusUpdate;
@Autowired
TaskFinish taskFinish;
@Autowired
TaskHandler taskHandler;
@Async
@Scheduled(cron = "*/2 * * * * *")
public void timerTask() {
try {
execution.executeTask();
Thread.sleep(200);
statusUpdate.statusUpdate();
Thread.sleep(200);
taskFinish.taskFinish();
Thread.sleep(200);
// generation.
} catch (Exception e) {
log.error("【调度任务异常】" + e.getMessage());
}
}
}