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
20580f56
Commit
20580f56
authored
Apr 28, 2022
by
Future
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
创建聊天室
parent
7e5af2de
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
5 deletions
+55
-5
core/src/main/java/com/wecloud/im/chatroom/action/ChatRoomAction.java
+1
-1
core/src/main/java/com/wecloud/im/param/add/ImConversationCreate.java
+3
-0
core/src/main/java/com/wecloud/im/service/impl/ImConversationServiceImpl.java
+51
-4
No files found.
core/src/main/java/com/wecloud/im/chatroom/action/ChatRoomAction.java
View file @
20580f56
...
...
@@ -40,7 +40,7 @@ import java.util.Map;
@Slf4j
@Component
@ActionMapping
@Api
(
value
=
"
聊天室消息处理"
,
tags
=
{
"
聊天室消息处理"
})
@Api
(
value
=
"
ws-聊天室消息处理"
,
tags
=
{
"ws-
聊天室消息处理"
})
public
class
ChatRoomAction
{
@Autowired
...
...
core/src/main/java/com/wecloud/im/param/add/ImConversationCreate.java
View file @
20580f56
...
...
@@ -33,6 +33,9 @@ public class ImConversationCreate extends BaseEntity {
@ApiModelProperty
(
"可选 邀请加入会话的客户端,如创建单聊,则填入对方的clientId"
)
private
List
<
String
>
clientIds
;
/**
* @see com.wecloud.im.sdk.enums.ChatTypeEnum
*/
@ApiModelProperty
(
"会话属性,1:单聊,2:普通群,3:万人群, 4:聊天室"
)
@NotNull
(
message
=
"会话类型不能为空"
)
private
Integer
chatType
;
...
...
core/src/main/java/com/wecloud/im/service/impl/ImConversationServiceImpl.java
View file @
20580f56
...
...
@@ -126,15 +126,19 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
ImConversationCreateVo
createImConversation
(
ImConversationCreate
imConversationCreate
)
{
if
(
BaseEnum
.
valueOf
(
ChatTypeEnum
.
class
,
imConversationCreate
.
getChatType
())
==
null
)
{
log
.
info
(
"会话类型不存在"
);
throw
new
BusinessException
(
ApiCode
.
PARAMETER_EXCEPTION
);
}
ImClient
createClient
=
contextService
.
getImClientIfNotNullOrThrow
();
if
(
ChatTypeEnum
.
CHAT_ROOM
.
getCode
().
equals
(
imConversationCreate
.
getChatType
()))
{
// 聊天室
return
this
.
createChatRoom
(
imConversationCreate
,
createClient
);
}
if
(
CollectionUtils
.
isEmpty
(
imConversationCreate
.
getClientIds
()))
{
log
.
info
(
"未找到群成员信息"
);
throw
new
BusinessException
(
ApiCode
.
PARAMETER_EXCEPTION
);
}
if
(
BaseEnum
.
valueOf
(
ChatTypeEnum
.
class
,
imConversationCreate
.
getChatType
())
==
null
)
{
log
.
info
(
"会话类型不存在"
);
throw
new
BusinessException
(
ApiCode
.
PARAMETER_EXCEPTION
);
}
// 成员不存在,不能创建会话
for
(
String
clientId
:
imConversationCreate
.
getClientIds
())
{
ImClient
imClient
=
imClientService
.
getOne
(
new
QueryWrapper
<
ImClient
>().
lambda
()
...
...
@@ -1288,4 +1292,47 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
return
result
;
}
private
ImConversationCreateVo
createChatRoom
(
ImConversationCreate
imConversationCreate
,
ImClient
createClient
)
{
// 会话id
Long
imConversationId
=
SnowflakeUtil
.
getId
();
// 创建者
Long
creator
=
createClient
.
getId
();
// 创建会话
ImConversation
imConversation
=
new
ImConversation
();
imConversation
.
setId
(
imConversationId
);
imConversation
.
setCreateTime
(
new
Date
());
imConversation
.
setLastMessage
(
null
);
imConversation
.
setFkAppid
(
createClient
.
getFkAppid
());
imConversation
.
setCreator
(
creator
);
imConversation
.
setMemberCount
(
imConversationCreate
.
getClientIds
().
size
()
+
1
);
imConversation
.
setChatType
(
imConversationCreate
.
getChatType
());
imConversation
.
setName
(
imConversationCreate
.
getName
());
imConversation
.
setSystemFlag
(
false
);
// 拓展数据
String
attributesStr
=
JsonUtils
.
encodeJson
(
imConversationCreate
.
getAttributes
());
imConversation
.
setAttributes
(
attributesStr
);
imConversationService
.
save
(
imConversation
);
// 将创建者自己添加到会话
Long
imConversationMembersId
=
SnowflakeUtil
.
getId
();
ImConversationMembers
imConversationMembers
=
new
ImConversationMembers
();
imConversationMembers
.
setId
(
imConversationMembersId
);
imConversationMembers
.
setCreateTime
(
new
Date
());
imConversationMembers
.
setUpdateTime
(
new
Date
());
imConversationMembers
.
setFkAppid
(
createClient
.
getFkAppid
());
imConversationMembers
.
setFkConversationId
(
imConversationId
);
imConversationMembers
.
setFkClientId
(
creator
);
imConversationMembers
.
setClientId
(
createClient
.
getClientId
());
imConversationMembers
.
setRole
(
GroupRoleEnum
.
OWNER
.
getCode
());
imConversationMembersService
.
save
(
imConversationMembers
);
ImConversationCreateVo
imConversationCreateVo
=
new
ImConversationCreateVo
();
imConversationCreateVo
.
setId
(
imConversationId
);
return
imConversationCreateVo
;
}
}
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