在零件生产组没有可以生成的零件时,更新窗口时间

tags/yfai-mes-ext-v1.3
臧学普 9 months ago
parent 38d65f2050
commit 91de11ab78

@ -2,17 +2,25 @@ package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.base;
import cn.estsh.i3plus.ext.mes.api.base.IMesBtoJobService;
import cn.estsh.i3plus.ext.mes.api.base.strategy.IRoundnessStrategy;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.platform.common.tool.TimeTool;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import cn.estsh.i3plus.pojo.mes.bean.MesCustomerMessagePoint;
import cn.estsh.i3plus.pojo.mes.bean.MesPartProdGroup;
import cn.estsh.i3plus.pojo.mes.bean.MesPartProdGroupDetail;
import cn.estsh.i3plus.pojo.mes.bean.MesPartProdGroupWindowTime;
import cn.estsh.i3plus.pojo.mes.bean.shipping.MesCustSortInfo;
import cn.estsh.i3plus.pojo.mes.repository.MesPartProdGroupWindowTimeRepository;
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
import cn.estsh.impp.framework.boot.util.SpringContextsUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -33,6 +41,10 @@ public class MesBtoJobServiceImpl implements IMesBtoJobService {
@Autowired
private MesCustSoftInfoServiceImpl mesCustSoftInfoService;
@Autowired
private MesPartProdGroupWindowTimeRepository windowTimeRao;
@Override
public void doCreateBto(String organizeCode, List<String> groupCodeList) {
//1. 根据 organizeCode 和 groupCodeList 查询零件生产组
@ -49,12 +61,25 @@ public class MesBtoJobServiceImpl implements IMesBtoJobService {
List<String> custPartNoList = details.stream().map(MesPartProdGroupDetail::getCustPartNo).collect(Collectors.toList());
List<MesCustSortInfo> sortInfoList = mesCustSoftInfoService.queryCustSortInfoList(prodGroup.getCustCode(), prodGroup.getCustOrganizeCode(), prodGroup.getCustInfoPoint(), organizeCode, custPartNoList);
//6. 根据零件生产组的RoundnessType 去做策略,现在只做 窗口时间 策略; 入参
String roundnessService = MesExtEnumUtil.SHIPPING_GROUP_ROUND_METHOD.valueOfService(prodGroup.getRoundMethod());
if (sortInfoList.isEmpty()){
log.info("当前零件生产组:{}没有排序信息",prodGroup.getPartProdGroupName());
//如果圆整方式是按时圆整,且没有排序信息,更新窗口时间
try {
MesPartProdGroupWindowTime time = getWindowTimeByProductGroup(prodGroup.getId(), organizeCode);
if (time != null){
String lastRunTime = TimeTool.getNowTime(true);
log.info("当前零件生产组:{},更新本次执行时间:{},窗口时间为:{}",prodGroup.getPartProdGroupCode(),lastRunTime,time.getWindowTime());
ConvertBean.saveOrUpdate(time, "JOB");
time.setLastRunTime(lastRunTime);
windowTimeRao.update(time);
}
} catch (ParseException e) {
log.info("解析失败:{}",e.getMessage());
}
continue;
}
//6. 根据零件生产组的RoundnessType 去做策略,现在只做 窗口时间 策略; 入参
String roundnessService = MesExtEnumUtil.SHIPPING_GROUP_ROUND_METHOD.valueOfService(prodGroup.getRoundMethod());
IRoundnessStrategy roundnessStrategy = (IRoundnessStrategy)SpringContextsUtil.getBean(roundnessService);
roundnessStrategy.execute(prodGroup,sortInfoList, details);
}
@ -72,4 +97,50 @@ public class MesBtoJobServiceImpl implements IMesBtoJobService {
return null;
}
private MesPartProdGroupWindowTime getWindowTimeByProductGroup(Long partProdGroupId, String organizeCode) throws ParseException {
DdlPackBean windowTimPackBean = DdlPackBean.getDdlPackBean(organizeCode);
DdlPreparedPack.getNumEqualPack(partProdGroupId, "pid", windowTimPackBean);
List<MesPartProdGroupWindowTime> windowTimeList = windowTimeRao.findByHqlWhere(windowTimPackBean);
if (windowTimeList.isEmpty()) {
return null;
}
//获取当前时间的HH mm
Date now = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(now);
int hour = calendar.get(Calendar.HOUR_OF_DAY); // 获取小时24小时制
int minute = calendar.get(Calendar.MINUTE);
String nowTime = String.format("%02d:%02d", hour, minute);
//遍历窗口时间获取最新的窗口时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//使用降序
List<MesPartProdGroupWindowTime> sortedTime = windowTimeList.stream().sorted(Comparator.comparing(MesPartProdGroupWindowTime::getWindowTime,Comparator.reverseOrder())).collect(Collectors.toList());
for (MesPartProdGroupWindowTime time : sortedTime) {
if (Integer.parseInt(time.getWindowTime().replace(":", "")) > Integer.parseInt(nowTime.replace(":", ""))) {
continue;
}
calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time.getWindowTime().substring(0, 2)));
calendar.set(Calendar.MINUTE, Integer.parseInt(time.getWindowTime().substring(2, 4)));
calendar.set(Calendar.SECOND, 0);
Date dateCreateOrder = calendar.getTime();
if (Objects.isNull(time.getLastRunTime())) {
return time;
}
//校验lastRuntime 是否已经在当前圆整时区已经生成完了工单
Date lastRunTime = sdf.parse(time.getLastRunTime());
Calendar lastRunTimeCalendar = Calendar.getInstance();
lastRunTimeCalendar.setTime(lastRunTime);
lastRunTimeCalendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time.getWindowTime().substring(0, 2)));
lastRunTimeCalendar.set(Calendar.MINUTE, Integer.parseInt(time.getWindowTime().substring(2, 4)));
lastRunTimeCalendar.set(Calendar.SECOND, 1);
//两个相同的时间比较before返回值为false,把上次运行的时间格式化为窗口时间加1秒是过滤掉相等的情况
if (dateCreateOrder.before(lastRunTimeCalendar.getTime())) {
continue;
}
log.info("零件生产组详情id:{},本次运行时间:{},格式化后的上次运行时间:{},上次运行时间为:{}",partProdGroupId,sdf.format(dateCreateOrder),sdf.format(lastRunTimeCalendar.getTime()),time.getLastRunTime());
return time;
}
return null;
}
}

@ -75,7 +75,7 @@ public class MesTimeRoundnessService implements IRoundnessStrategy {
return;
}
String lastRunTime = TimeTool.getNowTime(true);
log.info("当前零件生产组:{},更新本次执行时间:{}",partProdGroup.getPartProdGroupName(),lastRunTime);
log.info("当前零件生产组:{},更新本次执行时间:{},窗口时间为:{}",partProdGroup.getPartProdGroupName(),lastRunTime,time.getWindowTime());
ConvertBean.saveOrUpdate(time, "JOB");
time.setLastRunTime(lastRunTime);
windowTimeRao.update(time);
@ -233,7 +233,9 @@ public class MesTimeRoundnessService implements IRoundnessStrategy {
// 保存工单
ConvertBean.saveOrUpdate(mesWorkOrder, "edi");
if (mesWorkOrder.getQty() > 0){
mesWorkOrderRao.insert(mesWorkOrder);
}
//更新 custSortInfo 状态已解析
for (MesCustSortInfo sortInfo : sortInfos) {
sortInfo.setServiceFlag(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue());
@ -273,15 +275,23 @@ public class MesTimeRoundnessService implements IRoundnessStrategy {
}
calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time.getWindowTime().substring(0, 2)));
calendar.set(Calendar.MINUTE, Integer.parseInt(time.getWindowTime().substring(2, 4)));
calendar.set(Calendar.SECOND, 0);
Date dateCreateOrder = calendar.getTime();
if (Objects.isNull(time.getLastRunTime())) {
return time;
}
//校验lastRuntime 是否已经在当前圆整时区已经生成完了工单
Date lastRunTime = sdf.parse(time.getLastRunTime());
if (dateCreateOrder.before(lastRunTime)) {
Calendar lastRunTimeCalendar = Calendar.getInstance();
lastRunTimeCalendar.setTime(lastRunTime);
lastRunTimeCalendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time.getWindowTime().substring(0, 2)));
lastRunTimeCalendar.set(Calendar.MINUTE, Integer.parseInt(time.getWindowTime().substring(2, 4)));
lastRunTimeCalendar.set(Calendar.SECOND, 1);
//两个相同的时间比较before返回值为false,把上次运行的时间格式化为窗口时间加1秒是过滤掉相等的情况
if (dateCreateOrder.before(lastRunTimeCalendar.getTime())) {
continue;
}
log.info("零件生产组详情id:{},本次运行时间:{},格式化后的上次运行时间:{},上次运行时间为:{}",partProdGroupId,sdf.format(dateCreateOrder),sdf.format(lastRunTimeCalendar.getTime()),time.getLastRunTime());
return time;
}
return null;

Loading…
Cancel
Save