| | |
| | | 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_history.BattStationTempHistory; |
| | | import com.whyc.pojo.db_power_rt.BattStationTemp; |
| | | import com.whyc.service.BattStationTempAlarmService; |
| | | import com.whyc.service.BattStationTempHisService; |
| | | import com.whyc.service.BattStationTempService; |
| | | import com.whyc.service.PageParamService; |
| | | import com.whyc.util.DateUtil; |
| | | import com.whyc.util.HikTempUtil; |
| | | import com.whyc.util.ThreadLocalUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.beanutils.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.EnableScheduling; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.lang.reflect.InvocationTargetException; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | |
| | | @Autowired |
| | | private BattStationTempService service; |
| | | |
| | | @Autowired |
| | | private BattStationTempHisService hisService; |
| | | |
| | | @Autowired |
| | | private BattStationTempAlarmService alarmService; |
| | |
| | | Integer level1AlarmTemp = tempParmList.get(1).getValue(); |
| | | for (int i = 0; i < ipInfoList.size(); i++) { |
| | | BattCamera cameraInfo = ipInfoList.get(i); |
| | | ThreadPoolExecutorFactory.getPoolExecutor().execute(()-> { |
| | | //ThreadPoolExecutorFactory.getPoolExecutor().execute(()-> { |
| | | String ip = cameraInfo.getCameraIp(); |
| | | String cameraId = cameraInfo.getCameraId(); |
| | | Integer battGroupId = cameraInfo.getBattGroupId(); |
| | |
| | | battStationTemp.setStationId(stationId); |
| | | |
| | | service.addOrUpdate(battStationTemp); |
| | | //温度历史-TODO |
| | | |
| | | String yearMonth = ThreadLocalUtil.format(date, 2); |
| | | //温度历史 - 记录到 按电池组id,月度表 |
| | | boolean exist = hisService.existTempHisTableByMonth(battGroupId,yearMonth); |
| | | //不存在则创建.插入记录 |
| | | if(!exist){ |
| | | hisService.createTableByMonth(battGroupId,yearMonth); |
| | | } |
| | | BattStationTempHistory tempHistory = new BattStationTempHistory(); |
| | | try { |
| | | BeanUtils.copyProperties(tempHistory,battStationTemp); |
| | | } catch (IllegalAccessException | InvocationTargetException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | hisService.add(battGroupId,yearMonth,tempHistory); |
| | | //温度告警判断 |
| | | //查询温度告警表,如果存在 |
| | | BattStationTempAlarm alarmInDB = alarmService.getByBattGroupId(battGroupId); |
| | | if(alarmInDB != null){ |
| | | if(alarmInDB != null){ // TODO 校验温度点位和逻辑,很重要!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| | | //如果存在,同时当前温度大于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) |
| | | ){ |
| | | Float temp = alarmInDB.getTemp(); |
| | | int levelInDB = alarmInDB.getLevel(); |
| | | int levelNow; |
| | | if(temp>=level1AlarmTemp){ |
| | | levelNow = 1; |
| | | }else{ |
| | | levelNow = 2; |
| | | } |
| | | |
| | | }else{ //告警等级不同,调整告警等级 |
| | | if(levelInDB != levelNow){ //告警等级不同,调整告警等级 |
| | | BattStationTempAlarm alarm = new BattStationTempAlarm(); |
| | | alarm.setLevel(alarmInDB.getLevel()==1?2:1); |
| | | alarm.setId(alarmInDB.getId()); |
| | | if(!alarmInDB.getMaxTempPoint().equals(battStationTemp.getMaxTempPoint())){ |
| | | alarm.setMaxTempPoint(battStationTemp.getMaxTempPoint()); |
| | | } |
| | | alarmService.updateById(alarm); |
| | | } |
| | | }else if(!alarmInDB.getMaxTempPoint().equals(battStationTemp.getMaxTempPoint())){ //告警等级相同,最大温度点位不同则更新点位 |
| | | BattStationTempAlarm alarm = new BattStationTempAlarm(); |
| | | alarm.setId(alarmInDB.getId()); |
| | | alarm.setMaxTempPoint(battStationTemp.getMaxTempPoint()); |
| | | alarmService.updateById(alarm); |
| | | } |
| | | |
| | | } |
| | | //温度不同 |
| | |
| | | alarm.setLevel(1); |
| | | } else { |
| | | alarm.setLevel(2); |
| | | } |
| | | if(!alarmInDB.getMaxTempPoint().equals(battStationTemp.getMaxTempPoint())){ |
| | | alarm.setMaxTempPoint(battStationTemp.getMaxTempPoint()); |
| | | } |
| | | alarmService.updateById(alarm); |
| | | } |
| | |
| | | }else{ |
| | | alarm.setLevel(2); |
| | | } |
| | | //添加最高温度点位 |
| | | alarm.setMaxTempPoint(battStationTemp.getMaxTempPoint()); |
| | | alarmService.add(alarm); |
| | | } |
| | | |
| | |
| | | String msg = response.getMsg(); |
| | | // TODO 报错日志记录 |
| | | } |
| | | }); |
| | | //}); |
| | | } |
| | | |
| | | } |