Browse Source

聊天大厅和top50接口调整

sunkean 3 years ago
parent
commit
e04c776c6d

+ 25 - 0
src/main/java/com/izouma/nineth/dto/PublicScreenChatExceptionMsg.java

@@ -0,0 +1,25 @@
+package com.izouma.nineth.dto;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class PublicScreenChatExceptionMsg {
+
+    /**
+     * 消息类型
+     * 1:重复登陆
+     * 2:信息保存异常
+     * 3:非法消息
+     * 4:不合法参数
+     */
+    private int type;
+
+    /**
+     * 消息体
+     */
+    private String msg;
+}

+ 3 - 3
src/main/java/com/izouma/nineth/web/UserHoldCountController.java

@@ -30,10 +30,10 @@ public class UserHoldCountController {
     }
     }
 
 
     @GetMapping("/top")
     @GetMapping("/top")
-    public List<UserHoldDTO> top() {
+    public List<UserHoldDTO> top(@RequestParam int size) {
         PageQuery pageQuery = new PageQuery();
         PageQuery pageQuery = new PageQuery();
         pageQuery.setPage(0);
         pageQuery.setPage(0);
-        pageQuery.setSize(50);
+        pageQuery.setSize(size);
         List<UserHoldDTO> userHoldDTOs = userHoldCountService.all(pageQuery).getContent();
         List<UserHoldDTO> userHoldDTOs = userHoldCountService.all(pageQuery).getContent();
         userHoldDTOs.sort(Comparator.comparing(UserHoldDTO::getPrice).reversed());
         userHoldDTOs.sort(Comparator.comparing(UserHoldDTO::getPrice).reversed());
         return userHoldDTOs;
         return userHoldDTOs;
@@ -41,7 +41,7 @@ public class UserHoldCountController {
 
 
     @GetMapping("/app/top")
     @GetMapping("/app/top")
     public List<UserHoldDTO> appTop() {
     public List<UserHoldDTO> appTop() {
-        List<UserHoldDTO> top = top();
+        List<UserHoldDTO> top = top(20);
         if (CollectionUtils.isEmpty(top)) {
         if (CollectionUtils.isEmpty(top)) {
             return null;
             return null;
         }
         }

+ 10 - 9
src/main/java/com/izouma/nineth/websocket/PublicScreenChatWebsocket.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
 import com.izouma.nineth.domain.PublicScreenChat;
 import com.izouma.nineth.domain.PublicScreenChat;
 import com.izouma.nineth.domain.PurchaseLevel;
 import com.izouma.nineth.domain.PurchaseLevel;
 import com.izouma.nineth.domain.User;
 import com.izouma.nineth.domain.User;
+import com.izouma.nineth.dto.PublicScreenChatExceptionMsg;
 import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.repo.PublicScreenChatRepo;
 import com.izouma.nineth.repo.PublicScreenChatRepo;
 import com.izouma.nineth.repo.UserRepo;
 import com.izouma.nineth.repo.UserRepo;
@@ -64,12 +65,12 @@ public class PublicScreenChatWebsocket extends WebsocketCommon {
         // 判断当前玩家是否在其他地方登陆
         // 判断当前玩家是否在其他地方登陆
         if (clients.containsKey(PREFIX.concat(userId))) {
         if (clients.containsKey(PREFIX.concat(userId))) {
             String msg = String.format("已在别处登陆,sessionId为[%S],正在为您关闭本连接", session.getId());
             String msg = String.format("已在别处登陆,sessionId为[%S],正在为您关闭本连接", session.getId());
-            exceptionHandle(userId, msg);
+            exceptionHandle(userId, new PublicScreenChatExceptionMsg(1, msg));
             try {
             try {
                 log.info("关闭session连接");
                 log.info("关闭session连接");
                 clients.get(PREFIX.concat(userId)).close();
                 clients.get(PREFIX.concat(userId)).close();
             } catch (Exception e) {
             } catch (Exception e) {
-                exceptionHandle(userId, String.format("session close throw exception[%S]", e));
+                exceptionHandle(userId, new PublicScreenChatExceptionMsg(1, String.format("session close throw exception[%S]", e)));
                 return;
                 return;
             }
             }
         }
         }
@@ -81,7 +82,7 @@ public class PublicScreenChatWebsocket extends WebsocketCommon {
             publicScreenChat = savePublicScreenChat(userId, format, true);
             publicScreenChat = savePublicScreenChat(userId, format, true);
         } catch (Exception e) {
         } catch (Exception e) {
             String errMsg = String.format("玩家进入大厅,保存信息发生异常[%S]", e);
             String errMsg = String.format("玩家进入大厅,保存信息发生异常[%S]", e);
-            exceptionHandle(userId, errMsg);
+            exceptionHandle(userId, new PublicScreenChatExceptionMsg(2, errMsg));
             return;
             return;
         }
         }
         sendMessageToOther(clients, JSON.toJSONString(publicScreenChat), PREFIX.concat(userId));
         sendMessageToOther(clients, JSON.toJSONString(publicScreenChat), PREFIX.concat(userId));
@@ -103,7 +104,7 @@ public class PublicScreenChatWebsocket extends WebsocketCommon {
             publicScreenChat = savePublicScreenChat(userId, format, true);
             publicScreenChat = savePublicScreenChat(userId, format, true);
         } catch (Exception e) {
         } catch (Exception e) {
             String errMsg = String.format("玩家离开大厅,保存信息发生异常[%S]", e);
             String errMsg = String.format("玩家离开大厅,保存信息发生异常[%S]", e);
-            exceptionHandle(userId, errMsg);
+            exceptionHandle(userId, new PublicScreenChatExceptionMsg(2, errMsg));
             return;
             return;
         }
         }
         sendMessageToOther(clients, JSON.toJSONString(publicScreenChat), PREFIX.concat(userId));
         sendMessageToOther(clients, JSON.toJSONString(publicScreenChat), PREFIX.concat(userId));
@@ -115,12 +116,12 @@ public class PublicScreenChatWebsocket extends WebsocketCommon {
         init();
         init();
         if (StringUtils.isBlank(message)) {
         if (StringUtils.isBlank(message)) {
             String errMsg = "Illegal parameter : message can not be null";
             String errMsg = "Illegal parameter : message can not be null";
-            exceptionHandle(userId, errMsg);
+            exceptionHandle(userId, new PublicScreenChatExceptionMsg(4, errMsg));
             return;
             return;
         }
         }
         if (!contentAuditService.auditText(message)) {
         if (!contentAuditService.auditText(message)) {
             savePublicScreenChat(userId, message, false);
             savePublicScreenChat(userId, message, false);
-            exceptionHandle(userId, "消息包含非法内容");
+            exceptionHandle(userId, new PublicScreenChatExceptionMsg(3, "消息包含非法内容"));
             return;
             return;
         }
         }
         PublicScreenChat publicScreenChat;
         PublicScreenChat publicScreenChat;
@@ -128,7 +129,7 @@ public class PublicScreenChatWebsocket extends WebsocketCommon {
             publicScreenChat = savePublicScreenChat(userId, message, true);
             publicScreenChat = savePublicScreenChat(userId, message, true);
         } catch (Exception e) {
         } catch (Exception e) {
             String errMsg = String.format("玩家发送消息,保存信息发生异常[%S]", e);
             String errMsg = String.format("玩家发送消息,保存信息发生异常[%S]", e);
-            exceptionHandle(userId, errMsg);
+            exceptionHandle(userId, new PublicScreenChatExceptionMsg(2, errMsg));
             return;
             return;
         }
         }
         sendMessageToAll(clients, JSON.toJSONString(publicScreenChat), PREFIX.concat(userId));
         sendMessageToAll(clients, JSON.toJSONString(publicScreenChat), PREFIX.concat(userId));
@@ -173,8 +174,8 @@ public class PublicScreenChatWebsocket extends WebsocketCommon {
         return publicScreenChatRepo.save(publicScreenChat);
         return publicScreenChatRepo.save(publicScreenChat);
     }
     }
 
 
-    private void exceptionHandle(String userId, String msg) {
-        log.error(msg);
+    private void exceptionHandle(String userId, PublicScreenChatExceptionMsg msg) {
+        log.error(JSON.toJSONString(msg));
         // 推送消息给该玩家
         // 推送消息给该玩家
         sendMessageTo(clients, JSON.toJSONString(msg), PREFIX.concat(userId));
         sendMessageTo(clients, JSON.toJSONString(msg), PREFIX.concat(userId));
     }
     }

+ 1 - 1
src/main/vue/src/widgets/UserHoldTop.vue

@@ -49,7 +49,7 @@ export default {
     },
     },
      mounted() {
      mounted() {
         this.$http
         this.$http
-            .get('/userHold/top')
+            .get('/userHold/top', { size: 50 })
             .then(res => {
             .then(res => {
                 this.list = res;
                 this.list = res;
             });
             });