提交 5438dda4 编写于 作者: cxt104926's avatar cxt104926

bug fix

上级 85125cc5
......@@ -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. 正在学习使用这些技术,若有错误 不对之处欢迎大佬指正
......
......@@ -28,13 +28,6 @@
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<!-- 集成json -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.74</version>
</dependency>
<!-- 获取系统信息 -->
<dependency>
<groupId>com.github.oshi</groupId>
......
......@@ -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<String, Session> 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 {
});
}
/**
* 单聊
*
......
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<ChatMsg> {
int addMsg(@Param("chatMsg") ChatMsg chatMsg);
}
......@@ -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;
}
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;
}
}
......@@ -9,13 +9,13 @@
<!--
Added the entity ChatMsg.
-->
<changeSet id="20210615-01" author="cxt">
<changeSet id="20210616-01" author="cxt">
<createTable tableName="chat_msg" remarks="聊天消息">
<column name="id" type="varchar(22)">
<column name="id" type="int(11)" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="msg" type="varchar(300)" remarks="消息内容">
<column name="msg" type="varchar(100)" remarks="消息内容">
<constraints nullable="false"/>
</column>
......@@ -27,7 +27,7 @@
<constraints nullable="false"/>
</column>
<column name="send_type" type="varchar(2)" remarks="发送消息id">
<column name="send_type" type="varchar(2)" remarks="聊天类型">
<constraints nullable="false"/>
</column>
......@@ -35,21 +35,14 @@
<constraints nullable="false"/>
</column>
<column name="create_time" type="datetime" remarks="创建时间">
<column name="is_read" type="varchar(2)" remarks="是否已读">
<constraints nullable="false"/>
</column>
<column name="create_by" type="varchar(18)" remarks="创建人">
<column name="send_time" type="datetime" remarks="发送时间">
<constraints nullable="false"/>
</column>
<column name="update_time" type="datetime" remarks="更新时间">
<constraints nullable="true"/>
</column>
<column name="update_by" type="varchar(18)" remarks="更新人">
<constraints nullable="true"/>
</column>
</createTable>
</changeSet>
......
......@@ -11,6 +11,6 @@
<include file="classpath:config/liquibase/20210331_creat_table_role.xml" relativeToChangelogFile="false"/>
<include file="classpath:config/liquibase/20210331_creat_table_role_jurisdiction.xml" relativeToChangelogFile="false"/>
<include file="classpath:config/liquibase/20210615_creat_table_ChatFriends.xml" relativeToChangelogFile="false"/>
<include file="classpath:config/liquibase/20210615_creat_table_ChatMsg.xml" relativeToChangelogFile="false"/>
<include file="classpath:config/liquibase/20210616_creat_table_ChatMsg.xml" relativeToChangelogFile="false"/>
</databaseChangeLog>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.stu.stusystem.mapper.chat.ChatMapper">
<insert id="addMsg">
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})
</insert>
</mapper>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册