| | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public void runningAllEquFaultStatistical(String dateTime) { |
| | | String validDate = LocalDate.now().minusDays(1).toString().replaceAll("-", ""); |
| | | Date initDate = null; |
| | | |
| | | if (StringUtils.isNotBlank(dateTime)) { |
| | | validDate = DateUtils.format(DateUtils.toDate(dateTime, DateUtils.STRDATE), DateUtils.STRDATE); |
| | | initDate = DateUtils.toDate(dateTime, DateUtils.STRDATE); |
| | | } else { |
| | | // 取最后的统计时间 |
| | | String date = this.baseMapper.getMaxStaticsData(); |
| | | if (date != null) { |
| | | initDate = DateUtils.toDate(date, DateUtils.STRDATE); |
| | | } else { |
| | | // 初次取值 取最早时间记录 |
| | | MdcEquipmentRunningSection equipmentRunningSection = mdcEquipmentRunningSectionService.getFirstRecord(); |
| | | if (equipmentRunningSection != null) { |
| | | initDate = equipmentRunningSection.getStartTime(); |
| | | } |
| | | } |
| | | } |
| | | Date endDate = DateUtils.addDays(DateUtils.getNow(), -1); |
| | | List<String> dateList = DateUtils.getDatesStringList2(initDate, endDate); |
| | | |
| | | if (dateList.isEmpty()) { |
| | | return; |
| | | } |
| | | try { |
| | | this.remove(new LambdaQueryWrapper<MdcEquipmentFaultInfo>().eq(MdcEquipmentFaultInfo::getTheDate, validDate)); |
| | | this.remove(new LambdaQueryWrapper<MdcEquipmentFaultInfo>().in(MdcEquipmentFaultInfo::getTheDate, dateList)); |
| | | } catch (Exception e) { |
| | | log.error("参数格式不对", e); |
| | | } |
| | |
| | | return; |
| | | } |
| | | |
| | | Map<String, MdcEquipmentFaultInfo> map = new HashMap<>(); |
| | | String finalValidDate = validDate; |
| | | equipmentList.forEach(equipment -> { |
| | | MdcEquipmentFaultInfo mdcEquipmentFaultInfo = new MdcEquipmentFaultInfo(equipment.getEquipmentid(), finalValidDate); |
| | | map.put(equipment.getEquipmentid(), mdcEquipmentFaultInfo); |
| | | }); |
| | | |
| | | String planTime = "00:00:00"; |
| | | MdcSystemParameters mdcSystemParameters = mdcSystemParametersService.getOne(new LambdaQueryWrapper<MdcSystemParameters>().eq(MdcSystemParameters::getCode, "equip_log_statis_time")); |
| | | if (mdcSystemParameters != null) { |
| | |
| | | } |
| | | |
| | | List<String> equipmentIdList = equipmentList.stream().map(Equipment::getEquipmentid).collect(Collectors.toList()); |
| | | String startTime = DateUtils.format(DateUtils.setTimeForDay(DateUtils.toDate(validDate, DateUtils.STRDATE), planTime), DateUtils.STR_DATE_TIME_SMALL); |
| | | Date start = DateUtils.toDate(startTime, DateUtils.STR_DATE_TIME_SMALL); |
| | | String endTime = DateUtils.format(DateUtils.addDays(DateUtils.toDate(startTime, DateUtils.STR_DATE_TIME_SMALL), 1), DateUtils.STR_DATE_TIME_SMALL); |
| | | Date end = DateUtils.toDate(endTime, DateUtils.STR_DATE_TIME_SMALL); |
| | | //查询故障记录 |
| | | List<EquFaultRecord> equFaultRecordList = this.baseMapper.findFaultRecord(equipmentIdList, startTime, endTime); |
| | | if (equFaultRecordList != null && !equFaultRecordList.isEmpty()) { |
| | | // 修整时间 |
| | | Map<String, List<EquFaultRecord>> equFaultRecordMap = equFaultRecordList.stream().collect(Collectors.groupingBy(EquFaultRecord::getEquipmentId)); |
| | | map.forEach((key, value1) -> { |
| | | MdcEquipmentFaultInfo equFaultRecords = value1; |
| | | if (equFaultRecordMap.containsKey(key)) { |
| | | List<EquFaultRecord> value = equFaultRecordMap.get(key); |
| | | long faultLong = calculateTotalFaultDuration(value, start, end); |
| | | equFaultRecords.setFaultLong((int) faultLong); |
| | | if (faultLong != 0) { |
| | | equFaultRecords.setFaultRate(new BigDecimal(faultLong).divide(new BigDecimal("864"), 2, RoundingMode.HALF_UP)); |
| | | } |
| | | // 计算去除故障时长的加工时间 |
| | | // step.1 查询加工时间 |
| | | List<MdcEquipmentRunningSection> mdcEquipmentRunningSections = mdcEquipmentRunningSectionService.listEquipmentRunningSectionRun(key, start.getTime(), end.getTime()); |
| | | if (mdcEquipmentRunningSections != null && !mdcEquipmentRunningSections.isEmpty()) { |
| | | // 时间修正 |
| | | if (mdcEquipmentRunningSections.get(0).getStartTime().before(start)) { |
| | | mdcEquipmentRunningSections.get(0).setStartTime(start); |
| | | |
| | | for (String validDate : dateList) { |
| | | Map<String, MdcEquipmentFaultInfo> map = new HashMap<>(); |
| | | String finalValidDate = validDate; |
| | | equipmentList.forEach(equipment -> { |
| | | MdcEquipmentFaultInfo mdcEquipmentFaultInfo = new MdcEquipmentFaultInfo(equipment.getEquipmentid(), finalValidDate); |
| | | map.put(equipment.getEquipmentid(), mdcEquipmentFaultInfo); |
| | | }); |
| | | |
| | | String startTime = DateUtils.format(DateUtils.setTimeForDay(DateUtils.toDate(validDate, DateUtils.STRDATE), planTime), DateUtils.STR_DATE_TIME_SMALL); |
| | | Date start = DateUtils.toDate(startTime, DateUtils.STR_DATE_TIME_SMALL); |
| | | String endTime = DateUtils.format(DateUtils.addDays(DateUtils.toDate(startTime, DateUtils.STR_DATE_TIME_SMALL), 1), DateUtils.STR_DATE_TIME_SMALL); |
| | | Date end = DateUtils.toDate(endTime, DateUtils.STR_DATE_TIME_SMALL); |
| | | //查询故障记录 |
| | | List<EquFaultRecord> equFaultRecordList = this.baseMapper.findFaultRecord(equipmentIdList, startTime, endTime); |
| | | if (equFaultRecordList != null && !equFaultRecordList.isEmpty()) { |
| | | // 修整时间 |
| | | Map<String, List<EquFaultRecord>> equFaultRecordMap = equFaultRecordList.stream().collect(Collectors.groupingBy(EquFaultRecord::getEquipmentId)); |
| | | map.forEach((key, value1) -> { |
| | | MdcEquipmentFaultInfo equFaultRecords = value1; |
| | | if (equFaultRecordMap.containsKey(key)) { |
| | | List<EquFaultRecord> value = equFaultRecordMap.get(key); |
| | | long faultLong = calculateTotalFaultDuration(value, start, end); |
| | | equFaultRecords.setFaultLong((int) faultLong); |
| | | if (faultLong != 0) { |
| | | equFaultRecords.setFaultRate(new BigDecimal(faultLong).divide(new BigDecimal("864"), 2, RoundingMode.HALF_UP)); |
| | | } |
| | | if (mdcEquipmentRunningSections.size() > 1) { |
| | | if (mdcEquipmentRunningSections.get(mdcEquipmentRunningSections.size() - 1).getEndTime().after(end)) { |
| | | mdcEquipmentRunningSections.get(mdcEquipmentRunningSections.size() - 1).setEndTime(end); |
| | | // 计算去除故障时长的加工时间 |
| | | // step.1 查询加工时间 |
| | | List<MdcEquipmentRunningSection> mdcEquipmentRunningSections = mdcEquipmentRunningSectionService.listEquipmentRunningSectionRun(key, start.getTime(), end.getTime()); |
| | | if (mdcEquipmentRunningSections != null && !mdcEquipmentRunningSections.isEmpty()) { |
| | | // 时间修正 |
| | | if (mdcEquipmentRunningSections.get(0).getStartTime().before(start)) { |
| | | mdcEquipmentRunningSections.get(0).setStartTime(start); |
| | | } |
| | | } else { |
| | | if (mdcEquipmentRunningSections.get(0).getEndTime().after(end)) { |
| | | mdcEquipmentRunningSections.get(0).setEndTime(end); |
| | | if (mdcEquipmentRunningSections.size() > 1) { |
| | | if (mdcEquipmentRunningSections.get(mdcEquipmentRunningSections.size() - 1).getEndTime().after(end)) { |
| | | mdcEquipmentRunningSections.get(mdcEquipmentRunningSections.size() - 1).setEndTime(end); |
| | | } |
| | | } else { |
| | | if (mdcEquipmentRunningSections.get(0).getEndTime().after(end)) { |
| | | mdcEquipmentRunningSections.get(0).setEndTime(end); |
| | | } |
| | | } |
| | | List<MdcEquipmentRunningSection> collect = mdcEquipmentRunningSections.stream().filter(mdcEquipmentRunningSection -> mdcEquipmentRunningSection.getStatus() == 3).collect(Collectors.toList()); |
| | | if (!collect.isEmpty()) { |
| | | // step.2 计算去除故障时长的加工时间 |
| | | long processingTime = calculateProcessingTimeWithoutFaults(collect, value, start, end); |
| | | equFaultRecords.setRemoveFaultRunLong((int) processingTime); |
| | | if (faultLong != 0 && faultLong != 86400) { |
| | | // 计算去除故障时长的利用率 |
| | | BigDecimal removeFaultRate = new BigDecimal(processingTime).divide(new BigDecimal("864").subtract(new BigDecimal(faultLong)), 2, RoundingMode.HALF_UP); |
| | | equFaultRecords.setRemoveFaultRate(removeFaultRate); |
| | | } |
| | | } |
| | | } |
| | | List<MdcEquipmentRunningSection> collect = mdcEquipmentRunningSections.stream().filter(mdcEquipmentRunningSection -> mdcEquipmentRunningSection.getStatus() == 3).collect(Collectors.toList()); |
| | | if (!collect.isEmpty()) { |
| | | // step.2 计算去除故障时长的加工时间 |
| | | long processingTime = calculateProcessingTimeWithoutFaults(collect, value, start, end); |
| | | equFaultRecords.setRemoveFaultRunLong((int) processingTime); |
| | | if (faultLong != 0 && faultLong != 86400) { |
| | | } else { |
| | | List<MdcEquipmentRunningSection> mdcEquipmentRunningSections = mdcEquipmentRunningSectionService.listEquipmentRunningSectionRun(key, start.getTime(), end.getTime()); |
| | | if (mdcEquipmentRunningSections != null && !mdcEquipmentRunningSections.isEmpty()) { |
| | | // 时间修正 |
| | | if (mdcEquipmentRunningSections.get(0).getStartTime().before(start)) { |
| | | mdcEquipmentRunningSections.get(0).setStartTime(start); |
| | | } |
| | | if (mdcEquipmentRunningSections.size() > 1) { |
| | | if (mdcEquipmentRunningSections.get(mdcEquipmentRunningSections.size() - 1).getEndTime().after(end)) { |
| | | mdcEquipmentRunningSections.get(mdcEquipmentRunningSections.size() - 1).setEndTime(end); |
| | | } |
| | | } else { |
| | | if (mdcEquipmentRunningSections.get(0).getEndTime().after(end)) { |
| | | mdcEquipmentRunningSections.get(0).setEndTime(end); |
| | | } |
| | | } |
| | | List<MdcEquipmentRunningSection> collect = mdcEquipmentRunningSections.stream().filter(mdcEquipmentRunningSection -> mdcEquipmentRunningSection.getStatus() == 3).collect(Collectors.toList()); |
| | | |
| | | if (!collect.isEmpty()) { |
| | | long totalProcessingTime = 0; |
| | | for (MdcEquipmentRunningSection mdcEquipmentRunningSection : collect) { |
| | | totalProcessingTime += ChronoUnit.SECONDS.between(DateUtils.convertToLocalDateTime(mdcEquipmentRunningSection.getStartTime()), DateUtils.convertToLocalDateTime(mdcEquipmentRunningSection.getEndTime())); |
| | | } |
| | | equFaultRecords.setRemoveFaultRunLong((int) totalProcessingTime); |
| | | // 计算去除故障时长的利用率 |
| | | BigDecimal removeFaultRate = new BigDecimal(processingTime).divide(new BigDecimal("864").subtract(new BigDecimal(faultLong)), 2, RoundingMode.HALF_UP); |
| | | BigDecimal removeFaultRate = new BigDecimal(totalProcessingTime).divide(new BigDecimal("864"), 2, RoundingMode.HALF_UP); |
| | | equFaultRecords.setRemoveFaultRate(removeFaultRate); |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | List<MdcEquipmentRunningSection> mdcEquipmentRunningSections = mdcEquipmentRunningSectionService.listEquipmentRunningSectionRun(key, start.getTime(), end.getTime()); |
| | | if (mdcEquipmentRunningSections != null && !mdcEquipmentRunningSections.isEmpty()) { |
| | | // 时间修正 |
| | | if (mdcEquipmentRunningSections.get(0).getStartTime().before(start)) { |
| | | mdcEquipmentRunningSections.get(0).setStartTime(start); |
| | | } |
| | | if (mdcEquipmentRunningSections.size() > 1) { |
| | | if (mdcEquipmentRunningSections.get(mdcEquipmentRunningSections.size() - 1).getEndTime().after(end)) { |
| | | mdcEquipmentRunningSections.get(mdcEquipmentRunningSections.size() - 1).setEndTime(end); |
| | | } |
| | | } else { |
| | | if (mdcEquipmentRunningSections.get(0).getEndTime().after(end)) { |
| | | mdcEquipmentRunningSections.get(0).setEndTime(end); |
| | | } |
| | | } |
| | | List<MdcEquipmentRunningSection> collect = mdcEquipmentRunningSections.stream().filter(mdcEquipmentRunningSection -> mdcEquipmentRunningSection.getStatus() == 3).collect(Collectors.toList()); |
| | | |
| | | if (!collect.isEmpty()) { |
| | | long totalProcessingTime = 0; |
| | | for (MdcEquipmentRunningSection mdcEquipmentRunningSection : collect) { |
| | | totalProcessingTime += ChronoUnit.SECONDS.between(DateUtils.convertToLocalDateTime(mdcEquipmentRunningSection.getStartTime()), DateUtils.convertToLocalDateTime(mdcEquipmentRunningSection.getEndTime())); |
| | | } |
| | | equFaultRecords.setRemoveFaultRunLong((int) totalProcessingTime); |
| | | // 计算去除故障时长的利用率 |
| | | BigDecimal removeFaultRate = new BigDecimal(totalProcessingTime).divide(new BigDecimal("864"), 2, RoundingMode.HALF_UP); |
| | | equFaultRecords.setRemoveFaultRate(removeFaultRate); |
| | | } |
| | | } |
| | | } |
| | | map.put(key, equFaultRecords); |
| | | }); |
| | | } |
| | | if (!map.isEmpty()) { |
| | | this.saveBatch(new ArrayList<>(map.values())); |
| | | map.put(key, equFaultRecords); |
| | | }); |
| | | } |
| | | if (!map.isEmpty()) { |
| | | this.saveBatch(new ArrayList<>(map.values())); |
| | | } |
| | | } |
| | | } |
| | | |