| | |
| | | import org.jeecg.modules.mdc.service.*; |
| | | import org.jeecg.modules.mdc.util.DateUtils; |
| | | import org.jeecg.modules.mdc.util.TimeFieldUtils; |
| | | import org.jeecg.modules.mdc.vo.EquFaultRecord; |
| | | import org.jeecg.modules.mdc.vo.MdcAlarmAnalyzeQueryVo; |
| | | import org.jeecg.modules.mdc.vo.MdcEquipmentRunningSectionVo; |
| | | import org.jeecg.modules.mdc.vo.TimeInterval; |
| | | import org.jeecg.modules.system.service.ISysDictService; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @Description: 设备运行时段状态表 |
| | |
| | | List<MdcEquipmentRunningSection> running = loadEquipmentRunningTrace(equipmentRunningSectionVo.getEquipmentId(), equipmentRunningSectionVo.getCollectTimeStr()); |
| | | //查询报警数据 |
| | | List<MdcEquipmentRunningSection> errs = loadEquipmentErrorTrace(equipmentRunningSectionVo.getEquipmentId(), equipmentRunningSectionVo.getCollectTimeStr()); |
| | | //查询故障数据 |
| | | List<MdcEquipmentRunningSection> faults = loadEquipmentFaultTrace(equipmentRunningSectionVo.getEquipmentId(), equipmentRunningSectionVo.getCollectTimeStr()); |
| | | Equipment equip = equipmentService.getOne(new LambdaQueryWrapper<Equipment>().eq(Equipment::getEquipmentid, equipmentRunningSectionVo.getEquipmentId())); |
| | | if (!running.isEmpty()) { |
| | | MdcEquipmentRunningSectionDto dto; |
| | |
| | | dto = new MdcEquipmentRunningSectionDto(); |
| | | BeanUtils.copyProperties(entity, dto); |
| | | if (entity.getStatus() == 3 && StringUtils.isBlank(entity.getSequenceNumber()) && isTableExist && !"ZUOLAN".equals(equip.getDrivetype())) { |
| | | List<EquipmentMachingDto> esList = equipmentWorkLineService.getEquipmentSequencenumber(tableName, entity.getStartTime(), entity.getEndTime()); |
| | | if (esList != null && esList.size() > 1) { |
| | | dto.setSequenceNumber(esList.get(0).getSequencenumber()); |
| | | //FANUC获取程序名特殊处理 |
| | | if (equip.getDrivetype().startsWith("FANUC")) { |
| | | List<EquipmentMachingDto> esList = equipmentWorkLineService.getEquipProgramNum(equip.getDrivetype(), equip.getEquipmentid(), |
| | | entity.getStartTime(), entity.getEndTime()); |
| | | if (esList != null && esList.size() > 1) { |
| | | dto.setSequenceNumber(esList.get(0).getProductName()); |
| | | } |
| | | }else { |
| | | List<EquipmentMachingDto> esList = equipmentWorkLineService.getEquipmentSequencenumber(tableName, entity.getStartTime(), entity.getEndTime()); |
| | | if (esList != null && esList.size() > 1) { |
| | | dto.setSequenceNumber(esList.get(0).getSequencenumber()); |
| | | } |
| | | } |
| | | } |
| | | dtos.add(dto); |
| | |
| | | BeanUtils.copyProperties(entity, dto); |
| | | if (entity.getStatus() == 22) { |
| | | if (equip != null) { |
| | | List<MdcAlarmInfo> mdcAlarmInfo = mdcAlarmInfoService.list(new LambdaQueryWrapper<MdcAlarmInfo>().eq(MdcAlarmInfo::getDriveType, equip.getDrivetype()).eq(MdcAlarmInfo::getAlarmCode, entity.getAlarm()).eq(MdcAlarmInfo::getIsUse, 0)); |
| | | if (mdcAlarmInfo != null && !mdcAlarmInfo.isEmpty()) { |
| | | dto.setAlarmContent(mdcAlarmInfo.get(0).getAlarmContent()); |
| | | Optional<TmpEquipmentAlarm> tmpEquipmentAlarm = entity.getTmpEquipmentAlarmSet().stream().findFirst(); |
| | | if (tmpEquipmentAlarm.isPresent() && StringUtils.isNotBlank(tmpEquipmentAlarm.get().getAlarmContent())) { |
| | | dto.setAlarmContent(tmpEquipmentAlarm.get().getAlarmContent()); |
| | | }else { |
| | | List<MdcAlarmInfo> mdcAlarmInfo = mdcAlarmInfoService.list(new LambdaQueryWrapper<MdcAlarmInfo>().eq(MdcAlarmInfo::getDriveType, equip.getDrivetype()).eq(MdcAlarmInfo::getAlarmCode, entity.getAlarm()).eq(MdcAlarmInfo::getIsUse, 0)); |
| | | if (mdcAlarmInfo != null && !mdcAlarmInfo.isEmpty()) { |
| | | dto.setAlarmContent(mdcAlarmInfo.get(0).getAlarmContent()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // Set<TmpEquipmentAlarm> set = entity.getTmpEquipmentAlarmSet(); |
| | | // if (entity.getStatus() == 22 && set != null && !set.isEmpty()) { |
| | | // Iterator<TmpEquipmentAlarm> iterator = entity.getTmpEquipmentAlarmSet().iterator(); |
| | | // //获取报警编号相同的报警信息 |
| | | // while (iterator.hasNext()) { |
| | | // TmpEquipmentAlarm next = iterator.next(); |
| | | // if (StringUtils.isNotBlank(next.getAlarmNo()) && next.getAlarmNo().equals(entity.getStatus())) { |
| | | // dto.setAlarmContent(next.getAlarmContent()); |
| | | // } |
| | | // } |
| | | // } |
| | | dtos.add(dto); |
| | | } |
| | | } |
| | | |
| | | List<MdcEquipmentRunningSectionDto> result = new ArrayList<>(); |
| | | |
| | | //合并相同状态数据 |
| | | for (int i = 0; i < dtos.size() - 1; i++) { |
| | | MdcEquipmentRunningSectionDto mdcEquipmentRunningSectionDto = dtos.get(i); |
| | |
| | | result.addAll(dtos); |
| | | } |
| | | |
| | | if (faults != null && !faults.isEmpty()) { |
| | | MdcEquipmentRunningSectionDto dto; |
| | | for (MdcEquipmentRunningSection entity : faults) { |
| | | dto = new MdcEquipmentRunningSectionDto(); |
| | | BeanUtils.copyProperties(entity, dto); |
| | | result.add(dto); |
| | | } |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | private List<MdcEquipmentRunningSection> loadEquipmentFaultTrace(String equipmentId, String collectTimeStr) { |
| | | List<MdcEquipmentRunningSection> result = new ArrayList<>(); |
| | | Date startTime = DateUtils.getShortDate(collectTimeStr); |
| | | Date now = DateUtils.removeTime(DateUtils.getNow()); |
| | | long second = DateUtils.differentSecond(startTime, now); |
| | | Date endTime = DateUtils.plusTime(startTime, 1); |
| | | if (collectTimeStr.equals(LocalDate.now().toString())) { |
| | | endTime = DateUtils.getNow(); |
| | | } |
| | | if (second < 0) { |
| | | return Collections.emptyList(); |
| | | } else { |
| | | List<EquFaultRecord> equFaultRecordList = this.baseMapper.findFaultList(equipmentId, startTime, endTime); |
| | | if (equFaultRecordList != null && !equFaultRecordList.isEmpty()) { |
| | | |
| | | // 修正记录时间 |
| | | List<EquFaultRecord> correctedRecords = correctRecordTimes(equFaultRecordList, DateUtils.convertToLocalDateTime(startTime), DateUtils.convertToLocalDateTime(endTime)); |
| | | |
| | | // 按开始时间排序 |
| | | correctedRecords.sort(Comparator.comparing(EquFaultRecord::getStartTime)); |
| | | |
| | | // 合并重叠时间段 |
| | | List<TimeInterval> mergedIntervals = mergeIntervals(correctedRecords); |
| | | |
| | | for (TimeInterval mergedInterval : mergedIntervals) { |
| | | MdcEquipmentRunningSection mdcEquipmentRunningSection = new MdcEquipmentRunningSection(25, equipmentId, DateUtils.convertToDate(mergedInterval.getStart()), DateUtils.convertToDate(mergedInterval.getEnd()), DateUtils.convertToDate(mergedInterval.getStart()).getTime(), DateUtils.convertToDate(mergedInterval.getEnd()).getTime()); |
| | | mdcEquipmentRunningSection.setDuration(DateUtils.differentSecond(mdcEquipmentRunningSection.getStartTime(), mdcEquipmentRunningSection.getEndTime())); |
| | | result.add(mdcEquipmentRunningSection); |
| | | } |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private static List<EquFaultRecord> correctRecordTimes(List<EquFaultRecord> records, LocalDateTime startTime, LocalDateTime endTime) { |
| | | return records.stream() |
| | | .map(record -> { |
| | | LocalDateTime recordStart = DateUtils.convertToLocalDateTime(record.getStartTime()); |
| | | LocalDateTime recordEnd = record.getEndTime() != null ? |
| | | DateUtils.convertToLocalDateTime(record.getEndTime()) : null; |
| | | |
| | | // 修正开始时间 |
| | | LocalDateTime correctedStart = recordStart.isBefore(startTime) ? |
| | | startTime : recordStart; |
| | | |
| | | // 修正结束时间 |
| | | LocalDateTime correctedEnd = recordEnd == null || recordEnd.isAfter(endTime) ? |
| | | endTime : recordEnd; |
| | | |
| | | // 创建修正后的记录 |
| | | return new EquFaultRecord( |
| | | record.getEquipmentId(), |
| | | DateUtils.convertToDate(correctedStart), |
| | | DateUtils.convertToDate(correctedEnd) |
| | | ); |
| | | }) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | private static List<TimeInterval> mergeIntervals(List<EquFaultRecord> records) { |
| | | List<TimeInterval> intervals = records.stream() |
| | | .map(record -> new TimeInterval( |
| | | DateUtils.convertToLocalDateTime(record.getStartTime()), |
| | | DateUtils.convertToLocalDateTime(record.getEndTime()))) |
| | | .collect(Collectors.toList()); |
| | | |
| | | if (intervals.isEmpty()) { |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | List<TimeInterval> merged = new ArrayList<>(); |
| | | TimeInterval current = intervals.get(0); |
| | | |
| | | for (int i = 1; i < intervals.size(); i++) { |
| | | TimeInterval next = intervals.get(i); |
| | | if (next.getStart().isBefore(current.getEnd()) || next.getStart().equals(current.getEnd())) { |
| | | // 有重叠,合并区间 |
| | | current.setEnd(current.getEnd().isAfter(next.getEnd()) ? current.getEnd() : next.getEnd()); |
| | | } else { |
| | | // 无重叠,添加当前区间并更新当前区间 |
| | | merged.add(current); |
| | | current = next; |
| | | } |
| | | } |
| | | merged.add(current); // 添加最后一个区间 |
| | | |
| | | return merged; |
| | | } |
| | | |
| | | /** |
| | |
| | | queryWrapper.le(MdcEquipmentRunningSection::getStartTime, endTime); |
| | | queryWrapper.orderByAsc(MdcEquipmentRunningSection::getStartTime); |
| | | list = this.baseMapper.selectList(queryWrapper); |
| | | |
| | | list = mergeErrorRunningTrace(list); |
| | | |
| | | } |
| | | if (list == null || list.isEmpty()) { |
| | | return Collections.emptyList(); |
| | |
| | | //获取running运行的日志记录 |
| | | List<MdcEquipmentRunningSection> list = this.equipmentRunningTracesLog(equipment.getEquipmentid()); |
| | | if (list != null && !list.isEmpty()) { |
| | | // List<MdcEquipmentRunningSection> equipList = addSequenceNumber(list); //添加程序号 |
| | | this.ergodicTrim(list); |
| | | super.saveBatch(list); |
| | | List<MdcEquipmentRunningSection> equipList = addSequenceNumber(list); //添加程序号 |
| | | this.ergodicTrim(equipList); |
| | | super.saveBatch(equipList); |
| | | } |
| | | //获取报警的日志记录 |
| | | List<MdcEquipmentRunningSection> errorList = this.equipmentRunningTracesErrorLog(equipment.getEquipmentid()); |
| | |
| | | List<EquipmentMachingDto> esList = equipmentWorkLineService.getEquipProgramNum(equip.getDrivetype(), equip.getEquipmentid(), |
| | | e.getStartTime(), e.getEndTime()); |
| | | if (esList != null && esList.size() > 1) { |
| | | e.setSequenceNumber(esList.get(0).getProgramnumber()); |
| | | e.setSequenceNumber(esList.get(0).getProductName()); |
| | | } |
| | | } else if (StringUtils.isNotBlank(equip.getDrivetype()) && equip.getDrivetype().startsWith("SIEMENS")) { |
| | | List<EquipmentMachingDto> esList = equipmentWorkLineService.getEquipmentSequencenumber(equip.getDrivetype() + "_" + equip.getEquipmentid(), e.getStartTime(), e.getEndTime()); |
| | |
| | | return this.baseMapper.findWaitList(date); |
| | | } |
| | | |
| | | @Override |
| | | public MdcEquipmentRunningSection getFirstRecord() { |
| | | return this.baseMapper.getFirstRecord(); |
| | | } |
| | | |
| | | private Map<String, List<MdcEquipmentRunningSectionDto>> logCharts(MdcEquipmentRunningSectionVo equipmentRunningSectionVo, String date) { |
| | | Map<String, List<MdcEquipmentRunningSectionDto>> map = new HashMap<>(); |
| | | List<MdcEquipmentRunningSectionDto> normal = new ArrayList<>(); |