mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-25 07:33:49 +08:00
sql迁移持久层
This commit is contained in:
@@ -3,9 +3,16 @@ package com.abin.mallchat.common.user.dao;
|
|||||||
import com.abin.mallchat.common.user.domain.entity.UserApply;
|
import com.abin.mallchat.common.user.domain.entity.UserApply;
|
||||||
import com.abin.mallchat.common.user.mapper.UserApplyMapper;
|
import com.abin.mallchat.common.user.mapper.UserApplyMapper;
|
||||||
import com.abin.mallchat.common.user.service.IUserApplyService;
|
import com.abin.mallchat.common.user.service.IUserApplyService;
|
||||||
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.abin.mallchat.common.user.domain.enums.ApplyReadStatusEnum.UNREAD;
|
||||||
|
import static com.abin.mallchat.common.user.domain.enums.ApplyStatusEnum.AGREE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 用户申请表 服务实现类
|
* 用户申请表 服务实现类
|
||||||
@@ -17,4 +24,40 @@ import org.springframework.stereotype.Service;
|
|||||||
@Service
|
@Service
|
||||||
public class UserApplyDao extends ServiceImpl<UserApplyMapper, UserApply> implements IUserApplyService {
|
public class UserApplyDao extends ServiceImpl<UserApplyMapper, UserApply> implements IUserApplyService {
|
||||||
|
|
||||||
|
public UserApply queryUserApply(Long uid, Long targetUid) {
|
||||||
|
LambdaQueryChainWrapper<UserApply> wrapper = lambdaQuery()
|
||||||
|
.eq(UserApply::getUid, uid)
|
||||||
|
.eq(UserApply::getTargetId, targetUid);
|
||||||
|
return getOne(wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void insert(UserApply userApply) {
|
||||||
|
save(userApply);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<UserApply> queryUserApplyList(Long uid) {
|
||||||
|
LambdaQueryChainWrapper<UserApply> wrapper = lambdaQuery()
|
||||||
|
.eq(UserApply::getUid, uid)
|
||||||
|
.or()
|
||||||
|
.eq(UserApply::getTargetId, uid);
|
||||||
|
return list(wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer unreadCount(Long uid) {
|
||||||
|
LambdaQueryChainWrapper<UserApply> wrapper = lambdaQuery()
|
||||||
|
.eq(UserApply::getTargetId, uid)
|
||||||
|
.eq(UserApply::getReadStatus, UNREAD.getCode());
|
||||||
|
return count(wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserApply queryUserApplyById(Long applyId) {
|
||||||
|
return getById(applyId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void agreeUserApply(Long applyId) {
|
||||||
|
LambdaUpdateChainWrapper<UserApply> updateWrapper = lambdaUpdate()
|
||||||
|
.set(UserApply::getStatus, AGREE.getCode())
|
||||||
|
.eq(UserApply::getId, applyId);
|
||||||
|
update(updateWrapper);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,12 @@ package com.abin.mallchat.common.user.dao;
|
|||||||
import com.abin.mallchat.common.user.domain.entity.UserFriend;
|
import com.abin.mallchat.common.user.domain.entity.UserFriend;
|
||||||
import com.abin.mallchat.common.user.mapper.UserFriendMapper;
|
import com.abin.mallchat.common.user.mapper.UserFriendMapper;
|
||||||
import com.abin.mallchat.common.user.service.IUserFriendService;
|
import com.abin.mallchat.common.user.service.IUserFriendService;
|
||||||
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 用户联系人表 服务实现类
|
* 用户联系人表 服务实现类
|
||||||
@@ -17,4 +20,13 @@ import org.springframework.stereotype.Service;
|
|||||||
@Service
|
@Service
|
||||||
public class UserFriendDao extends ServiceImpl<UserFriendMapper, UserFriend> implements IUserFriendService {
|
public class UserFriendDao extends ServiceImpl<UserFriendMapper, UserFriend> implements IUserFriendService {
|
||||||
|
|
||||||
|
public List<UserFriend> queryUserFriend(Long uid, List<Long> friendUidList) {
|
||||||
|
LambdaQueryChainWrapper<UserFriend> wrapper = lambdaQuery()
|
||||||
|
.eq(UserFriend::getUid, uid).in(UserFriend::getFriendUid, friendUidList);
|
||||||
|
return list(wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void insertBatch(List<UserFriend> userFriends) {
|
||||||
|
saveBatch(userFriends);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import lombok.NoArgsConstructor;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class FriendApplyResp {
|
public class FriendApplyResp {
|
||||||
|
@ApiModelProperty("申请id")
|
||||||
|
private Long applyId;
|
||||||
|
|
||||||
@ApiModelProperty("申请人uid")
|
@ApiModelProperty("申请人uid")
|
||||||
private Long uid;
|
private Long uid;
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ 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.request.PageBaseReq;
|
||||||
import com.abin.mallchat.common.common.domain.vo.response.PageBaseResp;
|
import com.abin.mallchat.common.common.domain.vo.response.PageBaseResp;
|
||||||
|
import com.abin.mallchat.common.user.dao.UserApplyDao;
|
||||||
|
import com.abin.mallchat.common.user.dao.UserFriendDao;
|
||||||
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.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.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.FriendApplyReq;
|
||||||
import com.abin.mallchat.custom.user.domain.vo.request.friend.FriendApproveReq;
|
import com.abin.mallchat.custom.user.domain.vo.request.friend.FriendApproveReq;
|
||||||
@@ -17,8 +17,6 @@ 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.FriendService;
|
||||||
import com.abin.mallchat.custom.user.service.WebSocketService;
|
import com.abin.mallchat.custom.user.service.WebSocketService;
|
||||||
import com.abin.mallchat.custom.user.service.adapter.WSAdapter;
|
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 com.google.common.collect.Lists;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -43,16 +41,15 @@ import static com.abin.mallchat.common.user.domain.enums.ApplyTypeEnum.ADD_FRIEN
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class FriendServiceImpl implements FriendService {
|
public class FriendServiceImpl implements FriendService {
|
||||||
|
|
||||||
@Resource
|
|
||||||
private IUserFriendService friendService;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private IUserApplyService applyService;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private WebSocketService webSocketService;
|
private WebSocketService webSocketService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UserFriendDao userFriendDao;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UserApplyDao userApplyDao;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查
|
* 检查
|
||||||
* 检查是否是自己好友
|
* 检查是否是自己好友
|
||||||
@@ -63,10 +60,7 @@ public class FriendServiceImpl implements FriendService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public FriendCheckResp check(Long uid, FriendCheckReq request) {
|
public FriendCheckResp check(Long uid, FriendCheckReq request) {
|
||||||
LambdaQueryChainWrapper<UserFriend> wrapper = friendService.lambdaQuery();
|
List<UserFriend> friendList = userFriendDao.queryUserFriend(uid, request.getUidList());
|
||||||
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));
|
Map<Long, UserFriend> friendMap = friendList.stream().collect(Collectors.toMap(UserFriend::getFriendUid, friend -> friend));
|
||||||
List<FriendCheckResp.FriendCheck> friendCheckList = request.getUidList().stream().map(friendUid -> {
|
List<FriendCheckResp.FriendCheck> friendCheckList = request.getUidList().stream().map(friendUid -> {
|
||||||
FriendCheckResp.FriendCheck friendCheck = new FriendCheckResp.FriendCheck();
|
FriendCheckResp.FriendCheck friendCheck = new FriendCheckResp.FriendCheck();
|
||||||
@@ -84,10 +78,7 @@ public class FriendServiceImpl implements FriendService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void apply(Long uid, FriendApplyReq request) {
|
public void apply(Long uid, FriendApplyReq request) {
|
||||||
LambdaQueryChainWrapper<UserApply> wrapper = applyService.lambdaQuery();
|
UserApply userApply = userApplyDao.queryUserApply(uid, request.getTargetUid());
|
||||||
wrapper.eq(UserApply::getUid, uid)
|
|
||||||
.eq(UserApply::getTargetId, request.getTargetUid());
|
|
||||||
UserApply userApply = applyService.getOne(wrapper);
|
|
||||||
if (Objects.nonNull(userApply)) {
|
if (Objects.nonNull(userApply)) {
|
||||||
log.info("已有好友申请记录,uid:{}, targetId:{}", uid, request.getTargetUid());
|
log.info("已有好友申请记录,uid:{}, targetId:{}", uid, request.getTargetUid());
|
||||||
return;
|
return;
|
||||||
@@ -99,7 +90,7 @@ public class FriendServiceImpl implements FriendService {
|
|||||||
userApplyNew.setTargetId(request.getTargetUid());
|
userApplyNew.setTargetId(request.getTargetUid());
|
||||||
userApplyNew.setStatus(WAIT_APPROVAL.getCode());
|
userApplyNew.setStatus(WAIT_APPROVAL.getCode());
|
||||||
userApplyNew.setReadStatus(UNREAD.getCode());
|
userApplyNew.setReadStatus(UNREAD.getCode());
|
||||||
applyService.save(userApplyNew);
|
userApplyDao.insert(userApplyNew);
|
||||||
|
|
||||||
WSApplyMessage applyMessage = MessageAdapter.buildApplyResp(userApplyNew);
|
WSApplyMessage applyMessage = MessageAdapter.buildApplyResp(userApplyNew);
|
||||||
webSocketService.sendToFriend(WSAdapter.buildApplySend(applyMessage), request.getTargetUid());
|
webSocketService.sendToFriend(WSAdapter.buildApplySend(applyMessage), request.getTargetUid());
|
||||||
@@ -114,13 +105,10 @@ public class FriendServiceImpl implements FriendService {
|
|||||||
@Override
|
@Override
|
||||||
public PageBaseResp<FriendApplyResp> pageApplyFriend(Long uid, PageBaseReq request) {
|
public PageBaseResp<FriendApplyResp> pageApplyFriend(Long uid, PageBaseReq request) {
|
||||||
// todo 分页
|
// todo 分页
|
||||||
LambdaQueryChainWrapper<UserApply> wrapper = applyService.lambdaQuery();
|
List<UserApply> userApplyList = userApplyDao.queryUserApplyList(uid);
|
||||||
wrapper.eq(UserApply::getUid, uid)
|
|
||||||
.or()
|
|
||||||
.eq(UserApply::getTargetId, uid);
|
|
||||||
List<UserApply> userApplyList = applyService.list(wrapper);
|
|
||||||
List<FriendApplyResp> friendApplyResps = userApplyList.stream().map(userApply -> {
|
List<FriendApplyResp> friendApplyResps = userApplyList.stream().map(userApply -> {
|
||||||
FriendApplyResp friendApplyResp = new FriendApplyResp();
|
FriendApplyResp friendApplyResp = new FriendApplyResp();
|
||||||
|
friendApplyResp.setApplyId(userApply.getId());
|
||||||
friendApplyResp.setUid(userApply.getUid());
|
friendApplyResp.setUid(userApply.getUid());
|
||||||
friendApplyResp.setType(userApply.getType());
|
friendApplyResp.setType(userApply.getType());
|
||||||
friendApplyResp.setMsg(userApply.getMsg());
|
friendApplyResp.setMsg(userApply.getMsg());
|
||||||
@@ -139,16 +127,13 @@ public class FriendServiceImpl implements FriendService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public FriendUnreadResp unread(Long uid) {
|
public FriendUnreadResp unread(Long uid) {
|
||||||
LambdaQueryChainWrapper<UserApply> wrapper = applyService.lambdaQuery();
|
return new FriendUnreadResp(userApplyDao.unreadCount(uid));
|
||||||
wrapper.eq(UserApply::getTargetId, uid)
|
|
||||||
.eq(UserApply::getReadStatus, UNREAD.getCode());
|
|
||||||
return new FriendUnreadResp(applyService.count(wrapper));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void applyApprove(FriendApproveReq request) {
|
public void applyApprove(FriendApproveReq request) {
|
||||||
UserApply userApply = applyService.getById(request.getApplyId());
|
UserApply userApply = userApplyDao.queryUserApplyById(request.getApplyId());
|
||||||
if (Objects.isNull(userApply)) {
|
if (Objects.isNull(userApply)) {
|
||||||
log.error("不存在申请记录:{}", request.getApplyId());
|
log.error("不存在申请记录:{}", request.getApplyId());
|
||||||
return;
|
return;
|
||||||
@@ -157,16 +142,13 @@ public class FriendServiceImpl implements FriendService {
|
|||||||
log.error("已同意好友申请:{}", request.getApplyId());
|
log.error("已同意好友申请:{}", request.getApplyId());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LambdaUpdateChainWrapper<UserApply> updateWrapper = applyService.lambdaUpdate();
|
userApplyDao.agreeUserApply(request.getApplyId());
|
||||||
updateWrapper.set(UserApply::getStatus, AGREE.getCode())
|
|
||||||
.eq(UserApply::getId, request.getApplyId());
|
|
||||||
applyService.update(updateWrapper);
|
|
||||||
UserFriend userFriend1 = new UserFriend();
|
UserFriend userFriend1 = new UserFriend();
|
||||||
userFriend1.setUid(userApply.getUid());
|
userFriend1.setUid(userApply.getUid());
|
||||||
userFriend1.setFriendUid(userApply.getTargetId());
|
userFriend1.setFriendUid(userApply.getTargetId());
|
||||||
UserFriend userFriend2 = new UserFriend();
|
UserFriend userFriend2 = new UserFriend();
|
||||||
userFriend2.setUid(userApply.getTargetId());
|
userFriend2.setUid(userApply.getTargetId());
|
||||||
userFriend2.setFriendUid(userApply.getUid());
|
userFriend2.setFriendUid(userApply.getUid());
|
||||||
friendService.saveBatch(Lists.newArrayList(userFriend1, userFriend2));
|
userFriendDao.insertBatch(Lists.newArrayList(userFriend1, userFriend2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user