1. 修改分配逻辑
This commit is contained in:
parent
0e293223b7
commit
5d6b17bc77
|
|
@ -4,14 +4,12 @@ import org.springframework.boot.ApplicationArguments;
|
|||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@SpringBootApplication()
|
||||
@EnableScheduling
|
||||
@EnableTransactionManagement
|
||||
@EnableAsync
|
||||
public class WmsApplication {
|
||||
/**
|
||||
* 用于重启程序的上下文
|
||||
|
|
|
|||
|
|
@ -1,36 +0,0 @@
|
|||
package com.wms.config;
|
||||
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
/**
|
||||
* 线程池配置
|
||||
*/
|
||||
@SpringBootConfiguration
|
||||
public class ThreadPoolConfig {
|
||||
@Bean("myThreadPool")
|
||||
public TaskExecutor taskExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
// 设置核心线程数
|
||||
executor.setCorePoolSize(10);
|
||||
// 设置最大线程数
|
||||
executor.setMaxPoolSize(20);
|
||||
// 设置队列容量
|
||||
executor.setQueueCapacity(100);
|
||||
// 设置线程活跃时间(秒)
|
||||
executor.setKeepAliveSeconds(300);
|
||||
// 设置线程默认名称前缀
|
||||
executor.setThreadNamePrefix("wmsThreadPool-");
|
||||
// 设置拒绝策略
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
// 等待所有任务结束后关闭线程池
|
||||
executor.setWaitForTasksToCompleteOnShutdown(true);
|
||||
|
||||
return executor;
|
||||
}
|
||||
}
|
||||
|
|
@ -593,8 +593,16 @@ public class KateWorkQueryController {
|
|||
// 没有看板数据,不需要生成看板需求
|
||||
continue;
|
||||
}
|
||||
if (pullGoods.getFeedingValue() == null || pullGoods.getFeedingValue().compareTo(BigDecimal.ZERO) <= 0) {
|
||||
logger.error("看板物料信息缺少补货点。");
|
||||
response.setCode(ResponseCode.ERROR.getCode());
|
||||
response.setMessage(pullGoods.getGoodsId() + "基础信息中缺少补货点或者补货点的值小于等于0。");
|
||||
return convertJsonString(response);
|
||||
}
|
||||
// 最大容量
|
||||
BigDecimal maxNum = pullGoods.getKanbanNum().multiply(pullGoods.getQuantityPerKanban());
|
||||
// 目标数量
|
||||
BigDecimal targetNum = pullGoods.getKanbanNum().multiply(pullGoods.getQuantityPerKanban());
|
||||
BigDecimal targetNum = pullGoods.getFeedingValue();// 改动,目标数量修正为补货点
|
||||
BigDecimal remainNum = BigDecimal.ZERO;
|
||||
// 判断是否包含请求物料
|
||||
if (stockOfGoodsDtoMap.containsKey(pullGoods.getGoodsId())) {
|
||||
|
|
@ -602,8 +610,16 @@ public class KateWorkQueryController {
|
|||
StockOfGoodsDto stockOfGoodsDto = stockOfGoodsDtoMap.get(pullGoods.getGoodsId());
|
||||
remainNum = stockOfGoodsDto.getRemainNumSum();
|
||||
}
|
||||
if (targetNum.compareTo(remainNum) <= 0) {
|
||||
// 数量充足,不需要补货
|
||||
continue;
|
||||
}
|
||||
// 计算需要多少个看板
|
||||
BigDecimal needKanbanQuantity = targetNum.subtract(remainNum).divide(pullGoods.getQuantityPerKanban(), 0, RoundingMode.FLOOR);
|
||||
BigDecimal needKanbanQuantity = targetNum.subtract(remainNum).divide(pullGoods.getQuantityPerKanban(), 0, RoundingMode.CEILING);
|
||||
if (remainNum.add(needKanbanQuantity.multiply(pullGoods.getQuantityPerKanban())).compareTo(maxNum) > 0) {
|
||||
// 超过最大容量
|
||||
needKanbanQuantity = needKanbanQuantity.subtract(BigDecimal.ONE);
|
||||
}
|
||||
// 看板表中当前物料的所有看板
|
||||
List<Kanban> kanbanList = kanbanService.list(new LambdaQueryWrapper<Kanban>()
|
||||
.eq(Kanban::getGoodsId, pullGoods.getGoodsId())
|
||||
|
|
@ -867,7 +883,7 @@ public class KateWorkQueryController {
|
|||
continue;
|
||||
}
|
||||
// 设置返回结果
|
||||
int boxQuantity = 0;
|
||||
int boxQuantity;
|
||||
if (orderQuantity <= 0) {
|
||||
boxQuantity = 1;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -2762,7 +2762,8 @@ public class TaskController {
|
|||
return convertJsonString(response);
|
||||
}
|
||||
// 查询到这些工单的dbs
|
||||
List<String> orderedOrdersIds = kateDBSList.stream().map(KateDBS::getWorkOrder).distinct().toList();
|
||||
Map<String, Integer> orderedOrdersIdsMap = kateDBSList.stream().collect(Collectors.toMap(KateDBS::getWorkOrder, KateDBS::getWorkSequence));
|
||||
List<String> orderedOrdersIds = orderedOrdersIdsMap.keySet().stream().sorted(Comparator.comparingInt(orderedOrdersIdsMap::get)).toList();
|
||||
List<String> toBeLightedOrders = orderedOrdersIds.stream().skip((long) (sortBoxRequest.getOrderOfOrders() - 1) * orderQuantity).limit(orderQuantity).toList();
|
||||
// 生成亮灯数据
|
||||
if (!toBeLightedOrders.isEmpty()) {
|
||||
|
|
|
|||
|
|
@ -98,7 +98,6 @@ public class KateWorkExecutor implements Job {
|
|||
} catch (Exception e) {
|
||||
log.error("执行工作时发生错误:{}", convertJsonString(e.getMessage()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,11 +6,6 @@ import java.util.List;
|
|||
* 工作服务接口
|
||||
*/
|
||||
public interface IWorkService {
|
||||
/**
|
||||
* 创建工作
|
||||
* @param workStation 工作站台
|
||||
*/
|
||||
void createWork(String workStation) throws Exception;
|
||||
|
||||
/**
|
||||
* 执行工作
|
||||
|
|
@ -18,11 +13,6 @@ public interface IWorkService {
|
|||
*/
|
||||
void doWork(String workStation) throws Exception;
|
||||
|
||||
/**
|
||||
* 新版执行工作
|
||||
*/
|
||||
void doWorkNew(List<String> standIds) throws Exception;
|
||||
|
||||
/**
|
||||
* 完成工作
|
||||
* @param workStation 工作站台
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.wms.constants.enums.*;
|
||||
import com.wms.entity.app.dto.WorkCenterAndOrderDto;
|
||||
import com.wms.entity.app.dto.extend.StockDetailInfo;
|
||||
import com.wms.entity.table.*;
|
||||
import com.wms.service.*;
|
||||
import com.wms.service.business.IWmsTaskService;
|
||||
|
|
@ -58,176 +57,8 @@ public class WorkServiceImplements implements IWorkService {
|
|||
private final TaskService taskService;// 任务服务
|
||||
private final WorkFlowLastService workFlowLastService;// 服务
|
||||
private final List<String> workCreatingStations = new ArrayList<>();// 当前正在创建任务的站台
|
||||
private final List<String> workDoingStations = new ArrayList<>();// 当前正在执行任务的站台
|
||||
private final List<String> workFinishingStations = new ArrayList<>();// 当前正在完成任务的站台
|
||||
private final VehicleService vehicleService;// 料箱服务
|
||||
|
||||
/**
|
||||
* 新版创建工作
|
||||
*
|
||||
* @param workStation 工作站台
|
||||
*/
|
||||
@Override
|
||||
@Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
|
||||
public void createWork(String workStation) {
|
||||
if (workCreatingStations.contains(workStation)) {
|
||||
// 当前站台正在创建任务
|
||||
return;
|
||||
} else {
|
||||
// 添加站台
|
||||
workCreatingStations.add(workStation);
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(workStation)) {
|
||||
// 站台号为空
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// 先判断当日是否是工作日
|
||||
LocalDate currentWorkDate = LocalDate.now();
|
||||
// 获取当前配置日期
|
||||
try {
|
||||
String useSettingDate = configMap.get(ConfigMapKeyEnum.USE_SETTING_DATE.getConfigKey());
|
||||
if (!StringUtils.isEmpty(useSettingDate) && useSettingDate.equals("1")) {
|
||||
String settingDate = configMap.get(ConfigMapKeyEnum.SETTING_DATE.getConfigKey());
|
||||
if (!StringUtils.isEmpty(settingDate)) {
|
||||
String[] settingDateArray = settingDate.split("-");
|
||||
int settingDateYear = Integer.parseInt(settingDateArray[0]);
|
||||
int settingDateMonth = Integer.parseInt(settingDateArray[1]);
|
||||
int settingDateDay = Integer.parseInt(settingDateArray[2]);
|
||||
// 系统配置的当前日期
|
||||
currentWorkDate = LocalDate.of(settingDateYear, settingDateMonth, settingDateDay);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("获取配置工作日期错误,使用当前系统日期。");
|
||||
}
|
||||
|
||||
if (!localWorkDateList.contains(currentWorkDate)) {
|
||||
return;
|
||||
}
|
||||
// 先查看当前站台已经生成的工作流是否为空
|
||||
List<WorkFlow> currentWorkFlowList = workFlowService.list(new LambdaQueryWrapper<WorkFlow>()
|
||||
.eq(WorkFlow::getWorkStation, workStation));
|
||||
// 当前站台的工作流中还存在其他任务
|
||||
if (currentWorkFlowList != null && !currentWorkFlowList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
// 当前站台分配的工位
|
||||
List<WorkFlow> currentStationWorkFlows = new ArrayList<>();
|
||||
// 先找MWL机型
|
||||
String workPriority = configMap.get(ConfigMapKeyEnum.WORK_PRIORITY.getConfigKey());
|
||||
// 查找到当前站台所有可用的电子标签
|
||||
List<ETagLocation> eTagLocationList = eTagLocationService.list(new LambdaQueryWrapper<ETagLocation>()
|
||||
.eq(ETagLocation::getWorkStation, workStation)
|
||||
.eq(ETagLocation::getELocationStatus, 0)
|
||||
.orderByAsc(ETagLocation::getSequenceId));
|
||||
if (!StringUtils.isEmpty(workPriority) && workPriority.equals("1")) {
|
||||
// 找非MWL机型--先平地机
|
||||
findWorks(workStation, currentStationWorkFlows, "MG", currentWorkDate);
|
||||
if (currentStationWorkFlows.isEmpty()) {
|
||||
findWorks(workStation, currentStationWorkFlows, "MWL", currentWorkDate);
|
||||
}
|
||||
} else {
|
||||
// 先装载机
|
||||
findWorks(workStation, currentStationWorkFlows, "MWL", currentWorkDate);
|
||||
if (currentStationWorkFlows.isEmpty()) {
|
||||
// 找非MWL机型
|
||||
findWorks(workStation, currentStationWorkFlows, "MG", currentWorkDate);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果当前站台有任务
|
||||
if (!currentStationWorkFlows.isEmpty()) {
|
||||
// 将工作流列表添加进数据库
|
||||
workFlowService.saveBatch(currentStationWorkFlows);
|
||||
// 获得工单列表
|
||||
List<String> workOrderList = new ArrayList<>();
|
||||
// 获得工单以及小工位列表
|
||||
List<String> boxNoList = new ArrayList<>();
|
||||
// 要料Map
|
||||
Map<String, BigDecimal> needGoodsMap = new HashMap<>();
|
||||
for (WorkFlow tempWorkflow : currentStationWorkFlows) {
|
||||
// 添加工单
|
||||
if (!workOrderList.contains(tempWorkflow.getWorkOrder())) {
|
||||
workOrderList.add(tempWorkflow.getWorkOrder());
|
||||
}
|
||||
// 添加盒子配置
|
||||
String boxNo = tempWorkflow.getWorkOrder() + "@" + tempWorkflow.getWorkCenter();
|
||||
if (!boxNoList.contains(boxNo)) {
|
||||
boxNoList.add(boxNo);
|
||||
}
|
||||
// 添加要料信息
|
||||
if (!needGoodsMap.containsKey(tempWorkflow.getGoodsId())) {
|
||||
// 添加物料信息
|
||||
needGoodsMap.put(tempWorkflow.getGoodsId(), tempWorkflow.getNeedNum());
|
||||
} else {
|
||||
// 增加需求数量
|
||||
needGoodsMap.replace(tempWorkflow.getGoodsId(), needGoodsMap.get(tempWorkflow.getGoodsId()).add(tempWorkflow.getNeedNum()));
|
||||
}
|
||||
}
|
||||
if (eTagLocationList.isEmpty() || eTagLocationList.size() < boxNoList.size()) {
|
||||
throw new Exception("站台:" + workStation + "没有足够可用的电子标签位!");
|
||||
}
|
||||
// 站台要料
|
||||
List<GoodsToStation> goodsToStationList = new ArrayList<>();
|
||||
for (String goodsId : needGoodsMap.keySet()) {
|
||||
GoodsToStation goodsToStation = new GoodsToStation();
|
||||
goodsToStation.setGoodsId(goodsId);
|
||||
goodsToStation.setWorkStation(workStation);
|
||||
goodsToStation.setDistributeStatus(0);
|
||||
goodsToStation.setDistributedNum(BigDecimal.ZERO);
|
||||
goodsToStation.setTotalNum(needGoodsMap.get(goodsId));
|
||||
goodsToStationList.add(goodsToStation);
|
||||
}
|
||||
// 将站台要料列表存进数据库
|
||||
goodsToStationService.saveBatch(goodsToStationList);
|
||||
// 更新工单表
|
||||
List<String> orderIds = currentStationWorkFlows.stream().map(WorkFlow::getOrderId).distinct().toList();
|
||||
if (!orderIds.isEmpty()) {
|
||||
kateOrdersService.update(new LambdaUpdateWrapper<KateOrders>()
|
||||
.set(KateOrders::getOrderStatus, 1)
|
||||
.in(KateOrders::getOrderId, orderIds)
|
||||
.eq(KateOrders::getOrderStatus, 0));
|
||||
}
|
||||
// 更新dbs表
|
||||
if (!workOrderList.isEmpty()) {
|
||||
kateDBSService.update(new LambdaUpdateWrapper<KateDBS>()
|
||||
.set(KateDBS::getDbsStatus, 1)
|
||||
.in(KateDBS::getWorkOrder, workOrderList)
|
||||
.eq(KateDBS::getDbsStatus, 0));
|
||||
}
|
||||
// 电子标签库位配置
|
||||
List<ELocationConfig> eLocationConfigList = new ArrayList<>();
|
||||
for (ETagLocation eTagLocation : eTagLocationList) {
|
||||
if (boxNoList.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
String tempBoxNo = boxNoList.get(0);
|
||||
ELocationConfig eLocationConfig = new ELocationConfig();
|
||||
eLocationConfig.setWorkOrder(tempBoxNo.split("@")[0]);
|
||||
eLocationConfig.setWorkCenter(tempBoxNo.split("@")[1]);
|
||||
eLocationConfig.setWorkStation(workStation);
|
||||
eLocationConfig.setELocationId(eTagLocation.getELocationId());
|
||||
eLocationConfig.setOrderBoxNo(tempBoxNo);
|
||||
// 添加配置
|
||||
eLocationConfigList.add(eLocationConfig);
|
||||
// 移除已经分配的盒子
|
||||
boxNoList.remove(tempBoxNo);
|
||||
}
|
||||
// 将电子标签库位配置存进数据库
|
||||
eLocationConfigService.saveBatch(eLocationConfigList);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("创建站台:{}工作发生异常:{}", workStation, convertJsonString(e));
|
||||
// 回滚事务
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
} finally {
|
||||
// 当前站台创建任务完成
|
||||
workCreatingStations.remove(workStation);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 找到下一个工作日
|
||||
*
|
||||
|
|
@ -257,13 +88,6 @@ public class WorkServiceImplements implements IWorkService {
|
|||
@Override
|
||||
@Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
|
||||
public void doWork(String workStation) {
|
||||
if (workDoingStations.contains(workStation)) {
|
||||
// 当前站台正在创建任务
|
||||
return;
|
||||
} else {
|
||||
// 添加站台
|
||||
workDoingStations.add(workStation);
|
||||
}
|
||||
try {
|
||||
// 查找当前站台未开始的工作流
|
||||
List<WorkFlow> currentWorkFlowList = workFlowService.list(new LambdaQueryWrapper<WorkFlow>()
|
||||
|
|
@ -435,9 +259,6 @@ public class WorkServiceImplements implements IWorkService {
|
|||
logger.error("执行站台:{}工作发生异常:{}", workStation, convertJsonString(e));
|
||||
// 回滚事务
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
} finally {
|
||||
// 当前站台创建任务完成
|
||||
workDoingStations.remove(workStation);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -449,14 +270,6 @@ public class WorkServiceImplements implements IWorkService {
|
|||
*/
|
||||
@Override
|
||||
public String finishWork(String workStation) {
|
||||
if (workFinishingStations.contains(workStation)) {
|
||||
// 当前站台正在完成工作
|
||||
return "当前站台正在完成工作,请勿重复操作";
|
||||
|
||||
} else {
|
||||
// 添加站台
|
||||
workFinishingStations.add(workStation);
|
||||
}
|
||||
String result = "";
|
||||
try {
|
||||
if (workFlowService.exists(new LambdaQueryWrapper<WorkFlow>()
|
||||
|
|
@ -549,9 +362,6 @@ public class WorkServiceImplements implements IWorkService {
|
|||
} catch (Exception e) {
|
||||
logger.error("完成站台:{}工作发生异常:{}", workStation, convertJsonString(e));
|
||||
result = "完成站台:" + workStation + "工作发生异常!";
|
||||
} finally {
|
||||
// 当前站台工作完成
|
||||
workFinishingStations.remove(workStation);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
@ -684,13 +494,12 @@ public class WorkServiceImplements implements IWorkService {
|
|||
if (!StringUtils.isEmpty(useSettingDate) && useSettingDate.equals("1")) {
|
||||
String settingDate = configMap.get(ConfigMapKeyEnum.SETTING_DATE.getConfigKey());
|
||||
if (!StringUtils.isEmpty(settingDate)) {
|
||||
// String[] settingDateArray = settingDate.split("-");
|
||||
// int settingDateYear = Integer.parseInt(settingDateArray[0]);
|
||||
// int settingDateMonth = Integer.parseInt(settingDateArray[1]);
|
||||
// int settingDateDay = Integer.parseInt(settingDateArray[2]);
|
||||
// // 系统配置的当前日期
|
||||
// currentWorkDate = LocalDate.of(settingDateYear, settingDateMonth, settingDateDay);
|
||||
currentWorkDate = LocalDate.parse(settingDate);
|
||||
String[] settingDateArray = settingDate.split("-");
|
||||
int settingDateYear = Integer.parseInt(settingDateArray[0]);
|
||||
int settingDateMonth = Integer.parseInt(settingDateArray[1]);
|
||||
int settingDateDay = Integer.parseInt(settingDateArray[2]);
|
||||
// 系统配置的当前日期
|
||||
currentWorkDate = LocalDate.of(settingDateYear, settingDateMonth, settingDateDay);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
@ -794,13 +603,6 @@ public class WorkServiceImplements implements IWorkService {
|
|||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void distributeWorks(String workStation) {
|
||||
if (workCreatingStations.contains(workStation)) {
|
||||
// 当前站台正在创建任务
|
||||
return;
|
||||
} else {
|
||||
// 添加站台
|
||||
workCreatingStations.add(workStation);
|
||||
}
|
||||
if (StringUtils.isEmpty(workStation)) {
|
||||
// 站台号为空
|
||||
logger.error("站台号为空===》》》》》》");
|
||||
|
|
@ -933,13 +735,14 @@ public class WorkServiceImplements implements IWorkService {
|
|||
// 针对此站台的料盒号(工单@工作中心)生成一个map
|
||||
Map<String, String> eLocationIdOfBoxMap = new HashMap<>();
|
||||
for (ELocationConfig oldELocationConfig : allELocationConfigs) {
|
||||
if (!stationOfBigBoxMap.containsKey(oldELocationConfig.getWorkCenter())) {
|
||||
// 默认大盒子 = 小盒子
|
||||
String bigBox = oldELocationConfig.getWorkCenter();
|
||||
if (smallBoxToBigBoxConfigMap.containsKey(oldELocationConfig.getWorkCenter())) {
|
||||
// 设置为实际的大盒子
|
||||
bigBox = smallBoxToBigBoxConfigMap.get(oldELocationConfig.getWorkCenter());
|
||||
}
|
||||
// 默认大盒子 = 小盒子
|
||||
String bigBox = oldELocationConfig.getWorkCenter();
|
||||
if (smallBoxToBigBoxConfigMap.containsKey(oldELocationConfig.getWorkCenter())) {
|
||||
// 设置为实际的大盒子
|
||||
bigBox = smallBoxToBigBoxConfigMap.get(oldELocationConfig.getWorkCenter());
|
||||
}
|
||||
// 判断这个大盒子是否分配了站台
|
||||
if (!stationOfBigBoxMap.containsKey(bigBox)) {
|
||||
stationOfBigBoxMap.put(bigBox, oldELocationConfig.getWorkStation());
|
||||
}
|
||||
// 更新料盒号-电子标签库位Map
|
||||
|
|
@ -949,6 +752,11 @@ public class WorkServiceImplements implements IWorkService {
|
|||
}
|
||||
// 开始分配电子标签库位
|
||||
List<WorkFlow> thisTimeDistributeWorkFlows = new ArrayList<>();
|
||||
// 查询出需要分配的工单的dbs
|
||||
List<KateDBS> kateDBSS = kateDBSService.list(new LambdaQueryWrapper<KateDBS>()
|
||||
.in(KateDBS::getWorkOrder, needDistributeWorks.stream().map(WorkFlow::getWorkOrder).distinct().toList()));
|
||||
// 将这个工单的顺序号进行一个map
|
||||
Map<String, Integer> workOrderToSequenceMap = kateDBSS.stream().collect(Collectors.toMap(KateDBS::getWorkOrder, KateDBS::getWorkSequence));
|
||||
for (String bigBox : bigBoxes) {
|
||||
if (remainELocationIds.isEmpty()) {
|
||||
// 当前站台没有剩余电子标签位置可以分配了
|
||||
|
|
@ -960,6 +768,14 @@ public class WorkServiceImplements implements IWorkService {
|
|||
}
|
||||
// 获取到这个大盒子下面的所有工作流
|
||||
List<WorkFlow> thisBigBoxWorks = workFlowsByBigBoxMap.get(bigBox);
|
||||
if (thisBigBoxWorks.isEmpty()) {
|
||||
// 当前大盒子没有工作流,跳过
|
||||
continue;
|
||||
}
|
||||
// List<WorkFlow> thisBigBoxSortedWorks = thisBigBoxWorks.stream()
|
||||
// .sorted(Comparator.comparing(WorkFlow::getWorkCenter))
|
||||
// .sorted(Comparator.comparingInt(workFlow -> workOrderToSequenceMap.get(workFlow.getWorkOrder())))
|
||||
// .toList();
|
||||
// 未分配的工作流,按照boxNo分组
|
||||
Map<String, List<WorkFlow>> notDistributeYetWorksByBoxMap = new HashMap<>();
|
||||
for (WorkFlow workFlow : thisBigBoxWorks) {
|
||||
|
|
@ -983,7 +799,11 @@ public class WorkServiceImplements implements IWorkService {
|
|||
// 这个大盒子的位置不够了,整个大盒子都不分配。
|
||||
continue;
|
||||
}
|
||||
for (String boxNo : notDistributeYetWorksByBoxMap.keySet()) {
|
||||
List<String> sortedKeyString = notDistributeYetWorksByBoxMap.keySet().stream()
|
||||
.sorted(Comparator.comparing(o -> workOrderToSequenceMap.get(o.split("@")[0])))
|
||||
.sorted(Comparator.comparing(o -> o.split("@")[1]))
|
||||
.toList();
|
||||
for (String boxNo : sortedKeyString) {
|
||||
if (eLocationIdOfBoxMap.containsKey(boxNo)) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -1004,6 +824,9 @@ public class WorkServiceImplements implements IWorkService {
|
|||
remainELocationIds.remove(eLocationId);
|
||||
}
|
||||
}
|
||||
if (thisTimeDistributeWorkFlows.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
// 处理分配
|
||||
List<GoodsToStation> oldGoodsStations = goodsToStationService.list(
|
||||
new LambdaQueryWrapper<GoodsToStation>().eq(GoodsToStation::getWorkStation, workStation)
|
||||
|
|
@ -1054,14 +877,11 @@ public class WorkServiceImplements implements IWorkService {
|
|||
.set(WorkFlow::getWorkStation, workStation)
|
||||
.in(WorkFlow::getWorkFlowId, flowIds));
|
||||
}
|
||||
System.out.println("分配站台" + workStation + "工作完成");
|
||||
logger.info("分配站台{}工作完成", workStation);
|
||||
} catch (Exception e) {
|
||||
logger.error("分配站台:{}工作发生异常:{}", workStation, convertJsonString(e));
|
||||
// 回滚事务
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
} finally {
|
||||
// 当前站台创建任务完成
|
||||
workCreatingStations.remove(workStation);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1096,317 +916,4 @@ public class WorkServiceImplements implements IWorkService {
|
|||
|
||||
return stream.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 新版开始工作
|
||||
*/
|
||||
@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>()
|
||||
.notIn(WorkFlow::getWorkStatus, -1, 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user