Commit b13e20e7 authored by 刘基明's avatar 刘基明

数据分析

parent c6557a6e
...@@ -11,9 +11,6 @@ import java.util.List; ...@@ -11,9 +11,6 @@ import java.util.List;
@ApiModel("评论对象") @ApiModel("评论对象")
public class CommentQo { public class CommentQo {
@ApiModelProperty(value = "id")
private Integer id;
@ApiModelProperty(value = "uuid") @ApiModelProperty(value = "uuid")
private String commentId; private String commentId;
......
...@@ -2,7 +2,15 @@ package com.tanpu.community.api.beans.qo; ...@@ -2,7 +2,15 @@ package com.tanpu.community.api.beans.qo;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ThemeAnalysDO { public class ThemeAnalysDO {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
...@@ -38,7 +46,21 @@ public class ThemeAnalysDO { ...@@ -38,7 +46,21 @@ public class ThemeAnalysDO {
@ApiModelProperty(value = "点赞量") @ApiModelProperty(value = "点赞量")
private Integer likeCount; private Integer likeCount;
@ApiModelProperty(value = "收藏量")
private Integer collectCount;
@ApiModelProperty(value = "收藏量")
private Integer viewCount;
@ApiModelProperty(value = "距今时间") @ApiModelProperty(value = "距今时间")
private Long timeTillNow; private Long minuteTillNow;
public Double getRank(){
double p = (double) (viewCount + forwardCount + commentCount + likeCount + collectCount);
double t = Double.valueOf(minuteTillNow);
double g =1.8;
double rank=(p-1)/Math.pow(t+2,g);
return rank;
}
} }
...@@ -145,4 +145,12 @@ public class ThemeController { ...@@ -145,4 +145,12 @@ public class ThemeController {
return CommonResp.success(themeManager.getFollowUpdateCount(userId)); return CommonResp.success(themeManager.getFollowUpdateCount(userId));
} }
} @AuthLogin
@ApiOperation("关注主题更新数量")
@GetMapping(value = "/test")
@ResponseBody
public CommonResp<String> test() {
return CommonResp.success("");
}
}
...@@ -3,6 +3,7 @@ package com.tanpu.community.manager; ...@@ -3,6 +3,7 @@ package com.tanpu.community.manager;
import com.tanpu.common.exception.BizException; import com.tanpu.common.exception.BizException;
import com.tanpu.common.util.JsonUtil; import com.tanpu.common.util.JsonUtil;
import com.tanpu.community.api.beans.qo.FormerThemeQo; import com.tanpu.community.api.beans.qo.FormerThemeQo;
import com.tanpu.community.api.beans.qo.ThemeAnalysDO;
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;
import com.tanpu.community.api.beans.req.homepage.QueryRecordThemeReq; import com.tanpu.community.api.beans.req.homepage.QueryRecordThemeReq;
...@@ -73,7 +74,6 @@ public class ThemeManager { ...@@ -73,7 +74,6 @@ public class ThemeManager {
themeEntity.setContent(JsonUtil.toJson(req.getContent())); themeEntity.setContent(JsonUtil.toJson(req.getContent()));
if (StringUtils.isEmpty(req.getEditThemeId())) { if (StringUtils.isEmpty(req.getEditThemeId())) {
//新建 //新建
themeService.insertTheme(themeEntity); themeService.insertTheme(themeEntity);
...@@ -91,12 +91,12 @@ public class ThemeManager { ...@@ -91,12 +91,12 @@ public class ThemeManager {
themeAttachmentService.insertList(themeAttachments); themeAttachmentService.insertList(themeAttachments);
return CreateThemeResp.builder().themeId(themeEntity.getThemeId()).build(); return CreateThemeResp.builder().themeId(themeEntity.getThemeId()).build();
} }
/** /**
* 返回主题列表 * 返回主题列表
*
* @param req * @param req
* @param userId * @param userId
* @return * @return
...@@ -105,7 +105,7 @@ public class ThemeManager { ...@@ -105,7 +105,7 @@ public class ThemeManager {
List<ThemeEntity> themeEntities = new ArrayList<>(); List<ThemeEntity> themeEntities = new ArrayList<>();
if (ThemeListTypeEnum.RECOMMEND.getCode().equals(req.getType())) { if (ThemeListTypeEnum.RECOMMEND.getCode().equals(req.getType())) {
// TODO:推荐 // TODO:推荐
themeEntities = themeService.selectExcludeUser(userId,req.getLastId(), req.getPageSize()); themeEntities = themeService.selectExcludeUser(userId, req.getLastId(), req.getPageSize());
Set<String> recomondThemeIds; Set<String> recomondThemeIds;
Set<String> hotThemeIds; Set<String> hotThemeIds;
Set<String> newThemeIds; Set<String> newThemeIds;
...@@ -129,7 +129,7 @@ public class ThemeManager { ...@@ -129,7 +129,7 @@ public class ThemeManager {
public List<ThemeQo> searchThemes(ThemeSearchReq req, String userId) { public List<ThemeQo> searchThemes(ThemeSearchReq req, String userId) {
List<ThemeEntity> themeEntities= themeService.search(req.getKeyword(),req.getLastId(), req.getPageSize()); List<ThemeEntity> themeEntities = themeService.search(req.getKeyword(), req.getLastId(), req.getPageSize());
return convertEntityToQo(themeEntities, userId); return convertEntityToQo(themeEntities, userId);
} }
...@@ -315,7 +315,7 @@ public class ThemeManager { ...@@ -315,7 +315,7 @@ public class ThemeManager {
Integer forwardCountByUser = themeService.getForwardCountByUser(themeId, userId); Integer forwardCountByUser = themeService.getForwardCountByUser(themeId, userId);
themeQo.setHasForward(forwardCountByUser > 0); themeQo.setHasForward(forwardCountByUser > 0);
//是否收藏 //是否收藏
CollectionEntity collectionEntity = collectionService.getNotDeleteTargetCollection(themeId, userId, CollectionTypeEnum.COLLECT_THEME); CollectionEntity collectionEntity = collectionService.getNotDeleteTargetCollection(themeId, userId, CollectionTypeEnum.COLLECT_THEME);
themeQo.setHasCollect(collectionEntity != null); themeQo.setHasCollect(collectionEntity != null);
//点赞,收藏,转发 //点赞,收藏,转发
Integer likeCount = collectionService.getCountByTypeAndId(themeId, CollectionTypeEnum.LIKE_THEME); Integer likeCount = collectionService.getCountByTypeAndId(themeId, CollectionTypeEnum.LIKE_THEME);
...@@ -360,4 +360,23 @@ public class ThemeManager { ...@@ -360,4 +360,23 @@ public class ThemeManager {
List<String> fansList = followRelService.queryFansByFollowerId(userId); List<String> fansList = followRelService.queryFansByFollowerId(userId);
return themeService.queryCountFromLastTime(fansList, lastViewTime); return themeService.queryCountFromLastTime(fansList, lastViewTime);
} }
public void rank() {
List<ThemeEntity> themeEntities = themeService.queryAll();
List<ThemeAnalysDO> themeAnalysDOS = ConvertUtil.themeEntityToAnalysDOs(themeEntities);
for (ThemeAnalysDO theme : themeAnalysDOS) {
String themeId = theme.getThemeId();
Integer likeCount = collectionService.getCountByTypeAndId(themeId, CollectionTypeEnum.LIKE_THEME);
Integer bookCount = collectionService.getCountByTypeAndId(themeId, CollectionTypeEnum.COLLECT_THEME);
Integer commentCount = commentService.getCommentCountByThemeId(themeId);
Integer forwardCount = themeService.getForwardCountById(themeId);
theme.setCommentCount(commentCount);
theme.setLikeCount(likeCount);
theme.setForwardCount(forwardCount);
theme.setCollectCount(bookCount);
}
Map<Double, ThemeAnalysDO> collect = themeAnalysDOS.stream().collect(Collectors.toMap(ThemeAnalysDO::getRank, o -> o));
}
} }
...@@ -40,6 +40,17 @@ public class ThemeService { ...@@ -40,6 +40,17 @@ public class ThemeService {
themeMapper.update(themeEntity, new LambdaUpdateWrapper<ThemeEntity>().eq(ThemeEntity::getThemeId, themeId)); themeMapper.update(themeEntity, new LambdaUpdateWrapper<ThemeEntity>().eq(ThemeEntity::getThemeId, themeId));
} }
/**
* 根据主题Id查询列表
* @return
*/
public List<ThemeEntity> queryAll() {
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
return themeMapper.selectList(queryWrapper);
}
//根据id返回主题详情(未删) //根据id返回主题详情(未删)
public ThemeEntity queryByThemeId(String themeId) { public ThemeEntity queryByThemeId(String themeId) {
return themeMapper.selectOne(new LambdaQueryWrapper<ThemeEntity>() return themeMapper.selectOne(new LambdaQueryWrapper<ThemeEntity>()
...@@ -86,7 +97,11 @@ public class ThemeService { ...@@ -86,7 +97,11 @@ public class ThemeService {
return themeMapper.selectList(queryWrapper); return themeMapper.selectList(queryWrapper);
} }
//根据ids返回主题详情 /**
* 根据主题Id查询列表
* @param themeIds
* @return
*/
public List<ThemeEntity> queryByThemeIds(List<String> themeIds) { public List<ThemeEntity> queryByThemeIds(List<String> themeIds) {
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>() LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.in(ThemeEntity::getThemeId, themeIds) .in(ThemeEntity::getThemeId, themeIds)
...@@ -95,8 +110,10 @@ public class ThemeService { ...@@ -95,8 +110,10 @@ public class ThemeService {
return themeMapper.selectList(queryWrapper); return themeMapper.selectList(queryWrapper);
} }
/** /**
* 分页查询,非当前用户的主题 * 查询非传入作者的主题(可分页)
* @param lastId * @param lastId
* @param pageSize * @param pageSize
* @param userId * @param userId
...@@ -123,7 +140,7 @@ public class ThemeService { ...@@ -123,7 +140,7 @@ public class ThemeService {
/** /**
* 根据条件查询最新主题 * 根据话题查询最新主题(可分页)
* *
* @param topidId 话题Id * @param topidId 话题Id
* @param lastId 查询此主题Id之前的主题 * @param lastId 查询此主题Id之前的主题
...@@ -158,7 +175,13 @@ public class ThemeService { ...@@ -158,7 +175,13 @@ public class ThemeService {
} }
//关注的主题列表 /**
* 根据作者查询主题列表(可分页)
* @param userIds
* @param lastId
* @param pageSize
* @return
*/
public List<ThemeEntity> queryByUserIds(List<String> userIds, String lastId, Integer pageSize) { public List<ThemeEntity> queryByUserIds(List<String> userIds, String lastId, Integer pageSize) {
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>() LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.in(ThemeEntity::getAuthorId, userIds); .in(ThemeEntity::getAuthorId, userIds);
......
...@@ -57,19 +57,20 @@ public class ConvertUtil { ...@@ -57,19 +57,20 @@ public class ConvertUtil {
return themeQO; return themeQO;
} }
public static ThemeAnalysDO themeEntityToAnalysDO(ThemeEntity themeEntity) {
if (themeEntity == null) {
return null;
}
ThemeAnalysDO themeAnalysDO = new ThemeAnalysDO();
BeanUtils.copyProperties(themeEntity, themeAnalysDO);
themeAnalysDO.setMinuteTillNow(TimeUtil.calMinuteTillNow(themeEntity.getCreateTime()));
return themeAnalysDO;
}
public static ThemeEntity themeDTOToEntity(ThemeQo themeQO) { public static List<ThemeAnalysDO> themeEntityToAnalysDOs(List<ThemeEntity> themeEntities) {
ThemeEntity themeEntity = new ThemeEntity(); return themeEntities.stream().map(ConvertUtil::themeEntityToAnalysDO).collect(Collectors.toList());
BeanUtils.copyProperties(themeQO, themeEntity);
return themeEntity;
} }
/**
* 首页主题列表,限制附件个数为1(1文本+1附件)
*
* @param themeEntities
* @return
*/
public static List<ThemeQo> themeEntitiesToDTOs(List<ThemeEntity> themeEntities) { public static List<ThemeQo> themeEntitiesToDTOs(List<ThemeEntity> themeEntities) {
return themeEntities.stream().map(ConvertUtil::themeEntityToQo2).collect(Collectors.toList()); return themeEntities.stream().map(ConvertUtil::themeEntityToQo2).collect(Collectors.toList());
} }
......
...@@ -35,4 +35,10 @@ public class TimeUtil { ...@@ -35,4 +35,10 @@ public class TimeUtil {
return start.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); return start.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
} }
//计算迄今时间
public static long calMinuteTillNow(LocalDateTime start) {
Duration between = Duration.between(start, LocalDateTime.now());
return between.toMinutes();
}
} }
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