Commit 831d6451 by giaogiao

修复Attributes重复不能创建会话

parent e299ec07
...@@ -65,6 +65,16 @@ public interface ImConversationMapper extends BaseMapper<ImConversation> { ...@@ -65,6 +65,16 @@ public interface ImConversationMapper extends BaseMapper<ImConversation> {
*/ */
Integer getRepetitionConversation(@Param("clientId1") Long clientId1, @Param("clientId2") Long clientId2); Integer getRepetitionConversation(@Param("clientId1") Long clientId1, @Param("clientId2") Long clientId2);
/**
* 判断重复会话中的Attributes是否一样
*
* @param clientId1
* @param clientId2
* @param attributes
* @return 大于等于1为有重复会话
*/
Long getRepetitionConversationAttributes(@Param("clientId1") Long clientId1, @Param("clientId2") Long clientId2, @Param("attributes") String attributes);
/** /**
* 查询已经存在的会话信息 * 查询已经存在的会话信息
......
...@@ -102,5 +102,15 @@ public interface ImConversationService extends BaseService<ImConversation> { ...@@ -102,5 +102,15 @@ public interface ImConversationService extends BaseService<ImConversation> {
*/ */
Integer getRepetitionConversation(Long clientId1, Long clientId2); Integer getRepetitionConversation(Long clientId1, Long clientId2);
/**
* 判断重复会话中的Attributes是否一样
*
* @param clientId1
* @param clientId2
* @param attributes
* @return 大于等于1为有重复会话
*/
Long getRepetitionConversationAttributes(Long clientId1, Long clientId2, String attributes);
} }
...@@ -123,37 +123,30 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -123,37 +123,30 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
} }
} else { } else {
//创建重复会话时对比扩展字段 0不 1是 //创建重复会话时对比扩展字段 1是
if (imApplication.getContrastExtendedFieldStatus() == 1) { if (imApplication.getContrastExtendedFieldStatus() == 1) {
// 被邀请client // 被邀请client
ImClient inviteClient = imClientService.getOne(new QueryWrapper<ImClient>().lambda() ImClient inviteClient = imClientService.getOne(new QueryWrapper<ImClient>().lambda()
.eq(ImClient::getFkAppid, createClient.getFkAppid()) .eq(ImClient::getFkAppid, createClient.getFkAppid())
.eq(ImClient::getClientId, imConversationCreate.getClientIds().get(0))); .eq(ImClient::getClientId, imConversationCreate.getClientIds().get(0)));
JsonMapper jsonMapper = new JsonMapper();
String asString = jsonMapper.writeValueAsString(imConversationCreate.getAttributes());
log.info("RequestAttributes:" + asString);
// 是否存在重复会话
Integer repetitionConversation = getRepetitionConversation(createClient.getId(), inviteClient.getId());
if (repetitionConversation != 0) {
ImConversation repetitionConversationInfo = imConversationMapper.getRepetitionConversationInfo(createClient.getId(), inviteClient.getId());
log.info("出现Conversation重复");
JsonMapper jsonMapper = new JsonMapper(); Long repetitionConversation = getRepetitionConversationAttributes(createClient.getId(), inviteClient.getId(), asString);
HashMap dbAttributesMap = jsonMapper.readValue(repetitionConversationInfo.getAttributes(), HashMap.class);
log.info("DBAttributes:" + repetitionConversationInfo.getAttributes()); // 存在重复会话
log.info("RequestAttributes:" + jsonMapper.writeValueAsString(imConversationCreate.getAttributes())); if (repetitionConversation != null) {
log.info("出现Attributes重复");
ImConversationCreateVo imConversationCreateVo = new ImConversationCreateVo();
if (dbAttributesMap.equals(imConversationCreate.getAttributes())) { imConversationCreateVo.setId(repetitionConversation);
log.info("出现Attributes重复"); // 为重复
ImConversationCreateVo imConversationCreateVo = new ImConversationCreateVo(); return ApiResult.ok(imConversationCreateVo);
imConversationCreateVo.setId(repetitionConversationInfo.getId());
// 为重复
return ApiResult.ok(imConversationCreateVo);
}
} }
} }
} }
// 会话id // 会话id
...@@ -289,4 +282,9 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -289,4 +282,9 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
return imConversationMapper.getRepetitionConversation(clientId1, clientId2); return imConversationMapper.getRepetitionConversation(clientId1, clientId2);
} }
@Override
public Long getRepetitionConversationAttributes(Long clientId1, Long clientId2, String attributes) {
return imConversationMapper.getRepetitionConversationAttributes(clientId1, clientId2, attributes);
}
} }
...@@ -72,6 +72,25 @@ ...@@ -72,6 +72,25 @@
) AS r1 ) AS r1
WHERE members_count = 2 WHERE members_count = 2
</select> </select>
<select id="getRepetitionConversationAttributes" resultType="java.lang.Long">
SELECT *
FROM im_conversation
WHERE id IN (
SELECT im_conversation_members.fk_conversation_id
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}
)
AND attributes = CAST(#{attributes} AS json) LIMIT 1
</select>
<select id="getRepetitionConversationInfo" resultType="com.wecloud.im.entity.ImConversation"> <select id="getRepetitionConversationInfo" resultType="com.wecloud.im.entity.ImConversation">
SELECT im_conversation.* SELECT im_conversation.*
FROM im_conversation_members FROM im_conversation_members
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment