Commit c4195da7 by Future

好友关系逻辑调整

parent 46cc0362
......@@ -66,7 +66,7 @@ public class ImFriendController extends BaseController {
if(friendClient == null) {
return ApiResult.fail(ApiCode.CLIENT_NOT_FOUNT, null);
}
ImFriendApplyDto friendInfo = imFriendService.getFriendInfo(currentClient.getId(), friendClient.getId());
ImFriendApplyDto friendInfo = imFriendService.getFriendInfo(currentClient.getClientId(), friendClient.getClientId());
return ApiResult.ok(friendInfo);
}
......
......@@ -29,13 +29,13 @@ public class ImFriend extends BaseEntity {
private Long id;
@ApiModelProperty("我的client-id")
private Long fkClientId;
private String clientId;
@ApiModelProperty("好友的client-id")
private Long fkClientIdFriend;
private String clientIdFriend;
@ApiModelProperty("申请者")
private Long fkClientIdClaimer;
private String clientIdClaimer;
@ApiModelProperty("好友的昵称备注")
private String friendName;
......
......@@ -29,10 +29,10 @@ public class ImFriendRecommend extends BaseEntity {
private Long id;
@ApiModelProperty("我的client-id")
private Long fkClientId;
private String clientId;
@ApiModelProperty("好友的client-id")
private Long fkClientIdFriend;
private String clientIdFriend;
@ApiModelProperty("推荐来源")
private Integer source;
......
......@@ -21,23 +21,29 @@ public interface ImFriendMapper extends BaseMapper<ImFriend> {
IPage<ImFriendBaseDto> getImFriendPageList(@Param("page") Page<ImFriendBaseDto> page, @Param("clientId") Long fkClientId);
IPage<ImFriendApplyDto> getUnsureFriendPageList(@Param("page") Page<ImFriendApplyDto> page, @Param("clientId") Long fkClientId);
/**
* 获取待验证的好友列表
* @param page
* @param clientId
* @return
*/
IPage<ImFriendApplyDto> getUnsureFriendPageList(@Param("page") Page<ImFriendApplyDto> page, @Param("clientId") String clientId);
ImFriendApplyDto getFriendInfo(@Param("clientId") Long fkClientId, @Param("friendClientId") Long fkFriendClientId);
ImFriendApplyDto getFriendInfo(@Param("clientId") String clientId, @Param("friendClientId") String friendClientId);
/**
* 过滤得到真的好友,非好友的friendId将被它忽略
* @param fkClientId
* @param fkFriendClientIds
* @param clientId
* @param friendClientIds
* @return
*/
List<Long> filterNegativeFriends(@Param("clientId") Long fkClientId, @Param("friendClientIds") List<Long> fkFriendClientIds);
List<String> filterNegativeFriends(@Param("clientId") String clientId, @Param("friendClientIds") List<String> friendClientIds);
/**
* 批量删除好友
* @param fkClientId 删除人的clientId
* @param clientId 删除人的clientId
* @param fkAppId
* @param friendClientIds 被删除人的clientId列表
*/
void batchDeleteFriend(@Param("clientId") Long fkClientId, @Param("fkAppId") Long fkAppId, @Param("friendClientIds") List<String> friendClientIds);
void batchDeleteFriend(@Param("clientId") String clientId, @Param("fkAppId") Long fkAppId, @Param("friendClientIds") List<String> friendClientIds);
}
......@@ -22,7 +22,13 @@ public interface ImFriendRecommendMapper extends BaseMapper<ImFriendRecommend> {
IPage<ImFriendRecommendDto> getImFriendRecommendPageList(@Param("page") Page pageParam, @Param("clientId") Long clientId);
void batchDeleteRecommend(@Param("clientId") Long clientId, @Param("fkAppId") Long fkAppId, @Param("friendClientIds") List<String> friendClientIds);
/**
* 批量删除好友推荐
* @param clientId
* @param fkAppId
* @param friendClientIds
*/
void batchDeleteRecommend(@Param("clientId") String clientId, @Param("fkAppId") Long fkAppId, @Param("friendClientIds") List<String> friendClientIds);
void batchCreateRecommend(@Param("list") List<ImFriendRecommend> list);
}
......@@ -6,7 +6,7 @@ import lombok.Data;
import java.io.Serializable;
/**
* @Description TODO
* @Description 申请好友入参
* @Author lixiaozhong
* @Date 2022/1/13 4:24 下午
*/
......@@ -16,6 +16,7 @@ public class ImFriendApplyParam extends ImFriendBaseParam {
@ApiModelProperty("备注好友名称")
private String friendName;
@ApiModelProperty("请求备注")
private String requestRemark;
}
......@@ -6,7 +6,7 @@ import lombok.Data;
import java.io.Serializable;
/**
* @Description TODO
* @Description 好友相关base入参
* @Author lixiaozhong
* @Date 2022/1/13 4:24 下午
*/
......
......@@ -55,12 +55,12 @@ public class ImFriendService extends BaseServiceImpl<ImFriendMapper, ImFriend> {
/**
* 查看朋友详情
* @param curentClientId
* @param currentClientId
* @param friendClientId
* @return
*/
public ImFriendApplyDto getFriendInfo(Long curentClientId, Long friendClientId) {
return imFriendMapper.getFriendInfo(curentClientId, friendClientId);
public ImFriendApplyDto getFriendInfo(String currentClientId, String friendClientId) {
return imFriendMapper.getFriendInfo(currentClientId, friendClientId);
}
/**
......@@ -72,7 +72,7 @@ public class ImFriendService extends BaseServiceImpl<ImFriendMapper, ImFriend> {
ImFriendPageParam pageParam = new ImFriendPageParam();
pageParam.setPageSize(1000L);
Page<ImFriendApplyDto> page = new PageInfo(pageParam, OrderItem.desc(getLambdaColumn(ImFriend::getCreateTime)));
IPage<ImFriendApplyDto> pageList = imFriendMapper.getUnsureFriendPageList(page, currentClient.getId());
IPage<ImFriendApplyDto> pageList = imFriendMapper.getUnsureFriendPageList(page, currentClient.getClientId());
return pageList.getRecords();
}
......@@ -88,13 +88,13 @@ public class ImFriendService extends BaseServiceImpl<ImFriendMapper, ImFriend> {
public Boolean applyFriend(ImClient currentClient, ImClient friendClient, String friendName, String requestRemark) {
//好友关系有维护两条,我和他,他和我
ImFriend my = new ImFriend();
my.setFkClientId(currentClient.getId());
my.setFkClientIdFriend(friendClient.getId());
my.setFkClientIdClaimer(currentClient.getId());
my.setClientId(currentClient.getClientId());
my.setClientIdFriend(friendClient.getClientId());
my.setClientIdClaimer(currentClient.getClientId());
my.setFriendName(friendName);
my.setRequestRemark(requestRemark);
my.setState(FriendStateEnum.UNSURE.getCode());
if(getByKey(currentClient.getId(), friendClient.getId()) != null) {
if(getByKey(currentClient.getClientId(), friendClient.getClientId()) != null) {
if(StringUtils.isNotEmpty(requestRemark)) {
my.setRequestRemark(requestRemark);
}
......@@ -109,12 +109,12 @@ public class ImFriendService extends BaseServiceImpl<ImFriendMapper, ImFriend> {
}
ImFriend friend = new ImFriend();
friend.setFkClientId(friendClient.getId());
friend.setFkClientIdFriend(currentClient.getId());
friend.setFkClientIdClaimer(currentClient.getId());
friend.setClientId(friendClient.getClientId());
friend.setClientIdFriend(currentClient.getClientId());
friend.setClientIdClaimer(currentClient.getClientId());
friend.setRequestRemark(requestRemark);
friend.setState(FriendStateEnum.UNSURE.getCode());
if(getByKey(friendClient.getId(), currentClient.getId()) != null) {
if(getByKey(friendClient.getClientId(), currentClient.getClientId()) != null) {
if(StringUtils.isNotEmpty(requestRemark)) {
friend.setRequestRemark(requestRemark);
}
......@@ -142,10 +142,10 @@ public class ImFriendService extends BaseServiceImpl<ImFriendMapper, ImFriend> {
* @param friendClientId
* @return
*/
public ImFriend getByKey(Long clientId, Long friendClientId) {
public ImFriend getByKey(String clientId, String friendClientId) {
return this.getOne(new QueryWrapper<ImFriend>().lambda()
.eq(ImFriend::getFkClientId, clientId)
.eq(ImFriend::getFkClientIdFriend, friendClientId));
.eq(ImFriend::getClientId, clientId)
.eq(ImFriend::getClientIdFriend, friendClientId));
}
/**
......@@ -157,9 +157,9 @@ public class ImFriendService extends BaseServiceImpl<ImFriendMapper, ImFriend> {
imFriend.setId(null);
imFriend.setCreateTime(null);
return this.update(imFriend, new QueryWrapper<ImFriend>().lambda()
.eq(ImFriend::getFkClientId, imFriend.getFkClientId())
.eq(ImFriend::getFkClientIdFriend, imFriend.getFkClientIdFriend())
.eq(ImFriend::getFkClientIdClaimer, imFriend.getFkClientIdClaimer()));
.eq(ImFriend::getClientId, imFriend.getClientId())
.eq(ImFriend::getClientIdFriend, imFriend.getClientIdFriend())
.eq(ImFriend::getClientIdClaimer, imFriend.getClientIdClaimer()));
}
/**
......@@ -177,9 +177,9 @@ public class ImFriendService extends BaseServiceImpl<ImFriendMapper, ImFriend> {
//好友关系有维护两条,我和他,他和我
//好友的先更新
ImFriend friend = new ImFriend();
friend.setFkClientId(friendClient.getId());
friend.setFkClientIdFriend(currentClient.getId());
friend.setFkClientIdClaimer(friendClient.getId());
friend.setClientId(friendClient.getClientId());
friend.setClientIdFriend(currentClient.getClientId());
friend.setClientIdClaimer(friendClient.getClientId());
friend.setState(agree ? FriendStateEnum.CONFORM.getCode() : FriendStateEnum.REJECT.getCode());
if(StringUtils.isNotEmpty(rejectRemark)) {
friend.setRejectRemark(rejectRemark);
......@@ -187,9 +187,9 @@ public class ImFriendService extends BaseServiceImpl<ImFriendMapper, ImFriend> {
boolean ok1 = this.updateByKeyAndClaimer(friend);
// 同时更新我的
ImFriend my = new ImFriend();
my.setFkClientId(currentClient.getId());
my.setFkClientIdFriend(friendClient.getId());
my.setFkClientIdClaimer(friendClient.getId());
my.setClientId(currentClient.getClientId());
my.setClientIdFriend(friendClient.getClientId());
my.setClientIdClaimer(friendClient.getClientId());
my.setState(agree ? FriendStateEnum.CONFORM.getCode() : FriendStateEnum.REJECT.getCode());
if(StringUtils.isNotEmpty(rejectRemark)) {
my.setRejectRemark(rejectRemark);
......@@ -205,7 +205,7 @@ public class ImFriendService extends BaseServiceImpl<ImFriendMapper, ImFriend> {
if(CollectionUtils.isEmpty(friendClientIds)) {
return;
}
imFriendMapper.batchDeleteFriend(currentClient.getId(), currentClient.getFkAppid(), friendClientIds);
imFriendMapper.batchDeleteFriend(currentClient.getClientId(), currentClient.getFkAppid(), friendClientIds);
}
public Paging<ImFriendBaseDto> getImFriendPageList(Long currentClientId, ImFriendPageParam pageParam) {
......@@ -224,7 +224,7 @@ public class ImFriendService extends BaseServiceImpl<ImFriendMapper, ImFriend> {
if(CollectionUtils.isEmpty(friendClientIds)) {
return;
}
imFriendRecommendMapper.batchDeleteRecommend(currentClient.getId(), currentClient.getFkAppid(), friendClientIds);
imFriendRecommendMapper.batchDeleteRecommend(currentClient.getClientId(), currentClient.getFkAppid(), friendClientIds);
}
/**
......@@ -242,28 +242,28 @@ public class ImFriendService extends BaseServiceImpl<ImFriendMapper, ImFriend> {
return;
}
//对已经存在的好友过滤掉
List<Long> maybeFriendIds = simpleFriendClients.stream().map(ImClientSimpleDto::getId).collect(Collectors.toList());
List<Long> alreadyFriendIds = imFriendMapper.filterNegativeFriends(currentClient.getId(), maybeFriendIds);
List<String> maybeFriendClientIds = simpleFriendClients.stream().map(ImClientSimpleDto::getClientId).collect(Collectors.toList());
List<String> alreadyFriendClientIds = imFriendMapper.filterNegativeFriends(currentClient.getClientId(), maybeFriendClientIds);
Map<String, Long> friendIdMap = simpleFriendClients.stream().collect(Collectors.toMap(ImClientSimpleDto::getClientId,
ImClientSimpleDto::getId, (a, b) -> a));
Map<String, String> friendClientIdMap = simpleFriendClients.stream().collect(Collectors.toMap(ImClientSimpleDto::getClientId,
ImClientSimpleDto::getClientId, (a, b) -> a));
List<ImFriendRecommend> list = new ArrayList<>();
for (ImFriendRecommendDto p : friends) {
Long fkFriendCliendId = friendIdMap.get(p.getFriendClientId());
String friendClientId = friendClientIdMap.get(p.getFriendClientId());
// 只有client存在的数据才是真数据
if(fkFriendCliendId == null) {
if(friendClientId == null) {
continue;
}
// 如果推荐的人已经是好友,则忽略。
if (alreadyFriendIds.contains(fkFriendCliendId)) {
if (alreadyFriendClientIds.contains(friendClientId)) {
continue;
}
ImFriendRecommend recommend = new ImFriendRecommend();
recommend.setId(SnowflakeUtil.getId());
recommend.setFkClientId(currentClient.getId());
recommend.setClientId(currentClient.getClientId());
recommend.setFkClientIdFriend(fkFriendCliendId);
recommend.setClientIdFriend(friendClientId);
recommend.setSource(p.getSource());
recommend.setDelFlag(false);
list.add(recommend);
......
......@@ -138,10 +138,10 @@ public interface ImClientService extends BaseService<ImClient> {
/**
* 获取client的简单对象,减少开销
* @param applicationId
* @param clientId
* @param clientIds
* @return
*/
List<ImClientSimpleDto> getSimpleClients(Long applicationId, List<String> clientId);
List<ImClientSimpleDto> getSimpleClients(Long applicationId, List<String> clientIds);
List<ImClientSimpleDto> getSimpleClients(List<Long> ids);
}
......@@ -167,7 +167,7 @@ public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClien
BeanUtils.copyProperties(infoList.get(0), clientInfoVo);
clientInfoVo.setRelation(RelationEnum.STRANGER.getCode());
// 查询该好友与自己关系: 陌生人、好友、被拉黑名单
ImFriend imFriend = imFriendService.getByKey(currentClient.getId(), clientInfoVo.getId());
ImFriend imFriend = imFriendService.getByKey(currentClient.getClientId(), clientInfoVo.getClientId());
if (imFriend != null && FriendStateEnum.CONFORM.getCode().equals(imFriend.getState())) {
clientInfoVo.setRelation(RelationEnum.FRIEND.getCode());
}
......@@ -303,14 +303,14 @@ public class ImClientServiceImpl extends BaseServiceImpl<ImClientMapper, ImClien
}
@Override
// @Cacheable(key = "#p0")
@Cacheable(key = "#p0")
public ImClient getCacheImClient(Long id) {
return imClientMapper.selectById(id);
}
@Override
public List<ImClientSimpleDto> getSimpleClients(Long applicationId, List<String> clientId) {
return imClientMapper.getSimpleClients(applicationId, clientId);
public List<ImClientSimpleDto> getSimpleClients(Long applicationId, List<String> clientIds) {
return imClientMapper.getSimpleClients(applicationId, clientIds);
}
@Override
......
......@@ -4,47 +4,47 @@
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, fk_client_id, fk_client_id_friend, friend_name,reject_remark,request_remark,state,create_time, update_time
id, client_id, client_id_friend, friend_name,reject_remark,request_remark,state,create_time, update_time
</sql>
<select id="getFriendInfo" resultType="com.wecloud.im.friend.param.ImFriendApplyDto">
select
friend.id, client.client_id as friendClientId, friend.friend_name, claimer.client_id as claimerClientId,
friend.reject_remark, friend.request_remark, friend.state, friend.create_time
from im_friend friend inner join im_client client on friend.fk_client_id_friend = client.id
inner join im_client claimer on friend.fk_client_id_claimer = claimer.id
where friend.fk_client_id = #{clientId} and fk_client_id_friend = #{friendClientId} and friend.state = 2
from im_friend friend inner join im_client client on friend.client_id_friend = client.client_id
inner join im_client claimer on friend.client_id_claimer = claimer.client_id
where friend.client_id = #{clientId} and client_id_friend = #{friendClientId} and friend.state = 2
</select>
<select id="getImFriendPageList" resultType="com.wecloud.im.friend.param.ImFriendBaseDto">
select
friend.id, client.client_id as friendClientId, friend.friend_name, friend.state
from im_friend friend inner join im_client client on friend.fk_client_id_friend = client.id
where friend.fk_client_id = #{clientId} and friend.state = 2
from im_friend friend inner join im_client client on friend.client_id_friend = client.client_id
where friend.client_id = #{clientId} and friend.state = 2
</select>
<select id="getUnsureFriendPageList" resultType="com.wecloud.im.friend.param.ImFriendApplyDto">
select
friend.id, client.client_id as friendClientId, friend.friend_name, claimer.client_id as claimerClientId,
friend.reject_remark, friend.request_remark, friend.state, friend.create_time
from im_friend friend inner join im_client client on friend.fk_client_id_friend = client.id
inner join im_client claimer on friend.fk_client_id_claimer = claimer.id
where friend.fk_client_id = #{clientId} and friend.state = 1
from im_friend friend inner join im_client client on friend.client_id_friend = client.client_id
inner join im_client claimer on friend.client_id_claimer = claimer.client_id
where friend.client_id = #{clientId} and friend.state = 1
</select>
<select id="filterNegativeFriends" resultType="java.lang.Long">
<select id="filterNegativeFriends" resultType="java.lang.String">
select
fk_client_id_friend
client_id_friend
from im_friend
where fk_client_id = #{clientId} and fk_client_id_friend in
where client_id = #{clientId} and client_id_friend in
<foreach collection="friendClientIds" item="friendClientId" open="(" close=")" separator=",">
#{friendClientId}
</foreach>
</select>
<update id="batchDeleteFriend">
update im_friend set state = 4 where fk_client_id = #{clientId} and fk_client_id_friend in (
select id from im_client where (fk_appid, client_id) in
update im_friend set state = 4 where client_id = #{clientId} and client_id_friend in (
select client_id from im_client where (fk_appid, client_id) in
<foreach collection="friendClientIds" item="friendClientId" open="(" close=")" separator=",">
(#{fkAppId}, #{friendClientId})
</foreach>
......
......@@ -4,30 +4,30 @@
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, fk_client_id, fk_client_id_friend, source, del_flag, create_time, update_time
id, client_id, client_id_friend, source, del_flag, create_time, update_time
</sql>
<select id="getImFriendRecommendPageList" resultType="com.wecloud.im.friend.param.ImFriendRecommendDto">
select
recommend.id, client.client_id as friendClientId, recommend.source, recommend.del_flag
from im_friend_recommend recommend inner join im_client client on recommend.fk_client_id_friend = client.id
where fk_client_id = #{clientId}
from im_friend_recommend recommend inner join im_client client on recommend.client_id_friend = client.client_id
where client_id = #{clientId}
</select>
<update id="batchDeleteRecommend">
update im_friend_recommend set del_flag = 1 where fk_client_id = #{clientId} and fk_client_id_friend in (
select id from im_client where (fk_appid, client_id) in
<foreach collection="friendClientIds" item="friendCLientId" open="(" close=")" separator=",">
(#{fkAppId}, #{friendCLientId})
update im_friend_recommend set del_flag = 1 where client_id = #{clientId} and client_id_friend in (
select client_id from im_client where (fk_appid, client_id) in
<foreach collection="friendClientIds" item="friendClientId" open="(" close=")" separator=",">
(#{fkAppId}, #{friendClientId})
</foreach>
)
</update>
<insert id="batchCreateRecommend" >
insert into im_friend_recommend(id, fk_client_id, fk_client_id_friend, source, del_flag, create_time)
insert into im_friend_recommend(id, client_id, client_id_friend, source, del_flag, create_time)
values
<foreach collection="list" item="item" separator=",">
(#{item.id},#{item.fkClientId},#{item.fkClientIdFriend},#{item.source},#{item.delFlag}, NOW())
(#{item.id},#{item.clientId},#{item.clientIdFriend},#{item.source},#{item.delFlag}, NOW())
</foreach>
ON DUPLICATE KEY UPDATE update_time = now()
</insert>
......
-- 在feature-cluster 2021年12月22日之后,需要执行的的sql增量脚本
-- 在feature-cluster 2021年12月22日之后,需要执行的的sql增量脚本
......@@ -33,9 +33,9 @@ CREATE TABLE `im_msg_read_lastest`
CREATE TABLE `im_friend`
(
`id` bigint NOT NULL COMMENT '主键id',
`fk_client_id` bigint NOT NULL COMMENT '自己id',
`fk_client_id_friend` bigint NOT NULL COMMENT '好友id',
`fk_client_id_claimer` bigint NOT NULL COMMENT '好友申请者',
`client_id` varchar(32) NOT NULL COMMENT '自己id',
`client_id_friend` varchar(32) NOT NULL COMMENT '好友id',
`client_id_claimer` varchar(32) NOT NULL COMMENT '好友申请者',
`friend_name` varchar(255) DEFAULT NULL COMMENT '好友名称备注',
`reject_remark` varchar(255) DEFAULT NULL COMMENT '拒绝说明',
`request_remark` varchar(255) DEFAULT NULL COMMENT '好友请求说明',
......@@ -49,8 +49,8 @@ CREATE TABLE `im_friend`
CREATE TABLE `im_friend_recommend`
(
`id` bigint(20) NOT NULL COMMENT '主键id',
`fk_client_id` bigint(20) NOT NULL COMMENT '自己id',
`fk_client_id_friend` bigint(20) NOT NULL COMMENT '好友id',
`client_id` varchar(32) NOT NULL COMMENT '自己id',
`client_id_friend` varchar(32) NOT NULL COMMENT '好友id',
`source` tinyint DEFAULT NULL COMMENT '推荐来源',
`del_flag` bit(1) NOT NULL default 0 COMMENT '删除标识',
`create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间',
......
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