feat(location):移库逻辑修改

This commit is contained in:
陆一凡 2025-03-08 00:23:25 +08:00
parent 7656e6ab50
commit 3d1f0ec758
5 changed files with 126 additions and 283 deletions

View File

@ -157,34 +157,7 @@ public class JobComponent extends BaseController {
} }
logger.info("下发立库入库任务失败任务ID{},信息:{}", tempTask.getTaskId(), JSON.toJSONString(result)); 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){ }catch (Exception exception){
logger.error("下发入库任务发生异常:{}", exception.toString()); logger.error("下发入库任务发生异常:{}", exception.toString());
} }
@ -215,11 +188,11 @@ public class JobComponent extends BaseController {
} }
Location thisLocation = thisLocations.get(0); // 找出当前库位详细信息 Location thisLocation = thisLocations.get(0); // 找出当前库位详细信息
int depth = 0; int depth = 0;
// 检查该库位前面深度的库位
while (depth < thisLocation.getDepth()-1) { while (depth < thisLocation.getDepth()-1) {
depth++; depth++;
/* 检查该库位有没有任务,若有则退出函数,若没有则检查有没有库存,若没有库存则继续,若有库存则生成一个移库任务,生成之后退出函数 */ /* 检查该库位有没有任务,若有则退出函数,若没有则检查有没有库存,若没有库存则继续,若有库存则生成一个移库任务,生成之后退出函数 */
Location beforLocationsQuery = new Location(); Location beforLocationsQuery = new Location();
// logger.info("{},{},{},{},{}",thisLocation.getAreaId(),thisLocation.getQueue(),thisLocation.getLine(),thisLocation.getLayer(),depth);
beforLocationsQuery.setAreaId(thisLocation.getAreaId()); beforLocationsQuery.setAreaId(thisLocation.getAreaId());
beforLocationsQuery.setTunnelId(thisLocation.getTunnelId()); beforLocationsQuery.setTunnelId(thisLocation.getTunnelId());
beforLocationsQuery.setQueue(thisLocation.getQueue()); beforLocationsQuery.setQueue(thisLocation.getQueue());
@ -243,19 +216,20 @@ public class JobComponent extends BaseController {
return; return;
} }
if(!notCompleteTasks.isEmpty()) { if(!notCompleteTasks.isEmpty()) {
logger.info("发送出库任务时存在未完成的任务,退出函数"); logger.info("发送出库任务时,前面货位存在未完成的任务,退出函数");
return; return;
} }
// 检查是否有库存因为存在空框所以不在库存表中检验 // 检查是否有库存因为存在空框所以不在库存表中检验
Vehicle nextVehicle = new Vehicle(); Vehicle nextVehicle = new Vehicle();
nextVehicle.setCurrentLocation(beforLocation.getLocationId()); nextVehicle.setCurrentLocation(beforLocation.getLocationId());
List<Vehicle> beforVehicleCheckIfEmpty = vehicleMapper.selVehicles(nextVehicle); List<Vehicle> beforVehicleCheckIfEmpty = vehicleMapper.selVehicles(nextVehicle);
if(beforVehicleCheckIfEmpty == null) { if(beforVehicleCheckIfEmpty == null) {
logger.info("beforLocationsCheckIfEmpty == null"); logger.info("beforVehicleCheckIfEmpty == null");
return; return;
} }
if(beforVehicleCheckIfEmpty.isEmpty()) { if(beforVehicleCheckIfEmpty.isEmpty()) {
logger.info("位置{}没有",beforLocation.getLocationId()); logger.info("位置{}没有货物,继续寻找",beforLocation.getLocationId());
continue; // 没有库存继续 continue; // 没有库存继续
} }
/* 生成一个移库任务 */ /* 生成一个移库任务 */
@ -268,6 +242,7 @@ public class JobComponent extends BaseController {
emptyLocation.setTunnelId(Integer.parseInt(String.valueOf(thisLocation.getTunnelId()).substring(0,1))); emptyLocation.setTunnelId(Integer.parseInt(String.valueOf(thisLocation.getTunnelId()).substring(0,1)));
emptyLocation.setLayer(thisLocation.getLayer()); emptyLocation.setLayer(thisLocation.getLayer());
emptyLocation.setIsChangeArea(1); emptyLocation.setIsChangeArea(1);
emptyLocation.setIsLock(0);
List<Location> emptyLocations = locationMapper.findChangeLocation(emptyLocation); List<Location> emptyLocations = locationMapper.findChangeLocation(emptyLocation);
if(emptyLocations == null) { if(emptyLocations == null) {
logger.info("emptyLocations == null"); logger.info("emptyLocations == null");
@ -278,13 +253,14 @@ public class JobComponent extends BaseController {
logger.info("移库没有可用库位"); logger.info("移库没有可用库位");
return; // 移库没有可用库位 return; // 移库没有可用库位
} }
Location emptyLocationItem = locationUtils.checkCanUse(emptyLocations); // 取得新库位 Location emptyLocationItem = locationUtils.checkCanUseChangeLocation(emptyLocations); // 取得新库位
if(emptyLocationItem == null) { if(emptyLocationItem == null) {
logger.info("emptyLocationItem == null"); logger.info("没有可移动库位,移动库位存在任务");
return; // 没有可用库位或者m库位存在干涉 return; // 没有可用库位或者m库位存在干涉
} }
// 锁定旧库位库存 // 锁定旧库位库存
stockMapper.updateStockStatusWithLocationId(beforLocation.getLocationId(), StockStatus.LOCK.getCode()); stockMapper.updateStockStatusWithLocationId(beforLocation.getLocationId(), StockStatus.LOCK.getCode());
// 锁定新库位 // 锁定新库位
Location locationForUpdate = new Location(); Location locationForUpdate = new Location();
locationForUpdate.setLocationId(emptyLocationItem.getLocationId()); locationForUpdate.setLocationId(emptyLocationItem.getLocationId());
@ -304,12 +280,7 @@ public class JobComponent extends BaseController {
moveTask.setVehicleNo(beforVehicleCheckIfEmpty.get(0).getVehicleId()); moveTask.setVehicleNo(beforVehicleCheckIfEmpty.get(0).getVehicleId());
moveTask.setCreateTime(new Date()); moveTask.setCreateTime(new Date());
moveTask.setUserName("WMS"); moveTask.setUserName("WMS");
moveTask.setTaskPriority(thisLocation.getDepth() - depth); moveTask.setTaskPriority(thisLocation.getDepth() - depth+1);
// if(depth == 2){
// moveTask.setTaskPriority(8);
// } else if (depth == 1) {
// moveTask.setTaskPriority(9);
// }
if (beforVehicleCheckIfEmpty.get(0).getIsEmpty() == 1){ if (beforVehicleCheckIfEmpty.get(0).getIsEmpty() == 1){
moveTask.setRemark1("空框"); moveTask.setRemark1("空框");
}else { }else {
@ -359,7 +330,7 @@ public class JobComponent extends BaseController {
request.setPalletno(task.getVehicleNo()); request.setPalletno(task.getVehicleNo());
request.setTasktype("2"); // 出库 request.setTasktype("2"); // 出库
request.setFromcellno(task.getOrigin()); request.setFromcellno(task.getOrigin());
request.setTocellno("111"); // ??????? request.setTocellno("111");
String requestString = JSON.toJSONString(request); String requestString = JSON.toJSONString(request);
String responseString = HttpUtils.sendHttpPostWithoutToken(UrlEnums.URL_WMS_TO_WCS_CONTAINER_TASK.getValue(), requestString); String responseString = HttpUtils.sendHttpPostWithoutToken(UrlEnums.URL_WMS_TO_WCS_CONTAINER_TASK.getValue(), requestString);
//JSONObject jsonResponse = JSON.parseObject(responseString); //JSONObject jsonResponse = JSON.parseObject(responseString);
@ -380,9 +351,53 @@ public class JobComponent extends BaseController {
* 发送移库任务给WCS * 发送移库任务给WCS
* @param task 任务 * @param task 任务
*/ */
@Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED) @Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
public void sendTasksMoveToWcs(Task task){ public void sendTasksMoveToWcs(Task task){
List<Location> desLocations = locationService.selLocations(new Location(task.getDestination()));
if(desLocations == null) {
logger.info("下发移库任务查询库位详细信息失败,数据库网络连接异常");
return;
}
if(desLocations.isEmpty()) {
logger.info("下发移库任务查询库位详细信息异常,不存在详细信息,该库位可能不存在");
Task taskForUpdate = new Task();
taskForUpdate.setTaskId(task.getTaskId());
taskForUpdate.setTaskStatus(WmsTaskStatus.EXCEPTION.getCode());
taskForUpdate.setRemark1("该库位不存在");
taskService.executeTask(taskForUpdate);
return;
}
Location desLocation = desLocations.get(0); // 找出当前库位详细信息
int desDepth = desLocation.getDepth();
/* 检查该库位有没有任务,若有则退出函数,若没有则检查有没有库存,若没有库存则继续,若有库存则生成一个移库任务,生成之后退出函数 */
Location desLocationsQuery = new Location();
desLocationsQuery.setAreaId(desLocation.getAreaId());
desLocationsQuery.setTunnelId(desLocation.getTunnelId());
desLocationsQuery.setQueue(desLocation.getQueue());
desLocationsQuery.setLayer(desLocation.getLayer());
desLocationsQuery.setLocationType(1);
desLocationsQuery.setDepth(++desDepth);
List<Location> desDeepLocations = locationService.selLocations(desLocationsQuery);
if (desDeepLocations == null) {
logger.info("下发移库任务查询库位详细信息失败,数据库网络连接异常");
return;
}
if (desDeepLocations.isEmpty()) {
logger.info("后一个库位信息为空");
return;
}
Location desDeepLocation = desDeepLocations.get(0); // 前一个库位
List<Task> desNotCompleteTasks = taskMapper.haveNotCompleteTask(desDeepLocation.getLocationId());
if (desNotCompleteTasks == null) {
logger.info("查询任务异常");
return;
}
if (!desNotCompleteTasks.isEmpty()) {
logger.info("发送移库任务时目标库位,高深度存在未完成的任务,退出函数");
return;
}
/* 检查该库位前一个深度是否存在库存,若存在库存则生成一个移库任务,此任务暂不下发 */ /* 检查该库位前一个深度是否存在库存,若存在库存则生成一个移库任务,此任务暂不下发 */
List<Location> thisLocations = locationService.selLocations(new Location(task.getOrigin())); List<Location> thisLocations = locationService.selLocations(new Location(task.getOrigin()));
if(thisLocations == null) { if(thisLocations == null) {
@ -400,6 +415,8 @@ public class JobComponent extends BaseController {
} }
Location thisLocation = thisLocations.get(0); // 找出当前库位详细信息 Location thisLocation = thisLocations.get(0); // 找出当前库位详细信息
int depth = thisLocation.getDepth(); int depth = thisLocation.getDepth();
// 查看比它大1的深度是否有任务在执行
while (depth > 1) { while (depth > 1) {
depth--; depth--;
/* 检查该库位有没有任务,若有则退出函数,若没有则检查有没有库存,若没有库存则继续,若有库存则生成一个移库任务,生成之后退出函数 */ /* 检查该库位有没有任务,若有则退出函数,若没有则检查有没有库存,若没有库存则继续,若有库存则生成一个移库任务,生成之后退出函数 */
@ -416,7 +433,7 @@ public class JobComponent extends BaseController {
return; return;
} }
if (beforLocations.isEmpty()) { if (beforLocations.isEmpty()) {
logger.info("一个库位信息为空"); logger.info("一个库位信息为空");
return; return;
} }
Location beforLocation = beforLocations.get(0); // 前一个库位 Location beforLocation = beforLocations.get(0); // 前一个库位
@ -426,7 +443,7 @@ public class JobComponent extends BaseController {
return; return;
} }
if (!notCompleteTasks.isEmpty()) { if (!notCompleteTasks.isEmpty()) {
logger.info("发送移库任务时存在未完成的任务,退出函数"); logger.info("发送移库任务时源库位,低深度存在未完成的任务,退出函数");
return; return;
} }
} }
@ -445,7 +462,7 @@ public class JobComponent extends BaseController {
ContainerApiLocalResponse result = JSON.parseObject(responseString, ContainerApiLocalResponse.class); ContainerApiLocalResponse result = JSON.parseObject(responseString, ContainerApiLocalResponse.class);
if(result != null && result.getCode().equals("200")) { if(result != null && result.getCode().equals("200")) {
logger.info("下发四向车移库任务成功任务ID{}", task.getTaskId()); logger.info("下发四向车移库任务成功任务ID{}", task.getTaskId());
logger.info("移库目标位置为:{}",task.getDestination()); logger.info("移库源位置为:{},移库目标位置为:{}",task.getOrigin(),task.getDestination());
Task taskForUpdate = new Task(); Task taskForUpdate = new Task();
taskForUpdate.setTaskId(task.getTaskId()); taskForUpdate.setTaskId(task.getTaskId());
taskForUpdate.setTaskStatus(WmsTaskStatus.WAIT.getCode()); taskForUpdate.setTaskStatus(WmsTaskStatus.WAIT.getCode());
@ -455,149 +472,7 @@ public class JobComponent extends BaseController {
logger.info("下发四向车移库任务失败任务ID{},信息:{}", task.getTaskId(), JSON.toJSONString(result)); logger.info("下发四向车移库任务失败任务ID{},信息:{}", task.getTaskId(), JSON.toJSONString(result));
} }
@Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
public void sendTasksMoveToWcs1(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;
}
for(Task notCompleteTask : notCompleteTasks) {
String taskId = notCompleteTask.getTaskId();
if(!taskId.equals(task.getTaskId())) {
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库位存在干涉
}
// 锁定旧库位库存
stockMapper.updateStockStatusWithLocationId(beforLocation.getLocationId(), StockStatus.LOCK.getCode());
// 锁定新库位
Location locationForUpdate = new Location();
locationForUpdate.setLocationId(emptyLocationItem.getLocationId());
locationForUpdate.setLocationStatus(LocationStatus.OCCUPY.getCode());
locationMapper.modifyLocation(locationForUpdate);
// 构造移库任务
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.getTaskId());
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);
return;
}
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);
return;
}
// logger.info("下发四向车移库任务失败任务ID{},信息:{}", task.getTaskId(), JSON.toJSONString(result));
}
}

View File

@ -717,7 +717,7 @@ public class TaskOperation {
updateLocation.setLocationStatus(LocationStatus.EMPTY.getCode()); updateLocation.setLocationStatus(LocationStatus.EMPTY.getCode());
updateLocation.setVehicleId(""); updateLocation.setVehicleId("");
locationMapper.modifyLocation(updateLocation); // 更新库位为空 locationMapper.modifyLocation(updateLocation); // 更新库位为空
// 更新库存为 ok ??????? // 更新库存为 ok
int updateStock = stockMapper.updateStockStatusWithLocationId(task.getDestination(), StockStatus.OK.getCode()); int updateStock = stockMapper.updateStockStatusWithLocationId(task.getDestination(), StockStatus.OK.getCode());
if(updateStock > 0){ if(updateStock > 0){
log.info("入库取消更新库存成功,任务:{}", task.toLoggerString()); log.info("入库取消更新库存成功,任务:{}", task.toLoggerString());

View File

@ -86,7 +86,7 @@ public class OrderOutImplements implements IOrderOutService {
Stock queryStock = new Stock(); Stock queryStock = new Stock();
queryStock.setGoodsId(orderOut.getGoodsId() != null ? orderOut.getGoodsId().trim() : null); queryStock.setGoodsId(orderOut.getGoodsId() != null ? orderOut.getGoodsId().trim() : null);
queryStock.setWarehouseName(orderOut.getWarehouseOrigin()); queryStock.setWarehouseName(orderOut.getWarehouseOrigin());
queryStock.setStockStatus(StockStatus.OK.getCode()); // queryStock.setStockStatus(StockStatus.OK.getCode());
if (orderOut.getDeliveryTime() != null){ if (orderOut.getDeliveryTime() != null){
queryStock.setProductionDate(orderOut.getDeliveryTime()); queryStock.setProductionDate(orderOut.getDeliveryTime());
} }
@ -104,97 +104,6 @@ public class OrderOutImplements implements IOrderOutService {
return new WmsApiResponse<>(1, String.format("该物料库存不足,物料号:%s库存数量%d出库数量%s", orderOut.getGoodsId(), availableNum, orderOut.getGoodsNum()), null); return new WmsApiResponse<>(1, String.format("该物料库存不足,物料号:%s库存数量%d出库数量%s", orderOut.getGoodsId(), availableNum, orderOut.getGoodsNum()), null);
} }
//选择最优库存
// Boolean isMultiVehicle= true;
// for (Stock stock : stockList) {
// if (stock.getAvailableNum() >= needNum) {
// isMultiVehicle = false;
// }
// }
// if (isMultiVehicle) {
// // 生成多托盘出库任务
// List<Stock> sortStockList = stockList.stream().sorted(Comparator.comparingInt(Stock::getAvailableNum).reversed()).collect(Collectors.toList());
// for(Stock outStock : sortStockList) {
// if(needNum <= 0) {
// break;
// }
// // 生成出库任务更新库存为出库中
// int outNum = needNum > outStock.getAvailableNum() ? outStock.getAvailableNum() : needNum; // 需要操作的数量
// if(outTasks.stream().filter(task -> task.getOrigin().equals(outStock.getLocationId())).toList().isEmpty()) {
// Task task = new Task();
// task.setTaskId(String.valueOf(Calendar.getInstance().getTimeInMillis()));
// task.setTaskType(2);
// task.setTaskGroup(orderOut.getOrderId());
// task.setTaskStatus(OrderOutStatusEnum.CREATED.getCode());
// task.setOrigin(outStock.getLocationId());
// task.setDestination("111");
// task.setPickStand(orderOut.getRowId());
// task.setWeight(0.0);
// task.setVehicleNo(outStock.getVehicleId());
// task.setCreateTime(new Date());
// task.setUserName("WMS");
// task.setGoodsId(outStock.getGoodsId());
// task.setGoodsName(outStock.getGoodsName());
// task.setOperateNum(outNum);
// task.setTotalNum(outStock.getRealNum());
// task.setTaskPriority(1);
// task.setRemark1("手动出库");
// outTasks.add(task);
// taskRecordMapper.addTask(task);
// }
// // 把这条库存记录可用数量更新为 0
// stockMapper.updateStockAvailableNumWithStockId(outStock.getStockId(), outStock.getAvailableNum()-outNum);
// // 更新库存为出库中
// stockMapper.updateStockStatusWithLocationId(outStock.getLocationId(), StockStatus.OUT.getCode());
// // 重新计算需求数量
// needNum -= outNum;
// }
// }else{
// // 生成单托盘出库任务
// List<Stock> sortStockList = stockList.stream().sorted(Comparator.comparingInt(Stock::getAvailableNum)).collect(Collectors.toList());
// ArrayList satisfyStockList = new ArrayList<>();
// for (Stock stock : sortStockList) {
// if (stock.getAvailableNum() >= needNum){
// satisfyStockList.add(stock);
// break;
// }
// }
// for(Stock outStock : sortStockList) {
// if(needNum <= 0) {
// break;
// }
// // 生成出库任务更新库存为出库中
// int outNum = needNum > outStock.getAvailableNum() ? outStock.getAvailableNum() : needNum; // 需要操作的数量
// if(outTasks.stream().filter(task -> task.getOrigin().equals(outStock.getLocationId())).toList().isEmpty()) {
// Task task = new Task();
// task.setTaskId(String.valueOf(Calendar.getInstance().getTimeInMillis()));
// task.setTaskType(2);
// task.setTaskGroup(orderOut.getOrderId());
// task.setTaskStatus(OrderOutStatusEnum.CREATED.getCode());
// task.setOrigin(outStock.getLocationId());
// task.setDestination("111");
// task.setPickStand(orderOut.getRowId());
// task.setWeight(0.0);
// task.setVehicleNo(outStock.getVehicleId());
// task.setCreateTime(new Date());
// task.setUserName("WMS");
// task.setGoodsId(outStock.getGoodsId());
// task.setGoodsName(outStock.getGoodsName());
// task.setOperateNum(outNum);
// task.setTotalNum(outStock.getRealNum());
// task.setTaskPriority(1);
// task.setRemark1("手动出库");
// outTasks.add(task);
// taskRecordMapper.addTask(task);
// }
// // 把这条库存记录可用数量更新为 0
// stockMapper.updateStockAvailableNumWithStockId(outStock.getStockId(), outStock.getAvailableNum()-outNum);
// // 更新库存为出库中
// stockMapper.updateStockStatusWithLocationId(outStock.getLocationId(), StockStatus.OUT.getCode());
// // 重新计算需求数量
// needNum -= outNum;
// }
// }
// 手动出库的生成出库任务 // 手动出库的生成出库任务
for(Stock outStock : stockList) { for(Stock outStock : stockList) {
if(needNum <= 0) { if(needNum <= 0) {
@ -224,7 +133,7 @@ public class OrderOutImplements implements IOrderOutService {
outTasks.add(task); outTasks.add(task);
} }
// 把这条库存记录可用数量更新为 0 // 把这条库存记录可用数量更新为 0
stockMapper.updateStockAvailableNumWithStockId(outStock.getStockId(), outStock.getAvailableNum()-outNum); // stockMapper.updateStockAvailableNumWithStockId(outStock.getStockId(), outStock.getAvailableNum()-outNum);
// 更新库存为出库中 // 更新库存为出库中
stockMapper.updateStockStatusWithLocationId(outStock.getLocationId(), StockStatus.OUT.getCode()); stockMapper.updateStockStatusWithLocationId(outStock.getLocationId(), StockStatus.OUT.getCode());
// 重新计算需求数量 // 重新计算需求数量

View File

@ -109,6 +109,7 @@ public class LocationUtils {
} }
/** /**
* 入库检查
* 在一堆空闲的库位中寻找一个可用的入库库位 * 在一堆空闲的库位中寻找一个可用的入库库位
* @param canUseLocations 可用的库位 * @param canUseLocations 可用的库位
* @return 可用的库位若没有可用的库位则返回 null * @return 可用的库位若没有可用的库位则返回 null
@ -171,6 +172,64 @@ public class LocationUtils {
} }
/** /**
* 在一堆空闲的库位中寻找一个可用的移库库位
* @param canUseLocations 可用的库位
* @return 可用的库位若没有可用的库位则返回 null
*/
public Location checkCanUseChangeLocation(List<Location> canUseLocations) {
if(canUseLocations == null || canUseLocations.isEmpty()) {
return null;
}
boolean canUse = true;
for (Location location : canUseLocations) {
/* 校验此位置是否有遮挡 */ /* 如果这位置有库存(可能出现记错导致有库存),或者这位置其他深度(不论深度大小)有任务则不采用此位置 */
/* 1 判断库存 */
Stock checkStock = new Stock();
checkStock.setLocationId(location.getLocationId());
List<Stock> checkResult = stockMapper.selStocks(checkStock);
if(!checkResult.isEmpty()) {
continue; // 库存不为空跳过
}
/* 2 判断同位置不同深度是否有任务 */
// 找出此位置不同深度的库位
// Location queryDifferentDepthLocation = new Location();
// queryDifferentDepthLocation.setAreaId(location.getAreaId());
// queryDifferentDepthLocation.setQueue(location.getQueue());
// queryDifferentDepthLocation.setTunnelId(location.getTunnelId());
// queryDifferentDepthLocation.setLayer(location.getLayer());
// List<Location> differentDepthLocations = locationMapper.selLocations(queryDifferentDepthLocation);
// if(differentDepthLocations == null) {
// continue; // 数据库查询失败
// }
// if(!differentDepthLocations.isEmpty()) {
// // 存在干涉库位检验其是否有未完成的任务
// for (Location differentDepthLocation : differentDepthLocations) {
// // 找出此位置不同深度的库位
// Location queryLocationTask = new Location();
// queryLocationTask.setLocationId(differentDepthLocation.getLocationId());
// List<Task> locationTasks = taskMapper.haveNotCompleteTask(differentDepthLocation.getLocationId());
// if(locationTasks == null) {
// log.info("检查存在干涉库位失败,数据库异常");
// canUse = false;
// break; // 数据库查询失败
// }
// if(!locationTasks.isEmpty()) {
// log.info("检查存在干涉库位失败,此位置有未完成的任务,任务位置{}",differentDepthLocation.getLocationId());
// canUse = false;
// break; // 有任务这个库位不行
// }
// }
// }
if(canUse) {
return location;
}
}
return null;
}
/**
*
* 入库检查
* 在一堆空闲的库位中寻找一个可用的入库库位 存在交换区域进行里层交换区与可用库位交换 * 在一堆空闲的库位中寻找一个可用的入库库位 存在交换区域进行里层交换区与可用库位交换
* @param canUseLocations 可用的库位 * @param canUseLocations 可用的库位
* @return 可用的库位若没有可用的库位则返回 null * @return 可用的库位若没有可用的库位则返回 null

View File

@ -124,7 +124,7 @@
<if test="singleWeight != null"> and single_weight = #{singleWeight}</if> <if test="singleWeight != null"> and single_weight = #{singleWeight}</if>
<if test="storageDays != null"> and storage_days = #{storageDays}</if> <if test="storageDays != null"> and storage_days = #{storageDays}</if>
</where> </where>
order by goods_status desc, available_num desc , create_time asc order by available_num desc , create_time asc
</select> </select>
<insert id="addStock" parameterType="Stock"> <insert id="addStock" parameterType="Stock">