|
|
@@ -7,6 +7,7 @@ import com.izouma.meta.domain.PublicScreenChat;
|
|
|
import com.izouma.meta.dto.PublicScreenChatExceptionMsg;
|
|
|
import com.izouma.meta.dto.PurchaseLevelDTO;
|
|
|
import com.izouma.meta.dto.WebsocketUser;
|
|
|
+import com.izouma.meta.enums.ChatType;
|
|
|
import com.izouma.meta.exception.BusinessException;
|
|
|
import com.izouma.meta.repo.PublicScreenChatRepo;
|
|
|
import com.izouma.meta.service.ContentAuditService;
|
|
|
@@ -74,7 +75,7 @@ public class PublicScreenChatWebsocket {
|
|
|
String format = String.format("玩家[%S][%S]进入大厅", userId, nickName);
|
|
|
PublicScreenChat publicScreenChat;
|
|
|
try {
|
|
|
- publicScreenChat = savePublicScreenChat(userId, format, true);
|
|
|
+ publicScreenChat = savePublicScreenChat(userId, format, true, ChatType.DEFAULT, null);
|
|
|
} catch (Exception e) {
|
|
|
String errMsg = String.format("玩家进入大厅,保存信息发生异常[%S]", e);
|
|
|
exceptionHandle(userId, new PublicScreenChatExceptionMsg(2, errMsg));
|
|
|
@@ -97,7 +98,7 @@ public class PublicScreenChatWebsocket {
|
|
|
String format = String.format("玩家[%S][%S]离开大厅", userId, nickName);
|
|
|
PublicScreenChat publicScreenChat;
|
|
|
try {
|
|
|
- publicScreenChat = savePublicScreenChat(userId, format, true);
|
|
|
+ publicScreenChat = savePublicScreenChat(userId, format, true, ChatType.DEFAULT, null);
|
|
|
} catch (Exception e) {
|
|
|
String errMsg = String.format("玩家离开大厅,保存信息发生异常[%S]", e);
|
|
|
exceptionHandle(userId, new PublicScreenChatExceptionMsg(2, errMsg));
|
|
|
@@ -121,20 +122,61 @@ public class PublicScreenChatWebsocket {
|
|
|
return;
|
|
|
}
|
|
|
log.info(String.format("收到来自userId[%S]的消息[%S]", userId, message));
|
|
|
- if (!contentAuditService.auditText(message)) {
|
|
|
- savePublicScreenChat(userId, message, false);
|
|
|
+ JSONObject jsonObject;
|
|
|
+ try {
|
|
|
+ jsonObject = JSON.parseObject(message);
|
|
|
+ } catch (Exception e) {
|
|
|
+ String errMsg = String.format("json parse throw exception [%S]", e.getMessage());
|
|
|
+ log.error(errMsg);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (Objects.isNull(jsonObject)) {
|
|
|
+ log.error("Illegal parameter : jsonObject can not be null");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String type = jsonObject.getString("type");
|
|
|
+ if (StringUtils.isBlank(type)) {
|
|
|
+ log.error("Illegal parameter : type can not be null");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String msg = jsonObject.getString("msg");
|
|
|
+ String toUserId = jsonObject.getString("toUserId");
|
|
|
+ PublicScreenChat publicScreenChat = new PublicScreenChat();
|
|
|
+ if (Constants.PRIVATE_CHAT.equals(type)) {
|
|
|
+ if (StringUtils.isBlank(toUserId)) {
|
|
|
+ log.error("Illegal parameter : toUserId can not be null");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!contentAuditService.auditText(msg)) {
|
|
|
+ if (Constants.PUBLIC_CHAT.equals(type)) {
|
|
|
+ savePublicScreenChat(userId, message, false, ChatType.PUBLIC, null);
|
|
|
+ }
|
|
|
+ if (Constants.PRIVATE_CHAT.equals(type)) {
|
|
|
+ savePublicScreenChat(userId, message, false, ChatType.PRIVATE, toUserId);
|
|
|
+ }
|
|
|
exceptionHandle(userId, new PublicScreenChatExceptionMsg(3, "消息包含非法内容"));
|
|
|
return;
|
|
|
}
|
|
|
- PublicScreenChat publicScreenChat;
|
|
|
try {
|
|
|
- publicScreenChat = savePublicScreenChat(userId, message, true);
|
|
|
+ if (Constants.PUBLIC_CHAT.equals(type)) {
|
|
|
+ publicScreenChat = savePublicScreenChat(userId, msg, true, ChatType.PUBLIC, null);
|
|
|
+ }
|
|
|
+ if (Constants.PRIVATE_CHAT.equals(type)) {
|
|
|
+ publicScreenChat = savePublicScreenChat(userId, msg, true, ChatType.PRIVATE, toUserId);
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
String errMsg = String.format("玩家发送消息,保存信息发生异常[%S]", e);
|
|
|
exceptionHandle(userId, new PublicScreenChatExceptionMsg(2, errMsg));
|
|
|
return;
|
|
|
}
|
|
|
- sendMessageToAll(clients, JSON.toJSONString(publicScreenChat), PREFIX.concat(userId));
|
|
|
+ if (Constants.PUBLIC_CHAT.equals(type)) {
|
|
|
+ sendMessageToAll(clients, JSON.toJSONString(publicScreenChat), PREFIX.concat(userId));
|
|
|
+ }
|
|
|
+ if (Constants.PRIVATE_CHAT.equals(type)) {
|
|
|
+ websocketCommon.sendMessageTo(clients, JSON.toJSONString(publicScreenChat), PREFIX.concat(toUserId));
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -157,7 +199,7 @@ public class PublicScreenChatWebsocket {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private PublicScreenChat savePublicScreenChat(String userId, String messageInfo, boolean illegal) {
|
|
|
+ private PublicScreenChat savePublicScreenChat(String userId, String messageInfo, boolean illegal, ChatType chatType, String toUserId) {
|
|
|
String resultForWebsocketUser = websocketCommon.getRequest("/user/websocket/".concat(userId));
|
|
|
log.info(String.format("userId:[%S] userInfo:[%S]", userId, resultForWebsocketUser));
|
|
|
WebsocketUser websocketUser;
|
|
|
@@ -198,6 +240,44 @@ public class PublicScreenChatWebsocket {
|
|
|
publicScreenChat.setIllegal(illegal);
|
|
|
publicScreenChat.setRecall(1);
|
|
|
publicScreenChat.setType(1);
|
|
|
+ publicScreenChat.setChatType(chatType);
|
|
|
+ if (!ChatType.PRIVATE.equals(chatType)) {
|
|
|
+ return publicScreenChatRepo.save(publicScreenChat);
|
|
|
+ }
|
|
|
+ String resultForWebsocketToUser = websocketCommon.getRequest("/user/websocket/".concat(toUserId));
|
|
|
+ log.info(String.format("toUserId:[%S] toUserInfo:[%S]", toUserId, resultForWebsocketToUser));
|
|
|
+ WebsocketUser websocketToUser;
|
|
|
+ try {
|
|
|
+ websocketToUser = JSONObject.parseObject(resultForWebsocketToUser, WebsocketUser.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ String errMsg = String.format("WebsocketUser JSON parse throw exception:[%S]", e);
|
|
|
+ log.error(errMsg);
|
|
|
+ throw new BusinessException(errMsg);
|
|
|
+ }
|
|
|
+ if (Objects.isNull(websocketToUser)) {
|
|
|
+ String errMsg = "用户信息不存在";
|
|
|
+ log.error(errMsg);
|
|
|
+ throw new BusinessException(errMsg);
|
|
|
+ }
|
|
|
+ publicScreenChat.setToUserAvatar(websocketToUser.getAvatar());
|
|
|
+ publicScreenChat.setToUserNickname(websocketToUser.getNickname());
|
|
|
+ publicScreenChat.setToUserLevel(websocketToUser.getLevel());
|
|
|
+ String resultForToUserPurchaseLevel = websocketCommon.getRequest("/purchaseLevel/websocket/".concat(String.valueOf(websocketToUser.getLevel())));
|
|
|
+ log.info(String.format("toUserId:[%S] toUserPurchaseLevelInfo:[%S]", toUserId, resultForToUserPurchaseLevel));
|
|
|
+ PurchaseLevelDTO toUserPurchaseLevelDTO;
|
|
|
+ try {
|
|
|
+ toUserPurchaseLevelDTO = JSONObject.parseObject(resultForToUserPurchaseLevel, PurchaseLevelDTO.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ String errMsg = String.format("toUserPurchaseLevelDTO JSON parse throw exception:[%S]", e);
|
|
|
+ log.error(errMsg);
|
|
|
+ throw new BusinessException(errMsg);
|
|
|
+ }
|
|
|
+ if (Objects.isNull(toUserPurchaseLevelDTO)) {
|
|
|
+ throw new BusinessException("用户等级称号信息不存在");
|
|
|
+ }
|
|
|
+ publicScreenChat.setToUserRealm(toUserPurchaseLevelDTO.getRealm());
|
|
|
+ publicScreenChat.setToUserTitle(toUserPurchaseLevelDTO.getTitle());
|
|
|
+ publicScreenChat.setToUserId(Long.parseLong(toUserId));
|
|
|
return publicScreenChatRepo.save(publicScreenChat);
|
|
|
}
|
|
|
|