1. 增加可使用工站配置中开工日期的功能
This commit is contained in:
parent
6fe8a99049
commit
048654698b
|
|
@ -5,9 +5,11 @@ import com.wms.constants.enums.ConfigMapKeyEnum;
|
|||
import com.wms.entity.table.Config;
|
||||
import com.wms.entity.table.Location;
|
||||
import com.wms.entity.table.WorkDate;
|
||||
import com.wms.entity.table.WorkStationConfig;
|
||||
import com.wms.service.ConfigService;
|
||||
import com.wms.service.LocationService;
|
||||
import com.wms.service.WorkDateService;
|
||||
import com.wms.service.WorkStationConfigService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -40,11 +42,17 @@ public class InitLocalConfig implements ApplicationRunner {
|
|||
* 工作日历服务
|
||||
*/
|
||||
private final WorkDateService workDateService;
|
||||
/**
|
||||
* 工站配置服务
|
||||
*/
|
||||
private final WorkStationConfigService workStationConfigService;
|
||||
|
||||
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
public static Map<String, String> configMap = new HashMap<>();
|
||||
public static Map<String, Location> instantLocationMap = new HashMap<>();
|
||||
public static List<LocalDate> localWorkDateList = new ArrayList<>();
|
||||
public static Map<String, Integer> smallBoxDateAdjustMap = new HashMap<>();// 小盒子号对应开工日期调整map
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
List<Config> configs = configService.selectConfigs("");
|
||||
|
|
@ -74,5 +82,8 @@ public class InitLocalConfig implements ApplicationRunner {
|
|||
// 生成工作日历
|
||||
localWorkDateList = workDateService.list(new LambdaQueryWrapper<WorkDate>().orderByAsc(WorkDate::getWorkDate)).stream().map(WorkDate::getWorkDate).distinct().toList();
|
||||
logger.info("生成工作日历Map成功。");
|
||||
// 生成小盒子号对应开工日期调整Map
|
||||
smallBoxDateAdjustMap = workStationConfigService.list().stream().collect(Collectors.toMap(WorkStationConfig::getSmallBox, WorkStationConfig::getStartDateAdjust));
|
||||
logger.info("生成小盒子号对应开工日期调整Map成功。");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ public enum ConfigMapKeyEnum {
|
|||
SAME_AREA("SAME_AREA"),
|
||||
RATE_TYPE("RATE_TYPE"),
|
||||
USE_REQUIRE_DATE("USE_REQUIRE_DATE"),// 是否使用需求时间
|
||||
USE_DEFAULT_ADJUST("USE_DEFAULT_ADJUST"),// 使用默认调整天数
|
||||
START_DATE_ADJUST("START_DATE_ADJUST");// 开工日期调整天数
|
||||
private final String configKey;
|
||||
ConfigMapKeyEnum(String configKey) {
|
||||
|
|
|
|||
|
|
@ -1025,7 +1025,7 @@ public class WorkServiceImplements implements IWorkService {
|
|||
}
|
||||
|
||||
/**
|
||||
* 获取当日工作流
|
||||
* 获取当日工作流---使用需求日期,使用默认开工日期调整
|
||||
* @param workFlows 工作流
|
||||
* @param currentWorkDate 日期
|
||||
*/
|
||||
|
|
@ -1083,13 +1083,12 @@ public class WorkServiceImplements implements IWorkService {
|
|||
// 获得所有的小盒子号
|
||||
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("缺少工站配置,未生成工作流。");
|
||||
logger.error("缺少工站配置,未生成工作流。");
|
||||
return;
|
||||
}
|
||||
// 生成小盒子对应大盒子map
|
||||
|
|
@ -1120,6 +1119,128 @@ public class WorkServiceImplements implements IWorkService {
|
|||
logger.info("获取当日工作流耗时:{}ms", duration);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当日工作流---使用需求日期,使用工站配置日期调整
|
||||
* @param workFlows 工作流
|
||||
* @param currentWorkDate 日期
|
||||
*/
|
||||
private void findCurrentDateWorksUseConfig(List<WorkFlow> workFlows, LocalDate currentWorkDate) {
|
||||
//开始时间:
|
||||
LocalDateTime startTime = LocalDateTime.now();
|
||||
System.out.println("分析当日工作流,开始时间:" + startTime);
|
||||
// 获取开工日期调整配置
|
||||
int defaultDateAdjust = 0;
|
||||
try {
|
||||
String dateAdjustStr = configMap.get(ConfigMapKeyEnum.START_DATE_ADJUST.getConfigKey());
|
||||
if (StringUtils.isNotEmpty(dateAdjustStr)) {
|
||||
defaultDateAdjust = Integer.parseInt(dateAdjustStr);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("获取默认开工日期调整配置失败:{},使用默认值0。", e.getMessage());
|
||||
}
|
||||
// 获取到需要查询的开工日期
|
||||
int currentDateIndex = localWorkDateList.indexOf(currentWorkDate);
|
||||
if (currentDateIndex == -1) {
|
||||
logger.error("当前开工日期不在配置的工作日历中。");
|
||||
return;
|
||||
}
|
||||
// 查询所有未开工的工单
|
||||
List<KateOrders> allBeforeWorkingKateWorkOrders = kateOrdersService.list(new LambdaQueryWrapper<KateOrders>()
|
||||
.eq(KateOrders::getOrderStatus, 0)
|
||||
.eq(KateOrders::getSortString, configMap.get(ConfigMapKeyEnum.SLOC_FILTER_STRING.getConfigKey())));
|
||||
if (allBeforeWorkingKateWorkOrders.isEmpty()) {
|
||||
logger.info("没有未开工的工单。");
|
||||
return;
|
||||
}
|
||||
List<KateOrders> currentDateKateWorkOrders = new ArrayList<>();
|
||||
for (KateOrders tempOrder : allBeforeWorkingKateWorkOrders) {
|
||||
// 开工日期调整
|
||||
Integer dateAdjust = smallBoxDateAdjustMap.get(tempOrder.getSupplyArea());
|
||||
if (dateAdjust == null) {
|
||||
dateAdjust = defaultDateAdjust;
|
||||
}
|
||||
// 获取到需求日期
|
||||
LocalDate requireDate = tempOrder.getPlanStartDate();
|
||||
if (requireDate == null) {
|
||||
// logger.error("工单号:{},小盒子号:{},零件号:{},工单数据缺少需求日期。", tempOrder.getWorkOrder(), tempOrder.getSupplyArea(), tempOrder.getGoodsId());
|
||||
continue;
|
||||
}
|
||||
int requireDateIndex = localWorkDateList.indexOf(requireDate);
|
||||
if (requireDateIndex == -1) {
|
||||
logger.error("工单号:{},小盒子号:{},零件号:{},需求日期:{}不在配置的工作日历中。", tempOrder.getWorkOrder(), tempOrder.getSupplyArea(), tempOrder.getGoodsId(), requireDate);
|
||||
continue;
|
||||
}
|
||||
// 获取到需要查询的工单
|
||||
int workDateIndex = requireDateIndex + dateAdjust;
|
||||
if (workDateIndex < 0 || workDateIndex >= localWorkDateList.size()) {
|
||||
logger.error("需求日期计算出的开工日期不在配置的工作日历中。");
|
||||
continue;
|
||||
}
|
||||
if (workDateIndex != currentDateIndex) {
|
||||
// 开工日期不是当前日期
|
||||
continue;
|
||||
}
|
||||
currentDateKateWorkOrders.add(tempOrder);
|
||||
}
|
||||
if (currentDateKateWorkOrders.isEmpty()) {
|
||||
logger.info("当前工作日没有待生成的工作流。");
|
||||
}
|
||||
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.error("缺少必须的工站配置,未生成工作流。");
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前的工作日期
|
||||
*
|
||||
|
|
@ -1175,7 +1296,13 @@ public class WorkServiceImplements implements IWorkService {
|
|||
// 查询配置是否使用默认开工日期
|
||||
String useReqmtDate = configMap.get(ConfigMapKeyEnum.USE_REQUIRE_DATE.getConfigKey());
|
||||
if (!StringUtils.isEmpty(useReqmtDate) && useReqmtDate.equals("1")) {// 使用工单的开工日期
|
||||
findCurrentDateWorks(allFlows, currentWorkDate);
|
||||
// 查询配置是否使用默认开工日期调整
|
||||
String useDefaultAdjust = configMap.get(ConfigMapKeyEnum.USE_DEFAULT_ADJUST.getConfigKey());
|
||||
if (!StringUtils.isEmpty(useDefaultAdjust) && useDefaultAdjust.equals("1")) {
|
||||
findCurrentDateWorks(allFlows, currentWorkDate);
|
||||
} else {
|
||||
findCurrentDateWorksUseConfig(allFlows, currentWorkDate);
|
||||
}
|
||||
} else {
|
||||
// 获取当天所有的装载机工作
|
||||
List<WorkFlow> thisDayMWLWorks = new ArrayList<>();
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ 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.config.InitLocalConfig;
|
||||
import com.wms.entity.table.WorkStationConfig;
|
||||
import com.wms.service.WorkStationConfigService;
|
||||
import com.wms.utils.StringUtils;
|
||||
|
|
@ -17,6 +18,7 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.wms.utils.WmsUtils.generateId;
|
||||
|
||||
|
|
@ -119,5 +121,8 @@ public class UploadStationConfigListener implements ReadListener<StationConfigEx
|
|||
// 保存数据
|
||||
workStationConfigService.saveOrUpdateBatch(newWorkStationConfigMap.values(), BATCH_COUNT);
|
||||
logger.info("保存成功{}条数据。", newWorkStationConfigMap.size());
|
||||
// 生成小盒子号对应开工日期调整Map
|
||||
InitLocalConfig.smallBoxDateAdjustMap = workStationConfigService.list().stream().collect(Collectors.toMap(WorkStationConfig::getSmallBox, WorkStationConfig::getStartDateAdjust));
|
||||
logger.info("生成小盒子号对应开工日期调整Map成功。");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user