Skip to content

Commit

Permalink
feat: 调整点赞状态,补充到个人信息和成员信息中 (#73)
Browse files Browse the repository at this point in the history
* feat: 调整点赞状态,补充到个人信息和成员信息中

* feat: 一行判断likestatus
  • Loading branch information
Aseubel authored Nov 28, 2024
1 parent 37c4d4d commit d904f50
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<select id="queryUserById" resultType="int">
select count(1) from `user` where user_id = #{userId}
</select>
<select id="queryLikedById" resultType="boolean">
<select id="queryLikedById" resultType="Integer">
select is_liked from `like`
where user_id = #{fromId} and to_Id = #{toId}
</select>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ public interface IMemberRepository {
* 查询团队成员信息详情
* @author yangzhiyao
* @date 2024/11/19
* @param userId 用户ID
* @param memberId 成员ID
* @return 查询到的成员信息
*/
UserEntity queryMemberInfo(String memberId);
UserEntity queryMemberInfo(String userId, String memberId);

/**
* 查询团队成员列表
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ public interface IMemberService {
* 查询成员信息详情
* @author yangzhiyao
* @date 2024/11/19
* @param userId 用户ID
* @param memberId 成员ID
* @return 查询到的成员信息
*/
UserEntity queryMemberInfo(String memberId);
UserEntity queryMemberInfo(String userId, String memberId);

/**
* 查看团队成员列表
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,24 +111,24 @@ public PostContext<TeamBO> doMainProcessor(PostContext<TeamBO> postContext) {
}

@Override
public UserEntity queryMemberInfo(String memberId) {
public UserEntity queryMemberInfo(String userId, String memberId) {
PostContext<TeamBO> postContext = buildPostContext(memberId);
postContext = super.doPostProcessor(postContext, AddMemberPostProcessor.class,
new AbstractPostProcessorOperation<TeamBO>() {
@Override
public PostContext<TeamBO> doMainProcessor(PostContext<TeamBO> postContext) {
TeamBO userBO = postContext.getBizData();
TeamBO teamBO = postContext.getBizData();
log.info("开始查询团队成员信息,userId:{},memberId:{}, teamId:{}",
userBO.getUserId(),
userBO.getUserEntity().getUserId(),
userBO.getTeamId());
teamBO.getUserId(),
teamBO.getUserEntity().getUserId(),
teamBO.getTeamId());

UserEntity userEntity = memberRepository.queryMemberInfo(userBO.getUserEntity().getUserId());
UserEntity userEntity = memberRepository.queryMemberInfo(teamBO.getUserId(), teamBO.getUserEntity().getUserId());

log.info("查询团队成员信息成功,userId:{},memberId:{}, teamId:{}",
userBO.getUserId(),
userBO.getUserEntity().getUserId(),
userBO.getTeamId());
teamBO.getUserId(),
teamBO.getUserEntity().getUserId(),
teamBO.getTeamId());
postContext.setBizData(TeamBO.builder().userEntity(userEntity).build());
return postContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Optional;

/**
* @author huangwenxing
Expand All @@ -27,7 +28,7 @@ public class LikeRepository implements ILikeRepository {
/**键过期时间500ms*/
private long expired = 500;
@Override
@Transactional
@Transactional(rollbackFor = Exception.class)
public void like(String fromId, String toId, boolean liked) {
/**更新点赞状态*/
Integer row = mapper.updateLiked(fromId, toId, liked);
Expand All @@ -53,7 +54,12 @@ public String getLikeValue(String fromId, String toId) {

@Override
public boolean queryLikedById(String fromId, String toId) {
return mapper.queryLikedById(fromId, toId);
// Integer liked = mapper.queryLikedById(fromId, toId);
// if(liked==null){
// return false;
// }
// return liked == 1;
return Optional.ofNullable(mapper.queryLikedById(fromId, toId)).map(i -> i == 1).orElse(false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,23 @@
package com.achobeta.infrastructure.adapter.repository;

import com.achobeta.domain.team.adapter.repository.IMemberRepository;
import com.achobeta.infrastructure.dao.UserMapper;
import com.achobeta.infrastructure.redis.RedissonService;
import cn.hutool.core.collection.CollectionUtil;
import com.achobeta.domain.team.adapter.repository.IMemberRepository;
import com.achobeta.domain.user.model.entity.UserEntity;
import com.achobeta.infrastructure.dao.LikeMapper;
import com.achobeta.infrastructure.dao.PositionMapper;
import com.achobeta.infrastructure.dao.UserMapper;
import com.achobeta.infrastructure.dao.po.PositionPO;
import com.achobeta.infrastructure.dao.po.UserPO;
import com.achobeta.infrastructure.redis.IRedisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import com.achobeta.infrastructure.dao.po.UserPO;
import com.achobeta.infrastructure.redis.IRedisService;
import com.achobeta.types.common.RedisKey;
import com.achobeta.types.enums.GlobalServiceStatusCode;
import com.achobeta.types.exception.AppException;
import com.achobeta.infrastructure.dao.po.PositionPO;
import com.achobeta.infrastructure.dao.po.UserPO;
import com.achobeta.infrastructure.redis.IRedisService;
import com.achobeta.types.common.Constants;
import com.achobeta.types.common.RedisKey;
import com.achobeta.types.enums.GlobalServiceStatusCode;
import com.achobeta.types.exception.AppException;
import com.achobeta.infrastructure.redis.RedissonService;
import com.achobeta.types.common.RedisKey;
import jodd.util.StringUtil;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

import java.util.ArrayList;
import java.util.List;

Expand All @@ -55,6 +36,9 @@ public class MemberRepository implements IMemberRepository {
@Resource
private PositionMapper positionMapper;

@Resource
private LikeMapper likeMapper;

@Resource
private IRedisService redisService;

Expand Down Expand Up @@ -197,24 +181,22 @@ public UserEntity modifyMemberInfo(UserEntity userEntity, String teamId, List<St
}

@Override
public UserEntity queryMemberInfo(String userId) {
log.info("尝试从redis中获取用户信息,userId: {}",userId);
UserEntity userBaseInfo = redisService.getValue(RedisKey.USER_INFO + userId);
public UserEntity queryMemberInfo(String userId, String memberId) {
UserEntity userBaseInfo = redisService.getValue(RedisKey.USER_INFO + memberId);
if(userBaseInfo!= null) {
return userBaseInfo;
}

log.info("从数据库中查询用户信息,userId: {}",userId);
UserPO userPO = userMapper.getUserByUserId(userId);
UserPO userPO = userMapper.getUserByUserId(memberId);
if(userPO == null) {
log.error("用户不存在!userId:{}",userId);
log.error("用户不存在!userId:{}",memberId);
throw new AppException(String.valueOf(GlobalServiceStatusCode.USER_ACCOUNT_NOT_EXIST.getCode()),
GlobalServiceStatusCode.USER_ACCOUNT_NOT_EXIST.getMessage());
}

// 封装position信息,先存根节点
List<List<PositionPO>> positionPOList = new ArrayList<>();
List<PositionPO> listPositions = positionMapper.listPositionByUserId(userId);
List<PositionPO> listPositions = positionMapper.listPositionByUserId(memberId);
for(PositionPO rootPosition : listPositions) {
List<PositionPO> tempList = new ArrayList<>();
tempList.add(rootPosition);
Expand Down Expand Up @@ -247,7 +229,6 @@ public UserEntity queryMemberInfo(String userId) {
}
positionNames.add(tempList);
}
log.info("从数据库中查询用户信息成功,userId: {}",userId);
// TODO:待添加获取用户点赞状态
UserEntity userEntity = UserEntity.builder()
.userId(userPO.getUserId())
Expand All @@ -263,13 +244,11 @@ public UserEntity queryMemberInfo(String userId) {
.currentStatus(userPO.getCurrentStatus())
.entryTime(userPO.getEntryTime())
.likeCount(userPO.getLikeCount())
.liked(false)
.liked(likeMapper.queryLikedById(userId, memberId)==1)
.positions(positionNames)
.build();

log.info("将用户信息缓存到redis,userId: {}",userId);
redisService.setValue(RedisKey.USER_INFO + userId,userEntity);
log.info("将用户信息缓存到redis成功,userId: {}",userId);
redisService.setValue(RedisKey.USER_INFO + memberId,userEntity);
return userEntity;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cn.hutool.core.collection.CollectionUtil;
import com.achobeta.domain.user.model.entity.UserEntity;
import com.achobeta.infrastructure.dao.LikeMapper;
import com.achobeta.infrastructure.dao.PositionMapper;
import com.achobeta.infrastructure.dao.UserMapper;
import com.achobeta.infrastructure.dao.po.PositionPO;
Expand Down Expand Up @@ -33,6 +34,9 @@ public class UserRepository implements com.achobeta.domain.user.adapter.reposito
@Resource
private PositionMapper positionMapper;

@Resource
private LikeMapper likeMapper;

@Resource
private IRedisService redisService;

Expand Down Expand Up @@ -153,7 +157,7 @@ public UserEntity queryUserInfo(String userId) {
.currentStatus(userPO.getCurrentStatus())
.entryTime(userPO.getEntryTime())
.likeCount(userPO.getLikeCount())
.liked(false)
.liked(likeMapper.queryLikedById(userId,userId)==1)
.positions(positionNames)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface LikeMapper {
/**插入用户点赞状态*/
Integer insertLiked(String fromId, String toId, boolean liked);
/**查询用户点赞状态*/
boolean queryLikedById(String fromId, String toId);
Integer queryLikedById(String fromId, String toId);
/**查询用户是否存在*/
Integer queryUserById(String userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public Response<QueryMemberInfoResponseDTO> queryMemberInfo(@Valid QueryMemberIn
try {
log.info("用户访问团队成员信息详情服务开始,{}", requestDTO);

UserEntity userEntity = memberService.queryMemberInfo(requestDTO.getMemberId());
UserEntity userEntity = memberService.queryMemberInfo(requestDTO.getUserId(), requestDTO.getMemberId());
log.info("用户访问团队成员信息详情服务结束,{}", requestDTO);

return Response.SYSTEM_SUCCESS(QueryMemberInfoResponseDTO.builder()
Expand Down

0 comments on commit d904f50

Please sign in to comment.