Commit 48adc132 by 段启岩

新增话题贡献者列表

parent 477f2043
......@@ -20,6 +20,7 @@ import cn.meteor.beyondclouds.modules.topic.service.ITopicService;
import cn.meteor.beyondclouds.modules.user.dto.UserFollowDTO;
import cn.meteor.beyondclouds.modules.user.dto.UserInfoDTO;
import cn.meteor.beyondclouds.modules.user.entity.User;
import cn.meteor.beyondclouds.modules.user.entity.UserFollow;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -219,4 +220,15 @@ public class TopicApi {
PageDTO<TopicDTO> topicDTOPage = topicService.getHotSearchTopics(pageForm.getPage(), pageForm.getSize());
return Response.success(topicDTOPage);
}
@Anonymous
@ApiOperation("话题贡献者列表")
@GetMapping("/topic/{topicId}/contributes")
public Response<?> topicContributes(@PathVariable("topicId") String topicId, @Valid PageForm pageForm, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return Response.fieldError(bindingResult.getFieldError());
}
PageDTO<UserFollowDTO> userFollowDTOPage = topicService.getTopicContributes(topicId, pageForm.getPage(), pageForm.getSize());
return Response.success(userFollowDTOPage);
}
}
......@@ -45,4 +45,11 @@ public interface TopicMapper extends BaseMapper<Topic> {
*/
IPage<Post> searchPostInTopicWithConditions(Page<Post> postPage, @Param(Constants.WRAPPER) QueryWrapper<?> queryWrapper);
/**
* 获取话题贡献者的ID
* @param page
* @param topicId
* @return
*/
IPage<String> selectTopicContributeIdPage(Page<String> page, @Param("topicId") String topicId);
}
......@@ -23,5 +23,13 @@
</if>
</select>
<select id="selectTopicContributeIdPage" resultType="java.lang.String">
SELECT user_id
FROM topic_reference tr
WHERE topic_id = #{topicId}
GROUP BY user_id
ORDER BY COUNT(user_id) DESC
</select>
</mapper>
......@@ -164,4 +164,13 @@ public interface ITopicService extends IService<Topic> {
*/
PageDTO<TopicDTO> getHotSearchTopics(Integer pageNumber, Integer pageSize);
/**
* 获取话题的贡献者分页列表
*
* @param topicId
* @param page
* @param size
* @return
*/
PageDTO<UserFollowDTO> getTopicContributes(String topicId, Integer page, Integer size);
}
......@@ -22,6 +22,7 @@ import cn.meteor.beyondclouds.modules.topic.service.ITopicFollowService;
import cn.meteor.beyondclouds.modules.topic.service.ITopicReferenceService;
import cn.meteor.beyondclouds.modules.topic.service.ITopicService;
import cn.meteor.beyondclouds.modules.user.dto.UserFollowDTO;
import cn.meteor.beyondclouds.modules.user.dto.UserInfoDTO;
import cn.meteor.beyondclouds.modules.user.entity.User;
import cn.meteor.beyondclouds.modules.user.entity.UserStatistics;
import cn.meteor.beyondclouds.modules.user.service.IUserFollowService;
......@@ -34,7 +35,6 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -550,5 +550,29 @@ public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements
return toPageDTO(topicPage);
}
@Override
public PageDTO<UserFollowDTO> getTopicContributes(String topicId, Integer pageNumber, Integer pageSize) {
IPage<String> userIdPage = topicMapper.selectTopicContributeIdPage(new Page<>(pageNumber, pageSize), topicId);
List<String> userIds = userIdPage.getRecords();
PageDTO<UserFollowDTO> userFollowDTOPage = new PageDTO<>();
PageUtils.copyMeta(userIdPage, userFollowDTOPage);
if (!CollectionUtils.isEmpty(userIds)) {
List<UserFollowDTO> userInfoDTOList = userService.listByIdsWithStatistics(userIds);
if (SubjectUtils.isAuthenticated()) {
Set<String> followedUserIds = userFollowService.getCurrentUserFollowedUserIds();
userInfoDTOList.forEach(userFollowDTO -> {
userFollowDTO.setFollowedUser(followedUserIds.contains(userFollowDTO.getUserId()));
});
} else {
userInfoDTOList.forEach(userFollowDTO -> {
userFollowDTO.setFollowedUser(false);
});
}
userFollowDTOPage.setDataList(userInfoDTOList);
} else {
userFollowDTOPage.setDataList(List.of());
}
return userFollowDTOPage;
}
}
......@@ -5,6 +5,9 @@ import cn.meteor.beyondclouds.modules.user.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author 段启岩
......@@ -18,4 +21,11 @@ public interface UserMapper extends BaseMapper<User> {
* @return
*/
IPage<UserFollowDTO> selectHotBloggerPage(Page<User> page);
/**
* 批量查询用户-带统计信息
* @param userIds
* @return
*/
List<UserFollowDTO> listByIdsWithStatistics(@Param("userIds") List<String> userIds);
}
......@@ -18,5 +18,27 @@
AND US.blog_view_num > 0
order by us.blog_view_num desc
</select>
<select id="listByIdsWithStatistics" resultType="cn.meteor.beyondclouds.modules.user.dto.UserFollowDTO">
select
u.*,
u.nick_name user_nick,
us.followed_num `statistics.followed_num`,
us.fans_num `statistics.fans_num`,
us.blog_num `statistics.blog_num`,
us.blog_view_num `statistics.blog_view_num`,
us.project_num `statistics.project_num`,
us.post_num `statistics.post_num`,
us.question_num `statistics.question_num`,
us.visited_num `statistics.visited_num`
from `user` u, user_statistics us
where u.user_id = us.user_id
and u.user_id
in
<foreach collection="userIds" item="userId" index="index" open="(" close=")" separator=",">
#{userId}
</foreach>
order by us.blog_view_num desc
</select>
</mapper>
......@@ -9,6 +9,8 @@ import cn.meteor.beyondclouds.modules.user.entity.UserStatistics;
import cn.meteor.beyondclouds.modules.user.exception.UserServiceException;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
* @author meteor
*/
......@@ -105,4 +107,11 @@ public interface IUserService extends IService<User> {
* @return
*/
PageDTO<UserFollowDTO> getHotBloggers(Integer pageNumber, Integer pageSize);
/**
* 批量查询用户-带统计信息
* @param userIds
* @return
*/
List<UserFollowDTO> listByIdsWithStatistics(List<String> userIds);
}
......@@ -452,4 +452,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
userFollowDTOPage.setDataList(userFollowDTOList);
return userFollowDTOPage;
}
@Override
public List<UserFollowDTO> listByIdsWithStatistics(List<String> userIds) {
return userMapper.listByIdsWithStatistics(userIds);
}
}
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