153 changed files with 10968 additions and 6215 deletions
File diff suppressed because one or more lines are too long
@ -0,0 +1,32 @@
|
||||
package net.sopod.soim.client.cmd.args; |
||||
|
||||
import com.beust.jcommander.Parameter; |
||||
import lombok.Data; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* ArgsCreateGroup |
||||
* |
||||
* @author tmy |
||||
* @date 2022-06-05 09:32 |
||||
*/ |
||||
@Data |
||||
public class ArgsGroup { |
||||
|
||||
// @Parameter
|
||||
// private List<String> parameters;
|
||||
|
||||
@Parameter(names = {"create"}, required = false, description = "群聊名称") |
||||
private String groupNameCreate; |
||||
|
||||
@Parameter(names = {"search"}, required = false, description = "群聊名称") |
||||
private String groupNameSearch; |
||||
|
||||
@Parameter(names = {"join"}, required = false, description = "群聊id") |
||||
private Integer joinGroupId; |
||||
|
||||
@Parameter(names = {"users"}, required = false, description = "群聊id") |
||||
private Integer usersGroupId; |
||||
|
||||
} |
||||
@ -0,0 +1,123 @@
|
||||
package net.sopod.soim.client.handler.cmd; |
||||
|
||||
import com.google.inject.Inject; |
||||
import com.google.inject.Singleton; |
||||
import net.sopod.soim.client.cmd.args.ArgsGroup; |
||||
import net.sopod.soim.client.cmd.handler.CmdHandler; |
||||
import net.sopod.soim.client.logger.Console; |
||||
import net.sopod.soim.client.session.SoImSession; |
||||
import net.sopod.soim.common.util.ImClock; |
||||
import net.sopod.soim.common.util.StringUtil; |
||||
import net.sopod.soim.data.msg.common.Res; |
||||
import net.sopod.soim.data.msg.group.Group; |
||||
|
||||
import java.util.List; |
||||
import java.util.concurrent.CompletableFuture; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* GroupHandler |
||||
* |
||||
* @author tmy |
||||
* @date 2022-06-05 09:35 |
||||
*/ |
||||
@Singleton |
||||
public class GroupHandler implements CmdHandler<ArgsGroup> { |
||||
|
||||
@Inject |
||||
private SoImSession soImSession; |
||||
|
||||
@Override |
||||
public ArgsGroup newArgsInstance() { |
||||
return new ArgsGroup(); |
||||
} |
||||
|
||||
@Override |
||||
public void handleArgs(ArgsGroup args) { |
||||
if (args.getGroupNameCreate() != null) { |
||||
this.handleGroupCreate(args.getGroupNameCreate()); |
||||
|
||||
} else if (args.getGroupNameSearch() != null) { |
||||
this.handleGroupSearch(args.getGroupNameSearch()); |
||||
|
||||
} else if (args.getJoinGroupId() != null) { |
||||
this.handleGroupJoin(args.getJoinGroupId()); |
||||
|
||||
} else if (args.getUsersGroupId() != null) { |
||||
this.handleGroupUsers(args.getUsersGroupId()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 创建群聊 |
||||
*/ |
||||
private void handleGroupCreate(String groupName) { |
||||
if (StringUtil.isBlank(groupName)) { |
||||
Console.error("群聊名称不能为空"); |
||||
return; |
||||
} |
||||
Group.ReqCreateGroup req = Group.ReqCreateGroup.newBuilder() |
||||
.setGroupName(groupName) |
||||
.build(); |
||||
CompletableFuture<Res.ResState> future = soImSession.send(req); |
||||
Res.ResState res = future.join(); |
||||
String message = res.getMessage(); |
||||
Console.info(message); |
||||
} |
||||
|
||||
/** |
||||
* 群聊搜索 |
||||
*/ |
||||
private void handleGroupSearch(String groupName) { |
||||
if (StringUtil.isBlank(groupName)) { |
||||
Console.error("群聊名称不能为空"); |
||||
return; |
||||
} |
||||
Group.ReqSearchGroup req = Group.ReqSearchGroup.newBuilder() |
||||
.setGroupName(groupName) |
||||
.build(); |
||||
CompletableFuture<Group.ResSearchGroup> future = soImSession.send(req); |
||||
Group.ResSearchGroup res = future.join(); |
||||
List<Group.GroupInfo> groupsList = res.getGroupsList(); |
||||
|
||||
List<String> userLines = groupsList.stream() |
||||
.map(g -> g.getGid() + "|" + g.getGroupName() + "|" + g.getUserLimit() + "|" + g.getUserNum() + "|" + ImClock.millis2time(g.getCreateTime())) |
||||
.collect(Collectors.toList()); |
||||
Console.logList("群聊搜索结果", userLines); |
||||
} |
||||
|
||||
/** |
||||
* 加入群聊 |
||||
*/ |
||||
private void handleGroupJoin(Integer groupId) { |
||||
Group.ReqJoinGroup req = Group.ReqJoinGroup.newBuilder() |
||||
.setGid(groupId) |
||||
.build(); |
||||
CompletableFuture<Res.ResState> future = soImSession.send(req); |
||||
Res.ResState res = future.join(); |
||||
String message = res.getMessage(); |
||||
Console.info(message); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 群聊用户列表 |
||||
*/ |
||||
private void handleGroupUsers(Integer groupId) { |
||||
Group.ReqGroupUsers req = Group.ReqGroupUsers.newBuilder() |
||||
.setGid(groupId) |
||||
.build(); |
||||
CompletableFuture<Group.ResGroupUsers> future = soImSession.send(req); |
||||
Group.ResGroupUsers res = future.join(); |
||||
List<Group.UserInfo> usersList = res.getUsersList(); |
||||
|
||||
List<String> userLines = usersList.stream() |
||||
.map(u -> u.getUid() + "|" + u.getAccount() + "|" + |
||||
u.getNickname() + "|" + |
||||
u.getOnline() + "|" + |
||||
ImClock.millis2time(u.getLastActive()) |
||||
).collect(Collectors.toList()); |
||||
Console.logList("群用户列表", userLines); |
||||
} |
||||
|
||||
} |
||||
@ -1,27 +0,0 @@
|
||||
package net.sopod.soim.client.handler.msg; |
||||
|
||||
import com.google.inject.Singleton; |
||||
import net.sopod.soim.client.logger.Logger; |
||||
import net.sopod.soim.client.session.MessageHandler; |
||||
import net.sopod.soim.data.msg.user.Friend; |
||||
|
||||
/** |
||||
* ResAddFriendHandler |
||||
* |
||||
* @author tmy |
||||
* @date 2022-05-23 21:42 |
||||
*/ |
||||
@Singleton |
||||
public class ResAddFriendHandler implements MessageHandler<Friend.ResAddFriend> { |
||||
|
||||
@Override |
||||
public void handleMsg(Friend.ResAddFriend res) { |
||||
System.out.println(res); |
||||
if (res.getSuccess()) { |
||||
Logger.info("添加好友成功"); |
||||
} else { |
||||
Logger.error("添加失败:{}", res.getMsg()); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -1,30 +0,0 @@
|
||||
package net.sopod.soim.client.handler.msg; |
||||
|
||||
import com.google.inject.Singleton; |
||||
import net.sopod.soim.client.logger.Logger; |
||||
import net.sopod.soim.client.session.MessageHandler; |
||||
import net.sopod.soim.data.msg.user.Friend; |
||||
import net.sopod.soim.data.msg.user.UserMsg; |
||||
|
||||
import java.util.List; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* ResFriendListHandler |
||||
* |
||||
* @author tmy |
||||
* @date 2022-05-23 22:59 |
||||
*/ |
||||
@Singleton |
||||
public class ResFriendListHandler implements MessageHandler<Friend.ResFriendList> { |
||||
|
||||
@Override |
||||
public void handleMsg(Friend.ResFriendList res) { |
||||
List<UserMsg.UserInfo> friendsList = res.getFriendsList(); |
||||
List<String> userLines = friendsList.stream() |
||||
.map(u -> u.getUid() + "|" + u.getAccount() + "|" + u.getNickname() + "|" + u.getOnline()) |
||||
.collect(Collectors.toList()); |
||||
Logger.logList("好友列表", userLines); |
||||
} |
||||
|
||||
} |
||||
@ -1,31 +0,0 @@
|
||||
package net.sopod.soim.client.handler.msg; |
||||
|
||||
import com.google.inject.Singleton; |
||||
import net.sopod.soim.client.logger.Logger; |
||||
import net.sopod.soim.client.session.MessageHandler; |
||||
import net.sopod.soim.data.msg.user.AccountSearch; |
||||
import net.sopod.soim.data.msg.user.UserGroup; |
||||
import net.sopod.soim.data.msg.user.UserMsg; |
||||
|
||||
import java.util.List; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* ResFriendSearchHandler |
||||
* |
||||
* @author tmy |
||||
* @date 2022-05-17 23:41 |
||||
*/ |
||||
@Singleton |
||||
public class ResFriendSearchHandler implements MessageHandler<AccountSearch.ResAccountSearch> { |
||||
|
||||
@Override |
||||
public void handleMsg(AccountSearch.ResAccountSearch res) { |
||||
List<UserMsg.UserInfo> usersList = res.getUsersList(); |
||||
List<String> userLines = usersList.stream() |
||||
.map(u -> u.getUid() + "|" + u.getAccount() + "|" + u.getNickname()) |
||||
.collect(Collectors.toList()); |
||||
Logger.logList("搜索结果", userLines); |
||||
} |
||||
|
||||
} |
||||
@ -1,28 +0,0 @@
|
||||
package net.sopod.soim.client.handler.msg; |
||||
|
||||
import com.google.inject.Singleton; |
||||
import net.sopod.soim.client.logger.Logger; |
||||
import net.sopod.soim.client.session.MessageHandler; |
||||
import net.sopod.soim.data.msg.user.UserGroup; |
||||
|
||||
import java.util.List; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* ResOnlineUserListHandler |
||||
* |
||||
* @author tmy |
||||
* @date 2022-04-28 12:52 |
||||
*/ |
||||
@Singleton |
||||
public class ResOnlineUserListHandler implements MessageHandler<UserGroup.ResOnlineUserList> { |
||||
|
||||
@Override |
||||
public void handleMsg(UserGroup.ResOnlineUserList res) { |
||||
List<String> userLines = res.getUsersList().stream() |
||||
.map(user -> user.getUid() + " | " + user.getAccount()) |
||||
.collect(Collectors.toList()); |
||||
Logger.logList("在线用户", userLines); |
||||
} |
||||
|
||||
} |
||||
@ -1,26 +0,0 @@
|
||||
package net.sopod.soim.client.handler.msg; |
||||
|
||||
import com.google.inject.Inject; |
||||
import com.google.inject.Singleton; |
||||
import net.sopod.soim.client.session.MessageHandler; |
||||
import net.sopod.soim.client.session.SoImSession; |
||||
import net.sopod.soim.data.msg.auth.Auth; |
||||
|
||||
/** |
||||
* ResTokenAuthHandler |
||||
* |
||||
* @author tmy |
||||
* @date 2022-04-27 9:46 |
||||
*/ |
||||
@Singleton |
||||
public class ResTokenAuthHandler implements MessageHandler<Auth.ResTokenAuth> { |
||||
|
||||
@Inject |
||||
private SoImSession soImSession; |
||||
|
||||
@Override |
||||
public void handleMsg(Auth.ResTokenAuth res) { |
||||
soImSession.authResult(res.getSuccess(), res.getMessage(), res.getUid()); |
||||
} |
||||
|
||||
} |
||||
@ -1,28 +0,0 @@
|
||||
package net.sopod.soim.client.protocol; |
||||
|
||||
import io.netty.channel.ChannelHandlerContext; |
||||
import io.netty.channel.ChannelOutboundHandlerAdapter; |
||||
import io.netty.channel.ChannelPromise; |
||||
import net.sopod.soim.data.serialize.ImMessage; |
||||
|
||||
/** |
||||
* ImMessageOutboundHandler |
||||
* |
||||
* @author tmy |
||||
* @date 2022-06-02 17:53 |
||||
*/ |
||||
public class ImMessageOutboundHandler extends ChannelOutboundHandlerAdapter { |
||||
|
||||
@Override |
||||
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { |
||||
if (!(msg instanceof ImMessage)) { |
||||
return; |
||||
} |
||||
ImMessage imMessage = (ImMessage) msg; |
||||
imMessage.setSerialNo(10086); |
||||
// queue.add something..., 调用的地方,通过阻塞方式 FastThreadLocal 获取一个 CompletableFuture
|
||||
|
||||
super.write(ctx, msg, promise); |
||||
} |
||||
|
||||
} |
||||
@ -1,10 +0,0 @@
|
||||
package net.sopod.soim.client.protocol; |
||||
|
||||
/** |
||||
* ImMessageRegistry |
||||
* |
||||
* @author tmy |
||||
* @date 2022-06-02 17:32 |
||||
*/ |
||||
public class ImMessageRegistry { |
||||
} |
||||
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<parent> |
||||
<artifactId>im-das-api</artifactId> |
||||
<groupId>net.sopod</groupId> |
||||
<version>1.0.0</version> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<artifactId>im-das-common</artifactId> |
||||
|
||||
|
||||
</project> |
||||
@ -0,0 +1,26 @@
|
||||
package net.sopod.soim.das.group.api.model.dto; |
||||
|
||||
import lombok.Data; |
||||
import lombok.experimental.Accessors; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* GroupUser0 |
||||
* |
||||
* @author tmy |
||||
* @date 2022-06-03 21:24 |
||||
*/ |
||||
@Data |
||||
@Accessors(chain = true) |
||||
public class GroupUser_0 implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 2795983825784323892L; |
||||
|
||||
private Long uid; |
||||
|
||||
private Long lastActive; |
||||
|
||||
private transient Boolean isOnline; |
||||
|
||||
} |
||||
@ -1,11 +1,58 @@
|
||||
package net.sopod.soim.das.group.api.model.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import lombok.Data; |
||||
import lombok.experimental.Accessors; |
||||
import net.sopod.soim.das.common.config.LogicTables; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* ImGroup |
||||
* ImGroup 群聊 |
||||
* |
||||
* @author tmy |
||||
* @date 2022-05-28 14:57 |
||||
* @date 2022-05-28 15:14 |
||||
*/ |
||||
public class ImGroup { |
||||
@Data |
||||
@Accessors(chain = true) |
||||
@TableName(LogicTables.IM_GROUP) |
||||
public class ImGroup implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 2081139176340955425L; |
||||
|
||||
/** 群聊id */ |
||||
@TableId(value = "id") |
||||
private Long id; |
||||
|
||||
/** 群主id */ |
||||
@TableField(value = "master_uid") |
||||
private Long masterUid; |
||||
|
||||
/** 状态:0删除,1.正常,3禁用,4.解散 */ |
||||
@TableField(value = "status") |
||||
private Integer status; |
||||
|
||||
/** 群聊名称 */ |
||||
@TableField(value = "group_name") |
||||
private String groupName; |
||||
|
||||
/** 群聊人数限制 */ |
||||
@TableField(value = "user_limit") |
||||
private Integer userLimit; |
||||
|
||||
/** 当前群聊人数 */ |
||||
@TableField(value = "user_num") |
||||
private Integer userNum; |
||||
|
||||
/** 创建时间 */ |
||||
@TableField(value = "create_time") |
||||
private Date createTime; |
||||
|
||||
/** 更新时间 */ |
||||
@TableField(value = "update_time") |
||||
private Date updateTime; |
||||
|
||||
} |
||||
|
||||
@ -0,0 +1,21 @@
|
||||
package net.sopod.soim.das.group.api.service; |
||||
|
||||
import net.sopod.soim.das.group.api.model.entity.ImGroup; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* DasGroupService |
||||
* |
||||
* @author tmy |
||||
* @date 2022-06-03 20:04 |
||||
*/ |
||||
public interface DasGroupService { |
||||
|
||||
Boolean isGroupNameNotExists(String groupName); |
||||
|
||||
Long saveGroup(ImGroup imGroup); |
||||
|
||||
List<ImGroup> listGroup(String groupNameLike); |
||||
|
||||
} |
||||
@ -0,0 +1,25 @@
|
||||
package net.sopod.soim.das.group.api.service; |
||||
|
||||
import net.sopod.soim.das.group.api.model.dto.GroupUser_0; |
||||
|
||||
import java.util.Collections; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* DasGroupUserService |
||||
* |
||||
* @author tmy |
||||
* @date 2022-06-03 20:22 |
||||
*/ |
||||
public interface DasGroupUserService { |
||||
|
||||
Boolean isJoined(Long groupId, Long uid); |
||||
|
||||
Long insert(Long groupId, Long uid); |
||||
|
||||
void updateLastActive(Long id, Long millis); |
||||
|
||||
List<GroupUser_0> listGroupUsers(Long groupId); |
||||
|
||||
} |
||||
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<parent> |
||||
<artifactId>im-das-api</artifactId> |
||||
<groupId>net.sopod</groupId> |
||||
<version>1.0.0</version> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<artifactId>im-das-message-api</artifactId> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>net.sopod</groupId> |
||||
<artifactId>im-das-common</artifactId> |
||||
<version>${soim.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.baomidou</groupId> |
||||
<artifactId>mybatis-plus-annotation</artifactId> |
||||
<version>3.5.0</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>net.sopod</groupId> |
||||
<artifactId>im-common</artifactId> |
||||
<version>${soim.version}</version> |
||||
<scope>provided</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-amqp</artifactId> |
||||
<scope>provided</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.xerial.snappy</groupId> |
||||
<artifactId>snappy-java</artifactId> |
||||
</dependency> |
||||
</dependencies> |
||||
|
||||
</project> |
||||
@ -0,0 +1,3 @@
|
||||
|
||||
@org.springframework.lang.NonNullApi |
||||
package net.sopod.soim.das.message.api.config; |
||||
@ -1,11 +1,11 @@
|
||||
package net.sopod.soim.das.user.api.model.entity; |
||||
package net.sopod.soim.das.message.api.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import lombok.Data; |
||||
import lombok.experimental.Accessors; |
||||
import net.sopod.soim.das.user.api.config.LogicTables; |
||||
import net.sopod.soim.das.common.config.LogicTables; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
@ -1,4 +1,4 @@
|
||||
package net.sopod.soim.das.user.api.mq; |
||||
package net.sopod.soim.das.message.api.mq; |
||||
|
||||
import net.sopod.soim.common.constant.Consts; |
||||
import net.sopod.soim.common.util.Converter; |
||||
@ -1,4 +1,4 @@
|
||||
package net.sopod.soim.das.user.api.mq; |
||||
package net.sopod.soim.das.message.api.mq; |
||||
|
||||
/** |
||||
* ChatQueue |
||||
@ -1,9 +1,9 @@
|
||||
package net.sopod.soim.das.user.api.mq; |
||||
package net.sopod.soim.das.message.api.mq; |
||||
|
||||
import net.sopod.soim.common.util.Converter; |
||||
import net.sopod.soim.common.util.StringUtil; |
||||
import net.sopod.soim.das.user.api.model.entity.ImGroupMessage; |
||||
import net.sopod.soim.das.user.api.model.entity.ImMessage; |
||||
import net.sopod.soim.das.message.api.entity.ImGroupMessage; |
||||
import net.sopod.soim.das.message.api.entity.ImMessage; |
||||
|
||||
import java.util.function.Function; |
||||
|
||||
@ -0,0 +1,3 @@
|
||||
|
||||
@org.springframework.lang.NonNullApi |
||||
package net.sopod.soim.das.message.api.mq; |
||||
@ -1 +1 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=net.sopod.soim.das.user.api.config.ChatMQAutoConfiguration |
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=net.sopod.soim.das.message.api.config.ChatMQAutoConfiguration |
||||
@ -1,3 +0,0 @@
|
||||
|
||||
@org.springframework.lang.NonNullApi |
||||
package net.sopod.soim.das.user.api.config; |
||||
@ -1,54 +0,0 @@
|
||||
package net.sopod.soim.das.user.api.model.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import lombok.Data; |
||||
import lombok.experimental.Accessors; |
||||
import net.sopod.soim.das.user.api.config.LogicTables; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* ImGroup 群聊 |
||||
* |
||||
* @author tmy |
||||
* @date 2022-05-28 15:14 |
||||
*/ |
||||
@Data |
||||
@Accessors(chain = true) |
||||
@TableName(LogicTables.IM_GROUP) |
||||
public class ImGroup implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 2081139176340955425L; |
||||
|
||||
/** 群聊id */ |
||||
@TableId(value = "id") |
||||
private Long id; |
||||
|
||||
/** 群主id */ |
||||
@TableField(value = "master_uid") |
||||
private Long masterUid; |
||||
|
||||
/** 群聊名称 */ |
||||
@TableField(value = "group_name") |
||||
private String groupName; |
||||
|
||||
/** 群聊人数限制 */ |
||||
@TableField(value = "user_limit") |
||||
private String userLimit; |
||||
|
||||
/** 当前群聊人数 */ |
||||
@TableField(value = "user_num") |
||||
private Date userNum; |
||||
|
||||
/** 创建时间 */ |
||||
@TableField(value = "create_time") |
||||
private String createTime; |
||||
|
||||
/** 更新时间 */ |
||||
@TableField(value = "update_time") |
||||
private Date updateTime; |
||||
|
||||
} |
||||
@ -1,3 +0,0 @@
|
||||
|
||||
@org.springframework.lang.NonNullApi |
||||
package net.sopod.soim.das.user.api.mq; |
||||
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<parent> |
||||
<artifactId>im-das</artifactId> |
||||
<groupId>net.sopod</groupId> |
||||
<version>1.0.0</version> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<artifactId>im-das-group</artifactId> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>net.sopod</groupId> |
||||
<artifactId>im-common</artifactId> |
||||
<version>${soim.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>net.sopod</groupId> |
||||
<artifactId>im-das-group-api</artifactId> |
||||
<version>${soim.version}</version> |
||||
</dependency> |
||||
</dependencies> |
||||
|
||||
</project> |
||||
@ -0,0 +1,23 @@
|
||||
package net.sopod.soim.das.group; |
||||
|
||||
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; |
||||
import org.mybatis.spring.annotation.MapperScan; |
||||
import org.springframework.boot.SpringApplication; |
||||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||
|
||||
/** |
||||
* DasGroupApplication |
||||
* |
||||
* @author tmy |
||||
* @date 2022-06-03 11:33 |
||||
*/ |
||||
@SpringBootApplication |
||||
@EnableDubbo(scanBasePackages = "net.sopod.soim.das.group.service") |
||||
@MapperScan("net.sopod.soim.das.group.dao") |
||||
public class DasGroupApplication { |
||||
|
||||
public static void main(String[] args) { |
||||
SpringApplication.run(DasGroupApplication.class); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,14 @@
|
||||
package net.sopod.soim.das.group.dao; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import net.sopod.soim.das.group.api.model.entity.ImGroupUser; |
||||
|
||||
/** |
||||
* ImGroupMessageMapper |
||||
* |
||||
* @author tmy |
||||
* @date 2022-05-31 9:59 |
||||
*/ |
||||
public interface ImGroupUserMapper extends BaseMapper<ImGroupUser> { |
||||
|
||||
} |
||||
@ -0,0 +1,63 @@
|
||||
package net.sopod.soim.das.group.service; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import net.sopod.soim.common.util.ImClock; |
||||
import net.sopod.soim.das.common.config.LogicTables; |
||||
import net.sopod.soim.das.group.api.model.entity.ImGroup; |
||||
import net.sopod.soim.das.group.api.service.DasGroupService; |
||||
import net.sopod.soim.das.group.dao.ImGroupMapper; |
||||
import net.sopod.soim.logic.api.segmentid.core.SegmentIdGenerator; |
||||
import org.apache.dubbo.config.annotation.DubboService; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* DasGroupServiceImpl |
||||
* |
||||
* @author tmy |
||||
* @date 2022-06-03 20:29 |
||||
*/ |
||||
@DubboService |
||||
public class DasGroupServiceImpl implements DasGroupService { |
||||
|
||||
@Resource |
||||
private ImGroupMapper imGroupMapper; |
||||
|
||||
@Resource |
||||
private DasGroupUserServiceImpl dasGroupUserService; |
||||
|
||||
@Resource |
||||
private SegmentIdGenerator segmentIdGenerator; |
||||
|
||||
@Override |
||||
public Boolean isGroupNameNotExists(String groupName) { |
||||
Long groupId = imGroupMapper.selectExistsGroupByName(groupName); |
||||
return groupId == null; |
||||
} |
||||
|
||||
@Transactional |
||||
@Override |
||||
public Long saveGroup(ImGroup imGroup) { |
||||
long groupId = segmentIdGenerator.nextId(LogicTables.IM_GROUP); |
||||
// 添加群数据
|
||||
imGroup.setId(groupId) |
||||
.setStatus(LogicTables.STATUS_NORMAL) |
||||
.setUserNum(1) |
||||
.setCreateTime(ImClock.date()); |
||||
imGroupMapper.insert(imGroup); |
||||
// 添加群主为群用户
|
||||
dasGroupUserService.insert(groupId, imGroup.getMasterUid()); |
||||
return groupId; |
||||
} |
||||
|
||||
@Override |
||||
public List<ImGroup> listGroup(String groupNameLike) { |
||||
LambdaQueryWrapper<ImGroup> imGroupQuery = new QueryWrapper<ImGroup>().lambda() |
||||
.likeRight(ImGroup::getGroupName, groupNameLike); |
||||
return imGroupMapper.selectList(imGroupQuery); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,81 @@
|
||||
package net.sopod.soim.das.group.service; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import net.sopod.soim.common.util.Collects; |
||||
import net.sopod.soim.common.util.ImClock; |
||||
import net.sopod.soim.das.common.config.LogicTables; |
||||
import net.sopod.soim.das.group.api.model.dto.GroupUser_0; |
||||
import net.sopod.soim.das.group.api.model.entity.ImGroupUser; |
||||
import net.sopod.soim.das.group.api.service.DasGroupUserService; |
||||
import net.sopod.soim.das.group.dao.ImGroupUserMapper; |
||||
import net.sopod.soim.logic.api.segmentid.core.SegmentIdGenerator; |
||||
import org.apache.dubbo.config.annotation.DubboService; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.Collections; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* DasGroupUserServiceImpl |
||||
* |
||||
* @author tmy |
||||
* @date 2022-06-03 20:30 |
||||
*/ |
||||
@DubboService |
||||
public class DasGroupUserServiceImpl implements DasGroupUserService { |
||||
|
||||
@Resource |
||||
private ImGroupUserMapper imGroupUserMapper; |
||||
|
||||
@Resource |
||||
private SegmentIdGenerator segmentIdGenerator; |
||||
|
||||
@Override |
||||
public Boolean isJoined(Long groupId, Long uid) { |
||||
LambdaQueryWrapper<ImGroupUser> joinIdQuery = new QueryWrapper<ImGroupUser>().lambda() |
||||
.select(ImGroupUser::getId) |
||||
.eq(ImGroupUser::getGroupId, groupId) |
||||
.eq(ImGroupUser::getUid, uid); |
||||
return Collects.isNotEmpty(imGroupUserMapper.selectList(joinIdQuery)); |
||||
} |
||||
|
||||
@Override |
||||
public Long insert(Long groupId, Long uid) { |
||||
long id = segmentIdGenerator.nextId(LogicTables.IM_GROUP_USER); |
||||
Date now = ImClock.date(); |
||||
ImGroupUser imGroupUser = new ImGroupUser().setId(id) |
||||
.setUid(uid) |
||||
.setGroupId(groupId) |
||||
.setCreateTime(now) |
||||
.setLastActive(now) |
||||
.setUnreadNum(0) |
||||
.setUnreadOffsetId(0L); |
||||
imGroupUserMapper.insert(imGroupUser); |
||||
return id; |
||||
} |
||||
|
||||
@Override |
||||
public void updateLastActive(Long id, Long millis) { |
||||
ImGroupUser updateWrapper = new ImGroupUser() |
||||
.setId(id) |
||||
.setLastActive(new Date(millis)); |
||||
imGroupUserMapper.updateById(updateWrapper); |
||||
} |
||||
|
||||
@Override |
||||
public List<GroupUser_0> listGroupUsers(Long groupId) { |
||||
LambdaQueryWrapper<ImGroupUser> imGroupUserQueryWrapper = new QueryWrapper<ImGroupUser>().lambda() |
||||
.select(ImGroupUser::getUid, ImGroupUser::getLastActive) |
||||
.eq(ImGroupUser::getGroupId, groupId); |
||||
List<ImGroupUser> imGroupUsers = imGroupUserMapper.selectList(imGroupUserQueryWrapper); |
||||
List<GroupUser_0> groupUsers = imGroupUsers.stream().map(gu -> new GroupUser_0() |
||||
.setUid(gu.getUid()) |
||||
.setLastActive(gu.getLastActive() == null ? null : gu.getLastActive().getTime()) |
||||
).collect(Collectors.toList()); |
||||
return groupUsers; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,30 @@
|
||||
|
||||
|
||||
# sharding-jdbc 配置 |
||||
# 配置数据源 |
||||
spring.shardingsphere.datasource.names=ds1 |
||||
spring.shardingsphere.datasource.ds1.type=com.zaxxer.hikari.HikariDataSource |
||||
spring.shardingsphere.datasource.ds1.driver-class-name=com.mysql.cj.jdbc.Driver |
||||
spring.shardingsphere.datasource.ds1.jdbc-url=jdbc:mysql://cd-cdb-mrz9fw80.sql.tencentcdb.com:61843/soim_db?serverTimezone=GMT%2B8 |
||||
spring.shardingsphere.datasource.ds1.username=root |
||||
spring.shardingsphere.datasource.ds1.password=sopod@2347# |
||||
|
||||
# 5.1.0 分表 |
||||
# https://github.com/apache/shardingsphere/blob/master/examples/shardingsphere-jdbc-example/single-feature-example/sharding-example/sharding-raw-jdbc-example/src/main/resources/META-INF/sharding-tables.yaml |
||||
|
||||
# 打开sharding-jdbc sql输出日志 |
||||
spring.shardingsphere.props.sql-show=true |
||||
# 需要sharding处理的表 |
||||
spring.shardingsphere.rules.sharding.binding-tables=im_group,im_group_user |
||||
# im_group |
||||
spring.shardingsphere.rules.sharding.tables.im_group.actual-data-nodes=ds1.im_group_$->{0..3} |
||||
spring.shardingsphere.rules.sharding.tables.im_group.table-strategy.standard.sharding-column=id |
||||
spring.shardingsphere.rules.sharding.tables.im_group.table-strategy.standard.sharding-algorithm-name=im-group-inline |
||||
spring.shardingsphere.rules.sharding.sharding-algorithms.im-group-inline.type=INLINE |
||||
spring.shardingsphere.rules.sharding.sharding-algorithms.im-group-inline.props.algorithm-expression=im_group_$->{id & 3} |
||||
# im_group_user |
||||
spring.shardingsphere.rules.sharding.tables.im_group_user.actual-data-nodes=ds1.im_group_user_$->{0..7} |
||||
spring.shardingsphere.rules.sharding.tables.im_group_user.table-strategy.standard.sharding-column=group_id |
||||
spring.shardingsphere.rules.sharding.tables.im_group_user.table-strategy.standard.sharding-algorithm-name=im-group-user-inline |
||||
spring.shardingsphere.rules.sharding.sharding-algorithms.im-group-user-inline.type=INLINE |
||||
spring.shardingsphere.rules.sharding.sharding-algorithms.im-group-user-inline.props.algorithm-expression=im_group_user_$->{group_id & 7} |
||||
@ -0,0 +1,20 @@
|
||||
spring: |
||||
application: |
||||
name: im-das-group |
||||
|
||||
dubbo: |
||||
application: |
||||
name: ${spring.application.name} |
||||
registry: |
||||
address: nacos://124.222.131.236:3848 |
||||
group: so-im |
||||
protocol: |
||||
port: 3014 |
||||
consumer: |
||||
check: false |
||||
|
||||
mybatis-plus: |
||||
mapper-locations: classpath:mapper/*.xml |
||||
|
||||
im-segment-id: |
||||
enabled: true |
||||
@ -0,0 +1,9 @@
|
||||
<?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="net.sopod.soim.das.group.dao.ImGroupMapper"> |
||||
|
||||
<select id="selectExistsGroupByName" resultType="long"> |
||||
select id from im_group where group_name = #{groupName} limit 1 |
||||
</select> |
||||
|
||||
</mapper> |
||||
@ -1,5 +1,5 @@
|
||||
<?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="net.sopod.soim.das.user.dao.ImGroupMapper"> |
||||
<mapper namespace="net.sopod.soim.das.group.dao.ImGroupUserMapper"> |
||||
|
||||
</mapper> |
||||
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<parent> |
||||
<artifactId>im-das</artifactId> |
||||
<groupId>net.sopod</groupId> |
||||
<version>1.0.0</version> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<artifactId>im-das-message</artifactId> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>net.sopod</groupId> |
||||
<artifactId>im-common</artifactId> |
||||
<version>${soim.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>net.sopod</groupId> |
||||
<artifactId>im-das-message-api</artifactId> |
||||
<version>${soim.version}</version> |
||||
</dependency> |
||||
</dependencies> |
||||
</project> |
||||
@ -0,0 +1,21 @@
|
||||
package net.sopod.soim.das.message; |
||||
|
||||
import org.mybatis.spring.annotation.MapperScan; |
||||
import org.springframework.boot.SpringApplication; |
||||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||
|
||||
/** |
||||
* DasMessageApplication |
||||
* |
||||
* @author tmy |
||||
* @date 2022-06-03 11:53 |
||||
*/ |
||||
@MapperScan("net.sopod.soim.das.message.dao") |
||||
@SpringBootApplication |
||||
public class DasMessageApplication { |
||||
|
||||
public static void main(String[] args) { |
||||
SpringApplication.run(DasMessageApplication.class); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,56 @@
|
||||
package net.sopod.soim.das.message.consumer; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import net.sopod.soim.das.message.api.entity.ImGroupMessage; |
||||
import net.sopod.soim.das.message.api.entity.ImMessage; |
||||
import net.sopod.soim.das.message.api.mq.ChatQueue; |
||||
import net.sopod.soim.das.message.dao.ImGroupMessageMapper; |
||||
import net.sopod.soim.das.message.dao.ImMessageMapper; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.amqp.rabbit.annotation.RabbitHandler; |
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* Listener |
||||
* 只能接受字符串和字节数组 |
||||
* |
||||
* @author tmy |
||||
* @date 2022-05-28 16:26 |
||||
*/ |
||||
@Service |
||||
@AllArgsConstructor |
||||
@RabbitListener(queues = { |
||||
ChatQueue.IM_MESSAGE_PERSISTENT, |
||||
ChatQueue.IM_GROUP_MESSAGE_PERSISTENT |
||||
}) |
||||
public class ImMessagePersistentListener { |
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ImMessagePersistentListener.class); |
||||
|
||||
ImMessageMapper imMessageMapper; |
||||
|
||||
ImGroupMessageMapper imGroupMessageMapper; |
||||
|
||||
@RabbitHandler |
||||
public void process(ImGroupMessage imGroupMessage) { |
||||
// System.out.println("receiver2: " + imGroupMessage);
|
||||
try { |
||||
imGroupMessageMapper.insert(imGroupMessage); |
||||
} catch (Exception e) { |
||||
logger.error("ImGroupMessage insert 失败: {}", imGroupMessage); |
||||
} |
||||
} |
||||
|
||||
@RabbitHandler |
||||
public void process(ImMessage imMessage) { |
||||
// System.out.println("receive3: " + imMessage);
|
||||
try { |
||||
imMessageMapper.insert(imMessage); |
||||
} catch (Exception e) { |
||||
logger.error("ImMessage insert 失败: {}", imMessage); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -1,13 +1,13 @@
|
||||
package net.sopod.soim.das.user.dao; |
||||
package net.sopod.soim.das.message.dao; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import net.sopod.soim.das.user.api.model.entity.ImGroupMessage; |
||||
import net.sopod.soim.das.message.api.entity.ImGroupMessage; |
||||
|
||||
/** |
||||
* ImGroupMessageMapper |
||||
* |
||||
* @author tmy |
||||
* @date 2022-05-31 9:59 |
||||
* @date 2022-06-03 17:16 |
||||
*/ |
||||
public interface ImGroupMessageMapper extends BaseMapper<ImGroupMessage> { |
||||
|
||||
@ -0,0 +1,14 @@
|
||||
package net.sopod.soim.das.message.dao; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import net.sopod.soim.das.message.api.entity.ImMessage; |
||||
|
||||
/** |
||||
* ImMessageMapper |
||||
* |
||||
* @author tmy |
||||
* @date 2022-06-03 17:16 |
||||
*/ |
||||
public interface ImMessageMapper extends BaseMapper<ImMessage> { |
||||
|
||||
} |
||||
@ -0,0 +1,34 @@
|
||||
# sharding-jdbc 配置 |
||||
# 配置数据源 |
||||
spring.shardingsphere.datasource.names=ds1 |
||||
spring.shardingsphere.datasource.ds1.type=com.zaxxer.hikari.HikariDataSource |
||||
spring.shardingsphere.datasource.ds1.driver-class-name=com.mysql.cj.jdbc.Driver |
||||
spring.shardingsphere.datasource.ds1.jdbc-url=jdbc:mysql://cd-cdb-mrz9fw80.sql.tencentcdb.com:61843/soim_db?serverTimezone=GMT%2B8 |
||||
spring.shardingsphere.datasource.ds1.username=root |
||||
spring.shardingsphere.datasource.ds1.password=sopod@2347# |
||||
|
||||
# 分表 |
||||
#spring.shardingsphere.sharding.tables.im_user.actual-data-nodes=db1.im_user_$->{0..2} |
||||
## 指定im_user表的分片策略,分片策略包括分片键和分片算法 |
||||
#spring.shardingsphere.sharding.tables.im_user.table-strategy.inline.sharding-column=id |
||||
#spring.shardingsphere.sharding.tables.im_user.table-strategy.inline.algorithm-expression=im_user_$->{id % 3} |
||||
|
||||
# 5.1.0 分表 |
||||
# https://github.com/apache/shardingsphere/blob/master/examples/shardingsphere-jdbc-example/single-feature-example/sharding-example/sharding-raw-jdbc-example/src/main/resources/META-INF/sharding-tables.yaml |
||||
|
||||
# 打开sharding-jdbc sql输出日志 |
||||
spring.shardingsphere.props.sql-show=true |
||||
# 需要sharding处理的表 |
||||
spring.shardingsphere.rules.sharding.binding-tables=im_message,im_group_message |
||||
# im_message |
||||
spring.shardingsphere.rules.sharding.tables.im_message.actual-data-nodes=ds1.im_message_$->{0..7} |
||||
spring.shardingsphere.rules.sharding.tables.im_message.table-strategy.standard.sharding-column=relation_id |
||||
spring.shardingsphere.rules.sharding.tables.im_message.table-strategy.standard.sharding-algorithm-name=im-message-inline |
||||
spring.shardingsphere.rules.sharding.sharding-algorithms.im-message-inline.type=INLINE |
||||
spring.shardingsphere.rules.sharding.sharding-algorithms.im-message-inline.props.algorithm-expression=im_message_$->{relation_id & 7} |
||||
# im_group_message |
||||
spring.shardingsphere.rules.sharding.tables.im_group_message.actual-data-nodes=ds1.im_group_message_$->{0..15} |
||||
spring.shardingsphere.rules.sharding.tables.im_group_message.table-strategy.standard.sharding-column=group_id |
||||
spring.shardingsphere.rules.sharding.tables.im_group_message.table-strategy.standard.sharding-algorithm-name=im-group-message-inline |
||||
spring.shardingsphere.rules.sharding.sharding-algorithms.im-group-message-inline.type=INLINE |
||||
spring.shardingsphere.rules.sharding.sharding-algorithms.im-group-message-inline.props.algorithm-expression=im_group_message_$->{group_id & 15} |
||||
@ -0,0 +1,25 @@
|
||||
spring: |
||||
application: |
||||
name: im-das-message |
||||
rabbitmq: |
||||
host: 124.222.131.236 |
||||
port: 3672 |
||||
username: soim |
||||
password: sopod@rabbit# |
||||
|
||||
dubbo: |
||||
application: |
||||
name: ${spring.application.name} |
||||
registry: |
||||
address: nacos://124.222.131.236:3848 |
||||
group: so-im |
||||
protocol: |
||||
port: 3011 |
||||
consumer: |
||||
check: false |
||||
|
||||
mybatis-plus: |
||||
mapper-locations: classpath:mapper/*.xml |
||||
|
||||
im-segment-id: |
||||
enabled: true |
||||
@ -0,0 +1,5 @@
|
||||
<?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="net.sopod.soim.das.message.dao.ImGroupMessageMapper"> |
||||
|
||||
</mapper> |
||||
@ -1,5 +1,5 @@
|
||||
<?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="net.sopod.soim.das.user.dao.ImGroupMessageMapper"> |
||||
<mapper namespace="net.sopod.soim.das.message.dao.ImMessageMapper"> |
||||
|
||||
</mapper> |
||||
@ -1,44 +0,0 @@
|
||||
package net.sopod.soim.das.user.amqp; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import net.sopod.soim.das.user.api.model.entity.ImGroupMessage; |
||||
import net.sopod.soim.das.user.api.model.entity.ImMessage; |
||||
import net.sopod.soim.das.user.api.mq.ChatQueue; |
||||
import net.sopod.soim.das.user.dao.ImGroupMessageMapper; |
||||
import net.sopod.soim.das.user.dao.ImMessageMapper; |
||||
import org.springframework.amqp.rabbit.annotation.RabbitHandler; |
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* Listener |
||||
* 只能接受字符串和字节数组 |
||||
* |
||||
* @author tmy |
||||
* @date 2022-05-28 16:26 |
||||
*/ |
||||
@Service |
||||
@AllArgsConstructor |
||||
@RabbitListener(queues = { |
||||
ChatQueue.IM_MESSAGE_PERSISTENT, |
||||
ChatQueue.IM_GROUP_MESSAGE_PERSISTENT |
||||
}) |
||||
public class Receiver { |
||||
|
||||
ImMessageMapper imMessageMapper; |
||||
|
||||
ImGroupMessageMapper imGroupMessageMapper; |
||||
|
||||
@RabbitHandler |
||||
public void process(ImGroupMessage imGroupMessage) { |
||||
System.out.println("receiver2: " + imGroupMessage); |
||||
imGroupMessageMapper.insert(imGroupMessage); |
||||
} |
||||
|
||||
@RabbitHandler |
||||
public void process(ImMessage imMessage) { |
||||
System.out.println("receive3: " + imMessage); |
||||
imMessageMapper.insert(imMessage); |
||||
} |
||||
|
||||
} |
||||
@ -1,14 +0,0 @@
|
||||
package net.sopod.soim.das.user.dao; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import net.sopod.soim.das.user.api.model.entity.ImMessage; |
||||
|
||||
/** |
||||
* ImMessageMapper |
||||
* |
||||
* @author tmy |
||||
* @date 2022-05-31 9:47 |
||||
*/ |
||||
public interface ImMessageMapper extends BaseMapper<ImMessage> { |
||||
|
||||
} |
||||
@ -1,5 +0,0 @@
|
||||
<?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="net.sopod.soim.das.user.dao.ImMessageMapper"> |
||||
|
||||
</mapper> |
||||
@ -0,0 +1,24 @@
|
||||
package net.sopod.soim.entry.handlers.chat; |
||||
|
||||
import com.google.protobuf.MessageLite; |
||||
import net.sopod.soim.data.msg.group.Group; |
||||
import net.sopod.soim.entry.server.handler.AccountMessageHandler; |
||||
import net.sopod.soim.entry.server.handler.ImContext; |
||||
import net.sopod.soim.entry.server.session.Account; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* ReqGroupMessageHandler |
||||
* |
||||
* @author tmy |
||||
* @date 2022-06-05 11:05 |
||||
*/ |
||||
@Service |
||||
public class ReqGroupMessageHandler extends AccountMessageHandler<Group.ReqGroupMessage> { |
||||
|
||||
@Override |
||||
public MessageLite handle(ImContext ctx, Account account, Group.ReqGroupMessage req) { |
||||
return null; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,41 @@
|
||||
package net.sopod.soim.entry.handlers.group; |
||||
|
||||
import com.google.protobuf.MessageLite; |
||||
import net.sopod.soim.common.dubbo.exception.SoimException; |
||||
import net.sopod.soim.data.msg.common.Res; |
||||
import net.sopod.soim.data.msg.group.Group; |
||||
import net.sopod.soim.entry.server.handler.AccountMessageHandler; |
||||
import net.sopod.soim.entry.server.handler.ImContext; |
||||
import net.sopod.soim.entry.server.session.Account; |
||||
import net.sopod.soim.logic.api.group.service.ImGroupService; |
||||
import org.apache.dubbo.config.annotation.DubboReference; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* ReqCreateGroupHandler |
||||
* |
||||
* @author tmy |
||||
* @date 2022-06-03 10:43 |
||||
*/ |
||||
@Service |
||||
public class ReqCreateGroupHandler extends AccountMessageHandler<Group.ReqCreateGroup> { |
||||
|
||||
@DubboReference |
||||
private ImGroupService imGroupService; |
||||
|
||||
@Override |
||||
public MessageLite handle(ImContext ctx, Account account, Group.ReqCreateGroup req) { |
||||
String groupName = req.getGroupName(); |
||||
Res.ResState.Builder resBuilder = Res.ResState.newBuilder(); |
||||
try { |
||||
Long groupId = imGroupService.createGroup(account.getUid(), groupName); |
||||
resBuilder.setSuccess(true) |
||||
.setMessage("群聊创建成功:" + groupId); |
||||
} catch (SoimException e) { |
||||
resBuilder.setSuccess(false) |
||||
.setMessage(e.getMessage()); |
||||
} |
||||
return resBuilder.build(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,44 @@
|
||||
package net.sopod.soim.entry.handlers.group; |
||||
|
||||
import com.google.protobuf.MessageLite; |
||||
import net.sopod.soim.data.msg.group.Group; |
||||
import net.sopod.soim.entry.server.handler.AccountMessageHandler; |
||||
import net.sopod.soim.entry.server.handler.ImContext; |
||||
import net.sopod.soim.entry.server.session.Account; |
||||
import net.sopod.soim.logic.api.group.model.dto.GroupUserInfo; |
||||
import net.sopod.soim.logic.api.group.service.ImGroupService; |
||||
import org.apache.dubbo.config.annotation.DubboReference; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.List; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* ReqGroupUsersHandler |
||||
* |
||||
* @author tmy |
||||
* @date 2022-06-05 10:33 |
||||
*/ |
||||
@Service |
||||
public class ReqGroupUsersHandler extends AccountMessageHandler<Group.ReqGroupUsers> { |
||||
|
||||
@DubboReference |
||||
private ImGroupService imGroupService; |
||||
|
||||
@Override |
||||
public MessageLite handle(ImContext ctx, Account account, Group.ReqGroupUsers req) { |
||||
List<GroupUserInfo> groupUserInfos = imGroupService.listGroupUsers(req.getGid()); |
||||
List<Group.UserInfo> userInfos = groupUserInfos.stream().map(gu -> Group.UserInfo.newBuilder() |
||||
.setUid(gu.getUid()) |
||||
.setAccount(gu.getAccount()) |
||||
.setNickname(gu.getNickname()) |
||||
.setOnline(Boolean.TRUE.equals(gu.getOnline())) |
||||
.setLastActive(gu.getLastActive()) |
||||
.build() |
||||
).collect(Collectors.toList()); |
||||
return Group.ResGroupUsers.newBuilder() |
||||
.addAllUsers(userInfos) |
||||
.build(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,41 @@
|
||||
package net.sopod.soim.entry.handlers.group; |
||||
|
||||
import com.google.protobuf.MessageLite; |
||||
import net.sopod.soim.common.dubbo.exception.SoimException; |
||||
import net.sopod.soim.data.msg.common.Res; |
||||
import net.sopod.soim.data.msg.group.Group; |
||||
import net.sopod.soim.entry.server.handler.AccountMessageHandler; |
||||
import net.sopod.soim.entry.server.handler.ImContext; |
||||
import net.sopod.soim.entry.server.session.Account; |
||||
import net.sopod.soim.logic.api.group.service.ImGroupService; |
||||
import org.apache.dubbo.config.annotation.DubboReference; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
/** |
||||
* ReqJoinGroupHandler |
||||
* |
||||
* @author tmy |
||||
* @date 2022-06-05 10:28 |
||||
*/ |
||||
@Service |
||||
public class ReqJoinGroupHandler extends AccountMessageHandler<Group.ReqJoinGroup> { |
||||
|
||||
@DubboReference |
||||
private ImGroupService imGroupService; |
||||
|
||||
@Override |
||||
public MessageLite handle(ImContext ctx, Account account, Group.ReqJoinGroup req) { |
||||
long groupId = req.getGid(); |
||||
Res.ResState.Builder resBuilder = Res.ResState.newBuilder(); |
||||
try { |
||||
Long joinId = imGroupService.joinGroup(groupId, account.getUid()); |
||||
resBuilder.setSuccess(true) |
||||
.setMessage("加入群聊成功:" + joinId); |
||||
} catch (SoimException e) { |
||||
resBuilder.setSuccess(false) |
||||
.setMessage(e.getMessage()); |
||||
} |
||||
return resBuilder.build(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,43 @@
|
||||
package net.sopod.soim.entry.handlers.group; |
||||
|
||||
import com.google.protobuf.MessageLite; |
||||
import net.sopod.soim.das.group.api.model.entity.ImGroup; |
||||
import net.sopod.soim.data.msg.group.Group; |
||||
import net.sopod.soim.entry.server.handler.AccountMessageHandler; |
||||
import net.sopod.soim.entry.server.handler.ImContext; |
||||
import net.sopod.soim.entry.server.session.Account; |
||||
import net.sopod.soim.logic.api.group.service.ImGroupService; |
||||
import org.apache.dubbo.config.annotation.DubboReference; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.List; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* ReqSearchGroupHandler |
||||
* |
||||
* @author tmy |
||||
* @date 2022-06-05 09:20 |
||||
*/ |
||||
@Service |
||||
public class ReqSearchGroupHandler extends AccountMessageHandler<Group.ReqSearchGroup> { |
||||
|
||||
@DubboReference |
||||
private ImGroupService imGroupService; |
||||
|
||||
@Override |
||||
public MessageLite handle(ImContext ctx, Account account, Group.ReqSearchGroup req) { |
||||
String groupName = req.getGroupName(); |
||||
List<ImGroup> imGroups = imGroupService.searchGroup(groupName); |
||||
List<Group.GroupInfo> groupInfos = imGroups.stream().map(imGroup -> Group.GroupInfo.newBuilder() |
||||
.setGid(imGroup.getId()) |
||||
.setGroupName(imGroup.getGroupName()) |
||||
.setUserLimit(imGroup.getUserLimit()) |
||||
.setUserNum(imGroup.getUserNum()) |
||||
.setCreateTime(imGroup.getCreateTime().getTime()) |
||||
.build() |
||||
).collect(Collectors.toList()); |
||||
return Group.ResSearchGroup.newBuilder().addAllGroups(groupInfos).build(); |
||||
} |
||||
|
||||
} |
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue