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.time.LocalDateTime;
|
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(LocalDateTime.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(LocalDateTime.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;
|
}
|
}
|