whycxzp
2022-11-16 3919d59dacc6ed443feb9a60e567cf51a3014bb4
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.AlarmDaoFactory;
import com.whyc.dto.Response;
import com.whyc.mapper.PwrdevAlarmMapper;
import com.whyc.mapper.PwrdevAlarmParamMapper;
import com.whyc.pojo.PwrdevAlarm;
import com.whyc.pojo.PwrdevAlarmParam;
import com.whyc.pojo.UserInf;
import com.whyc.util.ActionUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.ListIterator;
import java.util.concurrent.atomic.AtomicBoolean;
 
@Service
public class PwrdevAlarmService {
 
    @Resource
    private PwrdevAlarmMapper mapper;
 
    @Resource
    private PwrdevAlarmParamMapper paramMapper;
 
    //电源实时告警查询
    public Response getAllPage(PwrdevAlarm pwrdevAlarm){
        //分页信息
        PageHelper.startPage(pwrdevAlarm.getPage().getPageCurr(), pwrdevAlarm.getPage().getPageSize());
        pwrdevAlarm.setUsrId(ActionUtil.getUser().getUId().intValue());
        List<PwrdevAlarm> list=mapper.getAllPage(pwrdevAlarm);
        for (PwrdevAlarm p:list) {
            p.setAlarmName(AlarmDaoFactory.getAllAlarmName(p.getAlmType()));
            if(p.getAlmIndex()!=0){
                p.setAlarmName(p.getAlarmName().replace("N","第"+p.getAlmIndex()+"路"));
            }
        }
        PageInfo pageInfo=new PageInfo(list);
        return new Response().set(1,pageInfo);
    }
    //电源实时告警查询-webSocket
    public Response getAllPageOfWebSocket(PwrdevAlarm pwrdevAlarm){
        //分页信息
        PageHelper.startPage(pwrdevAlarm.getPage().getPageCurr(), pwrdevAlarm.getPage().getPageSize());
        List<PwrdevAlarm> list=mapper.getAllPage(pwrdevAlarm);
        for (PwrdevAlarm p:list) {
            p.setAlarmName(AlarmDaoFactory.getAllAlarmName(p.getAlmType()));
            if(p.getAlmIndex()!=0){
                p.setAlarmName(p.getAlarmName().replace("N","第"+p.getAlmIndex()+"路"));
            }
        }
        PageInfo pageInfo=new PageInfo(list);
        return new Response().set(1,pageInfo);
    }
 
    //电源实时告警查询-webSocket
    @Transactional
    public Response getSendPwrAlarmOfWebSocket(Integer uId){
        List<PwrdevAlarm> list=mapper.getSendPwrdevAlarm(uId);
        Date now = new Date();
        ListIterator<PwrdevAlarm> it = list.listIterator();
        while (it.hasNext()){
            PwrdevAlarm adata = it.next();
            if(adata.getAlmLevel()==1 && adata.getRecordTime()!=null && now.getTime()-adata.getRecordTime().getTime()<24*3600000){
                it.remove();
            }
            if(adata.getAlmLevel()==2 && adata.getRecordTime()!=null && now.getTime()-adata.getRecordTime().getTime()<7*24*3600000){
                it.remove();
            }
            if(adata.getAlmLevel()==3 && adata.getRecordTime()!=null && now.getTime()-adata.getRecordTime().getTime()<30*7*24*3600000){
                it.remove();
            }
            adata.setAlarmName(AlarmDaoFactory.getAllAlarmName(adata.getAlmType()));
            if(adata.getAlmIndex()!=0){
                adata.setAlarmName(adata.getAlarmName().replace("N","第"+adata.getAlmIndex()+"路"));
            }
        }
        return new Response().set(1,list);
 
    }
    //电源实时确认告警
    public Response confirm(int num) {
        UpdateWrapper wrapper=new UpdateWrapper();
        wrapper.set("alm_is_confirmed",1);
        wrapper.set("alm_confirmed_time",new SimpleDateFormat(ActionUtil.time_yyyyMMddHHmmss).format(new Date()));
        wrapper.eq("num",num);
        int flag=mapper.update(null,wrapper);
        return new Response().set(flag);
    }
    //电源实时取消告警
    public Response cancle(int num) {
        UpdateWrapper wrapper=new UpdateWrapper();
        wrapper.set("alm_is_confirmed",2);
        wrapper.set("alm_confirmed_time",new SimpleDateFormat(ActionUtil.time_yyyyMMddHHmmss).format(new Date()));
        wrapper.eq("num",num);
        int flag=mapper.update(null,wrapper);
        return new Response().set(flag);
    }
 
    //电源实时删除告警
    public Response delete(int num) {
        UpdateWrapper wrapper=new UpdateWrapper();
        wrapper.eq("num",num);
        int flag=mapper.delete(wrapper);
        return new Response().set(flag);
    }
    //电源实时删除告警批量
    @Transactional
    public Response deletepro(List<Integer> list) {
        int flag=0;
        for (Integer num:list) {
            UpdateWrapper wrapper = new UpdateWrapper<>();
            // 通过num删除
            wrapper.eq("num",num);
            flag=mapper.delete(wrapper);
        }
        return  new Response().set(flag);
    }
    //电源告警个数
    public Response getAlarmNum() {
        UserInf uinf= ActionUtil.getUser();
        int powerAlarmNum=mapper.getAlarmNum(uinf.getUId().intValue());
        return  new Response().set(1,powerAlarmNum);
    }
    //通信电源告警--认证送检-配电柜专用
    public Response getAllPage2(PwrdevAlarm pwrdevAlarm) {
        //分页信息
        PageHelper.startPage(pwrdevAlarm.getPage().getPageCurr(), pwrdevAlarm.getPage().getPageSize());
        pwrdevAlarm.setUsrId(ActionUtil.getUser().getUId().intValue());
        List<PwrdevAlarm> list=mapper.getAllPage2(pwrdevAlarm);
        List<String> tableList = paramMapper.getParamList();
        //取第一条记录,即param表
        String alarmParamTableName = tableList.get(0);
        List<PwrdevAlarmParam>  paramList=paramMapper.searchAll(alarmParamTableName);
        for (PwrdevAlarm p:list) {
            int almType = p.getAlmType();
            AtomicBoolean matchFlag = new AtomicBoolean(false);
            paramList.stream().forEach(param->{
                if(param.getAlarmId() == almType){
                    p.setAlarmName(param.getAlarmName());
                    matchFlag.set(true);
                    return;
                }
            });
            if(!matchFlag.get()){
                p.setAlarmName("未知告警类型");
            }
            int alarmIndex = p.getAlmIndex();
            if(alarmIndex!=0){
                p.setAlmIndex(alarmIndex);
                p.setAlarmName(p.getAlarmName().replace("N","第"+alarmIndex+"路"));
            }
        }
        PageInfo pageInfo=new PageInfo(list);
        return new Response().set(1,pageInfo);
    }
    //通信电源告警--认证送检-配电柜专用-webSocket
    public Response getAllPage2OfWebSocket(PwrdevAlarm pwrdevAlarm) {
        //分页信息
        PageHelper.startPage(pwrdevAlarm.getPage().getPageCurr(), pwrdevAlarm.getPage().getPageSize());
        List<PwrdevAlarm> list=mapper.getAllPage2(pwrdevAlarm);
        List<String> tableList = paramMapper.getParamList();
        //取第一条记录,即param表
        String alarmParamTableName = tableList.get(0);
        List<PwrdevAlarmParam>  paramList=paramMapper.searchAll(alarmParamTableName);
        for (PwrdevAlarm p:list) {
            int almType = p.getAlmType();
            AtomicBoolean matchFlag = new AtomicBoolean(false);
            paramList.stream().forEach(param->{
                if(param.getAlarmId() == almType){
                    p.setAlarmName(param.getAlarmName());
                    matchFlag.set(true);
                    return;
                }
            });
            if(!matchFlag.get()){
                p.setAlarmName("未知告警类型");
            }
            int alarmIndex = p.getAlmIndex();
            if(alarmIndex!=0){
                p.setAlmIndex(alarmIndex);
                p.setAlarmName(p.getAlarmName().replace("N","第"+alarmIndex+"路"));
            }
        }
        PageInfo pageInfo=new PageInfo(list);
        return new Response().set(1,pageInfo);
    }
 
    public List<PwrdevAlarm> getList(Long userId) {
        return mapper.getList(userId);
    }
}