|  |  |  | @ -1,8 +1,10 @@ | 
			
		
	
		
			
				
					|  |  |  |  | package com.hnac.hzims.alarm.source.service.impl; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | import com.alibaba.fastjson.JSONObject; | 
			
		
	
		
			
				
					|  |  |  |  | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; | 
			
		
	
		
			
				
					|  |  |  |  | import com.hnac.hzims.alarm.config.entity.AlarmEntity; | 
			
		
	
		
			
				
					|  |  |  |  | import com.hnac.hzims.alarm.source.service.MessageService; | 
			
		
	
		
			
				
					|  |  |  |  | import com.hnac.hzims.alarm.ws.alart.AlarmSessionManager; | 
			
		
	
		
			
				
					|  |  |  |  | import com.hnac.hzims.common.constant.CommonConstant; | 
			
		
	
		
			
				
					|  |  |  |  | import com.hnac.hzims.operational.station.entity.StationEntity; | 
			
		
	
		
			
				
					|  |  |  |  | import com.hnac.hzims.operational.station.feign.IStationClient; | 
			
		
	
	
		
			
				
					|  |  |  | @ -17,13 +19,16 @@ import org.springblade.message.dto.SmsImmediatelyPushDTO; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springblade.message.dto.WxMessageDTO; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springblade.message.fegin.IMessageClient; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springblade.system.cache.DictCache; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springblade.system.feign.IDeptClient; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springblade.system.feign.ISysClient; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springblade.system.user.entity.User; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springblade.system.user.entity.UserInfo; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springblade.system.user.feign.IUserClient; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springframework.beans.factory.annotation.Value; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springframework.stereotype.Service; | 
			
		
	
		
			
				
					|  |  |  |  | import org.springframework.web.socket.TextMessage; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | import java.io.IOException; | 
			
		
	
		
			
				
					|  |  |  |  | import java.time.format.DateTimeFormatter; | 
			
		
	
		
			
				
					|  |  |  |  | import java.util.*; | 
			
		
	
		
			
				
					|  |  |  |  | import java.util.stream.Collectors; | 
			
		
	
	
		
			
				
					|  |  |  | @ -44,6 +49,8 @@ public class MessageServiceImpl implements MessageService { | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private final IUserClient userClient; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private final IDeptClient deptClient; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private final IMessageClient messageClient; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private final IStationClient stationClient; | 
			
		
	
	
		
			
				
					|  |  |  | @ -56,6 +63,34 @@ public class MessageServiceImpl implements MessageService { | 
			
		
	
		
			
				
					|  |  |  |  |     private String wxPushTemplate; | 
			
		
	
		
			
				
					|  |  |  |  |     @Value("${hzims.wxPush.enabled}") | 
			
		
	
		
			
				
					|  |  |  |  |     private Boolean wxPushEnabled; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |  |      * web告警展示消息推送 | 
			
		
	
		
			
				
					|  |  |  |  |      * @param alarm | 
			
		
	
		
			
				
					|  |  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |  |     public void webRightMessage(AlarmEntity alarm) { | 
			
		
	
		
			
				
					|  |  |  |  |         if(CollectionUtil.isEmpty(AlarmSessionManager.SESSION_POOL)){ | 
			
		
	
		
			
				
					|  |  |  |  |             return; | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         // 遍历websocket链接,拥有告警站点权限进行推送消息
 | 
			
		
	
		
			
				
					|  |  |  |  |         AlarmSessionManager.SESSION_POOL.forEach((key, session) -> { | 
			
		
	
		
			
				
					|  |  |  |  |             if(!session.getAttributes().containsKey("codes")){ | 
			
		
	
		
			
				
					|  |  |  |  |                 return; | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             List<String> codes = (List<String>) session.getAttributes().get("codes"); | 
			
		
	
		
			
				
					|  |  |  |  |             if(CollectionUtil.isEmpty(codes) || !codes.contains(alarm.getStationId())){ | 
			
		
	
		
			
				
					|  |  |  |  |                 return; | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             try { | 
			
		
	
		
			
				
					|  |  |  |  |                 session.sendMessage(new TextMessage(JSONObject.toJSONString(Collections.singletonList(alarm)))); | 
			
		
	
		
			
				
					|  |  |  |  |             } catch (IOException e) { | 
			
		
	
		
			
				
					|  |  |  |  |                 throw new RuntimeException(e); | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         }); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |  |      * web/app消息推送 | 
			
		
	
		
			
				
					|  |  |  |  |      * @param entity : 告警对象 | 
			
		
	
	
		
			
				
					|  |  |  | @ -161,8 +196,6 @@ public class MessageServiceImpl implements MessageService { | 
			
		
	
		
			
				
					|  |  |  |  |                 return; | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             userList.addAll(result.getData()); | 
			
		
	
		
			
				
					|  |  |  |  |             log.info("短信发送用户列表:{}",userList); | 
			
		
	
		
			
				
					|  |  |  |  |             log.info("短信发送用户列表,{}",userList); | 
			
		
	
		
			
				
					|  |  |  |  |         }else { | 
			
		
	
		
			
				
					|  |  |  |  |             //内测只推给对应的3个用户
 | 
			
		
	
		
			
				
					|  |  |  |  |             List<String> phoneList = Arrays.asList("18351807087", "18163793336", "18285121497"); | 
			
		
	
	
		
			
				
					|  |  |  | @ -172,9 +205,9 @@ public class MessageServiceImpl implements MessageService { | 
			
		
	
		
			
				
					|  |  |  |  |                     userList.add(userByPhone.getData().getUser()); | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         log.info("短信发送用户列表:{}",userList); | 
			
		
	
		
			
				
					|  |  |  |  |         log.info("短信发送用户列表,{}",userList); | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         String userIds = userList.stream().map(o -> String.valueOf(o.getId())).distinct().collect(Collectors.joining(",")); | 
			
		
	
		
			
				
					|  |  |  |  |         WxMessageDTO message = new WxMessageDTO(); | 
			
		
	
		
			
				
					|  |  |  |  |         // 模板Id
 | 
			
		
	
	
		
			
				
					|  |  |  | @ -191,8 +224,8 @@ public class MessageServiceImpl implements MessageService { | 
			
		
	
		
			
				
					|  |  |  |  |         message.setTaskId(entity.getId()); | 
			
		
	
		
			
				
					|  |  |  |  |         // 微信参数键值对
 | 
			
		
	
		
			
				
					|  |  |  |  |         HashMap<String,Object> map = new HashMap<>(); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("thing18",getTruncateString(entity.getStationName(), 20)); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("thing11",getTruncateString(entity.getAlarmContext(), 20)); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("thing18",getTruncateString(entity.getStationName())); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("thing11",getTruncateString(entity.getAlarmContext())); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("time2",entity.getAlarmTime()); | 
			
		
	
		
			
				
					|  |  |  |  |         map.put("thing14", DictCache.getValue("alarm_type", String.valueOf(entity.getAlarmType()))); | 
			
		
	
		
			
				
					|  |  |  |  |         DateTimeFormatter format = DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME); | 
			
		
	
	
		
			
				
					|  |  |  | @ -211,11 +244,12 @@ public class MessageServiceImpl implements MessageService { | 
			
		
	
		
			
				
					|  |  |  |  |         message.setTenantId(station.getData().getTenantId()); | 
			
		
	
		
			
				
					|  |  |  |  |         messageClient.sendWxMessage(message); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  |     private String getTruncateString(String ruleDefName, int maxSize) { | 
			
		
	
		
			
				
					|  |  |  |  |         if (ruleDefName.length()<= maxSize){ | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     private String getTruncateString(String ruleDefName) { | 
			
		
	
		
			
				
					|  |  |  |  |         if (ruleDefName.length()<= 20){ | 
			
		
	
		
			
				
					|  |  |  |  |             return ruleDefName; | 
			
		
	
		
			
				
					|  |  |  |  |         }else { | 
			
		
	
		
			
				
					|  |  |  |  |             return ruleDefName.substring(0, maxSize - 3) + "..."; | 
			
		
	
		
			
				
					|  |  |  |  |             return ruleDefName.substring(0, 20 - 3) + "..."; | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | } |