42692 MES:可疑品汇总逻辑更新

tags/yfai-mes-ext-v1.7
gsz 9 months ago
parent 19eea2b97e
commit 8e1461d066

@ -203,6 +203,13 @@ public class MesWhiteListController extends MesBaseController {
@ApiOperation(value = "qmsSuspicious", notes = " ")
public ResultBean doQmsSuspiciousTest(String organizeCode) {
DdlPackBean packBean = DdlPackBean.getDdlPackBean(organizeCode);
//按天执行前一天的所有可疑记录
//按小时 条码+物料出现过一次 就排除当前时间段
// DdlPreparedPack.getNumEqualPack(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), "systemSyncStatus", packBean);
// DdlPreparedPack.timeBuilder(
// new SimpleDateFormat("yyyy-MM-dd").format(TimeTool.getDateBefore(new Date(), 1)) + " 00:00:00",
// TimeTool.getToday() + " 00:00:00", "createDatetime", packBean, true);
// 获取当前时间前1小时的时间
LocalDateTime now = LocalDateTime.now();
LocalDateTime oneHourAgo = now.minusHours(1);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@ -215,20 +222,29 @@ public class MesWhiteListController extends MesBaseController {
if (!CollectionUtils.isEmpty(mesPartInspectionList)) {
//过滤掉已经汇总的
List<MesPartInspection> partInspectionList = new ArrayList<>();
//排序取未同步的一条最早的
Map<String, List<MesPartInspection>> partMap = mesPartInspectionList.stream().collect(Collectors.groupingBy(p -> p.getSn() + "-" + p.getPartNo()));
for (Map.Entry<String, List<MesPartInspection>> stringListEntry : partMap.entrySet()) {
//排序取单件逻辑未同步的一条最新的
Map<String, List<MesPartInspection>> partSnMap = mesPartInspectionList.stream()
.filter(p -> p.getSourceType() == 10)
.collect(Collectors.groupingBy(p -> p.getSn() + "-" + p.getPartNo()));
for (Map.Entry<String, List<MesPartInspection>> stringListEntry : partSnMap.entrySet()) {
List<MesPartInspection> value = stringListEntry.getValue();
MesPartInspection next = value.stream().sorted(Comparator.comparing(MesPartInspection::getCreateDatetime).reversed()).iterator().next();
partInspectionList.add(next);
}
//批次逻辑的全部汇总数量 42692 MES:可疑品汇总逻辑更新
Map<String, List<MesPartInspection>> partMap = mesPartInspectionList.stream()
.filter(p -> p.getSourceType() == 20)
.collect(Collectors.groupingBy(MesPartInspection::getPartNo));
for (Map.Entry<String, List<MesPartInspection>> stringListEntry : partMap.entrySet()) {
partInspectionList.addAll(stringListEntry.getValue());
}
LOGGER.info("MES可疑品汇总 ----- partInspectionList{}", partInspectionList.size());
qmsSuspiciousService.doQmsSuspiciousByPartInspection(partInspectionList, organizeCode);
for (MesPartInspection mesPartInspection : mesPartInspectionList) {
mesPartInspection.setQmsSync(1);
mesPartInspection.setSystemSyncDatetime(TimeTool.getNowTime(true));
ConvertBean.serviceModelUpdate(mesPartInspection, MesExtConstWords.JOB);
}
partInspectionRepository.saveAll(mesPartInspectionList);
}

@ -18,7 +18,10 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -69,19 +72,61 @@ public class MesQmsSuspiciousService extends BaseMesService<MesQmsSuspicious> im
for (MesPartInspection partInspection : mesPartInspectionsList) {
MesPartInspection partInspectionNew = new MesPartInspection();
BeanUtils.copyProperties(partInspection, partInspectionNew);
String qmsTime = partInspection.getCreateDatetime().substring(0, 13) + ":00:00";
if (partInspection.getSourceType() == MesExtEnumUtil.PART_INSPECTION_SOURCE_TYPE.LOT.getValue()) {
partInspectionNew.setInspectionDate(qmsTime);
mesPartInspectionsListTime.add(partInspectionNew);
} else {
//检验日期年月日可以根据创建日期截取,批次的不用取最早出现的
//去创建日期换算整点2024-07-25 10:00:00
DdlPackBean packBeanNew = DdlPackBean.getDdlPackBean(organizeCode);
DdlPreparedPack.getStringEqualPack(partInspection.getPartNo(), "partNo", packBeanNew);
DdlPreparedPack.getStringEqualPack(partInspection.getSn(), "sn", packBeanNew);
packBeanNew.setOrderByStr(" order by createDatetime ");
MesPartInspection partInspectionDao = partInspectionRepository.getByProperty(packBeanNew);
//检验日期年月日可以根据创建日期截取,批次的不用取最早出现的
String qmsTime = partInspection.getCreateDatetime().substring(0, 13) + ":00:00";
if (!StringUtil.isEmpty(partInspectionDao) && partInspection.getSourceType() == MesExtEnumUtil.PART_INSPECTION_SOURCE_TYPE.SINGLE.getValue()) {
//如果是最新的
if (!StringUtil.isEmpty(partInspectionDao) && partInspectionDao.getCreateDatetime().substring(0, 13).equals(partInspection.getCreateDatetime().substring(0, 13))) {
qmsTime = partInspectionDao.getCreateDatetime().substring(0, 13) + ":00:00";
}
partInspectionNew.setInspectionDate(qmsTime);
mesPartInspectionsListTime.add(partInspectionNew);
} else {
qmsTime = partInspectionDao.getCreateDatetime().substring(0, 13) + ":00:00";
partInspectionNew.setInspectionDate(qmsTime);
mesPartInspectionsListTime.add(partInspectionNew);
//如果第二次出现 找条码最早时间区间内 的非该条码 的 物料 集合
//获取最早条码创建时间 后一小时的时间
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime nextHourDateTime = LocalDateTime.parse(partInspectionDao.getCreateDatetime(), formatter).plusHours(1);
String afterQmsTime = nextHourDateTime.format(formatter);
DdlPackBean packBeanPart = DdlPackBean.getDdlPackBean(organizeCode);
DdlPreparedPack.getStringEqualPack(partInspectionDao.getPartNo(), "partNo", packBeanPart);
DdlPreparedPack.getNotInPack(partInspectionDao.getSn(), "sn", packBeanPart);
DdlPreparedPack.timeBuilder(partInspectionDao.getCreateDatetime(), afterQmsTime, "createDatetime", packBeanPart, true);
List<MesPartInspection> mesPartInspections = partInspectionRepository.findByHqlWhere(packBeanPart);
if (!CollectionUtils.isEmpty(mesPartInspections)) {
//排除其他非最早出现的条码
for (MesPartInspection mesPartInspection : mesPartInspections) {
MesPartInspection partInspectionNew2 = new MesPartInspection();
BeanUtils.copyProperties(mesPartInspection, partInspectionNew2);
qmsTime = mesPartInspection.getCreateDatetime().substring(0, 13) + ":00:00";
partInspectionNew2.setInspectionDate(qmsTime);
if (mesPartInspection.getSourceType()==10){
//如果条码重复出现时,对应最早时间段的零件不是最早,则不统计在汇总数据中
DdlPackBean packBeanSn = DdlPackBean.getDdlPackBean(organizeCode);
DdlPreparedPack.getStringEqualPack(mesPartInspection.getSn(), "sn", packBeanSn);
packBeanSn.setOrderByStr(" order by createDatetime ");
MesPartInspection partInspectionSn = partInspectionRepository.getByProperty(packBeanSn);
if (!StringUtil.isEmpty(partInspectionSn)&& partInspectionSn.getCreateDatetime().substring(0, 13).equals(mesPartInspection.getCreateDatetime().substring(0, 13))){
mesPartInspectionsListTime.add(partInspectionNew2);
}
}else {
mesPartInspectionsListTime.add(partInspectionNew2);
}
}
}
}
}
}
//根据时间分组发送
// 批次的:

Loading…
Cancel
Save