From 5c6457965206ba36c9ef8ed2bdfdf20cb0c381d9 Mon Sep 17 00:00:00 2001 From: fs-danaus <danaus314@qq.com> Date: 星期六, 24 九月 2022 16:48:06 +0800 Subject: [PATCH] 增加推送在线交流 --- src/com/yc/open/init/shcedule/MessagePopTipsSchedule.java | 39 ++++++++++++--------------------------- 1 files changed, 12 insertions(+), 27 deletions(-) diff --git a/src/com/yc/open/init/shcedule/MessagePopTipsSchedule.java b/src/com/yc/open/init/shcedule/MessagePopTipsSchedule.java index 368edd6..57e4ae4 100644 --- a/src/com/yc/open/init/shcedule/MessagePopTipsSchedule.java +++ b/src/com/yc/open/init/shcedule/MessagePopTipsSchedule.java @@ -11,6 +11,7 @@ import com.yc.sdk.WebSocketMessage.entity.MessageType; import com.yc.sdk.WebSocketMessage.entity.WsMessageUserEntity; import com.yc.service.BaseService; +import com.yc.service.impl.BaseDoIfc; import org.springframework.jdbc.core.BeanPropertyRowMapper; import java.text.SimpleDateFormat; @@ -37,9 +38,10 @@ if (Thread.interrupted()) { throw new InterruptedException(); } - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + //log.info(dataSourceEntity.getSystemID() + "鍙充笅瑙掑脊绐楀紑濮�....."); SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId()); - BaseService baseService = (BaseService) FactoryBean.getBean("BaseService"); + BaseDoIfc doIfc = (BaseDoIfc) FactoryBean.getBean("baseDoImpl"); + BaseService baseService=(BaseService)FactoryBean.getBean("BaseService"); //鑾峰彇褰撳墠宸茶繛鎺ebscoket鐨勭敤鎴� final List<WsMessageUserEntity> onlineUser = WebSocketMessageServer.getOnlineUser(dataSourceEntity.getDbId(), null); StringJoiner joiner = new StringJoiner(","); @@ -83,7 +85,10 @@ if(flag){ //鎴愬姛鎵嶆洿鏂版鏁� collect.stream().forEach(z->{ - updateJoiner.add(" insert into @table(MessId,UserCode) values ( "+z.getMessid()+","+GridUtils.prossSqlParm(userCode)+")"); + updateJoiner.add(" if not exists(select 1 from @table where MessId = "+z.getMessid()+" and UserCode = "+GridUtils.prossSqlParm(userCode)+")\n" + + " begin\n" + + " insert into @table(MessId,UserCode) values ( "+z.getMessid()+","+GridUtils.prossSqlParm(userCode)+")\n" + + " end\n"); }); } } @@ -95,13 +100,12 @@ if(updateJoiner.length()>0) { String sql = "set nocount on \n declare @table table(MessId int,UserCode varchar(50), Primary Key(MessId,UserCode))\n" + updateJoiner.toString() + - " \n update a set tipcount = isnull(tipcount,0) + 1 \n" + + " \n update a set tipcount = isnull(tipcount,0) + 1,LastPushTime=getDate() \n" + " from _sysMessageCount a \n" + - "where exists ( select 1 from @table b where a.MessId = b.MessId and a.UserCode = b.UserCode ) "; - - baseService.getSimpleJdbcTemplate().execute(sql); + "where exists ( select 1 from @table b where a.MessId = b.MessId and a.UserCode = b.UserCode and (a.LastPushTime is null or datediff(second,a.LastPushTime,getdate()) > 45 )) "; + doIfc.doExecute(sql); + //log.info(dataSourceEntity.getSystemID() + "鍙充笅瑙掑脊绐楀畬鎴�:"+sql); } - } } } catch (InterruptedException ex) { @@ -113,25 +117,6 @@ SpObserver.setDBtoInstance(); } } - - private void pushSystemMessage(MessageTipsEntity entity,SimpleDateFormat sdf) { - Map map=new HashMap(); - map.put("messagetxt",entity.getMessagetxt()); - map.put("unvaliddate",sdf.format(toString(entity.getUnvaliddate()))); - map.put("createtime",sdf.format(toString(entity.getCreatetime()))); - map.put("createusername",entity.getCreateusername()); - map.put("topic",entity.getTopic()); - map.put("messagetype",entity.getMessagetype()); - //---閫氱煡webscoket - MessageInfo messageInfo = new MessageInfo(); - messageInfo.setDbId(dataSourceEntity.getDbId()); - messageInfo.setMsgType(MessageType.POPUP_REMINDER); - messageInfo.setUserFromType("1");//TODO PC绔� - messageInfo.setUserCode(entity.getUsercode()); - messageInfo.setMsg(JSON.toJSONString(map)); - WebSocketMessageServer.publishMessageToRedis(messageInfo); - } - public String replaceBlank(String str) { if (str == null || str == "") { return ""; } Matcher m = null; -- Gitblit v1.8.0