|
|
@ -1,6 +1,7 @@ |
|
|
|
package com.zc.business.controller; |
|
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import cn.hutool.core.io.unit.DataUnit; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
@ -21,7 +22,9 @@ import com.zc.business.constant.DeviceTypeConstants; |
|
|
|
import com.zc.business.domain.DcDevice; |
|
|
|
import com.zc.business.domain.DcDoor; |
|
|
|
import com.zc.business.domain.DcEvent; |
|
|
|
import com.zc.business.domain.DcEventProcess; |
|
|
|
import com.zc.business.domain.DcSmokeRecord; |
|
|
|
import com.zc.business.domain.DcSnmpAlarm; |
|
|
|
import com.zc.business.enums.UniversalEnum; |
|
|
|
import com.zc.business.interfaces.OperationLog; |
|
|
|
import com.zc.business.request.DeviceGetPropertiesOperateRequest; |
|
|
@ -30,6 +33,8 @@ import com.zc.business.service.IDcWarningService; |
|
|
|
import com.zc.common.core.httpclient.OkHttp; |
|
|
|
import com.zc.common.core.httpclient.exception.HttpException; |
|
|
|
import com.zc.common.core.httpclient.request.RequestParams; |
|
|
|
import com.zc.common.core.websocket.WebSocketService; |
|
|
|
import com.zc.common.core.websocket.constant.WebSocketEvent; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import io.swagger.annotations.ApiParam; |
|
|
@ -37,6 +42,7 @@ import io.swagger.v3.oas.annotations.Parameter; |
|
|
|
import okhttp3.OkHttpClient; |
|
|
|
import okhttp3.Request; |
|
|
|
import okhttp3.Response; |
|
|
|
import org.aspectj.weaver.patterns.HasMemberTypePattern; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.http.converter.xml.AbstractJaxb2HttpMessageConverter; |
|
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
@ -53,6 +59,9 @@ import java.math.RoundingMode; |
|
|
|
import java.text.DecimalFormat; |
|
|
|
import java.text.ParseException; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.time.temporal.ChronoUnit; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.ExecutionException; |
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
@ -81,6 +90,7 @@ private VideoController videoController; |
|
|
|
|
|
|
|
private static final String DOORSTATUS = "doorStatus";//redis策略缓存的key
|
|
|
|
private static final String SOMKEVALUE = "smokeValue";//redis策略缓存的key
|
|
|
|
private static final String ALARMVALUE = "alarmValue";//redis策略缓存的key
|
|
|
|
/* |
|
|
|
@Value("${iot.address}") |
|
|
|
private String iotAddress; |
|
|
@ -1846,8 +1856,13 @@ private VideoController videoController; |
|
|
|
dcSmokeRecord.setSmokeValue(value); |
|
|
|
dcSmokeRecord.setCreateTime(DateUtils.getNowDate()); |
|
|
|
dcSmokeRecord.setIotDeviceId(device.getIotDeviceId()); |
|
|
|
dcSmokeRecord.setPushTime(DateUtils.getNowDate()); |
|
|
|
dcDeviceService.insertSmokeRecord(dcSmokeRecord); |
|
|
|
redisCache.setCacheMapValue(SOMKEVALUE,device.getIotDeviceId(),value); |
|
|
|
HashMap<Object, Object> hashMap = new HashMap<>(); |
|
|
|
hashMap.put("content",device.getDeviceName()+"烟感异常,烟感值为"+value); |
|
|
|
hashMap.put("time",DateUtils.getNowDate()); |
|
|
|
WebSocketService.broadcast("deviceAlarm",hashMap); |
|
|
|
}else { |
|
|
|
if (Integer.parseInt(value)==Integer.parseInt(cacheMapValue)){ //最新值与之前的缓存值一样,不予处理
|
|
|
|
continue; |
|
|
@ -1859,7 +1874,27 @@ private VideoController videoController; |
|
|
|
dcSmokeRecord.setIotDeviceId(device.getIotDeviceId()); |
|
|
|
dcSmokeRecord.setSmokeValue(value); |
|
|
|
dcSmokeRecord.setUpdateTime(DateUtils.getNowDate()); |
|
|
|
dcDeviceService.updateSmokeValue(dcSmokeRecord);//修改数据值
|
|
|
|
DcSmokeRecord dcSmokeRecordValue = dcDeviceService.selectSmokeRecordIotId(device.getIotDeviceId()); |
|
|
|
if (dcSmokeRecordValue!=null&&dcSmokeRecordValue.getPushTime()!=null){ |
|
|
|
String pushTime = dcSmokeRecordValue.getPushTime().toString(); |
|
|
|
String nowDate = DateUtils.getNowDate().toString(); |
|
|
|
// 解析 pushTime(根据实际格式调整)
|
|
|
|
DateTimeFormatter pushTimeFormatter = DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH); // 假设 pushTime 是此格式
|
|
|
|
LocalDateTime dateTime1 = LocalDateTime.parse(pushTime, pushTimeFormatter); |
|
|
|
// 解析 nowDate(修复格式)
|
|
|
|
DateTimeFormatter nowDateFormatter = DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH); |
|
|
|
LocalDateTime dateTime2 = LocalDateTime.parse(nowDate, nowDateFormatter); |
|
|
|
long diffInMillis = ChronoUnit.MINUTES.between(dateTime1, dateTime2); |
|
|
|
if (diffInMillis> 30) { |
|
|
|
// 时间差大于30分钟
|
|
|
|
dcSmokeRecord.setPushTime(DateUtils.getObtainDateAfter(1)); |
|
|
|
HashMap<Object, Object> hashMap = new HashMap<>(); |
|
|
|
hashMap.put("content",device.getDeviceName()+"烟感异常,烟感值为"+value); |
|
|
|
hashMap.put("time",DateUtils.getNowDate()); |
|
|
|
WebSocketService.broadcast("deviceAlarm",hashMap); |
|
|
|
} |
|
|
|
dcDeviceService.updateSmokeValue(dcSmokeRecord);//修改数据值
|
|
|
|
} |
|
|
|
} |
|
|
|
}else { |
|
|
|
String cacheMapValue = redisCache.getCacheMapValue(SOMKEVALUE, device.getIotDeviceId());//查询缓存
|
|
|
@ -1869,6 +1904,7 @@ private VideoController videoController; |
|
|
|
redisCache.delCacheMapValue(SOMKEVALUE,device.getIotDeviceId()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return AjaxResult.success(); |
|
|
|
} |
|
|
|
//设备箱机箱门状态采集
|
|
|
@ -1966,7 +2002,7 @@ private VideoController videoController; |
|
|
|
} |
|
|
|
//一体机柜空调定时调用,采数据
|
|
|
|
//@PostMapping("/integratedCabinetAir2")
|
|
|
|
@Scheduled(cron = "0 7 * * * *") |
|
|
|
@Scheduled(cron = "40 0,30 * * * *") |
|
|
|
public AjaxResult airConditioning() throws InterruptedException, IOException, HttpException { |
|
|
|
DcDevice dcDevice = new DcDevice(); |
|
|
|
dcDevice.setDeviceType(UniversalEnum.EIGHTEEN.getValue()); |
|
|
@ -2018,5 +2054,123 @@ private VideoController videoController; |
|
|
|
} |
|
|
|
return AjaxResult.success(resultArray); |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("/snmpUpsAlarm") |
|
|
|
public AjaxResult snmpUpsAlarm() throws IOException, HttpException { |
|
|
|
ArrayList<HashMap> objects = new ArrayList<>(); |
|
|
|
HashMap<String, String> hashMap = new HashMap<>(); |
|
|
|
hashMap.put("10.0.81.248-SNMP","大学城UPS-01+10.0.81.248"); hashMap.put("SNMP","大学城UPS-02+10.0.81.250"); |
|
|
|
hashMap.put("10.0.111.119-SNMP","分中心1号UPS+10.0.111.119"); hashMap.put("10.0.111.118-SNMP","分中心2号UPS+10.0.111.119"); |
|
|
|
hashMap.put("10.0.11.248-SNMP","长清UPS-01+10.0.11.248");hashMap.put("10.0.11.250-SNMP","长清UPS-02+10.0.11.250"); |
|
|
|
hashMap.put("10.0.21.248-SNMP","孝里USP-01+10.0.21.248"); hashMap.put("10.0.21.250-SNMP","孝里UPS-02+10.0.21.250"); |
|
|
|
hashMap.put("10.0.91.248-SNMP","安城UPS-01+10.0.91.248"); hashMap.put("10.0.91.250-SNMP","安城UPS-02+10.0.91.250"); |
|
|
|
hashMap.put("10.0.31.248-SNMP","平阴USP-01+10.0.31.248"); hashMap.put("10.0.31.250-SNMP","平阴UPS-02+10.0.31.250"); |
|
|
|
hashMap.put("10.0.41.248-SNMP","平阴南UPS-01+10.0.41.248"); hashMap.put("10.0.41.250-SNMP","平阴南UPS-02+10.0.41.250"); |
|
|
|
hashMap.put("10.0.51.248-SNMP","东平UPS-01+10.0.51.248");hashMap.put("10.0.51.250-SNMP","东平UPS-02+10.0.51.250"); |
|
|
|
hashMap.put("10.0.101.248-SNMP","韩岗UPS-01+10.0.101.248"); hashMap.put("10.0.101.250-SNMP","韩岗UPS-02+10.0.101.250"); |
|
|
|
hashMap.put("10.0.61.248-SNMP","梁山UPS-01+10.0.61.248"); hashMap.put("10.0.61.250-SNMP","梁山UPS-02+10.0.61.250"); |
|
|
|
hashMap.put("10.0.71.248-SNMP","嘉祥西UPS-01+10.0.71.248"); hashMap.put("10.0.71.250-SNMP","嘉祥西UPS-02+10.0.71.250"); |
|
|
|
objects.add(hashMap); |
|
|
|
for (HashMap<String, String> map:objects) { |
|
|
|
for (Map.Entry<String, String> entry : map.entrySet()) { |
|
|
|
String deviceKey = entry.getKey(); |
|
|
|
String deviceNameWithIp = entry.getValue(); |
|
|
|
AjaxResult overloadValue = getDeviceLatestProperty(deviceKey, "1.3.6.1.4.1.935.1.1.1.8.7.4.0");//过载
|
|
|
|
AjaxResult inverterOutputValue = getDeviceLatestProperty(deviceKey, "1.3.6.1.4.1.935.1.1.1.8.7.5.0");//逆变输出
|
|
|
|
AjaxResult overTemperatureValue = getDeviceLatestProperty(deviceKey, "1.3.6.1.4.1.935.1.1.1.8.7.6.0");//过温
|
|
|
|
AjaxResult shortCircuitValue = getDeviceLatestProperty(deviceKey, "1.3.6.1.4.1.935.1.1.1.8.7.7.0");//短路
|
|
|
|
if (!overloadValue.get("code").toString().equals("200") || !inverterOutputValue.get("code").toString().equals("200") || |
|
|
|
!overTemperatureValue.get("code").toString().equals("200") || !shortCircuitValue.get("code").toString().equals("200")) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
JSONObject overloadValueData = (JSONObject) overloadValue.get("data");//过载属性全部值
|
|
|
|
JSONObject inverterOutputValueData = (JSONObject) inverterOutputValue.get("data");//逆变输出属性全部值
|
|
|
|
JSONObject overTemperatureValueData = (JSONObject) overTemperatureValue.get("data");//过温属性全部值
|
|
|
|
JSONObject shortCircuitValueData = (JSONObject) shortCircuitValue.get("data");//短路属性全部值
|
|
|
|
if (overloadValueData == null || inverterOutputValueData == null || overTemperatureValueData == null || shortCircuitValueData == null) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
String overload = overloadValueData.get("value").toString();//过载
|
|
|
|
String inverterOutput = inverterOutputValueData.get("value").toString();//逆变输出
|
|
|
|
String overTemperature = overTemperatureValueData.get("value").toString();//过温
|
|
|
|
String shortCircuit = shortCircuitValueData.get("value").toString();//短路
|
|
|
|
if (overload == null || inverterOutput == null || overTemperature == null || shortCircuit == null) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
//全部状态正常,跳过
|
|
|
|
if ("16".equals(overload) && "16".equals(inverterOutput) && "16".equals(overTemperature) && "16".equals(shortCircuit)) { |
|
|
|
String cacheMapValue = redisCache.getCacheMapValue(ALARMVALUE, deviceKey);//查询缓存
|
|
|
|
if (cacheMapValue != null && !"".equals(cacheMapValue)) {//状态正常但是缓存有存在值,删除缓存跳过数据
|
|
|
|
redisCache.delCacheMapValue(ALARMVALUE,deviceKey); |
|
|
|
} |
|
|
|
continue; |
|
|
|
} |
|
|
|
StringBuilder alarmBuilder = new StringBuilder(); |
|
|
|
// 检查过载异常
|
|
|
|
if ("14".equals(overload)) { |
|
|
|
alarmBuilder.append("过载状态异常"); |
|
|
|
} |
|
|
|
// 检查逆变输出异常
|
|
|
|
if ("14".equals(inverterOutput)) { |
|
|
|
if (alarmBuilder.length() > 0) { |
|
|
|
alarmBuilder.append(","); |
|
|
|
} |
|
|
|
alarmBuilder.append("逆变输出状态异常"); |
|
|
|
} |
|
|
|
// 检查过温异常
|
|
|
|
if ("14".equals(overTemperature)) { |
|
|
|
if (alarmBuilder.length() > 0) { |
|
|
|
alarmBuilder.append(","); |
|
|
|
} |
|
|
|
alarmBuilder.append("过温状态异常"); |
|
|
|
} |
|
|
|
// 检查短路异常
|
|
|
|
if ("14".equals(shortCircuit)) { |
|
|
|
if (alarmBuilder.length() > 0) { |
|
|
|
alarmBuilder.append(","); |
|
|
|
} |
|
|
|
alarmBuilder.append("短路状态异常"); |
|
|
|
} |
|
|
|
String[] split = deviceNameWithIp.split("\\+"); |
|
|
|
DcSnmpAlarm dcSnmpAlarm = new DcSnmpAlarm(); |
|
|
|
String cacheMapValue = redisCache.getCacheMapValue(ALARMVALUE, deviceKey);//查询缓存
|
|
|
|
if (cacheMapValue == null || "".equals(cacheMapValue)) {//缓存不存在加入缓存加入数据
|
|
|
|
dcSnmpAlarm.setContent(split[0] + alarmBuilder.toString()); |
|
|
|
dcSnmpAlarm.setDeviceName(split[0]); |
|
|
|
dcSnmpAlarm.setIotDeviceId(deviceKey); |
|
|
|
dcSnmpAlarm.setIp(split[1]); |
|
|
|
dcSnmpAlarm.setCreateTime(DateUtils.getNowDate()); |
|
|
|
dcDeviceService.insertSnmpAlarm(dcSnmpAlarm);//加入数据
|
|
|
|
redisCache.setCacheMapValue(ALARMVALUE,deviceKey,split[1] + alarmBuilder.toString()); |
|
|
|
HashMap<Object, Object> alarmMap = new HashMap<>(); |
|
|
|
alarmMap.put("content", split[0] + alarmBuilder.toString()); |
|
|
|
alarmMap.put("time", DateUtils.getNowDate()); |
|
|
|
WebSocketService.broadcast("deviceAlarm", alarmMap); |
|
|
|
}else { //缓存存在更新值
|
|
|
|
//如果缓存存在,-缓存替换、数据替换
|
|
|
|
redisCache.delCacheMapValue(ALARMVALUE,deviceKey); |
|
|
|
redisCache.setCacheMapValue(ALARMVALUE,deviceKey,split[1] + alarmBuilder.toString()); |
|
|
|
dcSnmpAlarm.setContent(split[0] + alarmBuilder.toString()); |
|
|
|
dcSnmpAlarm.setIotDeviceId(deviceKey); |
|
|
|
dcDeviceService.updateSnmpAlarm(dcSnmpAlarm); |
|
|
|
HashMap<Object, Object> alarmMap = new HashMap<>(); |
|
|
|
alarmMap.put("content", split[0] + alarmBuilder.toString()); |
|
|
|
alarmMap.put("time", DateUtils.getNowDate()); |
|
|
|
WebSocketService.broadcast("deviceAlarm", alarmMap); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return AjaxResult.success(); |
|
|
|
} |
|
|
|
//查询机柜烟感记录
|
|
|
|
@GetMapping("/dcSnmpUpsAlarmList") |
|
|
|
public TableDataInfo nmpUpsAlarmList( DcSnmpAlarm dcSnmpAlarm){ |
|
|
|
startPage(); |
|
|
|
Map<String, Object> redisCacheCacheMap = redisCache.getCacheMap(ALARMVALUE); |
|
|
|
if (redisCacheCacheMap==null||redisCacheCacheMap.size()==0){ |
|
|
|
return getDataTable(Collections.emptyList()); |
|
|
|
} |
|
|
|
Set<String> strings = redisCacheCacheMap.keySet(); |
|
|
|
List<DcSnmpAlarm> list = dcDeviceService.selectSnmpAlarm(strings); |
|
|
|
return getDataTable(list); |
|
|
|
} |
|
|
|
} |
|
|
|