Commit 5d29373d authored by 刘基明's avatar 刘基明

用户信息源修改

parent 312f3678
package com.tanpu.community.api.beans.qo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class MyCommentThemeQo extends ThemeQo{
@ApiModelProperty(value = "评论内容")
private String comment;
}
...@@ -13,7 +13,7 @@ public class QueryRecordThemeReq { ...@@ -13,7 +13,7 @@ public class QueryRecordThemeReq {
@ApiModelProperty("用户Id") @ApiModelProperty("用户Id")
private String userId; private String userId;
@ApiModelProperty(value = "操作类型 1:发布 2:回复 3:点赞 4:收藏") @ApiModelProperty(value = "操作类型 1:发布 2:点赞 3:收藏")
private Integer recordType; private Integer recordType;
@ApiModelProperty(value = "当前浏览的最后一个themeId,可以为空") @ApiModelProperty(value = "当前浏览的最后一个themeId,可以为空")
......
...@@ -29,4 +29,8 @@ public class CreateThemeReq { ...@@ -29,4 +29,8 @@ public class CreateThemeReq {
private String topicId; private String topicId;
@ApiModelProperty(value = "修改,则传入正在编辑的ThemeId")
private String editThemeId;
} }
...@@ -22,4 +22,7 @@ public class ForwardThemeReq { ...@@ -22,4 +22,7 @@ public class ForwardThemeReq {
@ApiModelProperty(value = "话题Id") @ApiModelProperty(value = "话题Id")
private String topicId; private String topicId;
@ApiModelProperty(value = "修改,则传入正在编辑的ThemeId")
private String editThemeId;
} }
package com.tanpu.community.api.enums;
public enum VisitTypeEnum {
TOPIC_PAGE_VIEW(1,"进入话题页"),
THEME_PAGE_VIEW(2,"进入主题正文");
private Integer code;
private String type;
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
VisitTypeEnum(Integer code, String type) {
this.code = code;
this.type = type;
}
}
package com.tanpu.community.controller; package com.tanpu.community.controller;
import com.tanpu.common.api.CommonResp; import com.tanpu.common.api.CommonResp;
import com.tanpu.community.api.constants.RedisKeyConstant; import com.tanpu.common.auth.AuthLogin;
import com.tanpu.community.service.RedisService; import com.tanpu.community.manager.VisitSummaryManager;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@Slf4j
@RequestMapping(value = "/metric") @RequestMapping(value = "/metric")
public class MetricsController { public class MetricsController {
@Autowired @Autowired
private RedisService redisService; private VisitSummaryManager visitSummaryManager;
@ApiOperation("浏览量埋点") @AuthLogin
@RequestMapping("/pv") @ApiOperation("浏览话题")
public CommonResp pageView(@RequestParam String themeId){ @GetMapping("/view/topic")
redisService.incr(RedisKeyConstant.THEME_VIEW_COUNT_ +themeId, 1L); public CommonResp pageViewTopic(@RequestParam String topicId){
visitSummaryManager.addTopicPageView(topicId);
return CommonResp.success(); return CommonResp.success();
} }
@AuthLogin
@ApiOperation("浏览主题")
@GetMapping("/view/theme")
public CommonResp pageViewTheme(@RequestParam String themeId){
visitSummaryManager.addThemePageView(themeId);
return CommonResp.success();
}
......
...@@ -39,7 +39,6 @@ public class TopicController { ...@@ -39,7 +39,6 @@ public class TopicController {
@ApiOperation("话题详情页顶部") @ApiOperation("话题详情页顶部")
@ResponseBody @ResponseBody
public CommonResp<TopicDetailQo> gethotThemes(@RequestParam String topicId){ public CommonResp<TopicDetailQo> gethotThemes(@RequestParam String topicId){
//todo
TopicDetailQo detail = topicManager.getDetail(topicId); TopicDetailQo detail = topicManager.getDetail(topicId);
return CommonResp.success(detail); return CommonResp.success(detail);
} }
......
...@@ -10,10 +10,7 @@ import com.tanpu.community.api.enums.BlockTypeEnum; ...@@ -10,10 +10,7 @@ import com.tanpu.community.api.enums.BlockTypeEnum;
import com.tanpu.community.api.enums.CollectionTypeEnum; import com.tanpu.community.api.enums.CollectionTypeEnum;
import com.tanpu.community.api.enums.ThemeListTypeEnum; import com.tanpu.community.api.enums.ThemeListTypeEnum;
import com.tanpu.community.api.enums.ThemeTypeEnum; import com.tanpu.community.api.enums.ThemeTypeEnum;
import com.tanpu.community.dao.entity.community.BlackListEntity; import com.tanpu.community.dao.entity.community.*;
import com.tanpu.community.dao.entity.community.CollectionEntity;
import com.tanpu.community.dao.entity.community.ThemeAttachmentEntity;
import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.service.*; import com.tanpu.community.service.*;
import com.tanpu.community.service.other.BlackListService; import com.tanpu.community.service.other.BlackListService;
import com.tanpu.community.util.ConvertUtil; import com.tanpu.community.util.ConvertUtil;
...@@ -23,10 +20,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -23,10 +20,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.*;
import java.util.HashSet; import java.util.stream.Collectors;
import java.util.List;
import java.util.Set;
@Service @Service
public class ThemeManager { public class ThemeManager {
...@@ -70,7 +65,14 @@ public class ThemeManager { ...@@ -70,7 +65,14 @@ public class ThemeManager {
BeanUtils.copyProperties(req, themeEntity); BeanUtils.copyProperties(req, themeEntity);
themeEntity.setAuthorId(userId); themeEntity.setAuthorId(userId);
themeEntity.setContent(JsonUtil.toJson(req.getContent())); themeEntity.setContent(JsonUtil.toJson(req.getContent()));
themeService.insertTheme(themeEntity); if (StringUtils.isEmpty(req.getEditThemeId())){
//新建
themeService.insertTheme(themeEntity);
}else {
//修改
themeService.update(themeEntity,req.getEditThemeId());
}
//保存附件表 //保存附件表
List<ThemeAttachmentEntity> themeAttachments = ConvertUtil.themeReqToAttachmentList(req, themeEntity.getThemeId()); List<ThemeAttachmentEntity> themeAttachments = ConvertUtil.themeReqToAttachmentList(req, themeEntity.getThemeId());
themeAttachmentService.insertList(themeAttachments); themeAttachmentService.insertList(themeAttachments);
...@@ -86,7 +88,7 @@ public class ThemeManager { ...@@ -86,7 +88,7 @@ public class ThemeManager {
} else if (ThemeListTypeEnum.FOLLOW.getCode().equals(req.getType())) { } else if (ThemeListTypeEnum.FOLLOW.getCode().equals(req.getType())) {
//根据关注列表查询 //根据关注列表查询
List<String> fansList = followRelService.queryFansByFollowerId(userId); List<String> fansList = followRelService.queryFansByFollowerId(userId);
themeEntities = themeService.queryByFans(fansList, req.getLastId(), req.getPageSize()); themeEntities = themeService.queryByUserIds(fansList, req.getLastId(), req.getPageSize());
} else if (ThemeListTypeEnum.TOPIC_HOT.getCode().equals(req.getType())) { } else if (ThemeListTypeEnum.TOPIC_HOT.getCode().equals(req.getType())) {
//TODO 根据话题查询热门 //TODO 根据话题查询热门
...@@ -103,10 +105,30 @@ public class ThemeManager { ...@@ -103,10 +105,30 @@ public class ThemeManager {
// 返回用户发布、回复、收藏的主题列表 // 返回用户发布、回复、收藏的主题列表
public List<ThemeQo> queryThemesByUser(QueryRecordThemeReq req, String userId) { public List<ThemeQo> queryThemesByUser(QueryRecordThemeReq req, String userId) {
// TODO
// List<ThemeEntity> themeEntities = themeService.queryByUser(req.getUserId(), req.getPageSize(),req.getLastId()); List<ThemeEntity> themeEntities = Collections.emptyList();
List<ThemeEntity> themeEntities = themeService.selectAll(req.getLastId(), req.getPageSize()); switch (req.getRecordType()) {
return convertEntityToQo(themeEntities, userId); case 1://发布
themeEntities = themeService.queryThemeIdsByUserId(req.getUserId());
break;
case 2://点赞
Set<String> likeThemeIds = collectionService.getListByUser(userId, CollectionTypeEnum.LIKE_THEME);
themeEntities = themeService.queryByThemeIds(new ArrayList<>(likeThemeIds));
break;
case 3://收藏
Set<String> collectThemeIds = collectionService.getListByUser(userId, CollectionTypeEnum.COLLECT_THEME);
themeEntities = themeService.queryByThemeIds(new ArrayList<>(collectThemeIds));
break;
}
List<ThemeQo> themeQos = convertEntityToQo(themeEntities, userId);
return themeQos;
}
public List<ThemeQo> queryThemesByUserComment(QueryRecordThemeReq req, String userId) {
List<CommentEntity> commentEntities = commentService.queryThemesByUserId(req.getUserId());
Set<String> replyThemeIds = commentEntities.stream().map(CommentEntity::getThemeId).collect(Collectors.toSet());
List<ThemeEntity> themeEntities = themeService.queryByThemeIds(new ArrayList<>(replyThemeIds));
return null;
} }
...@@ -125,9 +147,9 @@ public class ThemeManager { ...@@ -125,9 +147,9 @@ public class ThemeManager {
// 点赞/取消点赞 // 点赞/取消点赞
public void like(LikeThemeReq req, String userId) { public void like(LikeThemeReq req, String userId) {
//todo 枚举值 //todo 枚举值
if (1==req.getType()){ if (1 == req.getType()) {
collectionService.addIfNotExist(req.getThemeId(), userId, CollectionTypeEnum.LIKE_THEME); collectionService.addIfNotExist(req.getThemeId(), userId, CollectionTypeEnum.LIKE_THEME);
}else if (2==req.getType()) { } else if (2 == req.getType()) {
collectionService.delete(req.getThemeId(), userId, CollectionTypeEnum.LIKE_THEME); collectionService.delete(req.getThemeId(), userId, CollectionTypeEnum.LIKE_THEME);
} }
...@@ -136,9 +158,9 @@ public class ThemeManager { ...@@ -136,9 +158,9 @@ public class ThemeManager {
//收藏/取消收藏 //收藏/取消收藏
public void collect(CollectThemeReq req, String userId) { public void collect(CollectThemeReq req, String userId) {
//todo 枚举值 //todo 枚举值
if (1==req.getType()){ if (1 == req.getType()) {
collectionService.addIfNotExist(req.getThemeId(), userId, CollectionTypeEnum.COLLECT_THEME); collectionService.addIfNotExist(req.getThemeId(), userId, CollectionTypeEnum.COLLECT_THEME);
}else if (2==req.getType()) { } else if (2 == req.getType()) {
collectionService.delete(req.getThemeId(), userId, CollectionTypeEnum.COLLECT_THEME); collectionService.delete(req.getThemeId(), userId, CollectionTypeEnum.COLLECT_THEME);
} }
} }
...@@ -154,13 +176,16 @@ public class ThemeManager { ...@@ -154,13 +176,16 @@ public class ThemeManager {
.themeType(ThemeTypeEnum.FORWARD.getCode()) .themeType(ThemeTypeEnum.FORWARD.getCode())
.build(); .build();
themeService.insertTheme(newTheme); if (StringUtils.isEmpty(req.getEditThemeId())){
//新建
themeService.insertTheme(newTheme);
}else {
//修改
themeService.update(newTheme,req.getEditThemeId());
}
} }
//投诉(主题) //投诉(主题)
public void complaint(String themeId, String user) { public void complaint(String themeId, String user) {
//TODO //TODO
...@@ -200,8 +225,8 @@ public class ThemeManager { ...@@ -200,8 +225,8 @@ public class ThemeManager {
List<ThemeQo> themeQos = ConvertUtil.themeEntitiesToDTOs(themeEntities); List<ThemeQo> themeQos = ConvertUtil.themeEntitiesToDTOs(themeEntities);
//批量查询附件detail //批量查询附件detail
productService.transferAttachments(themeQos); productService.transferAttachments(themeQos);
//其他信息
for (ThemeQo themeQO : themeQos) { for (ThemeQo themeQO : themeQos) {
buildThemeQoExtraInfo(userId, themeQO); buildThemeQoExtraInfo(userId, themeQO);
} }
return themeQos; return themeQos;
...@@ -210,22 +235,19 @@ public class ThemeManager { ...@@ -210,22 +235,19 @@ public class ThemeManager {
//组装主题列表 //组装主题列表
private void buildThemeQoExtraInfo(String userId, ThemeQo themeQo) { private void buildThemeQoExtraInfo(String userId, ThemeQo themeQo) {
//附件列表
String themeId = themeQo.getThemeId(); String themeId = themeQo.getThemeId();
//迄今时间
//是否关注作者 //是否关注作者
String authorId = themeQo.getAuthorId(); String authorId = themeQo.getAuthorId();
Set<String> fansSet = new HashSet<>(followRelService.queryFansByFollowerId(userId)); Set<String> fansSet = new HashSet<>(followRelService.queryFansByFollowerId(userId));
themeQo.setFollow(fansSet.contains(authorId)); themeQo.setFollow(fansSet.contains(authorId));
//是否点赞 //是否点赞
CollectionEntity likeEntity = collectionService.getNotDeleteTargetCollection(themeId, userId, CollectionTypeEnum.LIKE_THEME); CollectionEntity likeEntity = collectionService.getNotDeleteTargetCollection(themeId, userId, CollectionTypeEnum.LIKE_THEME);
themeQo.setHasLiked(likeEntity!=null); themeQo.setHasLiked(likeEntity != null);
//是否转发 //是否转发
Integer forwardCountByUser = themeService.getForwardCountByUser(themeId, userId); Integer forwardCountByUser = themeService.getForwardCountByUser(themeId, userId);
themeQo.setHasForward(forwardCountByUser>0); themeQo.setHasForward(forwardCountByUser > 0);
//转发原文 //转发原文
buildFormerTheme(themeQo); buildFormerTheme(themeQo);
//热点数据:点赞,收藏,转发 //热点数据:点赞,收藏,转发
...@@ -251,10 +273,10 @@ public class ThemeManager { ...@@ -251,10 +273,10 @@ public class ThemeManager {
private void buildFormerTheme(ThemeQo themeQo) { private void buildFormerTheme(ThemeQo themeQo) {
String formerThemeId = themeQo.getFormerThemeId(); String formerThemeId = themeQo.getFormerThemeId();
if (StringUtils.isNotEmpty(formerThemeId)){ if (StringUtils.isNotEmpty(formerThemeId)) {
ThemeQo formerTheme = ConvertUtil.themeEntityToQo2(themeService.queryByThemeId(formerThemeId)); ThemeQo formerTheme = ConvertUtil.themeEntityToQo2(themeService.queryByThemeId(formerThemeId));
if (formerTheme==null){ if (formerTheme == null) {
throw new BizException("转发主题Id错误,id:"+formerThemeId); throw new BizException("转发主题Id错误,id:" + formerThemeId);
} }
productService.transferAttachement(formerTheme); productService.transferAttachement(formerTheme);
FormerThemeQo f = FormerThemeQo.builder().formerThemeId(formerThemeId) FormerThemeQo f = FormerThemeQo.builder().formerThemeId(formerThemeId)
...@@ -267,9 +289,6 @@ public class ThemeManager { ...@@ -267,9 +289,6 @@ public class ThemeManager {
} }
public void delete(String themeId) { public void delete(String themeId) {
themeService.deleteById(themeId); themeService.deleteById(themeId);
......
...@@ -41,6 +41,9 @@ public class TopicManager { ...@@ -41,6 +41,9 @@ public class TopicManager {
@Autowired @Autowired
private CommentService commentService; private CommentService commentService;
@Autowired
private VisitSummaryService visitSummaryService;
//新增话题 //新增话题
public void insertTopic(String topicTitle, String userId) { public void insertTopic(String topicTitle, String userId) {
if (topicService.queryByTitile(topicTitle) == null) { if (topicService.queryByTitile(topicTitle) == null) {
...@@ -62,38 +65,42 @@ public class TopicManager { ...@@ -62,38 +65,42 @@ public class TopicManager {
List<TopicTitileQo> topicTitileQos = ConvertUtil.topicEntitiesToBriefDTOs(allTopic); List<TopicTitileQo> topicTitileQos = ConvertUtil.topicEntitiesToBriefDTOs(allTopic);
for (TopicTitileQo topicQo : topicTitileQos) { for (TopicTitileQo topicQo : topicTitileQos) {
//TODO 讨论数=发布主题贴数+回复总数 //讨论数=发布主题贴数+回复总数
// Integer commentCountByThemeIds = commentService.getCommentCountByThemeIds(themeIds); List<String> themeIds = themeService.queryThemeIdsByTopic(topicQo.getTopicId());
topicQo.setDiscussionCount(0); Integer commentCount = commentService.getCommentCountByThemeIds(themeIds);
topicQo.setDiscussionCount(themeIds.size() + commentCount);
} }
//TODO 判断顶置 //TODO 判断顶置
return PageUtils.page(req.getPage(),topicTitileQos); return PageUtils.page(req.getPage(), topicTitileQos);
} }
//话题详情页
public TopicDetailQo getDetail(String topicId) { public TopicDetailQo getDetail(String topicId) {
TopicEntity topicEntity = topicService.queryById(topicId); TopicEntity topicEntity = topicService.queryById(topicId);
if (topicEntity == null) { if (topicEntity == null) {
throw new BizException("找不到话题,id:" + topicId); throw new BizException("找不到话题,id:" + topicId);
} }
TopicDetailQo topicDetailQo = new TopicDetailQo(); TopicDetailQo topicDetailQo = new TopicDetailQo();
BeanUtils.copyProperties(topicEntity,topicDetailQo); BeanUtils.copyProperties(topicEntity, topicDetailQo);
List<String> themeIds = themeService.queryThemeIdsByTopic(topicId); List<String> themeIds = themeService.queryThemeIdsByTopic(topicId);
if (CollectionUtils.isEmpty(themeIds)){ if (CollectionUtils.isEmpty(themeIds)) {
topicDetailQo.setViewCount(1000); topicDetailQo.setViewCount(visitSummaryService.queryTopicDetailVisit(topicId));
topicDetailQo.setDisscussCount(0); topicDetailQo.setDisscussCount(0);
return topicDetailQo; return topicDetailQo;
} }
//TODO 浏览量 //浏览量
topicDetailQo.setViewCount(1000); Integer topicPV = visitSummaryService.queryTopicDetailVisit(topicId);
Integer themePV = visitSummaryService.queryThemeVisit(themeIds);
topicDetailQo.setViewCount(topicPV + themePV);
//讨论数=发布主题贴数+回复总数 //讨论数=发布主题贴数+回复总数
Integer commentCount = commentService.getCommentCountByThemeIds(themeIds); Integer commentCount = commentService.getCommentCountByThemeIds(themeIds);
topicDetailQo.setDisscussCount(themeIds.size()+commentCount); topicDetailQo.setDisscussCount(themeIds.size() + commentCount);
return topicDetailQo; return topicDetailQo;
} }
public List<TopicHotQo> getHotTopicTitles(){ public List<TopicHotQo> getHotTopicTitles() {
List<TopicEntity> topicEntities = topicService.queryAll(); List<TopicEntity> topicEntities = topicService.queryAll();
List<TopicHotQo> topicHotQos = ConvertUtil.topicEntityToHotQos(topicEntities); List<TopicHotQo> topicHotQos = ConvertUtil.topicEntityToHotQos(topicEntities);
//TODO 添加类型:热 新 顶 //TODO 添加类型:热 新 顶
...@@ -128,7 +135,6 @@ public class TopicManager { ...@@ -128,7 +135,6 @@ public class TopicManager {
} }
public void modifyViewCount(String topicId, Long modifyMount) { public void modifyViewCount(String topicId, Long modifyMount) {
TopicEntity topicEntity = topicService.queryById(topicId); TopicEntity topicEntity = topicService.queryById(topicId);
if (topicEntity == null) { if (topicEntity == null) {
...@@ -152,7 +158,7 @@ public class TopicManager { ...@@ -152,7 +158,7 @@ public class TopicManager {
List<String> themeIds = themeService.queryThemeIdsByTopic(topicId); List<String> themeIds = themeService.queryThemeIdsByTopic(topicId);
Integer likeCountByThemeIds = collectionService.getCountByTypeAndIds(themeIds, CollectionTypeEnum.LIKE_THEME); Integer likeCountByThemeIds = collectionService.getCountByTypeAndIds(themeIds, CollectionTypeEnum.LIKE_THEME);
Integer bookCountByThemeIds = collectionService.getCountByTypeAndIds(themeIds, CollectionTypeEnum.COLLECT_THEME); Integer bookCountByThemeIds = collectionService.getCountByTypeAndIds(themeIds, CollectionTypeEnum.COLLECT_THEME);
Long commentCountByThemeIds = (long)commentService.getCommentCountByThemeIds(themeIds); Long commentCountByThemeIds = (long) commentService.getCommentCountByThemeIds(themeIds);
Set<String> postUsers = themeService.getPostUserCount(themeIds); Set<String> postUsers = themeService.getPostUserCount(themeIds);
Set<String> commentUsers = commentService.getCommentUserCount(themeIds); Set<String> commentUsers = commentService.getCommentUserCount(themeIds);
HashSet<String> totalUsers = new HashSet<>(postUsers); HashSet<String> totalUsers = new HashSet<>(postUsers);
......
package com.tanpu.community.manager;
import com.tanpu.common.auth.UserHolder;
import com.tanpu.community.api.enums.VisitTypeEnum;
import com.tanpu.community.service.VisitSummaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class VisitSummaryManager {
@Resource
private VisitSummaryService visitSummaryService;
@Autowired
private UserHolder userHolder;
public void addTopicPageView(String topicId) {
String userId = userHolder.getUserId();
visitSummaryService.addPageView(userId, topicId, VisitTypeEnum.TOPIC_PAGE_VIEW);
}
public void addThemePageView(String themeId) {
String userId = userHolder.getUserId();
visitSummaryService.addPageView(userId, themeId, VisitTypeEnum.TOPIC_PAGE_VIEW);
}
}
...@@ -2,6 +2,7 @@ package com.tanpu.community.service; ...@@ -2,6 +2,7 @@ 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.uuid.UuidGenHelper; import com.tanpu.common.uuid.UuidGenHelper;
import com.tanpu.community.api.enums.CommentTypeEnum;
import com.tanpu.community.api.enums.DeleteTagEnum; import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.api.enums.TopicStatusEnum; import com.tanpu.community.api.enums.TopicStatusEnum;
import com.tanpu.community.dao.entity.community.CommentEntity; import com.tanpu.community.dao.entity.community.CommentEntity;
...@@ -63,4 +64,10 @@ public class CommentService { ...@@ -63,4 +64,10 @@ public class CommentService {
} }
public List<CommentEntity> queryThemesByUserId(String userId) {
return commentMapper.selectList(new LambdaQueryWrapper<CommentEntity>()
.eq(CommentEntity::getAuthorId,userId)
.eq(CommentEntity::getCommentType, CommentTypeEnum.THEME.getCode())
.eq(CommentEntity::getDeleteTag,DeleteTagEnum.NOT_DELETED.getCode()));
}
} }
...@@ -5,6 +5,7 @@ import com.tanpu.community.dao.entity.community.FollowRelEntity; ...@@ -5,6 +5,7 @@ import com.tanpu.community.dao.entity.community.FollowRelEntity;
import com.tanpu.community.dao.mapper.community.FollowRelMapper; import com.tanpu.community.dao.mapper.community.FollowRelMapper;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
...@@ -31,6 +32,7 @@ public class FollowRelService { ...@@ -31,6 +32,7 @@ public class FollowRelService {
.stream().map(FollowRelEntity::getFollowerId).collect(Collectors.toList()); .stream().map(FollowRelEntity::getFollowerId).collect(Collectors.toList());
} }
@Transactional
public void addFans(String idolId, String followerId) { public void addFans(String idolId, String followerId) {
FollowRelEntity rel = new FollowRelEntity(); FollowRelEntity rel = new FollowRelEntity();
rel.setFollowUserId(idolId); rel.setFollowUserId(idolId);
......
...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; ...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanpu.community.dao.entity.community.ThemeAttachmentEntity; import com.tanpu.community.dao.entity.community.ThemeAttachmentEntity;
import com.tanpu.community.dao.mapper.community.ThemeAttachmentMapper; import com.tanpu.community.dao.mapper.community.ThemeAttachmentMapper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
...@@ -19,6 +20,7 @@ public class ThemeAttachmentService { ...@@ -19,6 +20,7 @@ public class ThemeAttachmentService {
.eq(ThemeAttachmentEntity::getThemeId,themeId)); .eq(ThemeAttachmentEntity::getThemeId,themeId));
} }
@Transactional
public void insertList(List<ThemeAttachmentEntity> themeAttachments) { public void insertList(List<ThemeAttachmentEntity> themeAttachments) {
for (ThemeAttachmentEntity themeAttachment : themeAttachments) { for (ThemeAttachmentEntity themeAttachment : themeAttachments) {
themeAttachmentMapper.insert(themeAttachment); themeAttachmentMapper.insert(themeAttachment);
......
...@@ -9,6 +9,7 @@ import com.tanpu.community.dao.mapper.community.ThemeMapper; ...@@ -9,6 +9,7 @@ import com.tanpu.community.dao.mapper.community.ThemeMapper;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
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 org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
...@@ -24,14 +25,35 @@ public class ThemeService { ...@@ -24,14 +25,35 @@ public class ThemeService {
@Autowired @Autowired
private UuidGenHelper uuidGenHelper; private UuidGenHelper uuidGenHelper;
@Transactional
public void insertTheme(ThemeEntity themeEntity) { public void insertTheme(ThemeEntity themeEntity) {
themeEntity.setThemeId(uuidGenHelper.getUuidStr()); themeEntity.setThemeId(uuidGenHelper.getUuidStr());
themeMapper.insert(themeEntity); themeMapper.insert(themeEntity);
} }
@Transactional
public void update(ThemeEntity themeEntity,String themeId) {
themeEntity.setThemeId(themeId);
themeMapper.updateById(themeEntity);
}
//根据id返回主题详情 //根据id返回主题详情
public ThemeEntity queryByThemeId(String themeId) { public ThemeEntity queryByThemeId(String themeId) {
return themeMapper.selectOne(new LambdaQueryWrapper<ThemeEntity>().eq(ThemeEntity::getThemeId,themeId)); return themeMapper.selectOne(new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getThemeId,themeId));
}
public List<ThemeEntity> queryThemeIdsByUserId(String userId) {
return themeMapper.selectList(new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getAuthorId,userId)
.eq(ThemeEntity::getDeleteTag,DeleteTagEnum.NOT_DELETED.getCode()));
}
//根据ids返回主题详情
public List<ThemeEntity> queryByThemeIds(List<String> themeIds) {
return themeMapper.selectList(new LambdaQueryWrapper<ThemeEntity>()
.in(ThemeEntity::getThemeId,themeIds)
.eq(ThemeEntity::getDeleteTag,DeleteTagEnum.NOT_DELETED.getCode()));
} }
//分页倒叙lastId之前的主题 //分页倒叙lastId之前的主题
...@@ -81,9 +103,9 @@ public class ThemeService { ...@@ -81,9 +103,9 @@ public class ThemeService {
//关注的主题列表 //关注的主题列表
public List<ThemeEntity> queryByFans(List<String> fansList, 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, fansList) .in(ThemeEntity::getAuthorId, userIds)
.orderByDesc(ThemeEntity::getUpdateTime); .orderByDesc(ThemeEntity::getUpdateTime);
if (StringUtils.isNotEmpty(lastId)) { if (StringUtils.isNotEmpty(lastId)) {
ThemeEntity lastEntity = queryByThemeId(lastId); ThemeEntity lastEntity = queryByThemeId(lastId);
...@@ -117,6 +139,7 @@ public class ThemeService { ...@@ -117,6 +139,7 @@ public class ThemeService {
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED)); .eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED));
} }
@Transactional
public void deleteById(String themeId) { public void deleteById(String themeId) {
ThemeEntity themeEntity = themeMapper.selectById(themeId); ThemeEntity themeEntity = themeMapper.selectById(themeId);
if (themeEntity==null){ if (themeEntity==null){
...@@ -125,4 +148,6 @@ public class ThemeService { ...@@ -125,4 +148,6 @@ public class ThemeService {
themeEntity.setDeleteTag(DeleteTagEnum.DELETED.getCode()); themeEntity.setDeleteTag(DeleteTagEnum.DELETED.getCode());
themeMapper.updateById(themeEntity); themeMapper.updateById(themeEntity);
} }
} }
...@@ -10,6 +10,7 @@ import com.tanpu.community.dao.mapper.community.TopicMapper; ...@@ -10,6 +10,7 @@ import com.tanpu.community.dao.mapper.community.TopicMapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
...@@ -36,7 +37,7 @@ public class TopicService { ...@@ -36,7 +37,7 @@ public class TopicService {
.eq(TopicEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())); .eq(TopicEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()));
} }
@Transactional
public void addTopic(String topicTitle, String userId) { public void addTopic(String topicTitle, String userId) {
TopicEntity entity = TopicEntity.builder() TopicEntity entity = TopicEntity.builder()
.topicId(uuidGenHelper.getUuidStr()) .topicId(uuidGenHelper.getUuidStr())
......
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.community.api.enums.VisitTypeEnum;
import com.tanpu.community.dao.entity.community.VisitSummaryEntity; import com.tanpu.community.dao.entity.community.VisitSummaryEntity;
import com.tanpu.community.dao.mapper.community.VisitSummaryMapper; import com.tanpu.community.dao.mapper.community.VisitSummaryMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List;
@Slf4j @Slf4j
@Service @Service
...@@ -15,11 +18,34 @@ public class VisitSummaryService { ...@@ -15,11 +18,34 @@ public class VisitSummaryService {
@Resource @Resource
private VisitSummaryMapper visitSummaryMapper; private VisitSummaryMapper visitSummaryMapper;
@Transactional
public void addPageView(String userId, String targetId, VisitTypeEnum type) {
visitSummaryMapper.insert(VisitSummaryEntity.builder()
.visitorId(userId)
.refId(targetId)
.refType(type.getCode())
.build());
}
// 查询话题 详细页面 浏览量 // 查询话题 详细页面 浏览量
public Integer queryTopicDetailVisit(String topicId) { public Integer queryTopicDetailVisit(String topicId) {
return visitSummaryMapper.selectCount(new LambdaQueryWrapper<VisitSummaryEntity>() return visitSummaryMapper.selectCount(new LambdaQueryWrapper<VisitSummaryEntity>()
.eq(VisitSummaryEntity::getRefId, topicId)); .eq(VisitSummaryEntity::getRefId, topicId)
.eq(VisitSummaryEntity::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.TOPIC_PAGE_VIEW.getCode()));
}
// 查询主题 浏览量
public Integer queryThemeVisit(List<String> themes) {
return visitSummaryMapper.selectCount(new LambdaQueryWrapper<VisitSummaryEntity>()
.in(VisitSummaryEntity::getRefId, themes)
.eq(VisitSummaryEntity::getRefType,VisitTypeEnum.TOPIC_PAGE_VIEW.getCode()));
} }
// 更新访问时长 // 更新访问时长
......
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