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
6ce86067
Commit
6ce86067
authored
Jan 28, 2022
by
李晓钟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
创建会话的逻辑修改。
parent
ea3d2648
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
41 additions
and
112 deletions
+41
-112
bootstrap/src/main/java/io/geekidea/springbootplus/config/RedisCacheConfig.java
+8
-10
core/src/main/java/com/wecloud/im/action/NormalChatAction.java
+12
-27
core/src/main/java/com/wecloud/im/mapper/ImConversationMapper.java
+2
-12
core/src/main/java/com/wecloud/im/service/ImConversationService.java
+0
-10
core/src/main/java/com/wecloud/im/service/impl/ImApplicationServiceImpl.java
+4
-4
core/src/main/java/com/wecloud/im/service/impl/ImConversationServiceImpl.java
+6
-14
core/src/main/resources/mapper/ImConversationMapper.xml
+9
-35
No files found.
bootstrap/src/main/java/io/geekidea/springbootplus/config/RedisCacheConfig.java
View file @
6ce86067
...
...
@@ -29,9 +29,7 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
import
java.time.Duration
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Set
;
/**
* <p>
...
...
@@ -59,29 +57,29 @@ public class RedisCacheConfig extends CachingConfigurerSupport {
};
}
@Bean
public
CacheManager
cacheManager
(
RedisConnectionFactory
factory
)
{
// 生成一个默认配置,通过config对象即可对缓存进行自定义配置
RedisCacheConfiguration
config
=
RedisCacheConfiguration
.
defaultCacheConfig
();
// 设置缓存的默认过期时间,也是使用Duration设置
// 过期时间30分钟
config
=
config
.
entryTtl
(
Duration
.
ofMinutes
(
30
));
config
=
config
.
entryTtl
(
Duration
.
ofMinutes
(
30
))
.
prefixKeysWith
(
"cache"
)
;
// 设置一个初始化的缓存空间set集合
Set
<
String
>
cacheNames
=
new
HashSet
<>();
cacheNames
.
add
(
"my-redis-cache1
"
);
cacheNames
.
add
(
"my-redis-cache2"
);
//
Set<String> cacheNames = new HashSet<>();
// cacheNames.add("expireKey
");
//
cacheNames.add("my-redis-cache2");
// 对每个缓存空间应用不同的配置
Map
<
String
,
RedisCacheConfiguration
>
configMap
=
new
HashMap
<>(
10
);
configMap
.
put
(
"my-redis-cache1"
,
config
);
configMap
.
put
(
"my-redis-cache2"
,
config
.
entryTtl
(
Duration
.
ofSeconds
(
120
)));
configMap
.
put
(
"expireKey"
,
config
);
// 使用自定义的缓存配置初始化一个cacheManager
RedisCacheManager
cacheManager
=
RedisCacheManager
.
builder
(
factory
)
// 注意这两句的调用顺序,一定要先调用该方法设置初始化的缓存名,再初始化相关的配置
.
initialCacheNames
(
cacheNames
)
// .initialCacheNames(cacheNames)
.
cacheDefaults
(
config
)
.
withInitialCacheConfigurations
(
configMap
)
.
build
();
...
...
core/src/main/java/com/wecloud/im/action/NormalChatAction.java
View file @
6ce86067
...
...
@@ -4,24 +4,12 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import
com.wecloud.dispatch.annotation.ActionMapping
;
import
com.wecloud.dispatch.common.BaseRequest
;
import
com.wecloud.dispatch.extend.ActionRequest
;
import
com.wecloud.im.entity.ImApplication
;
import
com.wecloud.im.entity.ImClient
;
import
com.wecloud.im.entity.ImConversationMembers
;
import
com.wecloud.im.entity.ImInbox
;
import
com.wecloud.im.entity.ImMessage
;
import
com.wecloud.im.entity.ImMessageOnlineSend
;
import
com.wecloud.im.entity.*
;
import
com.wecloud.im.param.ChatContentVo
;
import
com.wecloud.im.param.ImClientSimpleDto
;
import
com.wecloud.im.param.ImConversationQueryVo
;
import
com.wecloud.im.param.MsgVo
;
import
com.wecloud.im.service.ImApplicationService
;
import
com.wecloud.im.service.ImClientBlacklistService
;
import
com.wecloud.im.service.ImClientService
;
import
com.wecloud.im.service.ImConversationMembersService
;
import
com.wecloud.im.service.ImConversationService
;
import
com.wecloud.im.service.ImInboxService
;
import
com.wecloud.im.service.ImMessageService
;
import
com.wecloud.im.thousandchat.cache.ThousandChatCacheManager
;
import
com.wecloud.im.service.*
;
import
com.wecloud.im.ws.enums.WsResponseCmdEnum
;
import
com.wecloud.im.ws.model.WsResponse
;
import
com.wecloud.im.ws.sender.AsyncPush
;
...
...
@@ -67,8 +55,6 @@ public class NormalChatAction {
@Autowired
private
ChannelSender
channelSender
;
@Autowired
private
ThousandChatCacheManager
thousandChatCacheManager
;
@Autowired
private
ImClientBlacklistService
imClientBlacklistService
;
@Autowired
private
ImInboxService
imInboxService
;
...
...
@@ -121,9 +107,6 @@ public class NormalChatAction {
ImMessageOnlineSend
imMessageOnlineSend
=
assembleImMessageOnlineSend
(
data
,
imClientSender
,
imApplication
.
getId
());
// 在线用户直接发消息
sendMsgForOnline
(
data
,
imMessageOnlineSend
);
// 再给所有人发 todo 需要改成批量
for
(
ImConversationMembers
conversationMembers
:
membersList
)
{
// 入库 保存收件箱
...
...
@@ -137,6 +120,13 @@ public class NormalChatAction {
if
(
imClientReceiver
==
null
)
{
continue
;
}
if
(
imClientReceiver
.
getId
().
equals
(
imClientSender
.
getId
()))
{
// 不给自己发
continue
;
}
// 在线用户直接发消息
sendMsgForOnline
(
imClientReceiver
.
getId
(),
imMessageOnlineSend
);
// 异步推送系统通知消息
systemPush
.
push
(
data
.
getPush
(),
imClientReceiver
,
imApplication
);
}
...
...
@@ -148,12 +138,10 @@ public class NormalChatAction {
/**
* 发送消息给在线客户
* @param
data
* @param
receiverClientId
* @param imMessageOnlineSend
*/
private
void
sendMsgForOnline
(
ChatContentVo
data
,
ImMessageOnlineSend
imMessageOnlineSend
)
{
Map
<
String
/** ip **/
,
List
<
String
/** client的主键ID:platform **/
>>
onlineIpClientMap
=
thousandChatCacheManager
.
findOnlineHostsByThousandGroupId
(
data
.
getToConversation
());
private
void
sendMsgForOnline
(
Long
receiverClientId
,
ImMessageOnlineSend
imMessageOnlineSend
)
{
// 封装要推给接收方的消息
WsResponse
<
ImMessageOnlineSend
>
responseModel
=
new
WsResponse
<>();
responseModel
.
setCmd
(
WsResponseCmdEnum
.
ONLINE_MSG
.
getCmdCode
());
...
...
@@ -162,10 +150,7 @@ public class NormalChatAction {
responseModel
.
setMsg
(
result
.
getMessage
());
responseModel
.
setData
(
imMessageOnlineSend
);
responseModel
.
setReqId
(
null
);
onlineIpClientMap
.
forEach
((
ip
,
clientIdAndPlatforms
)
->
{
channelSender
.
batchSendMsg
(
responseModel
,
ip
,
clientIdAndPlatforms
);
});
channelSender
.
sendMsg
(
responseModel
,
receiverClientId
);
}
/**
...
...
core/src/main/java/com/wecloud/im/mapper/ImConversationMapper.java
View file @
6ce86067
...
...
@@ -57,13 +57,13 @@ public interface ImConversationMapper extends BaseMapper<ImConversation> {
List
<
ImConversation
>
getMyImConversationList
(
@Param
(
"clientId"
)
Long
clientId
);
/**
*
判断两个客户端是否存在会话
*
查询已经存在的一对一会话信息
*
* @param clientId1
* @param clientId2
* @return
*/
I
nteger
getRepetitionConversation
(
@Param
(
"clientId1"
)
Long
clientId1
,
@Param
(
"clientId2"
)
Long
clientId2
);
I
mConversation
getRepetitionConversationSingle
(
@Param
(
"clientId1"
)
Long
clientId1
,
@Param
(
"clientId2"
)
Long
clientId2
);
/**
* 判断重复会话中的Attributes是否一样
...
...
@@ -75,16 +75,6 @@ public interface ImConversationMapper extends BaseMapper<ImConversation> {
*/
Long
getRepetitionConversationAttributes
(
@Param
(
"clientId1"
)
Long
clientId1
,
@Param
(
"clientId2"
)
Long
clientId2
,
@Param
(
"attributes"
)
String
attributes
);
/**
* 查询已经存在的一对一会话信息
*
* @param clientId1
* @param clientId2
* @return
*/
ImConversation
getRepetitionConversationInfo
(
@Param
(
"clientId1"
)
Long
clientId1
,
@Param
(
"clientId2"
)
Long
clientId2
);
/**
* 增减成员数量
* @param appId fkAppid
...
...
core/src/main/java/com/wecloud/im/service/ImConversationService.java
View file @
6ce86067
...
...
@@ -137,16 +137,6 @@ public interface ImConversationService extends BaseService<ImConversation> {
*/
List
<
ImConversation
>
getMyImConversationList
()
throws
Exception
;
/**
* 判断两个客户端是否存在会话
*
* @param clientId1
* @param clientId2
* @return
*/
Integer
getRepetitionConversation
(
Long
clientId1
,
Long
clientId2
);
/**
* 判断重复会话中的Attributes是否一样
*
...
...
core/src/main/java/com/wecloud/im/service/impl/ImApplicationServiceImpl.java
View file @
6ce86067
...
...
@@ -35,23 +35,23 @@ public class ImApplicationServiceImpl extends BaseServiceImpl<ImApplicationMappe
private
ImApplicationMapper
imApplicationMapper
;
@Override
@Cacheable
(
key
=
"#p0"
)
@Cacheable
(
key
=
"
'id_'+
#p0"
)
public
ImApplication
getCacheById
(
Long
id
)
{
return
super
.
getById
(
id
);
}
@Override
@CacheEvict
(
key
=
"#p0"
)
@CacheEvict
(
key
=
"
'id_'+
#p0"
)
public
void
deleteCacheById
(
Long
id
)
{
}
@Override
@CacheEvict
(
key
=
"#p0"
)
@CacheEvict
(
key
=
"
'appKey_'+
#p0"
)
public
void
deleteCacheByAppKey
(
String
appKey
)
{
}
@Override
@Cacheable
(
key
=
"#p0"
)
@Cacheable
(
key
=
"
'appKey_'+
#p0"
)
public
ImApplication
getCacheAppByAppKey
(
String
appKey
)
{
ImApplication
imApplication
=
this
.
getOne
(
new
QueryWrapper
<
ImApplication
>().
lambda
()
...
...
core/src/main/java/com/wecloud/im/service/impl/ImConversationServiceImpl.java
View file @
6ce86067
...
...
@@ -128,25 +128,22 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
// 根据appKey查询application
ImApplication
imApplication
=
imApplicationService
.
getCacheAppByAppKey
(
curentJwtToken
.
getAppKey
());
// 该应用 是否允许创建重复
一对一
会话 0不允许 1允许
// 该应用 是否允许创建重复
单聊类型
会话 0不允许 1允许
if
(
imApplication
.
getRepeatSessionStatus
()
!=
null
&&
imApplication
.
getRepeatSessionStatus
()
==
0
)
{
// 判断是否已经存在
一对一
会话
// 判断是否已经存在
单聊类型
会话
// size() == 1 为单聊不允许重复创建 两个用户如果已经创建过会话,不能重复创建会话
if
(
imConversationCreate
.
getClientIds
().
size
()
==
1
)
{
ImClient
client2
=
imClientService
.
getOne
(
new
QueryWrapper
<
ImClient
>().
lambda
()
.
eq
(
ImClient:
:
getFkAppid
,
createClient
.
getFkAppid
())
.
eq
(
ImClient:
:
getClientId
,
imConversationCreate
.
getClientIds
().
get
(
0
)));
// 是否存在重复一对一会话
Integer
repetitionConversation
=
getRepetitionConversation
(
createClient
.
getId
(),
client2
.
getId
());
if
(
repetitionConversation
!=
0
)
{
// 如果存在重复单聊类型会话,则不会为空
ImConversation
repetitionConversationInfo
=
imConversationMapper
.
getRepetitionConversationSingle
(
createClient
.
getId
(),
client2
.
getId
());
if
(
repetitionConversationInfo
!=
null
)
{
log
.
info
(
"repetitionConversation != 0"
);
// 返回已存在的一对一会话id
ImConversation
repetitionConversationInfo
=
imConversationMapper
.
getRepetitionConversationInfo
(
createClient
.
getId
(),
client2
.
getId
());
// 返回已存在的单聊类型会话id
ImConversationCreateVo
imConversationCreateVo
=
new
ImConversationCreateVo
();
imConversationCreateVo
.
setId
(
repetitionConversationInfo
.
getId
());
return
ApiResult
.
ok
(
imConversationCreateVo
);
}
}
...
...
@@ -848,11 +845,6 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
}
@Override
public
Integer
getRepetitionConversation
(
Long
clientId1
,
Long
clientId2
)
{
return
imConversationMapper
.
getRepetitionConversation
(
clientId1
,
clientId2
);
}
@Override
public
Long
getRepetitionConversationAttributes
(
Long
clientId1
,
Long
clientId2
,
String
attributes
)
{
return
imConversationMapper
.
getRepetitionConversationAttributes
(
clientId1
,
clientId2
,
attributes
);
}
...
...
core/src/main/resources/mapper/ImConversationMapper.xml
View file @
6ce86067
...
...
@@ -56,25 +56,16 @@
ON imConversation.id = imConversationMembers.fk_conversation_id
WHERE imConversationMembers.fk_client_id = #{clientId}
</select>
<select
id=
"getRepetitionConversation"
resultType=
"java.lang.Integer"
>
-- 查询是否有重复会话
SELECT COUNT(id)
FROM (
SELECT im_conversation_members.*,
(SELECT COUNT(im2.id)
FROM im_conversation_members AS im2
WHERE im2.fk_conversation_id = im_conversation_members.fk_conversation_id) AS members_count
FROM im_conversation_members
INNER JOIN (SELECT *
FROM im_conversation_members
WHERE im_conversation_members.fk_client_id = #{clientId2}) AS im_conversation_members2
ON im_conversation_members.fk_conversation_id =
im_conversation_members2.fk_conversation_id
WHERE im_conversation_members.fk_client_id = #{clientId1}
) AS r1
WHERE members_count = 2
</select>
<select
id=
"getRepetitionConversationSingle"
resultType=
"com.wecloud.im.entity.ImConversation"
>
-- 查询重复的单聊会话第一条
select con.* from im_conversation con
inner join im_conversation_members mem1
on con.id = mem1.fk_conversation_id and mem1.fk_client_id = #{clientId1}
inner join im_conversation_members mem2
on con.id = mem2.fk_conversation_id and mem2.fk_client_id = #{clientId2}
where con.chat_type = 1 and con.member_count = 2 order by con.id asc LIMIT 1
</select>
<select
id=
"getRepetitionConversationAttributes"
resultType=
"java.lang.Long"
>
SELECT *
...
...
@@ -92,23 +83,6 @@
AND attributes = CAST(#{attributes} AS json) LIMIT 1
</select>
<select
id=
"getRepetitionConversationInfo"
resultType=
"com.wecloud.im.entity.ImConversation"
>
SELECT im_conversation.*,
(SELECT COUNT(im2.id)
FROM im_conversation_members AS im2
WHERE im2.fk_conversation_id = im_conversation_members.fk_conversation_id) AS members_count
FROM im_conversation_members
INNER JOIN (SELECT *
FROM im_conversation_members
WHERE im_conversation_members.fk_client_id = #{clientId2}) AS im_conversation_members2
ON im_conversation_members.fk_conversation_id = im_conversation_members2.fk_conversation_id
INNER JOIN im_conversation ON im_conversation.id = im_conversation_members.fk_conversation_id
WHERE im_conversation_members.fk_client_id = #{clientId1}
HAVING members_count = 2 LIMIT 1
</select>
<update
id=
"addMemberCount"
>
update im_conversation set member_count = member_count + #{addCount} where fk_appid = #{appId} and id = #{conversationId}
</update>
...
...
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