¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.mdc.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.jeecg.common.system.vo.DictModel; |
| | | import org.jeecg.modules.mdc.dto.EquipmentMachingDto; |
| | | import org.jeecg.modules.mdc.dto.MdcAlarmListDto; |
| | | import org.jeecg.modules.mdc.dto.MdcEquipmentRunningSectionDto; |
| | | import org.jeecg.modules.mdc.dto.MdcEquipmentWaitSectionDto; |
| | | import org.jeecg.modules.mdc.entity.*; |
| | | import org.jeecg.modules.mdc.mapper.MdcEquipmentRunningSectionMapper; |
| | | 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: 设å¤è¿è¡æ¶æ®µç¶æè¡¨ |
| | | * @Author: LiuS |
| | | * @Date: 2023-04-13 |
| | | * @Version: V1.0 |
| | | */ |
| | | @Service |
| | | public class MdcEquipmentRunningSectionServiceImpl extends ServiceImpl<MdcEquipmentRunningSectionMapper, MdcEquipmentRunningSection> implements IMdcEquipmentRunningSectionService { |
| | | |
| | | @Resource |
| | | private IEquipmentService equipmentService; |
| | | |
| | | @Resource |
| | | private IEquipmentLogService equipmentLogService; |
| | | |
| | | @Resource |
| | | private IEquipmentAlarmService equipmentAlarmService; |
| | | |
| | | @Resource |
| | | private IEquipmentWorkLineService equipmentWorkLineService; |
| | | |
| | | @Resource |
| | | private ISysDictService sysDictService; |
| | | |
| | | @Resource |
| | | private IEquipmentRunningTraceService equipmentRunningTraceService; |
| | | |
| | | @Resource |
| | | private IMdcAlarmInfoService mdcAlarmInfoService; |
| | | |
| | | @Override |
| | | public List<MdcEquipmentRunningSectionDto> logList(MdcEquipmentRunningSectionVo equipmentRunningSectionVo) { |
| | | |
| | | if (StringUtils.isBlank(equipmentRunningSectionVo.getCollectTimeStr()) || StringUtils.isBlank(equipmentRunningSectionVo.getEquipmentId())) { |
| | | return null; |
| | | } |
| | | List<MdcEquipmentRunningSectionDto> dtos = new ArrayList<>(); |
| | | //æ¥è¯¢è¿è¡æ°æ® |
| | | 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; |
| | | String tableName = ""; |
| | | Boolean isTableExist = false; |
| | | if (equip != null) { |
| | | if (StringUtils.isNotBlank(equip.getDrivetype())) { |
| | | tableName = equip.getDrivetype() + "_" + equip.getEquipmentid(); |
| | | isTableExist = equipmentWorkLineService.isTableExist(tableName); |
| | | } |
| | | } |
| | | for (MdcEquipmentRunningSection entity : running) { |
| | | 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()); |
| | | } |
| | | } |
| | | dtos.add(dto); |
| | | } |
| | | } |
| | | if (!errs.isEmpty()) { |
| | | MdcEquipmentRunningSectionDto dto; |
| | | for (MdcEquipmentRunningSection entity : errs) { |
| | | dto = new MdcEquipmentRunningSectionDto(); |
| | | 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()); |
| | | } |
| | | } |
| | | } |
| | | dtos.add(dto); |
| | | } |
| | | } |
| | | |
| | | List<MdcEquipmentRunningSectionDto> result = new ArrayList<>(); |
| | | |
| | | //åå¹¶ç¸åç¶ææ°æ® |
| | | for (int i = 0; i < dtos.size() - 1; i++) { |
| | | MdcEquipmentRunningSectionDto mdcEquipmentRunningSectionDto = dtos.get(i); |
| | | MdcEquipmentRunningSectionDto next = dtos.get(i + 1); |
| | | if (mdcEquipmentRunningSectionDto.getStatus().equals(next.getStatus()) && mdcEquipmentRunningSectionDto.getEndTime().equals(next.getStartTime())) { |
| | | MdcEquipmentRunningSectionDto equipmentRunningSectionDto = new MdcEquipmentRunningSectionDto(); |
| | | BeanUtils.copyProperties(mdcEquipmentRunningSectionDto, equipmentRunningSectionDto); |
| | | equipmentRunningSectionDto.setEndTime(next.getEndTime()); |
| | | equipmentRunningSectionDto.setDuration(mdcEquipmentRunningSectionDto.getDuration() + next.getDuration()); |
| | | result.add(equipmentRunningSectionDto); |
| | | i++; |
| | | } else { |
| | | result.add(mdcEquipmentRunningSectionDto); |
| | | } |
| | | } |
| | | if (dtos.size() > 1) { |
| | | MdcEquipmentRunningSectionDto a = dtos.get(dtos.size() - 2); |
| | | MdcEquipmentRunningSectionDto b = dtos.get(dtos.size() - 1); |
| | | if (!a.getStatus().equals(b.getStatus()) && a.getEndTime().equals(b.getStartTime())) { |
| | | result.add(dtos.get(dtos.size() - 1)); |
| | | } |
| | | } else if (dtos.size() == 1){ |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢è¿è¡æ°æ® |
| | | */ |
| | | private List<MdcEquipmentRunningSection> loadEquipmentRunningTrace(String equipmentId, String collectTimeStr) { |
| | | Date startTime = DateUtils.getShortDate(collectTimeStr); |
| | | Date now = DateUtils.removeTime(DateUtils.getNow()); |
| | | long second = DateUtils.differentSecond(startTime, now); |
| | | List<MdcEquipmentRunningSection> list = new ArrayList<>(); |
| | | Date endTime = DateUtils.plusTime(startTime, 1); |
| | | if (second < 0) { |
| | | return Collections.emptyList(); |
| | | } else { |
| | | LambdaQueryWrapper<MdcEquipmentRunningSection> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(MdcEquipmentRunningSection::getEquipmentId, equipmentId); |
| | | queryWrapper.ne(MdcEquipmentRunningSection::getStatus, 22); |
| | | queryWrapper.ge(MdcEquipmentRunningSection::getEndTime, startTime); |
| | | queryWrapper.le(MdcEquipmentRunningSection::getStartTime, endTime); |
| | | queryWrapper.orderByAsc(MdcEquipmentRunningSection::getStartTime); |
| | | list = this.baseMapper.selectList(queryWrapper); |
| | | if (list == null || list.isEmpty()) { |
| | | list = equipmentRunningTracesCurrentLog(equipmentId); |
| | | } else { |
| | | //彿¥è¯¢çæ¶é´æ®µä¸æ¯å®æ´çä¸å¤© |
| | | if (list.get(list.size() - 1).getEndTime().getTime() < endTime.getTime()) { |
| | | List<MdcEquipmentRunningSection> notExcuteData = equipmentRunningTracesCurrentLog(equipmentId); |
| | | if (notExcuteData != null && !notExcuteData.isEmpty()) { |
| | | list.addAll(notExcuteData); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if (list == null || list.isEmpty()) { |
| | | return Collections.emptyList(); |
| | | } |
| | | return convertEquipmentRunningTrace(list, startTime, endTime); |
| | | } |
| | | |
| | | private List<MdcEquipmentRunningSection> loadEquipmentErrorTrace(String equipmentId, String collectTimeStr) { |
| | | List<MdcEquipmentRunningSection> list = new ArrayList<>(); |
| | | List<MdcEquipmentRunningSection> notExecuteData; |
| | | Date startTime = DateUtils.getShortDate(collectTimeStr); |
| | | Date endTime = DateUtils.plusTime(startTime, 1); |
| | | Date now = DateUtils.removeTime(new Date()); |
| | | if (startTime.compareTo(now) > 0) { |
| | | return Collections.emptyList(); |
| | | } else if (startTime.compareTo(now) == 0) { |
| | | LambdaQueryWrapper<MdcEquipmentRunningSection> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(MdcEquipmentRunningSection::getEquipmentId, equipmentId); |
| | | queryWrapper.eq(MdcEquipmentRunningSection::getStatus, 22); |
| | | queryWrapper.ge(MdcEquipmentRunningSection::getEndTime, startTime); |
| | | queryWrapper.le(MdcEquipmentRunningSection::getStartTime, endTime); |
| | | queryWrapper.orderByAsc(MdcEquipmentRunningSection::getStartTime); |
| | | list = this.baseMapper.selectList(queryWrapper); |
| | | notExecuteData = equipmentRunningTracesCurrentErrorLog(equipmentId); |
| | | if (list == null || list.isEmpty()) { |
| | | if (notExecuteData != null && !notExecuteData.isEmpty()) { |
| | | list = notExecuteData; |
| | | } |
| | | } else { |
| | | if (notExecuteData != null && !notExecuteData.isEmpty()) { |
| | | list.addAll(notExecuteData); |
| | | } |
| | | } |
| | | } else { |
| | | LambdaQueryWrapper<MdcEquipmentRunningSection> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(MdcEquipmentRunningSection::getEquipmentId, equipmentId); |
| | | queryWrapper.eq(MdcEquipmentRunningSection::getStatus, 22); |
| | | queryWrapper.ge(MdcEquipmentRunningSection::getEndTime, startTime); |
| | | queryWrapper.le(MdcEquipmentRunningSection::getStartTime, endTime); |
| | | queryWrapper.orderByAsc(MdcEquipmentRunningSection::getStartTime); |
| | | list = this.baseMapper.selectList(queryWrapper); |
| | | } |
| | | if (list == null || list.isEmpty()) { |
| | | return Collections.emptyList(); |
| | | } |
| | | return convertEquipmentErrorTrace(list, startTime, endTime); |
| | | } |
| | | |
| | | private List<MdcEquipmentRunningSection> convertEquipmentErrorTrace(List<MdcEquipmentRunningSection> list, Date startTime, Date endTime) { |
| | | if (list == null || list.isEmpty()) { |
| | | return Collections.emptyList(); |
| | | } |
| | | List<MdcEquipmentRunningSection> errorTraces = new ArrayList<>(); |
| | | MdcEquipmentRunningSection ert; |
| | | for (int i = 0; i < list.size(); i++) { |
| | | ert = list.get(i); |
| | | if (ert.getEndTime().getTime() <= startTime.getTime() || ert.getStartTime().getTime() >= endTime.getTime()) { |
| | | continue; |
| | | } |
| | | if (ert.getStartTime().getTime() < startTime.getTime()) { |
| | | ert.setStartTime(startTime); |
| | | ert.setDuration(TimeFieldUtils.duration(ert.getStartTime(), ert.getEndTime())); |
| | | } |
| | | if (ert.getEndTime().getTime() > endTime.getTime()) { |
| | | ert.setEndTime(endTime); |
| | | ert.setDuration(TimeFieldUtils.duration(ert.getStartTime(), ert.getEndTime())); |
| | | } |
| | | if (ert.getDuration() > 0) { |
| | | errorTraces.add(ert); |
| | | } |
| | | } |
| | | return errorTraces; |
| | | |
| | | } |
| | | |
| | | /** |
| | | * æ¥å¿æ¥è¯¢ä½¿ç¨ |
| | | * è·åæªè§£æçlogæ¥è¦æ¥å¿ |
| | | */ |
| | | private List<MdcEquipmentRunningSection> equipmentRunningTracesCurrentErrorLog(String equipmentId) { |
| | | //è·åæè¿ç设å¤è¿è¡è½¨è¿¹ç»ææ¶é´ |
| | | MdcEquipmentRunningSection nearestDate = this.baseMapper.getMaxError(equipmentId); |
| | | Date now = DateUtils.getNow(); |
| | | List<EquipmentLog> logList; |
| | | //æ¥æ¾è®¾å¤æ¥å¿ |
| | | if (nearestDate == null) { |
| | | logList = equipmentLogService.findEquipmentLogByErrorEndTime(equipmentId, null); |
| | | } else { |
| | | //TODO |
| | | /*å¾
éªè¯*/ |
| | | Date endTime = nearestDate.getEndTime(); |
| | | logList = equipmentLogService.findEquipmentLogByErrorEndTime(equipmentId, endTime); |
| | | } |
| | | //è®¾å¤æ¥å¿ä¸åå¨æåªæä¸æ¡è®°å½æ æ³è§£æ |
| | | if (logList == null || logList.size() < 1) { |
| | | return null; |
| | | } |
| | | List<MdcEquipmentRunningSection> erts = new ArrayList<MdcEquipmentRunningSection>(0); |
| | | MdcEquipmentRunningSection ert; |
| | | int length = logList.size(); |
| | | //å¯¹åªæä¸ä¸ªç¶æçè§£æ |
| | | if (length == 1 && logList.get(0).getOporation() == 22) { |
| | | MdcEquipmentRunningSection notEcut = new MdcEquipmentRunningSection(); |
| | | notEcut.setEquipmentId(logList.get(0).getEquipmentId()); |
| | | notEcut.setAlarm(logList.get(0).getAlarm()); |
| | | notEcut.setStatus(logList.get(0).getOporation()); |
| | | notEcut.setStartTime(logList.get(0).getCollectTime()); |
| | | notEcut.setEndTime(new Date()); |
| | | notEcut.setDuration(TimeFieldUtils.duration(notEcut.getStartTime(), notEcut.getEndTime())); |
| | | erts.add(notEcut); |
| | | return erts; |
| | | } else if (length == 1 && logList.get(0).getOporation() != 22) { |
| | | return null; |
| | | } |
| | | //è§£æEquipmentLogæ°æ® |
| | | for (int i = 0; i < length - 1; i++) { |
| | | if (logList.get(i).getOporation() != 22) { |
| | | continue; |
| | | } else { |
| | | ert = new MdcEquipmentRunningSection(); |
| | | ert.setStartTime(logList.get(i).getCollectTime()); |
| | | ert.setStatus(logList.get(i).getOporation()); |
| | | ert.setEquipmentId(logList.get(i).getEquipmentId()); |
| | | ert.setAlarm(logList.get(i).getAlarm()); |
| | | ert.setEndTime(logList.get(i + 1).getCollectTime()); |
| | | ert.setDuration(TimeFieldUtils.duration(ert.getStartTime(), ert.getEndTime())); |
| | | if (ert.getDuration() > 0) { |
| | | erts.add(ert); |
| | | } |
| | | } |
| | | } |
| | | //è§£ææå䏿¡è®°å½ |
| | | if (logList.get(length - 1).getOporation() == 22 && logList.get(length - 1).getCollectTime().getTime() < now.getTime()) { |
| | | ert = new MdcEquipmentRunningSection(); |
| | | ert.setStartTime(logList.get(length - 1).getCollectTime()); |
| | | ert.setStatus(logList.get(length - 1).getOporation()); |
| | | ert.setEquipmentId(logList.get(length - 1).getEquipmentId()); |
| | | ert.setAlarm(logList.get(length - 1).getAlarm()); |
| | | ert.setEndTime(now); |
| | | ert.setDuration(TimeFieldUtils.duration(ert.getStartTime(), ert.getEndTime())); |
| | | if (ert.getDuration() > 0) { |
| | | erts.add(ert); |
| | | } |
| | | } |
| | | if (erts.isEmpty()) { |
| | | return null; |
| | | } |
| | | return mergeErrorRunningTrace(erts); |
| | | } |
| | | |
| | | /** |
| | | * è·åæªè§£æçè®¾å¤æ¥å¿ |
| | | */ |
| | | private List<MdcEquipmentRunningSection> equipmentRunningTracesCurrentLog(String equipmentId) { |
| | | //è·åæè¿ç设å¤è¿è¡æ°æ®ç»ææ¶é´ |
| | | MdcEquipmentRunningSection nearestDate = this.baseMapper.getMaxNormal(equipmentId); |
| | | Date now = new Date(); |
| | | List<EquipmentLog> logList; |
| | | //æ¥æ¾è®¾å¤æ¥å¿ |
| | | if (nearestDate == null) { |
| | | logList = equipmentLogService.findEquipmentLogByEndTime(equipmentId, null); |
| | | } else { |
| | | Date endTime = nearestDate.getEndTime(); |
| | | logList = equipmentLogService.findEquipmentLogByEndTime(equipmentId, endTime); |
| | | } |
| | | //è®¾å¤æ¥å¿ä¸åå¨æåªæä¸æ¡è®°å½æ æ³è§£æ |
| | | if (logList.size() < 1 && nearestDate != null) { |
| | | List<MdcEquipmentRunningSection> result = new ArrayList<>(); |
| | | MdcEquipmentRunningSection one = new MdcEquipmentRunningSection(); |
| | | one.setStatus(nearestDate.getStatus()); |
| | | one.setEquipmentId(equipmentId); |
| | | one.setStartTime(nearestDate.getEndTime()); |
| | | one.setEndTime(DateUtils.getNow()); |
| | | one.setDuration(TimeFieldUtils.duration(one.getStartTime(), one.getEndTime())); |
| | | if (one.getDuration() > 0) { |
| | | result.add(one); |
| | | return result; |
| | | } else { |
| | | return Collections.emptyList(); |
| | | } |
| | | } else if (logList.size() == 1) { |
| | | List<MdcEquipmentRunningSection> result = new ArrayList<>(); |
| | | EquipmentLog eql = logList.get(0); |
| | | MdcEquipmentRunningSection one = new MdcEquipmentRunningSection(); |
| | | one.setStatus(eql.getOporation()); |
| | | one.setEquipmentId(equipmentId); |
| | | one.setStartTime(eql.getCollectTime()); |
| | | one.setEndTime(DateUtils.getNow()); |
| | | one.setDuration(TimeFieldUtils.duration(one.getStartTime(), one.getEndTime())); |
| | | if (one.getDuration() > 0) { |
| | | result.add(one); |
| | | return result; |
| | | } |
| | | return null; |
| | | } else if (nearestDate != null) { |
| | | EquipmentLog eql = new EquipmentLog(); |
| | | eql.setCollectTime(nearestDate.getEndTime()); |
| | | eql.setOporation(nearestDate.getStatus()); |
| | | eql.setEquipmentId(nearestDate.getEquipmentId()); |
| | | logList.add(0, eql); |
| | | } |
| | | //è§£å³æåæ¶é´nearestDate为å¤ä¸ªç¸åæ¶é´çæ°æ®ï¼å¯¼è´çæ¥è¯¢é误çé®é¢ |
| | | if (logList.size() > 1) { |
| | | boolean flag = true; |
| | | for (int i = 0; i < logList.size() - 1; i++) { |
| | | if (logList.get(i).getCollectTime().getTime() != logList.get(i + 1).getCollectTime().getTime()) { |
| | | flag = false; |
| | | } |
| | | } |
| | | if (flag) { |
| | | //å½æææ¥è¯¢åºçlogè®°å½çæ¶é´é½æ¯å¨å䏿¶é´ç¹ä¸ï¼å以ä¸å¤ç |
| | | List<MdcEquipmentRunningSection> result = new ArrayList<>(); |
| | | EquipmentLog eql = null; |
| | | for (EquipmentLog e : logList) { |
| | | //è·åå 个ç¸åæ¶é´çç¶æéå ä¼å
级 |
| | | if (e.getOporation() == 0) { |
| | | eql = e; |
| | | break; |
| | | } |
| | | if (eql == null) { |
| | | eql = e; |
| | | } else { |
| | | if ((eql.getOporation() == 1 && e.getOporation() == 2) || (eql.getOporation() == 1 && e.getOporation() == 3) || (eql.getOporation() == 2 && e.getOporation() == 3)) { |
| | | eql = e; |
| | | } |
| | | } |
| | | } |
| | | MdcEquipmentRunningSection one = new MdcEquipmentRunningSection(); |
| | | one.setStatus(eql.getOporation()); |
| | | one.setEquipmentId(equipmentId); |
| | | one.setStartTime(eql.getCollectTime()); |
| | | one.setEndTime(DateUtils.getNow()); |
| | | one.setDuration(TimeFieldUtils.duration(one.getStartTime(), one.getEndTime())); |
| | | if (one.getDuration() > 0) { |
| | | result.add(one); |
| | | return result; |
| | | } |
| | | return null; |
| | | } |
| | | } |
| | | List<MdcEquipmentRunningSection> erts = new ArrayList<>(); |
| | | int length = logList.size(); |
| | | MdcEquipmentRunningSection ert; |
| | | //è§£æEquipmentLogæ°æ® |
| | | if (length > 1) { |
| | | for (int i = 0; i < length - 1; i++) { |
| | | ert = new MdcEquipmentRunningSection(); |
| | | ert.setEquipmentId(equipmentId); |
| | | ert.setStatus(logList.get(i).getOporation() == 1 ? 2 : logList.get(i).getOporation()); |
| | | ert.setStartTime(logList.get(i).getCollectTime()); |
| | | ert.setEndTime(logList.get(i + 1).getCollectTime()); |
| | | ert.setDuration(TimeFieldUtils.duration(logList.get(i).getCollectTime(), logList.get(i + 1).getCollectTime())); |
| | | if (ert.getDuration() > 0) { |
| | | erts.add(ert); |
| | | } |
| | | } |
| | | if (logList.get(length - 1).getCollectTime().getTime() < now.getTime()) { |
| | | ert = new MdcEquipmentRunningSection(); |
| | | ert.setEquipmentId(equipmentId); |
| | | ert.setStatus(logList.get(length - 1).getOporation() == 1 ? 2 : logList.get(length - 1).getOporation()); |
| | | ert.setStartTime(logList.get(length - 1).getCollectTime()); |
| | | ert.setEndTime(now); |
| | | ert.setDuration(TimeFieldUtils.duration(logList.get(length - 1).getCollectTime(), now)); |
| | | if (ert.getDuration() > 0) { |
| | | erts.add(ert); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return mergeRunningTrace(erts); |
| | | } |
| | | |
| | | private List<MdcEquipmentRunningSection> convertEquipmentRunningTrace(List<MdcEquipmentRunningSection> list, Date startTime, Date endTime) { |
| | | //è¿æ»¤ä¸å¨åºé´çæ°æ® |
| | | List<MdcEquipmentRunningSection> newList = new ArrayList<>(); |
| | | for (MdcEquipmentRunningSection trace : list) { |
| | | if (trace.getEndTime().getTime() < startTime.getTime() || trace.getStartTime().getTime() > endTime.getTime()) { |
| | | continue; |
| | | } |
| | | newList.add(trace); |
| | | } |
| | | list = newList; |
| | | if (list.isEmpty()) { |
| | | return Collections.emptyList(); |
| | | } |
| | | //è§£æé¦å°¾æ¶é´ |
| | | MdcEquipmentRunningSection first = list.get(0); |
| | | MdcEquipmentRunningSection end = list.get(list.size() - 1); |
| | | Date now = new Date(); |
| | | if (first.getStartTime().getTime() < startTime.getTime()) { |
| | | first.setStartTime(startTime); |
| | | first.setDuration(TimeFieldUtils.duration(startTime, first.getEndTime())); |
| | | } else if (first.getStartTime().getTime() > startTime.getTime()) { |
| | | //list éåé¦é¨æ·»å 䏿¡è®°å½ |
| | | MdcEquipmentRunningSection newStart = new MdcEquipmentRunningSection(); |
| | | newStart.setEquipmentId(first.getEquipmentId()); |
| | | newStart.setEndTime(first.getStartTime()); |
| | | newStart.setStartTime(startTime); |
| | | newStart.setDuration(TimeFieldUtils.duration(startTime, first.getStartTime())); |
| | | MdcEquipmentRunningSection stats = getEndTimeInfoRunningLastDate(first.getEquipmentId(), first.getStartTime()); |
| | | if (stats != null) { |
| | | newStart.setStatus(stats.getStatus()); |
| | | } |
| | | if (newStart.getDuration() > 0) { |
| | | list.add(0, newStart); |
| | | } |
| | | } |
| | | if (end.getEndTime().getTime() > endTime.getTime()) { |
| | | end.setEndTime(endTime); |
| | | end.setDuration(TimeFieldUtils.duration(end.getStartTime(), endTime)); |
| | | } else if (end.getEndTime().getTime() < endTime.getTime()) { |
| | | if (endTime.getTime() <= now.getTime()) { |
| | | end.setEndTime(endTime); |
| | | end.setDuration(TimeFieldUtils.duration(end.getStartTime(), endTime)); |
| | | } else { |
| | | end.setEndTime(now); |
| | | end.setDuration(TimeFieldUtils.duration(end.getStartTime(), now)); |
| | | } |
| | | } |
| | | return mergeRunningTrace(list); |
| | | } |
| | | |
| | | private MdcEquipmentRunningSection getEndTimeInfoRunningLastDate(String equipmentId, Date endTime) { |
| | | if (StringUtils.isBlank(equipmentId) || endTime == null) { |
| | | return null; |
| | | } |
| | | List<MdcEquipmentRunningSection> list = this.baseMapper.listForEquipmentStatisticalInfo(equipmentId, endTime, DateUtils.plusTime(endTime, 1)); |
| | | if (list.size() > 0) { |
| | | return list.get(0); |
| | | } else { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设å¤è¿è¡ç¶æç¹æ¶é´è½¬ä¸ºæ®µæ¶é´ |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void runningAllEquipmentTraceProcess() { |
| | | //è·åææè®¾å¤ |
| | | List<Equipment> equipmentList = equipmentService.list(); |
| | | for (Equipment equipment : equipmentList) { |
| | | //è·å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> errorList = this.equipmentRunningTracesErrorLog(equipment.getEquipmentid()); |
| | | if (errorList != null && !errorList.isEmpty()) { |
| | | this.ergodicTrim(errorList); |
| | | //save errorList |
| | | super.saveBatch(errorList); |
| | | } |
| | | List<DictModel> dictList = sysDictService.queryDictItemsByCode("data_synchronization_flag"); |
| | | if (dictList != null && !dictList.isEmpty() && "0".equals(dictList.get(0).getValue())) { |
| | | this.dataSynchronizationHandler(list, errorList); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设å¤è¿è¡æ¥å¿æ·»å ç¨åºå· |
| | | * |
| | | * @param list |
| | | * @return |
| | | */ |
| | | public List<MdcEquipmentRunningSection> addSequenceNumber(List<MdcEquipmentRunningSection> list) { |
| | | if (list == null || list.size() < 1) { |
| | | return Collections.emptyList(); |
| | | } |
| | | Equipment equip = null; |
| | | for (MdcEquipmentRunningSection e : list) { |
| | | if (e.getStatus() == 3) { |
| | | equip = equipmentService.getOne(new LambdaQueryWrapper<Equipment>().eq(Equipment::getEquipmentid, e.getEquipmentId())); |
| | | if (StringUtils.isNotBlank(equip.getDrivetype()) && equip.getDrivetype().startsWith("FANUC")) { |
| | | 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()); |
| | | } |
| | | } else if (StringUtils.isNotBlank(equip.getDrivetype()) && equip.getDrivetype().startsWith("SIEMENS")) { |
| | | List<EquipmentMachingDto> esList = equipmentWorkLineService.getEquipmentSequencenumber(equip.getDrivetype() + "_" + equip.getEquipmentid(), e.getStartTime(), e.getEndTime()); |
| | | if (esList != null && esList.size() > 1) { |
| | | e.setSequenceNumber(esList.get(0).getSequencenumber()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * æ°æ®åæ¥å¤ç |
| | | * @param list |
| | | * @param errorList |
| | | */ |
| | | private void dataSynchronizationHandler(List<MdcEquipmentRunningSection> list, List<MdcEquipmentRunningSection> errorList) { |
| | | // æ°æ®è½¬æ¢ |
| | | List<EquipmentRunningTrace> equipList = new ArrayList<>(); |
| | | if (list != null && !list.isEmpty()) { |
| | | list.forEach(item -> { |
| | | EquipmentRunningTrace equipmentRunningSection = new EquipmentRunningTrace(); |
| | | equipmentRunningSection.setEquipment(item.getEquipmentId()); |
| | | equipmentRunningSection.setAlarm(item.getAlarm()); |
| | | equipmentRunningSection.setCreateTime(item.getCreateTime()); |
| | | equipmentRunningSection.setDuration(item.getDuration()); |
| | | equipmentRunningSection.setEndTime(item.getEndTime()); |
| | | equipmentRunningSection.setStartTime(item.getStartTime()); |
| | | equipmentRunningSection.setStatus(item.getStatus()); |
| | | equipmentRunningSection.setSequencenumber(item.getSequenceNumber()); |
| | | equipList.add(equipmentRunningSection); |
| | | }); |
| | | } |
| | | if (errorList != null && !errorList.isEmpty()) { |
| | | errorList.forEach(item -> { |
| | | EquipmentRunningTrace equipmentRunningSection = new EquipmentRunningTrace(); |
| | | equipmentRunningSection.setEquipment(item.getEquipmentId()); |
| | | equipmentRunningSection.setAlarm(item.getAlarm()); |
| | | equipmentRunningSection.setCreateTime(item.getCreateTime()); |
| | | equipmentRunningSection.setDuration(item.getDuration()); |
| | | equipmentRunningSection.setEndTime(item.getEndTime()); |
| | | equipmentRunningSection.setStartTime(item.getStartTime()); |
| | | equipmentRunningSection.setStatus(item.getStatus()); |
| | | equipmentRunningSection.setSequencenumber(item.getSequenceNumber()); |
| | | equipList.add(equipmentRunningSection); |
| | | }); |
| | | } |
| | | equipmentRunningTraceService.saveBatch(equipList); |
| | | } |
| | | |
| | | /** |
| | | * è·å设å¤è¿è¡è®°å½ææ©çæ°æ® |
| | | */ |
| | | @Override |
| | | public MdcEquipmentRunningSection getFirstData(String equipmentId) { |
| | | return this.baseMapper.getFirstData(equipmentId); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢è®¾å¤åæ¥è¿è¡ç¶ææ¶é´æ®µè®°å½ |
| | | */ |
| | | @Override |
| | | public List<MdcEquipmentRunningSection> listForEquipmentStatisticalInfo(String equipmentId, Date startDate, Date endDate) { |
| | | return this.baseMapper.listForEquipmentStatisticalInfo(equipmentId, startDate, endDate); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢è®¾å¤åå²è¿è¡ç¶æè®°å½æ°æ® |
| | | */ |
| | | @Override |
| | | public List<Map<String, Object>> logChart(MdcEquipmentRunningSectionVo equipmentRunningSectionVo) { |
| | | List<Map<String, Object>> result = new ArrayList<>(); |
| | | List<String> dateList = DateUtils.getDatesStringList(DateUtils.getShortDate(equipmentRunningSectionVo.getStartTime()), DateUtils.getShortDate(equipmentRunningSectionVo.getEndTime())); |
| | | for (String date : dateList) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("date", date); |
| | | Map<String, List<MdcEquipmentRunningSectionDto>> logCharts = this.logCharts(equipmentRunningSectionVo, date); |
| | | map.put("value", logCharts); |
| | | result.add(map); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 计ç®ä¸æ®µæ¶é´å
çæ°æ® |
| | | */ |
| | | @Override |
| | | public List<MdcEquipmentRunningSection> listEquipmentRunningSection(String equipmentid, long start, long end) { |
| | | return this.baseMapper.listEquipmentRunningSection(equipmentid, start, end); |
| | | } |
| | | |
| | | @Override |
| | | public List<MdcEquipmentRunningSection> listRunningSectionFromLog(String equipmentid, long start, long end) { |
| | | if (StringUtils.isBlank(equipmentid) || start <= 0 || end <= 0) { |
| | | return null; |
| | | } |
| | | Date startTime = DateUtils.toDate(DateUtils.longToDate(start), DateUtils.STR_DATE_TIME_SMALL); |
| | | Date endTime = DateUtils.toDate(DateUtils.longToDate(end), DateUtils.STR_DATE_TIME_SMALL); |
| | | EquipmentLog equipmentLog = equipmentLogService.getRow(equipmentid, startTime); |
| | | if (equipmentLog == null) { |
| | | return null; |
| | | } |
| | | List<EquipmentLog> logList = new ArrayList<>(); |
| | | EquipmentLog equipmentOne = new EquipmentLog(); |
| | | equipmentOne.setEquipmentId(equipmentid); |
| | | equipmentOne.setOporation(equipmentLog.getOporation()); |
| | | equipmentOne.setCollectTime(startTime); |
| | | logList.add(equipmentOne); |
| | | List<EquipmentLog> logListLast = equipmentLogService.findEquipmentLogByEndTime(equipmentid, startTime); |
| | | if (logListLast == null || logListLast.isEmpty()) { |
| | | EquipmentLog two = new EquipmentLog(); |
| | | two.setEquipmentId(equipmentid); |
| | | two.setOporation(equipmentLog.getOporation()); |
| | | two.setCollectTime(endTime); |
| | | logList.add(two); |
| | | } else { |
| | | for (EquipmentLog log : logListLast) { |
| | | if (log.getCollectTime().getTime() <= endTime.getTime()) { |
| | | logList.add(log); |
| | | } |
| | | } |
| | | } |
| | | if (logList.get(logList.size() - 1).getCollectTime().getTime() < endTime.getTime()) { |
| | | EquipmentLog two = new EquipmentLog(); |
| | | two.setEquipmentId(equipmentid); |
| | | two.setOporation(logList.get(logList.size() - 1).getOporation()); |
| | | two.setCollectTime(endTime); |
| | | logList.add(two); |
| | | } |
| | | //ç¹æ°æ®è½¬ä¸ºæ®µæ°æ® |
| | | List<MdcEquipmentRunningSection> erts = parseLogToRunningTrace(logList); |
| | | if (erts.isEmpty()) { |
| | | return Collections.emptyList(); |
| | | } |
| | | //æ´åå å·¥åå¾
æºæ¶é´å°äºnç§çæ°æ® |
| | | erts = mergeLessMinTimeRecords(erts, null); |
| | | List<MdcEquipmentRunningSection> running = mergeRunningTrace(erts); |
| | | if (running != null && !running.isEmpty()) { |
| | | this.ergodicTrim(running); |
| | | } |
| | | return running; |
| | | } |
| | | |
| | | @Override |
| | | public List<MdcEquipmentRunningSection> listEquipmentRunningSectionRun(String equipmentid, long start, long end) { |
| | | return this.baseMapper.listEquipmentRunningSectionRun(equipmentid, start, end); |
| | | } |
| | | |
| | | @Override |
| | | public List<MdcEquipmentRunningSection> listEquipmentRunningSectionError(String equipmentid, long start, long end) { |
| | | return this.baseMapper.listEquipmentRunningSectionError(equipmentid, start, end); |
| | | } |
| | | |
| | | @Override |
| | | public List<MdcEquipmentRunningSection> findAlarmList(MdcAlarmAnalyzeQueryVo vo) { |
| | | return this.baseMapper.findAlarmList(vo); |
| | | } |
| | | |
| | | @Override |
| | | public Integer findAlarmCount(String equipmentId, String startDate, String endDate, String alarmCode) { |
| | | return this.baseMapper.findAlarmCount(equipmentId, startDate, endDate, alarmCode); |
| | | } |
| | | |
| | | @Override |
| | | public Integer findAlarmCountByDate(String startDate, String endDate, MdcAlarmAnalyzeQueryVo vo) { |
| | | return this.baseMapper.findAlarmCountByDate(startDate, endDate, vo); |
| | | } |
| | | |
| | | @Override |
| | | public List<MdcEquipmentRunningSection> selectRunningData(String equipmentId, Date startDate, Date endDate) { |
| | | return this.baseMapper.selectRunningData(equipmentId, startDate, endDate); |
| | | } |
| | | |
| | | @Override |
| | | public List<MdcAlarmListDto> selectAlarmList(MdcAlarmAnalyzeQueryVo mdcAlarmAnalyzeQueryVo, String startDate, String endDate) { |
| | | return this.baseMapper.selectAlarmList(mdcAlarmAnalyzeQueryVo, startDate, endDate); |
| | | } |
| | | |
| | | @Override |
| | | public List<Integer> getDataList(String equipmentId, Date date) { |
| | | return this.baseMapper.getDataList(equipmentId, date); |
| | | } |
| | | |
| | | @Override |
| | | public List<MdcEquipmentWaitSectionDto> findWaitList(String date) { |
| | | 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<>(); |
| | | List<MdcEquipmentRunningSectionDto> waring = new ArrayList<>(); |
| | | List<MdcEquipmentRunningSectionDto> fault = new ArrayList<>(); |
| | | //è¿è¡ |
| | | List<MdcEquipmentRunningSection> running = loadEquipmentRunningTrace(equipmentRunningSectionVo.getEquipmentId(), date); |
| | | //æ¥è¦ |
| | | List<MdcEquipmentRunningSection> errs = loadEquipmentErrorTrace(equipmentRunningSectionVo.getEquipmentId(), date); |
| | | //æ
é |
| | | List<MdcEquipmentRunningSection> faults = loadEquipmentFaultTrace(equipmentRunningSectionVo.getEquipmentId(), date); |
| | | |
| | | if (running != null && !running.isEmpty()) { |
| | | MdcEquipmentRunningSectionDto dto; |
| | | for (MdcEquipmentRunningSection mdcEquipmentRunningSection : running) { |
| | | dto = new MdcEquipmentRunningSectionDto(); |
| | | BeanUtils.copyProperties(mdcEquipmentRunningSection, dto); |
| | | normal.add(dto); |
| | | } |
| | | } else { |
| | | map.put("normal", null); |
| | | } |
| | | |
| | | if (errs != null && !errs.isEmpty()) { |
| | | MdcEquipmentRunningSectionDto dto; |
| | | for (MdcEquipmentRunningSection mdcEquipmentRunningSection : errs) { |
| | | dto = new MdcEquipmentRunningSectionDto(); |
| | | BeanUtils.copyProperties(mdcEquipmentRunningSection, dto); |
| | | waring.add(dto); |
| | | } |
| | | } else { |
| | | map.put("waring", null); |
| | | } |
| | | |
| | | if (!faults.isEmpty()) { |
| | | MdcEquipmentRunningSectionDto dto; |
| | | for (MdcEquipmentRunningSection mdcEquipmentRunningSection : faults) { |
| | | dto = new MdcEquipmentRunningSectionDto(); |
| | | BeanUtils.copyProperties(mdcEquipmentRunningSection, dto); |
| | | fault.add(dto); |
| | | } |
| | | } else { |
| | | map.put("fault", null); |
| | | } |
| | | |
| | | map.put("normal", normal); |
| | | map.put("waring", waring); |
| | | map.put("fault", fault); |
| | | |
| | | return map; |
| | | } |
| | | |
| | | private void ergodicTrim(List<MdcEquipmentRunningSection> list) { |
| | | for (MdcEquipmentRunningSection temp : list) { |
| | | temp.setStartLong(temp.getStartTime().getTime()); |
| | | temp.setEndLong(temp.getEndTime().getTime()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åæªè§£æçlogæ¥è¦æ¥å¿ |
| | | */ |
| | | private List<MdcEquipmentRunningSection> equipmentRunningTracesErrorLog(String equipmentId) { |
| | | //è·åæè¿ç设å¤è¿è¡è½¨è¿¹ç»ææ¶é´ |
| | | MdcEquipmentRunningSection mdcEquipmentRunningSection = this.baseMapper.getMaxError(equipmentId); |
| | | Date endTime = null; |
| | | if (mdcEquipmentRunningSection != null) { |
| | | endTime = mdcEquipmentRunningSection.getEndTime(); |
| | | } |
| | | //æ¥æ¾è®¾å¤æ¥å¿ |
| | | List<EquipmentLog> logList = equipmentLogService.findEquipmentLogByErrorEndTime(equipmentId, endTime); |
| | | //è®¾å¤æ¥å¿ä¸åå¨æåªæä¸æ¡è®°å½æ æ³è§£æ |
| | | if (logList == null || logList.isEmpty()) { |
| | | return null; |
| | | } else if (logList.size() == 1) { |
| | | EquipmentLog traceLog = logList.get(0); |
| | | long differentSecond = DateUtils.differentSecond(traceLog.getCollectTime(), new Date()); |
| | | if (differentSecond > 30 * 60) { |
| | | MdcEquipmentRunningSection ert = new MdcEquipmentRunningSection(); |
| | | ert.setEquipmentId(traceLog.getEquipmentId()); |
| | | ert.setStatus(traceLog.getOporation() == 1 ? 2 : traceLog.getOporation()); |
| | | ert.setStartTime(traceLog.getCollectTime()); |
| | | Calendar cal = Calendar.getInstance(); |
| | | cal.setTime(ert.getStartTime()); |
| | | cal.add(Calendar.MINUTE, 30); |
| | | ert.setEndTime(cal.getTime()); |
| | | ert.setDuration(DateUtils.differentSecond(ert.getStartTime(), ert.getEndTime())); |
| | | } |
| | | } |
| | | List<MdcEquipmentRunningSection> erts = parseLogToErrorRunningTrace(logList); |
| | | if (erts == null || erts.isEmpty()) { |
| | | return Collections.emptyList(); |
| | | } |
| | | return mergeErrorRunningTrace(erts); |
| | | } |
| | | |
| | | /** |
| | | * åå¹¶è¿ç»æ¶é´çæ¥è¦æ°æ® |
| | | */ |
| | | private List<MdcEquipmentRunningSection> mergeErrorRunningTrace(List<MdcEquipmentRunningSection> list) { |
| | | List<MdcEquipmentRunningSection> nErts = new ArrayList<>(); |
| | | MdcEquipmentRunningSection ert; |
| | | for (int j = 0; j < list.size(); j++) { |
| | | ert = list.get(j); |
| | | if (j < list.size() - 1) { |
| | | if (ert.getEndTime().getTime() == list.get(j + 1).getStartTime().getTime()) { |
| | | ert.setEndTime(list.get(j + 1).getEndTime()); |
| | | ert.setDuration(DateUtils.differentSecond(ert.getStartTime(), ert.getEndTime())); |
| | | j++; |
| | | } |
| | | nErts.add(setTmpEquipmentAlarm(ert)); |
| | | } |
| | | if (j == list.size() - 1) { |
| | | if (list.size() > 1) { |
| | | MdcEquipmentRunningSection section = setTmpEquipmentAlarm(ert); |
| | | if (section != null && nErts.size() > 0 && section.getStartTime().getTime() != nErts.get(nErts.size() - 1).getStartTime().getTime()) { |
| | | nErts.add(section); |
| | | } |
| | | } else { |
| | | MdcEquipmentRunningSection section = setTmpEquipmentAlarm(ert); |
| | | nErts.add(section); |
| | | } |
| | | |
| | | } |
| | | } |
| | | return nErts; |
| | | } |
| | | |
| | | private MdcEquipmentRunningSection setTmpEquipmentAlarm(MdcEquipmentRunningSection ert) { |
| | | //è·åç¸åºæ¶é´æ®µæ¥è¦ä¿¡æ¯ |
| | | List<EquipmentAlarm> list = equipmentAlarmService.findEquipmentAlarmByDate(ert.getEquipmentId(), ert.getStartTime(), ert.getEndTime()); |
| | | if (list != null && !list.isEmpty()) { |
| | | Set<TmpEquipmentAlarm> alarmSet = new HashSet<>(); |
| | | for (EquipmentAlarm alarm : list) { |
| | | TmpEquipmentAlarm entity = new TmpEquipmentAlarm(); |
| | | entity.setEquipmentID(alarm.getEquipmentid()); |
| | | entity.setCollectTime(alarm.getCollecttime()); |
| | | entity.setAlarmContent(alarm.getAlarmContent()); |
| | | entity.setAlarmNo(alarm.getAlarmNo()); |
| | | alarmSet.add(entity); |
| | | } |
| | | ert.setTmpEquipmentAlarmSet(alarmSet); |
| | | } |
| | | return ert; |
| | | } |
| | | |
| | | /** |
| | | * è§£ææ¥è¦æ¥å¿ |
| | | * å·¥å
·æ¹æ³ |
| | | */ |
| | | private List<MdcEquipmentRunningSection> parseLogToErrorRunningTrace(List<EquipmentLog> logList) { |
| | | List<MdcEquipmentRunningSection> erts = new ArrayList<>(); |
| | | MdcEquipmentRunningSection ert; |
| | | int length = logList.size(); |
| | | //è§£æEquipmentLogæ°æ® |
| | | for (int i = 0; i < length - 1; i++) { |
| | | if (logList.get(i).getOporation() != 22) { |
| | | continue; |
| | | } else { |
| | | ert = new MdcEquipmentRunningSection(); |
| | | ert.setStartTime(logList.get(i).getCollectTime()); |
| | | ert.setStatus(logList.get(i).getOporation()); |
| | | ert.setEquipmentId(logList.get(i).getEquipmentId()); |
| | | ert.setAlarm(logList.get(i).getAlarm()); |
| | | ert.setEndTime(logList.get(i + 1).getCollectTime()); |
| | | ert.setDuration(DateUtils.differentSecond(ert.getStartTime(), ert.getEndTime())); |
| | | if (ert.getEndTime() != null && ert.getDuration() > 0) { |
| | | erts.add(ert); |
| | | } |
| | | } |
| | | } |
| | | if (erts.isEmpty()) { |
| | | return null; |
| | | } |
| | | return erts; |
| | | } |
| | | |
| | | /** |
| | | * è·årunningè¿è¡çæ¥å¿è®°å½ |
| | | */ |
| | | private List<MdcEquipmentRunningSection> equipmentRunningTracesLog(String equipmentId) { |
| | | //è·åè®¡ç®æ®µæ¶é´åçæå䏿¡è®°å½ |
| | | MdcEquipmentRunningSection mdcEquipmentRunningSection = this.baseMapper.getMaxNormal(equipmentId); |
| | | List<EquipmentLog> logList = new ArrayList<>(); |
| | | Date maxDate = null; |
| | | if (mdcEquipmentRunningSection != null) { |
| | | maxDate = mdcEquipmentRunningSection.getEndTime(); |
| | | } |
| | | logList = equipmentLogService.findEquipmentLogByEndTime(equipmentId, maxDate); |
| | | if (mdcEquipmentRunningSection != null) { |
| | | EquipmentLog traceLog = new EquipmentLog(); |
| | | traceLog.setCollectTime(mdcEquipmentRunningSection.getEndTime()); |
| | | traceLog.setEquipmentId(equipmentId); |
| | | traceLog.setOporation(mdcEquipmentRunningSection.getStatus()); |
| | | logList.add(0, traceLog); |
| | | } |
| | | //夿æåçè®°å½æ¯å¦è¶
è¿24å°æ¶ è¶
è¿åå
¥ç¶ææ°æ®differentSecond |
| | | if (logList == null || logList.isEmpty() || logList.size() == 1) { |
| | | return null; |
| | | } else { |
| | | long differentSecond = DateUtils.differentSecond(logList.get(logList.size() - 1).getCollectTime(), new Date()); |
| | | /*86400 */ |
| | | if (differentSecond >= 3600) { |
| | | EquipmentLog traceLog = new EquipmentLog(); |
| | | traceLog.setCollectTime(new Date()); |
| | | traceLog.setEquipmentId(equipmentId); |
| | | traceLog.setOporation(logList.get(logList.size() - 1).getOporation()); |
| | | logList.add(traceLog); |
| | | } |
| | | } |
| | | //ç¹æ°æ®è½¬ä¸ºæ®µæ°æ® |
| | | List<MdcEquipmentRunningSection> erts = parseLogToRunningTrace(logList); |
| | | if (erts.isEmpty()) { |
| | | return Collections.emptyList(); |
| | | } |
| | | //æ´åå å·¥åå¾
æºæ¶é´å°äºnç§çæ°æ® |
| | | erts = mergeLessMinTimeRecords(erts, mdcEquipmentRunningSection); |
| | | |
| | | return mergeRunningTrace(erts); |
| | | } |
| | | |
| | | /** |
| | | * ç¹æ°æ®è½¬ä¸ºæ®µæ°æ® |
| | | */ |
| | | private List<MdcEquipmentRunningSection> parseLogToRunningTrace(List<EquipmentLog> logList) { |
| | | List<MdcEquipmentRunningSection> erts = new ArrayList<>(0); |
| | | int length = logList.size(); |
| | | //è§£æEquipmentLogæ°æ® |
| | | for (int i = 0; i < length - 1; i++) { |
| | | EquipmentLog equipmentLog = logList.get(i); |
| | | EquipmentLog nextEquipmentLog = logList.get(i + 1); |
| | | long differentSecond = DateUtils.differentSecond(equipmentLog.getCollectTime(), nextEquipmentLog.getCollectTime()); |
| | | if (differentSecond <= 86400) { |
| | | MdcEquipmentRunningSection ert = new MdcEquipmentRunningSection(); |
| | | ert.setEquipmentId(logList.get(i).getEquipmentId()); |
| | | ert.setStatus(logList.get(i).getOporation() == 1 ? 2 : logList.get(i).getOporation()); |
| | | ert.setStartTime(logList.get(i).getCollectTime()); |
| | | ert.setEndTime(logList.get(i + 1).getCollectTime()); |
| | | ert.setDuration(DateUtils.differentSecond(ert.getStartTime(), ert.getEndTime())); |
| | | // if (ert.getDuration() > 0) { |
| | | erts.add(ert); |
| | | // } |
| | | } else { |
| | | long count = differentSecond / 86400; |
| | | if (count % 86400 > 0) { |
| | | count = count + 1; |
| | | } |
| | | Date start = equipmentLog.getCollectTime(); |
| | | Date end = nextEquipmentLog.getCollectTime(); |
| | | for (int j = 0; j < count; j++) { |
| | | if (j == 0) { |
| | | MdcEquipmentRunningSection ert = new MdcEquipmentRunningSection(); |
| | | ert.setEquipmentId(equipmentLog.getEquipmentId()); |
| | | ert.setStatus(equipmentLog.getOporation() == 1 ? 2 : equipmentLog.getOporation()); |
| | | ert.setStartTime(start); |
| | | long tmp = 86400000 - start.getTime() % 86400000 + start.getTime(); |
| | | ert.setEndTime(new Date(tmp)); |
| | | ert.setDuration(DateUtils.differentSecond(ert.getStartTime(), ert.getEndTime())); |
| | | erts.add(ert); |
| | | start = ert.getEndTime(); |
| | | } else if (j == count - 1) { |
| | | MdcEquipmentRunningSection ert = new MdcEquipmentRunningSection(); |
| | | ert.setEquipmentId(equipmentLog.getEquipmentId()); |
| | | ert.setStatus(equipmentLog.getOporation() == 1 ? 2 : equipmentLog.getOporation()); |
| | | ert.setStartTime(start); |
| | | ert.setEndTime(end); |
| | | ert.setDuration(DateUtils.differentSecond(ert.getStartTime(), ert.getEndTime())); |
| | | erts.add(ert); |
| | | } else { |
| | | MdcEquipmentRunningSection ert = new MdcEquipmentRunningSection(); |
| | | ert.setEquipmentId(equipmentLog.getEquipmentId()); |
| | | ert.setStatus(equipmentLog.getOporation() == 1 ? 2 : equipmentLog.getOporation()); |
| | | ert.setStartTime(start); |
| | | ert.setEndTime(new Date(start.getTime() + 86400000)); |
| | | ert.setDuration(DateUtils.differentSecond(ert.getStartTime(), ert.getEndTime())); |
| | | erts.add(ert); |
| | | start = ert.getEndTime(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return erts; |
| | | } |
| | | |
| | | /** |
| | | * æ´åå å·¥åå¾
æºæ¶é´å°äºnç§çæ°æ® |
| | | * å¤æç¶ææ¶é¿æ¯å¦å°äºæå°é´é |
| | | * 妿å°äºå䏿¡æ°æ®ä½æ¯è¾ï¼å°ä¸æ¡æ°æ®çç¶æå¤å¶å°å½åæ°æ® |
| | | */ |
| | | private List<MdcEquipmentRunningSection> mergeLessMinTimeRecords(List<MdcEquipmentRunningSection> erts, MdcEquipmentRunningSection mdcEquipmentRunningSection) { |
| | | if (erts == null || erts.isEmpty() || erts.size() == 1) { |
| | | return null; |
| | | } |
| | | Integer processMinTime = 10; |
| | | Integer waitMinTime = 10; |
| | | List<MdcEquipmentRunningSection> resultList = new ArrayList<>(); |
| | | MdcEquipmentRunningSection ert = erts.get(0); |
| | | if (ert.getStatus() == 2 && ert.getDuration() < waitMinTime) { |
| | | if (mdcEquipmentRunningSection != null && mdcEquipmentRunningSection.getStatus() == 3) { |
| | | ert.setStatus(3); |
| | | } |
| | | resultList.add(ert); |
| | | } else if (ert.getStatus() == 3 && ert.getDuration() < processMinTime) { |
| | | if (mdcEquipmentRunningSection != null && mdcEquipmentRunningSection.getStatus() == 2) { |
| | | ert.setStatus(2); |
| | | } |
| | | resultList.add(ert); |
| | | } else { |
| | | resultList.add(ert); |
| | | } |
| | | MdcEquipmentRunningSection previous = null; |
| | | for (int i = 1; i < erts.size(); i++) { |
| | | ert = erts.get(i); |
| | | if (ert.getStatus() == 2 && ert.getDuration() < waitMinTime) { |
| | | previous = resultList.get(resultList.size() - 1); |
| | | if (previous.getStatus() == 3) { |
| | | previous.setEndTime(ert.getEndTime()); |
| | | previous.setDuration(DateUtils.differentSecond(previous.getStartTime(), previous.getEndTime())); |
| | | } else { |
| | | resultList.add(ert); |
| | | } |
| | | } else if (ert.getStatus() == 3 && ert.getDuration() < processMinTime) { |
| | | previous = resultList.get(resultList.size() - 1); |
| | | if (previous.getStatus() == 2) { |
| | | previous.setEndTime(ert.getEndTime()); |
| | | previous.setDuration(DateUtils.differentSecond(previous.getStartTime(), previous.getEndTime())); |
| | | } else { |
| | | resultList.add(ert); |
| | | } |
| | | } else { |
| | | resultList.add(ert); |
| | | } |
| | | } |
| | | |
| | | return resultList; |
| | | } |
| | | |
| | | /** |
| | | * åå¹¶ç¸åç¶æçæ°æ® |
| | | */ |
| | | private List<MdcEquipmentRunningSection> mergeRunningTrace(List<MdcEquipmentRunningSection> list) { |
| | | if (list == null || list.isEmpty() || list.size() == 1) { |
| | | return list; |
| | | } |
| | | List<MdcEquipmentRunningSection> nErts = new ArrayList<>(); |
| | | boolean flag = false; |
| | | MdcEquipmentRunningSection fErt = null; |
| | | MdcEquipmentRunningSection ert; |
| | | for (int i = 0; i < list.size(); i++) { |
| | | do { |
| | | if (i < list.size()) { |
| | | ert = list.get(i); |
| | | if (i != 0) { |
| | | if (fErt.getStatus() == ert.getStatus()) { |
| | | flag = true; |
| | | //ä¸åå¹¶è·¨å¤©æ°æ® |
| | | if (DateUtils.differentSecond(fErt.getStartTime(), ert.getEndTime()) >= 86400) { |
| | | flag = false; |
| | | } |
| | | } else { |
| | | flag = false; |
| | | } |
| | | } |
| | | if (flag) { |
| | | fErt.setEndTime(ert.getEndTime()); |
| | | fErt.setDuration(DateUtils.differentSecond(fErt.getStartTime(), fErt.getEndTime())); |
| | | i++; |
| | | } else { |
| | | if (fErt != null) { |
| | | fErt.setAlarm(ert.getAlarm()); |
| | | nErts.add(fErt); |
| | | } |
| | | fErt = ert; |
| | | } |
| | | } else { |
| | | flag = false; |
| | | } |
| | | } while (flag); |
| | | } |
| | | nErts.add(fErt); |
| | | return nErts; |
| | | } |
| | | |
| | | } |