代码更新:
傻逼xhp屁事多
This commit is contained in:
parent
3c9eab36e7
commit
7d109bc7e6
|
|
@ -22,7 +22,9 @@ public enum ConfigMapKeyEnum {
|
||||||
RECORD_DELETE_INTERVAL("RECORD_DELETE_INTERVAL"),
|
RECORD_DELETE_INTERVAL("RECORD_DELETE_INTERVAL"),
|
||||||
IMPORTANT_RECORD_DELETE_INTERVAL("IMPORTANT_RECORD_DELETE_INTERVAL"),
|
IMPORTANT_RECORD_DELETE_INTERVAL("IMPORTANT_RECORD_DELETE_INTERVAL"),
|
||||||
USE_SETTING_DATE("USE_SETTING_DATE"),
|
USE_SETTING_DATE("USE_SETTING_DATE"),
|
||||||
SETTING_DATE("SETTING_DATE");
|
SETTING_DATE("SETTING_DATE"),
|
||||||
|
RATE_MIN_TO_MAX("RATE_MIN_TO_MAX"),
|
||||||
|
WORK_PRIORITY("WORK_PRIORITY");
|
||||||
private final String configKey;
|
private final String configKey;
|
||||||
ConfigMapKeyEnum(String configKey) {
|
ConfigMapKeyEnum(String configKey) {
|
||||||
this.configKey = configKey;
|
this.configKey = configKey;
|
||||||
|
|
|
||||||
|
|
@ -198,14 +198,21 @@ public class JobComponent {
|
||||||
List<Stand> stands = standService.list(new LambdaQueryWrapper<Stand>()
|
List<Stand> stands = standService.list(new LambdaQueryWrapper<Stand>()
|
||||||
.eq(Stand::getIsLock, 0).eq(Stand::getStandStatus, 0)
|
.eq(Stand::getIsLock, 0).eq(Stand::getStandStatus, 0)
|
||||||
.eq(Stand::getStandType, 2));
|
.eq(Stand::getStandType, 2));
|
||||||
for (Stand workStation : stands) {
|
List<String> standIds = stands.stream().map(Stand::getStandId).toList();
|
||||||
|
for (String standId : standIds) {
|
||||||
try {
|
try {
|
||||||
// 执行工作
|
workService.doWork(standId);
|
||||||
workService.doWork(workStation.getStandId());
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("执行工作时发生错误:{}", convertJsonString(e.getMessage()));
|
logger.error("执行工作时发生错误:{}", convertJsonString(e.getMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// try {
|
||||||
|
// // 执行工作
|
||||||
|
// workService.doWorkNew(standIds);
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// logger.error("执行工作时发生错误:{}", convertJsonString(e.getMessage()));
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package com.wms.service.business;
|
package com.wms.service.business;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 工作服务接口
|
* 工作服务接口
|
||||||
*/
|
*/
|
||||||
|
|
@ -16,6 +18,11 @@ public interface IWorkService {
|
||||||
*/
|
*/
|
||||||
void doWork(String workStation) throws Exception;
|
void doWork(String workStation) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新版执行工作
|
||||||
|
*/
|
||||||
|
void doWorkNew(List<String> standIds) throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 完成工作
|
* 完成工作
|
||||||
* @param workStation 工作站台
|
* @param workStation 工作站台
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static com.wms.config.InitLocalConfig.configMap;
|
import static com.wms.config.InitLocalConfig.configMap;
|
||||||
import static com.wms.config.InitLocalConfig.instantLocationMap;
|
import static com.wms.config.InitLocalConfig.instantLocationMap;
|
||||||
|
|
@ -718,6 +717,7 @@ public class WmsJobServiceImplements implements IWmsJobService {
|
||||||
String max_vehicle_nums = configMap.get(ConfigMapKeyEnum.MAX_VEHICLE_NUMS.getConfigKey());
|
String max_vehicle_nums = configMap.get(ConfigMapKeyEnum.MAX_VEHICLE_NUMS.getConfigKey());
|
||||||
String max_wcs_accept_nums = configMap.get(ConfigMapKeyEnum.MAX_WCS_ACCEPT_NUMS.getConfigKey());
|
String max_wcs_accept_nums = configMap.get(ConfigMapKeyEnum.MAX_WCS_ACCEPT_NUMS.getConfigKey());
|
||||||
String max_stand_vehicle_nums = configMap.get(ConfigMapKeyEnum.MAX_STAND_VEHICLE_NUMS.getConfigKey());
|
String max_stand_vehicle_nums = configMap.get(ConfigMapKeyEnum.MAX_STAND_VEHICLE_NUMS.getConfigKey());
|
||||||
|
String minToMax = configMap.get(ConfigMapKeyEnum.RATE_MIN_TO_MAX.getConfigKey());
|
||||||
if (StringUtils.isEmpty(max_vehicle_nums) || StringUtils.isEmpty(max_wcs_accept_nums) || StringUtils.isEmpty(max_stand_vehicle_nums)) {
|
if (StringUtils.isEmpty(max_vehicle_nums) || StringUtils.isEmpty(max_wcs_accept_nums) || StringUtils.isEmpty(max_stand_vehicle_nums)) {
|
||||||
logger.error("配置未生成");
|
logger.error("配置未生成");
|
||||||
return;
|
return;
|
||||||
|
|
@ -731,6 +731,17 @@ public class WmsJobServiceImplements implements IWmsJobService {
|
||||||
if (remainVehicleNums <= 0) {
|
if (remainVehicleNums <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// 少:多的比率
|
||||||
|
int minToMaxRate = 1;
|
||||||
|
try {
|
||||||
|
minToMaxRate = Integer.parseInt(minToMax);
|
||||||
|
if (minToMaxRate > 21) {
|
||||||
|
// 最大值设定为21
|
||||||
|
minToMaxRate = 21;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("获取少:多的比率错误,使用默认值1");
|
||||||
|
}
|
||||||
// 需要发送给wcs的任务列表
|
// 需要发送给wcs的任务列表
|
||||||
List<WcsTaskRequest> request = new ArrayList<>();
|
List<WcsTaskRequest> request = new ArrayList<>();
|
||||||
// 已经下发的任务组列表
|
// 已经下发的任务组列表
|
||||||
|
|
@ -776,7 +787,7 @@ public class WmsJobServiceImplements implements IWmsJobService {
|
||||||
// 找到之前完成的
|
// 找到之前完成的
|
||||||
List<StandStackerTask> currentStandFinishedTasks = standStackerTasks.stream().filter(standStackerTask -> standStackerTask.getStandId().equals(pickStand.getStandId()) && standStackerTask.getTaskType() == 1 && standStackerTask.getTaskStatus() == 1).toList();
|
List<StandStackerTask> currentStandFinishedTasks = standStackerTasks.stream().filter(standStackerTask -> standStackerTask.getStandId().equals(pickStand.getStandId()) && standStackerTask.getTaskType() == 1 && standStackerTask.getTaskStatus() == 1).toList();
|
||||||
if (!currentStandFinishedTasks.isEmpty()) {
|
if (!currentStandFinishedTasks.isEmpty()) {
|
||||||
if (currentStandFinishedTasks.get(0).getLastQtyType() <= 2) {
|
if (currentStandFinishedTasks.get(0).getLastQtyType() <= minToMaxRate) {
|
||||||
thisQtyType = currentStandFinishedTasks.get(0).getLastQtyType() + 1;
|
thisQtyType = currentStandFinishedTasks.get(0).getLastQtyType() + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -810,7 +821,7 @@ public class WmsJobServiceImplements implements IWmsJobService {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
String vehicleId;
|
String vehicleId;
|
||||||
if (thisQtyType == 1 || thisQtyType == 2) {
|
if (thisQtyType <= minToMaxRate) {
|
||||||
// 最少使用的箱子
|
// 最少使用的箱子
|
||||||
vehicleId = vehicleStandsMap.entrySet().stream()
|
vehicleId = vehicleStandsMap.entrySet().stream()
|
||||||
.min(Comparator.comparingInt(Map.Entry::getValue))
|
.min(Comparator.comparingInt(Map.Entry::getValue))
|
||||||
|
|
@ -883,7 +894,7 @@ public class WmsJobServiceImplements implements IWmsJobService {
|
||||||
while (availNum > 0) {
|
while (availNum > 0) {
|
||||||
// 设置分配策略
|
// 设置分配策略
|
||||||
StandStackerTask newStandStackerTask = new StandStackerTask();
|
StandStackerTask newStandStackerTask = new StandStackerTask();
|
||||||
newStandStackerTask.setLastQtyType(2);// 超额固定为2
|
newStandStackerTask.setLastQtyType(minToMaxRate);// 超额固定为少
|
||||||
// 查询这个这台堆垛机的料箱号
|
// 查询这个这台堆垛机的料箱号
|
||||||
List<String> thisStackerVehicleIds = new ArrayList<>();
|
List<String> thisStackerVehicleIds = new ArrayList<>();
|
||||||
for (Task task : allTasks) {
|
for (Task task : allTasks) {
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@ package com.wms.service.business.serviceImplements;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.wms.constants.enums.ConfigMapKeyEnum;
|
import com.wms.constants.enums.*;
|
||||||
import com.wms.constants.enums.TaskType;
|
|
||||||
import com.wms.entity.app.dto.WorkCenterAndOrderDto;
|
import com.wms.entity.app.dto.WorkCenterAndOrderDto;
|
||||||
|
import com.wms.entity.app.dto.extend.StockDetailInfo;
|
||||||
import com.wms.entity.table.*;
|
import com.wms.entity.table.*;
|
||||||
import com.wms.service.*;
|
import com.wms.service.*;
|
||||||
import com.wms.service.business.IWmsTaskService;
|
import com.wms.service.business.IWmsTaskService;
|
||||||
|
|
@ -31,6 +31,7 @@ import java.util.stream.Collectors;
|
||||||
import static com.wms.config.InitLocalConfig.*;
|
import static com.wms.config.InitLocalConfig.*;
|
||||||
import static com.wms.constants.WmsConstants.MYSQL_JSON_CI;
|
import static com.wms.constants.WmsConstants.MYSQL_JSON_CI;
|
||||||
import static com.wms.utils.StringUtils.convertJsonString;
|
import static com.wms.utils.StringUtils.convertJsonString;
|
||||||
|
import static com.wms.utils.WmsUtils.generateId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 工作服务接口的实现
|
* 工作服务接口的实现
|
||||||
|
|
@ -58,6 +59,7 @@ public class WorkServiceImplements implements IWorkService {
|
||||||
private final List<String> workCreatingStations = new ArrayList<>();// 当前正在创建任务的站台
|
private final List<String> workCreatingStations = new ArrayList<>();// 当前正在创建任务的站台
|
||||||
private final List<String> workDoingStations = new ArrayList<>();// 当前正在执行任务的站台
|
private final List<String> workDoingStations = new ArrayList<>();// 当前正在执行任务的站台
|
||||||
private final List<String> workFinishingStations = new ArrayList<>();// 当前正在完成任务的站台
|
private final List<String> workFinishingStations = new ArrayList<>();// 当前正在完成任务的站台
|
||||||
|
private final VehicleService vehicleService;// 料箱服务
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新版创建工作
|
* 新版创建工作
|
||||||
|
|
@ -113,11 +115,21 @@ public class WorkServiceImplements implements IWorkService {
|
||||||
// 当前站台分配的工位
|
// 当前站台分配的工位
|
||||||
List<WorkFlow> currentStationWorkFlows = new ArrayList<>();
|
List<WorkFlow> currentStationWorkFlows = new ArrayList<>();
|
||||||
// 先找MWL机型
|
// 先找MWL机型
|
||||||
|
String workPriority = configMap.get(ConfigMapKeyEnum.WORK_PRIORITY.getConfigKey());
|
||||||
|
if (!StringUtils.isEmpty(workPriority) && workPriority.equals("1")) {
|
||||||
|
// 找非MWL机型--先平地机
|
||||||
|
findWorks(workStation, currentStationWorkFlows, "NOT_MWL", currentWorkDate);
|
||||||
|
if (currentStationWorkFlows.isEmpty()) {
|
||||||
|
findWorks(workStation, currentStationWorkFlows, "MWL", currentWorkDate);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 先装载机
|
||||||
findWorks(workStation, currentStationWorkFlows, "MWL", currentWorkDate);
|
findWorks(workStation, currentStationWorkFlows, "MWL", currentWorkDate);
|
||||||
if (currentStationWorkFlows.isEmpty()) {
|
if (currentStationWorkFlows.isEmpty()) {
|
||||||
// 找非MWL机型
|
// 找非MWL机型
|
||||||
findWorks(workStation, currentStationWorkFlows, "NOT_MWL", currentWorkDate);
|
findWorks(workStation, currentStationWorkFlows, "NOT_MWL", currentWorkDate);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// 如果当前站台有任务
|
// 如果当前站台有任务
|
||||||
if (!currentStationWorkFlows.isEmpty()) {
|
if (!currentStationWorkFlows.isEmpty()) {
|
||||||
// 将工作流列表添加进数据库
|
// 将工作流列表添加进数据库
|
||||||
|
|
@ -310,7 +322,7 @@ public class WorkServiceImplements implements IWorkService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 保存重新分配的goodsToStationList
|
// 保存重新分配的goodsToStationList
|
||||||
if (!needDistributeGoodsMap.values().isEmpty()) {
|
if (!needDistributeGoodsMap.isEmpty()) {
|
||||||
goodsToStationService.saveOrUpdateBatch(needDistributeGoodsMap.values());
|
goodsToStationService.saveOrUpdateBatch(needDistributeGoodsMap.values());
|
||||||
}
|
}
|
||||||
// 保存需要完成的工作流
|
// 保存需要完成的工作流
|
||||||
|
|
@ -627,4 +639,317 @@ public class WorkServiceImplements implements IWorkService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新版开始工作
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
|
||||||
|
public void doWorkNew(List<String> standIds) {
|
||||||
|
try {
|
||||||
|
if (standIds == null || standIds.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 查找当前站台未开始的工作流
|
||||||
|
List<WorkFlow> currentWorkFlowList = workFlowService.list(new LambdaQueryWrapper<WorkFlow>()
|
||||||
|
.ne(WorkFlow::getWorkStatus, 2)
|
||||||
|
.in(WorkFlow::getWorkStation, standIds));
|
||||||
|
// 没有可做的任务
|
||||||
|
if (currentWorkFlowList == null || currentWorkFlowList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 查站台要料表---未分配以及分配但未完全分配
|
||||||
|
List<GoodsToStation> goodsToStationList = goodsToStationService.list(new LambdaQueryWrapper<GoodsToStation>()
|
||||||
|
.in(!standIds.isEmpty(), GoodsToStation::getWorkStation, standIds));
|
||||||
|
List<GoodsToStation> notFinishedGoodsList = goodsToStationList.stream().filter(goodsToStation -> goodsToStation.getDistributeStatus() < 2).toList();
|
||||||
|
if (notFinishedGoodsList.isEmpty()) {
|
||||||
|
List<GoodsToStation> needDistributeGoodsList = new ArrayList<>();
|
||||||
|
// 需要完成的工作流
|
||||||
|
List<WorkFlow> needFinishWorkFlowList = new ArrayList<>();
|
||||||
|
// 查询所有的outsideVehicles
|
||||||
|
List<OutsideVehicles> outsideVehiclesList = outsideVehiclesService.list(new LambdaQueryWrapper<OutsideVehicles>()
|
||||||
|
.ne(OutsideVehicles::getOutStatus, 2));
|
||||||
|
// 查询所有的拣选任务
|
||||||
|
List<PickTask> pickTaskList = pickTaskService.list();
|
||||||
|
for (String standId : standIds) {
|
||||||
|
// 当前站台未完成工作
|
||||||
|
List<WorkFlow> thisStandWorkFlowList = currentWorkFlowList.stream().filter(workFlow -> workFlow.getWorkStation().equals(standId)).toList();
|
||||||
|
// 当前站台拣选任务
|
||||||
|
List<PickTask> thisStandPickTaskList = pickTaskList.stream().filter(pickTask -> pickTask.getStandId().equals(standId)).toList();
|
||||||
|
// 需要重新分配的goodsToStationsList
|
||||||
|
Map<String, GoodsToStation> needDistributeGoodsMap = new HashMap<>();
|
||||||
|
// 所有缺料的分配
|
||||||
|
List<String> lackGoodsIdList = goodsToStationList.stream().filter(goodsToStation -> goodsToStation.getDistributeStatus() == 3 && goodsToStation.getWorkStation().equals(standId)).map(GoodsToStation::getGoodsId).distinct().toList();
|
||||||
|
// 不缺料的分配
|
||||||
|
Map<String, GoodsToStation> noLackGoodsMap = goodsToStationList.stream().filter(goodsToStation -> goodsToStation.getDistributeStatus() == 2 && goodsToStation.getWorkStation().equals(standId)).collect(Collectors.toMap(GoodsToStation::getGoodsId, goodsToStation -> goodsToStation));
|
||||||
|
// 查询当前工作流中所有缺料的数据行
|
||||||
|
for (WorkFlow notFinishedWorkFlow : thisStandWorkFlowList) {
|
||||||
|
if (notFinishedWorkFlow.getPickedNum().compareTo(notFinishedWorkFlow.getNeedNum()) < 0) {
|
||||||
|
// 判断这个料有没有在外面
|
||||||
|
List<OutsideVehicles> currentGoodsOutsideVehiclesList = outsideVehiclesList.stream().filter(outsideVehicles1 -> outsideVehicles1.getGoodsId().equals(notFinishedWorkFlow.getGoodsId())).toList();
|
||||||
|
if (!currentGoodsOutsideVehiclesList.isEmpty()) {
|
||||||
|
// 判断这些箱子有没有当前站台的拣选任务
|
||||||
|
boolean havePickTask = false;
|
||||||
|
for (OutsideVehicles currentGoodsOutsideVehicles : currentGoodsOutsideVehiclesList) {
|
||||||
|
List<PickTask> currentGoodsPickTaskList = thisStandPickTaskList.stream().filter(pickTask -> pickTask.getVehicleId().equals(currentGoodsOutsideVehicles.getVehicleId())).toList();
|
||||||
|
if (!currentGoodsPickTaskList.isEmpty()) {
|
||||||
|
havePickTask = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (havePickTask) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 缺料时,判断是否当前物料在缺料列表中
|
||||||
|
if (lackGoodsIdList.contains(notFinishedWorkFlow.getGoodsId())) {
|
||||||
|
// 缺料,添加到需要分配的列表中
|
||||||
|
notFinishedWorkFlow.setWorkStatus(2);
|
||||||
|
notFinishedWorkFlow.setFinishTime(LocalDateTime.now());
|
||||||
|
notFinishedWorkFlow.setOpUser("缺料,系统自动完成");
|
||||||
|
needFinishWorkFlowList.add(notFinishedWorkFlow);
|
||||||
|
} else {
|
||||||
|
BigDecimal needNum = notFinishedWorkFlow.getNeedNum().subtract(notFinishedWorkFlow.getPickedNum());
|
||||||
|
if (needDistributeGoodsMap.containsKey(notFinishedWorkFlow.getGoodsId())) {
|
||||||
|
// 减少分配数量
|
||||||
|
GoodsToStation oldGoodsToStation = needDistributeGoodsMap.get(notFinishedWorkFlow.getGoodsId());
|
||||||
|
oldGoodsToStation.setDistributedNum(oldGoodsToStation.getDistributedNum().subtract(needNum));
|
||||||
|
oldGoodsToStation.setDistributeStatus(1);
|
||||||
|
needDistributeGoodsMap.replace(notFinishedWorkFlow.getGoodsId(), oldGoodsToStation);
|
||||||
|
} else {
|
||||||
|
if (noLackGoodsMap.containsKey(notFinishedWorkFlow.getGoodsId())) {
|
||||||
|
GoodsToStation newGoodsToStation = noLackGoodsMap.get(notFinishedWorkFlow.getGoodsId());
|
||||||
|
newGoodsToStation.setDistributedNum(newGoodsToStation.getDistributedNum().subtract(needNum));
|
||||||
|
newGoodsToStation.setDistributeStatus(1);
|
||||||
|
needDistributeGoodsMap.put(notFinishedWorkFlow.getGoodsId(), newGoodsToStation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 不缺料,直接完成
|
||||||
|
notFinishedWorkFlow.setWorkStatus(2);
|
||||||
|
notFinishedWorkFlow.setFinishTime(LocalDateTime.now());
|
||||||
|
notFinishedWorkFlow.setOpUser("不缺料,系统自动完成");
|
||||||
|
needFinishWorkFlowList.add(notFinishedWorkFlow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 添加数据
|
||||||
|
needDistributeGoodsList.addAll(needDistributeGoodsMap.values());
|
||||||
|
}
|
||||||
|
// 保存重新分配的goodsToStationList
|
||||||
|
if (!needDistributeGoodsList.isEmpty()) {
|
||||||
|
goodsToStationService.saveOrUpdateBatch(needDistributeGoodsList);
|
||||||
|
}
|
||||||
|
// 保存需要完成的工作流
|
||||||
|
if (!needFinishWorkFlowList.isEmpty()) {
|
||||||
|
workFlowService.updateBatchById(needFinishWorkFlowList);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 未分配的物料需求
|
||||||
|
Map<String, List<GoodsToStation>> notFinishedGoodsMap = notFinishedGoodsList.stream().collect(Collectors.groupingBy(GoodsToStation::getGoodsId));
|
||||||
|
logger.info("物料种类数:{}", notFinishedGoodsMap.size());
|
||||||
|
StringBuilder goodsSqlString = new StringBuilder();
|
||||||
|
for (String goodsId : notFinishedGoodsMap.keySet()) {
|
||||||
|
if (StringUtils.isEmpty(goodsSqlString.toString())) {
|
||||||
|
goodsSqlString.append("(goods_related ->> '$.goodsId' in (\"").append(goodsId).append("\"");
|
||||||
|
} else {
|
||||||
|
goodsSqlString.append(",\"").append(goodsId).append("\"");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
goodsSqlString.append("))");
|
||||||
|
// 查找到所有的非间接物料库存
|
||||||
|
List<Stock> allStockList = stockService.list(new LambdaQueryWrapper<Stock>()
|
||||||
|
.ne(Stock::getGoodsType, "间接物料")
|
||||||
|
.apply(goodsSqlString + MYSQL_JSON_CI)
|
||||||
|
.orderByAsc(Stock::getCreateTime));
|
||||||
|
// 找到只在一个箱子中的料
|
||||||
|
Map<String, List<Stock>> goodsStockMap = allStockList.stream().collect(Collectors.groupingBy(stock -> stock.getGoodsRelated().getGoodsId()));
|
||||||
|
List<String> oneVehicleGoodsList = new ArrayList<>();// 存放料箱号
|
||||||
|
for (String goodsId : goodsStockMap.keySet()) {
|
||||||
|
if (goodsStockMap.get(goodsId).size() == 1 && !oneVehicleGoodsList.contains(goodsStockMap.get(goodsId).get(0).getVehicleId())) {
|
||||||
|
oneVehicleGoodsList.add(goodsStockMap.get(goodsId).get(0).getVehicleId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// OK库存的料
|
||||||
|
List<Stock> stockList = allStockList.stream().filter(stock -> Objects.equals(stock.getStockStatus(), StockStatus.OK.getCode())).toList();
|
||||||
|
// 所有库存的料--后续判断用
|
||||||
|
List<Stock> usedStockList = new ArrayList<>(allStockList.stream().filter(stock -> !Objects.equals(stock.getStockStatus(), StockStatus.OK.getCode())).toList());
|
||||||
|
// 转换成Map
|
||||||
|
Map<String, List<Stock>> stockMap = stockList.stream().sorted(Comparator.comparing(Stock::getCreateTime)).collect(Collectors.groupingBy(Stock::getVehicleId));
|
||||||
|
// 新建的任务列表
|
||||||
|
List<Task> newTaskList = new ArrayList<>();
|
||||||
|
List<PickTask> newPickTaskList = new ArrayList<>();
|
||||||
|
List<OutsideVehicles> newOutsideVehicleList = new ArrayList<>();
|
||||||
|
List<String> newOutVehicleList = new ArrayList<>();
|
||||||
|
// 循环生成任务
|
||||||
|
for (String vehicleId : stockMap.keySet()) {
|
||||||
|
List<Stock> thisVehicleStockList = stockMap.get(vehicleId);
|
||||||
|
// 站台列表
|
||||||
|
List<String> standIdList = new ArrayList<>();
|
||||||
|
int lastStandNo = 0;
|
||||||
|
// 针对这个库存去做处理
|
||||||
|
for (Stock stock : thisVehicleStockList) {
|
||||||
|
List<GoodsToStation> currentGoodsRequirementList = notFinishedGoodsMap.get(stock.getGoodsRelated().getGoodsId());
|
||||||
|
if (currentGoodsRequirementList == null || currentGoodsRequirementList.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BigDecimal thisNum = stock.getGoodsRelated().getRemainNum();
|
||||||
|
if (thisNum.compareTo(BigDecimal.ZERO) <= 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (GoodsToStation goodsToStation : currentGoodsRequirementList) {
|
||||||
|
BigDecimal needNum = goodsToStation.getTotalNum().subtract(goodsToStation.getDistributedNum());
|
||||||
|
if (needNum.compareTo(BigDecimal.ZERO) <= 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int thisStandNo = Integer.parseInt(String.valueOf(goodsToStation.getWorkStation().charAt(goodsToStation.getWorkStation().length() - 1)));
|
||||||
|
if (lastStandNo != 0 && !oneVehicleGoodsList.contains(vehicleId)) {
|
||||||
|
// 不是单箱物料
|
||||||
|
if (lastStandNo <= 5 && thisStandNo > 5) {
|
||||||
|
// 箱子去了前区就不去后区
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (lastStandNo > 5 && thisStandNo <= 5) {
|
||||||
|
// 箱子去了后区就不去前区
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (thisNum.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
// logger.info("箱号:{},料号:{},库存数量:{}, 需求数量:{},站台号:{}", stock.getVehicleId(), goodsToStation.getGoodsId(), stock.getGoodsRelated().getRemainNum(), needNum, goodsToStation.getWorkStation());
|
||||||
|
if (thisNum.compareTo(needNum) >= 0) {
|
||||||
|
// 当前箱子剩余物料数量多于需求数量
|
||||||
|
goodsToStation.setDistributedNum(goodsToStation.getTotalNum());
|
||||||
|
thisNum = thisNum.subtract(needNum);
|
||||||
|
} else {
|
||||||
|
goodsToStation.setDistributedNum(goodsToStation.getDistributedNum().add(thisNum));
|
||||||
|
thisNum = BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
// 更新剩余库存
|
||||||
|
StockDetailInfo goodsRelated = stock.getGoodsRelated();
|
||||||
|
goodsRelated.setRemainNum(thisNum);
|
||||||
|
stock.setGoodsRelated(goodsRelated);
|
||||||
|
// 更新站台No
|
||||||
|
lastStandNo = thisStandNo;
|
||||||
|
// 添加站台
|
||||||
|
if (!standIdList.contains(goodsToStation.getWorkStation())) {
|
||||||
|
standIdList.add(goodsToStation.getWorkStation());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 更新map
|
||||||
|
notFinishedGoodsMap.replace(stock.getGoodsRelated().getGoodsId(), currentGoodsRequirementList);
|
||||||
|
// 添加流转箱数据
|
||||||
|
if (!standIdList.isEmpty()) {
|
||||||
|
OutsideVehicles outsideVehicle = new OutsideVehicles();
|
||||||
|
outsideVehicle.setOutsideId(generateId("OUTSIDE_"));
|
||||||
|
outsideVehicle.setVehicleId(stock.getVehicleId());
|
||||||
|
outsideVehicle.setGoodsId(stock.getGoodsRelated().getGoodsId());
|
||||||
|
outsideVehicle.setRemainNum(stock.getGoodsRelated().getRemainNum());
|
||||||
|
outsideVehicle.setOutStatus(0);
|
||||||
|
newOutsideVehicleList.add(outsideVehicle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 添加库存列表
|
||||||
|
usedStockList.addAll(thisVehicleStockList);
|
||||||
|
// 没使用到当前箱子
|
||||||
|
if (standIdList.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 添加出库任务
|
||||||
|
Task tempOutTask = new Task();
|
||||||
|
tempOutTask.setTaskId(generateId("CK_"));
|
||||||
|
tempOutTask.setTaskType(TaskType.OUT.getCode());
|
||||||
|
tempOutTask.setTaskGroup(generateId(""));
|
||||||
|
tempOutTask.setTaskStatus(WmsTaskStatus.NEW.getCode());
|
||||||
|
tempOutTask.setTaskPriority(1);
|
||||||
|
tempOutTask.setVehicleId(vehicleId);
|
||||||
|
tempOutTask.setUserName("WMS_AUTO");
|
||||||
|
tempOutTask.setOrigin(thisVehicleStockList.get(0).getLocationId());
|
||||||
|
tempOutTask.setDestination("");
|
||||||
|
tempOutTask.setCreateTime(LocalDateTime.now());
|
||||||
|
tempOutTask.setIsPicking(1);
|
||||||
|
tempOutTask.setPickStand(standIdList.get(0));
|
||||||
|
newTaskList.add(tempOutTask);
|
||||||
|
// 添加出库箱子列表
|
||||||
|
newOutVehicleList.add(vehicleId);
|
||||||
|
// 添加拣选任务
|
||||||
|
for (String standId : standIdList) {
|
||||||
|
PickTask tempPickTask = new PickTask();
|
||||||
|
tempPickTask.setPickTaskId(vehicleId + "_" + standId);
|
||||||
|
tempPickTask.setVehicleId(vehicleId);
|
||||||
|
tempPickTask.setStandId(standId);
|
||||||
|
tempPickTask.setPickStatus(PickTaskStatusEnum.TEMP.getCode());
|
||||||
|
tempPickTask.setLastUpdateTime(LocalDateTime.now());
|
||||||
|
newPickTaskList.add(tempPickTask);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 保存数据库
|
||||||
|
if (!newTaskList.isEmpty()) {
|
||||||
|
taskService.saveBatch(newTaskList);
|
||||||
|
}
|
||||||
|
if (!newPickTaskList.isEmpty()) {
|
||||||
|
pickTaskService.saveBatch(newPickTaskList);
|
||||||
|
}
|
||||||
|
if (!newOutsideVehicleList.isEmpty()) {
|
||||||
|
outsideVehiclesService.saveBatch(newOutsideVehicleList);
|
||||||
|
}
|
||||||
|
if (!newOutVehicleList.isEmpty()) {
|
||||||
|
// 更新库存状态
|
||||||
|
stockService.update(new LambdaUpdateWrapper<Stock>()
|
||||||
|
.set(Stock::getStockStatus, StockStatus.OUT.getCode())
|
||||||
|
.in(Stock::getVehicleId, newOutVehicleList));
|
||||||
|
// 更新料箱状态
|
||||||
|
vehicleService.update(new LambdaUpdateWrapper<Vehicle>()
|
||||||
|
.set(Vehicle::getVehicleStatus, VehicleStatus.OUT.getCode())
|
||||||
|
.in(Vehicle::getVehicleId, newOutVehicleList));
|
||||||
|
}
|
||||||
|
// 处理任务需求
|
||||||
|
List<GoodsToStation> updateGoodsToStation = new LinkedList<>();
|
||||||
|
for (String goodsId : notFinishedGoodsMap.keySet()) {
|
||||||
|
List<GoodsToStation> thisGoodsToStationList = notFinishedGoodsMap.get(goodsId);
|
||||||
|
for (GoodsToStation thisGoodsToStation : thisGoodsToStationList) {
|
||||||
|
if (thisGoodsToStation.getDistributedNum().compareTo(thisGoodsToStation.getTotalNum()) >= 0) {
|
||||||
|
// 分配完成
|
||||||
|
thisGoodsToStation.setDistributeStatus(2);
|
||||||
|
} else {
|
||||||
|
// 判断当前物料的库存余量是否足够
|
||||||
|
List<Stock> thisGoodsStockList = usedStockList.stream().filter(
|
||||||
|
stock ->
|
||||||
|
stock.getGoodsRelated().getGoodsId().equals(goodsId)
|
||||||
|
&& stock.getGoodsRelated().getRemainNum().compareTo(BigDecimal.ZERO) > 0).toList();
|
||||||
|
if (thisGoodsStockList.isEmpty()) {
|
||||||
|
// 缺料
|
||||||
|
thisGoodsToStation.setDistributeStatus(3);
|
||||||
|
} else {
|
||||||
|
// 已分配但未结束
|
||||||
|
thisGoodsToStation.setDistributeStatus(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateGoodsToStation.addAll(thisGoodsToStationList);
|
||||||
|
}
|
||||||
|
goodsToStationService.updateBatchById(updateGoodsToStation);
|
||||||
|
// 更新工作流状态
|
||||||
|
List<String> workFlowIds = currentWorkFlowList.stream().map(WorkFlow::getWorkFlowId).distinct().toList();
|
||||||
|
List<String> orderIds = currentWorkFlowList.stream().map(WorkFlow::getOrderId).distinct().toList();
|
||||||
|
List<String> goodsIds = currentWorkFlowList.stream().map(WorkFlow::getGoodsId).distinct().toList();
|
||||||
|
List<String> smallBoxes = currentWorkFlowList.stream().map(WorkFlow::getWorkCenter).distinct().toList();
|
||||||
|
workFlowService.update(new LambdaUpdateWrapper<WorkFlow>()
|
||||||
|
.set(WorkFlow::getWorkStatus, 1)
|
||||||
|
.in(WorkFlow::getWorkFlowId, workFlowIds)
|
||||||
|
.eq(WorkFlow::getWorkStatus, 0));
|
||||||
|
// 更新工单表状态
|
||||||
|
kateOrdersService.update(new LambdaUpdateWrapper<KateOrders>()
|
||||||
|
.set(KateOrders::getOrderStatus, 2)
|
||||||
|
.in(KateOrders::getOrderId, orderIds)
|
||||||
|
.in(KateOrders::getGoodsId, goodsIds)
|
||||||
|
.in(KateOrders::getSupplyArea, smallBoxes)
|
||||||
|
.eq(KateOrders::getOrderStatus, 1));
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("执行工作发生异常:{}", convertJsonString(e));
|
||||||
|
// 回滚事务
|
||||||
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,20 +8,20 @@ spring:
|
||||||
# 主库
|
# 主库
|
||||||
master:
|
master:
|
||||||
# 卡特数据库服务器
|
# 卡特数据库服务器
|
||||||
# url: jdbc:mysql://10.90.36.71:3306/wms_kate_suzhou?characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowMultiQueries=true&rewriteBatchedStatements=true
|
url: jdbc:mysql://10.90.36.71:3306/wms_kate_suzhou?characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowMultiQueries=true&rewriteBatchedStatements=true
|
||||||
# username: developer
|
username: developer
|
||||||
# password: developer
|
password: developer
|
||||||
# driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
# 宝开服务器--内网
|
# 宝开服务器--内网
|
||||||
# url: jdbc:mysql://192.168.3.254:3306/wms_kate_suzhou?characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowMultiQueries=true&rewriteBatchedStatements=true
|
# url: jdbc:mysql://192.168.3.254:3306/wms_kate_suzhou?characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowMultiQueries=true&rewriteBatchedStatements=true
|
||||||
# username: coder
|
# username: coder
|
||||||
# password: coder
|
# password: coder
|
||||||
# driver-class-name: com.mysql.cj.jdbc.Driver
|
# driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
# # 本地环境
|
# # 本地环境
|
||||||
url: jdbc:mysql://localhost:3306/wms_kate_suzhou?characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowMultiQueries=true&rewriteBatchedStatements=true
|
# url: jdbc:mysql://localhost:3306/wms_kate_suzhou?characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowMultiQueries=true&rewriteBatchedStatements=true
|
||||||
username: developer
|
# username: developer
|
||||||
password: developer
|
# password: developer
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
# driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
# 从库
|
# 从库
|
||||||
# slave_1:
|
# slave_1:
|
||||||
# url: jdbc:mysql://localhost:3306/wms_aaa?characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowMultiQueries=true&rewriteBatchedStatements=true
|
# url: jdbc:mysql://localhost:3306/wms_aaa?characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowMultiQueries=true&rewriteBatchedStatements=true
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user