Commit 49f63e9c authored by 刘基明's avatar 刘基明

话题列表fix

parent 102b435b
......@@ -2,17 +2,19 @@ package com.tanpu.community.api.beans.qo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("关注列表")
public class FollowQo {
@ApiModelProperty(value = "id")
private String id;
@ApiModelProperty(value = "用户id")
private String userId;
......
......@@ -25,6 +25,21 @@ public class FormerThemeQo {
@ApiModelProperty(value = "被转发的主题Id")
private String formerThemeId;
@ApiModelProperty(value = "类型 1:讨论无标题 2:长文有标题 3:转发 ")
private Integer themeType;
@ApiModelProperty(value = "被转发的主题标题")
private String title;
@ApiModelProperty(value = "被转发的主题的话题名称")
private String topicTitle;
@ApiModelProperty(value = "被转发的主题所属的话题")
private String topicId;
@ApiModelProperty(value = "被转发的主题的作者id")
private String authorId;
@ApiModelProperty(value = "转发内容")
private List<ThemeContentQo> forwardContent;
......
......@@ -3,12 +3,18 @@ package com.tanpu.community.api.beans.qo;
import com.tanpu.community.api.beans.ImagesDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@ApiModel(value = "主题内容")
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ThemeContentQo {
@ApiModelProperty(value = "RelTypeEnum类型,8:文本,88:产品 3:直播 6:短视频 2:课程,9:图片 10:多图(讨论)")
......
......@@ -3,11 +3,17 @@ package com.tanpu.community.api.beans.qo;
import com.tanpu.community.api.beans.ImagesDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("主题信息流对象")
public class ThemeQo {
......
......@@ -4,11 +4,11 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class AddIdolReq {
public class FollowRelReq {
@ApiModelProperty(value = "关注对象Id")
private String followUserId;
@ApiModelProperty(value = "粉丝Id")
private String followerId;
@ApiModelProperty(value = "关注类型,1:关注 2:取消关注")
private Integer type;
}
......@@ -4,6 +4,7 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
@Data
......@@ -11,8 +12,10 @@ import javax.validation.constraints.NotNull;
public class QueryRecordThemeReq {
@ApiModelProperty("用户Id")
@NotBlank
private String userId;
@NotNull
@ApiModelProperty(value = "操作类型 1:发布 2:回复 3:点赞 4:收藏")
private Integer recordType;
......
package com.tanpu.community.api.enums;
/**
* 通用操作类型枚举,包括点赞/取消点赞,收藏/取消收藏,关注/取消关注
*/
public enum OperationTypeEnum {
CONFIRM(1,"确认操作"),
CANCEL(2,"取消操作");
private Integer code;
private String type;
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
OperationTypeEnum(Integer code, String type) {
this.code = code;
this.type = type;
}
}
package com.tanpu.community.controller;
import com.tanpu.common.api.CommonResp;
import com.tanpu.common.auth.AuthLogin;
import com.tanpu.common.auth.UserHolder;
import com.tanpu.community.api.beans.qo.FollowQo;
import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.api.beans.req.HomePageReq;
import com.tanpu.community.api.beans.req.homepage.AddIdolReq;
import com.tanpu.community.api.beans.req.homepage.FollowRelReq;
import com.tanpu.community.api.beans.req.homepage.QueryFollowReq;
import com.tanpu.community.api.beans.req.homepage.QueryRecordThemeReq;
import com.tanpu.community.api.beans.req.page.Page;
......@@ -16,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RestController
......@@ -29,6 +32,9 @@ public class HomePageController {
@Autowired
private ThemeManager themeManager;
@Resource
private UserHolder userHolder;
@PostMapping(value = "/editInfo")
@ApiOperation("编辑圈子个人资料")
@ResponseBody
......@@ -41,36 +47,37 @@ public class HomePageController {
@PostMapping(value = "/followList")
@ApiOperation("查询关注/粉丝列表")
@ResponseBody
@AuthLogin
public CommonResp<Page<FollowQo>> queryMyFans(@RequestBody QueryFollowReq req) {
String userId = "123";
return CommonResp.success(homePageManager.queryFollow(req));
String userId = userHolder.getUserId();
return CommonResp.success(homePageManager.queryFollow(req,userId));
}
@PostMapping(value = "/addIdol")
@ApiOperation("关注他人")
@ApiOperation("关注/取消关注他人")
@ResponseBody
public CommonResp addIdol(@RequestBody AddIdolReq req) {
String userId = "123";
homePageManager.addIdol(req.getFollowUserId(), req.getFollowUserId());
public CommonResp addIdol(@RequestBody FollowRelReq req) {
String userId = userHolder.getUserId();
homePageManager.addFollowRel(req,userId);
return CommonResp.success();
}
@PostMapping(value = "/themeList")
@ApiOperation("用户的帖子列表")
@ResponseBody
public CommonResp<List<ThemeQo>> likeList(@RequestBody QueryRecordThemeReq req){
String userId="123";
@AuthLogin
public CommonResp<List<ThemeQo>> likeList(@Validated @RequestBody QueryRecordThemeReq req){
String userId = userHolder.getUserId();
return CommonResp.success(themeManager.queryThemesByUser(req,userId));
}
@PostMapping(value = "/commentThemeList")
@ApiOperation("用户评论过的帖子列表")
@ResponseBody
public CommonResp<List<ThemeQo>> commentThemeList(@RequestBody QueryRecordThemeReq req){
String userId="123";
return CommonResp.success(themeManager.queryThemesByUser(req,userId));
}
// @PostMapping(value = "/commentThemeList")
// @ApiOperation("用户评论过的帖子列表")
// @ResponseBody
// public CommonResp<List<ThemeQo>> commentThemeList(@RequestBody QueryRecordThemeReq req){
// String userId="123";
//
// return CommonResp.success(themeManager.queryThemesByUser(req,userId));
// }
}
......@@ -5,6 +5,7 @@ import com.tanpu.community.api.beans.req.comment.CreateCommentReq;
import com.tanpu.community.api.beans.req.comment.LikeCommentReq;
import com.tanpu.community.api.enums.CollectionTypeEnum;
import com.tanpu.community.api.enums.CommentTypeEnum;
import com.tanpu.community.api.enums.OperationTypeEnum;
import com.tanpu.community.dao.entity.community.CommentEntity;
import com.tanpu.community.dao.entity.user.UserInfoEntity;
import com.tanpu.community.service.CollectionService;
......@@ -50,7 +51,7 @@ public class CommentManager {
}
//查询
public List<CommentQo> queryComments(String themeId,String userId) {
public List<CommentQo> queryComments(String themeId, String userId) {
List<CommentEntity> commentEntities = commentService.selectByThemeIdAndParentId(themeId, null);
List<CommentQo> commentQos = ConvertUtil.commentEntity2Qos(commentEntities);
......@@ -61,18 +62,18 @@ public class CommentManager {
//用户信息
String authorId = commentQo.getAuthorId();
UserInfoEntity userInfo = userInfoService.selectById(authorId);
if (userInfo!=null){
if (userInfo != null) {
commentQo.setUserImg(userInfo.getUiHeadimg());
commentQo.setNickName(userInfo.getUiNickname());
}
//是否点赞及点赞数
String commentId = commentQo.getCommentId();
if (likeCommentList.contains(commentId)){
if (likeCommentList.contains(commentId)) {
commentQo.setHasLiked(true);
}else {
} else {
commentQo.setHasLiked(false);
}
Integer countByTypeAndId = collectionService.getCountByTypeAndId(commentId,CollectionTypeEnum.LIKE_COMMENT);
Integer countByTypeAndId = collectionService.getCountByTypeAndId(commentId, CollectionTypeEnum.LIKE_COMMENT);
commentQo.setLikeCount(countByTypeAndId);
//二级评论,本期不上线
......@@ -86,10 +87,9 @@ public class CommentManager {
//点赞评论/取消点赞
public void likeComment(LikeCommentReq req, String userId) {
//todo 枚举值
if (1==req.getType()){
if (OperationTypeEnum.CONFIRM.getCode().equals(req.getType())) {
collectionService.addIfNotExist(req.getCommentId(), userId, CollectionTypeEnum.LIKE_COMMENT);
}else if (2==req.getType()) {
} else if (OperationTypeEnum.CANCEL.getCode().equals(req.getType())) {
collectionService.delete(req.getCommentId(), userId, CollectionTypeEnum.LIKE_COMMENT);
}
......
package com.tanpu.community.manager;
import com.tanpu.community.api.beans.qo.FollowQo;
import com.tanpu.community.api.beans.req.HomePageReq;
import com.tanpu.community.api.beans.req.homepage.FollowRelReq;
import com.tanpu.community.api.beans.req.homepage.QueryFollowReq;
import com.tanpu.community.api.beans.req.page.Page;
import com.tanpu.community.api.enums.OperationTypeEnum;
import com.tanpu.community.api.enums.QueryFollowTypeEnum;
import com.tanpu.community.dao.entity.community.HomePageEntity;
import com.tanpu.community.dao.entity.user.UserInfoEntity;
import com.tanpu.community.service.FollowRelService;
import com.tanpu.community.service.HomePageService;
import com.tanpu.community.service.UserInfoService;
import com.tanpu.community.util.ConvertUtil;
import com.tanpu.community.util.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
......@@ -25,42 +25,26 @@ public class HomePageManager {
@Autowired
private FollowRelService followRelService;
@Resource
private HomePageService homePageService;
// public void editUserInfo(HomePageReq req,String userId) {
// HomePageEntity entity = HomePageEntity.builder()
// .userId(userId)
// .nickName(req.getNickName())
// .headImg(req.getHeadImg())
// .introduction(req.getIntroduction())
// .sex(req.getSex())
// .location(req.getLocation())
// .build();
// if(homePageService.selectByUserId(userId) == null){
// homePageService.insert(entity);
// }else {
// homePageService.update(entity);
// }
// return;
// }
@Autowired
private UserInfoService userInfoService;
//获取用户关注、粉丝列表
public Page<FollowQo> queryFollow(QueryFollowReq req) {
List<String> userIds = QueryFollowTypeEnum.QUERY_FANS.getCode().equals(req.getQueryType())?
followRelService.queryFansByIdolId(req.getUserId()):followRelService.queryFansByFollowerId(req.getUserId());
List<HomePageEntity> list = homePageService.selectListByUserIds(userIds);
List<FollowQo> collect = list.stream().map(ConvertUtil::homePageEntity2FollowQo).collect(Collectors.toList());
List<FollowQo> followQos = judgeFollowed(collect, req.getUserId());
return PageUtils.page(req.getPage(),followQos);
public Page<FollowQo> queryFollow(QueryFollowReq req, String userId) {
List<String> userIds = QueryFollowTypeEnum.QUERY_FANS.getCode().equals(req.getQueryType()) ?
followRelService.queryFansByIdolId(req.getUserId()) : followRelService.queryFansByFollowerId(req.getUserId());
List<UserInfoEntity> userInfos = userInfoService.selectByIds(userIds);
List<FollowQo> collect = userInfos.stream().map(ConvertUtil::homePageEntity2FollowQo).collect(Collectors.toList());
List<FollowQo> followQos = judgeFollowed(collect, userId);
return PageUtils.page(req.getPage(), followQos);
}
//判断返回列表中的用户是否被当前用户关注
public List<FollowQo> judgeFollowed(List<FollowQo> followQos,String followerId){
public List<FollowQo> judgeFollowed(List<FollowQo> followQos, String followerId) {
Set<String> idolSet = new HashSet<>(followRelService.queryFansByFollowerId(followerId));
return followQos.stream().map(o->{
if (idolSet.contains(o.getUserId())){
return followQos.stream().map(o -> {
if (idolSet.contains(o.getUserId())) {
o.setFollowed(true);
}
return o;
......@@ -68,7 +52,11 @@ public class HomePageManager {
}
public void addIdol(String idolId, String followerId) {
followRelService.addFans(idolId, followerId);
public void addFollowRel(FollowRelReq req, String followerId) {
if (OperationTypeEnum.CONFIRM.getCode().equals(req.getType())) {
followRelService.addFollowRel(req.getFollowUserId(), followerId);
} else if (OperationTypeEnum.CANCEL.getCode().equals(req.getType())) {
followRelService.deleteFollowRel(req.getFollowUserId(), followerId);
}
}
}
......@@ -3,17 +3,17 @@ package com.tanpu.community.manager;
import com.tanpu.common.exception.BizException;
import com.tanpu.common.util.JsonUtil;
import com.tanpu.community.api.beans.qo.FormerThemeQo;
import com.tanpu.community.api.beans.qo.ThemeContentQo;
import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.api.beans.req.homepage.QueryRecordThemeReq;
import com.tanpu.community.api.beans.req.theme.*;
import com.tanpu.community.api.enums.BlockTypeEnum;
import com.tanpu.community.api.enums.CollectionTypeEnum;
import com.tanpu.community.api.enums.ThemeListTypeEnum;
import com.tanpu.community.api.enums.ThemeTypeEnum;
import com.tanpu.community.api.enums.*;
import com.tanpu.community.dao.entity.community.*;
import com.tanpu.community.dao.entity.user.UserInfoEntity;
import com.tanpu.community.service.*;
import com.tanpu.community.service.other.BlackListService;
import com.tanpu.community.util.ConvertUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -67,12 +67,12 @@ public class ThemeManager {
BeanUtils.copyProperties(req, themeEntity);
themeEntity.setAuthorId(userId);
themeEntity.setContent(JsonUtil.toJson(req.getContent()));
if (StringUtils.isEmpty(req.getEditThemeId())){
if (StringUtils.isEmpty(req.getEditThemeId())) {
//新建
themeService.insertTheme(themeEntity);
}else {
} else {
//修改
themeService.update(themeEntity,req.getEditThemeId());
themeService.update(themeEntity, req.getEditThemeId());
}
//保存附件表
......@@ -111,42 +111,57 @@ public class ThemeManager {
List<ThemeEntity> themeEntities = Collections.emptyList();
switch (req.getRecordType()) {
case 1://发布
themeEntities = themeService.queryThemeIdsByUserId(req.getUserId());
themeEntities = themeService.queryThemeIdsByUserId(req.getUserId(),req.getLastId(),req.getPageSize());
break;
case 2://回复
List<CommentEntity> commentEntities = commentService.queryThemesByUserId(req.getUserId());
List<ThemeQo> commentThemeList = new ArrayList<>();
//评论列表
List<CommentEntity> commentEntities = commentService.queryThemesByUserId(req.getUserId(),req.getLastId(),req.getPageSize());
//当前用户信息
UserInfoEntity userInfoEntity = userInfoService.selectById(req.getUserId());
Set<String> replyThemeIds = commentEntities.stream().map(CommentEntity::getThemeId).collect(Collectors.toSet());
if (CollectionUtils.isEmpty(replyThemeIds)){
return commentThemeList;
}
Map<String, CommentEntity> commentMap = commentEntities.stream()
.collect(Collectors.toMap(CommentEntity::getThemeId, o -> o));
themeEntities = themeService.queryByThemeIds(new ArrayList<>(replyThemeIds));
List<ThemeQo> themeQos = convertEntityToQo(themeEntities, userId);
for (ThemeQo themeQo : themeQos) {
FormerThemeQo f = FormerThemeQo.builder().formerThemeId(themeQo.getThemeId())
String themeId = themeQo.getThemeId();
ThemeContentQo commentContent = ThemeContentQo.builder()
.type(RelTypeEnum.TEXT.type)
.value(commentMap.get(themeId)
.getContent())
.build();
ThemeQo commentThemeQo = ThemeQo.builder().userImg(themeQo.getUserImg())
.nickName(userInfoEntity.getUiNickname())
.userImg(userInfoEntity.getUiHeadimg())
.content(Arrays.asList(commentContent))
.build();
FormerThemeQo f = FormerThemeQo.builder().formerThemeId(themeId)
.forwardContent(themeQo.getContent())
.userImg(themeQo.getUserImg())
.nickName(themeQo.getNickName())
.build();
themeQo.setFormerTheme(f);
commentThemeQo.setFormerTheme(f);
commentThemeList.add(commentThemeQo);
}
break;
return commentThemeList;
case 3://点赞
Set<String> likeThemeIds = collectionService.getListByUser(userId, CollectionTypeEnum.LIKE_THEME);
themeEntities = themeService.queryByThemeIds(new ArrayList<>(likeThemeIds));
themeEntities = themeService.queryByThemeIds(new ArrayList<>(likeThemeIds),req.getLastId(),req.getPageSize());
break;
case 4://收藏
Set<String> collectThemeIds = collectionService.getListByUser(userId, CollectionTypeEnum.COLLECT_THEME);
themeEntities = themeService.queryByThemeIds(new ArrayList<>(collectThemeIds));
themeEntities = themeService.queryByThemeIds(new ArrayList<>(collectThemeIds),req.getLastId(),req.getPageSize());
break;
}
List<ThemeQo> themeQos = convertEntityToQo(themeEntities, userId);
return themeQos;
}
public List<ThemeQo> queryThemesByUserComment(QueryRecordThemeReq req, String userId) {
List<CommentEntity> commentEntities = commentService.queryThemesByUserId(req.getUserId());
Set<String> replyThemeIds = commentEntities.stream().map(CommentEntity::getThemeId).collect(Collectors.toSet());
List<ThemeEntity> themeEntities = themeService.queryByThemeIds(new ArrayList<>(replyThemeIds));
return null;
}
//查询正文
......@@ -163,10 +178,9 @@ public class ThemeManager {
// 点赞/取消点赞
public void like(LikeThemeReq req, String userId) {
//todo 枚举值
if (1 == req.getType()) {
if (OperationTypeEnum.CONFIRM.getCode().equals(req.getType())) {
collectionService.addIfNotExist(req.getThemeId(), userId, CollectionTypeEnum.LIKE_THEME);
} else if (2 == req.getType()) {
} else if (OperationTypeEnum.CANCEL.getCode().equals(req.getType())) {
collectionService.delete(req.getThemeId(), userId, CollectionTypeEnum.LIKE_THEME);
}
......@@ -174,10 +188,9 @@ public class ThemeManager {
//收藏/取消收藏
public void collect(CollectThemeReq req, String userId) {
//todo 枚举值
if (1 == req.getType()) {
if (OperationTypeEnum.CONFIRM.getCode().equals(req.getType())) {
collectionService.addIfNotExist(req.getThemeId(), userId, CollectionTypeEnum.COLLECT_THEME);
} else if (2 == req.getType()) {
} else if (OperationTypeEnum.CANCEL.getCode().equals(req.getType())) {
collectionService.delete(req.getThemeId(), userId, CollectionTypeEnum.COLLECT_THEME);
}
}
......@@ -193,12 +206,12 @@ public class ThemeManager {
.themeType(ThemeTypeEnum.FORWARD.getCode())
.build();
if (StringUtils.isEmpty(req.getEditThemeId()) || req.getEditThemeId()== req.getFormerThemeId()){
if (StringUtils.isEmpty(req.getEditThemeId()) || req.getEditThemeId() == req.getFormerThemeId()) {
//新建
themeService.insertTheme(newTheme);
}else {
} else {
//修改
themeService.update(newTheme,req.getEditThemeId());
themeService.update(newTheme, req.getEditThemeId());
}
}
......
package com.tanpu.community.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanpu.common.exception.BizException;
import com.tanpu.common.uuid.UuidGenHelper;
import com.tanpu.community.api.enums.CommentTypeEnum;
import com.tanpu.community.api.enums.DeleteTagEnum;
......@@ -8,6 +9,7 @@ import com.tanpu.community.api.enums.TopicStatusEnum;
import com.tanpu.community.dao.entity.community.CommentEntity;
import com.tanpu.community.dao.mapper.community.CommentMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -74,4 +76,21 @@ public class CommentService {
.eq(CommentEntity::getCommentType, CommentTypeEnum.THEME.getCode())
.eq(CommentEntity::getDeleteTag,DeleteTagEnum.NOT_DELETED.getCode()));
}
public List<CommentEntity> queryThemesByUserId(String userId, String lastId,Integer pageSize) {
LambdaQueryWrapper<CommentEntity> queryWrapper = new LambdaQueryWrapper<CommentEntity>()
.eq(CommentEntity::getAuthorId, userId)
.eq(CommentEntity::getCommentType, CommentTypeEnum.THEME.getCode())
.eq(CommentEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
if (StringUtils.isNotEmpty(lastId)) {
CommentEntity commentEntity = commentMapper.selectById(lastId);
if (commentEntity==null) throw new BizException("主题未找到,id:"+lastId);
queryWrapper.lt(CommentEntity::getUpdateTime, commentEntity.getCreateTime());
}
if (pageSize!=null){
queryWrapper.last("limit "+pageSize);
}
return commentMapper.selectList(queryWrapper);
}
}
package com.tanpu.community.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanpu.common.exception.BizException;
import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.dao.entity.community.FollowRelEntity;
import com.tanpu.community.dao.mapper.community.FollowRelMapper;
import org.springframework.cache.annotation.EnableCaching;
......@@ -8,6 +10,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
......@@ -20,24 +23,61 @@ public class FollowRelService {
public List<String> queryFansByFollowerId(String followerId) {
return followRelMapper.selectList(new LambdaQueryWrapper<FollowRelEntity>()
.eq(FollowRelEntity::getFollowerId, followerId))
.stream().map(FollowRelEntity::getFollowUserId).collect(Collectors.toList());
.eq(FollowRelEntity::getFollowerId, followerId)
.eq(FollowRelEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()))
.stream().map(FollowRelEntity::getFollowUserId)
.collect(Collectors.toList());
}
// @Cacheable(value = "tempCache", keyGenerator = "communityKeyGenerator")
public List<String> queryFansByIdolId(String idolId) {
LambdaQueryWrapper<FollowRelEntity> queryWrapper = new LambdaQueryWrapper<FollowRelEntity>()
.eq(FollowRelEntity::getFollowUserId, idolId);
.eq(FollowRelEntity::getFollowUserId, idolId)
.eq(FollowRelEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
return followRelMapper.selectList(queryWrapper)
.stream().map(FollowRelEntity::getFollowerId).collect(Collectors.toList());
}
@Transactional
public void addFans(String idolId, String followerId) {
FollowRelEntity rel = new FollowRelEntity();
rel.setFollowUserId(idolId);
rel.setFollowerId(followerId);
public void addFollowRel(String idolId, String followerId) {
FollowRelEntity searchResult = queryRecord(idolId, followerId);
if (searchResult==null){
FollowRelEntity entity = FollowRelEntity.builder()
.followUserId(idolId)
.followerId(followerId)
.followTime(LocalDateTime.now())
.build();
followRelMapper.insert(rel);
followRelMapper.insert(entity);
}else {
searchResult.setFollowTime(LocalDateTime.now());
searchResult.setDeleteTag(DeleteTagEnum.NOT_DELETED.getCode());
followRelMapper.updateById(searchResult);
}
}
/**
* 逻辑删除关注关系
* @param idolId
* @param followerId
*/
@Transactional
public void deleteFollowRel(String idolId, String followerId) {
FollowRelEntity searchResult = queryRecord(idolId, followerId);
if (searchResult==null){
throw new BizException("未找到关注关系");
}
searchResult.setUnfollowTime(LocalDateTime.now());
searchResult.setDeleteTag(DeleteTagEnum.DELETED.getCode());
followRelMapper.updateById(searchResult);
}
public FollowRelEntity queryRecord(String idolId, String followerId){
return followRelMapper.selectOne(new LambdaQueryWrapper<FollowRelEntity>()
.eq(FollowRelEntity::getFollowUserId,idolId)
.eq(FollowRelEntity::getFollowerId,followerId));
}
}
package com.tanpu.community.service;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.tanpu.common.api.CommonResp;
import com.tanpu.common.enums.fund.ProductTypeEnum;
import com.tanpu.common.util.JsonUtil;
......@@ -31,10 +31,7 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
@Service
......@@ -98,9 +95,9 @@ public class ProductService {
// 图片信息
Map<String, UserInfoEntity> userMap = Maps.newHashMap();
// 批量查询资源信息
this.getResInfo(shortVideoMap, curriculumMap, courseMap, zhiboMap, fundMap, imgMap, topicMap,userMap, themeQos);
this.getResInfo(shortVideoMap, curriculumMap, courseMap, zhiboMap, fundMap, imgMap, topicMap, userMap, themeQos);
//逐个装入
setResInfo(themeQos, shortVideoMap, curriculumMap, courseMap, zhiboMap, fundMap, imgMap,userMap, topicMap);
setResInfo(themeQos, shortVideoMap, curriculumMap, courseMap, zhiboMap, fundMap, imgMap, userMap, topicMap);
}
......@@ -124,29 +121,29 @@ public class ProductService {
List<ThemeQo> themeQos
) {
// 白名单基金id
List<String> tanpuFundIds = Lists.newArrayList();
HashSet<String> tanpuFundIds = Sets.newHashSet();
// 私募基金id
List<String> fundIds = Lists.newArrayList();
HashSet<String> fundIds = Sets.newHashSet();
// 理财师导入
List<String> ifaFundIds = Lists.newArrayList();
HashSet<String> ifaFundIds = Sets.newHashSet();
// 公募基金id
List<String> publicFundIds = Lists.newArrayList();
HashSet<String> publicFundIds = Sets.newHashSet();
// 无净值产品id
List<String> notNetFundIds = Lists.newArrayList();
HashSet<String> notNetFundIds = Sets.newHashSet();
// 短视频id
List<String> shortVideoIds = Lists.newArrayList();
HashSet<String> shortVideoIds = Sets.newHashSet();
// 直播id
List<String> zhiboIds = Lists.newArrayList();
HashSet<String> zhiboIds = Sets.newHashSet();
// 课程id
List<String> curriculumIds = Lists.newArrayList();
HashSet<String> curriculumIds = Sets.newHashSet();
// 新课程id
List<String> courseIds = Lists.newArrayList();
HashSet<String> courseIds = Sets.newHashSet();
// 图片id
List<String> imageIds = Lists.newArrayList();
HashSet<String> imageIds = Sets.newHashSet();
// 话题id
List<String> topicIds = Lists.newArrayList();
HashSet<String> topicIds = Sets.newHashSet();
// 用户id
List<String> userIds = Lists.newArrayList();
HashSet<String> userIds = Sets.newHashSet();
// 获取关联资源id
if (themeQos != null) {
themeQos.forEach(o -> {
......@@ -189,43 +186,51 @@ public class ProductService {
}
if (!CollectionUtils.isEmpty(shortVideoIds)) {
// 短视频列表
CommonResp<List<ShortVideoBaseInfoResp>> commonResp = feignClientForTanpuroom.getShortVideoBaseInfo(shortVideoIds);
CommonResp<List<ShortVideoBaseInfoResp>> commonResp =
feignClientForTanpuroom.getShortVideoBaseInfo(setToList(shortVideoIds));
if (commonResp.isSuccess() && !CollectionUtils.isEmpty(commonResp.getData())) {
shortVideoMap.putAll(commonResp.getData().stream().collect(Collectors.toMap(ShortVideoBaseInfoResp::getSourceId, item -> item)));
shortVideoMap.putAll(commonResp.getData().stream()
.collect(Collectors.toMap(ShortVideoBaseInfoResp::getSourceId, item -> item)));
}
}
if (!CollectionUtils.isEmpty(curriculumIds)) {
// 课程列表
List<ShortVideoBaseInfoResp> commonResp = feignClientForFatools.getCurriculumByColumnRelId(curriculumIds);
List<ShortVideoBaseInfoResp> commonResp =
feignClientForFatools.getCurriculumByColumnRelId(setToList(curriculumIds));
if (commonResp != null && !CollectionUtils.isEmpty(commonResp)) {
curriculumMap.putAll(commonResp.stream().collect(Collectors.toMap(ShortVideoBaseInfoResp::getColumnRelId, item -> item)));
curriculumMap.putAll(commonResp.stream()
.collect(Collectors.toMap(ShortVideoBaseInfoResp::getColumnRelId, item -> item)));
}
}
if (!CollectionUtils.isEmpty(courseIds)) {
// 新版课程列表
CommonResp<List<CourseSimpleResp>> commonResp = feignForCourse.getCourseSimpleList(courseIds);
CommonResp<List<CourseSimpleResp>> commonResp =
feignForCourse.getCourseSimpleList(setToList(courseIds));
if (commonResp.isSuccess() & !CollectionUtils.isEmpty(commonResp.getData())) {
courseMap.putAll(commonResp.getData().stream().collect(Collectors.toMap(CourseSimpleResp::getCourseId, item -> item)));
}
}
if (!CollectionUtils.isEmpty(zhiboIds)) {
// 直播列表
CommonResp<List<ZhiboListResp>> commonResp = feignClientForZhibo.simpleList(zhiboIds);
CommonResp<List<ZhiboListResp>> commonResp =
feignClientForZhibo.simpleList(setToList(zhiboIds));
if (commonResp.isSuccess() && !CollectionUtils.isEmpty(commonResp.getData())) {
zhiboMap.putAll(commonResp.getData().stream().collect(Collectors.toMap(ZhiboListResp::getId, item -> item)));
}
}
if (!CollectionUtils.isEmpty(imageIds)) {
// 查询图片
List<FileRecordEntity> fileRecordEntities = ossFileService.queryByIds(imageIds);
List<FileRecordEntity> fileRecordEntities =
ossFileService.queryByIds(setToList(imageIds));
if (!CollectionUtils.isEmpty(fileRecordEntities)) {
imgMap.putAll(fileRecordEntities.stream().collect(Collectors
.toMap(FileRecordEntity::getFileId, o->o)));
.toMap(FileRecordEntity::getFileId, o -> o)));
}
}
if (!CollectionUtils.isEmpty(topicIds)) {
// 查询话题标题
List<TopicEntity> topicEntities = topicService.queryByIds(topicIds);
List<TopicEntity> topicEntities =
topicService.queryByIds(setToList(topicIds));
if (!CollectionUtils.isEmpty(topicEntities)) {
topicMap.putAll(topicEntities.stream().collect(Collectors
.toMap(TopicEntity::getTopicId, TopicEntity::getTopicTitle)));
......@@ -233,10 +238,11 @@ public class ProductService {
}
if (!CollectionUtils.isEmpty(userIds)) {
// 查询用户信息
List<UserInfoEntity> userInfos = userInfoService.selectByIds(userIds);
List<UserInfoEntity> userInfos =
userInfoService.selectByIds(setToList(userIds));
if (!CollectionUtils.isEmpty(userIds)) {
userMap.putAll(userInfos.stream().collect(Collectors
.toMap(UserInfoEntity::getId, o->o)));
.toMap(UserInfoEntity::getId, o -> o)));
}
}
this.getFundInfo(tanpuFundIds, fundIds, publicFundIds, ifaFundIds, notNetFundIds, fundMap);
......@@ -250,11 +256,11 @@ public class ProductService {
* @param publicFundIds
* @param fundMap
*/
private void getFundInfo(List<String> tanpuFundIds,
List<String> fundIds,
List<String> publicFundIds,
List<String> ifaFundIds,
List<String> notNetFundIds,
private void getFundInfo(Set<String> tanpuFundIds,
Set<String> fundIds,
Set<String> publicFundIds,
Set<String> ifaFundIds,
Set<String> notNetFundIds,
Map<String, FundInfoBaseResp> fundMap) {
Map<String, FundInfoBaseResp> tampFundMap = null;
Map<String, FundInfoBaseResp> privateFundMap = null;
......@@ -266,7 +272,8 @@ public class ProductService {
// .fundIds(Lists.newArrayList(tanpuFundIds))
// .build();
// 探普产品
CommonResp<List<ProductInfoVO>> commonResp = feignForProduct.getProductInfoByIds(tanpuFundIds);
CommonResp<List<ProductInfoVO>> commonResp =
feignForProduct.getProductInfoByIds(setToList(tanpuFundIds));
if (commonResp.isSuccess() && !CollectionUtils.isEmpty(commonResp.getData())) {
List<FundInfoBaseResp> fundInfoBaseRespList = commonResp.getData().stream().map(item -> {
FundInfoBaseResp fundInfoBaseResp = FundInfoBaseResp.builder().build();
......@@ -283,7 +290,8 @@ public class ProductService {
// 私募产品
if (!CollectionUtils.isEmpty(fundIds)) {
// 私募产品
CommonResp<List<ProductInfoVO>> fundResult = feignForFund.getProductList(fundIds);
CommonResp<List<ProductInfoVO>> fundResult =
feignForFund.getProductList(setToList(fundIds));
if (fundResult.isSuccess() && !CollectionUtils.isEmpty(fundResult.getData())) {
List<FundInfoBaseResp> fundInfoBaseRespList = fundResult.getData().stream().map(item -> {
FundInfoBaseResp fundInfoBaseResp = FundInfoBaseResp.builder().build();
......@@ -300,7 +308,8 @@ public class ProductService {
// 理财师导入产品
if (!CollectionUtils.isEmpty(ifaFundIds)) {
CommonResp<List<ProductInfoVO>> ifaFundResult = feignForFund.getPrivateFundList(ifaFundIds);
CommonResp<List<ProductInfoVO>> ifaFundResult =
feignForFund.getPrivateFundList(setToList(ifaFundIds));
if (ifaFundResult.isSuccess() && !CollectionUtils.isEmpty(ifaFundResult.getData())) {
List<FundInfoBaseResp> fundInfoBaseRespList = ifaFundResult.getData().stream().map(item -> {
FundInfoBaseResp fundInfoBaseResp = FundInfoBaseResp.builder().build();
......@@ -317,7 +326,8 @@ public class ProductService {
if (!CollectionUtils.isEmpty(publicFundIds)) {
// 公募产品
CommonResp<List<ProductInfoVO>> publicFundResult = feignForPublicFund.getProductList(publicFundIds);
CommonResp<List<ProductInfoVO>> publicFundResult =
feignForPublicFund.getProductList(setToList(publicFundIds));
if (publicFundResult.isSuccess() && !CollectionUtils.isEmpty(publicFundResult.getData())) {
List<FundInfoBaseResp> fundInfoBaseRespList = publicFundResult.getData().stream().map(item -> {
FundInfoBaseResp fundInfoBaseResp = FundInfoBaseResp.builder().build();
......@@ -333,7 +343,8 @@ public class ProductService {
if (!CollectionUtils.isEmpty(notNetFundIds)) {
// 无净值产品
CommonResp<List<ProductInfoVO>> notNetInfoResult = feignForFund.getProductListNotNetInfo(notNetFundIds);
CommonResp<List<ProductInfoVO>> notNetInfoResult =
feignForFund.getProductListNotNetInfo(setToList(notNetFundIds));
if (notNetInfoResult.isSuccess() && !CollectionUtils.isEmpty(notNetInfoResult.getData())) {
List<FundInfoBaseResp> fundInfoBaseRespList = notNetInfoResult.getData().stream().map(item -> {
FundInfoBaseResp fundInfoBaseResp = FundInfoBaseResp.builder().build();
......@@ -408,7 +419,7 @@ public class ProductService {
if (imgUrlMap.containsKey(themeContent.getValue())) {
FileRecordEntity imgEntity = imgUrlMap.get(themeContent.getValue());
String extInfo = imgEntity.getExtInfo();
if (!StringUtils.isEmpty(extInfo)){
if (!StringUtils.isEmpty(extInfo)) {
Map<String, Object> extMap = JsonUtil.toMap(extInfo);
ImagesDTO imagesDTO = ImagesDTO.builder().imgHeight((Integer) extMap.get("height"))
.imgWidth((Integer) extMap.get("width"))
......@@ -419,11 +430,16 @@ public class ProductService {
}
}
}
}
}
}
private List<String> setToList(Set<String> set) {
List<String> l = new ArrayList<>();
l.addAll(set);
return l;
}
}
......@@ -47,14 +47,49 @@ public class ThemeService {
public List<ThemeEntity> queryThemeIdsByUserId(String userId) {
return themeMapper.selectList(new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getAuthorId,userId)
.eq(ThemeEntity::getDeleteTag,DeleteTagEnum.NOT_DELETED.getCode()));
.eq(ThemeEntity::getDeleteTag,DeleteTagEnum.NOT_DELETED.getCode())
.orderByDesc(ThemeEntity::getId));
}
public List<ThemeEntity> queryThemeIdsByUserId(String userId, String lastId,Integer pageSize) {
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getAuthorId, userId)
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())
.orderByDesc(ThemeEntity::getId);
if (StringUtils.isNotEmpty(lastId)) {
ThemeEntity lastEntity = queryByThemeId(lastId);
if (lastEntity==null) throw new BizException("主题未找到,id:"+lastId);
queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getCreateTime());
}
if (pageSize!=null){
queryWrapper.last("limit "+pageSize);
}
return themeMapper.selectList(queryWrapper);
}
//根据ids返回主题详情
public List<ThemeEntity> queryByThemeIds(List<String> themeIds, String lastId,Integer pageSize) {
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.in(ThemeEntity::getThemeId, themeIds)
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
if (StringUtils.isNotEmpty(lastId)) {
ThemeEntity lastEntity = queryByThemeId(lastId);
if (lastEntity==null) throw new BizException("主题未找到,id:"+lastId);
queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getCreateTime());
}
if (pageSize!=null){
queryWrapper.last("limit "+pageSize);
}
return themeMapper.selectList(queryWrapper);
}
//根据ids返回主题详情
public List<ThemeEntity> queryByThemeIds(List<String> themeIds) {
return themeMapper.selectList(new LambdaQueryWrapper<ThemeEntity>()
.in(ThemeEntity::getThemeId,themeIds)
.eq(ThemeEntity::getDeleteTag,DeleteTagEnum.NOT_DELETED.getCode()));
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.in(ThemeEntity::getThemeId, themeIds)
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
return themeMapper.selectList(queryWrapper);
}
//分页倒叙lastId之前的主题
......@@ -64,7 +99,7 @@ public class ThemeService {
if (StringUtils.isNotEmpty(lastId)) {
ThemeEntity lastEntity = queryByThemeId(lastId);
if (lastEntity==null) throw new BizException("主题未找到,id:"+lastId);
queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getUpdateTime());
queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getCreateTime());
}
queryWrapper.last("limit "+pageSize);
queryWrapper.orderByDesc(ThemeEntity::getId);
......@@ -79,13 +114,13 @@ public class ThemeService {
* @param pageSize 查询数量
* @return
*/
public List<ThemeEntity> queryByTopic(String topidId, String lastId,Integer pageSize) {
public List<ThemeEntity> queryByTopic(String topidId, String lastId, Integer pageSize) {
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getTopicId, topidId);
if (StringUtils.isNotEmpty(lastId)) {
ThemeEntity lastEntity = queryByThemeId(lastId);
if (lastEntity==null) throw new BizException("主题未找到,id:"+lastId);
queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getUpdateTime());
queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getCreateTime());
}
if (pageSize!=null){
queryWrapper.last("limit "+pageSize);
......@@ -114,7 +149,7 @@ public class ThemeService {
if (StringUtils.isNotEmpty(lastId)) {
ThemeEntity lastEntity = queryByThemeId(lastId);
if (lastEntity==null) throw new BizException("主题未找到,id:"+lastId);
queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getUpdateTime());
queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getCreateTime());
}
queryWrapper.last("limit "+pageSize);
......
......@@ -10,6 +10,7 @@ import com.tanpu.community.api.beans.req.theme.ThemeContentReq;
import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.api.enums.RelTypeEnum;
import com.tanpu.community.dao.entity.community.*;
import com.tanpu.community.dao.entity.user.UserInfoEntity;
import org.springframework.beans.BeanUtils;
import java.util.ArrayList;
......@@ -171,13 +172,15 @@ public class ConvertUtil {
return list;
}
public static FollowQo homePageEntity2FollowQo(HomePageEntity entity) {
public static FollowQo homePageEntity2FollowQo(UserInfoEntity entity) {
if (entity == null) {
return null;
}
FollowQo followQo = new FollowQo();
BeanUtils.copyProperties(entity, followQo);
return followQo;
return FollowQo.builder().userId(entity.getId())
.nickName(entity.getUiNickname())
.headImg(entity.getUiHeadimg())
.introduction(entity.getUiIntroduction())
.build();
}
......
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