| | |
| | | package com.whyc.schedule; |
| | | |
| | | import com.whyc.constant.YamlProperties; |
| | | import com.whyc.dto.*; |
| | | import com.whyc.dto.Point; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.dto.TempPoint; |
| | | import com.whyc.factory.ThreadPoolExecutorFactory; |
| | | import com.whyc.pojo.db_alarm.BattStationTempAlarm; |
| | | import com.whyc.pojo.db_batt.BattCamera; |
| | | import com.whyc.pojo.db_param.PageParam; |
| | | import com.whyc.pojo.db_power_rt.BattStationTemp; |
| | | import com.whyc.service.BattStationTempAlarmService; |
| | | import com.whyc.service.BattStationTempService; |
| | | import com.whyc.service.VideoService; |
| | | import com.whyc.util.DateUtil; |
| | | import com.whyc.util.FileUtil; |
| | | import com.whyc.service.PageParamService; |
| | | import com.whyc.util.HikTempUtil; |
| | | 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.io.File; |
| | | import java.util.*; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @EnableScheduling |
| | |
| | | @Autowired |
| | | private BattStationTempService service; |
| | | |
| | | @Autowired |
| | | private BattStationTempAlarmService alarmService; |
| | | |
| | | @Autowired |
| | | private PageParamService paramService; |
| | | |
| | | /** |
| | | * 温度实时 |
| | | * */ |
| | | @Scheduled(fixedRate = 4000,initialDelay = 2000) |
| | | public void startRecordAndCheck(){ |
| | | List<IpInfo> ipInfoList = HikTempUtil.ipInfoList; |
| | | List<BattCamera> ipInfoList = HikTempUtil.cameraInfoList; |
| | | List<PageParam> tempParmList = paramService.getTempParmList(); |
| | | Integer level2AlarmTemp = tempParmList.get(0).getValue(); |
| | | Integer level1AlarmTemp = tempParmList.get(1).getValue(); |
| | | for (int i = 0; i < ipInfoList.size(); i++) { |
| | | IpInfo ipInfo = ipInfoList.get(i); |
| | | BattCamera cameraInfo = ipInfoList.get(i); |
| | | ThreadPoolExecutorFactory.getPoolExecutor().execute(()-> { |
| | | String ip = ipInfo.getIp(); |
| | | String cameraId = ipInfo.getCameraId(); |
| | | String ip = cameraInfo.getCameraIp(); |
| | | String cameraId = cameraInfo.getCameraId(); |
| | | Integer battGroupId = cameraInfo.getBattGroupId(); |
| | | Integer stationId = cameraInfo.getStationId(); |
| | | |
| | | Response response = HikTempUtil.getTempPoint(ip); |
| | | if ((Boolean) response.getData()){ |
| | |
| | | battStationTemp.setCameraId(cameraId); |
| | | Date date = new Date(); |
| | | battStationTemp.setRecordTime(date); |
| | | battStationTemp.setBattGroupId(battGroupId); |
| | | battStationTemp.setStationId(stationId); |
| | | |
| | | service.addOrUpdate(battStationTemp); |
| | | //温度历史-TODO |
| | | |
| | | //温度告警判断 |
| | | //查询温度告警表,如果存在 |
| | | BattStationTempAlarm alarmInDB = alarmService.getByBattGroupId(battGroupId); |
| | | if(alarmInDB != null){ |
| | | //如果存在,同时当前温度大于2级,则更新温度和告警等级 |
| | | if(battStationTemp.getMaxTemp()>=level2AlarmTemp){ |
| | | //温度相同,查看下告警等级是否一样 |
| | | if(alarmInDB.getTemp().floatValue() == battStationTemp.getMaxTemp()){ |
| | | if((alarmInDB.getTemp().floatValue() == level2AlarmTemp |
| | | && alarmInDB.getLevel() == 2) |
| | | || |
| | | (alarmInDB.getTemp().floatValue() == level1AlarmTemp |
| | | && alarmInDB.getLevel() == 1) |
| | | ){ |
| | | |
| | | }else{ //告警等级不同,调整告警等级 |
| | | BattStationTempAlarm alarm = new BattStationTempAlarm(); |
| | | alarm.setLevel(alarmInDB.getLevel()==1?2:1); |
| | | alarm.setId(alarmInDB.getId()); |
| | | alarmService.updateById(alarm); |
| | | } |
| | | |
| | | } |
| | | //温度不同 |
| | | else { |
| | | BattStationTempAlarm alarm = new BattStationTempAlarm(); |
| | | alarm.setId(alarmInDB.getId()); |
| | | alarm.setTemp(battStationTemp.getMaxTemp()); |
| | | if (battStationTemp.getMaxTemp() >= level1AlarmTemp) { //温度大于1级报警温度 |
| | | alarm.setLevel(1); |
| | | } else { |
| | | alarm.setLevel(2); |
| | | } |
| | | alarmService.updateById(alarm); |
| | | } |
| | | }else { |
| | | //如果不存在了,表明告警结束,更新结束时间 |
| | | BattStationTempAlarm alarm = new BattStationTempAlarm(); |
| | | alarm.setId(alarmInDB.getId()); |
| | | alarm.setEndTime(date); |
| | | alarmService.updateById(alarm); |
| | | } |
| | | } |
| | | |
| | | // 告警表内不存在当前电池组的告警,如果超过报警温度,则生成告警 |
| | | else if(battStationTemp.getMaxTemp()>=level2AlarmTemp){ //温度大于2级报警温度 |
| | | BattStationTempAlarm alarm = new BattStationTempAlarm(); |
| | | alarm.setBattGroupId(battGroupId); |
| | | alarm.setStationId(stationId); |
| | | alarm.setTemp(battStationTemp.getMaxTemp()); |
| | | alarm.setStartTime(date); |
| | | if (battStationTemp.getMaxTemp()>=level1AlarmTemp){ //温度大于1级报警温度 |
| | | alarm.setLevel(1); |
| | | }else{ |
| | | alarm.setLevel(2); |
| | | } |
| | | alarmService.add(alarm); |
| | | } |
| | | |
| | | }else{ |
| | | String msg = response.getMsg(); |