From 1da190e7f267bcd3501884f3aeaac7476850fec7 Mon Sep 17 00:00:00 2001 From: EricsHu <hrr145632> Date: 星期日, 26 十一月 2023 17:53:03 +0800 Subject: [PATCH] 优化菜单查询 --- src/main/java/com/qxueyou/scc/msg/service/impl/ChatroomMessageBean.java | 70 +++++++++++++++++----------------- 1 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/qxueyou/scc/msg/service/impl/ChatroomMessageBean.java b/src/main/java/com/qxueyou/scc/msg/service/impl/ChatroomMessageBean.java index 3c39294..71c3a16 100644 --- a/src/main/java/com/qxueyou/scc/msg/service/impl/ChatroomMessageBean.java +++ b/src/main/java/com/qxueyou/scc/msg/service/impl/ChatroomMessageBean.java @@ -24,21 +24,21 @@ private static final int PAGE_SIZE = 20; - private static final String CACHEKEY_MSG_QUEUE = "msg_chatroom_msg_"; // 实时消息队列 - private static final String CACHEKEY_MESSAGE_A_COUNT = "msg_chatroom_message_count_"; // A类消息总数 - private static final String CACHEKEY_MESSAGE_HISTORY = "msg_chatroom_msg_history_"; //历史消息 + private static final String CACHEKEY_MSG_QUEUE = "msg_chatroom_msg_"; // 瀹炴椂娑堟伅闃熷垪 + private static final String CACHEKEY_MESSAGE_A_COUNT = "msg_chatroom_message_count_"; // A绫绘秷鎭�绘暟 + private static final String CACHEKEY_MESSAGE_HISTORY = "msg_chatroom_msg_history_"; //鍘嗗彶娑堟伅 - private static final String CACHEKEY_ONLINE_COUNT = "msg_chatroom_online_count_"; // 在线人数 - private static final String CACHEKEY_PRAISE_COUNT = "msg_chatroom_praise_count_"; // 点赞数 - private static final String CACHEKEY_LOTTERY_COUNT = "msg_chatroom_lottery_count_"; // 签到数 - private static final String CACHEKEY_VIEW_COUNT = "msg_chatroom_view_count_"; // 浏览数 - private static final String CACHEKEY_LOTTERY_RESULT_COUNT = "msg_chatroom_lottery_result_count_"; //中奖结果 - private static final String CACHEKEY_REWARD_COUNT = "msg_chatroom_reward_count_"; //打赏次数 - private static final String CACHEKEY_CONSULT_COUNT = "msg_chatroom_consult_count_"; //咨询次数 - private static final String CACHEKEY_REWARD_AMOUNT = "msg_chatroom_reward_amount_"; //打赏金额 + private static final String CACHEKEY_ONLINE_COUNT = "msg_chatroom_online_count_"; // 鍦ㄧ嚎浜烘暟 + private static final String CACHEKEY_PRAISE_COUNT = "msg_chatroom_praise_count_"; // 鐐硅禐鏁� + private static final String CACHEKEY_LOTTERY_COUNT = "msg_chatroom_lottery_count_"; // 绛惧埌鏁� + private static final String CACHEKEY_VIEW_COUNT = "msg_chatroom_view_count_"; // 娴忚鏁� + private static final String CACHEKEY_LOTTERY_RESULT_COUNT = "msg_chatroom_lottery_result_count_"; //涓缁撴灉 + private static final String CACHEKEY_REWARD_COUNT = "msg_chatroom_reward_count_"; //鎵撹祻娆℃暟 + private static final String CACHEKEY_CONSULT_COUNT = "msg_chatroom_consult_count_"; //鍜ㄨ娆℃暟 + private static final String CACHEKEY_REWARD_AMOUNT = "msg_chatroom_reward_amount_"; //鎵撹祻閲戦 /** - * 发送消息 + * 鍙戦�佹秷鎭� */ @Override @@ -56,7 +56,7 @@ mes.setImgPath(imgPath); mes.setCreateTime(new Date()); - //缓存消息 + //缂撳瓨娑堟伅 this.msgCache(chatroomId, mes); this.msgTypeCountCache(chatroomId, type); @@ -65,7 +65,7 @@ } /** - * 聊天消息剪切, + * 鑱婂ぉ娑堟伅鍓垏锛� * * @param chatroomId */ @@ -84,13 +84,13 @@ } index ++; } - //保留20条 + //淇濈暀20鏉� redis.lstTrim(key, mesList.size() - index <= 20?mesList.size()-20:index, -1l); } } /** - * 缓存消息 + * 缂撳瓨娑堟伅 * * @param chatroomId * @param mes @@ -98,14 +98,14 @@ private void msgCache(String chatroomId, MsgChatroomMsg mes){ String key = CACHEKEY_MSG_QUEUE + chatroomId; - //先获取10秒内的数据 + //鍏堣幏鍙�10绉掑唴鐨勬暟鎹� // this.msgListTrim(key, chatroomId); // List<MsgChatroomMsg> mesList = redis.lstRange(key, 0l, -1l); - //获取PAGE_SIZE条以内的消息 + //鑾峰彇PAGE_SIZE鏉′互鍐呯殑娑堟伅 List<MsgChatroomMsg> mesList= redis.lstRange(key, 0l, PAGE_SIZE); - //最近20消息过滤重复的点赞,进入,退出 + //鏈�杩�20娑堟伅杩囨护閲嶅鐨勭偣璧烇紝杩涘叆锛岄��鍑� if((MsgChatroomMsg.TYPE_PRAISE == mes.getType() || MsgChatroomMsg.TYPE_ENTER == mes.getType() || MsgChatroomMsg.TYPE_EXIT == mes.getType()) && mesList.contains(mes)){ return; @@ -115,13 +115,13 @@ } /** - * 计数器 + * 璁℃暟鍣� * * @param chatroomId * @param type */ private void msgTypeCountCache(String chatroomId, Integer type){ - if(type == MsgChatroomMsg.TYPE_ENTER){//在线人数加一 + if(type == MsgChatroomMsg.TYPE_ENTER){//鍦ㄧ嚎浜烘暟鍔犱竴 redis.incr(CACHEKEY_ONLINE_COUNT + chatroomId); redis.expire(CACHEKEY_ONLINE_COUNT + chatroomId, 360, TimeUnit.DAYS); } @@ -129,20 +129,20 @@ || type == MsgChatroomMsg.TYPE_REWARD || type == MsgChatroomMsg.TYPE_CONSULT || type == MsgChatroomMsg.TYPE_LOTTERY_RESULT){ redis.incr(this.getKey(chatroomId, type)); redis.expire(this.getKey(chatroomId, type), 360, TimeUnit.DAYS); - }else if(type == MsgChatroomMsg.TYPE_EXIT){//在线人数减一 + }else if(type == MsgChatroomMsg.TYPE_EXIT){//鍦ㄧ嚎浜烘暟鍑忎竴 String key = CACHEKEY_ONLINE_COUNT + chatroomId; Long value = redis.getIncrValue(key); if(value.compareTo(0l)>0){ redis.decr(key); } redis.expire(key, 360, TimeUnit.DAYS); - }else if(type == MsgChatroomMsg.TYPE_NORMAL || type == MsgChatroomMsg.TYPE_LOTTERY_RESULT){//A类消息计数器 + }else if(type == MsgChatroomMsg.TYPE_NORMAL || type == MsgChatroomMsg.TYPE_LOTTERY_RESULT){//A绫绘秷鎭鏁板櫒 redis.incr(CACHEKEY_MESSAGE_A_COUNT + chatroomId); redis.expire(CACHEKEY_MESSAGE_A_COUNT + chatroomId, 360, TimeUnit.DAYS); } } - //获取缓存key值 + //鑾峰彇缂撳瓨key鍊� private String getKey(String chatroomId, Integer type){ String key = ""; switch(type){ @@ -171,7 +171,7 @@ } /** - * 轮询 + * 杞 * * @param chatroomId * @throws Exception @@ -180,11 +180,11 @@ public Result latestMsg(String chatroomId) { List<MsgChatroomMsg> mesList = redis.lstRange(CACHEKEY_MSG_QUEUE + chatroomId, 0l, -1l); - //奖金总数 + //濂栭噾鎬绘暟 Long rewardAmount = redis.getIncrValue(CACHEKEY_REWARD_AMOUNT + chatroomId); Map<String, Object> data = new HashMap<String, Object>(); - //统计数据 + //缁熻鏁版嵁 Map<String,Long> statistics = this.reStatistics(chatroomId); Integer maxPage = this.getMaxPage(chatroomId, String.valueOf(statistics.get("historyMsgCount"))); data.put("maxPage", maxPage); @@ -202,7 +202,7 @@ } /** - * 获取浏览人次 + * 鑾峰彇娴忚浜烘 * @param chatroomId * @throws Exception */ @@ -212,7 +212,7 @@ } /** - * 重新统计数据,读取数据库 + * 閲嶆柊缁熻鏁版嵁锛岃鍙栨暟鎹簱 * * @param type * @param statistics @@ -230,7 +230,7 @@ Map<String, Long> result = new HashMap<>(); result.put("msgCount", msgCount); - //历史消息数量,正常消息、中奖消息,打赏消息 + //鍘嗗彶娑堟伅鏁伴噺锛屾甯告秷鎭�佷腑濂栨秷鎭紝鎵撹祻娑堟伅 result.put("historyMsgCount", msgCount+lotteryResultCount+rewardCount); result.put("onlineCount", onlineCount); result.put("praiseCount", praiseCount); @@ -249,19 +249,19 @@ } /** - * 按页获取历史消息 + * 鎸夐〉鑾峰彇鍘嗗彶娑堟伅 */ @Override public Result getHistoryMes(String chatroomId, Integer pageNo) { - //统计数据 + //缁熻鏁版嵁 List<MsgChatroomMsg> mesList = redis.lstRange(CACHEKEY_MSG_QUEUE + chatroomId, 0l, -1l); Map<String,Long> statistics = this.reStatistics(chatroomId); Integer maxPage = getMaxPage(chatroomId, String.valueOf(statistics.get("historyMsgCount")+mesList.size())); String key = CACHEKEY_MESSAGE_HISTORY + chatroomId+ "_" + pageNo; if (StringUtils.isEmpty(chatroomId) || pageNo == null || pageNo > maxPage) { - return new Result(false, "参数错误"); + return new Result(false, "鍙傛暟閿欒"); } List<MsgChatroomMsg> msgList = redis.lstAll(key); msgList = this.distinct(msgList, chatroomId); @@ -273,7 +273,7 @@ } /** - * 去除重复消息 + * 鍘婚櫎閲嶅娑堟伅 * * @return */ @@ -295,7 +295,7 @@ /** - * 获取A类消息最大页码 + * 鑾峰彇A绫绘秷鎭渶澶ч〉鐮� * * @param chatroomId * @return -- Gitblit v1.8.0