<fix>[important]基本能用版本
This commit is contained in:
parent
4906e505fb
commit
6f740607da
525
src/main/java/com/wms/bussiness/JobComponent.java
Normal file
525
src/main/java/com/wms/bussiness/JobComponent.java
Normal file
|
|
@ -0,0 +1,525 @@
|
|||
package com.wms.bussiness;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.wms.constants.enums.*;
|
||||
import com.wms.controller.BaseController;
|
||||
import com.wms.entity.app.ResponseEntity;
|
||||
import com.wms.entity.app.container.ContainerApiLocalResponse;
|
||||
import com.wms.entity.app.container.SendContainerTaskRequest;
|
||||
import com.wms.entity.app.wcs.WcsTask;
|
||||
import com.wms.entity.table.*;
|
||||
import com.wms.mapper.LocationMapper;
|
||||
import com.wms.mapper.TaskMapper;
|
||||
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;
|
||||
|
||||
|
||||
|
||||
@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){
|
||||
if(task.getTaskType().equals(TaskType.IN.getCode())|| task.getTaskType().equals(TaskType.INVENTORY.getCode())){
|
||||
sendTasksInToWcs(task);
|
||||
return;
|
||||
}
|
||||
if(task.getTaskType().equals(TaskType.OUT.getCode())){
|
||||
sendTasksOutToWcs(task);
|
||||
return;
|
||||
}
|
||||
if(task.getTaskType().equals(TaskType.MOVE.getCode())){
|
||||
sendTasksMoveToWcs(task);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}catch (Exception exception){
|
||||
logger.error("定时器下发任务发生异常:{}", exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送入库任务给WCS
|
||||
* @param task 任务
|
||||
*/
|
||||
private void sendTasksInToWcs(Task task) {
|
||||
List<WcsTask> request = new ArrayList<>();
|
||||
// 创建发送的任务
|
||||
WcsTask tempTask = new WcsTask();
|
||||
tempTask.setTaskId(task.getTaskGroup());
|
||||
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());
|
||||
Task taskForUpdate = new Task();
|
||||
taskForUpdate.setTaskId(task.getTaskId());
|
||||
taskForUpdate.setTaskStatus(WmsTaskStatus.WAIT.getCode());
|
||||
taskService.executeTask(taskForUpdate);
|
||||
}
|
||||
logger.info("下发入库任务失败,任务ID:{},信息:{}", tempTask.getTaskId(), JSON.toJSONString(result));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送出库任务给WCS
|
||||
* @param task 任务
|
||||
*/
|
||||
private void sendTasksOutToWcs(Task task) {
|
||||
/* 检查该库位前一个深度是否存在库存,若存在库存则生成一个移库任务,此任务暂不下发 */
|
||||
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;
|
||||
}
|
||||
if(!notCompleteTasks.isEmpty()) {
|
||||
return; // 存在未完成的任务,退出函数
|
||||
}
|
||||
// 检查是否有库存、
|
||||
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库位存在干涉
|
||||
}
|
||||
// 构造移库任务
|
||||
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();
|
||||
tempTask.setTaskId(task.getTaskGroup());
|
||||
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);
|
||||
}
|
||||
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("2"); // 出库
|
||||
request.setFromcellno(task.getOrigin());
|
||||
request.setTocellno("A13-34-01"); // A13-34-01;A13-16-01;
|
||||
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);
|
||||
}
|
||||
logger.info("下发四向车出库任务失败,任务ID:{},信息:{}", task.getTaskId(), JSON.toJSONString(result));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送移库任务给WCS
|
||||
* @param task 任务
|
||||
*/
|
||||
private void sendTasksMoveToWcs(Task task) {
|
||||
/* 检查该库位前一个深度是否存在库存,若存在库存则生成一个移库任务,此任务暂不下发 */
|
||||
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;
|
||||
}
|
||||
if(!notCompleteTasks.isEmpty()) {
|
||||
return; // 存在未完成的任务,退出函数
|
||||
}
|
||||
// 检查是否有库存、
|
||||
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库位存在干涉
|
||||
}
|
||||
// 构造移库任务
|
||||
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();
|
||||
tempTask.setTaskId(task.getTaskGroup());
|
||||
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);
|
||||
}
|
||||
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")) {
|
||||
logger.info("下发四向车移库任务成功,任务ID:{}", task.getTaskId());
|
||||
Task taskForUpdate = new Task();
|
||||
taskForUpdate.setTaskId(task.getTaskId());
|
||||
taskForUpdate.setTaskStatus(WmsTaskStatus.WAIT.getCode());
|
||||
taskService.executeTask(taskForUpdate);
|
||||
}
|
||||
logger.info("下发四向车移库任务失败,任务ID:{},信息:{}", task.getTaskId(), JSON.toJSONString(result));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 每隔一秒检索一遍任务列表,同时向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点执行一次
|
||||
*/
|
||||
@Scheduled(cron = "0 0 22 * * ?")
|
||||
public void deleteOutOfDateData() {
|
||||
logger.info("执行定时任务:删除过期数据");
|
||||
taskRecordService.deleteTaskRecordRegularly();
|
||||
}
|
||||
}
|
||||
29
src/main/java/com/wms/bussiness/OrderTimer.java
Normal file
29
src/main/java/com/wms/bussiness/OrderTimer.java
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package com.wms.bussiness;
|
||||
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 订单定时器
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class OrderTimer {
|
||||
|
||||
@Scheduled(fixedDelay = 1000)
|
||||
public void parseOutOrder() {
|
||||
//解析出库订单 ---- 出库订单已经由api插入数据库
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
24
src/main/java/com/wms/bussiness/TaskTimer.java
Normal file
24
src/main/java/com/wms/bussiness/TaskTimer.java
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package com.wms.bussiness;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
/**
|
||||
* 任务定时器
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class TaskTimer {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -2,7 +2,8 @@ package com.wms.constants.enums;
|
|||
|
||||
public enum UrlEnums {
|
||||
URL_WMS_TO_WCS_SEND_TASK("WMS向WCS发送任务", "http://192.168.103.202:18990/api/Wms/WmsTask/SetStackerTask"),
|
||||
URL_WMS_TO_WCS_CHANGE_TASK("WMS请求变更任务状态", "http://192.168.103.202:18990/api/Wms/WmsTask/ChangeTaskStatus");
|
||||
URL_WMS_TO_WCS_CHANGE_TASK("WMS请求变更任务状态", "http://192.168.103.202:18990/api/Wms/WmsTask/ChangeTaskStatus"),
|
||||
URL_WMS_TO_WCS_CONTAINER_TASK("WMS向四向车发送任务","");
|
||||
|
||||
private final String description;
|
||||
private final String value;
|
||||
|
|
|
|||
|
|
@ -1,170 +0,0 @@
|
|||
package com.wms.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.wms.constants.enums.*;
|
||||
import com.wms.entity.app.ResponseEntity;
|
||||
import com.wms.entity.app.wcs.WcsTask;
|
||||
import com.wms.entity.table.*;
|
||||
import com.wms.constants.WmsConstants;
|
||||
import com.wms.service.*;
|
||||
import com.wms.utils.HttpUtils;
|
||||
import com.wms.utils.WmsUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import springfox.documentation.spring.web.json.Json;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 定期任务类
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class JobComponent extends BaseController {
|
||||
/**
|
||||
* 任务服务
|
||||
*/
|
||||
private final TaskService taskService;
|
||||
/**
|
||||
* 载具/料箱 服务
|
||||
*/
|
||||
private final VehicleService vehicleService;
|
||||
/**
|
||||
* 库位服务
|
||||
*/
|
||||
private final LocationService locationService;
|
||||
/**
|
||||
* 站台服务
|
||||
*/
|
||||
private final StandService standService;
|
||||
/**
|
||||
* 配置服务
|
||||
*/
|
||||
private final ConfigService configService;
|
||||
/**
|
||||
* 库存服务
|
||||
*/
|
||||
private final StockService stockService;
|
||||
private final TaskRecordService taskRecordService;
|
||||
|
||||
/**
|
||||
* 每隔一秒检索一遍任务列表,同时向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.size() > 0) {// 存在等待中的任务
|
||||
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.size() == 0) {
|
||||
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.size() > 0) {
|
||||
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.size() > 0) {
|
||||
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点执行一次
|
||||
*/
|
||||
@Scheduled(cron = "0 0 22 * * ?")
|
||||
public void deleteOutOfDateData() {
|
||||
logger.info("执行定时任务:删除过期数据");
|
||||
taskRecordService.deleteTaskRecordRegularly();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.wms.controller.parent;
|
||||
package com.wms.controller.others;
|
||||
|
||||
import com.wms.controller.BaseController;
|
||||
import com.wms.entity.app.container.ContainerApiLocalResponse;
|
||||
|
|
@ -8,7 +8,6 @@ import com.wms.entity.app.container.TaskStateNoticeRequest;
|
|||
import com.wms.service.ContainerService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.wms.controller.parent;
|
||||
package com.wms.controller.others;
|
||||
|
||||
import com.wms.controller.BaseController;
|
||||
import com.wms.entity.app.mes.CheckNoticeRequest;
|
||||
|
|
@ -8,7 +8,6 @@ import com.wms.entity.app.mes.ReceiptInRequest;
|
|||
import com.wms.service.MesService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
141
src/main/java/com/wms/controller/others/WcsController.java
Normal file
141
src/main/java/com/wms/controller/others/WcsController.java
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
package com.wms.controller.others;
|
||||
|
||||
import com.wms.constants.enums.*;
|
||||
import com.wms.entity.app.ResponseEntity;
|
||||
import com.wms.entity.app.mes.MesApiLocalResponse;
|
||||
import com.wms.entity.app.wcs.RequireInRequest;
|
||||
import com.wms.entity.table.Location;
|
||||
import com.wms.entity.table.Stock;
|
||||
import com.wms.entity.table.Task;
|
||||
import com.wms.mapper.LocationMapper;
|
||||
import com.wms.mapper.StockMapper;
|
||||
import com.wms.mapper.TaskMapper;
|
||||
import com.wms.utils.storage.LocationUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = "/api/wcs")
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class WcsController {
|
||||
|
||||
/**
|
||||
* 库存 Mapper
|
||||
*/
|
||||
private final StockMapper stockMapper;
|
||||
|
||||
/**
|
||||
* 库位 Mapper
|
||||
*/
|
||||
private final LocationMapper locationMapper;
|
||||
|
||||
/**
|
||||
* 任务 Mapper
|
||||
*/
|
||||
private final TaskMapper taskMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 库位操作类
|
||||
*/
|
||||
private final LocationUtils locationUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 立库申请入库
|
||||
* @param request 请求信息
|
||||
* @return 返回信息
|
||||
*/
|
||||
@PostMapping("/requestIn")
|
||||
public ResponseEntity requestIn(@RequestBody @Validated RequireInRequest request) {
|
||||
/* 校验库存是否存在待入库信息 */
|
||||
Stock checkIsExist = new Stock();
|
||||
checkIsExist.setBatchNo(request.getVehicleNo());
|
||||
checkIsExist.setStockStatus(StockStatus.WAIT_IN.getCode());
|
||||
List<Stock> checkIsExistListResult = stockMapper.selStocks(checkIsExist);
|
||||
if(checkIsExistListResult.isEmpty()) {
|
||||
// 记录不存在
|
||||
return new ResponseEntity(0, String.format("该条码不存在待入库记录,条码号:%s", request.getVehicleNo()));
|
||||
}
|
||||
/* 查找一个空库位 */
|
||||
Location emptyLocation = new Location();
|
||||
emptyLocation.setLocationStatus(LocationStatus.EMPTY.getCode());
|
||||
emptyLocation.setAreaId(1);
|
||||
List<Location> emptyLocations = locationMapper.selLocations(emptyLocation);
|
||||
if(emptyLocations == null) {
|
||||
return new ResponseEntity(0, "库位查找失败,网络连接异常,请稍后再试");
|
||||
}
|
||||
if(emptyLocations.isEmpty()){
|
||||
return new ResponseEntity(0, "没有可用库位");
|
||||
}
|
||||
Location emptyLocationItem = locationUtils.checkCanUse(emptyLocations);
|
||||
if(emptyLocationItem == null) {
|
||||
return new ResponseEntity(0, "没有可用库位或者库位存在干涉,请稍后再试");
|
||||
}
|
||||
// 该空库位可用,生成一个入库任务,并将库存表更新库位
|
||||
// 更新库位表,占掉库位
|
||||
Location updateLocation = new Location();
|
||||
updateLocation.setLocationId(emptyLocationItem.getLocationId());
|
||||
updateLocation.setLocationStatus(LocationStatus.OCCUPY.getCode());
|
||||
updateLocation.setVehicleId(request.getVehicleNo());
|
||||
locationMapper.modifyLocation(updateLocation);
|
||||
// ---- 更新库存中库位
|
||||
stockMapper.updateLocationIdWithBetchNo(request.getVehicleNo(), emptyLocationItem.getLocationId());
|
||||
stockMapper.updateStockStatusWithLocationId(emptyLocationItem.getLocationId(), StockStatus.IN_ING.getCode());
|
||||
// 添加入库任务
|
||||
Task task = new Task();
|
||||
task.setTaskId(UUID.randomUUID().toString());
|
||||
task.setTaskType(TaskType.IN.getCode());
|
||||
task.setTaskStatus(WmsTaskStatus.NEW.getCode());
|
||||
task.setTaskGroup(UUID.randomUUID().toString());
|
||||
task.setOrigin("");
|
||||
task.setDestination(emptyLocationItem.getLocationId());
|
||||
task.setPickStand("");
|
||||
task.setWeight(0.0);
|
||||
task.setVehicleNo(request.getVehicleNo());
|
||||
task.setCreateTime(new Date());
|
||||
task.setUserName("wcs");
|
||||
task.setGoodsId("");
|
||||
task.setGoodsName("");
|
||||
task.setOperateNum(0);
|
||||
task.setTotalNum(0);
|
||||
task.setTaskPriority(1);
|
||||
int addTask = taskMapper.addTask(task);
|
||||
if(addTask > 0) {
|
||||
return new ResponseEntity(1, "存在入库任务,申请成功");
|
||||
}
|
||||
return new ResponseEntity(0, "添加入库任务失败,网络连接异常,请稍后再试");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -7,6 +7,20 @@ import com.wms.entity.BaseEntity;
|
|||
*/
|
||||
public class ResponseEntity extends BaseEntity {
|
||||
|
||||
public ResponseEntity(Integer code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public ResponseEntity(Integer code, String message, Object returnData) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
this.returnData = returnData;
|
||||
}
|
||||
|
||||
public ResponseEntity() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 响应代码
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
package com.wms.entity.app.container;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 发送四向车任务的请求类
|
||||
*/
|
||||
@Data
|
||||
public class SendContainerTaskRequest {
|
||||
|
||||
/**
|
||||
* 请求号
|
||||
*/
|
||||
@JsonProperty("requestid")
|
||||
private String requestid;
|
||||
|
||||
/**
|
||||
* 秘钥
|
||||
*/
|
||||
@JsonProperty("key")
|
||||
private String key;
|
||||
|
||||
/**
|
||||
* wms任务号
|
||||
*/
|
||||
@JsonProperty("wmstaskid")
|
||||
private String wmstaskid;
|
||||
|
||||
/**
|
||||
* 容器号
|
||||
*/
|
||||
@JsonProperty("palletno")
|
||||
private String palletno;
|
||||
|
||||
/**
|
||||
* 源点
|
||||
*/
|
||||
@JsonProperty("fromcellno")
|
||||
private String fromcellno;
|
||||
|
||||
/**
|
||||
* 目的点
|
||||
*/
|
||||
@JsonProperty("tocellno")
|
||||
private String tocellno;
|
||||
|
||||
/**
|
||||
* 任务类型
|
||||
*/
|
||||
@JsonProperty("tasktype")
|
||||
private String tasktype;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
package com.wms.entity.app.wcs;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
|
||||
/**
|
||||
* WCS请求载具入库 实体类
|
||||
*/
|
||||
|
|
@ -7,10 +9,12 @@ public class RequireInRequest {
|
|||
/**
|
||||
* 点位
|
||||
*/
|
||||
@NotBlank(message = "请求的点位不能为空")
|
||||
private String point;
|
||||
/**
|
||||
* 载具编号
|
||||
*/
|
||||
@NotBlank(message = "请求的载具编号不能为空")
|
||||
private String vehicleNo;
|
||||
/**
|
||||
* 条码信息
|
||||
|
|
|
|||
|
|
@ -15,6 +15,9 @@ public interface LocationMapper {
|
|||
*/
|
||||
List<Location> selLocations(Location location);
|
||||
|
||||
|
||||
List<Location> selSmallDepthLocations(Location location);
|
||||
|
||||
/**
|
||||
* 查找下一个可用库位
|
||||
* @param location 具体信息
|
||||
|
|
|
|||
|
|
@ -76,6 +76,10 @@ public interface StockMapper {
|
|||
*/
|
||||
int updateStockStatusWithLocationId(@Param("locationId") String locationId, @Param("status") Integer status);
|
||||
|
||||
int updateLocationIdWithBetchNo(@Param("batchNo") String batchNo, @Param("locationId") String locationId);
|
||||
|
||||
|
||||
|
||||
List<Stock> selStocksByGoodsId(Stock stock);
|
||||
|
||||
List<Stock> selStockOutOfDate();
|
||||
|
|
|
|||
|
|
@ -22,6 +22,13 @@ public interface TaskMapper {
|
|||
*/
|
||||
int addTask(Task task);
|
||||
|
||||
/**
|
||||
* 添加任务
|
||||
* @param tasks
|
||||
* @return
|
||||
*/
|
||||
int addTasks(List<Task> tasks);
|
||||
|
||||
/**
|
||||
* 执行任务
|
||||
* @param task
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,20 +1,15 @@
|
|||
package com.wms.service.serviceImplements.parent;
|
||||
|
||||
import com.wms.constants.enums.OrderCheckStatusEnum;
|
||||
import com.wms.constants.enums.OrderOutStatusEnum;
|
||||
import com.wms.constants.enums.StockStatus;
|
||||
import com.wms.constants.enums.*;
|
||||
import com.wms.entity.app.mes.CheckNoticeRequest;
|
||||
import com.wms.entity.app.mes.MesApiLocalResponse;
|
||||
import com.wms.entity.app.mes.OutNoticeRequest;
|
||||
import com.wms.entity.app.mes.ReceiptInRequest;
|
||||
import com.wms.entity.table.OrderCheck;
|
||||
import com.wms.entity.table.OrderOut;
|
||||
import com.wms.entity.table.Stock;
|
||||
import com.wms.mapper.OrderCheckMapper;
|
||||
import com.wms.mapper.OrderOutMapper;
|
||||
import com.wms.mapper.StockMapper;
|
||||
import com.wms.entity.table.*;
|
||||
import com.wms.mapper.*;
|
||||
import com.wms.service.MesService;
|
||||
import com.wms.utils.StringUtils;
|
||||
import com.wms.utils.storage.StockUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -49,6 +44,13 @@ public class MesServiceImplement implements MesService {
|
|||
*/
|
||||
private final OrderCheckMapper orderCheckMapper;
|
||||
|
||||
/**
|
||||
* 任务 Mapper
|
||||
*/
|
||||
private final TaskMapper taskMapper;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* mes 入库之前用此接口推送信息
|
||||
* @param request 请求信息
|
||||
|
|
@ -68,7 +70,7 @@ public class MesServiceImplement implements MesService {
|
|||
Stock needInStock = new Stock();
|
||||
needInStock.setStockId(request.getGuid());
|
||||
needInStock.setLocationId("-");
|
||||
needInStock.setVehicleId("-");
|
||||
needInStock.setVehicleId(request.getLosnr());
|
||||
needInStock.setRemark(request.getType().toString());
|
||||
needInStock.setBatchNo(request.getLosnr());
|
||||
needInStock.setGoodsId(request.getItemCode());
|
||||
|
|
@ -101,7 +103,7 @@ public class MesServiceImplement implements MesService {
|
|||
if(!checkIsExistListResult.isEmpty()) {
|
||||
return new MesApiLocalResponse(0, String.format("该条记录已经存在,记录号:%s", request.getGuid()));
|
||||
}
|
||||
/* 插入数据 */
|
||||
/* 插入数据,插入记录表 */
|
||||
List<OrderOut> orderOutList = new ArrayList<>();
|
||||
for(var row : request.getRow()) {
|
||||
OrderOut orderOut = new OrderOut();
|
||||
|
|
@ -122,8 +124,68 @@ public class MesServiceImplement implements MesService {
|
|||
if(orderOutList.isEmpty()) {
|
||||
return new MesApiLocalResponse(0, "没有数据");
|
||||
}
|
||||
int addResult = orderOutMapper.insertList(orderOutList);
|
||||
if(addResult == orderOutList.size()) {
|
||||
int addOrderResult = orderOutMapper.insertList(orderOutList);
|
||||
if(addOrderResult != orderOutList.size()) {
|
||||
return new MesApiLocalResponse(0, "添加失败,请稍后再试");
|
||||
}
|
||||
// 计算出库
|
||||
List<Task> outTasks = new ArrayList<>(); // 出库任务列表
|
||||
/* 查询库存 */
|
||||
for(var goods : request.getRow()) {
|
||||
// 拉出该物料的所有库存
|
||||
Stock queryStock = new Stock();
|
||||
queryStock.setBatchNo(goods.getItemCode());
|
||||
queryStock.setStockStatus(StockStatus.OK.getCode());
|
||||
List<Stock> stockList = stockMapper.selStocks(queryStock);
|
||||
if(stockList == null) {
|
||||
return new MesApiLocalResponse(0, String.format("库存拉取失败,请稍后再试,物料号:%s", goods.getItemCode()));
|
||||
}
|
||||
if(stockList.isEmpty()) {
|
||||
return new MesApiLocalResponse(0, String.format("该物料没有库存,物料号:%s,其他物料也一并拒绝出库", goods.getItemCode()));
|
||||
}
|
||||
Integer availableNum = StockUtils.sumStcokAvailableNum(stockList); // 拥有的数量
|
||||
int needNum = Integer.parseInt(goods.getQty()); // 需要的数量
|
||||
if(availableNum.compareTo(Integer.parseInt(goods.getQty())) < 0) {
|
||||
return new MesApiLocalResponse(0, String.format("该物料库存不足,物料号:%s,库存数量:%d,出库数量:%s", goods.getItemCode(), availableNum, goods.getQty()));
|
||||
}
|
||||
// 生成出库任务
|
||||
for(Stock outStock : stockList) {
|
||||
if(needNum <= 0) {
|
||||
break;
|
||||
}
|
||||
// 生成出库任务,更新库存为出库中
|
||||
|
||||
int outNum = needNum > outStock.getAvailableNum() ? outStock.getAvailableNum() : needNum; // 需要操作的数量
|
||||
|
||||
Task task = new Task();
|
||||
task.setTaskId(String.format("%s-%s", request.getTransferNo(), outStock.getStockId()));
|
||||
task.setTaskType(TaskType.OUT.getCode());
|
||||
task.setTaskStatus(OrderOutStatusEnum.CREATED.getCode());
|
||||
task.setTaskGroup(request.getTransferNo());
|
||||
task.setOrigin(outStock.getLocationId());
|
||||
task.setDestination("");
|
||||
task.setPickStand("");
|
||||
task.setWeight(0.0);
|
||||
task.setVehicleNo(outStock.getVehicleId());
|
||||
task.setCreateTime(new Date());
|
||||
task.setUserName("mes");
|
||||
task.setGoodsId(outStock.getGoodsId());
|
||||
task.setGoodsName(outStock.getGoodsName());
|
||||
task.setOperateNum(outNum);
|
||||
task.setTotalNum(outStock.getRealNum());
|
||||
task.setTaskPriority(1);
|
||||
outTasks.add(task);
|
||||
// 更新库存为出库中
|
||||
stockMapper.updateStockStatusWithLocationId(outStock.getLocationId(), StockStatus.OUT.getCode());
|
||||
// 重新计算需求数量
|
||||
needNum -= outNum;
|
||||
}
|
||||
}
|
||||
if(outTasks.isEmpty()) {
|
||||
return new MesApiLocalResponse(0, "无法生成任务,请稍后再试");
|
||||
}
|
||||
int addResult = taskMapper.addTasks(outTasks);
|
||||
if(addResult == outTasks.size()) {
|
||||
return new MesApiLocalResponse(1, "添加成功");
|
||||
}
|
||||
return new MesApiLocalResponse(0, "添加失败");
|
||||
|
|
@ -143,17 +205,57 @@ public class MesServiceImplement implements MesService {
|
|||
if(!checkIsExistListResult.isEmpty()) {
|
||||
return new MesApiLocalResponse(0, String.format("该条记录已经存在,记录号:%s", request.getGuid()));
|
||||
}
|
||||
/* 添加记录 */
|
||||
/* 添加盘点记录 */
|
||||
OrderCheck orderCheck = new OrderCheck();
|
||||
orderCheck.setRecordId(request.getGuid());
|
||||
orderCheck.setCheckId(request.getInventoryNo());
|
||||
orderCheck.setWarehouse(request.getIWarehouse());
|
||||
orderCheck.setStatus(OrderCheckStatusEnum.CREATED.getCode());
|
||||
orderCheck.setCreateTime(new Date());
|
||||
int insertResult = orderCheckMapper.insert(orderCheck);
|
||||
if(insertResult == 1) {
|
||||
int insertOrderCheckResult = orderCheckMapper.insert(orderCheck);
|
||||
if(insertOrderCheckResult < 1) {
|
||||
return new MesApiLocalResponse(0, "添加失败,数据库连接异常,请稍后再试");
|
||||
}
|
||||
// 将该盘点单号对应的库别全部生成盘点任务
|
||||
List<Task> checkTasks = new ArrayList<>(); // 盘点任务列表
|
||||
Stock queryStock = new Stock();
|
||||
queryStock.setWarehouseName(request.getIWarehouse());
|
||||
List<Stock> stockList = stockMapper.selStocks(queryStock);
|
||||
if(stockList == null || stockList.isEmpty()) {
|
||||
return new MesApiLocalResponse(0, String.format("该库别没有库存,请稍后再试,库别:%s", request.getIWarehouse()));
|
||||
}
|
||||
// 检查这些应该盘点的库位有没有任务在执行
|
||||
for(Stock stock : stockList) {
|
||||
List<Task> notCompleteTasks = taskMapper.haveNotCompleteTask(stock.getLocationId());
|
||||
if(notCompleteTasks == null) {
|
||||
return new MesApiLocalResponse(0, String.format("数据库校验任务失败,请稍后再试,库位:%s", stock.getLocationId()));
|
||||
}
|
||||
if(!notCompleteTasks.isEmpty()) {
|
||||
return new MesApiLocalResponse(0, String.format("该库位有任务在执行,请稍后再试,库位:%s", stock.getLocationId()));
|
||||
}
|
||||
Task task = new Task();
|
||||
task.setTaskId(String.format("%s-%s", request.getGuid(), stock.getLocationId()));
|
||||
task.setTaskType(TaskType.INVENTORY.getCode());
|
||||
task.setTaskStatus(OrderOutStatusEnum.CREATED.getCode());
|
||||
task.setTaskGroup(request.getIWarehouse());
|
||||
task.setOrigin(stock.getLocationId());
|
||||
task.setDestination("");
|
||||
task.setPickStand("");
|
||||
task.setWeight(0.0);
|
||||
task.setVehicleNo(stock.getVehicleId());
|
||||
task.setCreateTime(new Date());
|
||||
task.setUserName("mes");
|
||||
task.setGoodsId(stock.getGoodsId());
|
||||
task.setGoodsName(stock.getGoodsName());
|
||||
task.setOperateNum(stock.getRealNum());
|
||||
task.setTotalNum(stock.getRealNum());
|
||||
task.setTaskPriority(1);
|
||||
checkTasks.add(task);
|
||||
}
|
||||
int addTasks = taskMapper.addTasks(checkTasks);
|
||||
if(addTasks == checkTasks.size()) {
|
||||
return new MesApiLocalResponse(1, "添加成功");
|
||||
}
|
||||
return new MesApiLocalResponse(0, "添加失败");
|
||||
return new MesApiLocalResponse(0, "添加失败,请稍后再试");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,6 +57,9 @@ public class LocationUtils {
|
|||
return null;
|
||||
}
|
||||
for (Location location : canUseLocations) {
|
||||
if(location.getDepth() == 1) {
|
||||
return location; // 1 深度的不需要检验
|
||||
}
|
||||
/* 校验此位置是否有遮挡 */ /* 如果这位置有库存(可能出现记错导致有库存),或者这位置其他深度(不论深度大小)有任务则不采用此位置 */
|
||||
/* 1 判断库存 */
|
||||
Stock checkStock = new Stock();
|
||||
|
|
|
|||
29
src/main/java/com/wms/utils/storage/StockUtils.java
Normal file
29
src/main/java/com/wms/utils/storage/StockUtils.java
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package com.wms.utils.storage;
|
||||
|
||||
import com.wms.entity.table.Stock;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 库存工具类
|
||||
*/
|
||||
public class StockUtils {
|
||||
|
||||
/**
|
||||
* 获取库存列表的总可用库存
|
||||
* @param stocks 库存列表
|
||||
* @return 可用库存总数
|
||||
*/
|
||||
public static Integer sumStcokAvailableNum(List<Stock> stocks) {
|
||||
if(stocks == null) {
|
||||
return null;
|
||||
}
|
||||
Integer sum = 0;
|
||||
for(Stock stock : stocks) {
|
||||
sum += stock.getAvailableNum();
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -41,6 +41,22 @@
|
|||
order by depth desc, line asc, layer asc
|
||||
</select>
|
||||
|
||||
<select id="selSmallDepthLocations" parameterType="Location" resultMap="LocationMap">
|
||||
<include refid="selectAll"/>
|
||||
<where>
|
||||
<if test="areaId != null"> and area_id = #{areaId}</if>
|
||||
<if test="tunnelId != null"> and tunnel_id = #{tunnelId}</if>
|
||||
<if test="equipmentId != null"> and equipment_id = #{equipmentId}</if>
|
||||
<if test="queue != null"> and queue = #{queue}</if>
|
||||
<if test="line != null"> and line = #{line}</if>
|
||||
<if test="layer != null"> and layer = #{layer}</if>
|
||||
<if test="depth != null"> and depth < #{depth}</if>
|
||||
<if test="isLock != null"> and is_lock = #{isLock}</if>
|
||||
</where>
|
||||
order by depth desc, line asc, layer asc
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selNextLocation" parameterType="Location" resultMap="LocationMap">
|
||||
<include refid="selectAll"/>
|
||||
<where>
|
||||
|
|
|
|||
|
|
@ -210,4 +210,10 @@
|
|||
update tbl_app_stock set stock_status = #{status} where location_id = #{locationId}
|
||||
</update>
|
||||
|
||||
<update id="updateLocationIdWithBetchNo">
|
||||
update tbl_app_stock set location_id = #{locationId} where batch_no = #{batchNo}
|
||||
</update>
|
||||
|
||||
|
||||
|
||||
</mapper>
|
||||
|
|
@ -115,6 +115,21 @@
|
|||
</trim>
|
||||
</insert>
|
||||
|
||||
<insert id="addTasks" parameterType="java.util.ArrayList">
|
||||
insert into tbl_app_task(task_id, task_type, task_status, task_group, origin,
|
||||
destination, pick_stand, weight, vehicle_no, vehicle_size,
|
||||
create_time, user_name, goods_id, goods_name, operate_num,
|
||||
total_num, etag_location, task_priority, production_date,
|
||||
expiration_date, kate_task_id, remark1) values
|
||||
<foreach collection="list" item="item" index="index" separator=",">
|
||||
(#{item.taskId}, #{item.taskType}, #{item.taskStatus}, #{item.taskGroup}, #{item.origin},
|
||||
#{item.destination}, #{item.pickStand}, #{item.weight}, #{item.vehicleNo}, #{item.vehicleSize},
|
||||
#{item.createTime}, #{item.userName}, #{item.goodsId}, #{item.goodsName}, #{item.operateNum},
|
||||
#{item.totalNum}, #{item.etagLocation}, #{item.taskPriority}, #{item.productionDate},
|
||||
#{item.expirationDate}, #{item.kateTaskId}, #{item.remark1})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<update id="executeTask" parameterType="Task">
|
||||
update tbl_app_task
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user