| | |
| | | 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.MdcAlarmAnalyzeQueryVo; |
| | | import org.jeecg.modules.mdc.vo.MdcEquipmentRunningSectionVo; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | List<MdcEquipmentRunningSection> errs = loadEquipmentErrorTrace(equipmentRunningSectionVo.getEquipmentId(), equipmentRunningSectionVo.getCollectTimeStr()); |
| | | if (!running.isEmpty()) { |
| | | MdcEquipmentRunningSectionDto dto; |
| | | Equipment equip = equipmentService.getOne(new LambdaQueryWrapper<Equipment>().eq(Equipment::getEquipmentid, equipmentRunningSectionVo.getEquipmentId())); |
| | | 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())) { |
| | | Equipment equip = equipmentService.getOne(new LambdaQueryWrapper<Equipment>().eq(Equipment::getEquipmentid, entity.getEquipmentId())); |
| | | if (equip != null) { |
| | | if (StringUtils.isNotBlank(equip.getDrivetype())) { |
| | | try { |
| | | List<EquipmentMachingDto> esList = equipmentWorkLineService.getEquipmentSequencenumber(equip.getDrivetype(), equip.getEquipmentid(), entity.getStartTime(), entity.getEndTime()); |
| | | if (esList != null && esList.size() > 1) { |
| | | dto.setSequenceNumber(esList.get(0).getSequencenumber()); |
| | | } |
| | | } catch (Exception e) { |
| | | continue; |
| | | } |
| | | |
| | | } |
| | | if (entity.getStatus() == 3 && StringUtils.isBlank(entity.getSequenceNumber()) && isTableExist) { |
| | | 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); |
| | |
| | | * 设备运行状态点时间转为段时间 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void runningAllEquipmentTraceProcess() { |
| | | //获取所有设备 |
| | | List<Equipment> equipmentList = equipmentService.list(); |
| | |
| | | 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); |
| | | } |
| | | |
| | | private Map<String, List<MdcEquipmentRunningSectionDto>> logCharts(MdcEquipmentRunningSectionVo equipmentRunningSectionVo, String date) { |
| | | Map<String, List<MdcEquipmentRunningSectionDto>> map = new HashMap<>(); |
| | | Map<String, List<MdcEquipmentRunningSectionDto>> map = new HashMap<>(); |
| | | List<MdcEquipmentRunningSectionDto> normal = new ArrayList<>(); |
| | | List<MdcEquipmentRunningSectionDto> waring = new ArrayList<>(); |
| | | //运行 |
| | |
| | | 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); |
| | | } |
| | | // if (ert.getDuration() > 0) { |
| | | erts.add(ert); |
| | | // } |
| | | } else { |
| | | long count = differentSecond / 86400; |
| | | if (count % 86400 > 0) { |