From 5d29373d6e4da0dc20c7ffb4133bbd3708e297bd Mon Sep 17 00:00:00 2001 From: liujiming <liujm@wealthgrow.cn> Date: Thu, 15 Jul 2021 10:44:41 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF=E6=BA=90?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/beans/qo/MyCommentThemeQo.java | 11 +++ .../req/homepage/QueryRecordThemeReq.java | 2 +- .../api/beans/req/theme/CreateThemeReq.java | 4 + .../api/beans/req/theme/ForwardThemeReq.java | 3 + .../community/api/enums/VisitTypeEnum.java | 30 +++++++ .../controller/MetricsController.java | 27 ++++-- .../community/controller/TopicController.java | 1 - .../tanpu/community/manager/ThemeManager.java | 87 +++++++++++-------- .../tanpu/community/manager/TopicManager.java | 32 ++++--- .../manager/VisitSummaryManager.java | 30 +++++++ .../community/service/CommentService.java | 7 ++ .../community/service/FollowRelService.java | 2 + .../service/ThemeAttachmentService.java | 2 + .../tanpu/community/service/ThemeService.java | 31 ++++++- .../tanpu/community/service/TopicService.java | 3 +- .../service/VisitSummaryService.java | 28 +++++- 16 files changed, 239 insertions(+), 61 deletions(-) create mode 100644 community-api/src/main/java/com/tanpu/community/api/beans/qo/MyCommentThemeQo.java create mode 100644 community-api/src/main/java/com/tanpu/community/api/enums/VisitTypeEnum.java create mode 100644 community-service/src/main/java/com/tanpu/community/manager/VisitSummaryManager.java diff --git a/community-api/src/main/java/com/tanpu/community/api/beans/qo/MyCommentThemeQo.java b/community-api/src/main/java/com/tanpu/community/api/beans/qo/MyCommentThemeQo.java new file mode 100644 index 0000000..d2d3d82 --- /dev/null +++ b/community-api/src/main/java/com/tanpu/community/api/beans/qo/MyCommentThemeQo.java @@ -0,0 +1,11 @@ +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; +} diff --git a/community-api/src/main/java/com/tanpu/community/api/beans/req/homepage/QueryRecordThemeReq.java b/community-api/src/main/java/com/tanpu/community/api/beans/req/homepage/QueryRecordThemeReq.java index 1089b20..473b097 100644 --- a/community-api/src/main/java/com/tanpu/community/api/beans/req/homepage/QueryRecordThemeReq.java +++ b/community-api/src/main/java/com/tanpu/community/api/beans/req/homepage/QueryRecordThemeReq.java @@ -13,7 +13,7 @@ public class QueryRecordThemeReq { @ApiModelProperty("用户Id") private String userId; - @ApiModelProperty(value = "æ“作类型 1:å‘布 2ï¼šå›žå¤ 3:点赞 4:收è—") + @ApiModelProperty(value = "æ“作类型 1:å‘布 2:点赞 3:收è—") private Integer recordType; @ApiModelProperty(value = "当剿µè§ˆçš„æœ€åŽä¸€ä¸ªthemeId,å¯ä»¥ä¸ºç©º") diff --git a/community-api/src/main/java/com/tanpu/community/api/beans/req/theme/CreateThemeReq.java b/community-api/src/main/java/com/tanpu/community/api/beans/req/theme/CreateThemeReq.java index 680dd3a..3726167 100644 --- a/community-api/src/main/java/com/tanpu/community/api/beans/req/theme/CreateThemeReq.java +++ b/community-api/src/main/java/com/tanpu/community/api/beans/req/theme/CreateThemeReq.java @@ -29,4 +29,8 @@ public class CreateThemeReq { private String topicId; + @ApiModelProperty(value = "ä¿®æ”¹ï¼Œåˆ™ä¼ å…¥æ£åœ¨ç¼–辑的ThemeId") + private String editThemeId; + + } diff --git a/community-api/src/main/java/com/tanpu/community/api/beans/req/theme/ForwardThemeReq.java b/community-api/src/main/java/com/tanpu/community/api/beans/req/theme/ForwardThemeReq.java index 1de7760..dd1f504 100644 --- a/community-api/src/main/java/com/tanpu/community/api/beans/req/theme/ForwardThemeReq.java +++ b/community-api/src/main/java/com/tanpu/community/api/beans/req/theme/ForwardThemeReq.java @@ -22,4 +22,7 @@ public class ForwardThemeReq { @ApiModelProperty(value = "è¯é¢˜Id") private String topicId; + + @ApiModelProperty(value = "ä¿®æ”¹ï¼Œåˆ™ä¼ å…¥æ£åœ¨ç¼–辑的ThemeId") + private String editThemeId; } diff --git a/community-api/src/main/java/com/tanpu/community/api/enums/VisitTypeEnum.java b/community-api/src/main/java/com/tanpu/community/api/enums/VisitTypeEnum.java new file mode 100644 index 0000000..3721040 --- /dev/null +++ b/community-api/src/main/java/com/tanpu/community/api/enums/VisitTypeEnum.java @@ -0,0 +1,30 @@ +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; + } +} diff --git a/community-service/src/main/java/com/tanpu/community/controller/MetricsController.java b/community-service/src/main/java/com/tanpu/community/controller/MetricsController.java index 8d96e96..2ef2c6f 100644 --- a/community-service/src/main/java/com/tanpu/community/controller/MetricsController.java +++ b/community-service/src/main/java/com/tanpu/community/controller/MetricsController.java @@ -1,25 +1,38 @@ package com.tanpu.community.controller; import com.tanpu.common.api.CommonResp; -import com.tanpu.community.api.constants.RedisKeyConstant; -import com.tanpu.community.service.RedisService; +import com.tanpu.common.auth.AuthLogin; +import com.tanpu.community.manager.VisitSummaryManager; import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; 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.RequestParam; +import org.springframework.web.bind.annotation.RestController; +@RestController +@Slf4j @RequestMapping(value = "/metric") public class MetricsController { @Autowired - private RedisService redisService; + private VisitSummaryManager visitSummaryManager; - @ApiOperation("æµè§ˆé‡åŸ‹ç‚¹") - @RequestMapping("/pv") - public CommonResp pageView(@RequestParam String themeId){ - redisService.incr(RedisKeyConstant.THEME_VIEW_COUNT_ +themeId, 1L); + @AuthLogin + @ApiOperation("æµè§ˆè¯é¢˜") + @GetMapping("/view/topic") + public CommonResp pageViewTopic(@RequestParam String topicId){ + visitSummaryManager.addTopicPageView(topicId); return CommonResp.success(); } + @AuthLogin + @ApiOperation("æµè§ˆä¸»é¢˜") + @GetMapping("/view/theme") + public CommonResp pageViewTheme(@RequestParam String themeId){ + visitSummaryManager.addThemePageView(themeId); + return CommonResp.success(); + } diff --git a/community-service/src/main/java/com/tanpu/community/controller/TopicController.java b/community-service/src/main/java/com/tanpu/community/controller/TopicController.java index d5d979f..07de478 100644 --- a/community-service/src/main/java/com/tanpu/community/controller/TopicController.java +++ b/community-service/src/main/java/com/tanpu/community/controller/TopicController.java @@ -39,7 +39,6 @@ public class TopicController { @ApiOperation("è¯é¢˜è¯¦æƒ…页顶部") @ResponseBody public CommonResp<TopicDetailQo> gethotThemes(@RequestParam String topicId){ - //todo TopicDetailQo detail = topicManager.getDetail(topicId); return CommonResp.success(detail); } diff --git a/community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java b/community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java index 3949434..1c7bf3d 100644 --- a/community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java +++ b/community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java @@ -10,10 +10,7 @@ import com.tanpu.community.api.enums.BlockTypeEnum; import com.tanpu.community.api.enums.CollectionTypeEnum; import com.tanpu.community.api.enums.ThemeListTypeEnum; import com.tanpu.community.api.enums.ThemeTypeEnum; -import com.tanpu.community.dao.entity.community.BlackListEntity; -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.dao.entity.community.*; import com.tanpu.community.service.*; import com.tanpu.community.service.other.BlackListService; import com.tanpu.community.util.ConvertUtil; @@ -23,10 +20,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; +import java.util.stream.Collectors; @Service public class ThemeManager { @@ -70,7 +65,14 @@ public class ThemeManager { BeanUtils.copyProperties(req, themeEntity); themeEntity.setAuthorId(userId); 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()); themeAttachmentService.insertList(themeAttachments); @@ -86,7 +88,7 @@ public class ThemeManager { } else if (ThemeListTypeEnum.FOLLOW.getCode().equals(req.getType())) { //æ ¹æ®å…³æ³¨åˆ—表查询 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())) { //TODO æ ¹æ®è¯é¢˜æŸ¥è¯¢çƒé—¨ @@ -103,10 +105,30 @@ public class ThemeManager { // 返回用户å‘布ã€å›žå¤ã€æ”¶è—的主题列表 public List<ThemeQo> queryThemesByUser(QueryRecordThemeReq req, String userId) { -// TODO -// List<ThemeEntity> themeEntities = themeService.queryByUser(req.getUserId(), req.getPageSize(),req.getLastId()); - List<ThemeEntity> themeEntities = themeService.selectAll(req.getLastId(), req.getPageSize()); - return convertEntityToQo(themeEntities, userId); + + List<ThemeEntity> themeEntities = Collections.emptyList(); + switch (req.getRecordType()) { + 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 { // 点赞/å–æ¶ˆç‚¹èµž public void like(LikeThemeReq req, String userId) { //todo 枚举值 - if (1==req.getType()){ + if (1 == req.getType()) { 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); } @@ -136,9 +158,9 @@ public class ThemeManager { //æ”¶è—/å–æ¶ˆæ”¶è— public void collect(CollectThemeReq req, String userId) { //todo 枚举值 - if (1==req.getType()){ + if (1 == req.getType()) { 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); } } @@ -154,13 +176,16 @@ public class ThemeManager { .themeType(ThemeTypeEnum.FORWARD.getCode()) .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) { //TODO @@ -200,8 +225,8 @@ public class ThemeManager { List<ThemeQo> themeQos = ConvertUtil.themeEntitiesToDTOs(themeEntities); //æ‰¹é‡æŸ¥è¯¢é™„ä»¶detail productService.transferAttachments(themeQos); + //å…¶ä»–ä¿¡æ¯ for (ThemeQo themeQO : themeQos) { - buildThemeQoExtraInfo(userId, themeQO); } return themeQos; @@ -210,22 +235,19 @@ public class ThemeManager { //组装主题列表 private void buildThemeQoExtraInfo(String userId, ThemeQo themeQo) { - //附件列表 String themeId = themeQo.getThemeId(); - //迄今时间 - //是å¦å…³æ³¨ä½œè€… String authorId = themeQo.getAuthorId(); Set<String> fansSet = new HashSet<>(followRelService.queryFansByFollowerId(userId)); themeQo.setFollow(fansSet.contains(authorId)); //是å¦ç‚¹èµž CollectionEntity likeEntity = collectionService.getNotDeleteTargetCollection(themeId, userId, CollectionTypeEnum.LIKE_THEME); - themeQo.setHasLiked(likeEntity!=null); + themeQo.setHasLiked(likeEntity != null); //是å¦è½¬å‘ Integer forwardCountByUser = themeService.getForwardCountByUser(themeId, userId); - themeQo.setHasForward(forwardCountByUser>0); + themeQo.setHasForward(forwardCountByUser > 0); //转å‘原文 buildFormerTheme(themeQo); //çƒç‚¹æ•°æ®:点赞,收è—ï¼Œè½¬å‘ @@ -251,10 +273,10 @@ public class ThemeManager { private void buildFormerTheme(ThemeQo themeQo) { String formerThemeId = themeQo.getFormerThemeId(); - if (StringUtils.isNotEmpty(formerThemeId)){ + if (StringUtils.isNotEmpty(formerThemeId)) { ThemeQo formerTheme = ConvertUtil.themeEntityToQo2(themeService.queryByThemeId(formerThemeId)); - if (formerTheme==null){ - throw new BizException("转å‘主题Id错误,id:"+formerThemeId); + if (formerTheme == null) { + throw new BizException("转å‘主题Id错误,id:" + formerThemeId); } productService.transferAttachement(formerTheme); FormerThemeQo f = FormerThemeQo.builder().formerThemeId(formerThemeId) @@ -267,9 +289,6 @@ public class ThemeManager { } - - - public void delete(String themeId) { themeService.deleteById(themeId); diff --git a/community-service/src/main/java/com/tanpu/community/manager/TopicManager.java b/community-service/src/main/java/com/tanpu/community/manager/TopicManager.java index 7c88b4c..a520315 100644 --- a/community-service/src/main/java/com/tanpu/community/manager/TopicManager.java +++ b/community-service/src/main/java/com/tanpu/community/manager/TopicManager.java @@ -41,6 +41,9 @@ public class TopicManager { @Autowired private CommentService commentService; + @Autowired + private VisitSummaryService visitSummaryService; + //新增è¯é¢˜ public void insertTopic(String topicTitle, String userId) { if (topicService.queryByTitile(topicTitle) == null) { @@ -62,38 +65,42 @@ public class TopicManager { List<TopicTitileQo> topicTitileQos = ConvertUtil.topicEntitiesToBriefDTOs(allTopic); for (TopicTitileQo topicQo : topicTitileQos) { - //TODO 讨论数=å‘布主题贴数+å›žå¤æ€»æ•° -// Integer commentCountByThemeIds = commentService.getCommentCountByThemeIds(themeIds); - topicQo.setDiscussionCount(0); + //讨论数=å‘布主题贴数+å›žå¤æ€»æ•° + List<String> themeIds = themeService.queryThemeIdsByTopic(topicQo.getTopicId()); + Integer commentCount = commentService.getCommentCountByThemeIds(themeIds); + topicQo.setDiscussionCount(themeIds.size() + commentCount); } //TODO 判æ–é¡¶ç½® - return PageUtils.page(req.getPage(),topicTitileQos); + return PageUtils.page(req.getPage(), topicTitileQos); } + //è¯é¢˜è¯¦æƒ…页 public TopicDetailQo getDetail(String topicId) { TopicEntity topicEntity = topicService.queryById(topicId); if (topicEntity == null) { throw new BizException("找ä¸åˆ°è¯é¢˜ï¼Œid:" + topicId); } TopicDetailQo topicDetailQo = new TopicDetailQo(); - BeanUtils.copyProperties(topicEntity,topicDetailQo); + BeanUtils.copyProperties(topicEntity, topicDetailQo); List<String> themeIds = themeService.queryThemeIdsByTopic(topicId); - if (CollectionUtils.isEmpty(themeIds)){ - topicDetailQo.setViewCount(1000); + if (CollectionUtils.isEmpty(themeIds)) { + topicDetailQo.setViewCount(visitSummaryService.queryTopicDetailVisit(topicId)); topicDetailQo.setDisscussCount(0); 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); - topicDetailQo.setDisscussCount(themeIds.size()+commentCount); + topicDetailQo.setDisscussCount(themeIds.size() + commentCount); return topicDetailQo; } - public List<TopicHotQo> getHotTopicTitles(){ + public List<TopicHotQo> getHotTopicTitles() { List<TopicEntity> topicEntities = topicService.queryAll(); List<TopicHotQo> topicHotQos = ConvertUtil.topicEntityToHotQos(topicEntities); //TODO æ·»åŠ ç±»åž‹:çƒ æ–° é¡¶ @@ -128,7 +135,6 @@ public class TopicManager { } - public void modifyViewCount(String topicId, Long modifyMount) { TopicEntity topicEntity = topicService.queryById(topicId); if (topicEntity == null) { @@ -152,7 +158,7 @@ public class TopicManager { List<String> themeIds = themeService.queryThemeIdsByTopic(topicId); Integer likeCountByThemeIds = collectionService.getCountByTypeAndIds(themeIds, CollectionTypeEnum.LIKE_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> commentUsers = commentService.getCommentUserCount(themeIds); HashSet<String> totalUsers = new HashSet<>(postUsers); diff --git a/community-service/src/main/java/com/tanpu/community/manager/VisitSummaryManager.java b/community-service/src/main/java/com/tanpu/community/manager/VisitSummaryManager.java new file mode 100644 index 0000000..4c2b199 --- /dev/null +++ b/community-service/src/main/java/com/tanpu/community/manager/VisitSummaryManager.java @@ -0,0 +1,30 @@ +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); + } + +} diff --git a/community-service/src/main/java/com/tanpu/community/service/CommentService.java b/community-service/src/main/java/com/tanpu/community/service/CommentService.java index 94aec77..4c5ece9 100644 --- a/community-service/src/main/java/com/tanpu/community/service/CommentService.java +++ b/community-service/src/main/java/com/tanpu/community/service/CommentService.java @@ -2,6 +2,7 @@ package com.tanpu.community.service; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.TopicStatusEnum; import com.tanpu.community.dao.entity.community.CommentEntity; @@ -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())); + } } diff --git a/community-service/src/main/java/com/tanpu/community/service/FollowRelService.java b/community-service/src/main/java/com/tanpu/community/service/FollowRelService.java index 1ec4080..78e437b 100644 --- a/community-service/src/main/java/com/tanpu/community/service/FollowRelService.java +++ b/community-service/src/main/java/com/tanpu/community/service/FollowRelService.java @@ -5,6 +5,7 @@ import com.tanpu.community.dao.entity.community.FollowRelEntity; import com.tanpu.community.dao.mapper.community.FollowRelMapper; import org.springframework.cache.annotation.EnableCaching; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.List; @@ -31,6 +32,7 @@ public class FollowRelService { .stream().map(FollowRelEntity::getFollowerId).collect(Collectors.toList()); } + @Transactional public void addFans(String idolId, String followerId) { FollowRelEntity rel = new FollowRelEntity(); rel.setFollowUserId(idolId); diff --git a/community-service/src/main/java/com/tanpu/community/service/ThemeAttachmentService.java b/community-service/src/main/java/com/tanpu/community/service/ThemeAttachmentService.java index d43853c..71079df 100644 --- a/community-service/src/main/java/com/tanpu/community/service/ThemeAttachmentService.java +++ b/community-service/src/main/java/com/tanpu/community/service/ThemeAttachmentService.java @@ -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.mapper.community.ThemeAttachmentMapper; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.List; @@ -19,6 +20,7 @@ public class ThemeAttachmentService { .eq(ThemeAttachmentEntity::getThemeId,themeId)); } + @Transactional public void insertList(List<ThemeAttachmentEntity> themeAttachments) { for (ThemeAttachmentEntity themeAttachment : themeAttachments) { themeAttachmentMapper.insert(themeAttachment); diff --git a/community-service/src/main/java/com/tanpu/community/service/ThemeService.java b/community-service/src/main/java/com/tanpu/community/service/ThemeService.java index e97c0b1..c5bdc3f 100644 --- a/community-service/src/main/java/com/tanpu/community/service/ThemeService.java +++ b/community-service/src/main/java/com/tanpu/community/service/ThemeService.java @@ -9,6 +9,7 @@ import com.tanpu.community.dao.mapper.community.ThemeMapper; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.List; @@ -24,14 +25,35 @@ public class ThemeService { @Autowired private UuidGenHelper uuidGenHelper; + @Transactional public void insertTheme(ThemeEntity themeEntity) { themeEntity.setThemeId(uuidGenHelper.getUuidStr()); themeMapper.insert(themeEntity); } + @Transactional + public void update(ThemeEntity themeEntity,String themeId) { + themeEntity.setThemeId(themeId); + themeMapper.updateById(themeEntity); + } + //æ ¹æ®id返回主题详情 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之å‰çš„主题 @@ -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>() - .in(ThemeEntity::getAuthorId, fansList) + .in(ThemeEntity::getAuthorId, userIds) .orderByDesc(ThemeEntity::getUpdateTime); if (StringUtils.isNotEmpty(lastId)) { ThemeEntity lastEntity = queryByThemeId(lastId); @@ -117,6 +139,7 @@ public class ThemeService { .eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED)); } + @Transactional public void deleteById(String themeId) { ThemeEntity themeEntity = themeMapper.selectById(themeId); if (themeEntity==null){ @@ -125,4 +148,6 @@ public class ThemeService { themeEntity.setDeleteTag(DeleteTagEnum.DELETED.getCode()); themeMapper.updateById(themeEntity); } + + } diff --git a/community-service/src/main/java/com/tanpu/community/service/TopicService.java b/community-service/src/main/java/com/tanpu/community/service/TopicService.java index 58f66c8..1ecbadd 100644 --- a/community-service/src/main/java/com/tanpu/community/service/TopicService.java +++ b/community-service/src/main/java/com/tanpu/community/service/TopicService.java @@ -10,6 +10,7 @@ import com.tanpu.community.dao.mapper.community.TopicMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.EnableCaching; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.List; @@ -36,7 +37,7 @@ public class TopicService { .eq(TopicEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())); } - + @Transactional public void addTopic(String topicTitle, String userId) { TopicEntity entity = TopicEntity.builder() .topicId(uuidGenHelper.getUuidStr()) diff --git a/community-service/src/main/java/com/tanpu/community/service/VisitSummaryService.java b/community-service/src/main/java/com/tanpu/community/service/VisitSummaryService.java index 334ef5b..b00f2f9 100644 --- a/community-service/src/main/java/com/tanpu/community/service/VisitSummaryService.java +++ b/community-service/src/main/java/com/tanpu/community/service/VisitSummaryService.java @@ -1,12 +1,15 @@ package com.tanpu.community.service; 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.mapper.community.VisitSummaryMapper; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.util.List; @Slf4j @Service @@ -15,11 +18,34 @@ public class VisitSummaryService { @Resource 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) { 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())); } // 更新访问时长 -- 2.18.1