2024-07-16 15:12:27 +08:00
|
|
|
|
package com.wms.bussiness;
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson2.JSON;
|
2024-07-18 13:26:56 +08:00
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
2024-07-16 15:12:27 +08:00
|
|
|
|
import com.wms.constants.enums.*;
|
|
|
|
|
|
import com.wms.controller.BaseController;
|
|
|
|
|
|
import com.wms.entity.app.ResponseEntity;
|
|
|
|
|
|
import com.wms.entity.app.container.ContainerApiLocalResponse;
|
2024-07-18 13:26:56 +08:00
|
|
|
|
import com.wms.entity.app.container.CreateInstoreTaskRequest;
|
2024-07-16 15:12:27 +08:00
|
|
|
|
import com.wms.entity.app.container.SendContainerTaskRequest;
|
|
|
|
|
|
import com.wms.entity.app.wcs.WcsTask;
|
|
|
|
|
|
import com.wms.entity.table.*;
|
|
|
|
|
|
import com.wms.mapper.LocationMapper;
|
2024-07-17 10:48:44 +08:00
|
|
|
|
import com.wms.mapper.StockMapper;
|
2024-07-16 15:12:27 +08:00
|
|
|
|
import com.wms.mapper.TaskMapper;
|
2024-07-18 13:26:56 +08:00
|
|
|
|
import com.wms.mapper.VehicleMapper;
|
2024-07-16 15:12:27 +08:00
|
|
|
|
import com.wms.service.*;
|
|
|
|
|
|
import com.wms.utils.HttpUtils;
|
|
|
|
|
|
import com.wms.utils.StringUtils;
|
|
|
|
|
|
import com.wms.utils.storage.LocationUtils;
|
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 定期任务类
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Component
|
|
|
|
|
|
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
|
|
|
|
|
public class JobComponent extends BaseController {
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 任务服务
|
|
|
|
|
|
*/
|
|
|
|
|
|
private final TaskService taskService;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 任务 Mapper
|
|
|
|
|
|
*/
|
|
|
|
|
|
private final TaskMapper taskMapper;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 载具/料箱 服务
|
|
|
|
|
|
*/
|
|
|
|
|
|
private final VehicleService vehicleService;
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 库位服务
|
|
|
|
|
|
*/
|
|
|
|
|
|
private final LocationService locationService;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 库位 Mapper
|
|
|
|
|
|
*/
|
|
|
|
|
|
private final LocationMapper locationMapper;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 库位操作类
|
|
|
|
|
|
*/
|
|
|
|
|
|
private final LocationUtils locationUtils;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 站台服务
|
|
|
|
|
|
*/
|
|
|
|
|
|
private final StandService standService;
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 配置服务
|
|
|
|
|
|
*/
|
|
|
|
|
|
private final ConfigService configService;
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 库存服务
|
|
|
|
|
|
*/
|
|
|
|
|
|
private final StockService stockService;
|
|
|
|
|
|
private final TaskRecordService taskRecordService;
|
2024-07-17 10:48:44 +08:00
|
|
|
|
private final StockMapper stockMapper;
|
2024-07-18 13:26:56 +08:00
|
|
|
|
private final VehicleMapper vehicleMapper;
|
2024-07-16 15:12:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Scheduled(fixedDelay = 1000)
|
|
|
|
|
|
public void sendTasksToWcs() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
// 查找待下发的任务
|
|
|
|
|
|
Task taskForQuery = new Task();
|
|
|
|
|
|
taskForQuery.setTaskStatus(WmsTaskStatus.NEW.getCode());
|
|
|
|
|
|
List<Task> tasks = taskService.selTasks(taskForQuery);
|
|
|
|
|
|
if(tasks == null) {
|
|
|
|
|
|
logger.error("定时器下发任务发生异常,数据库查询任务列表失败");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
for(Task task : tasks){
|
2024-07-18 13:26:56 +08:00
|
|
|
|
if(task.getTaskType().equals(TaskType.IN.getCode())) {
|
2024-07-16 15:12:27 +08:00
|
|
|
|
sendTasksInToWcs(task);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-07-18 13:26:56 +08:00
|
|
|
|
if(task.getTaskType().equals(TaskType.OUT.getCode()) || task.getTaskType().equals(TaskType.INVENTORY.getCode())){
|
2024-07-16 15:12:27 +08:00
|
|
|
|
sendTasksOutToWcs(task);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(task.getTaskType().equals(TaskType.MOVE.getCode())){
|
|
|
|
|
|
sendTasksMoveToWcs(task);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}catch (Exception exception){
|
2024-07-18 13:26:56 +08:00
|
|
|
|
logger.error("定时器下发任务发生异常:{}", exception.toString());
|
2024-07-16 15:12:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 发送入库任务给WCS
|
|
|
|
|
|
* @param task 任务
|
|
|
|
|
|
*/
|
|
|
|
|
|
private void sendTasksInToWcs(Task task) {
|
2024-07-18 13:26:56 +08:00
|
|
|
|
try {
|
|
|
|
|
|
List<Location> thisLocations = locationService.selLocations(new Location(task.getDestination()));
|
|
|
|
|
|
if(thisLocations == null) {
|
|
|
|
|
|
logger.warn("下发入库任务查询库位详细信息失败,数据库网络连接异常,任务号:{}", task.getTaskId());
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(thisLocations.isEmpty()) {
|
|
|
|
|
|
logger.warn("下发入库任务查询库位详细信息异常,不存在详细信息,该库位可能不存在,任务号:{}", task.getTaskId());
|
|
|
|
|
|
Task taskForUpdate = new Task();
|
|
|
|
|
|
taskForUpdate.setTaskId(task.getTaskId());
|
|
|
|
|
|
taskForUpdate.setTaskStatus(WmsTaskStatus.EXCEPTION.getCode());
|
|
|
|
|
|
taskForUpdate.setRemark1("该库位不存在");
|
|
|
|
|
|
taskService.executeTask(taskForUpdate);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
Location thisLocation = thisLocations.get(0);
|
|
|
|
|
|
if(thisLocation.getAreaId() == 1){
|
|
|
|
|
|
List<WcsTask> request = new ArrayList<>();
|
|
|
|
|
|
// 创建发送的任务
|
|
|
|
|
|
WcsTask tempTask = new WcsTask();
|
|
|
|
|
|
tempTask.setTaskId(task.getTaskId());
|
|
|
|
|
|
tempTask.setTaskType(TaskType.IN.getCode());
|
|
|
|
|
|
tempTask.setOrigin(task.getOrigin());
|
|
|
|
|
|
tempTask.setDestination(task.getDestination());
|
|
|
|
|
|
tempTask.setVehicleNo(task.getVehicleNo());
|
|
|
|
|
|
tempTask.setVehicleSize(1);
|
|
|
|
|
|
tempTask.setWeight(task.getWeight() == null ? 0 : task.getWeight());
|
|
|
|
|
|
tempTask.setPriority(task.getTaskPriority());
|
|
|
|
|
|
request.add(tempTask);
|
|
|
|
|
|
// 发送任务
|
|
|
|
|
|
ResponseEntity result = JSON.parseObject(HttpUtils.sendHttpPostWithoutToken(UrlEnums.URL_WMS_TO_WCS_SEND_TASK.getValue(), JSON.toJSONString(request)), ResponseEntity.class);
|
|
|
|
|
|
if (result != null && Objects.equals(ResponseCode.OK.getCode(), result.getCode())) {
|
|
|
|
|
|
logger.info("下发立库入库任务成功,任务ID:{},任务信息:{}", tempTask.getTaskId(), JSON.toJSONString(request));
|
|
|
|
|
|
Task taskForUpdate = new Task();
|
|
|
|
|
|
taskForUpdate.setTaskId(task.getTaskId());
|
|
|
|
|
|
taskForUpdate.setTaskStatus(WmsTaskStatus.WAIT.getCode());
|
|
|
|
|
|
taskService.executeTask(taskForUpdate);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
logger.info("下发立库入库任务失败,任务ID:{},信息:{}", tempTask.getTaskId(), JSON.toJSONString(result));
|
|
|
|
|
|
}
|
|
|
|
|
|
// else { //四向车库
|
|
|
|
|
|
// //List<WcsTask> request = new ArrayList<>();
|
|
|
|
|
|
// // 创建发送的任务
|
|
|
|
|
|
// String uuid = UUID.randomUUID().toString();
|
|
|
|
|
|
// CreateInstoreTaskRequest request = new CreateInstoreTaskRequest();
|
|
|
|
|
|
// request.setRequestId(uuid);
|
|
|
|
|
|
// request.setKey(StringUtils.containerMd5(uuid).toUpperCase());
|
|
|
|
|
|
// request.setPalletNo(task.getVehicleNo());
|
|
|
|
|
|
// request.setHeight("0");
|
|
|
|
|
|
// request.setWeight("0");
|
|
|
|
|
|
// request.setFromCellNo(task.getOrigin());
|
|
|
|
|
|
// // 发送任务
|
|
|
|
|
|
// String requestString = JSON.toJSONString(request);
|
|
|
|
|
|
// String responseString = HttpUtils.sendHttpPostWithoutToken(UrlEnums.URL_WMS_TO_WCS_CONTAINERIN_TASK.getValue(), requestString);
|
|
|
|
|
|
// if (responseString == null || responseString.isEmpty()) {
|
|
|
|
|
|
// logger.error("Response string is null or empty");
|
|
|
|
|
|
// }
|
|
|
|
|
|
// ContainerApiLocalResponse result = JSON.parseObject(responseString, ContainerApiLocalResponse.class);
|
|
|
|
|
|
// if (result != null && result.getCode().equals("200")) {
|
|
|
|
|
|
// logger.info("下发托盘库入库任务成功,任务ID:{}", task.getTaskId());
|
|
|
|
|
|
// Task taskForUpdate = new Task();
|
|
|
|
|
|
// taskForUpdate.setTaskId(task.getTaskId());
|
|
|
|
|
|
// taskForUpdate.setTaskStatus(WmsTaskStatus.WAIT.getCode());
|
|
|
|
|
|
// taskService.executeTask(taskForUpdate);
|
|
|
|
|
|
// return;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// logger.info("下发托盘库入库任务失败,任务ID:{},信息:{}", task.getTaskId(), JSON.toJSONString(result));
|
|
|
|
|
|
// }
|
|
|
|
|
|
}catch (Exception exception){
|
|
|
|
|
|
logger.error("下发入库任务发生异常:{}", exception.toString());
|
2024-07-16 15:12:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 发送出库任务给WCS
|
|
|
|
|
|
* @param task 任务
|
|
|
|
|
|
*/
|
|
|
|
|
|
private void sendTasksOutToWcs(Task task) {
|
|
|
|
|
|
/* 检查该库位前一个深度是否存在库存,若存在库存则生成一个移库任务,此任务暂不下发 */
|
|
|
|
|
|
List<Location> thisLocations = locationService.selLocations(new Location(task.getOrigin()));
|
|
|
|
|
|
if(thisLocations == null) {
|
|
|
|
|
|
logger.warn("下发出库任务查询库位详细信息失败,数据库网络连接异常,任务号:{}", task.getTaskId());
|
2024-07-18 13:26:56 +08:00
|
|
|
|
logger.info("下发出库任务查询库位详细信息失败,数据库网络连接异常");
|
2024-07-16 15:12:27 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(thisLocations.isEmpty()) {
|
|
|
|
|
|
logger.warn("下发出库任务查询库位详细信息异常,不存在详细信息,该库位可能不存在,任务号:{}", task.getTaskId());
|
2024-07-18 13:26:56 +08:00
|
|
|
|
logger.info("下发出库任务查询库位详细信息异常,不存在详细信息,该库位可能不存在");
|
2024-07-16 15:12:27 +08:00
|
|
|
|
Task taskForUpdate = new Task();
|
|
|
|
|
|
taskForUpdate.setTaskId(task.getTaskId());
|
|
|
|
|
|
taskForUpdate.setTaskStatus(WmsTaskStatus.EXCEPTION.getCode());
|
|
|
|
|
|
taskForUpdate.setRemark1("该库位不存在");
|
|
|
|
|
|
taskService.executeTask(taskForUpdate);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
Location thisLocation = thisLocations.get(0); // 找出当前库位详细信息
|
|
|
|
|
|
int depth = thisLocation.getDepth();
|
|
|
|
|
|
while (depth > 1) {
|
|
|
|
|
|
depth--;
|
|
|
|
|
|
/* 检查该库位有没有任务,若有则退出函数,若没有则检查有没有库存,若没有库存则继续,若有库存则生成一个移库任务,生成之后退出函数 */
|
|
|
|
|
|
Location beforLocationsQuery = new Location();
|
2024-07-18 13:26:56 +08:00
|
|
|
|
// logger.info("{},{},{},{},{}",thisLocation.getAreaId(),thisLocation.getQueue(),thisLocation.getLine(),thisLocation.getLayer(),depth);
|
2024-07-16 15:12:27 +08:00
|
|
|
|
beforLocationsQuery.setAreaId(thisLocation.getAreaId());
|
2025-02-23 14:39:37 +08:00
|
|
|
|
beforLocationsQuery.setTunnelId(thisLocation.getTunnelId());
|
|
|
|
|
|
beforLocationsQuery.setQueue(thisLocation.getQueue());
|
2024-07-16 15:12:27 +08:00
|
|
|
|
beforLocationsQuery.setLayer(thisLocation.getLayer());
|
2024-07-18 13:26:56 +08:00
|
|
|
|
beforLocationsQuery.setLocationType(1);
|
2024-07-16 15:12:27 +08:00
|
|
|
|
beforLocationsQuery.setDepth(depth);
|
|
|
|
|
|
List<Location> beforLocations = locationService.selLocations(beforLocationsQuery);
|
|
|
|
|
|
if(beforLocations == null) {
|
|
|
|
|
|
logger.warn("下发出库任务查询库位详细信息失败,数据库网络连接异常,任务号:{}", task.getTaskId());
|
2024-07-18 13:26:56 +08:00
|
|
|
|
logger.info("下发出库任务查询库位详细信息失败,数据库网络连接异常");
|
2024-07-16 15:12:27 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(beforLocations.isEmpty()) {
|
2024-07-18 13:26:56 +08:00
|
|
|
|
logger.info("beforLocations.isEmpty()");
|
2024-07-16 15:12:27 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
Location beforLocation = beforLocations.get(0); // 前一个库位
|
|
|
|
|
|
List<Task> notCompleteTasks = taskMapper.haveNotCompleteTask(beforLocation.getLocationId());
|
|
|
|
|
|
if(notCompleteTasks == null) {
|
2024-07-18 13:26:56 +08:00
|
|
|
|
logger.info("notCompleteTasks为null");
|
2024-07-16 15:12:27 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(!notCompleteTasks.isEmpty()) {
|
2024-07-18 13:26:56 +08:00
|
|
|
|
logger.info("存在未完成的任务,退出函数");
|
2024-07-16 15:12:27 +08:00
|
|
|
|
return; // 存在未完成的任务,退出函数
|
|
|
|
|
|
}
|
2024-07-18 13:26:56 +08:00
|
|
|
|
// 检查是否有库存,因为存在空框所以不在库存表中检验
|
|
|
|
|
|
Vehicle nextVehicle = new Vehicle();
|
|
|
|
|
|
nextVehicle.setCurrentLocation(beforLocation.getLocationId());
|
|
|
|
|
|
List<Vehicle> beforVehicleCheckIfEmpty = vehicleMapper.selVehicles(nextVehicle);
|
|
|
|
|
|
if(beforVehicleCheckIfEmpty == null) {
|
|
|
|
|
|
logger.info("beforLocationsCheckIfEmpty == null");
|
2024-07-16 15:12:27 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-07-18 13:26:56 +08:00
|
|
|
|
if(beforVehicleCheckIfEmpty.isEmpty()) {
|
|
|
|
|
|
logger.info("位置{}没有框",beforLocation.getLocationId());
|
2024-07-16 15:12:27 +08:00
|
|
|
|
continue; // 没有库存,继续
|
|
|
|
|
|
}
|
|
|
|
|
|
/* 生成一个移库任务 */
|
|
|
|
|
|
/* 查找一个空库位 */
|
|
|
|
|
|
Location emptyLocation = new Location();
|
|
|
|
|
|
emptyLocation.setLocationStatus(LocationStatus.EMPTY.getCode());
|
|
|
|
|
|
emptyLocation.setAreaId(beforLocation.getAreaId());
|
|
|
|
|
|
List<Location> emptyLocations = locationMapper.selLocations(emptyLocation);
|
|
|
|
|
|
if(emptyLocations == null) {
|
2024-07-18 13:26:56 +08:00
|
|
|
|
logger.info("emptyLocations == null");
|
2024-07-16 15:12:27 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(emptyLocations.isEmpty()){
|
2024-07-18 13:26:56 +08:00
|
|
|
|
logger.warn("移库没有可用库位,任务号:{}", task.getTaskId());
|
|
|
|
|
|
logger.info("移库没有可用库位");
|
2024-07-16 15:12:27 +08:00
|
|
|
|
return; // 移库没有可用库位
|
|
|
|
|
|
}
|
|
|
|
|
|
Location emptyLocationItem = locationUtils.checkCanUse(emptyLocations); // 取得新库位
|
|
|
|
|
|
if(emptyLocationItem == null) {
|
2024-07-18 13:26:56 +08:00
|
|
|
|
logger.info("emptyLocationItem == null");
|
2024-07-16 15:12:27 +08:00
|
|
|
|
return; // 没有可用库位或者m库位存在干涉
|
|
|
|
|
|
}
|
2024-07-17 10:48:44 +08:00
|
|
|
|
// 锁定旧库位库存
|
|
|
|
|
|
stockMapper.updateStockStatusWithLocationId(beforLocation.getLocationId(), StockStatus.LOCK.getCode());
|
|
|
|
|
|
// 锁定新库位
|
|
|
|
|
|
Location locationForUpdate = new Location();
|
|
|
|
|
|
locationForUpdate.setLocationId(emptyLocationItem.getLocationId());
|
|
|
|
|
|
locationForUpdate.setLocationStatus(LocationStatus.OCCUPY.getCode());
|
|
|
|
|
|
locationMapper.modifyLocation(locationForUpdate);
|
2024-07-18 13:26:56 +08:00
|
|
|
|
|
|
|
|
|
|
//创建移库任务
|
2024-07-16 15:12:27 +08:00
|
|
|
|
Task moveTask = new Task();
|
2024-07-18 13:26:56 +08:00
|
|
|
|
moveTask.setTaskId(String.valueOf(Calendar.getInstance().getTimeInMillis()));
|
2024-07-16 15:12:27 +08:00
|
|
|
|
moveTask.setTaskType(TaskType.MOVE.getCode());
|
2024-07-18 13:26:56 +08:00
|
|
|
|
moveTask.setTaskGroup(task.getTaskGroup());
|
|
|
|
|
|
moveTask.setTaskStatus(OrderOutStatusEnum.CREATED.getCode());
|
2024-07-16 15:12:27 +08:00
|
|
|
|
moveTask.setOrigin(beforLocation.getLocationId());
|
|
|
|
|
|
moveTask.setDestination(emptyLocationItem.getLocationId());
|
2024-07-18 13:26:56 +08:00
|
|
|
|
moveTask.setPickStand(null);
|
2024-07-16 15:12:27 +08:00
|
|
|
|
moveTask.setWeight(0.0);
|
2024-07-18 13:26:56 +08:00
|
|
|
|
moveTask.setVehicleNo(beforVehicleCheckIfEmpty.get(0).getVehicleId());
|
|
|
|
|
|
moveTask.setCreateTime(new Date());
|
|
|
|
|
|
moveTask.setUserName("WMS");
|
|
|
|
|
|
if(depth == 2){
|
|
|
|
|
|
moveTask.setTaskPriority(8);
|
|
|
|
|
|
} else if (depth == 1) {
|
|
|
|
|
|
moveTask.setTaskPriority(9);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (beforVehicleCheckIfEmpty.get(0).getIsEmpty() == 1){
|
|
|
|
|
|
moveTask.setRemark1("空框");
|
|
|
|
|
|
}else {
|
|
|
|
|
|
moveTask.setRemark1("带料");
|
|
|
|
|
|
}
|
|
|
|
|
|
int a = taskService.addTask(moveTask);
|
|
|
|
|
|
if (a == 1 && depth == 2){
|
|
|
|
|
|
logger.info("生成移库任务成功,任务号:{}", moveTask.getTaskId());
|
|
|
|
|
|
continue;
|
|
|
|
|
|
} else if (a == 1 && depth == 1) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
logger.info("生成移库任务失败,任务号:{}", moveTask.getTaskId());
|
|
|
|
|
|
}
|
2024-07-16 15:12:27 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(thisLocation.getAreaId() == 1) { // 宝开立库
|
|
|
|
|
|
List<WcsTask> request = new ArrayList<>();
|
|
|
|
|
|
// 创建发送的任务
|
|
|
|
|
|
WcsTask tempTask = new WcsTask();
|
2024-07-18 13:26:56 +08:00
|
|
|
|
tempTask.setTaskId(task.getTaskId());
|
2024-07-16 15:12:27 +08:00
|
|
|
|
tempTask.setTaskType(TaskType.OUT.getCode());
|
|
|
|
|
|
tempTask.setOrigin(task.getOrigin());
|
|
|
|
|
|
tempTask.setDestination(task.getDestination());
|
|
|
|
|
|
tempTask.setVehicleNo(task.getVehicleNo());
|
|
|
|
|
|
tempTask.setVehicleSize(1);
|
|
|
|
|
|
tempTask.setWeight(task.getWeight() == null ? 0 : task.getWeight());
|
|
|
|
|
|
tempTask.setPriority(task.getTaskPriority());
|
|
|
|
|
|
request.add(tempTask);
|
|
|
|
|
|
// 发送任务
|
|
|
|
|
|
ResponseEntity result = JSON.parseObject(HttpUtils.sendHttpPostWithoutToken(UrlEnums.URL_WMS_TO_WCS_SEND_TASK.getValue(), JSON.toJSONString(request)), ResponseEntity.class);
|
|
|
|
|
|
if (result != null && Objects.equals(ResponseCode.OK.getCode(), result.getCode())) {
|
|
|
|
|
|
logger.info("下发立库出库任务成功,任务ID:{}", tempTask.getTaskId());
|
|
|
|
|
|
Task taskForUpdate = new Task();
|
|
|
|
|
|
taskForUpdate.setTaskId(task.getTaskId());
|
|
|
|
|
|
taskForUpdate.setTaskStatus(WmsTaskStatus.WAIT.getCode());
|
|
|
|
|
|
taskService.executeTask(taskForUpdate);
|
2024-07-18 13:26:56 +08:00
|
|
|
|
return;
|
2024-07-16 15:12:27 +08:00
|
|
|
|
}
|
2024-07-18 13:26:56 +08:00
|
|
|
|
logger.info("下发立库出库任务失败,任务ID:{},信息:{},result结果:{}", tempTask.getTaskId(), JSON.toJSONString(result),result.getCode());
|
2024-07-16 15:12:27 +08:00
|
|
|
|
} else { // 四向车库
|
|
|
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
|
|
|
SendContainerTaskRequest request = new SendContainerTaskRequest();
|
|
|
|
|
|
request.setRequestid(uuid);
|
|
|
|
|
|
request.setKey(StringUtils.containerMd5(uuid).toUpperCase());
|
|
|
|
|
|
request.setWmstaskid(task.getTaskId());
|
|
|
|
|
|
request.setPalletno(task.getVehicleNo());
|
|
|
|
|
|
request.setTasktype("2"); // 出库
|
|
|
|
|
|
request.setFromcellno(task.getOrigin());
|
2024-07-18 13:26:56 +08:00
|
|
|
|
request.setTocellno("111"); // ???????
|
2024-07-16 15:12:27 +08:00
|
|
|
|
String requestString = JSON.toJSONString(request);
|
|
|
|
|
|
String responseString = HttpUtils.sendHttpPostWithoutToken(UrlEnums.URL_WMS_TO_WCS_CONTAINER_TASK.getValue(), requestString);
|
2024-07-18 13:26:56 +08:00
|
|
|
|
//JSONObject jsonResponse = JSON.parseObject(responseString);
|
2024-07-16 15:12:27 +08:00
|
|
|
|
ContainerApiLocalResponse result = JSON.parseObject(responseString, ContainerApiLocalResponse.class);
|
|
|
|
|
|
if(result != null && result.getCode().equals("200")) {
|
|
|
|
|
|
logger.info("下发四向车出库任务成功,任务ID:{}", task.getTaskId());
|
|
|
|
|
|
Task taskForUpdate = new Task();
|
|
|
|
|
|
taskForUpdate.setTaskId(task.getTaskId());
|
|
|
|
|
|
taskForUpdate.setTaskStatus(WmsTaskStatus.WAIT.getCode());
|
|
|
|
|
|
taskService.executeTask(taskForUpdate);
|
2024-07-18 13:26:56 +08:00
|
|
|
|
return;
|
2024-07-16 15:12:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
logger.info("下发四向车出库任务失败,任务ID:{},信息:{}", task.getTaskId(), JSON.toJSONString(result));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 发送移库任务给WCS
|
|
|
|
|
|
* @param task 任务
|
|
|
|
|
|
*/
|
2024-07-18 13:26:56 +08:00
|
|
|
|
private void sendTasksMoveToWcs(Task task){
|
|
|
|
|
|
/* 检查该库位前一个深度是否存在库存,若存在库存则生成一个移库任务,此任务暂不下发 */
|
|
|
|
|
|
List<Location> thisLocations = locationService.selLocations(new Location(task.getOrigin()));
|
|
|
|
|
|
if(thisLocations == null) {
|
|
|
|
|
|
logger.info("下发移库任务查询库位详细信息失败,数据库网络连接异常");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(thisLocations.isEmpty()) {
|
|
|
|
|
|
logger.info("下发移库任务查询库位详细信息异常,不存在详细信息,该库位可能不存在");
|
|
|
|
|
|
Task taskForUpdate = new Task();
|
|
|
|
|
|
taskForUpdate.setTaskId(task.getTaskId());
|
|
|
|
|
|
taskForUpdate.setTaskStatus(WmsTaskStatus.EXCEPTION.getCode());
|
|
|
|
|
|
taskForUpdate.setRemark1("该库位不存在");
|
|
|
|
|
|
taskService.executeTask(taskForUpdate);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
Location thisLocation = thisLocations.get(0); // 找出当前库位详细信息
|
|
|
|
|
|
int depth = thisLocation.getDepth();
|
|
|
|
|
|
while (depth > 1) {
|
|
|
|
|
|
depth--;
|
|
|
|
|
|
/* 检查该库位有没有任务,若有则退出函数,若没有则检查有没有库存,若没有库存则继续,若有库存则生成一个移库任务,生成之后退出函数 */
|
|
|
|
|
|
Location beforLocationsQuery = new Location();
|
|
|
|
|
|
// logger.info("{},{},{},{},{}",thisLocation.getAreaId(),thisLocation.getQueue(),thisLocation.getLine(),thisLocation.getLayer(),depth);
|
|
|
|
|
|
beforLocationsQuery.setAreaId(thisLocation.getAreaId());
|
|
|
|
|
|
//beforLocationsQuery.setQueue(thisLocation.getQueue());
|
|
|
|
|
|
beforLocationsQuery.setLine(thisLocation.getLine());
|
|
|
|
|
|
beforLocationsQuery.setLayer(thisLocation.getLayer());
|
|
|
|
|
|
beforLocationsQuery.setLocationType(1);
|
|
|
|
|
|
beforLocationsQuery.setDepth(depth);
|
|
|
|
|
|
List<Location> beforLocations = locationService.selLocations(beforLocationsQuery);
|
|
|
|
|
|
if (beforLocations == null) {
|
|
|
|
|
|
logger.info("下发移库任务查询库位详细信息失败,数据库网络连接异常");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (beforLocations.isEmpty()) {
|
|
|
|
|
|
logger.info(".isEmpty()");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
Location beforLocation = beforLocations.get(0); // 前一个库位
|
|
|
|
|
|
List<Task> notCompleteTasks = taskMapper.haveNotCompleteTask(beforLocation.getLocationId());
|
|
|
|
|
|
if (notCompleteTasks == null) {
|
|
|
|
|
|
logger.info("eteTasks为null");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!notCompleteTasks.isEmpty()) {
|
|
|
|
|
|
return; // 存在未完成的任务,退出函数
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
logger.info("开始发送移库任务给WCS,任务号:{}", task.getTaskId());
|
|
|
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
|
|
|
SendContainerTaskRequest request = new SendContainerTaskRequest();
|
|
|
|
|
|
request.setRequestid(uuid);
|
|
|
|
|
|
request.setKey(StringUtils.containerMd5(uuid).toUpperCase());
|
|
|
|
|
|
request.setWmstaskid(task.getTaskId());
|
|
|
|
|
|
request.setPalletno(task.getVehicleNo());
|
|
|
|
|
|
request.setTasktype("3"); // 移库
|
|
|
|
|
|
request.setFromcellno(task.getOrigin());
|
|
|
|
|
|
request.setTocellno(task.getDestination());
|
|
|
|
|
|
String requestString = JSON.toJSONString(request);
|
|
|
|
|
|
String responseString = HttpUtils.sendHttpPostWithoutToken(UrlEnums.URL_WMS_TO_WCS_CONTAINER_TASK.getValue(), requestString);
|
|
|
|
|
|
ContainerApiLocalResponse result = JSON.parseObject(responseString, ContainerApiLocalResponse.class);
|
|
|
|
|
|
if(result != null && result.getCode().equals("200")) {
|
|
|
|
|
|
logger.info("下发四向车移库任务成功,任务ID:{}", task.getTaskId());
|
|
|
|
|
|
Task taskForUpdate = new Task();
|
|
|
|
|
|
taskForUpdate.setTaskId(task.getTaskId());
|
|
|
|
|
|
taskForUpdate.setTaskStatus(WmsTaskStatus.WAIT.getCode());
|
|
|
|
|
|
taskService.executeTask(taskForUpdate);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
logger.info("下发四向车移库任务失败,任务ID:{},信息:{}", task.getTaskId(), JSON.toJSONString(result));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void sendTasksMoveToWcs1(Task task) {
|
2024-07-16 15:12:27 +08:00
|
|
|
|
/* 检查该库位前一个深度是否存在库存,若存在库存则生成一个移库任务,此任务暂不下发 */
|
|
|
|
|
|
List<Location> thisLocations = locationService.selLocations(new Location(task.getOrigin()));
|
|
|
|
|
|
if(thisLocations == null) {
|
|
|
|
|
|
logger.warn("下发移库任务查询库位详细信息失败,数据库网络连接异常,任务号:{}", task.getTaskId());
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(thisLocations.isEmpty()) {
|
|
|
|
|
|
logger.warn("下发移库任务查询库位详细信息异常,不存在详细信息,该库位可能不存在,任务号:{}", task.getTaskId());
|
|
|
|
|
|
Task taskForUpdate = new Task();
|
|
|
|
|
|
taskForUpdate.setTaskId(task.getTaskId());
|
|
|
|
|
|
taskForUpdate.setTaskStatus(WmsTaskStatus.EXCEPTION.getCode());
|
|
|
|
|
|
taskForUpdate.setRemark1("该库位不存在");
|
|
|
|
|
|
taskService.executeTask(taskForUpdate);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
Location thisLocation = thisLocations.get(0); // 找出当前库位详细信息
|
|
|
|
|
|
int depth = thisLocation.getDepth();
|
|
|
|
|
|
while (depth > 1) {
|
|
|
|
|
|
depth--;
|
|
|
|
|
|
/* 检查该库位有没有任务,若有则退出函数,若没有则检查有没有库存,若没有库存则继续,若有库存则生成一个移库任务,生成之后退出函数 */
|
|
|
|
|
|
Location beforLocationsQuery = new Location();
|
|
|
|
|
|
beforLocationsQuery.setAreaId(thisLocation.getAreaId());
|
|
|
|
|
|
beforLocationsQuery.setQueue(thisLocation.getQueue());
|
|
|
|
|
|
beforLocationsQuery.setLine(thisLocation.getLine());
|
|
|
|
|
|
beforLocationsQuery.setLayer(thisLocation.getLayer());
|
|
|
|
|
|
beforLocationsQuery.setDepth(depth);
|
|
|
|
|
|
List<Location> beforLocations = locationService.selLocations(beforLocationsQuery);
|
|
|
|
|
|
if(beforLocations == null) {
|
|
|
|
|
|
logger.warn("下发移库任务查询库位详细信息失败,数据库网络连接异常,任务号:{}", task.getTaskId());
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(beforLocations.isEmpty()) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
Location beforLocation = beforLocations.get(0); // 前一个库位
|
|
|
|
|
|
List<Task> notCompleteTasks = taskMapper.haveNotCompleteTask(beforLocation.getLocationId());
|
|
|
|
|
|
if(notCompleteTasks == null) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-07-18 13:26:56 +08:00
|
|
|
|
for(Task notCompleteTask : notCompleteTasks) {
|
|
|
|
|
|
String taskId = notCompleteTask.getTaskId();
|
|
|
|
|
|
if(!taskId.equals(task.getTaskId())) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-07-16 15:12:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
// 检查是否有库存、
|
|
|
|
|
|
Stock stockQuery = new Stock();
|
|
|
|
|
|
stockQuery.setLocationId(beforLocation.getLocationId());
|
|
|
|
|
|
List<Stock> stocks = stockService.selStocks(stockQuery);
|
|
|
|
|
|
if(stocks == null) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(stocks.isEmpty()) {
|
|
|
|
|
|
continue; // 没有库存,继续
|
|
|
|
|
|
}
|
|
|
|
|
|
/* 生成一个移库任务 */
|
|
|
|
|
|
/* 查找一个空库位 */
|
|
|
|
|
|
Location emptyLocation = new Location();
|
|
|
|
|
|
emptyLocation.setLocationStatus(LocationStatus.EMPTY.getCode());
|
|
|
|
|
|
emptyLocation.setAreaId(beforLocation.getAreaId());
|
|
|
|
|
|
List<Location> emptyLocations = locationMapper.selLocations(emptyLocation);
|
|
|
|
|
|
if(emptyLocations == null) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(emptyLocations.isEmpty()){
|
|
|
|
|
|
return; // 移库没有可用库位
|
|
|
|
|
|
}
|
|
|
|
|
|
Location emptyLocationItem = locationUtils.checkCanUse(emptyLocations); // 取得新库位
|
|
|
|
|
|
if(emptyLocationItem == null) {
|
|
|
|
|
|
return; // 没有可用库位或者m库位存在干涉
|
|
|
|
|
|
}
|
2024-07-17 10:48:44 +08:00
|
|
|
|
// 锁定旧库位库存
|
|
|
|
|
|
stockMapper.updateStockStatusWithLocationId(beforLocation.getLocationId(), StockStatus.LOCK.getCode());
|
|
|
|
|
|
// 锁定新库位
|
|
|
|
|
|
Location locationForUpdate = new Location();
|
|
|
|
|
|
locationForUpdate.setLocationId(emptyLocationItem.getLocationId());
|
|
|
|
|
|
locationForUpdate.setLocationStatus(LocationStatus.OCCUPY.getCode());
|
|
|
|
|
|
locationMapper.modifyLocation(locationForUpdate);
|
2024-07-16 15:12:27 +08:00
|
|
|
|
// 构造移库任务
|
|
|
|
|
|
Task moveTask = new Task();
|
|
|
|
|
|
moveTask.setTaskId(UUID.randomUUID().toString());
|
|
|
|
|
|
moveTask.setTaskGroup(task.getTaskGroup());
|
|
|
|
|
|
moveTask.setTaskType(TaskType.MOVE.getCode());
|
|
|
|
|
|
moveTask.setOrigin(beforLocation.getLocationId());
|
|
|
|
|
|
moveTask.setDestination(emptyLocationItem.getLocationId());
|
|
|
|
|
|
moveTask.setVehicleNo(stocks.get(0).getVehicleId());
|
|
|
|
|
|
moveTask.setVehicleSize(0);
|
|
|
|
|
|
moveTask.setWeight(0.0);
|
|
|
|
|
|
moveTask.setTaskPriority(9);
|
|
|
|
|
|
moveTask.setTaskStatus(WmsTaskStatus.NEW.getCode());
|
|
|
|
|
|
taskService.addTask(moveTask);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(thisLocation.getAreaId() == 1) { // 宝开立库
|
|
|
|
|
|
List<WcsTask> request = new ArrayList<>();
|
|
|
|
|
|
// 创建发送的任务
|
|
|
|
|
|
WcsTask tempTask = new WcsTask();
|
2024-07-18 13:26:56 +08:00
|
|
|
|
tempTask.setTaskId(task.getTaskId());
|
2024-07-16 15:12:27 +08:00
|
|
|
|
tempTask.setTaskType(TaskType.MOVE.getCode());
|
|
|
|
|
|
tempTask.setOrigin(task.getOrigin());
|
|
|
|
|
|
tempTask.setDestination(task.getDestination());
|
|
|
|
|
|
tempTask.setVehicleNo(task.getVehicleNo());
|
|
|
|
|
|
tempTask.setVehicleSize(1);
|
|
|
|
|
|
tempTask.setWeight(task.getWeight() == null ? 0 : task.getWeight());
|
|
|
|
|
|
tempTask.setPriority(task.getTaskPriority());
|
|
|
|
|
|
request.add(tempTask);
|
|
|
|
|
|
// 发送任务
|
|
|
|
|
|
ResponseEntity result = JSON.parseObject(HttpUtils.sendHttpPostWithoutToken(UrlEnums.URL_WMS_TO_WCS_SEND_TASK.getValue(), JSON.toJSONString(request)), ResponseEntity.class);
|
|
|
|
|
|
if (result != null && Objects.equals(ResponseCode.OK.getCode(), result.getCode())) {
|
|
|
|
|
|
logger.info("下发立库移库任务成功,任务ID:{}", tempTask.getTaskId());
|
|
|
|
|
|
Task taskForUpdate = new Task();
|
|
|
|
|
|
taskForUpdate.setTaskId(task.getTaskId());
|
|
|
|
|
|
taskForUpdate.setTaskStatus(WmsTaskStatus.WAIT.getCode());
|
|
|
|
|
|
taskService.executeTask(taskForUpdate);
|
2024-07-18 13:26:56 +08:00
|
|
|
|
return;
|
2024-07-16 15:12:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
logger.info("下发立库移库任务失败,任务ID:{},信息:{}", tempTask.getTaskId(), JSON.toJSONString(result));
|
|
|
|
|
|
} else {
|
|
|
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
|
|
|
SendContainerTaskRequest request = new SendContainerTaskRequest();
|
|
|
|
|
|
request.setRequestid(uuid);
|
|
|
|
|
|
request.setKey(StringUtils.containerMd5(uuid).toUpperCase());
|
|
|
|
|
|
request.setWmstaskid(task.getTaskId());
|
|
|
|
|
|
request.setPalletno(task.getVehicleNo());
|
|
|
|
|
|
request.setTasktype("3"); // 移库
|
|
|
|
|
|
request.setFromcellno(task.getOrigin());
|
|
|
|
|
|
request.setTocellno(task.getDestination());
|
|
|
|
|
|
String requestString = JSON.toJSONString(request);
|
|
|
|
|
|
String responseString = HttpUtils.sendHttpPostWithoutToken(UrlEnums.URL_WMS_TO_WCS_CONTAINER_TASK.getValue(), requestString);
|
|
|
|
|
|
ContainerApiLocalResponse result = JSON.parseObject(responseString, ContainerApiLocalResponse.class);
|
|
|
|
|
|
if(result != null && result.getCode().equals("200")) {
|
2024-07-18 13:26:56 +08:00
|
|
|
|
// logger.info("下发四向车移库任务成功,任务ID:{}", task.getTaskId());
|
2024-07-16 15:12:27 +08:00
|
|
|
|
Task taskForUpdate = new Task();
|
|
|
|
|
|
taskForUpdate.setTaskId(task.getTaskId());
|
|
|
|
|
|
taskForUpdate.setTaskStatus(WmsTaskStatus.WAIT.getCode());
|
|
|
|
|
|
taskService.executeTask(taskForUpdate);
|
2024-07-18 13:26:56 +08:00
|
|
|
|
return;
|
2024-07-16 15:12:27 +08:00
|
|
|
|
}
|
2024-07-18 13:26:56 +08:00
|
|
|
|
// logger.info("下发四向车移库任务失败,任务ID:{},信息:{}", task.getTaskId(), JSON.toJSONString(result));
|
2024-07-16 15:12:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 每隔一秒检索一遍任务列表,同时向WCS下发任务
|
|
|
|
|
|
*/
|
|
|
|
|
|
// @Scheduled(fixedDelay = 1000)
|
|
|
|
|
|
public void executeTasks() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
// 检索任务列表,查询状态为等待状态的任务
|
|
|
|
|
|
Task taskForQuery = new Task();
|
|
|
|
|
|
taskForQuery.setTaskStatus(WmsTaskStatus.NEW.getCode());
|
|
|
|
|
|
List<Task> tasks = taskService.selTasks(taskForQuery);
|
|
|
|
|
|
// 相同任务组的任务只发一次
|
|
|
|
|
|
List<String> taskGroupIds = new LinkedList<>();
|
|
|
|
|
|
List<WcsTask> request = new ArrayList<>();
|
|
|
|
|
|
if (!tasks.isEmpty()) {// 存在等待中的任务
|
|
|
|
|
|
for (Task task : tasks) {
|
|
|
|
|
|
if (taskGroupIds.contains(task.getTaskGroup())) {// 该taskGroup的任务已经发送过
|
|
|
|
|
|
task.setTaskStatus(WmsTaskStatus.WAIT.getCode());
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
// 创建发送的任务
|
|
|
|
|
|
WcsTask tempTask = new WcsTask();
|
|
|
|
|
|
tempTask.setTaskId(task.getTaskGroup());
|
|
|
|
|
|
if (TaskType.OUT.getCode().equals(task.getTaskType()) || TaskType.INVENTORY.getCode().equals(task.getTaskType())) {
|
|
|
|
|
|
tempTask.setTaskType(TaskType.OUT.getCode());
|
|
|
|
|
|
} else {
|
|
|
|
|
|
tempTask.setTaskType(TaskType.IN.getCode());
|
|
|
|
|
|
}
|
|
|
|
|
|
tempTask.setOrigin(task.getOrigin());
|
|
|
|
|
|
tempTask.setDestination(task.getDestination());
|
|
|
|
|
|
tempTask.setVehicleNo(task.getVehicleNo());
|
|
|
|
|
|
tempTask.setVehicleSize(1);
|
|
|
|
|
|
tempTask.setWeight(task.getWeight() == null ? 0 : task.getWeight());
|
|
|
|
|
|
tempTask.setPriority(task.getTaskPriority());
|
|
|
|
|
|
request.add(tempTask);
|
|
|
|
|
|
|
|
|
|
|
|
taskGroupIds.add(task.getTaskGroup());
|
|
|
|
|
|
task.setTaskStatus(WmsTaskStatus.WAIT.getCode());
|
|
|
|
|
|
}
|
|
|
|
|
|
if (request.isEmpty()) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
// 发送任务
|
|
|
|
|
|
ResponseEntity result = JSON.parseObject(HttpUtils.sendHttpPostWithoutToken(UrlEnums.URL_WMS_TO_WCS_SEND_TASK.getValue(), JSON.toJSONString(request)), ResponseEntity.class);
|
|
|
|
|
|
if (result != null && Objects.equals(ResponseCode.OK.getCode(), result.getCode())) {
|
|
|
|
|
|
// 更新任务列表
|
|
|
|
|
|
for (Task task : tasks) {
|
|
|
|
|
|
// 更新任务
|
|
|
|
|
|
taskService.executeTask(task);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (Exception exception) {
|
|
|
|
|
|
logger.error("发生异常:{}", exception.getMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 定期检查设备状态
|
|
|
|
|
|
* 5秒钟
|
|
|
|
|
|
*/
|
|
|
|
|
|
// @Scheduled(fixedDelay = 5000)
|
|
|
|
|
|
public void checkEquipmentStatus() {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 每天查询一次是否有过期的库存
|
|
|
|
|
|
* 每天晚上8点执行一次
|
|
|
|
|
|
*/
|
|
|
|
|
|
// @Scheduled(cron = "0 0 20 * * ?")
|
|
|
|
|
|
public void detectOutOfDateStock() {
|
|
|
|
|
|
logger.info("执行定时任务:查询过期库存");
|
|
|
|
|
|
List<Stock> outOfDateStocks = stockService.selStockOutOfDate();
|
|
|
|
|
|
if (!outOfDateStocks.isEmpty()) {
|
|
|
|
|
|
logger.info("过期库存数量不为0,准备更新过期库存");
|
|
|
|
|
|
for (Stock outOfDateStock : outOfDateStocks) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
outOfDateStock.setGoodsStatus(GoodsStatus.OVERDUE.getCode());
|
|
|
|
|
|
stockService.modifyStock(outOfDateStock);
|
|
|
|
|
|
logger.info("过期库存更新成功");
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
logger.error("过期库存更新异常:{}", e.getMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 每天查询一次是否有入库后长期未使用的库存
|
|
|
|
|
|
* 每天晚上9点执行一次
|
|
|
|
|
|
*/
|
|
|
|
|
|
// @Scheduled(cron = "0 0 21 * * ?")
|
|
|
|
|
|
public void detectStockLongTimeNoUse() {
|
|
|
|
|
|
logger.info("执行定时任务:查询是否有入库后长期未使用的库存");
|
|
|
|
|
|
List<Stock> stocksLongTimeNoUse = stockService.selStockLongTimeNoUse(7);
|
|
|
|
|
|
if (!stocksLongTimeNoUse.isEmpty()) {
|
|
|
|
|
|
logger.info("有入库后长期未使用的库存, 准备更新库存状态");
|
|
|
|
|
|
for (Stock stockLongTimeNoUse : stocksLongTimeNoUse) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
stockLongTimeNoUse.setGoodsStatus(GoodsStatus.SCRAP.getCode());
|
|
|
|
|
|
stockService.modifyStock(stockLongTimeNoUse);
|
|
|
|
|
|
logger.info("长时间未使用库存状态更新成功");
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
logger.error("长时间未使用库存状态更新异常:{}", e.getMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 每天查询一次是否有过期记录
|
|
|
|
|
|
* 每天晚上10点执行一次
|
|
|
|
|
|
*/
|
2024-07-18 13:26:56 +08:00
|
|
|
|
//@Scheduled(cron = "0 0 22 * * ?")
|
2024-07-16 15:12:27 +08:00
|
|
|
|
public void deleteOutOfDateData() {
|
|
|
|
|
|
logger.info("执行定时任务:删除过期数据");
|
|
|
|
|
|
taskRecordService.deleteTaskRecordRegularly();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|