mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-14 06:03:42 +08:00
加好友功能
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
package com.abin.mallchat.common.user.domain.enums;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : limeng
|
||||||
|
* @description : 申请阅读状态枚举
|
||||||
|
* @date : 2023/07/20
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum ApplyReadStatusEnum {
|
||||||
|
|
||||||
|
UNREAD(1, "未读"),
|
||||||
|
|
||||||
|
READ(2, "已读");
|
||||||
|
|
||||||
|
private final Integer code;
|
||||||
|
|
||||||
|
private final String desc;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.abin.mallchat.common.user.domain.enums;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : limeng
|
||||||
|
* @description : 申请状态枚举
|
||||||
|
* @date : 2023/07/20
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum ApplyStatusEnum {
|
||||||
|
|
||||||
|
WAIT_APPROVAL(1, "待审批"),
|
||||||
|
|
||||||
|
AGREE(2, "同意");
|
||||||
|
|
||||||
|
private final Integer code;
|
||||||
|
|
||||||
|
private final String desc;
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.abin.mallchat.common.user.domain.enums;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : limeng
|
||||||
|
* @description : 申请类型枚举
|
||||||
|
* @date : 2023/07/20
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum ApplyTypeEnum {
|
||||||
|
|
||||||
|
ADD_FRIEND(1, "加好友");
|
||||||
|
|
||||||
|
|
||||||
|
private final Integer code;
|
||||||
|
|
||||||
|
private final String desc;
|
||||||
|
}
|
||||||
@@ -12,9 +12,9 @@ mallchat.redis.password=123456
|
|||||||
##################jwt##################
|
##################jwt##################
|
||||||
mallchat.jwt.secret=dsfsdfsdfsdfsd
|
mallchat.jwt.secret=dsfsdfsdfsdfsd
|
||||||
##################微信公众号信息##################
|
##################微信公众号信息##################
|
||||||
mallchat.wx.callback=http://127.0.0.1:8080
|
mallchat.wx.callback=http://limeng-test.nat300.top/
|
||||||
mallchat.wx.appId=appid
|
mallchat.wx.appId=wx6cb0974bff30cce0
|
||||||
mallchat.wx.secret=380bfc1c9147fdsf4sf07
|
mallchat.wx.secret=072c615d9704d2e9bf0a048407928258
|
||||||
# 接口配置里的Token值
|
# 接口配置里的Token值
|
||||||
mallchat.wx.token=sdfsf
|
mallchat.wx.token=sdfsf
|
||||||
# 接口配置里的EncodingAESKey值
|
# 接口配置里的EncodingAESKey值
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ mybatis-plus:
|
|||||||
spring:
|
spring:
|
||||||
profiles:
|
profiles:
|
||||||
#运行的环境
|
#运行的环境
|
||||||
active: my-prod
|
active: test
|
||||||
application:
|
application:
|
||||||
name: mallchat
|
name: mallchat
|
||||||
datasource:
|
datasource:
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,6 +26,9 @@ public class ChatMessageResp {
|
|||||||
@ApiModelProperty("消息详情")
|
@ApiModelProperty("消息详情")
|
||||||
private Message message;
|
private Message message;
|
||||||
|
|
||||||
|
@ApiModelProperty("申请消息")
|
||||||
|
private ApplyMessage applyMessage;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public static class UserInfo {
|
public static class UserInfo {
|
||||||
@ApiModelProperty("用户id")
|
@ApiModelProperty("用户id")
|
||||||
@@ -55,4 +60,18 @@ public class ChatMessageResp {
|
|||||||
@ApiModelProperty("该用户是否已经举报 0否 1是")
|
@ApiModelProperty("该用户是否已经举报 0否 1是")
|
||||||
private Integer userDislike;
|
private Integer userDislike;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class ApplyMessage {
|
||||||
|
@ApiModelProperty("申请id")
|
||||||
|
private Long applyId;
|
||||||
|
|
||||||
|
@ApiModelProperty("申请信息")
|
||||||
|
private String applyMsg;
|
||||||
|
|
||||||
|
@ApiModelProperty("申请发送时间")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
|
||||||
|
private LocalDateTime sendTime;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,19 @@ import com.abin.mallchat.common.chat.domain.entity.MessageMark;
|
|||||||
import com.abin.mallchat.common.chat.domain.enums.MessageMarkTypeEnum;
|
import com.abin.mallchat.common.chat.domain.enums.MessageMarkTypeEnum;
|
||||||
import com.abin.mallchat.common.chat.domain.enums.MessageStatusEnum;
|
import com.abin.mallchat.common.chat.domain.enums.MessageStatusEnum;
|
||||||
import com.abin.mallchat.common.common.domain.enums.YesOrNoEnum;
|
import com.abin.mallchat.common.common.domain.enums.YesOrNoEnum;
|
||||||
|
import com.abin.mallchat.common.user.domain.entity.UserApply;
|
||||||
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessageReq;
|
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessageReq;
|
||||||
import com.abin.mallchat.custom.chat.domain.vo.response.ChatMessageResp;
|
import com.abin.mallchat.custom.chat.domain.vo.response.ChatMessageResp;
|
||||||
import com.abin.mallchat.custom.chat.service.strategy.msg.AbstractMsgHandler;
|
import com.abin.mallchat.custom.chat.service.strategy.msg.AbstractMsgHandler;
|
||||||
import com.abin.mallchat.custom.chat.service.strategy.msg.MsgHandlerFactory;
|
import com.abin.mallchat.custom.chat.service.strategy.msg.MsgHandlerFactory;
|
||||||
|
import com.abin.mallchat.custom.user.domain.vo.response.ws.WSApplyMessage;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -76,5 +83,20 @@ public class MessageAdapter {
|
|||||||
return userInfo;
|
return userInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static WSApplyMessage buildApplyResp(UserApply userApply) {
|
||||||
|
WSApplyMessage wsApplyMessage = new WSApplyMessage();
|
||||||
|
wsApplyMessage.setApplyMessage(buildApplyMessage(userApply));
|
||||||
|
wsApplyMessage.setFromUser(buildFromUser(userApply.getUid()));
|
||||||
|
return wsApplyMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ChatMessageResp.ApplyMessage buildApplyMessage(UserApply userApply) {
|
||||||
|
ChatMessageResp.ApplyMessage applyMessage = new ChatMessageResp.ApplyMessage();
|
||||||
|
applyMessage.setApplyId(userApply.getId());
|
||||||
|
applyMessage.setApplyMsg(userApply.getMsg());
|
||||||
|
applyMessage.setSendTime(userApply.getCreateTime());
|
||||||
|
return applyMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.abin.mallchat.custom.chat.service.adapter;
|
package com.abin.mallchat.custom.chat.service.adapter;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import com.abin.mallchat.common.chat.domain.entity.Room;
|
||||||
import com.abin.mallchat.custom.chat.domain.vo.response.ChatRoomResp;
|
import com.abin.mallchat.custom.chat.domain.vo.response.ChatRoomResp;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@@ -17,12 +17,14 @@ import com.abin.mallchat.custom.user.domain.vo.request.friend.FriendDeleteReq;
|
|||||||
import com.abin.mallchat.custom.user.domain.vo.response.friend.FriendApplyResp;
|
import com.abin.mallchat.custom.user.domain.vo.response.friend.FriendApplyResp;
|
||||||
import com.abin.mallchat.custom.user.domain.vo.response.friend.FriendCheckResp;
|
import com.abin.mallchat.custom.user.domain.vo.response.friend.FriendCheckResp;
|
||||||
import com.abin.mallchat.custom.user.domain.vo.response.friend.FriendUnreadResp;
|
import com.abin.mallchat.custom.user.domain.vo.response.friend.FriendUnreadResp;
|
||||||
|
import com.abin.mallchat.custom.user.service.FriendService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,50 +45,57 @@ public class FriendController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private UserCache userCache;
|
private UserCache userCache;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private FriendService friendService;
|
||||||
|
|
||||||
@GetMapping("/check")
|
@GetMapping("/check")
|
||||||
@ApiOperation("批量判断是否是自己好友")
|
@ApiOperation("批量判断是否是自己好友")
|
||||||
public ApiResult<FriendCheckResp> check(@Valid FriendCheckReq request) {//todo
|
public ApiResult<FriendCheckResp> check(@Valid FriendCheckReq request) {
|
||||||
return ApiResult.success();
|
Long uid = RequestHolder.get().getUid();
|
||||||
|
return ApiResult.success(friendService.check(uid, request));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/apply")
|
@PostMapping("/apply")
|
||||||
@ApiOperation("申请好友")
|
@ApiOperation("申请好友")
|
||||||
public ApiResult<Void> apply(@Valid @RequestBody FriendApplyReq request) {//todo
|
public ApiResult<Void> apply(@Valid @RequestBody FriendApplyReq request) {
|
||||||
Long uid = RequestHolder.get().getUid();
|
Long uid = RequestHolder.get().getUid();
|
||||||
|
friendService.apply(uid, request);
|
||||||
return ApiResult.success();
|
return ApiResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping()
|
@DeleteMapping()
|
||||||
@ApiOperation("删除好友")
|
@ApiOperation("删除好友")
|
||||||
public ApiResult<Void> delete(@Valid @RequestBody FriendDeleteReq request) {//todo
|
public ApiResult<Void> delete(@Valid @RequestBody FriendDeleteReq request) {
|
||||||
|
//todo
|
||||||
Long uid = RequestHolder.get().getUid();
|
Long uid = RequestHolder.get().getUid();
|
||||||
return ApiResult.success();
|
return ApiResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/apply/page")
|
@GetMapping("/apply/page")
|
||||||
@ApiOperation("好友申请列表")
|
@ApiOperation("好友申请列表")
|
||||||
public ApiResult<PageBaseResp<FriendApplyResp>> page(@Valid PageBaseReq request) {//todo
|
public ApiResult<PageBaseResp<FriendApplyResp>> page(@Valid PageBaseReq request) {
|
||||||
Long uid = RequestHolder.get().getUid();
|
Long uid = RequestHolder.get().getUid();
|
||||||
return ApiResult.success();
|
return ApiResult.success(friendService.pageApplyFriend(uid, request));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/apply/unread")
|
@GetMapping("/apply/unread")
|
||||||
@ApiOperation("申请未读数")
|
@ApiOperation("申请未读数")
|
||||||
public ApiResult<FriendUnreadResp> unread() {//todo
|
public ApiResult<FriendUnreadResp> unread() {
|
||||||
Long uid = RequestHolder.get().getUid();
|
Long uid = RequestHolder.get().getUid();
|
||||||
return ApiResult.success();
|
return ApiResult.success(friendService.unread(uid));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/apply")
|
@PutMapping("/apply")
|
||||||
@ApiOperation("申请审批")
|
@ApiOperation("申请审批")
|
||||||
public ApiResult<Void> applyApprove(@Valid @RequestBody FriendApproveReq request) {//todo
|
public ApiResult<Void> applyApprove(@Valid @RequestBody FriendApproveReq request) {
|
||||||
Long uid = RequestHolder.get().getUid();
|
friendService.applyApprove(request);
|
||||||
return ApiResult.success();
|
return ApiResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/page")
|
@PutMapping("/page")
|
||||||
@ApiOperation("联系人列表")
|
@ApiOperation("联系人列表")
|
||||||
public ApiResult<CursorPageBaseResp<ChatMemberResp>> applyApprove(@Valid CursorPageBaseReq request) {//todo
|
public ApiResult<CursorPageBaseResp<ChatMemberResp>> applyApprove(@Valid CursorPageBaseReq request) {
|
||||||
|
//todo
|
||||||
Long uid = RequestHolder.get().getUid();
|
Long uid = RequestHolder.get().getUid();
|
||||||
return ApiResult.success();
|
return ApiResult.success();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ public enum WSRespTypeEnum {
|
|||||||
BLACK(7, "拉黑用户", WSBlack.class),
|
BLACK(7, "拉黑用户", WSBlack.class),
|
||||||
MARK(8, "消息标记", WSMsgMark.class),
|
MARK(8, "消息标记", WSMsgMark.class),
|
||||||
RECALL(9, "消息撤回", WSMsgRecall.class),
|
RECALL(9, "消息撤回", WSMsgRecall.class),
|
||||||
|
APPLY(10,"好友申请", WSApplyMessage.class),
|
||||||
;
|
;
|
||||||
|
|
||||||
private final Integer type;
|
private final Integer type;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import javax.validation.constraints.NotNull;
|
|||||||
public class FriendApproveReq {
|
public class FriendApproveReq {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ApiModelProperty("审批动作 2同意")
|
@ApiModelProperty("申请id")
|
||||||
private Integer approveStatus;
|
private Long applyId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,6 @@ public class FriendApplyResp {
|
|||||||
@ApiModelProperty("申请信息")
|
@ApiModelProperty("申请信息")
|
||||||
private String msg;
|
private String msg;
|
||||||
|
|
||||||
@ApiModelProperty("申请状态 1待审批 2同意")//todo 自己去加枚举
|
@ApiModelProperty("申请状态 1待审批 2同意")
|
||||||
private Integer status;
|
private Integer status;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.abin.mallchat.custom.user.domain.vo.response.ws;
|
||||||
|
|
||||||
|
import com.abin.mallchat.custom.chat.domain.vo.response.ChatMessageResp;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : limeng
|
||||||
|
* @description : 好友申请消息推送
|
||||||
|
* @date : 2023/07/21
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class WSApplyMessage extends ChatMessageResp {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.abin.mallchat.custom.user.service;
|
||||||
|
|
||||||
|
import com.abin.mallchat.common.common.domain.vo.request.PageBaseReq;
|
||||||
|
import com.abin.mallchat.common.common.domain.vo.response.PageBaseResp;
|
||||||
|
import com.abin.mallchat.custom.user.domain.vo.request.friend.FriendApplyReq;
|
||||||
|
import com.abin.mallchat.custom.user.domain.vo.request.friend.FriendApproveReq;
|
||||||
|
import com.abin.mallchat.custom.user.domain.vo.request.friend.FriendCheckReq;
|
||||||
|
import com.abin.mallchat.custom.user.domain.vo.response.friend.FriendApplyResp;
|
||||||
|
import com.abin.mallchat.custom.user.domain.vo.response.friend.FriendCheckResp;
|
||||||
|
import com.abin.mallchat.custom.user.domain.vo.response.friend.FriendUnreadResp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : limeng
|
||||||
|
* @description : 好友
|
||||||
|
* @date : 2023/07/19
|
||||||
|
*/
|
||||||
|
public interface FriendService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查
|
||||||
|
* 检查是否是自己好友
|
||||||
|
*
|
||||||
|
* @param request 请求
|
||||||
|
* @param uid uid
|
||||||
|
* @return {@link FriendCheckResp}
|
||||||
|
*/
|
||||||
|
FriendCheckResp check(Long uid, FriendCheckReq request);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用
|
||||||
|
* 申请好友
|
||||||
|
*
|
||||||
|
* @param request 请求
|
||||||
|
* @param uid uid
|
||||||
|
*/
|
||||||
|
void apply(Long uid, FriendApplyReq request);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询好友申请
|
||||||
|
*
|
||||||
|
* @param request 请求
|
||||||
|
* @return {@link PageBaseResp}<{@link FriendApplyResp}>
|
||||||
|
*/
|
||||||
|
PageBaseResp<FriendApplyResp> pageApplyFriend(Long uid, PageBaseReq request);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 申请未读数
|
||||||
|
*
|
||||||
|
* @return {@link FriendUnreadResp}
|
||||||
|
*/
|
||||||
|
FriendUnreadResp unread(Long uid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同意好友申请
|
||||||
|
*
|
||||||
|
* @param uid uid
|
||||||
|
* @param request 请求
|
||||||
|
*/
|
||||||
|
void applyApprove(FriendApproveReq request);
|
||||||
|
}
|
||||||
@@ -66,5 +66,7 @@ public interface WebSocketService {
|
|||||||
*/
|
*/
|
||||||
void sendToAllOnline(WSBaseResp<?> wsBaseResp);
|
void sendToAllOnline(WSBaseResp<?> wsBaseResp);
|
||||||
|
|
||||||
|
void sendToFriend(WSBaseResp<?> wsBaseResp, Long friendUid);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,4 +132,11 @@ public class WSAdapter {
|
|||||||
wsBaseResp.setData(mark);
|
wsBaseResp.setData(mark);
|
||||||
return wsBaseResp;
|
return wsBaseResp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static WSBaseResp<WSApplyMessage> buildApplySend(WSApplyMessage resp) {
|
||||||
|
WSBaseResp<WSApplyMessage> wsBaseResp = new WSBaseResp<>();
|
||||||
|
wsBaseResp.setType(WSRespTypeEnum.APPLY.getType());
|
||||||
|
wsBaseResp.setData(resp);
|
||||||
|
return wsBaseResp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,172 @@
|
|||||||
|
package com.abin.mallchat.custom.user.service.impl;
|
||||||
|
|
||||||
|
import com.abin.mallchat.common.common.domain.vo.request.PageBaseReq;
|
||||||
|
import com.abin.mallchat.common.common.domain.vo.response.PageBaseResp;
|
||||||
|
import com.abin.mallchat.common.user.domain.entity.UserApply;
|
||||||
|
import com.abin.mallchat.common.user.domain.entity.UserFriend;
|
||||||
|
import com.abin.mallchat.common.user.service.IUserApplyService;
|
||||||
|
import com.abin.mallchat.common.user.service.IUserFriendService;
|
||||||
|
import com.abin.mallchat.custom.chat.service.adapter.MessageAdapter;
|
||||||
|
import com.abin.mallchat.custom.user.domain.vo.request.friend.FriendApplyReq;
|
||||||
|
import com.abin.mallchat.custom.user.domain.vo.request.friend.FriendApproveReq;
|
||||||
|
import com.abin.mallchat.custom.user.domain.vo.request.friend.FriendCheckReq;
|
||||||
|
import com.abin.mallchat.custom.user.domain.vo.response.friend.FriendApplyResp;
|
||||||
|
import com.abin.mallchat.custom.user.domain.vo.response.friend.FriendCheckResp;
|
||||||
|
import com.abin.mallchat.custom.user.domain.vo.response.friend.FriendUnreadResp;
|
||||||
|
import com.abin.mallchat.custom.user.domain.vo.response.ws.WSApplyMessage;
|
||||||
|
import com.abin.mallchat.custom.user.service.FriendService;
|
||||||
|
import com.abin.mallchat.custom.user.service.WebSocketService;
|
||||||
|
import com.abin.mallchat.custom.user.service.adapter.WSAdapter;
|
||||||
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
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.ApplyStatusEnum.AGREE;
|
||||||
|
import static com.abin.mallchat.common.user.domain.enums.ApplyStatusEnum.WAIT_APPROVAL;
|
||||||
|
import static com.abin.mallchat.common.user.domain.enums.ApplyTypeEnum.ADD_FRIEND;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : limeng
|
||||||
|
* @description : 好友
|
||||||
|
* @date : 2023/07/19
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class FriendServiceImpl implements FriendService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IUserFriendService friendService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IUserApplyService applyService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private WebSocketService webSocketService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查
|
||||||
|
* 检查是否是自己好友
|
||||||
|
*
|
||||||
|
* @param uid uid
|
||||||
|
* @param request 请求
|
||||||
|
* @return {@link FriendCheckResp}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public FriendCheckResp check(Long uid, FriendCheckReq request) {
|
||||||
|
LambdaQueryChainWrapper<UserFriend> wrapper = friendService.lambdaQuery();
|
||||||
|
wrapper.eq(UserFriend::getUid, uid)
|
||||||
|
.in(UserFriend::getFriendUid, request.getUidList());
|
||||||
|
List<UserFriend> friendList = friendService.list(wrapper);
|
||||||
|
Map<Long, UserFriend> friendMap = friendList.stream().collect(Collectors.toMap(UserFriend::getFriendUid, friend -> friend));
|
||||||
|
List<FriendCheckResp.FriendCheck> friendCheckList = request.getUidList().stream().map(friendUid -> {
|
||||||
|
FriendCheckResp.FriendCheck friendCheck = new FriendCheckResp.FriendCheck();
|
||||||
|
friendCheck.setUid(friendUid);
|
||||||
|
friendCheck.setIsFriend(friendMap.containsKey(friendUid));
|
||||||
|
return friendCheck;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
return new FriendCheckResp(friendCheckList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 申请好友
|
||||||
|
*
|
||||||
|
* @param request 请求
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void apply(Long uid, FriendApplyReq request) {
|
||||||
|
LambdaQueryChainWrapper<UserApply> wrapper = applyService.lambdaQuery();
|
||||||
|
wrapper.eq(UserApply::getUid, uid)
|
||||||
|
.eq(UserApply::getTargetId, request.getTargetUid());
|
||||||
|
UserApply userApply = applyService.getOne(wrapper);
|
||||||
|
if (Objects.nonNull(userApply)) {
|
||||||
|
log.info("已有好友申请记录,uid:{}, targetId:{}", uid, request.getTargetUid());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
UserApply userApplyNew = new UserApply();
|
||||||
|
userApplyNew.setUid(uid);
|
||||||
|
userApplyNew.setMsg(request.getMsg());
|
||||||
|
userApplyNew.setType(ADD_FRIEND.getCode());
|
||||||
|
userApplyNew.setTargetId(request.getTargetUid());
|
||||||
|
userApplyNew.setStatus(WAIT_APPROVAL.getCode());
|
||||||
|
userApplyNew.setReadStatus(UNREAD.getCode());
|
||||||
|
applyService.save(userApplyNew);
|
||||||
|
|
||||||
|
WSApplyMessage applyMessage = MessageAdapter.buildApplyResp(userApplyNew);
|
||||||
|
webSocketService.sendToFriend(WSAdapter.buildApplySend(applyMessage), request.getTargetUid());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询好友申请
|
||||||
|
*
|
||||||
|
* @param request 请求
|
||||||
|
* @return {@link PageBaseResp}<{@link FriendApplyResp}>
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PageBaseResp<FriendApplyResp> pageApplyFriend(Long uid, PageBaseReq request) {
|
||||||
|
// todo 分页
|
||||||
|
LambdaQueryChainWrapper<UserApply> wrapper = applyService.lambdaQuery();
|
||||||
|
wrapper.eq(UserApply::getUid, uid)
|
||||||
|
.or()
|
||||||
|
.eq(UserApply::getTargetId, uid);
|
||||||
|
List<UserApply> userApplyList = applyService.list(wrapper);
|
||||||
|
List<FriendApplyResp> friendApplyResps = userApplyList.stream().map(userApply -> {
|
||||||
|
FriendApplyResp friendApplyResp = new FriendApplyResp();
|
||||||
|
friendApplyResp.setUid(userApply.getUid());
|
||||||
|
friendApplyResp.setType(userApply.getType());
|
||||||
|
friendApplyResp.setMsg(userApply.getMsg());
|
||||||
|
friendApplyResp.setStatus(userApply.getStatus());
|
||||||
|
return friendApplyResp;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
PageBaseResp<FriendApplyResp> pageBaseResp = new PageBaseResp<>();
|
||||||
|
pageBaseResp.setList(friendApplyResps);
|
||||||
|
return pageBaseResp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 申请未读数
|
||||||
|
*
|
||||||
|
* @return {@link FriendUnreadResp}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public FriendUnreadResp unread(Long uid) {
|
||||||
|
LambdaQueryChainWrapper<UserApply> wrapper = applyService.lambdaQuery();
|
||||||
|
wrapper.eq(UserApply::getTargetId, uid)
|
||||||
|
.eq(UserApply::getReadStatus, UNREAD.getCode());
|
||||||
|
return new FriendUnreadResp(applyService.count(wrapper));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void applyApprove(FriendApproveReq request) {
|
||||||
|
UserApply userApply = applyService.getById(request.getApplyId());
|
||||||
|
if (Objects.isNull(userApply)) {
|
||||||
|
log.error("不存在申请记录:{}", request.getApplyId());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Objects.equals(userApply.getStatus(), AGREE.getCode())) {
|
||||||
|
log.error("已同意好友申请:{}", request.getApplyId());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LambdaUpdateChainWrapper<UserApply> updateWrapper = applyService.lambdaUpdate();
|
||||||
|
updateWrapper.set(UserApply::getStatus, AGREE.getCode())
|
||||||
|
.eq(UserApply::getId, request.getApplyId());
|
||||||
|
applyService.update(updateWrapper);
|
||||||
|
UserFriend userFriend1 = new UserFriend();
|
||||||
|
userFriend1.setUid(userApply.getUid());
|
||||||
|
userFriend1.setFriendUid(userApply.getTargetId());
|
||||||
|
UserFriend userFriend2 = new UserFriend();
|
||||||
|
userFriend2.setUid(userApply.getTargetId());
|
||||||
|
userFriend2.setFriendUid(userApply.getUid());
|
||||||
|
friendService.saveBatch(Lists.newArrayList(userFriend1, userFriend2));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -257,6 +257,16 @@ public class WebSocketServiceImpl implements WebSocketService {
|
|||||||
sendToAllOnline(wsBaseResp, null);
|
sendToAllOnline(wsBaseResp, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendToFriend(WSBaseResp<?> wsBaseResp, Long friendUid) {
|
||||||
|
CopyOnWriteArrayList<Channel> channels = ONLINE_UID_MAP.get(friendUid);
|
||||||
|
if (CollectionUtil.isEmpty(channels)) {
|
||||||
|
log.info("用户:{}不在线", friendUid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
threadPoolTaskExecutor.execute(() -> sendMsg(channels.get(0), wsBaseResp));
|
||||||
|
}
|
||||||
|
|
||||||
private void sendMsg(Channel channel, WSBaseResp<?> wsBaseResp) {
|
private void sendMsg(Channel channel, WSBaseResp<?> wsBaseResp) {
|
||||||
channel.writeAndFlush(new TextWebSocketFrame(JSONUtil.toJsonStr(wsBaseResp)));
|
channel.writeAndFlush(new TextWebSocketFrame(JSONUtil.toJsonStr(wsBaseResp)));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user