VVT789
2025-04-18 cc273f0fb102a905033641fdd4e9fc325c52e086
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package com.zhitan.alarm.services.impl;
 
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhitan.alarm.domain.HistoryAlarm;
import com.zhitan.alarm.domain.JkHistoryAlarm;
import com.zhitan.alarm.mapper.HistoryAlarmMapper;
import com.zhitan.alarm.services.IHistoryAlarmService;
import com.zhitan.basicdata.domain.MeterImplement;
import com.zhitan.basicdata.mapper.MeterImplementMapper;
import com.zhitan.common.enums.TimeType;
import com.zhitan.common.utils.DateUtils;
import com.zhitan.common.utils.PageUtils;
import com.zhitan.common.utils.StringUtils;
import com.zhitan.model.domain.EnergyIndex;
import com.zhitan.model.domain.ModelNode;
import com.zhitan.model.domain.NodeIndex;
import com.zhitan.model.domain.vo.ModelNodeIndexInfo;
import com.zhitan.model.mapper.EnergyIndexMapper;
import com.zhitan.model.mapper.ModelNodeMapper;
import com.zhitan.model.mapper.NodeIndexMapper;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
 
@AllArgsConstructor
 
@Service
public class HistoryAlarmServiceImpl implements IHistoryAlarmService {
 
    @Resource
    private HistoryAlarmMapper historyAlarmMapper;
 
    @Resource
    private MeterImplementMapper meterImplementMapper;
 
    @Resource
    private ModelNodeMapper modelNodeMapper;
    @Resource
    private NodeIndexMapper nodeIndexMapper;
    @Resource
    private EnergyIndexMapper energyIndexMapper;
 
 
    @Override
    public List<HistoryAlarm> getHistoryAlarm(Date beginTime, Date endTime) {
        return null;
    }
 
    @Override
    public List<HistoryAlarm> getHistoryAlarm(Date beginTime, Date endTime, TimeType timeType) {
        return null;
    }
 
    @Override
    public List<HistoryAlarm> getHistoryAlarm(Date beginTime, Date endTime, String alarmType) {
        return null;
    }
 
    @Override
    public List<JkHistoryAlarm> selectJkHistoryAlarmList(JkHistoryAlarm jkHistoryAlarm) {
        return historyAlarmMapper.selectJkHistoryAlarmList(jkHistoryAlarm);
    }
 
    @Override
    public List<JkHistoryAlarm> selectJkHistoryAlarmListExcel(JkHistoryAlarm jkHistoryAlarm) {
        return historyAlarmMapper.selectJkHistoryAlarmListExcel(jkHistoryAlarm);
    }
 
    /**
     * 实时检测 功能 的多 sheet页  展示 组态图  测点 报警信息
     *
     * @param jkHistoryAlarm
     * @return
     */
    @Override
    public List<JkHistoryAlarm> selectHistoryAlarmNoteList(JkHistoryAlarm jkHistoryAlarm) {
        return historyAlarmMapper.selectHistoryAlarmNoteList(jkHistoryAlarm);
    }
 
    @Override
    public void updateHistoryAlarm(String alarmCode, HistoryAlarm historyAlarm) {
        historyAlarmMapper.updateHistoryAlarm(alarmCode, historyAlarm);
    }
 
    /**
     * 获取历史报警分页数据
     *
     * @param historyAlarm
     * @return
     */
    @Override
    public Page<JkHistoryAlarm> selectHistoryAlarmPageList(JkHistoryAlarm historyAlarm) {
        Page<JkHistoryAlarm> pageInfo = PageUtils.getPageInfo(JkHistoryAlarm.class);
 
        List<String> indexIdList = new ArrayList<>();
        if ("ALL".equals(historyAlarm.getEierarchyFlag())) {
 
            ModelNode modelNode = modelNodeMapper.selectModelNodeById(historyAlarm.getNodeId());
            List<ModelNodeIndexInfo> modelNodeIndexInfoList =
                    modelNodeMapper.getAllModelNodeIndexByAddress(modelNode.getModelCode(), modelNode.getAddress());
            if (StringUtils.isNotEmpty(historyAlarm.getIndexName())) {
                modelNodeIndexInfoList = modelNodeIndexInfoList.stream()
                        .filter(modelNodeIndexInfo -> modelNodeIndexInfo.getIndexName().contains(historyAlarm.getIndexName()))
                        .collect(Collectors.toList());
            }
            if (ObjectUtils.isNotEmpty(historyAlarm.getIndexType())) {
                modelNodeIndexInfoList = modelNodeIndexInfoList.stream()
                        .filter(modelNodeIndexInfo -> historyAlarm.getIndexType().equals(modelNodeIndexInfo.getIndexType()))
                        .collect(Collectors.toList());
            }
            indexIdList = modelNodeIndexInfoList.stream().map(ModelNodeIndexInfo::getIndexId).collect(Collectors.toList());
 
        } else {
 
            LambdaQueryWrapper<NodeIndex> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(NodeIndex::getNodeId, historyAlarm.getNodeId());
            List<NodeIndex> nodeIndexList = nodeIndexMapper.selectList(queryWrapper);
            List<String> allIndexIdList = nodeIndexList.stream().map(NodeIndex::getIndexId).collect(Collectors.toList());
            if (ObjectUtils.isNotEmpty(allIndexIdList)) {
                List<EnergyIndex> indexList = energyIndexMapper.selectEnergyIndexByIds(allIndexIdList);
                if (ObjectUtils.isNotEmpty(historyAlarm.getIndexName())) {
                    indexList = indexList.stream().filter(energyIndex -> energyIndex.getName().contains(historyAlarm.getIndexName())).collect(Collectors.toList());
                }
                if (ObjectUtils.isNotEmpty(historyAlarm.getIndexType())) {
                    indexList = indexList.stream().filter(energyIndex -> historyAlarm.getIndexType().equals(energyIndex.getIndexTypeCode())).collect(Collectors.toList());
                }
                indexIdList = indexList.stream().map(EnergyIndex::getIndexId).collect(Collectors.toList());
            }
        }
 
        if (ObjectUtils.isEmpty(indexIdList)) {
            return pageInfo;
        }
 
        //时间处理 如果不传时间默认查询当天的数据
        Date endTime = DateUtils.parseDate(historyAlarm.getEndTime());
        if (ObjectUtils.isEmpty(endTime)) {
            endTime = DateUtil.endOfDay(DateUtils.getNowDate());
        }
        Date beginTime = DateUtils.parseDate(historyAlarm.getBeginTime());
        if (ObjectUtils.isEmpty(beginTime)) {
            beginTime = DateUtil.beginOfDay(DateUtils.getNowDate());
        }
 
        return historyAlarmMapper.getHistoryAlarmList(beginTime, endTime,indexIdList, pageInfo);
    }
 
}