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

Merge branch 'v2.3.1' into 'dev'

V2.3.1

See merge request !44
parents cb2cbf45 22030d18
......@@ -38,9 +38,12 @@ public class CommentQo {
@ApiModelProperty(value = "当前用户是否点赞")
private boolean hasLiked;
@ApiModelProperty(value = "2级评论")
@ApiModelProperty(value = "2级评论,目前未使用")
private List<CommentLv2Qo> commentLv2Qos;
@ApiModelProperty(value = "是否讨论区管理员")
private boolean isManager;
// 认证标签相关
@ApiModelProperty("认证标签用-用户等级体系 0 游客 1注册用户 10投资人 20 探普理顾 30 探普专家理顾 40 交易理财师 50 首席投顾")
private Integer levelGrade;
......
......@@ -11,8 +11,8 @@ import lombok.NoArgsConstructor;
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("话题详情对象")
public class TopicDetailQo {
@ApiModel("关注话题列表")
public class TopicFollowQo {
@ApiModelProperty(value = "话题ID")
private String topicId;
......@@ -26,4 +26,28 @@ public class TopicDetailQo {
@ApiModelProperty(value = "讨论量")
private Integer disscussCount;
@ApiModelProperty(value = "阅读量-格式化")
private String formatViewCount;
@ApiModelProperty(value = "讨论量-格式化")
private String formatDisscussCount;
@ApiModelProperty(value = "话题介绍")
private String topicDesc;
@ApiModelProperty(value = "封面")
private String coverImg;
@ApiModelProperty(value = "是否专属 0否,1是")
private Integer specialPermission;
@ApiModelProperty(value = "更新帖子数量")
private Integer updateCount;
@ApiModelProperty(value = "最近一条讨论")
public String lastTheme;
@ApiModelProperty(value = "最近一条讨论发表时间-格式化")
public String lastThemeTime;
}
......@@ -39,6 +39,15 @@ public class TopicRankQo {
@ApiModelProperty(value = "话题下的帖子权重")
private Double themeWeight;
@ApiModelProperty(value = "话题介绍")
private String topicDesc;
@ApiModelProperty(value = "封面")
private String coverImg;
@ApiModelProperty(value = "是否专属 0否,1是")
private Integer specialPermission;
private Integer minutesTillNow;
private Double score;
......
package com.tanpu.community.api.beans.req.topic;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class FollowTopicReq {
@ApiModelProperty(value = "关注对象Id")
private String topicId;
@ApiModelProperty(value = "关注类型,1:关注 2:取消关注")
private Integer type;
}
......@@ -8,7 +8,7 @@ import lombok.Data;
@Data
public class TopicSearchReq {
@ApiModelProperty(value = "搜索关键字,可以为空")
private String searchKeyword="";
private String searchKeyword = "";
@ApiModelProperty(value = "分页")
private Pageable page;
......
package com.tanpu.community.api.enums;
public enum TopicSearchTypeEnum {
RECOMMEND(1,"推荐列表"),
FOLLOW(2,"关注列表");
private Integer code;
private String type;
TopicSearchTypeEnum(Integer code, String type) {
this.code = code;
this.type = 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;
}
}
package com.tanpu.community.api.enums;
public enum TopicSpecialPermissionEnum {
FALSE(0,"没有特殊权限"),
TRUE(1,"有特殊权限");
private Integer code;
private String type;
TopicSpecialPermissionEnum(Integer code, String type) {
this.code = code;
this.type = 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;
}
}
......@@ -3,52 +3,73 @@ package com.tanpu.community.controller;
import com.tanpu.common.api.CommonResp;
import com.tanpu.common.auth.AuthLogin;
import com.tanpu.common.auth.UserHolder;
import com.tanpu.community.api.beans.qo.TopicFollowQo;
import com.tanpu.community.api.beans.qo.TopicRankQo;
import com.tanpu.community.api.beans.req.page.Page;
import com.tanpu.community.api.beans.req.topic.FollowTopicReq;
import com.tanpu.community.api.beans.req.topic.TopicSearchReq;
import com.tanpu.community.manager.TopicManager;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
@RestController
@Slf4j
@RequestMapping(value = "/api/topic")
@ResponseBody
public class TopicController {
@Autowired
@Resource
private TopicManager topicManager;
@Autowired
@Resource
private UserHolder userHolder;
@AuthLogin
@GetMapping(value = "/followList")
@ApiOperation("关注话题列表")
public CommonResp<List<TopicFollowQo>> getFollowList() {
return CommonResp.success(topicManager.getFollowTopicList());
}
@PostMapping(value = "/list")
@ApiOperation("APP全部话题页面,可搜索")
@ResponseBody
public CommonResp<Page<TopicRankQo>> getTopicList(@RequestBody TopicSearchReq req){
@ApiOperation("热门话题,含搜索")
public CommonResp<Page<TopicRankQo>> getTopicList(@RequestBody TopicSearchReq req) {
return CommonResp.success(topicManager.getAllTopicBriefInfo(req));
}
@GetMapping(value = "/detailPage")
@ApiOperation("话题详情页顶部")
@ResponseBody
public CommonResp<TopicRankQo> getDetail(@RequestParam String topicId){
public CommonResp<TopicRankQo> getDetail(@RequestParam String topicId) {
return topicManager.getDetail(topicId);
}
@GetMapping(value = "/titleList")
@ApiOperation("首页顶部话题标题列")
@ResponseBody
public CommonResp<List<TopicRankQo>> getTop4Topic(){
public CommonResp<List<TopicRankQo>> getTop4Topic() {
return CommonResp.success(topicManager.getTop4TopicTitles());
}
@AuthLogin
@PostMapping(value = "/follow")
@ApiOperation("首页顶部话题标题列")
public CommonResp<Void> follow(@RequestBody FollowTopicReq req) {
topicManager.follow(req, userHolder.getUserId());
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://rm-uf6lqwk9969zao53uro.mysql.rds.aliyuncs.com:3306/tamp_community";
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[]{"theme_check_duplicate"};
String[] tables = new String[]{"topic_follow_rel"};
String basePackage = "com.tanpu.community";
String mapperPackage = "dao.mapper.community";
String entityPackage = "dao.entity.community";
......
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-29
* @since 2022-02-17
*/
@TableName("topic")
@ApiModel(value="TopicEntity对象", description="话题")
......@@ -38,6 +39,18 @@ public class TopicEntity implements Serializable {
@ApiModelProperty(value = "话题名称")
private String topicTitle;
@ApiModelProperty(value = "话题介绍")
private String topicDesc;
@ApiModelProperty(value = "封面")
private String coverImg;
@ApiModelProperty(value = "是否专属 0否,1是")
private Integer specialPermission;
@ApiModelProperty(value = "是否同步动态至管理员企业微信 0:否 1:是")
private Integer syncCorpWechat;
@ApiModelProperty(value = "是否置顶")
private Integer isTop;
......@@ -78,6 +91,38 @@ public class TopicEntity implements Serializable {
this.topicTitle = topicTitle;
}
public String getTopicDesc() {
return topicDesc;
}
public void setTopicDesc(String topicDesc) {
this.topicDesc = topicDesc;
}
public String getCoverImg() {
return coverImg;
}
public void setCoverImg(String coverImg) {
this.coverImg = coverImg;
}
public Integer getSpecialPermission() {
return specialPermission;
}
public void setSpecialPermission(Integer specialPermission) {
this.specialPermission = specialPermission;
}
public Integer getSyncCorpWechat() {
return syncCorpWechat;
}
public void setSyncCorpWechat(Integer syncCorpWechat) {
this.syncCorpWechat = syncCorpWechat;
}
public Integer getIsTop() {
return isTop;
}
......@@ -132,6 +177,10 @@ public class TopicEntity implements Serializable {
"id=" + id +
", topicId=" + topicId +
", topicTitle=" + topicTitle +
", topicDesc=" + topicDesc +
", coverImg=" + coverImg +
", specialPermission=" + specialPermission +
", syncCorpWechat=" + syncCorpWechat +
", isTop=" + isTop +
", isConceal=" + isConceal +
", viewCntAdjust=" + viewCntAdjust +
......
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 io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* <p>
* 讨论区(主题)关注关系表
* </p>
*
* @author xudong
* @since 2022-02-17
*/
@TableName("topic_follow_rel")
@ApiModel(value="TopicFollowRelEntity对象", description="讨论区(主题)关注关系表")
@Builder
public class TopicFollowRelEntity implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id")
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@ApiModelProperty(value = "主题Id")
private String topicId;
@ApiModelProperty(value = "用户id")
private String userId;
@ApiModelProperty(value = "关注时间")
private LocalDateTime followTime;
@ApiModelProperty(value = "取消关注时间")
private LocalDateTime unfollowTime;
private LocalDateTime createTime;
private LocalDateTime updateTime;
private Integer deleteTag;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTopicId() {
return topicId;
}
public void setTopicId(String topicId) {
this.topicId = topicId;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public LocalDateTime getFollowTime() {
return followTime;
}
public void setFollowTime(LocalDateTime followTime) {
this.followTime = followTime;
}
public LocalDateTime getUnfollowTime() {
return unfollowTime;
}
public void setUnfollowTime(LocalDateTime unfollowTime) {
this.unfollowTime = unfollowTime;
}
public LocalDateTime getCreateTime() {
return createTime;
}
public void setCreateTime(LocalDateTime createTime) {
this.createTime = createTime;
}
public LocalDateTime getUpdateTime() {
return updateTime;
}
public void setUpdateTime(LocalDateTime updateTime) {
this.updateTime = updateTime;
}
public Integer getDeleteTag() {
return deleteTag;
}
public void setDeleteTag(Integer deleteTag) {
this.deleteTag = deleteTag;
}
@Override
public String toString() {
return "TopicFollowRelEntity{" +
"id=" + id +
", topicId=" + topicId +
", userId=" + userId +
", followTime=" + followTime +
", unfollowTime=" + unfollowTime +
", createTime=" + createTime +
", updateTime=" + updateTime +
", deleteTag=" + deleteTag +
"}";
}
}
package com.tanpu.community.dao.mapper.community;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tanpu.community.dao.entity.community.TimesCountEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.time.LocalDateTime;
import java.util.List;
/**
......@@ -22,4 +22,12 @@ public interface ThemeMapper extends BaseMapper<ThemeEntity> {
@Select("select former_theme_id as id, count(1) as times from theme ${ew.customSqlSegment}")
List<TimesCountEntity> selectCountByThemeIds(@Param(Constants.WRAPPER) LambdaQueryWrapper wrapper);
ThemeEntity queryOneByTopicIdOrderByUpdateTimeDesc(@Param("topicId")String topicId);
Integer countByTopicIdAndCreateTimeAfter(@Param("topicId")String topicId,@Param("minCreateTime")LocalDateTime minCreateTime);
}
package com.tanpu.community.dao.mapper.community;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tanpu.community.dao.entity.community.TopicFollowRelEntity;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* <p>
* 讨论区(主题)关注关系表 Mapper 接口
* </p>
*
* @author xudong
* @since 2022-02-17
*/
public interface TopicFollowRelMapper extends BaseMapper<TopicFollowRelEntity> {
List<String> selectTopicIdByUserId(@Param("userId")String userId);
TopicFollowRelEntity queryOneByTopicIdAndUserId(@Param("topicId")String topicId,@Param("userId")String userId);
}
package com.tanpu.community.dao.mapper.community;
import com.tanpu.community.dao.entity.community.TopicEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tanpu.community.dao.entity.community.TopicEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.Collection;
import java.util.List;
/**
......@@ -13,9 +13,15 @@ import java.util.List;
* </p>
*
* @author xudong
* @since 2021-07-22
* @since 2022-02-17
*/
public interface TopicMapper extends BaseMapper<TopicEntity> {
@Select("select * from topic where id>#{startId} and delete_tag=0 and is_conceal=0 order by id asc limit #{size}")
List<TopicEntity> selectGtIdPageable(@Param("startId") Long startId, @Param("size") Integer size);
List<TopicEntity> selectAllByTopicIdIn(@Param("topicIdCollection")Collection<String> topicIdCollection);
}
......@@ -32,4 +32,10 @@ public interface VisitLogMapper extends BaseMapper<VisitLogEntity> {
@Select("select ref_id from visit_log where visitor_id=#{visitorId} and date(create_time) between #{startDate} and #{endDate}")
List<String> selectRefIdByVisitorIdAndCreateBetween(@Param("visitorId") String visitorId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
VisitLogEntity queryLastByVisitorIdAndRefId(@Param("visitorId")String visitorId, @Param("refId")String refId);
}
......@@ -132,6 +132,7 @@ public class CommentManager {
commentQo.setHasLiked(likeCommentList.contains(commentId));
Integer countByTypeAndId = collectionService.getCountByTypeAndId(commentId, CollectionTypeEnum.LIKE_COMMENT);
commentQo.setLikeCount(countByTypeAndId);
commentQo.setManager(true);
}
//排序:点赞降序+时间降序
......
package com.tanpu.community.manager;
import com.tanpu.common.api.CommonResp;
import com.tanpu.common.auth.UserHolder;
import com.tanpu.common.constant.ErrorCodeConstant;
import com.tanpu.community.api.beans.qo.TopicFollowQo;
import com.tanpu.community.api.beans.qo.TopicRankQo;
import com.tanpu.community.api.beans.req.page.Page;
import com.tanpu.community.api.beans.req.topic.FollowTopicReq;
import com.tanpu.community.api.beans.req.topic.TopicSearchReq;
import com.tanpu.community.api.enums.OperationTypeEnum;
import com.tanpu.community.api.enums.TopicSpecialPermissionEnum;
import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.dao.mapper.community.TopicFollowRelMapper;
import com.tanpu.community.service.RankService;
import com.tanpu.community.service.ThemeService;
import com.tanpu.community.service.TopicService;
import com.tanpu.community.util.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class TopicManager {
@Autowired
@Resource
private TopicService topicService;
@Autowired
@Resource
private RankService rankService;
@Resource
private UserHolder userHolder;
@Resource
TopicFollowRelMapper topicFollowRelMapper;
@Resource
private ThemeService themeService;
// 首页-话题标签
public List<TopicRankQo> getTop4TopicTitles() {
......@@ -33,20 +50,88 @@ public class TopicManager {
// 话题搜索列表
public Page<TopicRankQo> getAllTopicBriefInfo(TopicSearchReq req) {
// 全量排序,内存分页
List<TopicRankQo> topicList = rankService.getRankTopicList(req.getSearchKeyword());
return PageUtils.page(req.getPage(), topicList);
}
// 话题详情页
/**
* 关注话题(讨论区)列表
*/
public List<TopicFollowQo> getFollowTopicList() {
String userId = userHolder.getUserId();
// 查库
List<TopicFollowQo> topicFollowQos = topicService.queryFollowTopic(userId);
// 从缓存中获取浏览量
Map<String, TopicRankQo> topicMap = rankService.getRankTopicList(null).stream().collect(Collectors.toMap(TopicRankQo::getTopicId, o -> o, (a, b) -> a));
topicFollowQos.stream().forEach(o->{
TopicRankQo topicRankQo = topicMap.get(o.getTopicId());
BeanUtils.copyProperties(topicRankQo,o);
});
// 最新讨论
themeService.queryCommentForTopic(topicFollowQos, userId);
// 排序
topicFollowQos.stream().sorted(Comparator.comparing(TopicFollowQo::getSpecialPermission, Comparator.reverseOrder()).
thenComparing(TopicFollowQo::getLastThemeTime, Comparator.nullsFirst(String::compareTo).reversed()))
.collect(Collectors.toList());
return topicFollowQos;
}
/**
* 话题详情页
* @param topicId
* @return
*/
public CommonResp<TopicRankQo> getDetail(String topicId) {
TopicEntity topicEntity = topicService.queryById(topicId);
if (topicEntity==null){
TopicEntity topicEntity = topicService.queryOnlineTopicById(topicId);
if (topicEntity == null) {
return CommonResp.error(ErrorCodeConstant.TOPIC_NOT_FOUND.getCode(), "抱歉!该话题已下线。");
}
//
if (TopicSpecialPermissionEnum.TRUE.getCode().equals(topicEntity.getSpecialPermission()) && !checkPermission(topicId, userHolder.getUserId())) {
return CommonResp.error(ErrorCodeConstant.TOPIC_PERMISSION_ABORT.getCode(), getPermissionToast(topicId));
}
return CommonResp.success(rankService.getTopicDetail(topicId));
}
private String getPermissionToast(String topicId) {
String permission = "专业版会员";
// return "暂无权限参与此话题~您可联系官方客服 021- 了解详情";
return "该话题仅限" + permission + "可参与哦~";
}
/**
* 判断用户是否拥有权限(1对1)
*
* @param topicId
* @param userId
*/
private boolean checkPermission(String topicId, String userId) {
return true;
}
public void follow(FollowTopicReq req, String userId) {
if (OperationTypeEnum.CONFIRM.getCode().equals(req.getType())) {
topicService.addFollowTopic(req.getTopicId(), userId);
} else if (OperationTypeEnum.CANCEL.getCode().equals(req.getType())) {
topicService.deleteFollowTopic(req.getTopicId(), userId);
}
}
}
......@@ -8,17 +8,21 @@ import com.tanpu.common.exception.BizException;
import com.tanpu.common.redis.RedisHelper;
import com.tanpu.common.util.JsonUtil;
import com.tanpu.common.uuid.UuidGenHelper;
import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.api.beans.qo.TopicFollowQo;
import com.tanpu.community.api.beans.req.comment.CreateCommentReq;
import com.tanpu.community.api.beans.req.theme.ThemeContentReq;
import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.api.enums.ThemeTypeEnum;
import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.dao.entity.community.TimesCountEntity;
import com.tanpu.community.dao.entity.community.VisitLogEntity;
import com.tanpu.community.dao.mapper.community.ThemeMapper;
import com.tanpu.community.dao.mapper.community.VisitLogMapper;
import com.tanpu.community.util.ConvertUtil;
import com.tanpu.community.util.TimeUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -38,15 +42,17 @@ public class ThemeService {
@Resource
private ThemeMapper themeMapper;
@Autowired
@Resource
private UuidGenHelper uuidGenHelper;
@Autowired
@Resource
private RedisHelper redisHelper;
@Resource
private VisitLogMapper visitLogMapper;
@Transactional
public void insertTheme(ThemeEntity themeEntity) {
if (StringUtils.isBlank(themeEntity.getThemeId())){
if (StringUtils.isBlank(themeEntity.getThemeId())) {
themeEntity.setThemeId(uuidGenHelper.getUuidStr());
}
......@@ -147,8 +153,6 @@ public class ThemeService {
}
/**
* 根据话题查询最新主题(可分页)
*
......@@ -181,13 +185,14 @@ public class ThemeService {
/**
* 根据作者查询主题分页列表
*
* @param userIds
* @param pageStart
* @param pageSize
* @return
*/
public List<ThemeEntity> queryByUserIdsCreateDesc(List<String> userIds, Integer pageStart, Integer pageSize) {
if (CollectionUtils.isEmpty(userIds)){
if (CollectionUtils.isEmpty(userIds)) {
return Collections.emptyList();
}
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
......@@ -209,11 +214,11 @@ public class ThemeService {
return themeMapper.selectCount(new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getFormerThemeId, themeId)
.eq(ThemeEntity::getAuthorId, userId)
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED))>0;
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED)) > 0;
}
public Set<String> getForwardUsers(List<String> themeIds) {
if (CollectionUtils.isEmpty(themeIds)){
if (CollectionUtils.isEmpty(themeIds)) {
return new HashSet<>();
}
return themeMapper.selectList(new LambdaQueryWrapper<ThemeEntity>()
......@@ -223,13 +228,12 @@ public class ThemeService {
}
@Transactional
public void deleteById(String themeId,String userId) {
public void deleteById(String themeId, String userId) {
ThemeEntity themeEntity = themeMapper.selectOne(new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getThemeId, themeId));
if (themeEntity == null || !themeEntity.getAuthorId().equals(userId)) {
throw new BizException("主题与用户不匹配,id:" + themeId+",userId"+userId);
throw new BizException("主题与用户不匹配,id:" + themeId + ",userId" + userId);
}
themeEntity.setDeleteTag(DeleteTagEnum.DELETED.getCode());
themeMapper.updateById(themeEntity);
......@@ -238,8 +242,8 @@ public class ThemeService {
/**
* 查询更新节点后的用户新建主题数
*
* @param userIds 用户ids
* @param lastId 更新时间节点
* @param userIds 用户ids
* @param lastId 更新时间节点
* @return
*/
public Integer queryCountFromLastId(List<String> userIds, Long lastId) {
......@@ -257,7 +261,7 @@ public class ThemeService {
public void updateReportStatus(String themeId) {
ThemeEntity themeEntity = queryByThemeId(themeId);
if (themeEntity == null) {
throw new BizException("主题未找到,id:"+themeId);
throw new BizException("主题未找到,id:" + themeId);
}
themeEntity.setReportStatus(ReportStatusEnum.REPORTED.getCode());
themeMapper.updateById(themeEntity);
......@@ -265,12 +269,12 @@ public class ThemeService {
//统计主题集合的浏览量
public Map<String, Integer> getForwardCountMap(List<String> themeIds) {
if (CollectionUtils.isEmpty(themeIds)){
if (CollectionUtils.isEmpty(themeIds)) {
return new HashMap<String, Integer>();
}
LambdaQueryWrapper<ThemeEntity> wrapper = new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED)
.in(ThemeEntity::getFormerThemeId,themeIds)
.in(ThemeEntity::getFormerThemeId, themeIds)
.groupBy(ThemeEntity::getFormerThemeId);
return themeMapper.selectCountByThemeIds(wrapper).stream()
.collect(Collectors.toMap(TimesCountEntity::getId, TimesCountEntity::getTimes));
......@@ -279,7 +283,7 @@ public class ThemeService {
public List<ThemeEntity> queryAllForward() {
return themeMapper.selectList(new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getThemeType, ThemeTypeEnum.FORWARD.getCode())
.eq(ThemeEntity::getDeleteTag,DeleteTagEnum.NOT_DELETED.getCode())
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())
.orderByAsc(ThemeEntity::getCreateTime));
}
......@@ -297,4 +301,33 @@ public class ThemeService {
this.insertTheme(themeEntity);
return themeEntity.getThemeId();
}
public void queryCommentForTopic(List<TopicFollowQo> topicQos, String userId) {
for (TopicFollowQo topic : topicQos) {
String topicId = topic.getTopicId();
// 最近的一条讨论
ThemeEntity themeEntity = themeMapper.queryOneByTopicIdOrderByUpdateTimeDesc(topicId);
if (themeEntity != null) {
ThemeQo themeQo = ConvertUtil.themeEntityToQo(themeEntity);
topic.setLastTheme(themeQo.getAuthorId() + themeQo.content.get(0).getValue());
topic.setLastThemeTime(TimeUtils.format(themeEntity.getUpdateTime()));
}
// 查询更新条数
VisitLogEntity visitLogEntity = visitLogMapper.queryLastByVisitorIdAndRefId(userId, topicId);
if (visitLogEntity != null) {
Integer updates = themeMapper.countByTopicIdAndCreateTimeAfter(topicId, visitLogEntity.getUpdateTime());
topic.setUpdateCount(updates);
} else {
topic.setUpdateCount(0);
}
}
}
}
......@@ -2,15 +2,20 @@ package com.tanpu.community.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanpu.common.uuid.UuidGenHelper;
import com.tanpu.community.api.beans.qo.TopicFollowQo;
import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.api.enums.StatusEnum;
import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.dao.entity.community.TopicFollowRelEntity;
import com.tanpu.community.dao.mapper.community.TopicFollowRelMapper;
import com.tanpu.community.dao.mapper.community.TopicMapper;
import com.tanpu.community.util.ConvertUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
......@@ -21,10 +26,18 @@ import java.util.List;
public class TopicService {
@Resource
private TopicMapper topicMapper;
TopicFollowRelMapper topicFollowRelMapper;
@Autowired
@Resource
TopicMapper topicMapper;
@Resource
private UuidGenHelper uuidGenHelper;
@Resource
private ThemeService themeService;
@Resource
private VisitLogService visitLogService;
public List<TopicEntity> queryAll() {
List<TopicEntity> retList = new ArrayList<>();
......@@ -42,8 +55,7 @@ public class TopicService {
}
public TopicEntity queryById(String topicId) {
public TopicEntity queryOnlineTopicById(String topicId) {
return topicMapper.selectOne(new LambdaQueryWrapper<TopicEntity>()
.eq(TopicEntity::getTopicId, topicId)
.eq(TopicEntity::getIsConceal, StatusEnum.FALSE)
......@@ -54,7 +66,7 @@ public class TopicService {
public String queryTitleById(String topicId) {
TopicEntity topicEntity = topicMapper.selectOne(new LambdaQueryWrapper<TopicEntity>()
.eq(TopicEntity::getTopicId, topicId));
return topicEntity!=null?topicEntity.getTopicTitle():null;
return topicEntity != null ? topicEntity.getTopicTitle() : null;
}
public List<TopicEntity> queryByIds(List<String> topicIds) {
......@@ -64,4 +76,49 @@ public class TopicService {
return topicMapper.selectList(new LambdaQueryWrapper<TopicEntity>().in(TopicEntity::getTopicId, topicIds));
}
public List<TopicFollowQo> queryFollowTopic(String userId) {
// 用户的关注列表(包括专属)
List<String> followTopicIds = topicFollowRelMapper.selectTopicIdByUserId(userId);
if (CollectionUtils.isEmpty(followTopicIds)){
return Collections.emptyList();
}
List<TopicEntity> topicEntities = topicMapper.selectAllByTopicIdIn(followTopicIds);
List<TopicFollowQo> topicFollowQos = ConvertUtil.topicEntityToFollowQos(topicEntities);
return topicFollowQos;
}
public void followTopic(String topicId, String userId) {
}
public boolean addFollowTopic(String topicId, String userId) {
TopicFollowRelEntity searchResult = topicFollowRelMapper.queryOneByTopicIdAndUserId(topicId, userId);
if (searchResult == null) {
TopicFollowRelEntity entity = TopicFollowRelEntity.builder()
.topicId(topicId)
.userId(userId)
.followTime(LocalDateTime.now())
.build();
topicFollowRelMapper.insert(entity);
return true;
} else {
searchResult.setFollowTime(LocalDateTime.now());
searchResult.setDeleteTag(DeleteTagEnum.NOT_DELETED.getCode());
topicFollowRelMapper.updateById(searchResult);
return false;
}
}
public void deleteFollowTopic(String topicId, String userId) {
TopicFollowRelEntity searchResult = topicFollowRelMapper.queryOneByTopicIdAndUserId(topicId, userId);
if (searchResult != null){
searchResult.setUnfollowTime(LocalDateTime.now());
searchResult.setDeleteTag(DeleteTagEnum.DELETED.getCode());
topicFollowRelMapper.updateById(searchResult);
}
}
}
......@@ -138,4 +138,13 @@ public class VisitLogService {
return visitLogMapper.selectCountByThemeIds(wrapper).stream()
.collect(Collectors.toMap(TimesCountEntity::getId, TimesCountEntity::getTimes));
}
// 查询讨论区最近浏览
public Integer queryLastTopicVisit(String theme) {
return visitLogMapper.selectCount(new LambdaQueryWrapper<VisitLogEntity>()
.eq(VisitLogEntity::getRefId, theme)
.eq(VisitLogEntity::getRefType, PageEnum.COMM_VISIT_THEME.getId()));
}
}
......@@ -51,7 +51,7 @@ public class ConvertUtil {
List<ThemeContentQo> themeContentQos = JsonUtil.toBean(themeEntity.getContent(), new TypeReference<List<ThemeContentQo>>() {
});
// 屏蔽手机号和邮箱
themeContentQos.stream().filter(o->RelTypeEnum.TEXT.type.equals(o.getType())).forEach(o->o.setValue(OtherUtil.blockPhoneAndEmail(o.getValue())));
themeContentQos.stream().filter(o -> RelTypeEnum.TEXT.type.equals(o.getType())).forEach(o -> o.setValue(OtherUtil.blockPhoneAndEmail(o.getValue())));
themeQO.setContent(themeContentQos);
return themeQO;
......@@ -133,6 +133,19 @@ public class ConvertUtil {
return topicEntities.stream().map(ConvertUtil::topicEntityToHotQo).collect(Collectors.toList());
}
public static List<TopicFollowQo> topicEntityToFollowQos(List<TopicEntity> topicEntities) {
if (topicEntities == null) {
return Collections.emptyList();
}
return topicEntities.stream().map(ConvertUtil::topicEntityToFollowQo).collect(Collectors.toList());
}
private static TopicFollowQo topicEntityToFollowQo(TopicEntity topicEntity) {
TopicFollowQo topicFollowQo = new TopicFollowQo();
BeanUtils.copyProperties(topicEntity, topicFollowQo);
return topicFollowQo;
}
public static CommentQo commentEntity2Qo(CommentEntity entity) {
CommentQo qo = new CommentQo();
......
......@@ -7,10 +7,16 @@ apollo.bootstrap.enabled: false
# bootstrap:
# namespaces: application.yml
springfox:
documentation:
swagger:
v2:
path: /api-docs
server:
port: 8080
servlet:
context-path: /community
context-path: /community2
spring.datasource:
community:
......@@ -95,6 +101,8 @@ recommend:
tmpfile:
dir: /data/tmp
logging.level.com.tanpu: debug
tanpu:
fatools:
svc: https://testtamper.tanpuyun.com
......
......@@ -3,6 +3,21 @@
<mapper namespace="com.tanpu.community.dao.mapper.community.ThemeMapper">
<!-- 通用查询映射结果 -->
<sql id="Base_Column_List">
id,
theme_id,
title,
theme_type,
content,
author_id,
former_theme_id,
topic_id,
review_status,
report_status,
create_time,
update_time,
delete_tag
</sql>
<resultMap id="BaseResultMap" type="com.tanpu.community.dao.entity.community.ThemeEntity">
<id column="id" property="id" />
<result column="theme_id" property="themeId" />
......@@ -19,4 +34,18 @@
<result column="delete_tag" property="deleteTag" />
</resultMap>
<!--auto generated by MybatisCodeHelper on 2022-02-17-->
<select id="queryOneByTopicIdOrderByUpdateTimeDesc" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from theme
where topic_id=#{topicId} order by update_time desc limit 1
</select>
<!--auto generated by MybatisCodeHelper on 2022-02-17-->
<select id="countByTopicIdAndCreateTimeAfter" resultType="java.lang.Integer">
select count(1)
from theme
where topic_id=#{topicId} and create_time <![CDATA[>]]> #{minCreateTime}
</select>
</mapper>
......@@ -3,10 +3,29 @@
<mapper namespace="com.tanpu.community.dao.mapper.community.TopicMapper">
<!-- 通用查询映射结果 -->
<sql id="Base_Column_List">
id,
topic_id,
topic_title,
topic_desc,
cover_img,
special_permission,
sync_corp_wechat,
is_top,
is_conceal,
view_cnt_adjust,
create_time,
update_time,
delete_tag
</sql>
<resultMap id="BaseResultMap" type="com.tanpu.community.dao.entity.community.TopicEntity">
<id column="id" property="id" />
<result column="topic_id" property="topicId" />
<result column="topic_title" property="topicTitle" />
<result column="topic_desc" property="topicDesc" />
<result column="cover_img" property="coverImg" />
<result column="special_permission" property="specialPermission" />
<result column="sync_corp_wechat" property="syncCorpWechat" />
<result column="is_top" property="isTop" />
<result column="is_conceal" property="isConceal" />
<result column="view_cnt_adjust" property="viewCntAdjust" />
......@@ -15,4 +34,16 @@
<result column="delete_tag" property="deleteTag" />
</resultMap>
<!--auto generated by MybatisCodeHelper on 2022-02-17-->
<select id="selectAllByTopicIdIn" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from topic
where topic_id in
<foreach item="item" index="index" collection="topicIdCollection"
open="(" separator="," close=")">
#{item}
</foreach>
</select>
</mapper>
<?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.TopicFollowRelMapper">
<!-- 通用查询映射结果 -->
<sql id="Base_Column_List">
id,
topic_id,
user_id,
follow_time,
unfollow_time,
create_time,
update_time,
delete_tag
</sql>
<resultMap id="BaseResultMap" type="com.tanpu.community.dao.entity.community.TopicFollowRelEntity">
<id column="id" property="id" />
<result column="topic_id" property="topicId" />
<result column="user_id" property="userId" />
<result column="follow_time" property="followTime" />
<result column="unfollow_time" property="unfollowTime" />
<result column="create_time" property="createTime" />
<result column="update_time" property="updateTime" />
<result column="delete_tag" property="deleteTag" />
</resultMap>
<!--auto generated by MybatisCodeHelper on 2022-02-17-->
<select id="selectTopicIdByUserId" resultType="java.lang.String">
select topic_id
from topic_follow_rel
where user_id=#{userId}
and delete_tag = 0
</select>
<!--auto generated by MybatisCodeHelper on 2022-02-17-->
<select id="queryOneByTopicIdAndUserId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from topic_follow_rel
where topic_id=#{topicId} and user_id=#{userId}
</select>
</mapper>
......@@ -3,6 +3,18 @@
<mapper namespace="com.tanpu.community.dao.mapper.community.VisitLogMapper">
<!-- 通用查询映射结果 -->
<sql id="Base_Column_List">
id,
ident,
visitor_id,
author_id,
ref_id,
ref_type,
duration,
create_time,
update_time,
delete_tag
</sql>
<resultMap id="BaseResultMap" type="com.tanpu.community.dao.entity.community.VisitLogEntity">
<id column="id" property="id" />
<result column="ident" property="ident" />
......@@ -16,4 +28,12 @@
<result column="delete_tag" property="deleteTag" />
</resultMap>
<!--auto generated by MybatisCodeHelper on 2022-02-17-->
<select id="queryLastByVisitorIdAndRefId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from visit_log
where visitor_id=#{visitorId} and ref_id=#{refId}
order by update_time limit 1
</select>
</mapper>
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