lius
2023-09-07 aec08e3c84590f50f5673a24ce9367f82bdb872c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package org.jeecg.modules.mdc.service.impl;
 
import io.swagger.models.auth.In;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.jeecg.modules.mdc.dto.MdcAlarmAnalyzeDto;
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.DayUtilizationRateContrastQueryVo;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.logging.Handler;
 
/**
 * @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, DayUtilizationRateContrastQueryVo 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;
    }
}