diff --git a/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/controller/busi/MesWhiteListController.java b/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/controller/busi/MesWhiteListController.java index da6ffbd..d1e9bc1 100644 --- a/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/controller/busi/MesWhiteListController.java +++ b/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/controller/busi/MesWhiteListController.java @@ -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 partInspectionList = new ArrayList<>(); - //排序取未同步的一条最早的 - Map> partMap = mesPartInspectionList.stream().collect(Collectors.groupingBy(p -> p.getSn() + "-" + p.getPartNo())); - for (Map.Entry> stringListEntry : partMap.entrySet()) { + //排序取单件逻辑未同步的一条最新的 + Map> partSnMap = mesPartInspectionList.stream() + .filter(p -> p.getSourceType() == 10) + .collect(Collectors.groupingBy(p -> p.getSn() + "-" + p.getPartNo())); + for (Map.Entry> stringListEntry : partSnMap.entrySet()) { List value = stringListEntry.getValue(); MesPartInspection next = value.stream().sorted(Comparator.comparing(MesPartInspection::getCreateDatetime).reversed()).iterator().next(); partInspectionList.add(next); } - + //批次逻辑的全部汇总数量 42692 MES:可疑品汇总逻辑更新 + Map> partMap = mesPartInspectionList.stream() + .filter(p -> p.getSourceType() == 20) + .collect(Collectors.groupingBy(MesPartInspection::getPartNo)); + for (Map.Entry> 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); } diff --git a/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/serviceimpl/base/MesQmsSuspiciousService.java b/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/serviceimpl/base/MesQmsSuspiciousService.java index 86aca2b..9f07d23 100644 --- a/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/serviceimpl/base/MesQmsSuspiciousService.java +++ b/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/serviceimpl/base/MesQmsSuspiciousService.java @@ -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 im for (MesPartInspection partInspection : mesPartInspectionsList) { MesPartInspection partInspectionNew = new MesPartInspection(); BeanUtils.copyProperties(partInspection, partInspectionNew); - //去创建日期换算整点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()) { - qmsTime = partInspectionDao.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.getSn(), "sn", packBeanNew); + packBeanNew.setOrderByStr(" order by createDatetime "); + MesPartInspection partInspectionDao = partInspectionRepository.getByProperty(packBeanNew); + //如果是最新的 + 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 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); + } + } + + } + + } } - partInspectionNew.setInspectionDate(qmsTime); - mesPartInspectionsListTime.add(partInspectionNew); } //根据时间分组发送 // 批次的: