diff --git a/README.md b/README.md index 21521c3b5dc30692cc043204a61419c1e9b5ceeb..6b1ed244d567bbefc7a739697cd756279171626b 100644 --- a/README.md +++ b/README.md @@ -60,9 +60,18 @@ 管理员账号:admin 密码:1 -#### 5.说在最后 -1. 系统正在开发,想到的后面再更新 -2. 正在学习使用这些技术,若有错误 不对之处欢迎大佬指正 +#### 5.报错 + ① 启动项目时候卡死,控制台报 `Waiting for changelog lock....` + 出现的问题:liquibase导致表锁死报错 + 解决办法,在数据库中执行更新语句,将DATABASECHANGELOGLOCK表中锁状态改成0 + + UPDATE DATABASECHANGELOGLOCK + SET locked=0, lockgranted=null, lockedby=null + WHERE id=1 + +#### 6.说在最后 + 1. 系统正在开发,想到的后面再更新 + 2. 正在学习使用这些技术,若有错误 不对之处欢迎大佬指正 diff --git a/pom.xml b/pom.xml index 963971d560485cf6c5b5cfb0173729cf5cfdeb5f..1a8a64a288022a3ae377536547acdbc2ed504e41 100644 --- a/pom.xml +++ b/pom.xml @@ -28,13 +28,6 @@ spring-boot-starter-websocket - - - com.alibaba - fastjson - 1.2.74 - - com.github.oshi diff --git a/src/main/java/com/stu/stusystem/controller/chat/ChatController.java b/src/main/java/com/stu/stusystem/controller/chat/ChatController.java index 5f7a5d0033ef936542be46e187fe12bb194064bc..26e85333ea124faba6a55d9cd55c6efeeb536fbf 100644 --- a/src/main/java/com/stu/stusystem/controller/chat/ChatController.java +++ b/src/main/java/com/stu/stusystem/controller/chat/ChatController.java @@ -4,7 +4,9 @@ import com.alibaba.fastjson.JSONArray; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.stu.stusystem.model.chat.ChatMsg; +import com.stu.stusystem.service.chat.ChatService; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.websocket.*; @@ -24,6 +26,13 @@ import java.util.concurrent.ConcurrentHashMap; @ServerEndpoint("/stu/chat/{name}") public class ChatController { + private static ChatService chatMsgService; + + @Autowired + public void setChatService(ChatService chatService) { + ChatController.chatMsgService = chatService; + } + private static final Map clients = new ConcurrentHashMap<>(); @OnOpen @@ -33,7 +42,6 @@ public class ChatController { log.info("当前在线用户数:{}", clients.size()); } - /** * 发送消息,前端将消息转成json字符串,后端转成对象 */ @@ -51,7 +59,14 @@ public class ChatController { } else if ("3".equals(msg.getSendType())) { Session se = clients.get(msg.getAcceptUser()); if (se != null) { + new Thread(() -> { + if (chatMsgService == null) + return; + chatMsgService.addMsg(msg); + }).start(); sendMessage(se, msg); + }else { + } } } catch (JsonProcessingException e) { @@ -140,7 +155,6 @@ public class ChatController { }); } - /** * 单聊 * diff --git a/src/main/java/com/stu/stusystem/mapper/chat/ChatMapper.java b/src/main/java/com/stu/stusystem/mapper/chat/ChatMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..3c1782585763b0d4eac0b7225b750b3350606a40 --- /dev/null +++ b/src/main/java/com/stu/stusystem/mapper/chat/ChatMapper.java @@ -0,0 +1,15 @@ +package com.stu.stusystem.mapper.chat; + +import com.stu.stusystem.common.CommonMapper; +import com.stu.stusystem.model.chat.ChatMsg; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + * @author: cxt + * @time: 2021/6/23 + */ +@Mapper +public interface ChatMapper extends CommonMapper { + int addMsg(@Param("chatMsg") ChatMsg chatMsg); +} diff --git a/src/main/java/com/stu/stusystem/model/chat/ChatMsg.java b/src/main/java/com/stu/stusystem/model/chat/ChatMsg.java index 18a78fe7c7429433cf681471ec7d551fbcd83bc8..601d04d9e6697fb2a9aeed542443a9320bf81857 100644 --- a/src/main/java/com/stu/stusystem/model/chat/ChatMsg.java +++ b/src/main/java/com/stu/stusystem/model/chat/ChatMsg.java @@ -16,7 +16,7 @@ import java.util.Date; @NoArgsConstructor public class ChatMsg extends BaseModel { - private String id; + private Integer id; // 消息内容 private String msg; @@ -33,5 +33,9 @@ public class ChatMsg extends BaseModel { // 内容类型:0文本;1图片; private String msgType; + // 是否已读 + private String isRead; + + // 发送时间 private Date sendTime; } diff --git a/src/main/java/com/stu/stusystem/service/chat/ChatService.java b/src/main/java/com/stu/stusystem/service/chat/ChatService.java new file mode 100644 index 0000000000000000000000000000000000000000..0f98f5db404cbf218143004789365e897f54bf52 --- /dev/null +++ b/src/main/java/com/stu/stusystem/service/chat/ChatService.java @@ -0,0 +1,32 @@ +package com.stu.stusystem.service.chat; + +import com.stu.stusystem.common.ApiException; +import com.stu.stusystem.mapper.chat.ChatMapper; +import com.stu.stusystem.model.chat.ChatMsg; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * @author: cxt + * @time: 2021/6/23 + */ +@Service +public class ChatService { + + private ChatMapper chatMapper; + + public void addMsg(ChatMsg chatMsg){ + if (chatMapper == null){ + return; + } + int insert = this.chatMapper.addMsg(chatMsg); + if (insert == 0){ + throw new ApiException(ApiException.SAVE_FAIL); + } + } + + @Autowired + public void setChatMapper(ChatMapper chatMapper) { + this.chatMapper = chatMapper; + } +} diff --git a/src/main/resources/config/liquibase/20210615_creat_table_ChatMsg.xml b/src/main/resources/config/liquibase/20210616_creat_table_ChatMsg.xml similarity index 70% rename from src/main/resources/config/liquibase/20210615_creat_table_ChatMsg.xml rename to src/main/resources/config/liquibase/20210616_creat_table_ChatMsg.xml index 6bff2c93051ba9547a3408a6540b5cafd8e88b0e..2f06dd6309e052602338e5d6a64cd83e5c3c7168 100644 --- a/src/main/resources/config/liquibase/20210615_creat_table_ChatMsg.xml +++ b/src/main/resources/config/liquibase/20210616_creat_table_ChatMsg.xml @@ -9,13 +9,13 @@ - + - + - + @@ -27,7 +27,7 @@ - + @@ -35,21 +35,14 @@ - + - + - - - - - - - diff --git a/src/main/resources/config/master.xml b/src/main/resources/config/master.xml index d3e0c297ade5e1645f3c8f4ad94daa87c585fa47..d019b980872438508b0148f953ed0b362f3943b8 100644 --- a/src/main/resources/config/master.xml +++ b/src/main/resources/config/master.xml @@ -11,6 +11,6 @@ - + \ No newline at end of file diff --git a/src/main/resources/mapper/chat/ChatMapper.xml b/src/main/resources/mapper/chat/ChatMapper.xml new file mode 100644 index 0000000000000000000000000000000000000000..f8b16ed4693e235d26be2a4750f634a773df0324 --- /dev/null +++ b/src/main/resources/mapper/chat/ChatMapper.xml @@ -0,0 +1,9 @@ + + + + + insert into chat_msg(msg, accept_user, send_user, send_type, msg_type, is_read, send_time) + VALUES (#{chatMsg.msg}, #{chatMsg.acceptUser}, #{chatMsg.sendUser}, #{chatMsg.sendType}, #{chatMsg.msgType}, #{chatMsg.isRead}, #{chatMsg.sendTime}) + + + \ No newline at end of file