Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wecloud_im_server
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hewei
wecloud_im_server
Commits
4843faef
Commit
4843faef
authored
May 11, 2022
by
Future
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
解散聊天室逻辑
parent
f9784c21
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
26 deletions
+84
-26
core/src/main/java/com/wecloud/im/entity/ImConversation.java
+4
-0
core/src/main/java/com/wecloud/im/param/ChatRoomMemberPageParam.java
+4
-0
core/src/main/java/com/wecloud/im/service/impl/ImConversationServiceImpl.java
+76
-26
No files found.
core/src/main/java/com/wecloud/im/entity/ImConversation.java
View file @
4843faef
...
@@ -45,6 +45,10 @@ public class ImConversation extends BaseEntity {
...
@@ -45,6 +45,10 @@ public class ImConversation extends BaseEntity {
@ApiModelProperty
(
"群成员数量"
)
@ApiModelProperty
(
"群成员数量"
)
private
Integer
memberCount
;
private
Integer
memberCount
;
/**
* 会话属性
* @see com.wecloud.im.sdk.enums.ChatTypeEnum
*/
@ApiModelProperty
(
"会话属性,1:单聊,2:普通群,3:万人群,4:聊天室"
)
@ApiModelProperty
(
"会话属性,1:单聊,2:普通群,3:万人群,4:聊天室"
)
private
Integer
chatType
;
private
Integer
chatType
;
...
...
core/src/main/java/com/wecloud/im/param/ChatRoomMemberPageParam.java
View file @
4843faef
...
@@ -2,7 +2,9 @@ package com.wecloud.im.param;
...
@@ -2,7 +2,9 @@ package com.wecloud.im.param;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
lombok.experimental.Accessors
;
import
lombok.experimental.Accessors
;
import
java.io.Serializable
;
import
java.io.Serializable
;
...
@@ -15,6 +17,8 @@ import java.io.Serializable;
...
@@ -15,6 +17,8 @@ import java.io.Serializable;
@Data
@Data
@Accessors
(
chain
=
true
)
@Accessors
(
chain
=
true
)
@ApiModel
(
value
=
"聊天室成员分页入参"
)
@ApiModel
(
value
=
"聊天室成员分页入参"
)
@NoArgsConstructor
@AllArgsConstructor
public
class
ChatRoomMemberPageParam
implements
Serializable
{
public
class
ChatRoomMemberPageParam
implements
Serializable
{
private
static
final
long
serialVersionUID
=
3284648263835691087L
;
private
static
final
long
serialVersionUID
=
3284648263835691087L
;
...
...
core/src/main/java/com/wecloud/im/service/impl/ImConversationServiceImpl.java
View file @
4843faef
package
com
.
wecloud
.
im
.
service
.
impl
;
package
com
.
wecloud
.
im
.
service
.
impl
;
import
io.geekidea.springbootplus.framework.common.api.ApiCode
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
import
io.geekidea.springbootplus.framework.common.enums.BaseEnum
;
import
io.geekidea.springbootplus.framework.common.exception.BusinessException
;
import
io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl
;
import
io.geekidea.springbootplus.framework.core.pagination.PageInfo
;
import
io.geekidea.springbootplus.framework.core.pagination.Paging
;
import
lombok.extern.slf4j.Slf4j
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.date.DateUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper
;
import
com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper
;
...
@@ -88,6 +62,29 @@ import com.wecloud.im.ws.sender.ChannelSender;
...
@@ -88,6 +62,29 @@ import com.wecloud.im.ws.sender.ChannelSender;
import
com.wecloud.im.ws.utils.RedisUtils
;
import
com.wecloud.im.ws.utils.RedisUtils
;
import
com.wecloud.utils.JsonUtils
;
import
com.wecloud.utils.JsonUtils
;
import
com.wecloud.utils.SnowflakeUtil
;
import
com.wecloud.utils.SnowflakeUtil
;
import
io.geekidea.springbootplus.framework.common.api.ApiCode
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
import
io.geekidea.springbootplus.framework.common.enums.BaseEnum
;
import
io.geekidea.springbootplus.framework.common.exception.BusinessException
;
import
io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl
;
import
io.geekidea.springbootplus.framework.core.pagination.PageInfo
;
import
io.geekidea.springbootplus.framework.core.pagination.Paging
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
import
static
cn
.
hutool
.
core
.
date
.
DatePattern
.
CHINESE_DATE_PATTERN
;
import
static
cn
.
hutool
.
core
.
date
.
DatePattern
.
CHINESE_DATE_PATTERN
;
import
static
com
.
wecloud
.
im
.
ws
.
enums
.
MsgTypeEnum
.
CONVERSATION_FORBID_ADD_FRIEND
;
import
static
com
.
wecloud
.
im
.
ws
.
enums
.
MsgTypeEnum
.
CONVERSATION_FORBID_ADD_FRIEND
;
...
@@ -686,8 +683,17 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
...
@@ -686,8 +683,17 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
@Override
@Override
public
void
disband
(
DisbandConversationParam
param
)
{
public
void
disband
(
DisbandConversationParam
param
)
{
ImConversation
imConversation
=
imConversationMapper
.
selectById
(
param
.
getConversationId
());
if
(
imConversation
==
null
)
{
throw
new
BusinessException
(
"查无会话信息"
);
}
// 获取当前client
// 获取当前client
ImClient
currentClient
=
contextService
.
getImClientIfNotNullOrThrow
();
ImClient
currentClient
=
contextService
.
getImClientIfNotNullOrThrow
();
if
(
ChatTypeEnum
.
CHAT_ROOM
.
getCode
().
equals
(
imConversation
.
getChatType
()))
{
// 聊天室事件发送逻辑
disbandChatRoom
(
param
.
getConversationId
(),
currentClient
);
return
;
}
// 判断是否为群主
// 判断是否为群主
ImConversationMembers
conversationMember
=
imConversationMembersService
.
getOne
(
ImConversationMembers
conversationMember
=
imConversationMembersService
.
getOne
(
new
QueryWrapper
<
ImConversationMembers
>().
lambda
()
new
QueryWrapper
<
ImConversationMembers
>().
lambda
()
...
@@ -734,6 +740,44 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
...
@@ -734,6 +740,44 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
sendMsgToMembers
(
conversationId
,
membersList
,
appId
,
sender
,
content
,
imMessage
);
sendMsgToMembers
(
conversationId
,
membersList
,
appId
,
sender
,
content
,
imMessage
);
}
}
/**
* 解散聊天室
* @param conversationId
* @param currentClient
*/
private
void
disbandChatRoom
(
Long
conversationId
,
ImClient
currentClient
)
{
Map
<
String
,
String
>
chatRoomMembers
=
chatRoomCacheManager
.
findOnlineClientsByChatRoomId
(
conversationId
);
if
(
chatRoomMembers
.
isEmpty
())
{
throw
new
BusinessException
(
"聊天室成员列为空"
);
}
// 保存事件消息
ImMessage
imMessage
=
new
ImMessage
();
Map
<
String
,
Object
>
content
=
new
HashMap
<>();
content
.
put
(
"operator"
,
currentClient
.
getClientId
());
imMessage
.
setContent
(
JsonUtils
.
encodeJson
(
content
));
// 保存消息至消息表
imMessage
.
setId
(
SnowflakeUtil
.
getId
());
imMessage
.
setMsgType
(
MsgTypeEnum
.
CONVERSATION_DISBAND
.
getUriCode
());
imMessage
.
setCreateTime
(
new
Date
());
imMessage
.
setFkAppid
(
currentClient
.
getFkAppid
());
imMessage
.
setSender
(
currentClient
.
getId
());
imMessage
.
setWithdraw
(
false
);
imMessage
.
setEvent
(
true
);
imMessage
.
setSystemFlag
(
false
);
imMessage
.
setSendStatus
(
2
);
imMessage
.
setFkConversationId
(
conversationId
);
Long
appId
=
currentClient
.
getFkAppid
();
String
sender
=
currentClient
.
getClientId
();
// 遍历发送给已在群内的成员
for
(
String
key
:
chatRoomMembers
.
keySet
())
{
Long
fkClientId
=
Long
.
valueOf
(
key
.
split
(
RedisUtils
.
SPLIT
)[
0
]);
sendEventMsgToMember
(
conversationId
,
currentClient
.
getFkAppid
(),
currentClient
.
getClientId
(),
fkClientId
,
null
,
imMessage
);
}
}
@Override
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Boolean
leaveConversation
(
ImClientLeaveConversation
imClientToConversation
)
{
public
Boolean
leaveConversation
(
ImClientLeaveConversation
imClientToConversation
)
{
...
@@ -1217,6 +1261,9 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
...
@@ -1217,6 +1261,9 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
@Override
@Override
public
Boolean
intoChatRoom
(
IntoChatRoomParam
param
)
{
public
Boolean
intoChatRoom
(
IntoChatRoomParam
param
)
{
if
(
param
.
getPlatform
()
==
null
)
{
throw
new
BusinessException
(
"平台入参不可为空"
);
}
// 获取当前client
// 获取当前client
ImClient
imClientSender
=
contextService
.
getImClientIfNotNullOrThrow
();
ImClient
imClientSender
=
contextService
.
getImClientIfNotNullOrThrow
();
// 根据appId查询application
// 根据appId查询application
...
@@ -1368,6 +1415,9 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
...
@@ -1368,6 +1415,9 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
}
}
private
ImConversationCreateVo
createChatRoom
(
ImConversationCreate
imConversationCreate
,
ImClient
createClient
)
{
private
ImConversationCreateVo
createChatRoom
(
ImConversationCreate
imConversationCreate
,
ImClient
createClient
)
{
if
(
imConversationCreate
.
getPlatform
()
==
null
)
{
throw
new
BusinessException
(
"平台入参不可为空"
);
}
// 会话id
// 会话id
Long
chatRoomId
=
SnowflakeUtil
.
getId
();
Long
chatRoomId
=
SnowflakeUtil
.
getId
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment