¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.mdc.service.impl; |
| | | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.jeecg.modules.mdc.dto.MdcAlarmAnalyzeDto; |
| | | import org.jeecg.modules.mdc.dto.MdcAlarmDto; |
| | | import org.jeecg.modules.mdc.dto.MdcAlarmTrendDto; |
| | | import org.jeecg.modules.mdc.entity.MdcEquipmentRunningSection; |
| | | import org.jeecg.modules.mdc.service.IMdcEquipmentRunningSectionService; |
| | | import org.jeecg.modules.mdc.service.IMdcEquipmentService; |
| | | import org.jeecg.modules.mdc.service.MdcEquipmentAlarmAnalyzeService; |
| | | import org.jeecg.modules.mdc.util.DateUtils; |
| | | import org.jeecg.modules.mdc.vo.MdcAlarmAnalyzeQueryVo; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @author: LiuS |
| | | * @create: 2023-09-06 17:31 |
| | | */ |
| | | @Service |
| | | public class MdcEquipmentAlarmAnalyzeServiceImpl implements MdcEquipmentAlarmAnalyzeService { |
| | | |
| | | @Resource |
| | | private IMdcEquipmentRunningSectionService mdcEquipmentRunningSectionService; |
| | | |
| | | @Resource |
| | | private IMdcEquipmentService mdcEquipmentService; |
| | | |
| | | @Override |
| | | public List<MdcAlarmAnalyzeDto> alarmList(String userId, MdcAlarmAnalyzeQueryVo vo) { |
| | | List<MdcAlarmAnalyzeDto> result = new ArrayList<>(); |
| | | List<String> equipmentIds = new ArrayList<>(); |
| | | if (StringUtils.isNotEmpty(vo.getParentId()) && StringUtils.isEmpty(vo.getEquipmentId())) { |
| | | if ("2".equals(vo.getTypeTree())) { |
| | | // é¨é¨å±çº§ |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, vo.getParentId()); |
| | | } else { |
| | | // 产线å±çº§ |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, vo.getParentId()); |
| | | } |
| | | } else if (StringUtils.isNotEmpty(vo.getEquipmentId())) { |
| | | // åå°è®¾å¤ä¿¡æ¯ |
| | | vo.setEquipmentIdList(Collections.singletonList(vo.getEquipmentId())); |
| | | } else { |
| | | // æ¥è¯¢ç¨æ·æ¥æçææè®¾å¤ä¿¡æ¯ |
| | | if ("2".equals(vo.getTypeTree())) { |
| | | // é¨é¨å±çº§ |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null); |
| | | } else { |
| | | // 产线å±çº§ |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null); |
| | | } |
| | | } |
| | | if (vo.getEquipmentIdList() == null || vo.getEquipmentIdList().isEmpty()) { |
| | | vo.setEquipmentIdList(equipmentIds); |
| | | } |
| | | if (vo.getEquipmentIdList() == null || vo.getEquipmentIdList().isEmpty()) { |
| | | return result; |
| | | } else { |
| | | vo.setStartDate(DateUtils.format(DateUtils.toDate(vo.getStartDate(), DateUtils.STRDATE), DateUtils.STR_DATE) + " 00:00:00"); |
| | | vo.setEndDate(DateUtils.format(DateUtils.addDays(DateUtils.toDate(vo.getEndDate(), DateUtils.STRDATE), 1), DateUtils.STR_DATE) + " 00:00:00"); |
| | | // æ¥è¯¢ |
| | | List<MdcEquipmentRunningSection> mdcEquipmentRunningSections = mdcEquipmentRunningSectionService.findAlarmList(vo); |
| | | Map<String, MdcAlarmAnalyzeDto> map = new HashMap<>(); |
| | | for (MdcEquipmentRunningSection mdcEquipmentRunningSection : mdcEquipmentRunningSections) { |
| | | if (map.containsKey(mdcEquipmentRunningSection.getAlarm())) { |
| | | MdcAlarmAnalyzeDto mdcAlarmAnalyzeDto = map.get(mdcEquipmentRunningSection.getAlarm()); |
| | | mdcAlarmAnalyzeDto.setCount(mdcAlarmAnalyzeDto.getCount() + 1); |
| | | mdcAlarmAnalyzeDto.setTimeCount(mdcAlarmAnalyzeDto.getTimeCount().add(new BigDecimal(mdcEquipmentRunningSection.getDuration()))); |
| | | map.put(mdcEquipmentRunningSection.getAlarm(), mdcAlarmAnalyzeDto); |
| | | } else { |
| | | MdcAlarmAnalyzeDto mdcAlarmAnalyzeDto = new MdcAlarmAnalyzeDto(); |
| | | mdcAlarmAnalyzeDto.setAlarmCode(mdcEquipmentRunningSection.getAlarm()); |
| | | mdcAlarmAnalyzeDto.setCount(1); |
| | | mdcAlarmAnalyzeDto.setTimeCount(new BigDecimal(mdcEquipmentRunningSection.getDuration())); |
| | | map.put(mdcEquipmentRunningSection.getAlarm(), mdcAlarmAnalyzeDto); |
| | | } |
| | | } |
| | | if (!map.isEmpty()) { |
| | | result = new ArrayList<>(map.values()); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public MdcAlarmTrendDto alarmTrend(String userId, MdcAlarmAnalyzeQueryVo vo) { |
| | | MdcAlarmTrendDto result = new MdcAlarmTrendDto(); |
| | | List<String> equipmentIds = new ArrayList<>(); |
| | | if (StringUtils.isNotEmpty(vo.getParentId()) && StringUtils.isEmpty(vo.getEquipmentId())) { |
| | | if ("2".equals(vo.getTypeTree())) { |
| | | // é¨é¨å±çº§ |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, vo.getParentId()); |
| | | } else { |
| | | // 产线å±çº§ |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, vo.getParentId()); |
| | | } |
| | | } else if (StringUtils.isNotEmpty(vo.getEquipmentId())) { |
| | | // åå°è®¾å¤ä¿¡æ¯ |
| | | vo.setEquipmentIdList(Collections.singletonList(vo.getEquipmentId())); |
| | | } else { |
| | | // æ¥è¯¢ç¨æ·æ¥æçææè®¾å¤ä¿¡æ¯ |
| | | if ("2".equals(vo.getTypeTree())) { |
| | | // é¨é¨å±çº§ |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null); |
| | | } else { |
| | | // 产线å±çº§ |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null); |
| | | } |
| | | } |
| | | if (vo.getEquipmentIdList() == null || vo.getEquipmentIdList().isEmpty()) { |
| | | vo.setEquipmentIdList(equipmentIds); |
| | | } |
| | | if (vo.getEquipmentIdList() != null && !vo.getEquipmentIdList().isEmpty()) { |
| | | result.setEquipmentList(vo.getEquipmentIdList()); |
| | | List<MdcAlarmDto> equipmentCountList = new ArrayList<>(); |
| | | String startDate = DateUtils.format(DateUtils.toDate(vo.getStartDate(), DateUtils.STRDATE), DateUtils.STR_DATE) + " 00:00:00"; |
| | | String endDate = DateUtils.format(DateUtils.addDays(DateUtils.toDate(vo.getEndDate(), DateUtils.STRDATE), 1), DateUtils.STR_DATE) + " 00:00:00"; |
| | | for (String equipmentId : result.getEquipmentList()) { |
| | | MdcAlarmDto mdcAlarmDto = new MdcAlarmDto(); |
| | | mdcAlarmDto.setKey(equipmentId); |
| | | Integer count = mdcEquipmentRunningSectionService.findAlarmCount(equipmentId, startDate, endDate, vo.getAlarmCode()); |
| | | mdcAlarmDto.setCount(count); |
| | | equipmentCountList.add(mdcAlarmDto); |
| | | } |
| | | result.setEquipmentCountList(equipmentCountList); |
| | | } |
| | | |
| | | Date start = DateUtils.toDate(vo.getStartDate(), DateUtils.STRDATE); |
| | | Date end = DateUtils.toDate(vo.getEndDate(), DateUtils.STRDATE); |
| | | List<String> dateList = DateUtils.getDatesStringLists(start, end); |
| | | result.setDateList(dateList); |
| | | List<String> datesStringList = DateUtils.getDatesStringList(start, end); |
| | | List<MdcAlarmDto> dateCountList = new ArrayList<>(); |
| | | for (String date : datesStringList) { |
| | | MdcAlarmDto mdcAlarmDto = new MdcAlarmDto(); |
| | | mdcAlarmDto.setKey(DateUtils.format(DateUtils.toDate(date, DateUtils.STR_DATE), DateUtils.STR_MMDD)); |
| | | String startDate = date + " 00:00:00"; |
| | | String endDate = DateUtils.format(DateUtils.addDays(DateUtils.toDate(date, DateUtils.STR_DATE), 1), DateUtils.STR_DATE) + " 00:00:00"; |
| | | Integer count = mdcEquipmentRunningSectionService.findAlarmCountByDate(startDate, endDate, vo); |
| | | mdcAlarmDto.setCount(count); |
| | | dateCountList.add(mdcAlarmDto); |
| | | } |
| | | result.setDateCountList(dateCountList); |
| | | return result; |
| | | } |
| | | } |