1. 改动需求日期暂存

This commit is contained in:
梁州 2025-12-23 17:15:43 +08:00
parent 45da059027
commit 2e37264300
6 changed files with 148 additions and 52 deletions

View File

@ -1,5 +1,11 @@
package com.wms.constants.enums;
import lombok.Getter;
/**
* 配置项枚举
*/
@Getter
public enum ConfigMapKeyEnum {
MAX_WEIGHT("MAX_WEIGHT"),
URL_WCS_TASK("URL_WCS_TASK"),
@ -30,12 +36,10 @@ public enum ConfigMapKeyEnum {
IF_MERGE_TOMORROW("IF_MERGE_TOMORROW"),
SAME_MACHINE("SAME_MACHINE"),
SAME_AREA("SAME_AREA"),
RATE_TYPE("RATE_TYPE");
RATE_TYPE("RATE_TYPE"),
USE_REQUIRE_DATE("USE_REQUIRE_DATE");// 是否使用需求时间
private final String configKey;
ConfigMapKeyEnum(String configKey) {
this.configKey = configKey;
}
public String getConfigKey() {
return configKey;
}
}

View File

@ -26,7 +26,6 @@ import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
@ -72,9 +71,6 @@ public class ExcelController {
private final List<String> uploadFileHashStringList = new ArrayList<>();
@Value("${reqmtsDate}")
private boolean reqmtsDate;
/**
* 查询上传记录
*
@ -103,8 +99,7 @@ public class ExcelController {
} catch (Exception e) {
// 回滚事务
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
e.printStackTrace();
logger.error("查询上传记录发生异常:{}", e.getMessage());
logger.error("查询上传记录发生异常:{}", convertJsonString(e));
response.setCode(ResponseCode.ERROR.getCode());
response.setMessage("查询上传记录发生异常");
return convertJsonString(response);
@ -214,7 +209,7 @@ public class ExcelController {
// 获取之前DBS表的内容
Map<String, KateDBS> kateDbsMap = kateDbsService.list().stream().collect(Collectors.toMap(KateDBS::getWorkOrder, kateDBS -> kateDBS));
// 导入excel
EasyExcel.read(file.getInputStream(), KateDbsExcelVo.class, new UploadDbsListener(kateDbsService, kateDbsMap, fileVo.getUserName(),reqmtsDate)).sheet().headRowNumber(8).doRead();
EasyExcel.read(file.getInputStream(), KateDbsExcelVo.class, new UploadDbsListener(kateDbsService, kateDbsMap, fileVo.getUserName())).sheet().headRowNumber(8).doRead();
// 添加导入记录
uploadRecordService.save(UploadRecord.ofFileVo(fileVo, "DBS"));
uploadFileHashStringList.remove(fileVo.getHash());
@ -255,7 +250,7 @@ public class ExcelController {
// 获取之前工单表的内容
Map<String, KateOrders> kateOrdersMap = kateOrdersService.list().stream().collect(Collectors.toMap(kateOrders -> kateOrders.getWorkOrder() + "_" + kateOrders.getGoodsId() + "_" + kateOrders.getSupplyArea(), kateOrders -> kateOrders));
// 导入excel
EasyExcel.read(file.getInputStream(), KateOrdersExcelVo.class, new UploadKateOrdersListener(kateOrdersService, kateOrdersMap, fileVo.getUserName(),reqmtsDate)).sheet().doRead();
EasyExcel.read(file.getInputStream(), KateOrdersExcelVo.class, new UploadKateOrdersListener(kateOrdersService, kateOrdersMap, fileVo.getUserName())).sheet().doRead();
// 添加导入记录
uploadRecordService.save(UploadRecord.ofFileVo(fileVo, "ORDERS"));
uploadFileHashStringList.remove(fileVo.getHash());

View File

@ -908,6 +908,7 @@ public class WorkServiceImplements implements IWorkService {
//开始时间
LocalDateTime startTime = LocalDateTime.now();
System.out.println("分析当日" + modelStr + "工作流,开始时间:" + startTime);
// 查到当前站台所有的小工位
LambdaQueryWrapper<WorkStationConfig> stationConfigQueryWrapper = new LambdaQueryWrapper<WorkStationConfig>()
.eq(StringUtils.isNotEmpty(workStation), WorkStationConfig::getWorkStation, workStation);
@ -920,6 +921,7 @@ public class WorkServiceImplements implements IWorkService {
List<WorkStationConfig> currentStationConfigsOfNwl = workStationConfigService.list(stationConfigQueryWrapper);
// 没有工站配置
if (currentStationConfigsOfNwl == null || currentStationConfigsOfNwl.isEmpty()) {
logger.info("缺少{}工站配置,未生成工作流。", model);
return;
}
// 今日开工的工单和小工位
@ -1018,13 +1020,87 @@ public class WorkServiceImplements implements IWorkService {
}
}
}
//结束时间
LocalDateTime endTime = LocalDateTime.now();
System.out.println("分析当日" + modelStr + "工作流,结束时间:" + endTime);
// 用时
long duration = Duration.between(startTime, endTime).toMillis();
logger.info("分析当日{}工作流耗时:{}ms", modelStr, duration);
}
/**
* 获取当日工作流
* @param workFlows 工作流
* @param currentWorkDate 日期
*/
private void findCurrentDateWorks(List<WorkFlow> workFlows, LocalDate currentWorkDate) {
//开始时间
LocalDateTime startTime = LocalDateTime.now();
System.out.println("分析当日工作流,开始时间:" + startTime);
List<KateOrders> currentDateKateWorkOrders = kateOrdersService.list(new LambdaQueryWrapper<KateOrders>()
.eq(KateOrders::getOrderStatus, 0)
.eq(KateOrders::getSortString, configMap.get(ConfigMapKeyEnum.SLOC_FILTER_STRING.getConfigKey()))
.eq(KateOrders::getPlanStartDate, currentWorkDate));
if (currentDateKateWorkOrders.isEmpty()) {
logger.info("没有当日工单。");
return;
}
for (KateOrders tempOrder : currentDateKateWorkOrders) {
// 生成workFlow
WorkFlow tempWorkFlow = new WorkFlow();
tempWorkFlow.setWorkFlowId(generateId("WORKFLOW_"));
tempWorkFlow.setOrderId(tempOrder.getOrderId());
tempWorkFlow.setWorkStation("");
tempWorkFlow.setWorkOrder(tempOrder.getWorkOrder());
tempWorkFlow.setWorkCenter(tempOrder.getSupplyArea());
tempWorkFlow.setGoodsId(tempOrder.getGoodsId());
tempWorkFlow.setNeedNum(tempOrder.getRequirementQuantity());
tempWorkFlow.setCreateTime(LocalDateTime.now());
tempWorkFlow.setWorkStatus(0);
tempWorkFlow.setLightStatus(0);
tempWorkFlow.setPickedNum(BigDecimal.ZERO);
tempWorkFlow.setPlanDate(currentWorkDate);
workFlows.add(tempWorkFlow);
}
// 获得所有的小盒子号
List<String> smallBoxList = workFlows.stream().map(WorkFlow::getWorkCenter).distinct().toList();
// 查询工站配置
// 查到当前站台所有的小工位
List<WorkStationConfig> currentStationConfigsOfNwl = workStationConfigService.list(new LambdaQueryWrapper<WorkStationConfig>()
.in(WorkStationConfig::getSmallBox, smallBoxList)
.orderByAsc(WorkStationConfig::getSmallBox));
// 没有工站配置
if (currentStationConfigsOfNwl == null || currentStationConfigsOfNwl.isEmpty()) {
logger.info("缺少工站配置,未生成工作流。");
return;
}
// 生成小盒子对应大盒子map
Map<String, String> smallBoxToBigBoxMap = currentStationConfigsOfNwl.stream().collect(Collectors.toMap(WorkStationConfig::getSmallBox, WorkStationConfig::getBigBox));
// 生成小盒子对应机型Map
Map<String, String> smallBoxToMachineTypeMap = currentStationConfigsOfNwl.stream().collect(Collectors.toMap(WorkStationConfig::getSmallBox, WorkStationConfig::getModel));
// 更新机型和大盒子号
for (WorkFlow tempWorkFlow : workFlows) {
// 机型
String model = smallBoxToMachineTypeMap.get(tempWorkFlow.getWorkCenter());
// 大盒子号
String bigBox = smallBoxToBigBoxMap.get(tempWorkFlow.getWorkCenter());
// 改动
if (StringUtils.isEmpty(model)) {
// 未知机型
tempWorkFlow.setMachineType(0);
} else {
tempWorkFlow.setMachineType(Objects.equals(model, "MWL") ? 1 : 2);
}
tempWorkFlow.setBigBox(bigBox);
}
//结束时间
LocalDateTime endTime = LocalDateTime.now();
System.out.println("分析当日工作流,结束时间:" + endTime);
// 用时
long duration = Duration.between(startTime, endTime).toMillis();
logger.info("获取当日工作流耗时:{}ms", duration);
}
/**
@ -1079,35 +1155,42 @@ public class WorkServiceImplements implements IWorkService {
}
// 添加进总汇总数据
List<WorkFlow> allFlows = new ArrayList<>();
// 获取当天所有的装载机工作
List<WorkFlow> thisDayMWLWorks = new ArrayList<>();
// 获取到当天所有的平地机工作
List<WorkFlow> thisDayMGWorks = new ArrayList<>();
// 需要合并第二天的平地机工作
List<WorkFlow> nextDayMGWorks = new ArrayList<>();
// 生成装载机工作流
findWorks("", thisDayMWLWorks, "MWL", currentWorkDate);
if (!thisDayMWLWorks.isEmpty()) {
allFlows.addAll(thisDayMWLWorks);
}
// 生成当天平地机工作流
findWorks("", thisDayMGWorks, "NOT_MWL", currentWorkDate);
if (!thisDayMGWorks.isEmpty()) {
allFlows.addAll(thisDayMGWorks);
// 查询配置是否需要合并第二天的配置
String ifMergeTomorrow = configMap.get(ConfigMapKeyEnum.IF_MERGE_TOMORROW.getConfigKey());
if (!StringUtils.isEmpty(ifMergeTomorrow) && ifMergeTomorrow.equals("1")) {
// 获取下一个工作日
LocalDate nextWorkDate = nextWorkDate(currentWorkDate);
if (nextWorkDate != null && nextWorkDate.isAfter(currentWorkDate)) {
findWorks("", nextDayMGWorks, "NOT_MWL", nextWorkDate);
}
if (!nextDayMGWorks.isEmpty()) {
// 添加第二天的平地机工作进汇总
allFlows.addAll(nextDayMGWorks);
// 查询配置是否使用默认开工日期
String useReqmtDate = configMap.get(ConfigMapKeyEnum.USE_REQUIRE_DATE.getConfigKey());
if (!StringUtils.isEmpty(useReqmtDate) && useReqmtDate.equals("1")) {// 使用工单的开工日期
findCurrentDateWorks(allFlows, currentWorkDate);
} else {
// 获取当天所有的装载机工作
List<WorkFlow> thisDayMWLWorks = new ArrayList<>();
// 获取到当天所有的平地机工作
List<WorkFlow> thisDayMGWorks = new ArrayList<>();
// 需要合并第二天的平地机工作
List<WorkFlow> nextDayMGWorks = new ArrayList<>();
// 生成装载机工作流
findWorks("", thisDayMWLWorks, "MWL", currentWorkDate);
if (!thisDayMWLWorks.isEmpty()) {
allFlows.addAll(thisDayMWLWorks);
}
// 生成当天平地机工作流
findWorks("", thisDayMGWorks, "NOT_MWL", currentWorkDate);
if (!thisDayMGWorks.isEmpty()) {
allFlows.addAll(thisDayMGWorks);
// 查询配置是否需要合并第二天的配置
String ifMergeTomorrow = configMap.get(ConfigMapKeyEnum.IF_MERGE_TOMORROW.getConfigKey());
if (!StringUtils.isEmpty(ifMergeTomorrow) && ifMergeTomorrow.equals("1")) {
// 获取下一个工作日
LocalDate nextWorkDate = nextWorkDate(currentWorkDate);
if (nextWorkDate != null && nextWorkDate.isAfter(currentWorkDate)) {
findWorks("", nextDayMGWorks, "NOT_MWL", nextWorkDate);
}
if (!nextDayMGWorks.isEmpty()) {
// 添加第二天的平地机工作进汇总
allFlows.addAll(nextDayMGWorks);
}
}
}
}
if (!allFlows.isEmpty()) {
// 处理这些工作流
List<WorkFlow> oldWorkFlows = workFlowService.list();

View File

@ -3,6 +3,7 @@ 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.wms.constants.enums.ConfigMapKeyEnum;
import com.wms.entity.table.KateDBS;
import com.wms.service.KateDBSService;
import com.wms.utils.StringUtils;
@ -15,6 +16,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.wms.config.InitLocalConfig.configMap;
import static com.wms.utils.WmsUtils.generateId;
/**
@ -32,14 +34,18 @@ public class UploadDbsListener implements ReadListener<KateDbsExcelVo> {
private final Map<String, KateDBS> oldKateDBSMap;// 旧的DBS数据
private final Map<String, KateDBS> newKateDBSMap = new HashMap<>();// 新的DBS数据
private final int maxSequence;
private final boolean isAddReqmtDate;
public UploadDbsListener(KateDBSService kateDBSService, Map<String, KateDBS> oldKateDBSMap, String uploadUser, boolean isAddReqmtDate) {
private boolean isAddReqmtDate = false;
public UploadDbsListener(KateDBSService kateDBSService, Map<String, KateDBS> oldKateDBSMap, String uploadUser) {
this.kateDBSService = kateDBSService;
this.oldKateDBSMap = oldKateDBSMap;
this.uploadUser = uploadUser;
this.isAddReqmtDate = isAddReqmtDate;
// 获取最大序列号
maxSequence = oldKateDBSMap.values().stream().mapToInt(KateDBS::getWorkSequence).max().orElse(0);
// 查询配置是否使用默认开工日期
String useReqmtDate = configMap.get(ConfigMapKeyEnum.USE_REQUIRE_DATE.getConfigKey());
if (!StringUtils.isEmpty(useReqmtDate) && useReqmtDate.equals("1")) {
isAddReqmtDate = true;
}
}
@Override
@ -60,11 +66,15 @@ public class UploadDbsListener implements ReadListener<KateDbsExcelVo> {
if (kateDbsExcelVo.getWorkSequence() != null
&& StringUtils.isNotEmpty(kateDbsExcelVo.getWorkOrder())
&& StringUtils.isNotEmpty(kateDbsExcelVo.getMachineNo())) {
if(!isAddReqmtDate){
if (!isAddReqmtDate) {
if(kateDbsExcelVo.getPlanStartDate() != null){
cachedDataList.add(kateDbsExcelVo);
} else {
int rowCount = analysisContext.readRowHolder().getRowIndex() + 1;
logger.error("第{}行DBS缺少开工日期。", rowCount);
throw new RuntimeException("" + rowCount + "行DBS缺少开工日期。");
}
}else{
} else {
cachedDataList.add(kateDbsExcelVo);
}

View File

@ -36,20 +36,23 @@ public class UploadKateOrdersListener implements ReadListener<KateOrdersExcelVo>
private final String uploadUser;// 用户
private final Map<String, KateOrders> oldKateOrdersMap;// 旧的工单数据
private final Map<String, KateOrders> newKateOrdersMap = new HashMap<>();// 新的工单数据
private final boolean isAddReqmtDate;
public UploadKateOrdersListener(KateOrdersService kateOrdersService, Map<String, KateOrders> oldKateOrdersMap, String uploadUser, boolean isAddReqmtDate) {
private boolean isAddReqmtDate = false;
public UploadKateOrdersListener(KateOrdersService kateOrdersService, Map<String, KateOrders> oldKateOrdersMap, String uploadUser) {
this.kateOrdersService = kateOrdersService;
this.oldKateOrdersMap = oldKateOrdersMap;
this.uploadUser = uploadUser;
this.isAddReqmtDate = isAddReqmtDate;
// 查询配置是否使用默认开工日期
String useReqmtDate = configMap.get(ConfigMapKeyEnum.USE_REQUIRE_DATE.getConfigKey());
if (!StringUtils.isEmpty(useReqmtDate) && useReqmtDate.equals("1")) {
isAddReqmtDate = true;
}
}
@Override
public void onException(Exception exception, AnalysisContext context) throws Exception {
int rowCount = context.readRowHolder().getRowIndex() + 1;
logger.error("处理工单数据发生异常,第{}行发生异常。", rowCount);
throw new Exception("" + rowCount + "行数据异常。");
throw new Exception("" + rowCount + "行数据异常。" + exception.getMessage());
}
/**
@ -68,9 +71,13 @@ public class UploadKateOrdersListener implements ReadListener<KateOrdersExcelVo>
&& StringUtils.isNotEmpty(kateOrdersExcelVo.getSupplyArea())
&& kateOrdersExcelVo.getRequirementQuantity() != null
&& kateOrdersExcelVo.getRequirementQuantity().compareTo(BigDecimal.ZERO) > 0) {
if(isAddReqmtDate){
if (isAddReqmtDate) {
if(kateOrdersExcelVo.getPlanStartDate() != null){
cachedDataList.add(kateOrdersExcelVo);
} else {
int rowCount = analysisContext.readRowHolder().getRowIndex() + 1;
logger.error("第{}行工单缺少开工日期。", rowCount);
throw new RuntimeException("" + rowCount + "行工单缺少开工日期。");
}
} else {
// 符合条件

View File

@ -3,10 +3,7 @@ package com.wms.utils.excel.vo;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.wms.entity.table.KateOrders;
import com.wms.entity.table.Location;
import lombok.Data;
import java.math.BigDecimal;