代码更新:

1. 增加导入工作日历的功能
2. 修改自动生成工作部分的代码逻辑
This commit is contained in:
梁州 2024-10-20 17:42:15 +08:00
parent 21238025c5
commit 1a780398fd
13 changed files with 675 additions and 375 deletions

View File

@ -1,9 +1,12 @@
package com.wms.config; package com.wms.config;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wms.entity.table.Config; import com.wms.entity.table.Config;
import com.wms.entity.table.Location; import com.wms.entity.table.Location;
import com.wms.entity.table.WorkDate;
import com.wms.service.ConfigService; import com.wms.service.ConfigService;
import com.wms.service.LocationService; import com.wms.service.LocationService;
import com.wms.service.WorkDateService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -13,6 +16,8 @@ import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -30,9 +35,15 @@ public class InitLocalConfig implements ApplicationRunner {
* 库位服务 * 库位服务
*/ */
private final LocationService locationService; private final LocationService locationService;
/**
* 工作日历服务
*/
private final WorkDateService workDateService;
protected final Logger logger = LoggerFactory.getLogger(this.getClass()); protected final Logger logger = LoggerFactory.getLogger(this.getClass());
public static Map<String, String> configMap = new HashMap<String, String>(); public static Map<String, String> configMap = new HashMap<>();
public static Map<String, Location> instantLocationMap = new HashMap<>(); public static Map<String, Location> instantLocationMap = new HashMap<>();
public static List<LocalDate> localWorkDateList = new ArrayList<>();
@Override @Override
public void run(ApplicationArguments args) { public void run(ApplicationArguments args) {
List<Config> configs = configService.selectConfigs(""); List<Config> configs = configService.selectConfigs("");
@ -44,6 +55,9 @@ public class InitLocalConfig implements ApplicationRunner {
} }
// 生成库位Map // 生成库位Map
instantLocationMap = locationService.list().stream().collect(Collectors.toMap(Location::getLocationId, location -> location)); instantLocationMap = locationService.list().stream().collect(Collectors.toMap(Location::getLocationId, location -> location));
logger.info("生成库位Map成功"); logger.info("生成库位Map成功。");
// 生成工作日历
localWorkDateList = workDateService.list(new LambdaQueryWrapper<WorkDate>().orderByAsc(WorkDate::getWorkDate)).stream().map(WorkDate::getWorkDate).distinct().toList();
logger.info("生成工作日历Map成功。");
} }
} }

View File

@ -66,6 +66,7 @@ public class ExcelController {
private final WorkSummaryService workSummaryService;// 工作分析服务 private final WorkSummaryService workSummaryService;// 工作分析服务
private final KanbanService kanbanService;// 看板服务 private final KanbanService kanbanService;// 看板服务
private final WorkFlowService workFlowService;// 工作流服务 private final WorkFlowService workFlowService;// 工作流服务
private final WorkDateService workDateService;// 工作日历服务
private final List<String> uploadFileHashStringList = new ArrayList<>(); private final List<String> uploadFileHashStringList = new ArrayList<>();
@ -143,6 +144,47 @@ public class ExcelController {
} }
} }
/**
* 导入工作日
*
* @param file 文件
* @return 导入结果
*/
@PostMapping("/uploadWorkDate")
@ResponseBody
@Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
public String uploadWorkDate(@RequestPart("file") MultipartFile file, @RequestPart("obj") FileVo fileVo) {
logger.info("导入工作日历请求ip{},文件详情:{}", getIpAddr(servletRequest), convertJsonString(fileVo));
ResponseEntity response = new ResponseEntity();
try {
// 判断是否重复导入
if (uploadFileHashStringList.contains(fileVo.getHash())) {
response.setCode(ResponseCode.ERROR.getCode());
response.setMessage("请勿导入相同文件。");
return convertJsonString(response);
}
uploadFileHashStringList.add(fileVo.getHash());
// 移除之前的工作日历
workDateService.remove(new LambdaQueryWrapper<>());
// 导入新的工作日历
EasyExcel.read(file.getInputStream(), WorkDateExcelVo.class, new UploadWorkDateListener(workDateService)).sheet().doRead();
// 添加导入记录
uploadRecordService.save(UploadRecord.ofFileVo(fileVo, "WORK_DATE"));
uploadFileHashStringList.remove(fileVo.getHash());
response.setCode(ResponseCode.OK.getCode());
response.setMessage("导入工作日历成功。");
return convertJsonString(response);
} catch (Exception e) {
logger.error("导入工作日历异常:{}", convertJsonString(e));
// 回滚事务
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
uploadFileHashStringList.remove(fileVo.getHash());
response.setCode(ResponseCode.ERROR.getCode());
response.setMessage("导入工作日历异常。");
return convertJsonString(response);
}
}
/** /**
* 导入DBS * 导入DBS
* *

View File

@ -459,6 +459,10 @@ public class TaskController {
taskRecordService.save(BeanUtil.copyProperties(inTask, TaskRecord.class)); taskRecordService.save(BeanUtil.copyProperties(inTask, TaskRecord.class));
// 删除移库任务 // 删除移库任务
taskService.remove(new LambdaQueryWrapper<Task>().eq(Task::getTaskId, inTask.getTaskId())); taskService.remove(new LambdaQueryWrapper<Task>().eq(Task::getTaskId, inTask.getTaskId()));
// 移除当前料箱所有的拣选任务
pickTaskService.remove(new LambdaQueryWrapper<PickTask>().eq(PickTask::getVehicleId, inTask.getVehicleId()));
// 移除当前料箱所有的outsideVehicles
outsideVehiclesService.remove(new LambdaQueryWrapper<OutsideVehicles>().eq(OutsideVehicles::getVehicleId, inTask.getVehicleId()));
} }
} }
// 出库任务 // 出库任务
@ -1419,42 +1423,6 @@ public class TaskController {
if (currentGoodsVehicle != null) { if (currentGoodsVehicle != null) {
currentGoodsVehicle.setRemainNum(BigDecimal.ZERO); currentGoodsVehicle.setRemainNum(BigDecimal.ZERO);
outsideVehiclesService.updateById(currentGoodsVehicle); outsideVehiclesService.updateById(currentGoodsVehicle);
// // 已经分配的数量
// BigDecimal distributedNum = workConfirmRequest.getRemainNumOrigin().subtract(workConfirmRequest.getRemainNumReal());
// // 将当前物料的所有goodsToStation
// List<GoodsToStation> goodsToStations = goodsToStationService.list(new LambdaQueryWrapper<GoodsToStation>()
// .eq(GoodsToStation::getGoodsId, currentGoodsVehicle.getGoodsId()));
// List<GoodsToStation> updatedGoodsToStationList = new ArrayList<>();
// for (GoodsToStation goodsToStation : goodsToStations) {
// if (distributedNum.compareTo(BigDecimal.ZERO) > 0) {
// // 查询这个料对应的当前站台未完成工作流
// List<WorkFlow> workFlows = workFlowService.list(new LambdaQueryWrapper<WorkFlow>()
// .eq(WorkFlow::getWorkStation, goodsToStation.getWorkStation())
// .eq(WorkFlow::getGoodsId, goodsToStation.getGoodsId())
// .eq(WorkFlow::getWorkStatus, 1));
// BigDecimal recallNum = BigDecimal.ZERO;
// for (WorkFlow workFlow : workFlows) {
// // 分配数量无了
// if (distributedNum.compareTo(BigDecimal.ZERO) <= 0) {
// break;
// }
// BigDecimal needNum = workFlow.getNeedNum().subtract(workFlow.getPickedNum());
// if (needNum.compareTo(BigDecimal.ZERO) > 0) {
// recallNum = recallNum.add(needNum);
// distributedNum = distributedNum.subtract(needNum);
// }
// }
// if (recallNum.compareTo(BigDecimal.ZERO) >0) {
// goodsToStation.setDistributedNum(goodsToStation.getDistributedNum().subtract(recallNum));
// goodsToStation.setDistributeStatus(1);
// updatedGoodsToStationList.add(goodsToStation);
// }
// }
// }
// // 更新站台要料表
// if (!updatedGoodsToStationList.isEmpty()) {
// goodsToStationService.updateBatchById(updatedGoodsToStationList);
// }
} }
} else { } else {
// 更新流转载具表剩余数量 // 更新流转载具表剩余数量
@ -2170,12 +2138,6 @@ public class TaskController {
} }
} }
} }
boolean hasPickTasksAgain = pickTaskService.exists(new LambdaQueryWrapper<PickTask>()
.eq(PickTask::getVehicleId, requestBackQuery.getVehicleId()));
if (hasPickTasksAgain) {
// 防止生成回库任务时正好又生成拣选任务
throw new Exception("生成新的拣选任务,不可回库。");
}
response.setCode(ResponseCode.OK.getCode()); response.setCode(ResponseCode.OK.getCode());
response.setMessage("可以回库。"); response.setMessage("可以回库。");
} else { } else {

View File

@ -25,4 +25,9 @@ public class WorkCenterAndOrderDto {
*/ */
@JsonProperty("startDate") @JsonProperty("startDate")
private LocalDateTime startDate; private LocalDateTime startDate;
/**
* DBS顺序
*/
@JsonProperty("dbsSequence")
private Integer dbsSequence;
} }

View File

@ -0,0 +1,31 @@
package com.wms.entity.table;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.time.LocalDate;
/**
* 工作日
*/
@Data
@TableName(value = "tbl_app_work_date", autoResultMap = true)
public class WorkDate {
/**
* id
*/
@TableId("id")
private Integer keyId;
/**
* 工作日
*/
@TableField("work_date")
private LocalDate workDate;
/**
* 备注
*/
@TableField("remark")
private String remark;
}

View File

@ -0,0 +1,9 @@
package com.wms.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wms.entity.table.WorkDate;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface WorkDateMapper extends BaseMapper<WorkDate> {
}

View File

@ -0,0 +1,10 @@
package com.wms.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.wms.entity.table.WorkDate;
/**
* 卡特DBS服务接口
*/
public interface WorkDateService extends IService<WorkDate> {
}

View File

@ -507,6 +507,9 @@ public class WmsTaskServiceImplements implements IWmsTaskService {
Map<String, PickTask> currentStandPickTasksMap = allPickTasks.stream().filter(pickTask -> pickTask.getStandId().equals(workStation)).collect(Collectors.toMap(pickTask -> pickTask.getVehicleId() + "_" + pickTask.getStandId(), pickTask -> pickTask)); Map<String, PickTask> currentStandPickTasksMap = allPickTasks.stream().filter(pickTask -> pickTask.getStandId().equals(workStation)).collect(Collectors.toMap(pickTask -> pickTask.getVehicleId() + "_" + pickTask.getStandId(), pickTask -> pickTask));
// 拣选任务暂存列表 // 拣选任务暂存列表
Map<String, PickTask> pickTaskMap = new HashMap<>(); Map<String, PickTask> pickTaskMap = new HashMap<>();
// 查询出这些箱子
List<OutsideVehicles> outsideVehicles = outsideVehiclesService.list(new LambdaQueryWrapper<OutsideVehicles>()
.in(OutsideVehicles::getVehicleId, vehicleIds));
// 增加的拣选任务数量 // 增加的拣选任务数量
int addNum = 0; int addNum = 0;
for (String vehicleId : vehicleIds) { for (String vehicleId : vehicleIds) {
@ -533,6 +536,13 @@ public class WmsTaskServiceImplements implements IWmsTaskService {
pickTaskMap.put(key, tempPickTask); pickTaskMap.put(key, tempPickTask);
if (!Objects.equals(tempPickTask.getPickStatus(), PickTaskStatusEnum.TEMP.getCode())) { if (!Objects.equals(tempPickTask.getPickStatus(), PickTaskStatusEnum.TEMP.getCode())) {
addNum++; addNum++;
} else {
List<OutsideVehicles> currentOutsideVehicles = outsideVehicles.stream().filter(outsideVehicle ->
outsideVehicle.getVehicleId().equals(vehicleId) && outsideVehicle.getOutStatus().equals(1)).toList();
if (!currentOutsideVehicles.isEmpty()) {
// 已经下发出库任务计数+1
addNum++;
}
} }
} }
// 添加数据库 // 添加数据库

View File

@ -21,11 +21,12 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport; import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.wms.config.InitLocalConfig.configMap; 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;
@ -52,131 +53,6 @@ public class WorkServiceImplements implements IWorkService {
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<>();// 当前正在完成任务的站台
// @Override
// @Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
// public void createWork(String workStation) throws Exception {
// if (workCreatingStations.contains(workStation)) {
// // 当前站台正在创建任务
// return;
// } else {
// // 添加站台
// workCreatingStations.add(workStation);
// }
// if (StringUtils.isEmpty(workStation)) {
// // 站台号为空
// return;
// }
// try {
// // 先查看当前站台已经生成的工作流是否为空
// List<WorkFlow> currentWorkFlowList = workFlowService.list(new LambdaQueryWrapper<WorkFlow>()
// .eq(WorkFlow::getWorkStation, workStation));
// // 当前站台的工作流中还存在其他任务
// if (currentWorkFlowList != null && !currentWorkFlowList.isEmpty()) {
// return;
// }
// // 当前站台分配的工位
// List<WorkFlow> currentStationWorkFlows = new ArrayList<>();
// // 先找MWL机型
// findWorks(workStation, currentStationWorkFlows, "MWL");
// if (currentStationWorkFlows.isEmpty()) {
// // 找非MWL机型
// findWorks(workStation, currentStationWorkFlows, "NOT_MWL");
// }
// // 如果当前站台有任务
// 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()));
// }
// }
// // 站台要料
// 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<>();
// // 查找到当前站台所有可用的电子标签
// List<ETagLocation> eTagLocationList = eTagLocationService.list(new LambdaQueryWrapper<ETagLocation>()
// .eq(ETagLocation::getWorkStation, workStation)
// .eq(ETagLocation::getELocationStatus, 0)
// .orderByAsc(ETagLocation::getSequenceId));
// if (eTagLocationList.isEmpty() || eTagLocationList.size() < boxNoList.size()) {
// throw new Exception("站台:" + workStation + "没有足够可用的电子标签位!");
// }
// for (ETagLocation eTagLocation : eTagLocationList) {
// if (!boxNoList.isEmpty()) {
// 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);
// }
// }
@Override @Override
@Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED) @Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
public void createWork(String workStation) throws Exception { public void createWork(String workStation) throws Exception {
@ -192,31 +68,40 @@ public class WorkServiceImplements implements IWorkService {
return; return;
} }
try { try {
// 先判断当日是否是工作日
if (!localWorkDateList.contains(LocalDate.now())) {
return;
}
// 先查看当前站台已经生成的工作流是否为空 // 先查看当前站台已经生成的工作流是否为空
List<WorkFlow> currentWorkFlowList = workFlowService.list(new LambdaQueryWrapper<WorkFlow>() List<WorkFlow> currentWorkFlowList = workFlowService.list(new LambdaQueryWrapper<WorkFlow>()
.eq(WorkFlow::getWorkStation, workStation) .eq(WorkFlow::getWorkStation, workStation));
.ne(WorkFlow::getWorkStatus, 0));
// 当前站台的工作流中还存在其他任务 // 当前站台的工作流中还存在其他任务
if (currentWorkFlowList != null && !currentWorkFlowList.isEmpty()) { if (currentWorkFlowList != null && !currentWorkFlowList.isEmpty()) {
return; return;
} }
// 查询是否有已经分配好的电子标签库位信息 // 当前站台分配的工位
List<ELocationConfig> oldELocationConfigList = eLocationConfigService.list(new LambdaQueryWrapper<ELocationConfig>() List<WorkFlow> currentStationWorkFlows = new ArrayList<>();
.eq(ELocationConfig::getWorkStation, workStation)); // 先找MWL机型
if (oldELocationConfigList != null && !oldELocationConfigList.isEmpty()) { findWorks(workStation, currentStationWorkFlows, "MWL");
return; if (currentStationWorkFlows.isEmpty()) {
// 找非MWL机型
findWorks(workStation, currentStationWorkFlows, "NOT_MWL");
} }
// 查询所有待下发的
List<WorkFlow> currentStationWorkFlows = workFlowService.list(new LambdaQueryWrapper<WorkFlow>()
.eq(WorkFlow::getWorkStatus, 0)
.eq(WorkFlow::getWorkStation, workStation));
// 如果当前站台有任务 // 如果当前站台有任务
if (!currentStationWorkFlows.isEmpty()) { if (!currentStationWorkFlows.isEmpty()) {
// 将工作流列表添加进数据库
workFlowService.saveBatch(currentStationWorkFlows);
// 获得工单列表
List<String> workOrderList = new ArrayList<>();
// 获得工单以及小工位列表 // 获得工单以及小工位列表
List<String> boxNoList = new ArrayList<>(); List<String> boxNoList = new ArrayList<>();
// 要料Map // 要料Map
Map<String, BigDecimal> needGoodsMap = new HashMap<>(); Map<String, BigDecimal> needGoodsMap = new HashMap<>();
for (WorkFlow tempWorkflow : currentStationWorkFlows) { for (WorkFlow tempWorkflow : currentStationWorkFlows) {
// 添加工单
if (!workOrderList.contains(tempWorkflow.getWorkOrder())) {
workOrderList.add(tempWorkflow.getWorkOrder());
}
// 添加盒子配置 // 添加盒子配置
String boxNo = tempWorkflow.getWorkOrder() + "@" + tempWorkflow.getWorkCenter(); String boxNo = tempWorkflow.getWorkOrder() + "@" + tempWorkflow.getWorkCenter();
if (!boxNoList.contains(boxNo)) { if (!boxNoList.contains(boxNo)) {
@ -235,7 +120,6 @@ public class WorkServiceImplements implements IWorkService {
List<GoodsToStation> goodsToStationList = new ArrayList<>(); List<GoodsToStation> goodsToStationList = new ArrayList<>();
for (String goodsId : needGoodsMap.keySet()) { for (String goodsId : needGoodsMap.keySet()) {
GoodsToStation goodsToStation = new GoodsToStation(); GoodsToStation goodsToStation = new GoodsToStation();
goodsToStation.setConfigId(goodsId + "_" + workStation);
goodsToStation.setGoodsId(goodsId); goodsToStation.setGoodsId(goodsId);
goodsToStation.setWorkStation(workStation); goodsToStation.setWorkStation(workStation);
goodsToStation.setDistributeStatus(0); goodsToStation.setDistributeStatus(0);
@ -244,7 +128,22 @@ public class WorkServiceImplements implements IWorkService {
goodsToStationList.add(goodsToStation); goodsToStationList.add(goodsToStation);
} }
// 将站台要料列表存进数据库 // 将站台要料列表存进数据库
goodsToStationService.saveOrUpdateBatch(goodsToStationList); 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<>(); List<ELocationConfig> eLocationConfigList = new ArrayList<>();
// 查找到当前站台所有可用的电子标签 // 查找到当前站台所有可用的电子标签
@ -272,12 +171,6 @@ public class WorkServiceImplements implements IWorkService {
} }
// 将电子标签库位配置存进数据库 // 将电子标签库位配置存进数据库
eLocationConfigService.saveBatch(eLocationConfigList); eLocationConfigService.saveBatch(eLocationConfigList);
// 更新工作流状态
List<String> workFlowIds = currentStationWorkFlows.stream().map(WorkFlow::getWorkFlowId).distinct().toList();
workFlowService.update(new LambdaUpdateWrapper<WorkFlow>()
.set(WorkFlow::getWorkStatus, 1)
.in(WorkFlow::getWorkFlowId, workFlowIds)
.eq(WorkFlow::getWorkStatus, 0));
} }
} catch (Exception e) { } catch (Exception e) {
logger.error("创建站台:{}工作发生异常:{}", workStation, convertJsonString(e)); logger.error("创建站台:{}工作发生异常:{}", workStation, convertJsonString(e));
@ -291,103 +184,113 @@ public class WorkServiceImplements implements IWorkService {
// @Override // @Override
// @Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED) // @Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
// public void doWork(String workStation) throws Exception { // public void createWork(String workStation) throws Exception {
// if (workDoingStations.contains(workStation)) { // if (workCreatingStations.contains(workStation)) {
// // 当前站台正在创建任务 // // 当前站台正在创建任务
// return; // return;
// } else { // } else {
// // 添加站台 // // 添加站台
// workDoingStations.add(workStation); // workCreatingStations.add(workStation);
// }
// if (StringUtils.isEmpty(workStation)) {
// // 站台号为空
// return;
// } // }
// try { // try {
// // 查找当前站台未开始的工作流 // // 先查看当前站台已经生成的工作流是否为空
// List<WorkFlow> currentWorkFlowList = workFlowService.list(new LambdaQueryWrapper<WorkFlow>() // List<WorkFlow> currentWorkFlowList = workFlowService.list(new LambdaQueryWrapper<WorkFlow>()
// .eq(WorkFlow::getWorkStation, workStation) // .eq(WorkFlow::getWorkStation, workStation)
// .ne(WorkFlow::getWorkStatus, 2)); // .ne(WorkFlow::getWorkStatus, 0));
// // 没有可做的任务 // // 当前站台的工作流中还存在其他任务
// if (currentWorkFlowList == null || currentWorkFlowList.isEmpty()) { // if (currentWorkFlowList != null && !currentWorkFlowList.isEmpty()) {
// return; // return;
// } // }
// // 查站台要料表---未分配以及分配但未完全分配 // // 查询是否有已经分配好的电子标签库位信息
// List<GoodsToStation> goodsToStationList = goodsToStationService.list(new LambdaQueryWrapper<GoodsToStation>() // List<ELocationConfig> oldELocationConfigList = eLocationConfigService.list(new LambdaQueryWrapper<ELocationConfig>()
// .eq(GoodsToStation::getWorkStation, workStation) // .eq(ELocationConfig::getWorkStation, workStation));
// .lt(GoodsToStation::getDistributeStatus, 2)); // if (oldELocationConfigList != null && !oldELocationConfigList.isEmpty()) {
// if (goodsToStationList == null || goodsToStationList.isEmpty()) { // return;
// // 查询是否还有这个站台的拣选任务 // }
// if (!pickTaskService.exists(new LambdaQueryWrapper<PickTask>() // // 查询所有待下发的
// .eq(PickTask::getStandId, workStation))) { // List<WorkFlow> currentStationWorkFlows = workFlowService.list(new LambdaQueryWrapper<WorkFlow>()
// // 已经不存在未分配的任务且没有拣选任务可视为完成 // .eq(WorkFlow::getWorkStatus, 0)
// // 更新工作流状态-->完成 // .eq(WorkFlow::getWorkStation, workStation));
// List<String> workFlowIds = currentWorkFlowList.stream().map(WorkFlow::getWorkFlowId).distinct().toList(); // // 如果当前站台有任务
// if (!workFlowIds.isEmpty()) { // if (!currentStationWorkFlows.isEmpty()) {
// workFlowService.update(new LambdaUpdateWrapper<WorkFlow>() // // 获得工单以及小工位列表
// .set(WorkFlow::getWorkStatus, 2) // List<String> boxNoList = new ArrayList<>();
// .set(WorkFlow::getFinishTime, LocalDateTime.now()) // // 要料Map
// .set(WorkFlow::getOpUser, "系统自动完成") // Map<String, BigDecimal> needGoodsMap = new HashMap<>();
// .in(WorkFlow::getWorkFlowId, workFlowIds) // for (WorkFlow tempWorkflow : currentStationWorkFlows) {
// .ne(WorkFlow::getWorkStatus, 2)); // // 添加盒子配置
// String boxNo = tempWorkflow.getWorkOrder() + "@" + tempWorkflow.getWorkCenter();
// if (!boxNoList.contains(boxNo)) {
// boxNoList.add(boxNo);
// } // }
// } // // 添加要料信息
// return; // if (!needGoodsMap.containsKey(tempWorkflow.getGoodsId())) {
// } // // 添加物料信息
// for (GoodsToStation goodsToStation : goodsToStationList) { // needGoodsMap.put(tempWorkflow.getGoodsId(), tempWorkflow.getNeedNum());
// // 当前物料当前站台需求数量
// BigDecimal needNum = goodsToStation.getTotalNum().subtract(goodsToStation.getDistributedNum());
// if (needNum.compareTo(BigDecimal.ZERO) == 0) {
// // 需求数量为0
// continue;
// }
// // 判断实际库存是否充足
// List<Stock> stockList = stockService.list(new LambdaQueryWrapper<Stock>()
// .apply("goods_related ->> '$.goodsId' = {0}" + MYSQL_JSON_CI, goodsToStation.getGoodsId())
// .apply("goods_related ->> '$.remainNum' > 0"));
// if (stockList == null || stockList.isEmpty()) {
// goodsToStation.setDistributeStatus(3);
// continue;
// }
// // 判断当前物料是否在流转中
// needNum = wmsTaskService.callGoods(goodsToStation.getGoodsId(), needNum, workStation);
// // 判断此时需求数量是否为0
// if (needNum.compareTo(BigDecimal.ZERO) <= 0) {
// // 分配完成
// goodsToStation.setDistributeStatus(2);
// } else {
// needNum = wmsTaskService.callStocks(goodsToStation.getGoodsId(), needNum, workStation);
// if (needNum.compareTo(BigDecimal.ZERO) > 0) {
// // 已分配但未完全分配
// goodsToStation.setDistributeStatus(1);
// } else { // } else {
// // 分配完成 // // 增加需求数量
// goodsToStation.setDistributeStatus(2); // needGoodsMap.replace(tempWorkflow.getGoodsId(), needGoodsMap.get(tempWorkflow.getGoodsId()).add(tempWorkflow.getNeedNum()));
// } // }
// } // }
// // 更新已分配数量 // // 站台要料
// goodsToStation.setDistributedNum(goodsToStation.getTotalNum().subtract(needNum)); // List<GoodsToStation> goodsToStationList = new ArrayList<>();
// for (String goodsId : needGoodsMap.keySet()) {
// GoodsToStation goodsToStation = new GoodsToStation();
// goodsToStation.setConfigId(goodsId + "_" + workStation);
// goodsToStation.setGoodsId(goodsId);
// goodsToStation.setWorkStation(workStation);
// goodsToStation.setDistributeStatus(0);
// goodsToStation.setDistributedNum(BigDecimal.ZERO);
// goodsToStation.setTotalNum(needGoodsMap.get(goodsId));
// goodsToStationList.add(goodsToStation);
// }
// // 将站台要料列表存进数据库
// goodsToStationService.saveOrUpdateBatch(goodsToStationList);
// // 电子标签库位配置
// List<ELocationConfig> eLocationConfigList = new ArrayList<>();
// // 查找到当前站台所有可用的电子标签
// List<ETagLocation> eTagLocationList = eTagLocationService.list(new LambdaQueryWrapper<ETagLocation>()
// .eq(ETagLocation::getWorkStation, workStation)
// .eq(ETagLocation::getELocationStatus, 0)
// .orderByAsc(ETagLocation::getSequenceId));
// if (eTagLocationList.isEmpty() || eTagLocationList.size() < boxNoList.size()) {
// throw new Exception("站台:" + workStation + "没有足够可用的电子标签位!");
// }
// for (ETagLocation eTagLocation : eTagLocationList) {
// if (!boxNoList.isEmpty()) {
// 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);
// // 更新工作流状态
// List<String> workFlowIds = currentStationWorkFlows.stream().map(WorkFlow::getWorkFlowId).distinct().toList();
// workFlowService.update(new LambdaUpdateWrapper<WorkFlow>()
// .set(WorkFlow::getWorkStatus, 1)
// .in(WorkFlow::getWorkFlowId, workFlowIds)
// .eq(WorkFlow::getWorkStatus, 0));
// } // }
// goodsToStationService.updateBatchById(goodsToStationList);
// // 更新工作流状态
// 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) { // } catch (Exception e) {
// logger.error("执行站台:{}工作发生异常:{}", workStation, convertJsonString(e)); // logger.error("创建站台:{}工作发生异常:{}", workStation, convertJsonString(e));
// // 回滚事务 // // 回滚事务
// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); // TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
// } finally { // } finally {
// // 当前站台创建任务完成 // // 当前站台创建任务完成
// workDoingStations.remove(workStation); // workCreatingStations.remove(workStation);
// } // }
// } // }
@ -405,7 +308,7 @@ public class WorkServiceImplements implements IWorkService {
// 查找当前站台未开始的工作流 // 查找当前站台未开始的工作流
List<WorkFlow> currentWorkFlowList = workFlowService.list(new LambdaQueryWrapper<WorkFlow>() List<WorkFlow> currentWorkFlowList = workFlowService.list(new LambdaQueryWrapper<WorkFlow>()
.eq(WorkFlow::getWorkStation, workStation) .eq(WorkFlow::getWorkStation, workStation)
.eq(WorkFlow::getWorkStatus, 1)); .ne(WorkFlow::getWorkStatus, 2));
// 没有可做的任务 // 没有可做的任务
if (currentWorkFlowList == null || currentWorkFlowList.isEmpty()) { if (currentWorkFlowList == null || currentWorkFlowList.isEmpty()) {
return; return;
@ -512,6 +415,22 @@ public class WorkServiceImplements implements IWorkService {
goodsToStation.setDistributedNum(goodsToStation.getTotalNum().subtract(needNum)); goodsToStation.setDistributedNum(goodsToStation.getTotalNum().subtract(needNum));
} }
goodsToStationService.updateBatchById(notFinishedGoodsList); goodsToStationService.updateBatchById(notFinishedGoodsList);
// 更新工作流状态
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) { } catch (Exception e) {
logger.error("执行站台:{}工作发生异常:{}", workStation, convertJsonString(e)); logger.error("执行站台:{}工作发生异常:{}", workStation, convertJsonString(e));
// 回滚事务 // 回滚事务
@ -523,105 +442,134 @@ public class WorkServiceImplements implements IWorkService {
} }
// @Override // @Override
// public String finishWork(String workStation) throws Exception { // @Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED)
// if (workFinishingStations.contains(workStation)) { // public void doWork(String workStation) throws Exception {
// // 当前站台正在完成工作 // if (workDoingStations.contains(workStation)) {
// return "当前站台正在完成工作,请勿重复操作"; // // 当前站台正在创建任务
// return;
// } else { // } else {
// // 添加站台 // // 添加站台
// workFinishingStations.add(workStation); // workDoingStations.add(workStation);
// } // }
// try { // try {
// if (workFlowService.exists(new LambdaQueryWrapper<WorkFlow>() // // 查找当前站台未开始的工作流
// List<WorkFlow> currentWorkFlowList = workFlowService.list(new LambdaQueryWrapper<WorkFlow>()
// .eq(WorkFlow::getWorkStation, workStation) // .eq(WorkFlow::getWorkStation, workStation)
// .ne(WorkFlow::getWorkStatus, 2))) { // .eq(WorkFlow::getWorkStatus, 1));
// // 当前站台工作未全部完成 // // 没有可做的任务
// return "工作未全部做完,不允许确认完成。"; // if (currentWorkFlowList == null || currentWorkFlowList.isEmpty()) {
// return;
// } // }
// if (eLocationConfigService.exists(new LambdaQueryWrapper<ELocationConfig>() // // 查站台要料表---未分配以及分配但未完全分配
// .eq(ELocationConfig::getWorkStation, workStation) // List<GoodsToStation> goodsToStationList = goodsToStationService.list(new LambdaQueryWrapper<GoodsToStation>()
// .eq(ELocationConfig::getPrintStatus, 0))) {
// // 有标签未打印
// return "有标签未打印";
// }
// if (!eLocationConfigService.exists(new LambdaQueryWrapper<ELocationConfig>()
// .eq(ELocationConfig::getWorkStation, workStation))) {
// // 没有标签说明点过确认
// return "没有可以确认完成的工作,请勿重复点击。";
// }
// // 查找当前站台的标签配置
// List<ELocationConfig> eLocationConfigList = eLocationConfigService.list(new LambdaQueryWrapper<ELocationConfig>()
// .eq(ELocationConfig::getWorkStation, workStation));
// // 保存一下记录
// List<ELocationConfigLast> eLocationConfigLastList = ELocationConfig.toLocationsConfigLastList(eLocationConfigList);
// // 先清空之前的
// eLocationConfigLastService.remove(new LambdaQueryWrapper<ELocationConfigLast>()
// .eq(ELocationConfigLast::getWorkStation, workStation));
// eLocationConfigLastService.saveBatch(eLocationConfigLastList);
// // 删除所有的标签配置
// eLocationConfigService.remove(new LambdaQueryWrapper<ELocationConfig>()
// .eq(ELocationConfig::getWorkStation, workStation));
// // 查询当前站台的所有工作流列表
// List<WorkFlow> workFlowList = workFlowService.list(new LambdaQueryWrapper<WorkFlow>()
// .eq(WorkFlow::getWorkStation, workStation)
// .eq(WorkFlow::getWorkStatus, 2));
// // workSummary列表
// List<WorkSummary> workSummaryList = new ArrayList<>();
// for (WorkFlow workFlow : workFlowList) {
// WorkSummary summary = new WorkSummary();
// summary.setWorkFlowId(workFlow.getWorkFlowId());
// summary.setWorkStation(workFlow.getWorkStation());
// summary.setWorkOrder(workFlow.getWorkOrder());
// summary.setWorkCenter(workFlow.getWorkCenter());
// summary.setGoodsId(workFlow.getGoodsId());
// summary.setPickedNum(workFlow.getPickedNum());
// summary.setNeedNum(workFlow.getNeedNum());
// summary.setLackNum(workFlow.getNeedNum().subtract(workFlow.getPickedNum()));
// summary.setWorkDate(workFlow.getCreateTime().toLocalDate().atStartOfDay());
// summary.setWorkStatus(workFlow.getWorkStatus());
// summary.setLackStatus(summary.getLackNum().compareTo(BigDecimal.ZERO) > 0 ? 1 : 0);
// summary.setFinishTime(workFlow.getFinishTime());
// summary.setOpUser(workFlow.getOpUser());
// // 设置电子标签位置
// List<ELocationConfig> currentBoxELocationList = eLocationConfigList.stream().filter(e ->
// e.getWorkOrder().equals(workFlow.getWorkOrder())
// && e.getWorkCenter().equals(workFlow.getWorkCenter())).toList();
// summary.setELocationId(currentBoxELocationList.size() > 0 ? currentBoxELocationList.get(0).getELocationId() : "");
// workSummaryList.add(summary);
// // 更新工单表
// kateOrdersService.update(new LambdaUpdateWrapper<KateOrders>()
// .set(KateOrders::getOrderStatus, 4)
// .set(KateOrders::getFinishTime, LocalDateTime.now())
// .set(KateOrders::getPickedQuantity, workFlow.getPickedNum())
// .set(KateOrders::getLackQuantity, workFlow.getNeedNum().subtract(workFlow.getPickedNum()))
// .eq(KateOrders::getOrderId, workFlow.getOrderId())
// .eq(KateOrders::getSupplyArea, workFlow.getWorkCenter())
// .eq(KateOrders::getGoodsId, workFlow.getGoodsId()));
// // 如果当前工单已经没有未完成的工作更新DBS状态完成
// if (!kateOrdersService.exists(new LambdaQueryWrapper<KateOrders>()
// .eq(KateOrders::getOrderId, workFlow.getOrderId())
// .ne(KateOrders::getOrderStatus, 4))) {
// kateDBSService.update(new LambdaUpdateWrapper<KateDBS>()
// .set(KateDBS::getDbsStatus, 2)
// .set(KateDBS::getLastUpdateTime, LocalDateTime.now())
// .eq(KateDBS::getWorkOrder, workFlow.getOrderId()));
// }
// }
// workSummaryService.saveBatch(workSummaryList);
// // 移除工作流
// workFlowService.remove(new LambdaQueryWrapper<WorkFlow>()
// .eq(WorkFlow::getWorkStation, workStation));
// // 移库站台要料
// goodsToStationService.remove(new LambdaQueryWrapper<GoodsToStation>()
// .eq(GoodsToStation::getWorkStation, workStation)); // .eq(GoodsToStation::getWorkStation, workStation));
// List<GoodsToStation> notFinishedGoodsList = goodsToStationList.stream().filter(goodsToStation -> goodsToStation.getDistributeStatus() < 2).toList();
// if (notFinishedGoodsList.isEmpty()) {
// // 查询是否还有这个站台的拣选任务
// if (!pickTaskService.exists(new LambdaQueryWrapper<PickTask>()
// .eq(PickTask::getStandId, workStation))) {
// // 需要重新分配的goodsToStationsList
// Map<String, GoodsToStation> needDistributeGoodsMap = new HashMap<>();
// // 需要完成的工作流
// List<WorkFlow> needFinishWorkFlowList = new ArrayList<>();
// // 所有缺料的分配
// List<String> lackGoodsIdList = goodsToStationList.stream().filter(goodsToStation -> goodsToStation.getDistributeStatus() == 3).map(GoodsToStation::getGoodsId).distinct().toList();
// // 不缺料的分配
// Map<String, GoodsToStation> noLackGoodsMap = goodsToStationList.stream().filter(goodsToStation -> goodsToStation.getDistributeStatus() == 2).collect(Collectors.toMap(GoodsToStation::getGoodsId, goodsToStation -> goodsToStation));
// // 查询当前工作流中所有缺料的数据行
// for (WorkFlow notFinishedWorkFlow : currentWorkFlowList) {
// if (notFinishedWorkFlow.getPickedNum().compareTo(notFinishedWorkFlow.getNeedNum()) < 0) {
// // 缺料时判断是否当前物料在缺料列表中
// 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 {
// GoodsToStation goodsToStation = new GoodsToStation();
// goodsToStation.setConfigId(notFinishedWorkFlow.getGoodsId() + "_" + workStation);
// goodsToStation.setGoodsId(notFinishedWorkFlow.getGoodsId());
// goodsToStation.setWorkStation(workStation);
// goodsToStation.setDistributeStatus(0);
// goodsToStation.setDistributedNum(BigDecimal.ZERO);
// goodsToStation.setTotalNum(needNum);
// needDistributeGoodsMap.put(notFinishedWorkFlow.getGoodsId(), goodsToStation);
// }
// }
// }
// } else {
// // 不缺料直接完成
// notFinishedWorkFlow.setWorkStatus(2);
// notFinishedWorkFlow.setFinishTime(LocalDateTime.now());
// notFinishedWorkFlow.setOpUser("系统自动完成");
// needFinishWorkFlowList.add(notFinishedWorkFlow);
// }
// }
// // 保存重新分配的goodsToStationList
// goodsToStationService.saveOrUpdateBatch(needDistributeGoodsMap.values());
// // 保存需要完成的工作流
// workFlowService.updateBatchById(needFinishWorkFlowList);
// }
// return;
// }
// for (GoodsToStation goodsToStation : notFinishedGoodsList) {
// // 当前物料当前站台需求数量
// BigDecimal needNum = goodsToStation.getTotalNum().subtract(goodsToStation.getDistributedNum());
// if (needNum.compareTo(BigDecimal.ZERO) == 0) {
// // 需求数量为0
// continue;
// }
// // 判断实际库存是否充足
// List<Stock> stockList = stockService.list(new LambdaQueryWrapper<Stock>()
// .apply("goods_related ->> '$.goodsId' = {0}" + MYSQL_JSON_CI, goodsToStation.getGoodsId())
// .apply("goods_related ->> '$.remainNum' > 0"));
// if (stockList == null || stockList.isEmpty()) {
// goodsToStation.setDistributeStatus(3);
// continue;
// }
// // 判断当前物料是否在流转中
// needNum = wmsTaskService.callGoods(goodsToStation.getGoodsId(), needNum, workStation);
// // 判断此时需求数量是否为0
// if (needNum.compareTo(BigDecimal.ZERO) <= 0) {
// // 分配完成
// goodsToStation.setDistributeStatus(2);
// } else {
// needNum = wmsTaskService.callStocks(goodsToStation.getGoodsId(), needNum, workStation);
// if (needNum.compareTo(BigDecimal.ZERO) > 0) {
// // 已分配但未完全分配
// goodsToStation.setDistributeStatus(1);
// } else {
// // 分配完成
// goodsToStation.setDistributeStatus(2);
// }
// }
// // 更新已分配数量
// goodsToStation.setDistributedNum(goodsToStation.getTotalNum().subtract(needNum));
// }
// goodsToStationService.updateBatchById(notFinishedGoodsList);
// } catch (Exception e) { // } catch (Exception e) {
// logger.error("完成站台:{}工作发生异常:{}", workStation, convertJsonString(e)); // logger.error("执行站台:{}工作发生异常:{}", workStation, convertJsonString(e));
// throw new Exception("完成站台:" + workStation + "工作发生异常!"); // // 回滚事务
// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
// } finally { // } finally {
// // 当前站台工作完成 // // 当前站台创建任务完成
// workFinishingStations.remove(workStation); // workDoingStations.remove(workStation);
// } // }
// return "";
// } // }
@Override @Override
@ -636,7 +584,7 @@ public class WorkServiceImplements implements IWorkService {
try { try {
if (workFlowService.exists(new LambdaQueryWrapper<WorkFlow>() if (workFlowService.exists(new LambdaQueryWrapper<WorkFlow>()
.eq(WorkFlow::getWorkStation, workStation) .eq(WorkFlow::getWorkStation, workStation)
.eq(WorkFlow::getWorkStatus, 1))) { .ne(WorkFlow::getWorkStatus, 2))) {
// 当前站台工作未全部完成 // 当前站台工作未全部完成
return "工作未全部做完,不允许确认完成。"; return "工作未全部做完,不允许确认完成。";
} }
@ -690,6 +638,24 @@ public class WorkServiceImplements implements IWorkService {
&& e.getWorkCenter().equals(workFlow.getWorkCenter())).toList(); && e.getWorkCenter().equals(workFlow.getWorkCenter())).toList();
summary.setELocationId(currentBoxELocationList.size() > 0 ? currentBoxELocationList.get(0).getELocationId() : ""); summary.setELocationId(currentBoxELocationList.size() > 0 ? currentBoxELocationList.get(0).getELocationId() : "");
workSummaryList.add(summary); workSummaryList.add(summary);
// 更新工单表
kateOrdersService.update(new LambdaUpdateWrapper<KateOrders>()
.set(KateOrders::getOrderStatus, 4)
.set(KateOrders::getFinishTime, LocalDateTime.now())
.set(KateOrders::getPickedQuantity, workFlow.getPickedNum())
.set(KateOrders::getLackQuantity, workFlow.getNeedNum().subtract(workFlow.getPickedNum()))
.eq(KateOrders::getOrderId, workFlow.getOrderId())
.eq(KateOrders::getSupplyArea, workFlow.getWorkCenter())
.eq(KateOrders::getGoodsId, workFlow.getGoodsId()));
// 如果当前工单已经没有未完成的工作更新DBS状态完成
if (!kateOrdersService.exists(new LambdaQueryWrapper<KateOrders>()
.eq(KateOrders::getOrderId, workFlow.getOrderId())
.ne(KateOrders::getOrderStatus, 4))) {
kateDBSService.update(new LambdaUpdateWrapper<KateDBS>()
.set(KateDBS::getDbsStatus, 2)
.set(KateDBS::getLastUpdateTime, LocalDateTime.now())
.eq(KateDBS::getWorkOrder, workFlow.getOrderId()));
}
} }
workSummaryService.saveBatch(workSummaryList); workSummaryService.saveBatch(workSummaryList);
// 移除工作流 // 移除工作流
@ -708,6 +674,90 @@ public class WorkServiceImplements implements IWorkService {
return ""; return "";
} }
// @Override
// public String finishWork(String workStation) throws Exception {
// if (workFinishingStations.contains(workStation)) {
// // 当前站台正在完成工作
// return "当前站台正在完成工作,请勿重复操作";
// } else {
// // 添加站台
// workFinishingStations.add(workStation);
// }
// try {
// if (workFlowService.exists(new LambdaQueryWrapper<WorkFlow>()
// .eq(WorkFlow::getWorkStation, workStation)
// .eq(WorkFlow::getWorkStatus, 1))) {
// // 当前站台工作未全部完成
// return "工作未全部做完,不允许确认完成。";
// }
// if (eLocationConfigService.exists(new LambdaQueryWrapper<ELocationConfig>()
// .eq(ELocationConfig::getWorkStation, workStation)
// .eq(ELocationConfig::getPrintStatus, 0))) {
// // 有标签未打印
// return "有标签未打印";
// }
// if (!eLocationConfigService.exists(new LambdaQueryWrapper<ELocationConfig>()
// .eq(ELocationConfig::getWorkStation, workStation))) {
// // 没有标签说明点过确认
// return "没有可以确认完成的工作,请勿重复点击。";
// }
// // 查找当前站台的标签配置
// List<ELocationConfig> eLocationConfigList = eLocationConfigService.list(new LambdaQueryWrapper<ELocationConfig>()
// .eq(ELocationConfig::getWorkStation, workStation));
// // 保存一下记录
// List<ELocationConfigLast> eLocationConfigLastList = ELocationConfig.toLocationsConfigLastList(eLocationConfigList);
// // 先清空之前的
// eLocationConfigLastService.remove(new LambdaQueryWrapper<ELocationConfigLast>()
// .eq(ELocationConfigLast::getWorkStation, workStation));
// eLocationConfigLastService.saveBatch(eLocationConfigLastList);
// // 删除所有的标签配置
// eLocationConfigService.remove(new LambdaQueryWrapper<ELocationConfig>()
// .eq(ELocationConfig::getWorkStation, workStation));
// // 查询当前站台的所有工作流列表
// List<WorkFlow> workFlowList = workFlowService.list(new LambdaQueryWrapper<WorkFlow>()
// .eq(WorkFlow::getWorkStation, workStation)
// .eq(WorkFlow::getWorkStatus, 2));
// // workSummary列表
// List<WorkSummary> workSummaryList = new ArrayList<>();
// for (WorkFlow workFlow : workFlowList) {
// WorkSummary summary = new WorkSummary();
// summary.setWorkFlowId(workFlow.getWorkFlowId());
// summary.setWorkStation(workFlow.getWorkStation());
// summary.setWorkOrder(workFlow.getWorkOrder());
// summary.setWorkCenter(workFlow.getWorkCenter());
// summary.setGoodsId(workFlow.getGoodsId());
// summary.setPickedNum(workFlow.getPickedNum());
// summary.setNeedNum(workFlow.getNeedNum());
// summary.setLackNum(workFlow.getNeedNum().subtract(workFlow.getPickedNum()));
// summary.setWorkDate(workFlow.getCreateTime().toLocalDate().atStartOfDay());
// summary.setWorkStatus(workFlow.getWorkStatus());
// summary.setLackStatus(summary.getLackNum().compareTo(BigDecimal.ZERO) > 0 ? 1 : 0);
// summary.setFinishTime(workFlow.getFinishTime());
// summary.setOpUser(workFlow.getOpUser());
// // 设置电子标签位置
// List<ELocationConfig> currentBoxELocationList = eLocationConfigList.stream().filter(e ->
// e.getWorkOrder().equals(workFlow.getWorkOrder())
// && e.getWorkCenter().equals(workFlow.getWorkCenter())).toList();
// summary.setELocationId(currentBoxELocationList.size() > 0 ? currentBoxELocationList.get(0).getELocationId() : "");
// workSummaryList.add(summary);
// }
// workSummaryService.saveBatch(workSummaryList);
// // 移除工作流
// workFlowService.remove(new LambdaQueryWrapper<WorkFlow>()
// .eq(WorkFlow::getWorkStation, workStation));
// // 移库站台要料
// goodsToStationService.remove(new LambdaQueryWrapper<GoodsToStation>()
// .eq(GoodsToStation::getWorkStation, workStation));
// } catch (Exception e) {
// logger.error("完成站台:{}工作发生异常:{}", workStation, convertJsonString(e));
// throw new Exception("完成站台:" + workStation + "工作发生异常!");
// } finally {
// // 当前站台工作完成
// workFinishingStations.remove(workStation);
// }
// return "";
// }
/** /**
* 先找到MWL的小工位的配置 * 先找到MWL的小工位的配置
* *
@ -724,12 +774,18 @@ public class WorkServiceImplements implements IWorkService {
stationConfigQueryWrapper.ne(WorkStationConfig::getModel, "MWL"); stationConfigQueryWrapper.ne(WorkStationConfig::getModel, "MWL");
} }
List<WorkStationConfig> currentStationConfigsOfNwl = workStationConfigService.list(stationConfigQueryWrapper); List<WorkStationConfig> currentStationConfigsOfNwl = workStationConfigService.list(stationConfigQueryWrapper);
// 当前站台未分配库位 // 没有工站配置
if (currentStationConfigsOfNwl == null || currentStationConfigsOfNwl.isEmpty()) { if (currentStationConfigsOfNwl == null || currentStationConfigsOfNwl.isEmpty()) {
return; return;
} }
// 今日开工的工单和小工位 // 今日开工的工单和小工位
Map<String, List<WorkCenterAndOrderDto>> tasksOfTodayMap = new HashMap<>(); Map<String, List<WorkCenterAndOrderDto>> tasksOfTodayMap = new HashMap<>();
// 查询当前未开始的工单
List<KateOrders> allNewKateWorkOrders = kateOrdersService.list(new LambdaQueryWrapper<KateOrders>()
.eq(KateOrders::getOrderStatus, 0)
.eq(KateOrders::getSortString, configMap.get(ConfigMapKeyEnum.SLOC_FILTER_STRING.getConfigKey())));
// 查询所有的dbs
List<KateDBS> allKateDBS = kateDBSService.list(new LambdaQueryWrapper<KateDBS>().orderByAsc(KateDBS::getWorkSequence));
// 根据所有小工位查到对应的任务 // 根据所有小工位查到对应的任务
for (WorkStationConfig workConfig : currentStationConfigsOfNwl) { for (WorkStationConfig workConfig : currentStationConfigsOfNwl) {
// 查询当前小工位是否已经判断过开工日期 // 查询当前小工位是否已经判断过开工日期
@ -737,12 +793,10 @@ public class WorkServiceImplements implements IWorkService {
continue; continue;
} }
// 通过工单表查询到对应的工单 // 通过工单表查询到对应的工单
List<KateOrders> kateWorkOrders = kateOrdersService.list(new LambdaQueryWrapper<KateOrders>() List<KateOrders> kateWorkOrders = allNewKateWorkOrders.stream().filter(kateWorkOrder ->
.eq(KateOrders::getSupplyArea, workConfig.getSmallBox()) kateWorkOrder.getSupplyArea().equals(workConfig.getSmallBox())).toList();
.eq(KateOrders::getOrderStatus, 0)
.eq(KateOrders::getSortString, configMap.get(ConfigMapKeyEnum.SLOC_FILTER_STRING.getConfigKey())));
// 当前工位没有未完成的工单 // 当前工位没有未完成的工单
if (kateWorkOrders == null || kateWorkOrders.isEmpty()) { if (kateWorkOrders.isEmpty()) {
continue; continue;
} }
List<WorkCenterAndOrderDto> toDaysOrders = new ArrayList<>(); List<WorkCenterAndOrderDto> toDaysOrders = new ArrayList<>();
@ -751,16 +805,23 @@ public class WorkServiceImplements implements IWorkService {
for (KateOrders kateWorkOrder : kateWorkOrders) { for (KateOrders kateWorkOrder : kateWorkOrders) {
if (!ordersAndDBSMap.containsKey(kateWorkOrder.getWorkOrder())) { if (!ordersAndDBSMap.containsKey(kateWorkOrder.getWorkOrder())) {
// 从DBS表查询对应的工单以及开工时间 // 从DBS表查询对应的工单以及开工时间
KateDBS kateDBS = kateDBSService.getOne(new LambdaQueryWrapper<KateDBS>() KateDBS kateDBS = allKateDBS.stream().filter(tempKateDBS ->
.eq(KateDBS::getWorkOrder, kateWorkOrder.getWorkOrder()) tempKateDBS.getWorkOrder().equals(kateWorkOrder.getWorkOrder())).findFirst().orElse(null);
.ne(KateDBS::getDbsStatus, 2)
.orderByAsc(KateDBS::getWorkSequence)
.last("limit 1"));
if (kateDBS == null || StringUtils.isEmpty(kateDBS.getWorkOrder())) {// 不存在对应的工单计划 if (kateDBS == null || StringUtils.isEmpty(kateDBS.getWorkOrder())) {// 不存在对应的工单计划
continue; continue;
} }
// 判断是否是当天开工 // 判断是否是当天开工
if (kateDBS.getPlanStartDate().plusDays(workConfig.getStartDateAdjust()).toLocalDate().isEqual(LocalDateTime.now().toLocalDate())) { int indexOfDbs = localWorkDateList.indexOf(kateDBS.getPlanStartDate().toLocalDate());
if (indexOfDbs == -1) {
// 工作日不包含此开工日期
continue;
}
int indexAfterAdjust = indexOfDbs + workConfig.getStartDateAdjust();
if (indexAfterAdjust < 0 || indexAfterAdjust >= localWorkDateList.size()) {
// 调整后的日期不再工作日范围
continue;
}
if (localWorkDateList.get(indexAfterAdjust).equals(LocalDate.now())) {
// 已经查询过的为了不重复查询添加map // 已经查询过的为了不重复查询添加map
ordersAndDBSMap.put(kateWorkOrder.getWorkOrder(), kateDBS); ordersAndDBSMap.put(kateWorkOrder.getWorkOrder(), kateDBS);
// 添加工作计划 // 添加工作计划
@ -768,6 +829,7 @@ public class WorkServiceImplements implements IWorkService {
wcoDto.setWorkCenter(workConfig.getSmallBox()); wcoDto.setWorkCenter(workConfig.getSmallBox());
wcoDto.setWorkOrder(kateWorkOrder.getWorkOrder()); wcoDto.setWorkOrder(kateWorkOrder.getWorkOrder());
wcoDto.setStartDate(LocalDateTime.now().toLocalDate().atStartOfDay()); wcoDto.setStartDate(LocalDateTime.now().toLocalDate().atStartOfDay());
wcoDto.setDbsSequence(kateDBS.getWorkSequence());
toDaysOrders.add(wcoDto); toDaysOrders.add(wcoDto);
} }
} }
@ -777,14 +839,12 @@ public class WorkServiceImplements implements IWorkService {
// 判断是否有今天开工的工单和小工位 // 判断是否有今天开工的工单和小工位
if (!tasksOfTodayMap.isEmpty()) { if (!tasksOfTodayMap.isEmpty()) {
for (String smallBoxKey : tasksOfTodayMap.keySet()) { for (String smallBoxKey : tasksOfTodayMap.keySet()) {
List<WorkCenterAndOrderDto> currentWorkCenterAndOrderDtoList = tasksOfTodayMap.get(smallBoxKey); List<WorkCenterAndOrderDto> currentWorkCenterAndOrderDtoList = tasksOfTodayMap.get(smallBoxKey).stream().sorted(Comparator.comparingInt(WorkCenterAndOrderDto::getDbsSequence)).toList();
for (WorkCenterAndOrderDto currentWorkCenterAndOrderDto : currentWorkCenterAndOrderDtoList) { for (WorkCenterAndOrderDto currentWorkCenterAndOrderDto : currentWorkCenterAndOrderDtoList) {
// 通过工单表查询到对应的工单 // 通过工单表查询到对应的工单
List<KateOrders> kateWorkOrderList = kateOrdersService.list(new LambdaQueryWrapper<KateOrders>() List<KateOrders> kateWorkOrderList = allNewKateWorkOrders.stream().filter(kateWorkOrder ->
.eq(KateOrders::getWorkOrder, currentWorkCenterAndOrderDto.getWorkOrder()) kateWorkOrder.getWorkOrder().equals(currentWorkCenterAndOrderDto.getWorkOrder())
.eq(KateOrders::getSupplyArea, currentWorkCenterAndOrderDto.getWorkCenter()) && kateWorkOrder.getSupplyArea().equals(currentWorkCenterAndOrderDto.getWorkCenter())).toList();
.eq(KateOrders::getOrderStatus, 0)
.eq(KateOrders::getSortString, configMap.get(ConfigMapKeyEnum.SLOC_FILTER_STRING.getConfigKey())));
for (KateOrders tempOrder : kateWorkOrderList) { for (KateOrders tempOrder : kateWorkOrderList) {
// 生成workFlow // 生成workFlow
WorkFlow tempWorkFlow = new WorkFlow(); WorkFlow tempWorkFlow = new WorkFlow();

View File

@ -0,0 +1,17 @@
package com.wms.service.serviceImplements;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wms.entity.table.WorkDate;
import com.wms.mapper.WorkDateMapper;
import com.wms.service.WorkDateService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* 工作日历
*/
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class WorkDateServiceImpl extends ServiceImpl<WorkDateMapper, WorkDate> implements WorkDateService {
}

View File

@ -0,0 +1,109 @@
package com.wms.utils.excel.listener;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.util.ListUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wms.entity.table.WorkDate;
import com.wms.service.WorkDateService;
import com.wms.utils.excel.vo.WorkDateExcelVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.wms.config.InitLocalConfig.localWorkDateList;
/**
* 上传DBS监听
*/
public class UploadWorkDateListener implements ReadListener<WorkDateExcelVo> {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
/**
* 每隔5条存储数据库实际使用中可以100条然后清理list 方便内存回收
*/
private static final int BATCH_COUNT = 100;
private List<WorkDateExcelVo> cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
private final WorkDateService workDateService;// 工作日服务
private int key = 1;// 主键
private final Map<LocalDate, WorkDate> newWorkDateMap = new HashMap<>();// 新的工作日
public UploadWorkDateListener(WorkDateService workDateService) {
this.workDateService = workDateService;
}
@Override
public void onException(Exception exception, AnalysisContext context) throws Exception {
int rowCount = context.readRowHolder().getRowIndex() + 1;
logger.error("处理Dbs数据发生异常第{}行发生异常。", rowCount);
throw new Exception("" + rowCount + "行数据异常。");
}
/**
* 这个每一条数据解析都会来调用
*
* @param workDateExcelVo one row value. It is same as {@link AnalysisContext#readRowHolder()}
* @param analysisContext context
*/
@Override
public void invoke(WorkDateExcelVo workDateExcelVo, AnalysisContext analysisContext) {
if (workDateExcelVo.getWorkDate() != null && !newWorkDateMap.containsKey(workDateExcelVo.getWorkDate())) {
// 符合条件的数据
cachedDataList.add(workDateExcelVo);
}
// 达到BATCH_COUNT了需要去存储一次数据库防止数据几万条数据在内存容易OOM
if (cachedDataList.size() >= BATCH_COUNT) {
saveData();
// 存储完成清理 list
cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
}
}
/**
* 所有数据解析完成了 都会来调用
*
* @param analysisContext context
*/
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
// 再做一次数据处理
saveData();
// 在这里统一保存数据
insertIntoDb();
}
/**
* 存储数据
*/
private void saveData() {
for (WorkDateExcelVo workDateExcelVo : cachedDataList) {
if (newWorkDateMap.containsKey(workDateExcelVo.getWorkDate())) {
// 工作日重复
continue;
}
// 创建一个新的工作日历对象
WorkDate workDate = new WorkDate();
workDate.setKeyId(key);
workDate.setWorkDate(workDateExcelVo.getWorkDate());
workDate.setRemark(workDateExcelVo.getRemark());
newWorkDateMap.put(workDateExcelVo.getWorkDate(), workDate);
key++;
}
}
/**
* 保存数据库
*/
private void insertIntoDb() {
logger.info("此次共导入{}条数据。", newWorkDateMap.size());
// 保存数据
workDateService.saveOrUpdateBatch(newWorkDateMap.values(), BATCH_COUNT);
logger.info("保存成功{}条数据。", newWorkDateMap.size());
// 生成工作日历
localWorkDateList = workDateService.list(new LambdaQueryWrapper<WorkDate>().orderByAsc(WorkDate::getWorkDate)).stream().map(WorkDate::getWorkDate).distinct().toList();
logger.info("生成工作日历Map成功。");
}
}

View File

@ -0,0 +1,25 @@
package com.wms.utils.excel.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import lombok.Data;
import java.time.LocalDate;
/**
* 导入工作日历
*/
@Data
public class WorkDateExcelVo {
/**
* 工作日
*/
@ExcelProperty("Date")
@DateTimeFormat("yyyy/MM/dd")
private LocalDate workDate;
/**
* 备注
*/
@ExcelProperty("Remark")
private String remark;
}

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.wms.mapper.WorkDateMapper">
</mapper>