|  |  |  | @ -2,7 +2,6 @@ package com.hnac.hzims.alarm.show.service.impl; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | import com.alibaba.fastjson.JSONObject; | 
			
		
	
		
			
				
					|  |  |  |  | import com.alibaba.fastjson.TypeReference; | 
			
		
	
		
			
				
					|  |  |  |  | import com.baomidou.mybatisplus.core.toolkit.Wrappers; | 
			
		
	
		
			
				
					|  |  |  |  | import com.hnac.hzims.alarm.constants.AlarmConstants; | 
			
		
	
		
			
				
					|  |  |  |  | import com.hnac.hzims.alarm.entity.AlarmEntity; | 
			
		
	
		
			
				
					|  |  |  |  | import com.hnac.hzims.alarm.show.service.AlarmService; | 
			
		
	
	
		
			
				
					|  |  |  | @ -22,9 +21,9 @@ import org.springblade.core.tool.utils.DateUtil; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springframework.data.redis.core.RedisTemplate; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springframework.stereotype.Service; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | import java.util.ArrayList; | 
			
		
	
		
			
				
					|  |  |  |  | import java.util.Date; | 
			
		
	
		
			
				
					|  |  |  |  | import java.util.List; | 
			
		
	
		
			
				
					|  |  |  |  | import java.util.concurrent.CompletableFuture; | 
			
		
	
		
			
				
					|  |  |  |  | import java.util.stream.Collectors; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | /** | 
			
		
	
	
		
			
				
					|  |  |  | @ -70,48 +69,42 @@ public class LevelAlarmServiceImpl implements LevelAlarmService { | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |  |      * 处理websocket消息 | 
			
		
	
		
			
				
					|  |  |  |  |      * 转换接收服务推送消息 | 
			
		
	
		
			
				
					|  |  |  |  |      * @param message | 
			
		
	
		
			
				
					|  |  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |  |     public void receive(String message) { | 
			
		
	
		
			
				
					|  |  |  |  |     public List<AlarmEntity> receiveMessage(String message) { | 
			
		
	
		
			
				
					|  |  |  |  |         // 对象转换
 | 
			
		
	
		
			
				
					|  |  |  |  |         List<LevelVo> levels = JSONObject.parseArray(message,LevelVo.class); | 
			
		
	
		
			
				
					|  |  |  |  |         if(CollectionUtil.isEmpty(levels)){ | 
			
		
	
		
			
				
					|  |  |  |  |             return; | 
			
		
	
		
			
				
					|  |  |  |  |         List<LevelVo> alarms = JSONObject.parseArray(message, LevelVo.class); | 
			
		
	
		
			
				
					|  |  |  |  |         if (CollectionUtil.isEmpty(alarms)) { | 
			
		
	
		
			
				
					|  |  |  |  |             return new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         // 设备
 | 
			
		
	
		
			
				
					|  |  |  |  |         List<AlarmEntity> res = alarms.stream().map(s -> { | 
			
		
	
		
			
				
					|  |  |  |  |             AlarmEntity entity = getAlarmEntity(s); | 
			
		
	
		
			
				
					|  |  |  |  |             return entity; | 
			
		
	
		
			
				
					|  |  |  |  |         }).collect(Collectors.toList()); | 
			
		
	
		
			
				
					|  |  |  |  |         return res; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private AlarmEntity getAlarmEntity(LevelVo level) { | 
			
		
	
		
			
				
					|  |  |  |  |         List<EminfoAndEmParamVo> devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(),new TypeReference<List<EminfoAndEmParamVo>>() {}); | 
			
		
	
		
			
				
					|  |  |  |  |         // 查询已经保存等级告警数据
 | 
			
		
	
		
			
				
					|  |  |  |  |         List<AlarmEntity> records = alarmService.list(Wrappers.<AlarmEntity>lambdaQuery() | 
			
		
	
		
			
				
					|  |  |  |  |                 .ge(AlarmEntity::getAlarmSource,AlarmConstants.LEVEL_ALARM) | 
			
		
	
		
			
				
					|  |  |  |  |                 .in(AlarmEntity::getAlarmId,levels.stream().map(LevelVo::getId).collect(Collectors.toList())) | 
			
		
	
		
			
				
					|  |  |  |  |         ); | 
			
		
	
		
			
				
					|  |  |  |  |         // 遍历等级告警数据
 | 
			
		
	
		
			
				
					|  |  |  |  |         levels.stream().filter(o-> CollectionUtil.isEmpty(records) || !records.stream().map(AlarmEntity::getAlarmId).collect(Collectors.toList()).contains(o.getId())). | 
			
		
	
		
			
				
					|  |  |  |  |                 forEach(level->{ | 
			
		
	
		
			
				
					|  |  |  |  |                     AlarmEntity entity = new AlarmEntity(); | 
			
		
	
		
			
				
					|  |  |  |  |                     entity.setAlarmSource(AlarmConstants.LEVEL_ALARM); | 
			
		
	
		
			
				
					|  |  |  |  |                     entity.setAlarmId(level.getId()); | 
			
		
	
		
			
				
					|  |  |  |  |                     entity.setAlarmTime(DateUtil.parse(level.getTs(), "yyyy-MM-dd HH:mm:ss.s")); | 
			
		
	
		
			
				
					|  |  |  |  |                     entity.setAlarmType(level.getType()); | 
			
		
	
		
			
				
					|  |  |  |  |                     entity.setRealId(level.getSignage()); | 
			
		
	
		
			
				
					|  |  |  |  |                     entity.setAlarmContext(level.getName()); | 
			
		
	
		
			
				
					|  |  |  |  |                     entity.setDeviceCode(level.getDevicecode()); | 
			
		
	
		
			
				
					|  |  |  |  |                     entity.setDeviceName(level.getDevicename()); | 
			
		
	
		
			
				
					|  |  |  |  |                     entity.setAlarmLevel(level.getLevel()); | 
			
		
	
		
			
				
					|  |  |  |  |                     List<EminfoAndEmParamVo> ems = devices.stream().filter(o->level.getDevicecode().equals(o.getEmCode())).collect(Collectors.toList()); | 
			
		
	
		
			
				
					|  |  |  |  |                     if(CollectionUtil.isNotEmpty(ems)){ | 
			
		
	
		
			
				
					|  |  |  |  |                         entity.setStationId(ems.get(0).getStationCode()); | 
			
		
	
		
			
				
					|  |  |  |  |                         entity.setDeviceName(ems.get(0).getStationName()); | 
			
		
	
		
			
				
					|  |  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |  |                     this.alarmService.save(entity); | 
			
		
	
		
			
				
					|  |  |  |  |                     // 短信
 | 
			
		
	
		
			
				
					|  |  |  |  |                     CompletableFuture.runAsync(() -> this.messageService.message(entity)); | 
			
		
	
		
			
				
					|  |  |  |  |                     // web/app消息推送
 | 
			
		
	
		
			
				
					|  |  |  |  |                     CompletableFuture.runAsync(() -> this.messageService.webAppMessage(entity)); | 
			
		
	
		
			
				
					|  |  |  |  |                     // 微信公众号推送
 | 
			
		
	
		
			
				
					|  |  |  |  |                     CompletableFuture.runAsync(() -> this.messageService.weChatMessage(entity)); | 
			
		
	
		
			
				
					|  |  |  |  |                 }); | 
			
		
	
		
			
				
					|  |  |  |  |    } | 
			
		
	
		
			
				
					|  |  |  |  |         AlarmEntity entity = new AlarmEntity(); | 
			
		
	
		
			
				
					|  |  |  |  |         entity.setAlarmSource(AlarmConstants.LEVEL_ALARM); | 
			
		
	
		
			
				
					|  |  |  |  |         entity.setAlarmId(level.getId()); | 
			
		
	
		
			
				
					|  |  |  |  |         entity.setAlarmTime(DateUtil.parse(level.getTs(), "yyyy-MM-dd HH:mm:ss.s")); | 
			
		
	
		
			
				
					|  |  |  |  |         entity.setAlarmType(level.getType()); | 
			
		
	
		
			
				
					|  |  |  |  |         entity.setRealId(level.getSignage()); | 
			
		
	
		
			
				
					|  |  |  |  |         entity.setAlarmContext(level.getName()); | 
			
		
	
		
			
				
					|  |  |  |  |         entity.setDeviceCode(level.getDevicecode()); | 
			
		
	
		
			
				
					|  |  |  |  |         entity.setDeviceName(level.getDevicename()); | 
			
		
	
		
			
				
					|  |  |  |  |         entity.setAlarmLevel(level.getLevel()); | 
			
		
	
		
			
				
					|  |  |  |  |         List<EminfoAndEmParamVo> ems = devices.stream().filter(o->level.getDevicecode().equals(o.getEmCode())).collect(Collectors.toList()); | 
			
		
	
		
			
				
					|  |  |  |  |         if(CollectionUtil.isNotEmpty(ems)){ | 
			
		
	
		
			
				
					|  |  |  |  |             entity.setStationId(ems.get(0).getStationCode()); | 
			
		
	
		
			
				
					|  |  |  |  |             entity.setDeviceName(ems.get(0).getStationName()); | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         return entity; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | } |