Commit 2e5f22ef authored by 吴泽佳's avatar 吴泽佳

Merge branch 'dev' of http://47.100.44.39:10001/tp-backend/tanpu-community into dev

# Conflicts:
#	community-service/src/main/java/com/tanpu/community/manager/CommentManager.java
#	community-service/src/main/java/com/tanpu/community/manager/HomePageManager.java
#	community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java
#	community-service/src/main/java/com/tanpu/community/service/RankService.java
#	community-service/src/main/resources/application-dev.yml
parents d1ba9594 8f4feb3e
......@@ -26,6 +26,9 @@ public class TopicRankQo {
@ApiModelProperty(value = "是否置顶")
private Integer isTop;
@ApiModelProperty(value = "浏览量调整基数")
private Integer viewCntAdjust;
/**
* TODO 热度计算算法
* @return
......@@ -35,6 +38,6 @@ public class TopicRankQo {
if (isTop>0){
return Integer.MAX_VALUE;
}
return this.viewCount+this.disscussCount*3;
return this.viewCount+this.disscussCount*3+viewCount;
}
}
......@@ -10,8 +10,6 @@ import java.util.List;
@Data
public class CreateThemeReq {
private static final long serialVersionUID = 1L;
@NotNull(message = "类型不能为空")
@ApiModelProperty(value = "类型 1:讨论无标题 2:长文有标题")
......
......@@ -11,7 +11,7 @@ import java.util.List;
@ApiModel(value = "主题内容")
public class ThemeContentReq {
@ApiModelProperty(value = "RelTypeEnum类型,8:文本,88:产品 3:直播 6:短视频 2:课程,9:图片 10:多图(讨论)")
@ApiModelProperty(value = "RelTypeEnum类型,108:文本,88:产品 3:直播 6:短视频 303:新版课程-视频,304: 新版课程-音频,109:单图(长文) 110:多图(讨论))")
private String type;
@ApiModelProperty(value = "文本的值是内容,附件的值为id")
......
package com.tanpu.community.api.beans.vo.feign.pay;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "支付详情")
public class PayDetailVO {
private String id;
private String title;
private String cover;
private String info;
private Integer score;
private Long price;
/**
* 划线价
*/
private Long crossedPrice;
private Integer availableScore;
private Integer balance;
/**
* 1:免费 2:积分 3现金
*/
private Integer chargeMode;
/**
* 类型:1:栏目 3:直播 4:视频 5 音频 7:直播课件
*/
private Integer relType;
}
......@@ -65,6 +65,16 @@
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
<!-- mybatis-plus自动生成所需包-->
<dependency>
<groupId>org.apache.velocity</groupId>
......
......@@ -3,10 +3,13 @@ package com.tanpu.community.config;
import com.tanpu.community.cache.RedisCache;
import com.tanpu.community.util.SpringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.annotation.Resource;
import java.util.Arrays;
@Configuration
public class CacheConfig {
......@@ -16,6 +19,14 @@ public class CacheConfig {
@Bean
public RedisCache redisCache() {
return new RedisCache.Builder().cacheName("community2").build();
return new RedisCache.Builder().cacheName("redis").build();
}
@Bean
public CacheManager cacheManager() {
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
cacheManager.setCacheNames(Arrays.asList("local"));
cacheManager.setCacheSpecification("maximumSize=10,expireAfterWrite=10s");
return cacheManager;
}
}
......@@ -71,4 +71,14 @@ public class CommentController {
commentManager.report(req,userId);
return CommonResp.success();
}
@ApiOperation("删除评论")
@GetMapping(value = "/deleteComment")
@AuthLogin
@ResponseBody
public CommonResp<Void> reportComment(@RequestParam(value = "commentId") String commentId) {
String userId = userHolder.getUserId();
commentManager.delete(commentId,userId);
return CommonResp.success();
}
}
......@@ -21,4 +21,16 @@ public class FileController {
public CommonResp<FileUploadResp> uploadToRemote(@RequestParam(value = "file") MultipartFile file) {
return CommonResp.success(fileManager.uploadFile(file));
}
@GetMapping("/test")
public String test() {
for (int i = 0; i < 30; i++) {
System.out.println(fileManager.getId("" + i / 2));
}
for (int i = 30; i > 0; i--) {
System.out.println(fileManager.getId("" + i / 2));
}
return "";
}
}
......@@ -8,7 +8,6 @@ import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.api.beans.req.theme.*;
import com.tanpu.community.api.beans.resp.CreateThemeResp;
import com.tanpu.community.api.beans.resp.ThemeListResp;
import com.tanpu.community.cache.RedisCache;
import com.tanpu.community.manager.ThemeManager;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
......@@ -17,7 +16,6 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RestController
@Slf4j
......@@ -28,8 +26,6 @@ public class ThemeController {
private ThemeManager themeManager;
@Resource
private UserHolder userHolder;
@Autowired
private RedisCache redisCache;
@AuthLogin
@ApiOperation("发表主题")
......@@ -79,12 +75,12 @@ public class ThemeController {
}
@AuthLogin
@ApiOperation("用户删除自有主题")
@ApiOperation("用户删除主题")
@GetMapping(value = "/delete")
@ResponseBody
public CommonResp<Void> delete(@RequestParam(value = "themeId") String themeId) {
String userId = userHolder.getUserId();
themeManager.delete(themeId);
themeManager.delete(themeId, userId);
return CommonResp.success();
}
......
......@@ -19,11 +19,11 @@ public class CodeAutoGenerator {
String currentPath = System.getProperty("user.dir");
String codeBaseHome = "/community-service/src/main/java";
String author = "xudong";
String mysqlUserName = "dev";
String mysqlPassword = "qimeng123";
String jdbcUrl = "jdbc:mysql://47.101.189.151:31931/tamp_community";
String[] tables = new String[]{"comment"};
// String[] tables = new String[]{"follow_rel", "black_list","collection","comment","follow_rel","file_record","home_page","theme","topic","theme_attachment"};
String mysqlUserName = "tamp_admin";
String mysqlPassword = "@imeng123";
String jdbcUrl = "jdbc:mysql://rm-uf6r22t3d798q4kmkao.mysql.rds.aliyuncs.com:3306/tamp_community";
// String[] tables = new String[]{"theme"};
String[] tables = new String[]{"comment","follow_rel","theme","visit_log"};
String basePackage = "com.tanpu.community";
String mapperPackage = "dao.mapper.community";
String entityPackage = "dao.entity.community";
......
......@@ -3,7 +3,6 @@ package com.tanpu.community.dao.entity.community;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
......@@ -19,7 +18,7 @@ import java.time.LocalDateTime;
* </p>
*
* @author xudong
* @since 2021-07-22
* @since 2021-07-28
*/
@TableName("comment")
@ApiModel(value="CommentEntity对象", description="评论")
......@@ -55,16 +54,14 @@ public class CommentEntity implements Serializable {
@ApiModelProperty(value = "回复评论id")
private String replyId;
@ApiModelProperty(value = "是否通过 0:初始值 1:已通过(管理后台使用)")
private Integer isPass;
@ApiModelProperty(value = "审核状态 0:初始值 1:已通过(管理后台使用)")
private Integer reviewStatus;
@ApiModelProperty(value = "举报状态 0:未被举报 1:被举报 2:已处理")
private Integer reportStatus;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private LocalDateTime createTime;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private LocalDateTime updateTime;
private Integer deleteTag;
......@@ -134,12 +131,12 @@ public class CommentEntity implements Serializable {
this.replyId = replyId;
}
public Integer getIsPass() {
return isPass;
public Integer getReviewStatus() {
return reviewStatus;
}
public void setIsPass(Integer isPass) {
this.isPass = isPass;
public void setReviewStatus(Integer reviewStatus) {
this.reviewStatus = reviewStatus;
}
public Integer getReportStatus() {
......@@ -185,7 +182,7 @@ public class CommentEntity implements Serializable {
", themeId=" + themeId +
", parentId=" + parentId +
", replyId=" + replyId +
", isPass=" + isPass +
", reviewStatus=" + reviewStatus +
", reportStatus=" + reportStatus +
", createTime=" + createTime +
", updateTime=" + updateTime +
......
package com.tanpu.community.dao.entity.community;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import java.io.Serializable;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* <p>
* 粉丝关系
* </p>
*
* @author xudong
* @since 2021-07-22
* @since 2021-07-28
*/
@TableName("follow_rel")
@ApiModel(value="FollowRelEntity对象", description="粉丝关系")
......@@ -33,10 +34,10 @@ public class FollowRelEntity implements Serializable {
private Long id;
@ApiModelProperty(value = "被关注的人id")
private String followUserId;
private String idolId;
@ApiModelProperty(value = "粉丝id")
private String followerId;
private String fansId;
@ApiModelProperty(value = "关注时间")
private LocalDateTime followTime;
......@@ -59,20 +60,20 @@ public class FollowRelEntity implements Serializable {
this.id = id;
}
public String getFollowUserId() {
return followUserId;
public String getIdolId() {
return idolId;
}
public void setFollowUserId(String followUserId) {
this.followUserId = followUserId;
public void setIdolId(String idolId) {
this.idolId = idolId;
}
public String getFollowerId() {
return followerId;
public String getFansId() {
return fansId;
}
public void setFollowerId(String followerId) {
this.followerId = followerId;
public void setFansId(String fansId) {
this.fansId = fansId;
}
public LocalDateTime getFollowTime() {
......@@ -119,8 +120,8 @@ public class FollowRelEntity implements Serializable {
public String toString() {
return "FollowRelEntity{" +
"id=" + id +
", followUserId=" + followUserId +
", followerId=" + followerId +
", idolId=" + idolId +
", fansId=" + fansId +
", followTime=" + followTime +
", unfollowTime=" + unfollowTime +
", createTime=" + createTime +
......
......@@ -18,7 +18,7 @@ import java.time.LocalDateTime;
* </p>
*
* @author xudong
* @since 2021-07-23
* @since 2021-07-28
*/
@TableName("theme")
@Builder
......@@ -42,12 +42,9 @@ public class ThemeEntity implements Serializable {
@ApiModelProperty(value = "类型 1:讨论无标题 2:长文有标题 3:转发")
private Integer themeType;
@ApiModelProperty(value = "文本内容(json),type:附件类型(8:文本,88:产品 3:直播 6:短视频 300:课程,9:图片 10:多图),productType:基金类型(0 公募,1 私募,2 白名单,3 私有)")
@ApiModelProperty(value = "文本内容(json),type:附件类型(108:文本,88:产品 3:直播 6:短视频 303:新版课程-视频,304: 新版课程-音频,109:单图(长文) 110:多图(讨论)),productType:基金类型(0 公募,1 私募,2 白名单,3 私有)")
private String content;
@ApiModelProperty(value = "讨论中的文本")
private String discussContent;
@ApiModelProperty(value = "作者id")
private String authorId;
......@@ -57,8 +54,8 @@ public class ThemeEntity implements Serializable {
@ApiModelProperty(value = "所属的话题")
private String topicId;
@ApiModelProperty(value = "是否通过 0:初始值 1:已通过(管理后台使用)")
private Integer isPass;
@ApiModelProperty(value = "审核状态 0:未审核 1:审核通过(管理后台使用)")
private Integer reviewStatus;
@ApiModelProperty(value = "举报状态 0:未被举报 1:被举报 2:已处理")
private Integer reportStatus;
......@@ -111,14 +108,6 @@ public class ThemeEntity implements Serializable {
this.content = content;
}
public String getDiscussContent() {
return discussContent;
}
public void setDiscussContent(String discussContent) {
this.discussContent = discussContent;
}
public String getAuthorId() {
return authorId;
}
......@@ -143,12 +132,12 @@ public class ThemeEntity implements Serializable {
this.topicId = topicId;
}
public Integer getIsPass() {
return isPass;
public Integer getReviewStatus() {
return reviewStatus;
}
public void setIsPass(Integer isPass) {
this.isPass = isPass;
public void setReviewStatus(Integer reviewStatus) {
this.reviewStatus = reviewStatus;
}
public Integer getReportStatus() {
......@@ -191,11 +180,10 @@ public class ThemeEntity implements Serializable {
", title=" + title +
", themeType=" + themeType +
", content=" + content +
", discussContent=" + discussContent +
", authorId=" + authorId +
", formerThemeId=" + formerThemeId +
", topicId=" + topicId +
", isPass=" + isPass +
", reviewStatus=" + reviewStatus +
", reportStatus=" + reportStatus +
", createTime=" + createTime +
", updateTime=" + updateTime +
......
......@@ -17,7 +17,7 @@ import lombok.NoArgsConstructor;
* </p>
*
* @author xudong
* @since 2021-07-22
* @since 2021-07-29
*/
@TableName("topic")
@ApiModel(value="TopicEntity对象", description="话题")
......@@ -45,7 +45,7 @@ public class TopicEntity implements Serializable {
private Integer isConceal;
@ApiModelProperty(value = "浏览量调整基数")
private Long viewCntAdjust;
private Integer viewCntAdjust;
private LocalDateTime createTime;
......@@ -94,11 +94,11 @@ public class TopicEntity implements Serializable {
this.isConceal = isConceal;
}
public Long getViewCntAdjust() {
public Integer getViewCntAdjust() {
return viewCntAdjust;
}
public void setViewCntAdjust(Long viewCntAdjust) {
public void setViewCntAdjust(Integer viewCntAdjust) {
this.viewCntAdjust = viewCntAdjust;
}
......
......@@ -15,14 +15,14 @@ import lombok.NoArgsConstructor;
* </p>
*
* @author xudong
* @since 2021-07-22
* @since 2021-07-28
*/
@TableName("visit_summary")
@ApiModel(value="VisitSummaryEntity对象", description="浏览记录")
@TableName("visit_log")
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class VisitSummaryEntity implements Serializable {
@ApiModel(value="VisitLogEntity对象", description="浏览记录")
public class VisitLogEntity implements Serializable {
private static final long serialVersionUID = 1L;
......@@ -136,7 +136,7 @@ public class VisitSummaryEntity implements Serializable {
@Override
public String toString() {
return "VisitSummaryEntity{" +
return "VisitLogEntity{" +
"id=" + id +
", ident=" + ident +
", visitorId=" + visitorId +
......
......@@ -3,13 +3,12 @@ package com.tanpu.community.dao.mapper.community;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.tanpu.community.dao.entity.community.TimesCountEntity;
import com.tanpu.community.dao.entity.community.VisitSummaryEntity;
import com.tanpu.community.dao.entity.community.VisitLogEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
......@@ -19,21 +18,21 @@ import java.util.List;
* </p>
*
* @author xudong
* @since 2021-07-22
* @since 2021-07-28
*/
public interface VisitSummaryMapper extends BaseMapper<VisitSummaryEntity> {
@Select("select * from visit_summary where ident=#{ident}")
VisitSummaryEntity selectByIdent(@Param("ident") String ident);
public interface VisitLogMapper extends BaseMapper<VisitLogEntity> {
@Select("select * from visit_log where ident=#{ident}")
VisitLogEntity selectByIdent(@Param("ident") String ident);
@Update("update visit_summary set duration=duration+#{duration} where ident=#{ident}")
@Update("update visit_log set duration=duration+#{duration} where ident=#{ident}")
void updateDurByIdent(@Param("duration") Integer dur, @Param("ident") String ident);
@Select("select ref_id from visit_summary where visitor_id=#{visitorId} and ref_id in (#{refIds})")
@Select("select ref_id from visit_log where visitor_id=#{visitorId} and ref_id in (#{refIds})")
List<String> selectRefIdByUserId(@Param("visitorId") String visitorId, @Param("refIds") String refIds);
@Select("select ref_id as id, count(1) as times from visit_summary ${ew.customSqlSegment}")
List<TimesCountEntity> selectCountByThemeIds(@Param(Constants.WRAPPER)LambdaQueryWrapper wrapper);
@Select("select ref_id as id, count(1) as times from visit_log ${ew.customSqlSegment}")
List<TimesCountEntity> selectCountByThemeIds(@Param(Constants.WRAPPER) LambdaQueryWrapper wrapper);
@Select("select ref_id from visit_summary where visitor_id=#{visitorId} and date(create_time) between #{startDate} and #{endDate}")
@Select("select ref_id from visit_log where visitor_id=#{visitorId} and date(create_time) between #{startDate} and #{endDate}")
List<String> selectRefIdByUserIdAndCreateBetween(@Param("visitorId") String visitorId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
}
......@@ -75,7 +75,7 @@ public class CommentManager {
//查询用户信息
String authorId = commentQo.getAuthorId();
UserInfoResp userInfo = redisCache.getObject(StringUtils.joinWith("_", CACHE_FEIGN_USER_INFO, authorId),
60 * 10, () ->this.getUserInfo(authorId) , UserInfoResp.class);
60, () ->this.getUserInfo(authorId) , UserInfoResp.class);
if (userInfo != null) {
commentQo.setUserImg(userInfo.getHeadImageUrl());
commentQo.setNickName(userInfo.getNickName());
......@@ -124,4 +124,10 @@ public class CommentManager {
CommentEntity commentEntity = commentService.queryByCommentId(req.getCommentId());
reportLogService.insert(ReportTypeEnum.COMMENT, userId, req.getCommentId(), commentEntity.getAuthorId(), req.getReason());
}
//删除评论
public void delete(String commentId, String userId) {
commentService.delete(commentId,userId);
}
}
......@@ -2,7 +2,7 @@ package com.tanpu.community.manager;
import com.tanpu.community.service.RankService;
import com.tanpu.community.service.RedisService;
import com.tanpu.community.service.VisitSummaryService;
import com.tanpu.community.service.VisitLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
......@@ -15,7 +15,7 @@ import org.springframework.stereotype.Service;
public class ConJobManager {
@Autowired
private VisitSummaryService visitSummaryService;
private VisitLogService visitLogService;
@Autowired
private RedisService redisService;
......@@ -29,7 +29,7 @@ public class ConJobManager {
@Scheduled(cron = "*/10 * * * * ?")
public void topicVisitorStats() {
String topicId = "123";
Integer detailVisitTimes = visitSummaryService.queryTopicDetailVisit(topicId);
Integer detailVisitTimes = visitLogService.queryTopicDetailVisit(topicId);
redisService.set("topicVisitorStats", detailVisitTimes);
}
......
......@@ -8,6 +8,7 @@ import com.tanpu.community.service.OSSFileService;
import com.tanpu.community.util.ConvertUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
......@@ -49,4 +50,10 @@ public class FileManager {
return ossFileService.queryByIds(fileIds).stream()
.collect(Collectors.toMap(FileRecordEntity::getFileId, FileRecordEntity::getUrl));
}
@Cacheable(value = "local", key = "#id")
public String getId(String id) {
System.out.println("cache " + id);
return "haha " + id;
}
}
......@@ -126,10 +126,10 @@ public class HomePageManager {
// 设置关注列表
List<String> collect = userInfoOrgs.stream().map(UserInfoOrg::getUserId).collect(Collectors.toList());
List<FollowRelEntity> followRelEntities = followRelMapper.selectList(new LambdaQueryWrapper<FollowRelEntity>()
.eq(FollowRelEntity::getFollowerId, userId)
.in(FollowRelEntity::getFollowUserId, collect)
.eq(FollowRelEntity::getIdolId, userId)
.in(FollowRelEntity::getFansId, collect)
.eq(FollowRelEntity::getDeleteTag, BizStatus.DeleteTag.tag_init));
Map<String, FollowRelEntity> collect1 = followRelEntities.stream().collect(Collectors.toMap(FollowRelEntity::getFollowUserId, Function.identity()));
Map<String, FollowRelEntity> collect1 = followRelEntities.stream().collect(Collectors.toMap(FollowRelEntity::getIdolId, Function.identity()));
userInfoOrgs.forEach(userInfoOrg -> {
if (collect1.containsKey(userInfoOrg.getUserId()))
userInfoOrg.setIsFollower(ShowFollowStatusEnum.FOLLOWED.getCode());//1已关注
......@@ -154,9 +154,9 @@ public class HomePageManager {
}
private void getFansNUmAndFollowNum(UserInfoResp userInfoNew) {
Integer fansNumber = followRelMapper.selectCount(new LambdaQueryWrapper<FollowRelEntity>().eq(FollowRelEntity::getFollowUserId, userInfoNew.getUserId())
Integer fansNumber = followRelMapper.selectCount(new LambdaQueryWrapper<FollowRelEntity>().eq(FollowRelEntity::getIdolId, userInfoNew.getUserId())
.eq(FollowRelEntity::getDeleteTag, BizStatus.DeleteTag.tag_init));
Integer followNumber = followRelMapper.selectCount(new LambdaQueryWrapper<FollowRelEntity>().eq(FollowRelEntity::getFollowerId, userInfoNew.getUserId())
Integer followNumber = followRelMapper.selectCount(new LambdaQueryWrapper<FollowRelEntity>().eq(FollowRelEntity::getFansId, userInfoNew.getUserId())
.eq(FollowRelEntity::getDeleteTag, BizStatus.DeleteTag.tag_init));
userInfoNew.setFollowNumber(followNumber);
userInfoNew.setFansNumber(fansNumber);
......
......@@ -69,7 +69,7 @@ public class ThemeManager {
private BatchFeignCallService batchFeignCallService;
@Autowired
private VisitSummaryService visitSummaryService;
private VisitLogService visitLogService;
@Autowired
private ReportLogService reportLogService;
......@@ -104,14 +104,17 @@ public class ThemeManager {
return !excludeIds.contains(tId);
}).limit(pageSize).collect(Collectors.toList());
List<ThemeQo> themes = ConvertUtil.themeEntitiesToDTOs(themeService.queryByThemeIds(filterEsIds));
resp.themes = convertEntityToQo(themeService.queryByThemeIds(filterEsIds), userId);
resp.themes.sort(new Comparator<ThemeQo>() {
@Override
public int compare(ThemeQo o1, ThemeQo o2) {
return o2.createTime.compareTo(o1.createTime);
}
});
// 截取关键词出现的那一部分段落
for (ThemeQo theme : resp.themes) {
theme.briefContent4FullSearch = BizUtils.getThemeContent(keyword, theme);
}
resp.excludeIds.addAll(filterEsIds);
return resp;
......@@ -124,35 +127,29 @@ public class ThemeManager {
@Transactional
public CreateThemeResp publishTheme(CreateThemeReq req, String userId) {
//保存主题表
// 保存主题表
ThemeEntity themeEntity = new ThemeEntity();
BeanUtils.copyProperties(req, themeEntity);
themeEntity.setAuthorId(userId);
themeEntity.setContent(JsonUtil.toJson(req.getContent()));
//讨论类型,将讨论中的文本放入到discussContent中
if (ThemeTypeEnum.DISCUSSION.getCode().equals(themeEntity.getThemeType())) {
String content = req.getContent().get(0).getValue();
if (content.length()>256){
content= content.substring(0,255);
}
themeEntity.setDiscussContent(content);
}
//腾讯云敏感词校验
// 腾讯云敏感词校验,
// TODO 图片校验
checkContent(themeEntity.getContent());
if (StringUtils.isEmpty(req.getEditThemeId())) {
//新建
// 新建
themeService.insertTheme(themeEntity);
} else {
//修改
// 修改
themeService.update(themeEntity, req.getEditThemeId());
themeEntity.setThemeId(req.getEditThemeId());
}
//保存附件表
// 保存附件表
List<ThemeAttachmentEntity> themeAttachments = ConvertUtil.themeReqToAttachmentList(req, themeEntity.getThemeId());
if (StringUtils.isNotEmpty(req.getEditThemeId())) {
//修改需要刪除
// 修改需要刪除
themeAttachmentService.deleteByThemeId(req.getEditThemeId());
}
themeAttachmentService.insertList(themeAttachments);
......@@ -180,13 +177,12 @@ public class ThemeManager {
.build();
if (StringUtils.isEmpty(req.getEditThemeId()) || req.getEditThemeId().equals(req.getFormerThemeId())) {
//新建
// 新建
themeService.insertTheme(themeEntity);
} else {
//修改
// 修改
themeService.update(themeEntity, req.getEditThemeId());
themeEntity.setThemeId(req.getEditThemeId());
}
return CreateThemeResp.builder().themeId(themeEntity.getThemeId()).build();
}
......@@ -206,7 +202,7 @@ public class ThemeManager {
if (ThemeListTypeEnum.RECOMMEND.getCode().equals(req.getType())) {
//推荐
// 需要筛掉用户访问过详情的 & 最近出现在列表页过的.
List<String> visitedIds = visitSummaryService.queryUserRecentVisited(userId);
List<String> visitedIds = visitLogService.queryUserRecentVisited(userId);
List<String> excludes = ListUtils.union(req.excludeIds, visitedIds);
List<String> recmdIds = recommendService.getRecommendThemes(pageStart, querySize, userId, excludes);
......@@ -217,7 +213,7 @@ public class ThemeManager {
} else if (ThemeListTypeEnum.FOLLOW.getCode().equals(req.getType())) {
// TODO 临时埋点,接入新埋点后删除
if (CollectionUtils.isEmpty(req.getExcludeIds())) {
visitSummaryService.addPageView(userId, userId, VisitTypeEnum.FOLLOW_THEME_VIEW);
visitLogService.addPageView(userId, userId, VisitTypeEnum.FOLLOW_THEME_VIEW);
}
// 根据关注列表查询,按时间倒序
List<String> fansList = followRelService.queryFansByFollowerId(userId);
......@@ -252,31 +248,31 @@ public class ThemeManager {
return resp;
}
//主题Entity转QO,组装所有信息
// 主题Entity转QO,组装所有信息
private List<ThemeQo> convertEntityToQo(List<ThemeEntity> themeEntities, String userId) {
//Entity转Qo
List<ThemeQo> themeQos = ConvertUtil.themeEntitiesToDTOs(themeEntities);
//批量查询附件detail
// 批量查询附件detail
batchFeignCallService.getAttachDetailByBatch(themeQos);
//其他信息
for (ThemeQo themeQO : themeQos) {
//通用信息
// 通用信息
buildThemeQoExtraInfo(themeQO);
//和用户相关信息
// 和用户相关信息
buildThemeExtraInfoByUser(userId, themeQO);
}
return themeQos;
}
//转发对象、点赞、收藏、转发数
// 转发对象、点赞、收藏、转发数
private void buildThemeQoExtraInfo(ThemeQo themeQo) {
String themeId = themeQo.getThemeId();
//封装转发对象
// 封装转发对象
FormerThemeQo former = redisCache.getObject(StringUtils.joinWith("_", CACHE_FORMER_THEME_ID, themeId), 60,
() -> this.getFormerTheme(themeQo.getFormerThemeId()), FormerThemeQo.class);
themeQo.setFormerTheme(former);
//点赞,收藏,转发
// 点赞,收藏,转发
Integer likeCount = collectionService.getCountByTypeAndId(themeId, CollectionTypeEnum.LIKE_THEME);
Integer commentCount = commentService.getCommentCountByThemeId(themeId);
Integer forwardCount = themeService.getForwardCountById(themeId);
......@@ -285,18 +281,19 @@ public class ThemeManager {
themeQo.setForwardCount(forwardCount);
}
//组装和当前用户相关信息
// 组装和当前用户相关信息
private void buildThemeExtraInfoByUser(String userId, ThemeQo themeQo) {
//todo 批量查询 IN
String themeId = themeQo.getThemeId();
//是否关注作者
// 是否关注作者
themeQo.setFollow(followRelService.checkFollow(themeQo.getAuthorId(), userId));
//是否点赞
// 是否点赞
CollectionEntity likeEntity = collectionService.getNotDeleteTargetCollection(themeId, userId, CollectionTypeEnum.LIKE_THEME);
themeQo.setHasLiked(likeEntity != null);
//是否转发
// 是否转发
Integer forwardCountByUser = themeService.getForwardCountByUser(themeId, userId);
themeQo.setHasForward(forwardCountByUser > 0);
//是否收藏
// 是否收藏
CollectionEntity collectionEntity = collectionService.getNotDeleteTargetCollection(themeId, userId, CollectionTypeEnum.COLLECT_THEME);
themeQo.setHasCollect(collectionEntity != null);
}
......@@ -329,19 +326,19 @@ public class ThemeManager {
}
//查询正文
// 查询正文
public ThemeQo getThemeDetail(String themeId, String userId) {
//TODO 临时埋点,接入新埋点后删除
visitSummaryService.addPageView(userId, themeId, VisitTypeEnum.THEME_PAGE_VIEW);
//查询详情
visitLogService.addPageView(userId, themeId, VisitTypeEnum.THEME_PAGE_VIEW);
// 查询详情
ThemeQo themeQo = redisCache.getObject(StringUtils.joinWith("_", CACHE_THEME_ID, themeId), 60,
() -> this.getDetailCommon(themeId), ThemeQo.class);
//添加用户相关信息
// 添加用户相关信息
buildThemeExtraInfoByUser(userId, themeQo);
return themeQo;
}
//正文通用信息,与用户无关,可使用缓存
// 正文通用信息,与用户无关,可使用缓存
private ThemeQo getDetailCommon(String themeId) {
ThemeEntity themeEntity = themeService.queryByThemeId(themeId);
if (themeEntity == null) {
......@@ -389,7 +386,7 @@ public class ThemeManager {
//关注用户是否有更新
public Integer getFollowUpdateCount(String userId) {
LocalDateTime lastViewTime = visitSummaryService.queryLatestViewFollow(userId);
LocalDateTime lastViewTime = visitLogService.queryLatestViewFollow(userId);
List<String> fansList = followRelService.queryFansByFollowerId(userId);
return themeService.queryCountFromLastTime(fansList, lastViewTime);
}
......@@ -418,9 +415,9 @@ public class ThemeManager {
}
//逻辑删除主题
public void delete(String themeId) {
themeService.deleteById(themeId);
// 逻辑删除主题,校验用户
public void delete(String themeId,String userId) {
themeService.deleteById(themeId,userId);
}
......@@ -477,23 +474,23 @@ public class ThemeManager {
private List<ThemeQo> getCommentThemeQos(QueryRecordThemeReq req, String userId) {
List<ThemeQo> commentThemeList = new ArrayList<>();
List<ThemeEntity> themeEntities;
//评论列表
// 评论列表
List<CommentEntity> commentEntities = commentService.queryCommentsByUserId(req.getUserId(), req.getLastId(), req.getPageSize());
//当前用户信息
UserInfoResp userInfo = redisCache.getObject(StringUtils.joinWith(CACHE_FEIGN_USER_INFO, req.getUserId()),
60 * 10, () -> this.getUserInfo(req.getUserId()), UserInfoResp.class);
// 当前用户信息
UserInfoResp userInfo = redisCache.getObject(StringUtils.joinWith("_", CACHE_FEIGN_USER_INFO, req.getUserId()),
60, () -> this.getUserInfo(req.getUserId()), UserInfoResp.class);
Set<String> replyThemeIds = commentEntities.stream().map(CommentEntity::getThemeId).collect(Collectors.toSet());
if (CollectionUtils.isEmpty(replyThemeIds)) {
return commentThemeList;
}
themeEntities = themeService.queryByThemeIds(new ArrayList<>(replyThemeIds));
List<ThemeQo> themeQos = convertEntityToQo(themeEntities, userId);
//组装附件
// 组装附件
batchFeignCallService.getAttachDetailByBatch(themeQos);
//主题列表
// 主题列表
Map<String, ThemeQo> themeMap = themeQos.stream()
.collect(Collectors.toMap(ThemeQo::getThemeId, o -> o));
//主题+评论封装转发对象
// 主题+评论封装转发对象
for (CommentEntity commentEntity : commentEntities) {
String themeId = commentEntity.getThemeId();
//评论内容包装到ThemeContentQo里
......
......@@ -7,7 +7,7 @@ import com.tanpu.community.api.beans.req.topic.TopicSearchReq;
import com.tanpu.community.api.enums.VisitTypeEnum;
import com.tanpu.community.service.RankService;
import com.tanpu.community.service.TopicService;
import com.tanpu.community.service.VisitSummaryService;
import com.tanpu.community.service.VisitLogService;
import com.tanpu.community.util.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -18,11 +18,9 @@ import java.util.List;
@Service
public class TopicManager {
@Autowired
private TopicService topicService;
@Autowired
private VisitSummaryService visitSummaryService;
private VisitLogService visitLogService;
@Autowired
private RankService rankService;
......@@ -46,7 +44,7 @@ public class TopicManager {
// 话题详情页
public TopicRankQo getDetail(String topicId) {
//TODO 临时埋点,接入新埋点后删除
visitSummaryService.addPageView(userHolder.getUserId(), topicId, VisitTypeEnum.TOPIC_PAGE_VIEW);
visitLogService.addPageView(userHolder.getUserId(), topicId, VisitTypeEnum.TOPIC_PAGE_VIEW);
return rankService.getTopicDetail(topicId);
}
......
......@@ -2,8 +2,8 @@ package com.tanpu.community.manager;
import com.alibaba.fastjson.JSON;
import com.tanpu.community.api.beans.vo.KafkaDurationUptMsg;
import com.tanpu.community.dao.entity.community.VisitSummaryEntity;
import com.tanpu.community.service.VisitSummaryService;
import com.tanpu.community.dao.entity.community.VisitLogEntity;
import com.tanpu.community.service.VisitLogService;
import com.tanpu.community.util.ConvertUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -21,7 +21,7 @@ public class VisitSummaryManager {
private KafkaTemplate<String, String> kafkaTemplate;
@Autowired
private VisitSummaryService visitSummaryService;
private VisitLogService visitLogService;
@KafkaListener(topics = kafakTopic)
......@@ -29,7 +29,7 @@ public class VisitSummaryManager {
log.info("receive kafka msg: {}", message);
KafkaDurationUptMsg msg = JSON.parseObject(message, KafkaDurationUptMsg.class);
// ident在每次进入新页面 & 回退 的时候都会随机生成一个,所以用ident做唯一key即可。
VisitSummaryEntity vs = ConvertUtil.convertFromKafka(msg);
visitSummaryService.insertOrUpdateDur(vs);
VisitLogEntity vs = ConvertUtil.convertFromKafka(msg);
visitLogService.insertOrUpdateDur(vs);
}
}
......@@ -79,7 +79,8 @@ public class CollectionService {
return collectionMapper.selectList(new LambdaQueryWrapper<CollectionEntity>()
.eq(CollectionEntity::getUserId, userId)
.eq(CollectionEntity::getCollectionType, type.getCode())
.eq(CollectionEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()))
.eq(CollectionEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())
.orderByDesc(CollectionEntity::getCollectionTime))
.stream().map(CollectionEntity::getTargetId).collect(Collectors.toList());
}
......
......@@ -124,4 +124,18 @@ public class CommentService {
commentMapper.updateById(commentEntity);
redisCache.evict(StringUtils.joinWith("_", CAHCE_COMMENT_ID, commentId));
}
//删除评论
@Transactional
public void delete(String commentId, String userId) {
CommentEntity commentEntity = this.queryByCommentId(commentId);
if (commentEntity==null || !commentEntity.getAuthorId().equals(userId)){
throw new BizException("删除评论与用户不匹配,commentId:"+commentId+",userId:"+userId);
}
commentEntity.setDeleteTag(DeleteTagEnum.DELETED.getCode());
commentMapper.updateById(commentEntity);
//删除主题的评论列表缓存
redisCache.evict(StringUtils.joinWith("_", CAHCE_COMMENT_ID, commentEntity.getThemeId()));
}
}
......@@ -23,19 +23,19 @@ public class FollowRelService {
public List<String> queryFansByFollowerId(String followerId) {
return followRelMapper.selectList(new LambdaQueryWrapper<FollowRelEntity>()
.eq(FollowRelEntity::getFollowerId, followerId)
.eq(FollowRelEntity::getFansId, followerId)
.eq(FollowRelEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()))
.stream().map(FollowRelEntity::getFollowUserId)
.stream().map(FollowRelEntity::getIdolId)
.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::getIdolId, idolId)
.eq(FollowRelEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
return followRelMapper.selectList(queryWrapper)
.stream().map(FollowRelEntity::getFollowerId).collect(Collectors.toList());
.stream().map(FollowRelEntity::getFansId).collect(Collectors.toList());
}
@Transactional
......@@ -43,8 +43,8 @@ public class FollowRelService {
FollowRelEntity searchResult = queryRecord(idolId, followerId);
if (searchResult==null){
FollowRelEntity entity = FollowRelEntity.builder()
.followUserId(idolId)
.followerId(followerId)
.idolId(idolId)
.fansId(followerId)
.followTime(LocalDateTime.now())
.build();
......@@ -75,14 +75,14 @@ public class FollowRelService {
public FollowRelEntity queryRecord(String idolId, String followerId){
return followRelMapper.selectOne(new LambdaQueryWrapper<FollowRelEntity>()
.eq(FollowRelEntity::getFollowUserId,idolId)
.eq(FollowRelEntity::getFollowerId,followerId));
.eq(FollowRelEntity::getIdolId,idolId)
.eq(FollowRelEntity::getFansId,followerId));
}
public boolean checkFollow(String idolId,String followerId){
return followRelMapper.selectCount(new LambdaQueryWrapper<FollowRelEntity>()
.eq(FollowRelEntity::getFollowUserId,idolId)
.eq(FollowRelEntity::getFollowerId,followerId)
.eq(FollowRelEntity::getIdolId,idolId)
.eq(FollowRelEntity::getFansId,followerId)
.eq(FollowRelEntity::getDeleteTag,DeleteTagEnum.NOT_DELETED.getCode()))
>0;
}
......
......@@ -33,7 +33,7 @@ public class RankService {
@Autowired
private TopicService topicService;
@Autowired
private VisitSummaryService visitSummaryService;
private VisitLogService visitLogService;
@Autowired
private FeignService feignService;
......@@ -57,7 +57,7 @@ public class RankService {
public void rankThemes() {
//7天内所有主题进行热度值排序
List<ThemeEntity> themeEntities = themeService.queryRecentdays(7);
if (CollectionUtils.isEmpty(themeEntities)){
if (CollectionUtils.isEmpty(themeEntities)) {
return;
}
List<ThemeAnalysDO> themeAnalysDOS = ConvertUtil.themeEntityToAnalysDOs(themeEntities);
......@@ -67,19 +67,19 @@ public class RankService {
Map<String, Integer> bookCountMap = collectionService.getCountMapByType(themeIds, CollectionTypeEnum.COLLECT_THEME);
Map<String, Integer> commentCountMap = commentService.getCountMapByThemeIds(themeIds);
Map<String, Integer> forwardCountMap = themeService.getForwardCountMap(themeIds);
Map<String, Integer> visitCountMap = visitSummaryService.getCountMapByTargetIds(themeIds, VisitTypeEnum.THEME_PAGE_VIEW);
Map<String, Integer> visitCountMap = visitLogService.getCountMapByTargetIds(themeIds, VisitTypeEnum.THEME_PAGE_VIEW);
for (ThemeAnalysDO theme : themeAnalysDOS) {
String themeId = theme.getThemeId();
theme.setCommentCount(commentCountMap.getOrDefault(themeId,0));
theme.setCommentCount(commentCountMap.getOrDefault(themeId, 0));
theme.setLikeCount(likeCountMap.getOrDefault(themeId, 0));
theme.setForwardCount(forwardCountMap.getOrDefault(themeId,0));
theme.setCollectCount(bookCountMap.getOrDefault(themeId,0));
theme.setViewCount(visitCountMap.getOrDefault(themeId,0));
theme.setForwardCount(forwardCountMap.getOrDefault(themeId, 0));
theme.setCollectCount(bookCountMap.getOrDefault(themeId, 0));
theme.setViewCount(visitCountMap.getOrDefault(themeId, 0));
//查询用户质量
String authorId = theme.getAuthorId();
UserInfoResp authorInfo = redisCache.getObject(StringUtils.joinWith(CACHE_FEIGN_USER_INFO, authorId),
60 * 10, () -> feignService.getUserInfoById(authorId), UserInfoResp.class);
UserInfoResp authorInfo = redisCache.getObject(StringUtils.joinWith("_", CACHE_FEIGN_USER_INFO, authorId),
60, () -> feignService.getUserInfoById(authorId), UserInfoResp.class);
if (authorInfo == null || authorInfo.getLevelGrade() == null) {
theme.setUserWeight(0.0);
} else {
......@@ -109,17 +109,17 @@ public class RankService {
}
List<TopicRankQo> topicRankQos = ConvertUtil.topicEntityToHotQos(topicEntities);
List<String> topicIds = topicRankQos.stream().map(TopicRankQo::getTopicId).collect(Collectors.toList());
Map<String, Integer> countMapByTargetIds = visitSummaryService.getCountMapByTargetIds(topicIds, VisitTypeEnum.TOPIC_PAGE_VIEW);
Map<String, Integer> countMapByTargetIds = visitLogService.getCountMapByTargetIds(topicIds, VisitTypeEnum.TOPIC_PAGE_VIEW);
for (TopicRankQo topic : topicRankQos) {
List<String> themeIds = themeService.queryThemeIdsByTopic(topic.getTopicId());
if (CollectionUtils.isEmpty(themeIds)) {
topic.setViewCount(countMapByTargetIds.getOrDefault(topic.getTopicId(),0));
topic.setViewCount(countMapByTargetIds.getOrDefault(topic.getTopicId(), 0));
topic.setDisscussCount(0);
continue;
}
// 浏览量
Integer topicPV = countMapByTargetIds.getOrDefault(topic.getTopicId(),0);
Integer themePV = visitSummaryService.queryThemeVisit(themeIds);
Integer topicPV = countMapByTargetIds.getOrDefault(topic.getTopicId(), 0);
Integer themePV = visitLogService.queryThemeVisit(themeIds);
topic.setViewCount(topicPV + themePV);
//讨论数=发布主题贴数+回复总数
Integer commentCount = commentService.getTotalCountByThemeIds(themeIds);
......
......@@ -42,7 +42,7 @@ public class RecommendService {
private ThemeService themeService;
@Autowired
private VisitSummaryService visitSummaryService;
private VisitLogService visitLogService;
// 最新
private List<ThemeAnalysDO> recentThemeList = new ArrayList<>();
......
......@@ -263,11 +263,11 @@ public class ThemeService {
}
@Transactional
public void deleteById(String themeId) {
public void deleteById(String themeId,String userId) {
ThemeEntity themeEntity = themeMapper.selectOne(new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getThemeId, themeId));
if (themeEntity == null) {
throw new BizException("主题未找到,id:" + themeId);
if (themeEntity == null || !themeEntity.getAuthorId().equals(userId)) {
throw new BizException("主题与用户不匹配,id:" + themeId+",userId"+userId);
}
themeEntity.setDeleteTag(DeleteTagEnum.DELETED.getCode());
themeMapper.updateById(themeEntity);
......
......@@ -4,8 +4,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.api.enums.VisitTypeEnum;
import com.tanpu.community.dao.entity.community.TimesCountEntity;
import com.tanpu.community.dao.entity.community.VisitSummaryEntity;
import com.tanpu.community.dao.mapper.community.VisitSummaryMapper;
import com.tanpu.community.dao.entity.community.VisitLogEntity;
import com.tanpu.community.dao.mapper.community.VisitLogMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
......@@ -23,16 +23,16 @@ import java.util.stream.Collectors;
@Slf4j
@Service
public class VisitSummaryService {
public class VisitLogService {
@Resource
private VisitSummaryMapper visitSummaryMapper;
private VisitLogMapper visitLogMapper;
// 获取用户7天内访问过的
public List<String> queryUserRecentVisited(String userId) {
Date endDate = new Date();
Date startDate = DateUtils.addDays(endDate, -7);
List<String> visited = visitSummaryMapper.selectRefIdByUserIdAndCreateBetween(userId, startDate, endDate);
List<String> visited = visitLogMapper.selectRefIdByUserIdAndCreateBetween(userId, startDate, endDate);
return visited;
}
......@@ -41,33 +41,33 @@ public class VisitSummaryService {
if (refIds.isEmpty()) {
return refIds;
}
List<String> visited = visitSummaryMapper.selectList(new LambdaQueryWrapper<VisitSummaryEntity>()
.eq(VisitSummaryEntity::getVisitorId, userId)
.in(VisitSummaryEntity::getRefId, refIds))
.stream().map(VisitSummaryEntity::getRefId).distinct().collect(Collectors.toList());
List<String> visited = visitLogMapper.selectList(new LambdaQueryWrapper<VisitLogEntity>()
.eq(VisitLogEntity::getVisitorId, userId)
.in(VisitLogEntity::getRefId, refIds))
.stream().map(VisitLogEntity::getRefId).distinct().collect(Collectors.toList());
return ListUtils.subtract(refIds, visited);
}
public List<String> queryUserVisited(String userId) {
List<String> visited = visitSummaryMapper.selectList(new LambdaQueryWrapper<VisitSummaryEntity>()
.eq(VisitSummaryEntity::getVisitorId, userId))
.stream().map(VisitSummaryEntity::getRefId).distinct().collect(Collectors.toList());
List<String> visited = visitLogMapper.selectList(new LambdaQueryWrapper<VisitLogEntity>()
.eq(VisitLogEntity::getVisitorId, userId))
.stream().map(VisitLogEntity::getRefId).distinct().collect(Collectors.toList());
return visited;
}
@Transactional
public void insertOrUpdateDur(VisitSummaryEntity vs) {
if (visitSummaryMapper.selectByIdent(vs.getIdent()) == null) {
visitSummaryMapper.insert(vs);
public void insertOrUpdateDur(VisitLogEntity vs) {
if (visitLogMapper.selectByIdent(vs.getIdent()) == null) {
visitLogMapper.insert(vs);
} else {
visitSummaryMapper.updateDurByIdent(vs.getDuration(), vs.getIdent());
visitLogMapper.updateDurByIdent(vs.getDuration(), vs.getIdent());
}
}
@Transactional
//TODO 临时埋点,接入新埋点后删除
public void addPageView(String userId, String targetId, VisitTypeEnum type) {
visitSummaryMapper.insert(VisitSummaryEntity.builder()
visitLogMapper.insert(VisitLogEntity.builder()
.visitorId(userId)
.refId(targetId)
.refType(type.getCode())
......@@ -77,16 +77,16 @@ public class VisitSummaryService {
// 查询话题 详细页面 浏览量
public Integer queryTopicDetailVisit(String topicId) {
return visitSummaryMapper.selectCount(new LambdaQueryWrapper<VisitSummaryEntity>()
.eq(VisitSummaryEntity::getRefId, topicId)
.eq(VisitSummaryEntity::getRefType, VisitTypeEnum.TOPIC_PAGE_VIEW.getCode()));
return visitLogMapper.selectCount(new LambdaQueryWrapper<VisitLogEntity>()
.eq(VisitLogEntity::getRefId, topicId)
.eq(VisitLogEntity::getRefType, VisitTypeEnum.TOPIC_PAGE_VIEW.getCode()));
}
// 查询主题 浏览量
public Integer queryThemeVisit(String theme) {
return visitSummaryMapper.selectCount(new LambdaQueryWrapper<VisitSummaryEntity>()
.eq(VisitSummaryEntity::getRefId, theme)
.eq(VisitSummaryEntity::getRefType, VisitTypeEnum.THEME_PAGE_VIEW.getCode()));
return visitLogMapper.selectCount(new LambdaQueryWrapper<VisitLogEntity>()
.eq(VisitLogEntity::getRefId, theme)
.eq(VisitLogEntity::getRefType, VisitTypeEnum.THEME_PAGE_VIEW.getCode()));
}
// 查询主题 浏览量
......@@ -94,16 +94,16 @@ public class VisitSummaryService {
if (CollectionUtils.isEmpty(themes)){
return 0;
}
return visitSummaryMapper.selectCount(new LambdaQueryWrapper<VisitSummaryEntity>()
.in(VisitSummaryEntity::getRefId, themes)
.eq(VisitSummaryEntity::getRefType, VisitTypeEnum.THEME_PAGE_VIEW.getCode()));
return visitLogMapper.selectCount(new LambdaQueryWrapper<VisitLogEntity>()
.in(VisitLogEntity::getRefId, themes)
.eq(VisitLogEntity::getRefType, VisitTypeEnum.THEME_PAGE_VIEW.getCode()));
}
public LocalDateTime queryLatestViewFollow(String userId) {
List<VisitSummaryEntity> visitSummaryEntities = visitSummaryMapper.selectList(new LambdaQueryWrapper<VisitSummaryEntity>()
.eq(VisitSummaryEntity::getVisitorId, userId)
.eq(VisitSummaryEntity::getRefType, VisitTypeEnum.FOLLOW_THEME_VIEW.getCode())
.orderByDesc(VisitSummaryEntity::getCreateTime));
List<VisitLogEntity> visitSummaryEntities = visitLogMapper.selectList(new LambdaQueryWrapper<VisitLogEntity>()
.eq(VisitLogEntity::getVisitorId, userId)
.eq(VisitLogEntity::getRefType, VisitTypeEnum.FOLLOW_THEME_VIEW.getCode())
.orderByDesc(VisitLogEntity::getCreateTime));
if (CollectionUtils.isEmpty(visitSummaryEntities)) {
return null;
} else {
......@@ -116,12 +116,12 @@ public class VisitSummaryService {
if (CollectionUtils.isEmpty(refIds)){
return new HashMap<>();
}
LambdaQueryWrapper<VisitSummaryEntity> wrapper = (new LambdaQueryWrapper<VisitSummaryEntity>()
.in(VisitSummaryEntity::getRefId,refIds))
.eq(VisitSummaryEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED)
.eq(VisitSummaryEntity::getRefType,type.getCode())
.groupBy(VisitSummaryEntity::getRefId);
return visitSummaryMapper.selectCountByThemeIds(wrapper).stream()
LambdaQueryWrapper<VisitLogEntity> wrapper = (new LambdaQueryWrapper<VisitLogEntity>()
.in(VisitLogEntity::getRefId,refIds))
.eq(VisitLogEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED)
.eq(VisitLogEntity::getRefType,type.getCode())
.groupBy(VisitLogEntity::getRefId);
return visitLogMapper.selectCountByThemeIds(wrapper).stream()
.collect(Collectors.toMap(TimesCountEntity::getId, TimesCountEntity::getTimes));
}
}
......@@ -31,7 +31,7 @@ public class BizUtils {
return paragraph.getValue();
} else {
// 否则,保留关键词 向前20个字符
return paragraph.getValue().substring(idx - 20);
return "..." + paragraph.getValue().substring(idx - 20);
}
}
}
......
......@@ -120,8 +120,8 @@ public class ConvertUtil {
/**
* VISIT_SUMMARY
*/
public static VisitSummaryEntity convertFromKafka(KafkaDurationUptMsg msg) {
VisitSummaryEntity vs = new VisitSummaryEntity();
public static VisitLogEntity convertFromKafka(KafkaDurationUptMsg msg) {
VisitLogEntity vs = new VisitLogEntity();
vs.setAuthorId(msg.pidUserId);
vs.setDeleteTag(DeleteTagEnum.NOT_DELETED.ordinal());
vs.setDuration(1);
......
apollo.bootstrap.enabled: true
apollo.bootstrap.enabled: false
#app.id: tanpu-community
#apollo:
......@@ -11,21 +11,19 @@ server:
port: 8080
servlet:
context-path: /community
spring.datasource:
community:
driver-class-name: com.mysql.cj.jdbc.Driver
jdbc-url: jdbc:mysql://47.101.189.151:31931/tamp_community?useUnicode=true&characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=CONVERT_TO_NULL&allowMultiQueries=true&rewriteBatchedStatements=true
username: dev
password: qimeng123
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
password: '@imeng123'
maxActive: 2
minIdle: 2
initialSize: 2
user:
driver-class-name: com.mysql.cj.jdbc.Driver
jdbc-url: jdbc:mysql://47.101.189.151:31931/tamp_user?useUnicode=true&characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=CONVERT_TO_NULL&allowMultiQueries=true&rewriteBatchedStatements=true
username: dev
password: qimeng123
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
password: '@imeng123'
maxActive: 2
minIdle: 2
initialSize: 2
......@@ -95,5 +93,5 @@ recommend:
new: 2
python: 1
python:
enable: false
enable: true
url: http://172.168.0.164:9000/api/get_recommend?user_id=2431614397151511
\ No newline at end of file
......@@ -8,7 +8,7 @@ apollo.bootstrap.enabled: true
# namespaces: application.yml
server:
port: 8060
port: 8080
servlet:
context-path: /community
......
......@@ -12,7 +12,7 @@
<result column="theme_id" property="themeId" />
<result column="parent_id" property="parentId" />
<result column="reply_id" property="replyId" />
<result column="is_pass" property="isPass" />
<result column="review_status" property="reviewStatus" />
<result column="report_status" property="reportStatus" />
<result column="create_time" property="createTime" />
<result column="update_time" property="updateTime" />
......
......@@ -5,8 +5,8 @@
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.tanpu.community.dao.entity.community.FollowRelEntity">
<id column="id" property="id" />
<result column="follow_user_id" property="followUserId" />
<result column="follower_id" property="followerId" />
<result column="idol_id" property="idolId" />
<result column="fans_id" property="fansId" />
<result column="follow_time" property="followTime" />
<result column="unfollow_time" property="unfollowTime" />
<result column="create_time" property="createTime" />
......
......@@ -9,11 +9,10 @@
<result column="title" property="title" />
<result column="theme_type" property="themeType" />
<result column="content" property="content" />
<result column="discuss_content" property="discussContent" />
<result column="author_id" property="authorId" />
<result column="former_theme_id" property="formerThemeId" />
<result column="topic_id" property="topicId" />
<result column="is_pass" property="isPass" />
<result column="review_status" property="reviewStatus" />
<result column="report_status" property="reportStatus" />
<result column="create_time" property="createTime" />
<result column="update_time" property="updateTime" />
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tanpu.community.dao.mapper.community.VisitSummaryMapper">
<mapper namespace="com.tanpu.community.dao.mapper.community.VisitLogMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.tanpu.community.dao.entity.community.VisitSummaryEntity">
<resultMap id="BaseResultMap" type="com.tanpu.community.dao.entity.community.VisitLogEntity">
<id column="id" property="id" />
<result column="ident" property="ident" />
<result column="visitor_id" property="visitorId" />
......
......@@ -128,6 +128,18 @@
<version>2.4.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
......
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