|
@@ -37,7 +37,7 @@ public class WebSocketServer {
|
|
|
public static ICommunityChatMsgService chatMsgService;
|
|
|
|
|
|
@Autowired
|
|
|
- public void setChatMsgService(ICommunityChatMsgService chatMsgService){
|
|
|
+ public void setChatMsgService(ICommunityChatMsgService chatMsgService) {
|
|
|
WebSocketServer.chatMsgService = chatMsgService;
|
|
|
}
|
|
|
|
|
@@ -84,19 +84,53 @@ public class WebSocketServer {
|
|
|
public void onMessage(String message) throws IOException {
|
|
|
JSONObject jsonObject = JSONObject.parseObject(message);
|
|
|
Long sendUserId = jsonObject.getLong("sendUserId");
|
|
|
- Long userId = jsonObject.getLong("userId");
|
|
|
- String type = jsonObject.getString("type");
|
|
|
- String detail = jsonObject.getString("detail");
|
|
|
+ Long receiveUserId = jsonObject.getLong("receiveUserId");
|
|
|
+ String type = jsonObject.getString("type"); //消息分类 chat
|
|
|
+ int messageType = jsonObject.getInteger("messageType"); //消息类型
|
|
|
+ JSONObject sendText = jsonObject.getJSONObject("sendText");
|
|
|
if (type.equals(MessageType.CHAT.getType())) {
|
|
|
log.debug("聊天消息推送");
|
|
|
- sendToUser(String.valueOf(userId), JSONObject.toJSONString(jsonObject));
|
|
|
- //存储历史消息
|
|
|
+ sendToUser(String.valueOf(receiveUserId), JSONObject.toJSONString(jsonObject));
|
|
|
+
|
|
|
CommunityChatMsg chatMsg = new CommunityChatMsg();
|
|
|
chatMsg.setSenderId(sendUserId);
|
|
|
- chatMsg.setReceiverId(userId);
|
|
|
- chatMsg.setContent(detail);
|
|
|
+ chatMsg.setReceiverId(receiveUserId);
|
|
|
chatMsg.setCreateBy(sendUserId);
|
|
|
+ chatMsg.setMessageType(messageType);
|
|
|
chatMsg.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
+ switch (messageType) {
|
|
|
+ case 0:
|
|
|
+ //文字
|
|
|
+ String context = sendText.getString("context");
|
|
|
+ //存储历史消息
|
|
|
+ chatMsg.setContent(context);
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ //图片
|
|
|
+ chatMsg.setFileUrl(sendText.getString("fileUrl"));
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ //语音
|
|
|
+ chatMsg.setFileUrl(sendText.getString("fileUrl"));
|
|
|
+ chatMsg.setTime(sendText.getInteger("time"));
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ //定位
|
|
|
+ String address = sendText.getString("address");
|
|
|
+ Double latitude = sendText.getDouble("latitude"); //纬度
|
|
|
+ Double longitude = sendText.getDouble("longitude"); //经度
|
|
|
+ chatMsg.setAddress(address);
|
|
|
+ chatMsg.setLatitude(latitude);
|
|
|
+ chatMsg.setLongitude(longitude);
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ //视频
|
|
|
+ chatMsg.setFileUrl(sendText.getString("fileUrl"));
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //存储历史消息
|
|
|
chatMsgService.save(chatMsg);
|
|
|
}
|
|
|
}
|