代码更新:

1. 增加定时器:任务解析与发送。
This commit is contained in:
梁州 2025-01-20 09:45:09 +08:00
parent 3b49880332
commit 38baf12e7b
5 changed files with 356 additions and 2 deletions

View File

@ -0,0 +1,43 @@
package com.ruoyi.web.domain;
/**
* Wcs通用响应信息
*/
public class WcsCommonResponse {
/**
* code
*/
private Integer code;
/**
* message
*/
private String message;
/**
* data
*/
private Object data;
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
}

View File

@ -0,0 +1,117 @@
package com.ruoyi.web.domain;
import java.math.BigDecimal;
/**
* Wcs堆垛机任务详情
*/
public class WcsStackerTask {
/**
* 任务id
*/
private String taskId;
/**
* 任务类型
*/
private Integer taskType;
/**
* 任务优先级
*/
private Integer priority;
/**
* 任务起点
*/
private String origin;
/**
* 任务中间点
*/
private String midpoint;
/**
* 任务终点
*/
private String destination;
/**
* 载具编号
*/
private String vehicleNo;
/**
* 载具尺寸
*/
private Integer vehicleSize = 0;
/**
* 总重量
*/
private BigDecimal weight = BigDecimal.ZERO;
public String getTaskId() {
return taskId;
}
public void setTaskId(String taskId) {
this.taskId = taskId;
}
public Integer getTaskType() {
return taskType;
}
public void setTaskType(Integer taskType) {
this.taskType = taskType;
}
public Integer getPriority() {
return priority;
}
public void setPriority(Integer priority) {
this.priority = priority;
}
public String getOrigin() {
return origin;
}
public void setOrigin(String origin) {
this.origin = origin;
}
public String getMidpoint() {
return midpoint;
}
public void setMidpoint(String midpoint) {
this.midpoint = midpoint;
}
public String getDestination() {
return destination;
}
public void setDestination(String destination) {
this.destination = destination;
}
public String getVehicleNo() {
return vehicleNo;
}
public void setVehicleNo(String vehicleNo) {
this.vehicleNo = vehicleNo;
}
public Integer getVehicleSize() {
return vehicleSize;
}
public void setVehicleSize(Integer vehicleSize) {
this.vehicleSize = vehicleSize;
}
public BigDecimal getWeight() {
return weight;
}
public void setWeight(BigDecimal weight) {
this.weight = weight;
}
}

View File

@ -0,0 +1,117 @@
package com.ruoyi.web.domain;
import java.math.BigDecimal;
/**
* 向wcs发送堆垛机任务请求
*/
public class WcsStackerTaskRequest {
/**
* 任务id
*/
private String taskId;
/**
* 任务类型
*/
private Integer taskType;
/**
* 任务优先级
*/
private Integer priority;
/**
* 任务起点
*/
private String origin;
/**
* 任务中间点
*/
private String midpoint;
/**
* 任务终点
*/
private String destination;
/**
* 载具编号
*/
private String vehicleNo;
/**
* 载具尺寸
*/
private Integer vehicleSize = 0;
/**
* 总重量
*/
private BigDecimal weight = BigDecimal.ZERO;
public String getTaskId() {
return taskId;
}
public void setTaskId(String taskId) {
this.taskId = taskId;
}
public Integer getTaskType() {
return taskType;
}
public void setTaskType(Integer taskType) {
this.taskType = taskType;
}
public Integer getPriority() {
return priority;
}
public void setPriority(Integer priority) {
this.priority = priority;
}
public String getOrigin() {
return origin;
}
public void setOrigin(String origin) {
this.origin = origin;
}
public String getMidpoint() {
return midpoint;
}
public void setMidpoint(String midpoint) {
this.midpoint = midpoint;
}
public String getDestination() {
return destination;
}
public void setDestination(String destination) {
this.destination = destination;
}
public String getVehicleNo() {
return vehicleNo;
}
public void setVehicleNo(String vehicleNo) {
this.vehicleNo = vehicleNo;
}
public Integer getVehicleSize() {
return vehicleSize;
}
public void setVehicleSize(Integer vehicleSize) {
this.vehicleSize = vehicleSize;
}
public BigDecimal getWeight() {
return weight;
}
public void setWeight(BigDecimal weight) {
this.weight = weight;
}
}

View File

@ -38,6 +38,12 @@
<groupId>com.ruoyi</groupId> <groupId>com.ruoyi</groupId>
<artifactId>ruoyi-system</artifactId> <artifactId>ruoyi-system</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-admin</artifactId>
<version>3.8.9</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>

View File

@ -1,11 +1,18 @@
package com.ruoyi.quartz.task; package com.ruoyi.quartz.task;
import com.alibaba.fastjson2.JSON;
import com.ruoyi.app.domain.AppTask; import com.ruoyi.app.domain.AppTask;
import com.ruoyi.app.domain.AppWcsTask; import com.ruoyi.app.domain.AppWcsTask;
import com.ruoyi.app.service.IAppTaskService; import com.ruoyi.app.service.IAppTaskService;
import com.ruoyi.app.service.IAppWcsTaskService; import com.ruoyi.app.service.IAppWcsTaskService;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.common.utils.uuid.IdUtils; import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.web.domain.WcsCommonResponse;
import com.ruoyi.web.domain.WcsStackerTaskRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -21,6 +28,10 @@ public class TaskExecutor {
private IAppTaskService appTaskService; private IAppTaskService appTaskService;
@Autowired @Autowired
private IAppWcsTaskService appWcsTaskService; private IAppWcsTaskService appWcsTaskService;
@Autowired
private ISysConfigService sysConfigService;
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
private final HashMap<Integer, Integer> taskTypeMap = new HashMap<Integer, Integer>() {{ private final HashMap<Integer, Integer> taskTypeMap = new HashMap<Integer, Integer>() {{
put(1, 1);// 入库 put(1, 1);// 入库
@ -67,7 +78,7 @@ public class TaskExecutor {
newWcsTask.setCreateTime(new Date()); newWcsTask.setCreateTime(new Date());
wcsTaskMap.put(appTask.getVehicleId(), newWcsTask); wcsTaskMap.put(appTask.getVehicleId(), newWcsTask);
// 更新wms任务信息 // 更新wms任务信息
appTask.setWcsTaskId(wcsTaskMap.get(appTask.getVehicleId()).getWcsTaskId()); appTask.setWcsTaskId(newWcsTask.getWcsTaskId());
appTask.setTaskStatus(1); appTask.setTaskStatus(1);
} }
// 更新wms任务 // 更新wms任务
@ -82,6 +93,66 @@ public class TaskExecutor {
* 任务状态为0 * 任务状态为0
*/ */
public void sendWcsTask() { public void sendWcsTask() {
// 查询出所有的待下发的wcs任务
AppWcsTask wcsTaskQuery = new AppWcsTask();
wcsTaskQuery.setWcsTaskStatus(0);
List<AppWcsTask> wcsTaskList = appWcsTaskService.selectAppWcsTaskList(wcsTaskQuery);
if (wcsTaskList == null || wcsTaskList.isEmpty()) {
// 没有待下发的任务跳过任务
return;
}
// 获取请求地址
String url = sysConfigService.selectConfigByKey("wcs.url");
if (StringUtils.isEmpty(url)) {
// 查询不到wcs任务发送地址
return;
}
for (AppWcsTask appWcsTask : wcsTaskList) {
// 添加wcs任务请求
WcsStackerTaskRequest wcsStackerTaskRequest = getWcsStackerTaskRequest(appWcsTask);
// 发送http请求---请求5次
for (int i = 0; i < 5; i++) {
try {
WcsCommonResponse wcsCommonResponse = JSON.parseObject(HttpUtils.sendPost(url, JSON.toJSONString(wcsStackerTaskRequest)), WcsCommonResponse.class);
if (wcsCommonResponse == null) {
continue;
}
if (wcsCommonResponse.getCode() == 0) {
// 返回ok
appWcsTask.setWcsTaskStatus(1);// 已经发送成功
} else {
// 返回error
appWcsTask.setWcsTaskStatus(999);// 任务异常
}
appWcsTask.setSendTime(new Date());
appWcsTaskService.updateAppWcsTask(appWcsTask);
// 请求成功不再发送
break;
} catch (Exception e) {
logger.error("任务发送异常。{}", JSON.toJSONString(e));
}
}
}
}
/**
* 创建wcs请求
* @param appWcsTask 任务
* @return 请求详情
*/
private WcsStackerTaskRequest getWcsStackerTaskRequest(AppWcsTask appWcsTask) {
WcsStackerTaskRequest wcsStackerTaskRequest = new WcsStackerTaskRequest();
wcsStackerTaskRequest.setTaskId(appWcsTask.getWcsTaskId());
wcsStackerTaskRequest.setTaskType(appWcsTask.getWcsTaskType());
wcsStackerTaskRequest.setPriority(appWcsTask.getTaskPriority());
wcsStackerTaskRequest.setOrigin(appWcsTask.getOrigin());
wcsStackerTaskRequest.setDestination(appWcsTask.getDestination());
wcsStackerTaskRequest.setVehicleNo(appWcsTask.getVehicleId());
return wcsStackerTaskRequest;
} }
} }