kongdeqiang
2023-07-03 3ef994024caff28a57cb3812f222030b3cf71d30
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
package com.boying.job;
 
import cn.hutool.core.lang.UUID;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.boying.entity.DongHuanBaoJing;
import com.boying.entity.SnmpInfo;
import com.boying.entity.WarnLog;
import com.boying.service.DongHuanBaoJingService;
import com.boying.service.WarnService;
import com.boying.util.SnmpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.time.LocalDate;
import java.util.List;
 
/**
 * @author kdq
 * @version 1.0.0
 * @ClassName BaoJingScheduled.java
 * @Description TODO
 * @createTime 2023年07月01日 14:18:00
 */
@Slf4j
@Component
public class BaoJingScheduled {
 
    @Autowired
    private DongHuanBaoJingService dongHuanBaoJingService;
    @Autowired
    private WarnService warnService;
    private Boolean taskFlag = false;
 
    @Scheduled(cron = "0 0/6 * * * ?")
    public void execute() throws Exception {
        if (taskFlag == true) {
            System.out.println("正在运行,强制退出-------》");
            return;
        }else {
            SnmpInfo snmpInfo = new SnmpInfo();
            snmpInfo.setSnmpCommunity("private");
            snmpInfo.setSnmpVersion("1");
            snmpInfo.setSnmpPort("161");
            snmpInfo.setHostName("139.24.190.121");
            QueryWrapper<DongHuanBaoJing> wrapper = new QueryWrapper<>();
            wrapper.select(" id,oid,device_name,bian_liang_name,value,type");
            List<DongHuanBaoJing> list = dongHuanBaoJingService.list(wrapper);
            for (DongHuanBaoJing dongHuanBaoJing : list) {
                String s = SnmpUtil.snmpGetTest(snmpInfo, dongHuanBaoJing.getOid());
                if(s != null){
                   dongHuanBaoJing.setValue(s);
                   dongHuanBaoJingService.updateById(dongHuanBaoJing);
                   if(s.equals("1")&& !dongHuanBaoJing.getDeviceName().contains("机房门")&& !dongHuanBaoJing.getDeviceName().contains("机房漏水")
                           && !dongHuanBaoJing.getBianLiangName().contains("负载保护")){
                       WarnLog warnLog = new WarnLog();
                       warnLog.setId(UUID.fastUUID().toString(true));
                       warnLog.setWarnDate(LocalDate.now());
                       warnLog.setName(dongHuanBaoJing.getDeviceName());
                       warnLog.setContent(dongHuanBaoJing.getBianLiangName()+"异常");
                       WarnLog type = getType(warnLog);
                       warnService.save(type);
                   }else if(s.equals("0")&&(dongHuanBaoJing.getDeviceName().contains("机房门") || dongHuanBaoJing.getDeviceName().contains("机房漏水")
                           || dongHuanBaoJing.getBianLiangName().contains("负载保护")) ){
                       WarnLog warnLog = new WarnLog();
                       warnLog.setId(UUID.fastUUID().toString(true));
                       warnLog.setWarnDate(LocalDate.now());
                       warnLog.setName(dongHuanBaoJing.getDeviceName());
                       warnLog.setContent(dongHuanBaoJing.getBianLiangName()+"异常");
                       WarnLog type = getType(warnLog);
                       warnService.save(type);
                   }
                }else {
                    System.out.println(dongHuanBaoJing.getOid()+" 检测异常");
                }
 
            }
        }
    }
 
    private WarnLog getType(WarnLog warnLog){
        switch (warnLog.getName()){
            case "机房湿温度1":
                warnLog.setType(5);
                break;
            case "机房湿温度2":
                warnLog.setType(5);
                break;
            case "机房湿温度3":
                warnLog.setType(5);
                break;
            case "机房湿温度4":
                warnLog.setType(5);
                break;
            case "UPS机房湿温度":
                warnLog.setType(5);
                break;
            case "UPS1":
                warnLog.setType(3);
                break;
            case "UPS2":
                warnLog.setType(3);
                break;
            case "UPS3":
                warnLog.setType(3);
                break;
            case "UPS4":
                warnLog.setType(3);
                break;
            case "UPS机房配电输入":
                warnLog.setType(3);
                break;
            case "电池1":
                warnLog.setType(3);
                break;
            case "电池2":
                warnLog.setType(3);
                break;
            case "电池3":
                warnLog.setType(3);
                break;
            case "电池4":
                warnLog.setType(3);
                break;
            case "电池5":
                warnLog.setType(3);
                break;
            case "电池6":
                warnLog.setType(3);
                break;
            case "机房门":
                warnLog.setType(7);
                break;
            case "机房漏水西":
                warnLog.setType(6);
                break;
            case "机房漏水东":
                warnLog.setType(6);
                break;
            case "UPS机房漏水":
                warnLog.setType(6);
                break;
            case "UPS机房空调5(STULZ-CCU121A)":
                warnLog.setType(4);
                break;
            case "UPS机房空调6(STULZ-CCU121A)":
                warnLog.setType(4);
                break;
            case "楼道正门":
                warnLog.setType(7);
                break;
            case "中心机房空调1":
                warnLog.setType(4);
                break;
            case "中心机房空调2":
                warnLog.setType(4);
                break;
            case "中心机房空调3":
                warnLog.setType(4);
                break;
            case "中心机房空调4":
                warnLog.setType(4);
                break;
            case "高新区温湿度":
                warnLog.setType(5);
                break;
            case "路北区温湿度":
                warnLog.setType(5);
                break;
            case "路南区温湿度":
                warnLog.setType(5);
                break;
        }
        return warnLog;
    }
}