Commit 1bd75841 authored by 吴泽佳's avatar 吴泽佳
parents 4961ff7c 1bc324ab
...@@ -20,4 +20,7 @@ public final class CommunityConstant { ...@@ -20,4 +20,7 @@ public final class CommunityConstant {
public static final String OSS_PREFIX_FOLDER ="community/"; public static final String OSS_PREFIX_FOLDER ="community/";
//图片压缩比例:50%
public static final String OSS_RESIZE_RATIO = "?x-oss-process=image/resize,p_50";
} }
...@@ -50,11 +50,23 @@ public class ThemeAnalysDO { ...@@ -50,11 +50,23 @@ public class ThemeAnalysDO {
private Double userWeight = 0.0; private Double userWeight = 0.0;
public Double getRank() { public Double getRank() {
double viewRatio = 0.1;
double forwardRatio = 3;
double commentRatio = 2;
double likeRation = 1;
double collectRatio = 3;
double userWeightRatio = 0.8;
double initialWeight = 1.0;
double timeRation = 0.3;
// 质量=帖子质量+用户质量 // 质量=帖子质量+用户质量
double w = (double) (viewCount * 0.1 + forwardCount * 3 + commentCount * 2 + likeCount * 1 + collectCount * 3) + userWeight; double w = viewCount * viewRatio + forwardCount * forwardRatio + commentCount * commentRatio
double i = 1; // 初始权重 + likeCount * likeRation + collectCount * collectRatio
+ Math.pow(userWeight, userWeightRatio);
double i = initialWeight; // 初始权重
double t = Double.valueOf(minuteTillNow) / 60; double t = Double.valueOf(minuteTillNow) / 60;
double g = 0.1; // 时间系数 double g = timeRation; // 时间系数
return (w + i) / Math.pow(t + 1, g); return (w + i) / Math.pow(t + 1, g);
} }
......
...@@ -10,11 +10,11 @@ import lombok.Data; ...@@ -10,11 +10,11 @@ import lombok.Data;
public class QueryFollowReq { public class QueryFollowReq {
@ApiModelProperty(value = "用户Id") @ApiModelProperty(value = "用户Id")
private String userId; public String userId;
@ApiModelProperty(value = "查询类型,1:粉丝 2:关注") @ApiModelProperty(value = "查询类型,1:粉丝 2:关注")
private Integer queryType; public Integer queryType;
@ApiModelProperty(value = "分页") @ApiModelProperty(value = "分页")
private Pageable page; public Pageable page;
} }
...@@ -22,6 +22,9 @@ public class ImagesDTO { ...@@ -22,6 +22,9 @@ public class ImagesDTO {
@ApiModelProperty("图片url") @ApiModelProperty("图片url")
private String remark; private String remark;
@ApiModelProperty("压缩图片url")
private String resizeUrl;
@ApiModelProperty("图片宽度") @ApiModelProperty("图片宽度")
private Integer imgHeight; private Integer imgHeight;
......
...@@ -2,32 +2,12 @@ package com.tanpu.community.api.constants; ...@@ -2,32 +2,12 @@ package com.tanpu.community.api.constants;
public class RedisKeyConstant { public class RedisKeyConstant {
//话题页浏览量
public static final String TOPIC_PAGE_VIEW_COUNT_ ="TOPIC_PAGE_VIEW_COUNT_";
//话题总浏览量=总浏览量+带这个话题的帖子量
public static final String TOPIC_TOTAL_VIEW_COUNT_="TOPIC_TOTAL_VIEW_COUNT_";
//点赞量 //点赞量
public static final String TOPIC_LIKE_COUNT_="TOPIC_LIKE_COUNT_"; public static final String THEME_LIKE_COUNT ="THEME_LIKE_COUNT_";
//收藏量 //收藏量
public static final String TOPIC_BOOK_COUNT_="TOPIC_BOOK_COUNT_"; public static final String THEME_COMMENT_COUNT ="THEME_COMMENT_COUNT_";
//用户数
public static final String TOPIC_USER_COUNT_="TOPIC_USER_COUNT_";
//讨论量=发布主题贴数+回复总数 //讨论量=发布主题贴数+回复总数
public static final String TOPIC_DISCUSS_COUNT_="TOPIC_DISCUSS_COUNT_"; public static final String THEME_FORWARD_COUNT ="THEME_FORWARD_COUNT_";
//发帖数
public static final String TOPIC_THEME_COUNT_="TOPIC_THEME_COUNT_";
//回帖数
public static final String TOPIC_COMMENT_COUNT_="TOPIC_COMMENT_COUNT_";
//总用户数=访问话题页+发帖+回帖(去重)
public static final String TOPIC_TOTAL_USER_COUNT_ ="TOPIC_TOTAL_USER_COUNT_";
//访问话题人数
public static final String TOPIC_USER_VIEW_COUNT_="TOPIC_USER_VIEW_COUNT_";
//发帖人数
public static final String TOPIC_POST_USER_COUNT_ ="TOPIC_POST_USER_COUNT_";
//回帖人数
public static final String TOPIC_COMMENT_USER_COUNT_ ="TOPIC_COMMENT_USER_COUNT_";
// 出现在用户的搜索列表中的主题id
public static final String THEME_APPEAR_IN_SEARCH_LIST = "THEME_APPEAR_IN_SEARCH_LIST_";
// feign 查询用户信息 // feign 查询用户信息
public static final String CACHE_FEIGN_USER_INFO = "CACHE_FEIGN_USER_INFO_"; public static final String CACHE_FEIGN_USER_INFO = "CACHE_FEIGN_USER_INFO_";
...@@ -38,12 +18,9 @@ public class RedisKeyConstant { ...@@ -38,12 +18,9 @@ public class RedisKeyConstant {
// 主题本身 // 主题本身
public static final String CACHE_THEME_ID = "CACHE_THEME_ID_"; public static final String CACHE_THEME_ID = "CACHE_THEME_ID_";
// 转发主题本身 // 转发主题本身
public static final String CACHE_FORMER_THEME_ID = "CACHE_FORMER_THEME_ID_"; public static final String CACHE_FORWARD_THEME_ID = "CACHE_FORWARD_THEME_ID_";
// 关注的人,上次浏览的最新主题last id // 关注的人,上次浏览的最新主题last id
public static final String CACHE_IDOL_THEME_LAST_ID = "CACHE_IDOL_THEME_LAST_ID_"; public static final String CACHE_IDOL_THEME_LAST_ID = "CACHE_IDOL_THEME_LAST_ID_";
public static final String THEME_VIEW_COUNT_="THEME_VIEW_COUNT_";
public static final String THEME_LIKE_COUNT_="THEME_LIKE_COUNT_";
public static final String THEME_BOOK_COUNT_="THEME_BOOK_COUNT_";
} }
...@@ -78,6 +78,7 @@ public class HomePageController { ...@@ -78,6 +78,7 @@ public class HomePageController {
@PostMapping(value = "/addIdol") @PostMapping(value = "/addIdol")
@ApiOperation("关注/取消关注他人") @ApiOperation("关注/取消关注他人")
@ResponseBody @ResponseBody
@AuthLogin
public CommonResp addIdol(@RequestBody FollowRelReq req) { public CommonResp addIdol(@RequestBody FollowRelReq req) {
String userId = userHolder.getUserId(); String userId = userHolder.getUserId();
homePageManager.addFollowRel(req, userId); homePageManager.addFollowRel(req, userId);
......
...@@ -31,7 +31,7 @@ public class TopicController { ...@@ -31,7 +31,7 @@ public class TopicController {
@PostMapping(value = "/list") @PostMapping(value = "/list")
@ApiOperation("APP全部话题页面,可搜索") @ApiOperation("APP全部话题页面,可搜索")
@ResponseBody @ResponseBody
public CommonResp<Page<TopicRankQo>> getTopicBriefInfoList(@RequestBody TopicSearchReq req){ public CommonResp<Page<TopicRankQo>> getTopicList(@RequestBody TopicSearchReq req){
return CommonResp.success(topicManager.getAllTopicBriefInfo(req)); return CommonResp.success(topicManager.getAllTopicBriefInfo(req));
} }
...@@ -39,7 +39,7 @@ public class TopicController { ...@@ -39,7 +39,7 @@ public class TopicController {
@GetMapping(value = "/detailPage") @GetMapping(value = "/detailPage")
@ApiOperation("话题详情页顶部") @ApiOperation("话题详情页顶部")
@ResponseBody @ResponseBody
public CommonResp<TopicRankQo> gethotThemes(@RequestParam String topicId){ public CommonResp<TopicRankQo> getDetail(@RequestParam String topicId){
return CommonResp.success(topicManager.getDetail(topicId)); return CommonResp.success(topicManager.getDetail(topicId));
} }
...@@ -47,7 +47,7 @@ public class TopicController { ...@@ -47,7 +47,7 @@ public class TopicController {
@GetMapping(value = "/titleList") @GetMapping(value = "/titleList")
@ApiOperation("首页顶部话题标题列") @ApiOperation("首页顶部话题标题列")
@ResponseBody @ResponseBody
public CommonResp<List<TopicRankQo>> getTitleList(){ public CommonResp<List<TopicRankQo>> getTop4Topic(){
return CommonResp.success(topicManager.getTop4TopicTitles()); return CommonResp.success(topicManager.getTop4TopicTitles());
} }
......
...@@ -53,6 +53,9 @@ public class CommentManager { ...@@ -53,6 +53,9 @@ public class CommentManager {
// 发表评论(对主题) // 发表评论(对主题)
public void comment(CreateCommentReq req, String userId) { public void comment(CreateCommentReq req, String userId) {
if (StringUtils.isEmpty(req.getComment())) {
throw new IllegalArgumentException("评论内容不能为空");
}
if (req.getComment().length()>500){ if (req.getComment().length()>500){
throw new IllegalArgumentException("评论内容不能超过500字"); throw new IllegalArgumentException("评论内容不能超过500字");
} }
......
package com.tanpu.community.manager; package com.tanpu.community.manager;
import com.tanpu.community.service.RankService; import com.tanpu.community.service.RankService;
import com.tanpu.community.service.RecommendService;
import com.tanpu.community.service.RedisService; import com.tanpu.community.service.RedisService;
import com.tanpu.community.service.VisitLogService; import com.tanpu.community.service.VisitLogService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -23,6 +24,9 @@ public class ConJobManager { ...@@ -23,6 +24,9 @@ public class ConJobManager {
@Autowired @Autowired
private RankService rankService; private RankService rankService;
@Autowired
private RecommendService recommendService;
/** /**
* 定时统计 话题 访问数据,并刷到redis * 定时统计 话题 访问数据,并刷到redis
*/ */
...@@ -36,9 +40,17 @@ public class ConJobManager { ...@@ -36,9 +40,17 @@ public class ConJobManager {
/** /**
* 定时统计主题、话题排行 * 定时统计主题、话题排行
*/ */
@Scheduled(cron = "0 */2 * * * ?") @Scheduled(cron = "*/30 * * * * ?")
public void themeRank() { public void themeRank() {
rankService.rankThemes(); rankService.rankThemes();
rankService.rankTopics(); rankService.rankTopics();
} }
/**
* 定时统计主题、话题排行
*/
@Scheduled(cron = "*/5 * * * * ?")
public void getThemeNewest() {
recommendService.refreshNewestThemes();
}
} }
...@@ -59,7 +59,8 @@ public class HomePageManager { ...@@ -59,7 +59,8 @@ public class HomePageManager {
//查询 个人中心 相关信息 //查询 个人中心 相关信息
public UserInfoResp queryUsersInfo(String userIdMyself, String userId) { public UserInfoResp queryUsersInfo(String userIdMyself, String userId) {
CommonResp<UserInfoResp> queryUsersListNew = feignClientForFatools.queryUsersListNew(StringUtils.isNotBlank(userId) ? userId : userIdMyself); CommonResp<UserInfoResp> queryUsersListNew = feignClientForFatools.queryUsersListNew(StringUtils.isNotBlank(userId) ? userId : userIdMyself);
if (queryUsersListNew.isNotSuccess() || !ObjectUtils.anyNotNull(queryUsersListNew.getData())) throw new BizException("内部接口调用失败"); if (queryUsersListNew.isNotSuccess() || !ObjectUtils.anyNotNull(queryUsersListNew.getData()))
throw new BizException("内部接口调用失败");
UserInfoResp userInfoNew = queryUsersListNew.getData(); UserInfoResp userInfoNew = queryUsersListNew.getData();
if (StringUtils.isNotBlank(userId) && !StringUtils.equals(userIdMyself, userId)) { //查询别人的个人主页 if (StringUtils.isNotBlank(userId) && !StringUtils.equals(userIdMyself, userId)) { //查询别人的个人主页
...@@ -95,7 +96,7 @@ public class HomePageManager { ...@@ -95,7 +96,7 @@ public class HomePageManager {
} }
// 查询首席投顾数量 // 查询首席投顾数量
CommonResp<Page<UserInfoNewChief>> pageCommonResp = feignClientForFatools.queryChiefFinancialAdviserList(1, 1); CommonResp<Page<UserInfoNewChief>> pageCommonResp = feignClientForFatools.queryChiefFinancialAdviserList(1, 1);
if (pageCommonResp.isSuccess()){ if (pageCommonResp.isSuccess()) {
userInfoNew.getUserInfoNewChief().setChiefCount(pageCommonResp.getData().getTotalSize()); userInfoNew.getUserInfoNewChief().setChiefCount(pageCommonResp.getData().getTotalSize());
} else { } else {
userInfoNew.getUserInfoNewChief().setChiefCount(0L); userInfoNew.getUserInfoNewChief().setChiefCount(0L);
...@@ -181,28 +182,32 @@ public class HomePageManager { ...@@ -181,28 +182,32 @@ public class HomePageManager {
/** /**
* 用户关注列表 * 用户关注列表
*
* @param req 目标用户 * @param req 目标用户
* @param userId 当前用户 * @param userId 当前用户
* @return * @return
*/ */
public Page<FollowQo> queryFollow(QueryFollowReq req, String userId) { public Page<FollowQo> queryFollow(QueryFollowReq req, String userId) {
//TODO 数据库分页 //数据库分页
List<String> userIds = QueryFollowTypeEnum.QUERY_FANS.getCode().equals(req.getQueryType()) ? Integer pageSize = req.page.pageSize;
followRelService.queryFansByIdolId(req.getUserId()) : followRelService.queryIdolsByFollowerId(req.getUserId()); Integer pageNumber = req.page.pageNumber;
Page<String> userIdsPage = QueryFollowTypeEnum.QUERY_FANS.getCode().equals(req.getQueryType()) ?
followRelService.queryFansByIdolId(req.userId, pageNumber, pageSize)
: followRelService.queryIdolsByFansId(req.userId, pageNumber, pageSize);
List<FollowQo> followQos = new ArrayList<>(); List<FollowQo> followQos = new ArrayList<>();
if (!CollectionUtils.isEmpty(userIds)) { if (!CollectionUtils.isEmpty(userIdsPage.getContent())) {
List<UserInfoResp> userInfoNews = feignClientForFatools.queryUserListNew(userIds); List<UserInfoResp> userInfoNews = feignClientForFatools.queryUserListNew(userIdsPage.getContent());
List<FollowQo> collect = userInfoNews.stream().map(ConvertUtil::userInfoNew2FollowQo).collect(Collectors.toList()); List<FollowQo> collect = userInfoNews.stream().map(ConvertUtil::userInfoNew2FollowQo).collect(Collectors.toList());
followQos = judgeFollowed(collect, userId); followQos = judgeFollowed(collect, userId);
} }
//分页 return PageUtils.page(userIdsPage,followQos);
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.queryIdolsByFollowerId(followerId)); Set<String> idolSet = new HashSet<>(followRelService.queryIdolsByFansId(followerId));
return followQos.stream().map(o -> { return followQos.stream().map(o -> {
if (idolSet.contains(o.getUserId())) { if (idolSet.contains(o.getUserId())) {
o.setFollowed(true); o.setFollowed(true);
......
package com.tanpu.community.manager; package com.tanpu.community.manager;
import com.tanpu.common.auth.UserHolder; import com.tanpu.common.constant.ErrorCodeConstant;
import com.tanpu.common.exception.BizException;
import com.tanpu.community.api.beans.qo.TopicRankQo; import com.tanpu.community.api.beans.qo.TopicRankQo;
import com.tanpu.community.api.beans.req.page.Page; import com.tanpu.community.api.beans.req.page.Page;
import com.tanpu.community.api.beans.req.topic.TopicSearchReq; import com.tanpu.community.api.beans.req.topic.TopicSearchReq;
import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.service.RankService; import com.tanpu.community.service.RankService;
import com.tanpu.community.service.TopicService; import com.tanpu.community.service.TopicService;
import com.tanpu.community.service.VisitLogService;
import com.tanpu.community.util.PageUtils; import com.tanpu.community.util.PageUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List; import java.util.List;
import static com.tanpu.biz.common.enums.clue.PageEnum.COMM_VISIT_TOPIC_DETAIL;
@Service @Service
public class TopicManager { public class TopicManager {
@Autowired @Autowired
private VisitLogService visitLogService; private TopicService topicService;
@Autowired @Autowired
private RankService rankService; private RankService rankService;
@Resource
private UserHolder userHolder;
// 首页-话题标签 // 首页-话题标签
...@@ -43,10 +39,11 @@ public class TopicManager { ...@@ -43,10 +39,11 @@ public class TopicManager {
} }
// 话题详情页 // 话题详情页
public TopicRankQo getDetail(String topicId) { public TopicRankQo getDetail(String topicId) {
//TODO 临时埋点,接入新埋点后删除 TopicEntity topicEntity = topicService.queryById(topicId);
visitLogService.addPageView(userHolder.getUserId(), topicId, COMM_VISIT_TOPIC_DETAIL); if (topicEntity==null){
throw new BizException(ErrorCodeConstant.TOPIC_NOT_FOUND);
}
return rankService.getTopicDetail(topicId); return rankService.getTopicDetail(topicId);
} }
......
...@@ -7,6 +7,7 @@ import com.tanpu.biz.common.enums.user.UserLevelEnum; ...@@ -7,6 +7,7 @@ import com.tanpu.biz.common.enums.user.UserLevelEnum;
import com.tanpu.common.api.CommonResp; import com.tanpu.common.api.CommonResp;
import com.tanpu.common.enums.fund.ProductTypeEnum; import com.tanpu.common.enums.fund.ProductTypeEnum;
import com.tanpu.common.util.JsonUtil; import com.tanpu.common.util.JsonUtil;
import com.tanpu.community.api.CommunityConstant;
import com.tanpu.community.api.beans.qo.AttachmentDetailVo; import com.tanpu.community.api.beans.qo.AttachmentDetailVo;
import com.tanpu.community.api.beans.qo.ThemeContentQo; import com.tanpu.community.api.beans.qo.ThemeContentQo;
import com.tanpu.community.api.beans.qo.ThemeQo; import com.tanpu.community.api.beans.qo.ThemeQo;
...@@ -258,10 +259,10 @@ public class BatchFeignCallService { ...@@ -258,10 +259,10 @@ public class BatchFeignCallService {
Set<String> ifaFundIds, Set<String> ifaFundIds,
Set<String> notNetFundIds, Set<String> notNetFundIds,
Map<String, FundInfoBaseResp> fundMap) { Map<String, FundInfoBaseResp> fundMap) {
Map<String, FundInfoBaseResp> tampFundMap = null; Map<String, FundInfoBaseResp> tampFundMap;
Map<String, FundInfoBaseResp> privateFundMap = null; Map<String, FundInfoBaseResp> privateFundMap;
Map<String, FundInfoBaseResp> publicFundMap = null; Map<String, FundInfoBaseResp> publicFundMap;
Map<String, FundInfoBaseResp> ifaFundMap = null; Map<String, FundInfoBaseResp> ifaFundMap;
Map<String, FundInfoBaseResp> notNetFundMap = null; Map<String, FundInfoBaseResp> notNetFundMap = null;
if (!CollectionUtils.isEmpty(tanpuFundIds)) { if (!CollectionUtils.isEmpty(tanpuFundIds)) {
// ProductListReq productListReq = ProductListReq.builder() // ProductListReq productListReq = ProductListReq.builder()
...@@ -276,7 +277,7 @@ public class BatchFeignCallService { ...@@ -276,7 +277,7 @@ public class BatchFeignCallService {
}).collect(Collectors.toList()); }).collect(Collectors.toList());
tampFundMap = fundInfoBaseRespList.stream().collect(Collectors.toMap(FundInfoBaseResp::getFundId, item -> item)); tampFundMap = fundInfoBaseRespList.stream().collect(Collectors.toMap(FundInfoBaseResp::getFundId, item -> item));
if (tampFundMap != null && tampFundMap.size() > 0) { if (tampFundMap.size() > 0) {
fundMap.putAll(tampFundMap); fundMap.putAll(tampFundMap);
} }
} }
...@@ -291,7 +292,7 @@ public class BatchFeignCallService { ...@@ -291,7 +292,7 @@ public class BatchFeignCallService {
}).collect(Collectors.toList()); }).collect(Collectors.toList());
privateFundMap = fundInfoBaseRespList.stream().collect(Collectors.toMap(FundInfoBaseResp::getFundId, item -> item)); privateFundMap = fundInfoBaseRespList.stream().collect(Collectors.toMap(FundInfoBaseResp::getFundId, item -> item));
if (privateFundMap != null && privateFundMap.size() > 0) { if (privateFundMap.size() > 0) {
fundMap.putAll(privateFundMap); fundMap.putAll(privateFundMap);
} }
} }
...@@ -307,7 +308,7 @@ public class BatchFeignCallService { ...@@ -307,7 +308,7 @@ public class BatchFeignCallService {
ifaFundMap = fundInfoBaseRespList.stream().collect(Collectors.toMap(FundInfoBaseResp::getFundId, item -> item)); ifaFundMap = fundInfoBaseRespList.stream().collect(Collectors.toMap(FundInfoBaseResp::getFundId, item -> item));
if (ifaFundMap != null && ifaFundMap.size() > 0) { if (ifaFundMap.size() > 0) {
fundMap.putAll(ifaFundMap); fundMap.putAll(ifaFundMap);
} }
} }
...@@ -322,7 +323,7 @@ public class BatchFeignCallService { ...@@ -322,7 +323,7 @@ public class BatchFeignCallService {
}).collect(Collectors.toList()); }).collect(Collectors.toList());
publicFundMap = fundInfoBaseRespList.stream().collect(Collectors.toMap(FundInfoBaseResp::getFundId, item -> item)); publicFundMap = fundInfoBaseRespList.stream().collect(Collectors.toMap(FundInfoBaseResp::getFundId, item -> item));
if (publicFundMap != null && publicFundMap.size() > 0) { if (publicFundMap.size() > 0) {
fundMap.putAll(publicFundMap); fundMap.putAll(publicFundMap);
} }
} }
...@@ -427,19 +428,20 @@ public class BatchFeignCallService { ...@@ -427,19 +428,20 @@ public class BatchFeignCallService {
//单图封装到imglist列表中 //单图封装到imglist列表中
if (imgUrlMap.containsKey(themeContent.getValue())) { if (imgUrlMap.containsKey(themeContent.getValue())) {
FileRecordEntity imgEntity = imgUrlMap.get(themeContent.getValue()); FileRecordEntity imgEntity = imgUrlMap.get(themeContent.getValue());
String extInfo = imgEntity.getExtInfo(); if (imgEntity!=null && !StringUtils.isEmpty(imgEntity.getExtInfo())) {
if (!StringUtils.isEmpty(extInfo)) { Map<String, Object> extMap = JsonUtil.toMap(imgEntity.getExtInfo());
Map<String, Object> extMap = JsonUtil.toMap(extInfo);
ImagesDTO imagesDTO = ImagesDTO.builder().imgHeight((Integer) extMap.get("height")) ImagesDTO imagesDTO = ImagesDTO.builder().imgHeight((Integer) extMap.get("height"))
.imgWidth((Integer) extMap.get("width")) .imgWidth((Integer) extMap.get("width"))
.remark(imgEntity.getUrl()) .remark(imgEntity.getUrl())
.relId(imgEntity.getFileId()) .relId(imgEntity.getFileId())
//压缩图片
.resizeUrl(imgEntity.getUrl() + CommunityConstant.OSS_RESIZE_RATIO)
.build(); .build();
themeContent.setImgList(Collections.singletonList(imagesDTO)); themeContent.setImgList(Collections.singletonList(imagesDTO));
} }
} }
} else if (themeContent.getType().equals(RelTypeEnum.MULTIPLE_IMAGE.type)) { } else if (themeContent.getType().equals(RelTypeEnum.MULTIPLE_IMAGE.type)) {
//多图写入图片宽高 //多图写入图片宽高,压缩图片url
List<ImagesDTO> imgList = themeContent.getImgList(); List<ImagesDTO> imgList = themeContent.getImgList();
for (ImagesDTO imagesDTO : imgList) { for (ImagesDTO imagesDTO : imgList) {
if (imgUrlMap.containsKey(imagesDTO.getRelId())) { if (imgUrlMap.containsKey(imagesDTO.getRelId())) {
...@@ -450,6 +452,8 @@ public class BatchFeignCallService { ...@@ -450,6 +452,8 @@ public class BatchFeignCallService {
imagesDTO.setImgHeight((Integer) extMap.get("height")); imagesDTO.setImgHeight((Integer) extMap.get("height"));
imagesDTO.setImgWidth((Integer) extMap.get("width")); imagesDTO.setImgWidth((Integer) extMap.get("width"));
} }
//压缩图片地址
imagesDTO.setResizeUrl(imgEntity.getUrl() + CommunityConstant.OSS_RESIZE_RATIO);
} }
} }
......
...@@ -7,12 +7,18 @@ import com.tanpu.community.dao.entity.community.CollectionEntity; ...@@ -7,12 +7,18 @@ import com.tanpu.community.dao.entity.community.CollectionEntity;
import com.tanpu.community.dao.entity.community.TimesCountEntity; import com.tanpu.community.dao.entity.community.TimesCountEntity;
import com.tanpu.community.dao.mapper.community.CollectionMapper; import com.tanpu.community.dao.mapper.community.CollectionMapper;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
...@@ -48,7 +54,7 @@ public class CollectionService { ...@@ -48,7 +54,7 @@ public class CollectionService {
//根据用户、主题、类型查询未删除对象 //根据用户、主题、类型查询未删除对象
public CollectionEntity getTarget(String targetId, String userId, CollectionTypeEnum type) { public CollectionEntity queryCollection(String targetId, String userId, CollectionTypeEnum type) {
LambdaQueryWrapper<CollectionEntity> queryWrapper = new LambdaQueryWrapper<CollectionEntity>() LambdaQueryWrapper<CollectionEntity> queryWrapper = new LambdaQueryWrapper<CollectionEntity>()
.eq(CollectionEntity::getCollectionType, type.getCode()) .eq(CollectionEntity::getCollectionType, type.getCode())
.eq(CollectionEntity::getUserId, userId) .eq(CollectionEntity::getUserId, userId)
...@@ -57,6 +63,15 @@ public class CollectionService { ...@@ -57,6 +63,15 @@ public class CollectionService {
return collectionMapper.selectOne(queryWrapper); return collectionMapper.selectOne(queryWrapper);
} }
//根据用户、主题、类型查询未删除对象
public CollectionEntity queryIncludeDelete(String targetId, String userId, CollectionTypeEnum type) {
LambdaQueryWrapper<CollectionEntity> queryWrapper = new LambdaQueryWrapper<CollectionEntity>()
.eq(CollectionEntity::getCollectionType, type.getCode())
.eq(CollectionEntity::getUserId, userId)
.eq(CollectionEntity::getTargetId, targetId);
return collectionMapper.selectOne(queryWrapper);
}
//根据用户、主题、类型查询未删除对象 //根据用户、主题、类型查询未删除对象
public Set<String> getTargets(List<String> targetIds, String userId, CollectionTypeEnum type) { public Set<String> getTargets(List<String> targetIds, String userId, CollectionTypeEnum type) {
if (CollectionUtils.isEmpty(targetIds)){ if (CollectionUtils.isEmpty(targetIds)){
...@@ -91,6 +106,27 @@ public class CollectionService { ...@@ -91,6 +106,27 @@ public class CollectionService {
.stream().map(CollectionEntity::getTargetId).collect(Collectors.toList()); .stream().map(CollectionEntity::getTargetId).collect(Collectors.toList());
} }
// 根据用户id和行为type获取target_id列表
public List<String> getListByUser(String userId, CollectionTypeEnum type,String lastId,Integer pageSize) {
LambdaQueryWrapper<CollectionEntity> queryWrapper = new LambdaQueryWrapper<CollectionEntity>()
.eq(CollectionEntity::getUserId, userId)
.eq(CollectionEntity::getCollectionType, type.getCode())
.eq(CollectionEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())
.orderByDesc(CollectionEntity::getCollectionTime);
if (StringUtils.isNotEmpty(lastId)) {
CollectionEntity target = queryIncludeDelete(lastId, userId, type);
if (target == null) return Collections.emptyList();
queryWrapper.lt(CollectionEntity::getCollectionType, target.getCollectionTime());
}
if (pageSize != null) {
queryWrapper.last("limit " + pageSize);
}
return collectionMapper.selectList(queryWrapper)
.stream().map(CollectionEntity::getTargetId).collect(Collectors.toList());
}
// 统计单个对象(主题、评论)的数量(点赞、收藏) // 统计单个对象(主题、评论)的数量(点赞、收藏)
public Integer getCountByTypeAndId(String targetId, CollectionTypeEnum type) { public Integer getCountByTypeAndId(String targetId, CollectionTypeEnum type) {
...@@ -123,7 +159,7 @@ public class CollectionService { ...@@ -123,7 +159,7 @@ public class CollectionService {
//逻辑删除,修改delete_tag //逻辑删除,修改delete_tag
@Transactional @Transactional
public void delete(String themeId, String userId, CollectionTypeEnum type) { public void delete(String themeId, String userId, CollectionTypeEnum type) {
CollectionEntity queryCollection = getTarget(themeId, userId, type); CollectionEntity queryCollection = queryCollection(themeId, userId, type);
if (queryCollection != null) { if (queryCollection != null) {
queryCollection.setDeleteTag(DeleteTagEnum.DELETED.getCode()); queryCollection.setDeleteTag(DeleteTagEnum.DELETED.getCode());
queryCollection.setUncollectionTime(LocalDateTime.now()); queryCollection.setUncollectionTime(LocalDateTime.now());
......
...@@ -109,7 +109,7 @@ public class CommentService { ...@@ -109,7 +109,7 @@ public class CommentService {
CommentEntity commentEntity = commentMapper.selectOne(new LambdaQueryWrapper<CommentEntity>() CommentEntity commentEntity = commentMapper.selectOne(new LambdaQueryWrapper<CommentEntity>()
.eq(CommentEntity::getCommentId, lastId)); .eq(CommentEntity::getCommentId, lastId));
if (commentEntity == null) throw new BizException("评论未找到,id:" + lastId); if (commentEntity == null) throw new BizException("评论未找到,id:" + lastId);
queryWrapper.lt(CommentEntity::getUpdateTime, commentEntity.getCreateTime()); queryWrapper.lt(CommentEntity::getCreateTime, commentEntity.getCreateTime());
} }
if (pageSize != null) { if (pageSize != null) {
queryWrapper.last("limit " + pageSize); queryWrapper.last("limit " + pageSize);
...@@ -145,8 +145,12 @@ public class CommentService { ...@@ -145,8 +145,12 @@ public class CommentService {
// 失效关联主题缓存 // 失效关联主题缓存
private void evictThemeCache(String themeId){ private void evictThemeCache(String themeId){
// 评论内容
redisCache.evict(StringUtils.joinWith("_", CACHE_COMMENT_THEMEID, themeId)); redisCache.evict(StringUtils.joinWith("_", CACHE_COMMENT_THEMEID, themeId));
// 主题内容
redisCache.evict(StringUtils.joinWith("_", CACHE_THEME_ID, themeId)); redisCache.evict(StringUtils.joinWith("_", CACHE_THEME_ID, themeId));
// 评论数
redisCache.evict(StringUtils.joinWith("_", THEME_LIKE_COUNT, themeId));
} }
} }
package com.tanpu.community.service; package com.tanpu.community.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanpu.common.constant.BizStatus;
import com.tanpu.common.exception.BizException; import com.tanpu.common.exception.BizException;
import com.tanpu.community.api.beans.req.page.Page;
import com.tanpu.community.api.enums.DeleteTagEnum; import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.dao.entity.community.FollowRelEntity; import com.tanpu.community.dao.entity.community.FollowRelEntity;
import com.tanpu.community.dao.mapper.community.FollowRelMapper; import com.tanpu.community.dao.mapper.community.FollowRelMapper;
...@@ -21,7 +23,7 @@ public class FollowRelService { ...@@ -21,7 +23,7 @@ public class FollowRelService {
@Resource @Resource
private FollowRelMapper followRelMapper; private FollowRelMapper followRelMapper;
public List<String> queryIdolsByFollowerId(String followerId) { public List<String> queryIdolsByFansId(String followerId) {
return followRelMapper.selectList(new LambdaQueryWrapper<FollowRelEntity>() return followRelMapper.selectList(new LambdaQueryWrapper<FollowRelEntity>()
.eq(FollowRelEntity::getFansId, followerId) .eq(FollowRelEntity::getFansId, followerId)
.eq(FollowRelEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())) .eq(FollowRelEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()))
...@@ -29,19 +31,55 @@ public class FollowRelService { ...@@ -29,19 +31,55 @@ public class FollowRelService {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
// @Cacheable(value = "tempCache", keyGenerator = "communityKeyGenerator") public Page<String> queryIdolsByFansId(String fansId, Integer pageNum, Integer pageSize) {
public List<String> queryFansByIdolId(String idolId) { Integer pageStart = (pageNum - 1) * pageSize;
List<FollowRelEntity> idols = followRelMapper.selectList(new LambdaQueryWrapper<FollowRelEntity>()
.eq(FollowRelEntity::getFansId, fansId)
.last("limit " + pageStart + ", " + pageSize)
.eq(FollowRelEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()));
List<String> list = idols.stream().map(FollowRelEntity::getIdolId)
.collect(Collectors.toList());
Integer totalSize = followRelMapper.selectCount(new LambdaQueryWrapper<FollowRelEntity>().eq(FollowRelEntity::getFansId,fansId)
.eq(FollowRelEntity::getDeleteTag, BizStatus.DeleteTag.tag_init));
Page<String> tPage = new Page<>(pageNum, pageSize, (long) totalSize, 0, list);
int totalPage = list.size() / pageSize;
if (list.size() % pageSize == 0) {
tPage.setTotalPages(totalPage);
} else {
tPage.setTotalPages(totalPage + 1);
}
return tPage;
}
public Page<String> queryFansByIdolId(String idolId, Integer pageNum, Integer pageSize) {
Integer pageStart = (pageNum - 1) * pageSize;
LambdaQueryWrapper<FollowRelEntity> queryWrapper = new LambdaQueryWrapper<FollowRelEntity>() LambdaQueryWrapper<FollowRelEntity> queryWrapper = new LambdaQueryWrapper<FollowRelEntity>()
.eq(FollowRelEntity::getIdolId, idolId) .eq(FollowRelEntity::getIdolId, idolId)
.last("limit " + pageStart + ", " + pageSize)
.eq(FollowRelEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()); .eq(FollowRelEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
return followRelMapper.selectList(queryWrapper) List<String> list = followRelMapper.selectList(queryWrapper)
.stream().map(FollowRelEntity::getFansId).collect(Collectors.toList()); .stream().map(FollowRelEntity::getFansId).collect(Collectors.toList());
// 分页
Integer totalSize = followRelMapper.selectCount(new LambdaQueryWrapper<FollowRelEntity>().eq(FollowRelEntity::getIdolId, idolId)
.eq(FollowRelEntity::getDeleteTag, BizStatus.DeleteTag.tag_init));
Page<String> tPage = new Page<>(pageNum, pageSize, (long) totalSize, 0, list);
int totalPage = list.size() / pageSize;
if (list.size() % pageSize == 0) {
tPage.setTotalPages(totalPage);
} else {
tPage.setTotalPages(totalPage + 1);
}
return tPage;
} }
@Transactional @Transactional
public void addFollowRel(String idolId, String followerId) { public void addFollowRel(String idolId, String followerId) {
FollowRelEntity searchResult = queryRecord(idolId, followerId); FollowRelEntity searchResult = queryRecord(idolId, followerId);
if (searchResult==null){ if (searchResult == null) {
FollowRelEntity entity = FollowRelEntity.builder() FollowRelEntity entity = FollowRelEntity.builder()
.idolId(idolId) .idolId(idolId)
.fansId(followerId) .fansId(followerId)
...@@ -49,7 +87,7 @@ public class FollowRelService { ...@@ -49,7 +87,7 @@ public class FollowRelService {
.build(); .build();
followRelMapper.insert(entity); followRelMapper.insert(entity);
}else { } else {
searchResult.setFollowTime(LocalDateTime.now()); searchResult.setFollowTime(LocalDateTime.now());
searchResult.setDeleteTag(DeleteTagEnum.NOT_DELETED.getCode()); searchResult.setDeleteTag(DeleteTagEnum.NOT_DELETED.getCode());
followRelMapper.updateById(searchResult); followRelMapper.updateById(searchResult);
...@@ -59,13 +97,14 @@ public class FollowRelService { ...@@ -59,13 +97,14 @@ public class FollowRelService {
/** /**
* 逻辑删除关注关系 * 逻辑删除关注关系
*
* @param idolId * @param idolId
* @param followerId * @param followerId
*/ */
@Transactional @Transactional
public void deleteFollowRel(String idolId, String followerId) { public void deleteFollowRel(String idolId, String followerId) {
FollowRelEntity searchResult = queryRecord(idolId, followerId); FollowRelEntity searchResult = queryRecord(idolId, followerId);
if (searchResult==null){ if (searchResult == null) {
throw new BizException("未找到关注关系"); throw new BizException("未找到关注关系");
} }
searchResult.setUnfollowTime(LocalDateTime.now()); searchResult.setUnfollowTime(LocalDateTime.now());
...@@ -73,18 +112,18 @@ public class FollowRelService { ...@@ -73,18 +112,18 @@ public class FollowRelService {
followRelMapper.updateById(searchResult); followRelMapper.updateById(searchResult);
} }
public FollowRelEntity queryRecord(String idolId, String followerId){ public FollowRelEntity queryRecord(String idolId, String followerId) {
return followRelMapper.selectOne(new LambdaQueryWrapper<FollowRelEntity>() return followRelMapper.selectOne(new LambdaQueryWrapper<FollowRelEntity>()
.eq(FollowRelEntity::getIdolId,idolId) .eq(FollowRelEntity::getIdolId, idolId)
.eq(FollowRelEntity::getFansId,followerId)); .eq(FollowRelEntity::getFansId, followerId));
} }
public boolean checkFollow(String idolId,String followerId){ public boolean checkFollow(String idolId, String followerId) {
return followRelMapper.selectCount(new LambdaQueryWrapper<FollowRelEntity>() return followRelMapper.selectCount(new LambdaQueryWrapper<FollowRelEntity>()
.eq(FollowRelEntity::getIdolId,idolId) .eq(FollowRelEntity::getIdolId, idolId)
.eq(FollowRelEntity::getFansId,followerId) .eq(FollowRelEntity::getFansId, followerId)
.eq(FollowRelEntity::getDeleteTag,DeleteTagEnum.NOT_DELETED.getCode())) .eq(FollowRelEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()))
>0; > 0;
} }
......
...@@ -129,26 +129,28 @@ public class RecommendService { ...@@ -129,26 +129,28 @@ public class RecommendService {
int newTimes = newRatio; int newTimes = newRatio;
int recTimes = pythonRatio; int recTimes = pythonRatio;
String id; String id;
while (hotTimes > 0 && hotThemeIds.size() > hotIdx) { while (newTimes > 0 && newThemeIds.size() > newIdx) {
id = hotThemeIds.get(hotIdx); id = newThemeIds.get(newIdx);
if (!set.contains(id)) { if (!set.contains(id)) {
result.add(id); result.add(id);
set.add(id); set.add(id);
} }
hotIdx++; newIdx++;
hotTimes--; newTimes--;
} }
while (newTimes > 0 && newThemeIds.size() > newIdx) {
id = newThemeIds.get(newIdx); while (hotTimes > 0 && hotThemeIds.size() > hotIdx) {
id = hotThemeIds.get(hotIdx);
if (!set.contains(id)) { if (!set.contains(id)) {
result.add(id); result.add(id);
set.add(id); set.add(id);
} }
newIdx++; hotIdx++;
newTimes--; hotTimes--;
} }
while (recTimes > 0 && recThemeIds.size() > recIdx) { while (recTimes > 0 && recThemeIds.size() > recIdx) {
id = recThemeIds.get(recIdx); id = recThemeIds.get(recIdx);
if (!set.contains(id)) { if (!set.contains(id)) {
...@@ -170,15 +172,14 @@ public class RecommendService { ...@@ -170,15 +172,14 @@ public class RecommendService {
int round = 0; int round = 0;
while (true) { while (true) {
int hotStart = round * 6; int hotStart = round * 3;
int newestStart = round * 3; int newestStart = round * 6;
int recmdStart = round; int recmdStart = round;
if (hotStart >= hotIds.size() && newestStart >= newestIds.size() && recmdStart >= recmdIds.size()) { if (hotStart >= hotIds.size() && newestStart >= newestIds.size() && recmdStart >= recmdIds.size()) {
break; break;
} }
retList.addAll(BizUtils.subList(hotIds, hotStart, hotStart + 6));
retList.addAll(BizUtils.subList(newestIds, newestStart, newestStart + 3)); retList.addAll(BizUtils.subList(newestIds, newestStart, newestStart + 3));
retList.addAll(BizUtils.subList(hotIds, hotStart, hotStart + 6));
retList.addAll(BizUtils.subList(recmdIds, recmdStart, recmdStart + 1)); retList.addAll(BizUtils.subList(recmdIds, recmdStart, recmdStart + 1));
round++; round++;
......
...@@ -18,8 +18,12 @@ import org.springframework.stereotype.Service; ...@@ -18,8 +18,12 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDateTime; import java.util.Collections;
import java.util.*; import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
...@@ -73,15 +77,15 @@ public class ThemeService { ...@@ -73,15 +77,15 @@ public class ThemeService {
} }
//根据用户id查询主题list //根据用户id查询主题list
public List<ThemeEntity> queryThemesByUserId(String userId, String lastId, Integer pageSize) { public List<ThemeEntity> queryThemesByUserIdCreateDesc(String userId, String lastId, Integer pageSize) {
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>() LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getAuthorId, userId) .eq(ThemeEntity::getAuthorId, userId)
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()) .eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())
.orderByDesc(ThemeEntity::getId); .orderByDesc(ThemeEntity::getCreateTime);
if (StringUtils.isNotEmpty(lastId)) { if (StringUtils.isNotEmpty(lastId)) {
ThemeEntity lastEntity = queryByThemeId(lastId); ThemeEntity lastEntity = queryByThemeId(lastId);
if (lastEntity == null) throw new BizException("主题未找到,id:" + lastId); if (lastEntity == null) throw new BizException("主题未找到,id:" + lastId);
queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getCreateTime()); queryWrapper.lt(ThemeEntity::getCreateTime, lastEntity.getCreateTime());
} }
if (pageSize != null) { if (pageSize != null) {
queryWrapper.last("limit " + pageSize); queryWrapper.last("limit " + pageSize);
...@@ -100,7 +104,7 @@ public class ThemeService { ...@@ -100,7 +104,7 @@ public class ThemeService {
if (StringUtils.isNotEmpty(lastId)) { if (StringUtils.isNotEmpty(lastId)) {
ThemeEntity lastEntity = queryByThemeId(lastId); ThemeEntity lastEntity = queryByThemeId(lastId);
if (lastEntity == null) throw new BizException("主题未找到,id:" + lastId); if (lastEntity == null) throw new BizException("主题未找到,id:" + lastId);
queryWrapper.lt(ThemeEntity::getUpdateTime, lastEntity.getCreateTime()); queryWrapper.lt(ThemeEntity::getCreateTime, lastEntity.getCreateTime());
} }
if (pageSize != null) { if (pageSize != null) {
queryWrapper.last("limit " + pageSize); queryWrapper.last("limit " + pageSize);
...@@ -126,67 +130,6 @@ public class ThemeService { ...@@ -126,67 +130,6 @@ public class ThemeService {
} }
/**
* 查询非传入作者的主题(可分页)
*
* @param lastId
* @param pageSize
* @param userId
* @return
*/
public List<ThemeEntity> selectExcludeUser(String userId, String lastId, Integer pageSize) {
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<>();
if (!StringUtils.isEmpty(userId)) {
queryWrapper.ne(ThemeEntity::getAuthorId, userId);
}
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);
}
queryWrapper.orderByDesc(ThemeEntity::getId);
queryWrapper.orderByDesc(ThemeEntity::getCreateTime);
queryWrapper.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
return themeMapper.selectList(queryWrapper);
}
/**
* 查询非传入作者的主题(可分页)
*
* @param lastId
* @param pageSize
* @param userId
* @return
*/
public List<ThemeEntity> queryByThemeIdsExcludeUser(List<String> themeIds, String userId, String lastId, Integer pageSize) {
if (CollectionUtils.isEmpty(themeIds)) {
return Collections.emptyList();
}
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.in(ThemeEntity::getThemeId, themeIds);
if (!StringUtils.isEmpty(userId)) {
queryWrapper.ne(ThemeEntity::getAuthorId, userId);
}
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);
}
queryWrapper.orderByDesc(ThemeEntity::getId);
queryWrapper.orderByDesc(ThemeEntity::getCreateTime);
queryWrapper.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
return themeMapper.selectList(queryWrapper);
}
/** /**
...@@ -230,7 +173,6 @@ public class ThemeService { ...@@ -230,7 +173,6 @@ public class ThemeService {
if (CollectionUtils.isEmpty(userIds)){ if (CollectionUtils.isEmpty(userIds)){
return Collections.emptyList(); return Collections.emptyList();
} }
//TODO 索引优化
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>() LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.in(ThemeEntity::getAuthorId, userIds) .in(ThemeEntity::getAuthorId, userIds)
.last("limit " + pageStart + ", " + pageSize) .last("limit " + pageStart + ", " + pageSize)
......
...@@ -75,7 +75,10 @@ public class TopicService { ...@@ -75,7 +75,10 @@ public class TopicService {
} }
public TopicEntity queryById(String topicId) { public TopicEntity queryById(String topicId) {
return topicMapper.selectOne(new LambdaQueryWrapper<TopicEntity>().eq(TopicEntity::getTopicId, topicId)); return topicMapper.selectOne(new LambdaQueryWrapper<TopicEntity>()
.eq(TopicEntity::getTopicId, topicId)
.eq(TopicEntity::getIsConceal, StatusEnum.FALSE)
.eq(TopicEntity::getDeleteTag, StatusEnum.FALSE));
} }
public List<TopicEntity> queryByIds(List<String> topicIds) { public List<TopicEntity> queryByIds(List<String> topicIds) {
......
...@@ -12,12 +12,14 @@ import java.util.List; ...@@ -12,12 +12,14 @@ import java.util.List;
* @email: zhoupeng@wealthgrow.cn * @email: zhoupeng@wealthgrow.cn
*/ */
public class PageUtils { public class PageUtils {
public static <T> Page<T> page(Pageable pageable, List<T> list) { public static <T> Page<T> page(Pageable pageable, List<T> list) {
if (CollectionUtils.isEmpty(list)) { if (CollectionUtils.isEmpty(list)) {
if(pageable==null){ if(pageable==null){
return new Page<T>(1,0, (long)list.size(),1, list); return new Page<T>(1,0, (long)list.size(),1, list);
} }
return new Page<>(pageable, 0L, new ArrayList<>()); return new Page<T>(pageable, 0L, new ArrayList<>());
} else { } else {
if(pageable==null){ if(pageable==null){
return new Page<T>(1,list.size(), (long)list.size(),1, list); return new Page<T>(1,list.size(), (long)list.size(),1, list);
...@@ -64,4 +66,8 @@ public class PageUtils { ...@@ -64,4 +66,8 @@ public class PageUtils {
} }
} }
} }
public static <T> Page<T> page(Page<String> o, List<T> list) {
return new Page<>(o.getPageNum(),o.getPageSize(),o.getTotalSize(),o.getTotalPages(),list);
}
} }
...@@ -15,7 +15,7 @@ server: ...@@ -15,7 +15,7 @@ server:
spring.datasource: spring.datasource:
community: community:
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
jdbc-url: jdbc:mysql://rm-uf6r22t3d798q4kmk.mysql.rds.aliyuncs.com:3306/tamp_community?useUnicode=true&characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull jdbc-url: jdbc:mysql://rm-uf6r22t3d798q4kmkao.mysql.rds.aliyuncs.com:3306/tamp_community?useUnicode=true&characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull
username: tamp_admin username: tamp_admin
password: '@imeng123' password: '@imeng123'
maxActive: 2 maxActive: 2
...@@ -23,7 +23,8 @@ spring.datasource: ...@@ -23,7 +23,8 @@ spring.datasource:
initialSize: 2 initialSize: 2
user: user:
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
jdbc-url: jdbc:mysql://rm-uf6r22t3d798q4kmk.mysql.rds.aliyuncs.com:3306/tamp_user?useUnicode=true&characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull jdbc-url: jdbc:mysql://rm-uf6r22t3d798q4kmkao.mysql.rds.aliyuncs.com:3306/tamp_user?useUnicode=true&characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull
username: tamp_admin
password: '@imeng123' password: '@imeng123'
maxActive: 2 maxActive: 2
minIdle: 2 minIdle: 2
...@@ -80,6 +81,7 @@ es: ...@@ -80,6 +81,7 @@ es:
port: 9200 port: 9200
userName: 1 userName: 1
userPasswd: 2 userPasswd: 2
index: test
tencent: tencent:
cloud: cloud:
......
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