mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-13 21:53:41 +08:00
fix:代码优化
This commit is contained in:
@@ -218,7 +218,8 @@ CREATE TABLE `user_apply` (
|
|||||||
`create_time` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT '创建时间',
|
`create_time` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT '创建时间',
|
||||||
`update_time` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT '修改时间',
|
`update_time` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT '修改时间',
|
||||||
PRIMARY KEY (`id`) USING BTREE,
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
KEY `idx_target_id_uid_status` (`target_id`,`uid`,`status`) USING BTREE,
|
KEY `idx_uid_target_id` (`uid`,`target_id`) USING BTREE,
|
||||||
|
KEY `idx_target_id_read_status` (`target_id`,`read_status`) USING BTREE,
|
||||||
KEY `idx_target_id` (`target_id`) USING BTREE,
|
KEY `idx_target_id` (`target_id`) USING BTREE,
|
||||||
KEY `idx_create_time` (`create_time`) USING BTREE,
|
KEY `idx_create_time` (`create_time`) USING BTREE,
|
||||||
KEY `idx_update_time` (`update_time`) USING BTREE
|
KEY `idx_update_time` (`update_time`) USING BTREE
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ public class RoomAppServiceImpl implements RoomAppService {
|
|||||||
public CursorPageBaseResp<ChatMemberResp> getMemberPage(MemberReq request) {
|
public CursorPageBaseResp<ChatMemberResp> getMemberPage(MemberReq request) {
|
||||||
Room room = roomCache.get(request.getRoomId());
|
Room room = roomCache.get(request.getRoomId());
|
||||||
AssertUtil.isNotEmpty(room, "房间号有误");
|
AssertUtil.isNotEmpty(room, "房间号有误");
|
||||||
List<Long> memberUidList = null;
|
List<Long> memberUidList;
|
||||||
if (isHotGroup(room)) {//全员群展示所有用户
|
if (isHotGroup(room)) {//全员群展示所有用户
|
||||||
memberUidList = null;
|
memberUidList = null;
|
||||||
} else {//只展示房间内的群成员
|
} else {//只展示房间内的群成员
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class CursorPageBaseReq {
|
|||||||
private String cursor;
|
private String cursor;
|
||||||
|
|
||||||
public Page plusPage() {
|
public Page plusPage() {
|
||||||
return new Page(1, this.pageSize);
|
return new Page(1, this.pageSize, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
|
|||||||
@@ -38,9 +38,13 @@ public abstract class AbstractRedisStringCache<IN, OUT> implements BatchCache<IN
|
|||||||
if (CollectionUtil.isEmpty(req)) {//防御性编程
|
if (CollectionUtil.isEmpty(req)) {//防御性编程
|
||||||
return new HashMap<>();
|
return new HashMap<>();
|
||||||
}
|
}
|
||||||
|
//去重
|
||||||
req = req.stream().distinct().collect(Collectors.toList());
|
req = req.stream().distinct().collect(Collectors.toList());
|
||||||
|
//组装key
|
||||||
List<String> keys = req.stream().map(this::getKey).collect(Collectors.toList());
|
List<String> keys = req.stream().map(this::getKey).collect(Collectors.toList());
|
||||||
|
//批量get
|
||||||
List<OUT> valueList = RedisUtils.mget(keys, outClass);
|
List<OUT> valueList = RedisUtils.mget(keys, outClass);
|
||||||
|
//差集计算
|
||||||
List<IN> loadReqs = new ArrayList<>();
|
List<IN> loadReqs = new ArrayList<>();
|
||||||
for (int i = 0; i < valueList.size(); i++) {
|
for (int i = 0; i < valueList.size(); i++) {
|
||||||
if (Objects.isNull(valueList.get(i))) {
|
if (Objects.isNull(valueList.get(i))) {
|
||||||
@@ -50,6 +54,7 @@ public abstract class AbstractRedisStringCache<IN, OUT> implements BatchCache<IN
|
|||||||
Map<IN, OUT> load = new HashMap<>();
|
Map<IN, OUT> load = new HashMap<>();
|
||||||
//不足的重新加载进redis
|
//不足的重新加载进redis
|
||||||
if (CollectionUtil.isNotEmpty(loadReqs)) {
|
if (CollectionUtil.isNotEmpty(loadReqs)) {
|
||||||
|
//批量load
|
||||||
load = load(loadReqs);
|
load = load(loadReqs);
|
||||||
Map<String, OUT> loadMap = load.entrySet().stream()
|
Map<String, OUT> loadMap = load.entrySet().stream()
|
||||||
.map(a -> Pair.of(getKey(a.getKey()), a.getValue()))
|
.map(a -> Pair.of(getKey(a.getKey()), a.getValue()))
|
||||||
|
|||||||
@@ -47,20 +47,25 @@ public class CursorUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <T> CursorPageBaseResp<T> getCursorPageByMysql(IService<T> mapper, CursorPageBaseReq request, Consumer<LambdaQueryWrapper<T>> initWrapper, SFunction<T, ?> cursorColumn) {
|
public static <T> CursorPageBaseResp<T> getCursorPageByMysql(IService<T> mapper, CursorPageBaseReq request, Consumer<LambdaQueryWrapper<T>> initWrapper, SFunction<T, ?> cursorColumn) {
|
||||||
|
//游标字段类型
|
||||||
Class<?> cursorType = LambdaUtils.getReturnType(cursorColumn);
|
Class<?> cursorType = LambdaUtils.getReturnType(cursorColumn);
|
||||||
LambdaQueryWrapper<T> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<T> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
//额外条件
|
||||||
initWrapper.accept(wrapper);
|
initWrapper.accept(wrapper);
|
||||||
|
//游标条件
|
||||||
if (StrUtil.isNotBlank(request.getCursor())) {
|
if (StrUtil.isNotBlank(request.getCursor())) {
|
||||||
wrapper.lt(cursorColumn, parseCursor(request.getCursor(), cursorType));
|
wrapper.lt(cursorColumn, parseCursor(request.getCursor(), cursorType));
|
||||||
}
|
}
|
||||||
|
//游标方向
|
||||||
wrapper.orderByDesc(cursorColumn);
|
wrapper.orderByDesc(cursorColumn);
|
||||||
Page pageReq = request.plusPage();
|
|
||||||
pageReq.setSearchCount(false);
|
Page<T> page = mapper.page(request.plusPage(), wrapper);
|
||||||
Page<T> page = mapper.page(pageReq, wrapper);
|
//取出游标
|
||||||
String cursor = Optional.ofNullable(CollectionUtil.getLast(page.getRecords()))
|
String cursor = Optional.ofNullable(CollectionUtil.getLast(page.getRecords()))
|
||||||
.map(cursorColumn)
|
.map(cursorColumn)
|
||||||
.map(CursorUtils::toCursor)
|
.map(CursorUtils::toCursor)
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
|
//判断是否最后一页
|
||||||
Boolean isLast = page.getRecords().size() != request.getPageSize();
|
Boolean isLast = page.getRecords().size() != request.getPageSize();
|
||||||
return new CursorPageBaseResp<>(cursor, isLast, page.getRecords());
|
return new CursorPageBaseResp<>(cursor, isLast, page.getRecords());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ import com.abin.mallchat.common.user.domain.vo.request.friend.FriendCheckReq;
|
|||||||
import com.abin.mallchat.common.user.domain.vo.request.friend.FriendDeleteReq;
|
import com.abin.mallchat.common.user.domain.vo.request.friend.FriendDeleteReq;
|
||||||
import com.abin.mallchat.common.user.domain.vo.response.friend.FriendApplyResp;
|
import com.abin.mallchat.common.user.domain.vo.response.friend.FriendApplyResp;
|
||||||
import com.abin.mallchat.common.user.domain.vo.response.friend.FriendCheckResp;
|
import com.abin.mallchat.common.user.domain.vo.response.friend.FriendCheckResp;
|
||||||
|
import com.abin.mallchat.common.user.domain.vo.response.friend.FriendResp;
|
||||||
import com.abin.mallchat.common.user.domain.vo.response.friend.FriendUnreadResp;
|
import com.abin.mallchat.common.user.domain.vo.response.friend.FriendUnreadResp;
|
||||||
import com.abin.mallchat.common.user.domain.vo.response.ws.ChatMemberResp;
|
|
||||||
import com.abin.mallchat.common.user.service.FriendService;
|
import com.abin.mallchat.common.user.service.FriendService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
@@ -78,7 +78,7 @@ public class FriendController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/apply")
|
@PutMapping("/apply")
|
||||||
@ApiOperation("审批申请")
|
@ApiOperation("审批同意")
|
||||||
public ApiResult<Void> applyApprove(@Valid @RequestBody FriendApproveReq request) {
|
public ApiResult<Void> applyApprove(@Valid @RequestBody FriendApproveReq request) {
|
||||||
friendService.applyApprove(RequestHolder.get().getUid(), request);
|
friendService.applyApprove(RequestHolder.get().getUid(), request);
|
||||||
return ApiResult.success();
|
return ApiResult.success();
|
||||||
@@ -86,7 +86,7 @@ public class FriendController {
|
|||||||
|
|
||||||
@GetMapping("/page")
|
@GetMapping("/page")
|
||||||
@ApiOperation("联系人列表")
|
@ApiOperation("联系人列表")
|
||||||
public ApiResult<CursorPageBaseResp<ChatMemberResp>> friendList(@Valid CursorPageBaseReq request) {
|
public ApiResult<CursorPageBaseResp<FriendResp>> friendList(@Valid CursorPageBaseReq request) {
|
||||||
Long uid = RequestHolder.get().getUid();
|
Long uid = RequestHolder.get().getUid();
|
||||||
return ApiResult.success(friendService.friendList(uid, request));
|
return ApiResult.success(friendService.friendList(uid, request));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,11 +60,10 @@ public class UserDao extends ServiceImpl<UserMapper, User> {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<User> getUserList(List<Long> uids) {
|
public List<User> getFriendList(List<Long> uids) {
|
||||||
return lambdaQuery()
|
return lambdaQuery()
|
||||||
.in(User::getId, uids)
|
.in(User::getId, uids)
|
||||||
.orderByDesc(User::getId)
|
.select(User::getId, User::getActiveStatus, User::getName, User::getAvatar)
|
||||||
.select(User::getId, User::getActiveStatus, User::getLastOptTime)
|
|
||||||
.list();
|
.list();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.abin.mallchat.common.user.domain.dto;
|
package com.abin.mallchat.common.user.domain.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@@ -18,6 +19,7 @@ import java.util.List;
|
|||||||
@Builder
|
@Builder
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
public class SummeryInfoDTO {
|
public class SummeryInfoDTO {
|
||||||
@ApiModelProperty(value = "用户id")
|
@ApiModelProperty(value = "用户id")
|
||||||
private Long uid;
|
private Long uid;
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package com.abin.mallchat.common.user.domain.entity;
|
package com.abin.mallchat.common.user.domain.entity;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
@@ -43,6 +40,13 @@ public class UserFriend implements Serializable {
|
|||||||
@TableField("friend_uid")
|
@TableField("friend_uid")
|
||||||
private Long friendUid;
|
private Long friendUid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 逻辑删除(0-正常,1-删除)
|
||||||
|
*/
|
||||||
|
@TableField("delete_status")
|
||||||
|
@TableLogic(value = "0", delval = "1")
|
||||||
|
private Integer deleteStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建时间
|
* 创建时间
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -18,7 +18,11 @@ import lombok.NoArgsConstructor;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class FriendResp {
|
public class FriendResp {
|
||||||
|
|
||||||
@ApiModelProperty("申请列表的未读数")
|
@ApiModelProperty("好友uid")
|
||||||
private Integer unReadCount;
|
private Long uid;
|
||||||
|
/**
|
||||||
|
* @see com.abin.mallchat.common.user.domain.enums.ChatActiveStatusEnum
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("在线状态 1在线 2离线")
|
||||||
|
private Integer activeStatus;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import com.abin.mallchat.common.user.domain.vo.request.friend.FriendApproveReq;
|
|||||||
import com.abin.mallchat.common.user.domain.vo.request.friend.FriendCheckReq;
|
import com.abin.mallchat.common.user.domain.vo.request.friend.FriendCheckReq;
|
||||||
import com.abin.mallchat.common.user.domain.vo.response.friend.FriendApplyResp;
|
import com.abin.mallchat.common.user.domain.vo.response.friend.FriendApplyResp;
|
||||||
import com.abin.mallchat.common.user.domain.vo.response.friend.FriendCheckResp;
|
import com.abin.mallchat.common.user.domain.vo.response.friend.FriendCheckResp;
|
||||||
|
import com.abin.mallchat.common.user.domain.vo.response.friend.FriendResp;
|
||||||
import com.abin.mallchat.common.user.domain.vo.response.friend.FriendUnreadResp;
|
import com.abin.mallchat.common.user.domain.vo.response.friend.FriendUnreadResp;
|
||||||
import com.abin.mallchat.common.user.domain.vo.response.ws.ChatMemberResp;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : limeng
|
* @author : limeng
|
||||||
@@ -69,5 +69,5 @@ public interface FriendService {
|
|||||||
*/
|
*/
|
||||||
void deleteFriend(Long uid, Long friendUid);
|
void deleteFriend(Long uid, Long friendUid);
|
||||||
|
|
||||||
CursorPageBaseResp<ChatMemberResp> friendList(Long uid, CursorPageBaseReq request);
|
CursorPageBaseResp<FriendResp> friendList(Long uid, CursorPageBaseReq request);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
package com.abin.mallchat.common.user.service.adapter;
|
package com.abin.mallchat.common.user.service.adapter;
|
||||||
|
|
||||||
|
import com.abin.mallchat.common.user.domain.entity.User;
|
||||||
import com.abin.mallchat.common.user.domain.entity.UserApply;
|
import com.abin.mallchat.common.user.domain.entity.UserApply;
|
||||||
|
import com.abin.mallchat.common.user.domain.entity.UserFriend;
|
||||||
import com.abin.mallchat.common.user.domain.vo.request.friend.FriendApplyReq;
|
import com.abin.mallchat.common.user.domain.vo.request.friend.FriendApplyReq;
|
||||||
import com.abin.mallchat.common.user.domain.vo.response.friend.FriendApplyResp;
|
import com.abin.mallchat.common.user.domain.vo.response.friend.FriendApplyResp;
|
||||||
|
import com.abin.mallchat.common.user.domain.vo.response.friend.FriendResp;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static com.abin.mallchat.common.user.domain.enums.ApplyReadStatusEnum.UNREAD;
|
import static com.abin.mallchat.common.user.domain.enums.ApplyReadStatusEnum.UNREAD;
|
||||||
@@ -41,4 +46,17 @@ public class FriendAdapter {
|
|||||||
return friendApplyResp;
|
return friendApplyResp;
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<FriendResp> buildFriend(List<UserFriend> list, List<User> userList) {
|
||||||
|
Map<Long, User> userMap = userList.stream().collect(Collectors.toMap(User::getId, user -> user));
|
||||||
|
return list.stream().map(userFriend -> {
|
||||||
|
FriendResp resp = new FriendResp();
|
||||||
|
resp.setUid(userFriend.getFriendUid());
|
||||||
|
User user = userMap.get(userFriend.getFriendUid());
|
||||||
|
if (Objects.nonNull(user)) {
|
||||||
|
resp.setActiveStatus(user.getActiveStatus());
|
||||||
|
}
|
||||||
|
return resp;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,15 +123,19 @@ public class UserCache {
|
|||||||
* 获取用户信息,盘路缓存模式
|
* 获取用户信息,盘路缓存模式
|
||||||
*/
|
*/
|
||||||
public Map<Long, User> getUserInfoBatch(Set<Long> uids) {
|
public Map<Long, User> getUserInfoBatch(Set<Long> uids) {
|
||||||
|
//批量组装key
|
||||||
List<String> keys = uids.stream().map(a -> RedisKey.getKey(RedisKey.USER_INFO_STRING, a)).collect(Collectors.toList());
|
List<String> keys = uids.stream().map(a -> RedisKey.getKey(RedisKey.USER_INFO_STRING, a)).collect(Collectors.toList());
|
||||||
|
//批量get
|
||||||
List<User> mget = RedisUtils.mget(keys, User.class);
|
List<User> mget = RedisUtils.mget(keys, User.class);
|
||||||
Map<Long, User> map = mget.stream().filter(Objects::nonNull).collect(Collectors.toMap(User::getId, Function.identity()));
|
Map<Long, User> map = mget.stream().filter(Objects::nonNull).collect(Collectors.toMap(User::getId, Function.identity()));
|
||||||
//还需要load更新的uid
|
//发现差集——还需要load更新的uid
|
||||||
List<Long> needLoadUidList = uids.stream().filter(a -> !map.containsKey(a)).collect(Collectors.toList());
|
List<Long> needLoadUidList = uids.stream().filter(a -> !map.containsKey(a)).collect(Collectors.toList());
|
||||||
if (CollUtil.isNotEmpty(needLoadUidList)) {
|
if (CollUtil.isNotEmpty(needLoadUidList)) {
|
||||||
|
//批量load
|
||||||
List<User> needLoadUserList = userDao.listByIds(needLoadUidList);
|
List<User> needLoadUserList = userDao.listByIds(needLoadUidList);
|
||||||
Map<String, User> redisMap = needLoadUserList.stream().collect(Collectors.toMap(a -> RedisKey.getKey(RedisKey.USER_INFO_STRING, a.getId()), Function.identity()));
|
Map<String, User> redisMap = needLoadUserList.stream().collect(Collectors.toMap(a -> RedisKey.getKey(RedisKey.USER_INFO_STRING, a.getId()), Function.identity()));
|
||||||
RedisUtils.mset(redisMap, 5 * 60);
|
RedisUtils.mset(redisMap, 5 * 60);
|
||||||
|
//加载回redis
|
||||||
map.putAll(needLoadUserList.stream().collect(Collectors.toMap(User::getId, Function.identity())));
|
map.putAll(needLoadUserList.stream().collect(Collectors.toMap(User::getId, Function.identity())));
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import com.abin.mallchat.common.chat.domain.entity.RoomFriend;
|
|||||||
import com.abin.mallchat.common.chat.service.ChatService;
|
import com.abin.mallchat.common.chat.service.ChatService;
|
||||||
import com.abin.mallchat.common.chat.service.ContactService;
|
import com.abin.mallchat.common.chat.service.ContactService;
|
||||||
import com.abin.mallchat.common.chat.service.RoomService;
|
import com.abin.mallchat.common.chat.service.RoomService;
|
||||||
import com.abin.mallchat.common.chat.service.adapter.MemberAdapter;
|
|
||||||
import com.abin.mallchat.common.chat.service.adapter.MessageAdapter;
|
import com.abin.mallchat.common.chat.service.adapter.MessageAdapter;
|
||||||
import com.abin.mallchat.common.common.annotation.RedissonLock;
|
import com.abin.mallchat.common.common.annotation.RedissonLock;
|
||||||
import com.abin.mallchat.common.common.domain.vo.request.CursorPageBaseReq;
|
import com.abin.mallchat.common.common.domain.vo.request.CursorPageBaseReq;
|
||||||
@@ -26,8 +25,8 @@ import com.abin.mallchat.common.user.domain.vo.request.friend.FriendApproveReq;
|
|||||||
import com.abin.mallchat.common.user.domain.vo.request.friend.FriendCheckReq;
|
import com.abin.mallchat.common.user.domain.vo.request.friend.FriendCheckReq;
|
||||||
import com.abin.mallchat.common.user.domain.vo.response.friend.FriendApplyResp;
|
import com.abin.mallchat.common.user.domain.vo.response.friend.FriendApplyResp;
|
||||||
import com.abin.mallchat.common.user.domain.vo.response.friend.FriendCheckResp;
|
import com.abin.mallchat.common.user.domain.vo.response.friend.FriendCheckResp;
|
||||||
|
import com.abin.mallchat.common.user.domain.vo.response.friend.FriendResp;
|
||||||
import com.abin.mallchat.common.user.domain.vo.response.friend.FriendUnreadResp;
|
import com.abin.mallchat.common.user.domain.vo.response.friend.FriendUnreadResp;
|
||||||
import com.abin.mallchat.common.user.domain.vo.response.ws.ChatMemberResp;
|
|
||||||
import com.abin.mallchat.common.user.service.FriendService;
|
import com.abin.mallchat.common.user.service.FriendService;
|
||||||
import com.abin.mallchat.common.user.service.adapter.FriendAdapter;
|
import com.abin.mallchat.common.user.service.adapter.FriendAdapter;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
@@ -138,12 +137,16 @@ public class FriendServiceImpl implements FriendService {
|
|||||||
return PageBaseResp.empty();
|
return PageBaseResp.empty();
|
||||||
}
|
}
|
||||||
//将这些申请列表设为已读
|
//将这些申请列表设为已读
|
||||||
|
readApples(uid, userApplyIPage);
|
||||||
|
//返回消息
|
||||||
|
return PageBaseResp.init(userApplyIPage, FriendAdapter.buildFriendApplyList(userApplyIPage.getRecords()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void readApples(Long uid, IPage<UserApply> userApplyIPage) {
|
||||||
List<Long> applyIds = userApplyIPage.getRecords()
|
List<Long> applyIds = userApplyIPage.getRecords()
|
||||||
.stream().map(UserApply::getId)
|
.stream().map(UserApply::getId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
userApplyDao.readApples(uid, applyIds);
|
userApplyDao.readApples(uid, applyIds);
|
||||||
//返回消息
|
|
||||||
return PageBaseResp.init(userApplyIPage, FriendAdapter.buildFriendApplyList(userApplyIPage.getRecords()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -171,9 +174,6 @@ public class FriendServiceImpl implements FriendService {
|
|||||||
createFriend(uid, userApply.getUid());
|
createFriend(uid, userApply.getUid());
|
||||||
//创建一个聊天房间
|
//创建一个聊天房间
|
||||||
RoomFriend roomFriend = roomService.createFriendRoom(Arrays.asList(uid, userApply.getUid()));
|
RoomFriend roomFriend = roomService.createFriendRoom(Arrays.asList(uid, userApply.getUid()));
|
||||||
// //创建双方的会话
|
|
||||||
// contactService.createContact(uid, roomFriend.getRoomId());
|
|
||||||
// contactService.createContact(userApply.getUid(), roomFriend.getRoomId());
|
|
||||||
//发送一条同意消息。。我们已经是好友了,开始聊天吧
|
//发送一条同意消息。。我们已经是好友了,开始聊天吧
|
||||||
chatService.sendMsg(MessageAdapter.buildAgreeMsg(roomFriend.getRoomId()), uid);
|
chatService.sendMsg(MessageAdapter.buildAgreeMsg(roomFriend.getRoomId()), uid);
|
||||||
}
|
}
|
||||||
@@ -199,7 +199,7 @@ public class FriendServiceImpl implements FriendService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CursorPageBaseResp<ChatMemberResp> friendList(Long uid, CursorPageBaseReq request) {
|
public CursorPageBaseResp<FriendResp> friendList(Long uid, CursorPageBaseReq request) {
|
||||||
CursorPageBaseResp<UserFriend> friendPage = userFriendDao.getFriendPage(uid, request);
|
CursorPageBaseResp<UserFriend> friendPage = userFriendDao.getFriendPage(uid, request);
|
||||||
if (CollectionUtils.isEmpty(friendPage.getList())) {
|
if (CollectionUtils.isEmpty(friendPage.getList())) {
|
||||||
return CursorPageBaseResp.empty();
|
return CursorPageBaseResp.empty();
|
||||||
@@ -207,8 +207,8 @@ public class FriendServiceImpl implements FriendService {
|
|||||||
List<Long> friendUids = friendPage.getList()
|
List<Long> friendUids = friendPage.getList()
|
||||||
.stream().map(UserFriend::getFriendUid)
|
.stream().map(UserFriend::getFriendUid)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
List<User> userList = userDao.getUserList(friendUids);
|
List<User> userList = userDao.getFriendList(friendUids);
|
||||||
return CursorPageBaseResp.init(friendPage, MemberAdapter.buildMember(friendPage.getList(), userList));
|
return CursorPageBaseResp.init(friendPage, FriendAdapter.buildFriend(friendPage.getList(), userList));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createFriend(Long uid, Long targetUid) {
|
private void createFriend(Long uid, Long targetUid) {
|
||||||
|
|||||||
@@ -167,16 +167,16 @@ public class UserServiceImpl implements UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<Long> getNeedSyncUidList(List<SummeryInfoReq.infoReq> reqList) {
|
private List<Long> getNeedSyncUidList(List<SummeryInfoReq.infoReq> reqList) {
|
||||||
List<Long> result = new ArrayList<>();
|
List<Long> needSyncUidList = new ArrayList<>();
|
||||||
List<Long> userModifyTime = userCache.getUserModifyTime(reqList.stream().map(SummeryInfoReq.infoReq::getUid).collect(Collectors.toList()));
|
List<Long> userModifyTime = userCache.getUserModifyTime(reqList.stream().map(SummeryInfoReq.infoReq::getUid).collect(Collectors.toList()));
|
||||||
for (int i = 0; i < reqList.size(); i++) {
|
for (int i = 0; i < reqList.size(); i++) {
|
||||||
SummeryInfoReq.infoReq infoReq = reqList.get(i);
|
SummeryInfoReq.infoReq infoReq = reqList.get(i);
|
||||||
Long modifyTime = userModifyTime.get(i);
|
Long modifyTime = userModifyTime.get(i);
|
||||||
if (Objects.isNull(infoReq.getLastModifyTime()) || (Objects.nonNull(modifyTime) && modifyTime > infoReq.getLastModifyTime())) {
|
if (Objects.isNull(infoReq.getLastModifyTime()) || (Objects.nonNull(modifyTime) && modifyTime > infoReq.getLastModifyTime())) {
|
||||||
result.add(infoReq.getUid());
|
needSyncUidList.add(infoReq.getUid());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return needSyncUidList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void blackIp(String ip) {
|
public void blackIp(String ip) {
|
||||||
|
|||||||
Reference in New Issue
Block a user