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

讨论区

parent 314567f0
......@@ -4,8 +4,6 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.time.LocalDateTime;
@Data
@ApiModel("讨论区讨论")
......@@ -26,11 +24,10 @@ public class ThemeSimpleQo {
@ApiModelProperty(value = "文本内容")
private String content;
@ApiModelProperty(value = "评论时间")
private LocalDateTime updateTime;
@ApiModelProperty(value = "评论时间,格式化")
private String commentTime;
@ApiModelProperty(value = "更新时间")
private String updateTime;
@ApiModelProperty(value = "发表时间-标准格式化")
public String formatTime;
}
......@@ -50,7 +50,7 @@ public class TopicController {
@PostMapping(value = "/list")
@ApiOperation("热门话题,含搜索")
public CommonResp<Page<TopicRankQo>> getTopicList(@RequestBody TopicSearchReq req) {
return CommonResp.success(topicManager.getAllTopicBriefInfo(req));
return CommonResp.success(topicManager.getAllTopicRankInfo(req));
}
@GetMapping(value = "/detailPage")
......@@ -76,7 +76,7 @@ public class TopicController {
}
@GetMapping(value = "/link/discussion")
@PostMapping(value = "/rel/discussion")
@ApiOperation("资源关联讨论区,课程(基金)介绍用")
public CommonResp<DiscussionAeraQo> getForum(@RequestBody TopicDiscussionReq req) {
return CommonResp.success(topicManager.getForum(req));
......
......@@ -11,19 +11,25 @@ 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.TopicDiscussionReq;
import com.tanpu.community.api.beans.req.topic.TopicSearchReq;
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp;
import com.tanpu.community.api.enums.OperationTypeEnum;
import com.tanpu.community.api.enums.TopicSpecialPermissionEnum;
import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.dao.mapper.community.TopicFollowRelMapper;
import com.tanpu.community.service.FeignService;
import com.tanpu.community.service.RankService;
import com.tanpu.community.service.ThemeService;
import com.tanpu.community.service.TopicService;
import com.tanpu.community.util.ConvertUtil;
import com.tanpu.community.util.PageUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
......@@ -45,6 +51,8 @@ public class TopicManager {
TopicFollowRelMapper topicFollowRelMapper;
@Resource
private ThemeService themeService;
@Resource
private FeignService feignService;
// 首页-话题标签
public List<TopicRankQo> getTop4TopicTitles() {
......@@ -52,7 +60,7 @@ public class TopicManager {
}
// 话题列表
public Page<TopicRankQo> getAllTopicBriefInfo(TopicSearchReq req) {
public Page<TopicRankQo> getAllTopicRankInfo(TopicSearchReq req) {
// 全量排序,内存分页
List<TopicRankQo> topicList = rankService.getRankTopicList(req.getSearchKeyword());
Page<TopicRankQo> result = PageUtils.page(req.getPage(), topicList);
......@@ -169,7 +177,30 @@ public class TopicManager {
}
public DiscussionAeraQo getForum(TopicDiscussionReq req) {
return null;
TopicEntity topicEntity = topicService.queryRelateTopic(req);
// 没有关联话题,或者已下线
if (topicEntity==null) return null;
DiscussionAeraQo result = new DiscussionAeraQo();
List<TopicRankQo> rankTopicList = rankService.getRankTopicList(topicEntity.getTopicTitle());
List<TopicRankQo> collect = rankTopicList.stream().filter(o -> o.getTopicId().equals(topicEntity.getTopicId())).collect(Collectors.toList());
BeanUtils.copyProperties(collect.get(0),result);
// 最新讨论
List<ThemeEntity> themeEntities = themeService.queryNewestByTopic(topicEntity.getTopicId(), 0, 3, Collections.emptyList());
// 查询用户信息
List<String> authorIds = new ArrayList<>(themeEntities.stream().map(ThemeEntity::getAuthorId).collect(Collectors.toSet()));
List<UserInfoResp> queryUsersListNew = feignService.getUserList(authorIds);
Map<String, UserInfoResp> nameMap = queryUsersListNew.stream().collect(Collectors.toMap(UserInfoResp::getUserId, o->o));
result.setThemes(ConvertUtil.themeEntity2Discussion(themeEntities,nameMap));
return result;
}
}
......@@ -160,13 +160,13 @@ public class ThemeService {
* @param pageSize 查询数量
* @return
*/
public List<ThemeEntity> queryNewestByTopic(String topidId, Integer pageNo, Integer pageSize, List<String> excludeIds) {
public List<ThemeEntity> queryNewestByTopic(String topidId, Integer pageStart, Integer pageSize, List<String> excludeIds) {
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getTopicId, topidId);
if (!excludeIds.isEmpty()) {
queryWrapper.notIn(ThemeEntity::getThemeId, excludeIds);
}
queryWrapper.last("limit " + pageNo + ", " + pageSize)
queryWrapper.last("limit " + pageStart + ", " + pageSize)
.orderByDesc(ThemeEntity::getCreateTime)
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
return themeMapper.selectList(queryWrapper);
......@@ -313,7 +313,7 @@ public class ThemeService {
if (themeEntity != null) {
ThemeQo themeQo = ConvertUtil.themeEntityToQo(themeEntity);
topic.setLastTheme(getUserName(themeQo.getAuthorId()) + ":" + themeQo.content.get(0).getValue());
topic.setLastThemeTime(TimeUtils.format(themeEntity.getUpdateTime()));
topic.setLastThemeTime(TimeUtils.formatTopicListTime(themeEntity.getUpdateTime()));
}
......
......@@ -9,6 +9,7 @@ import com.tanpu.community.api.beans.qo.TopicAttachmentDetail;
import com.tanpu.community.api.beans.qo.TopicFollowQo;
import com.tanpu.community.api.beans.qo.TopicPageDetailQo;
import com.tanpu.community.api.beans.qo.TopicRankQo;
import com.tanpu.community.api.beans.req.topic.TopicDiscussionReq;
import com.tanpu.community.api.beans.resp.CoursePackageSimpleResp;
import com.tanpu.community.api.beans.vo.feign.product.FundCompanyVO;
import com.tanpu.community.api.beans.vo.feign.activity.OfflineActivitySimpleResp;
......@@ -259,4 +260,27 @@ public class TopicService {
return StringUtils.join(userNames, "、");
}
/**
* 查询资源关联的话题
* @param req
* @return
*/
public TopicEntity queryRelateTopic(TopicDiscussionReq req) {
List<TopicSubjectEntity> topicSubjectEntities = topicSubjectMapper.selectList(new LambdaQueryWrapper<TopicSubjectEntity>()
.eq(TopicSubjectEntity::getSubjectId, req.getSubjectId())
.eq(TopicSubjectEntity::getSubjectType, req.getSubjectType())
.orderByDesc(TopicSubjectEntity::getCreateTime));
if (CollectionUtils.isEmpty(topicSubjectEntities)){
return null;
}
String topicId = topicSubjectEntities.get(0).getTopicId();
return topicMapper.selectOne(new LambdaQueryWrapper<TopicEntity>()
.eq(TopicEntity::getTopicId, topicId)
.eq(TopicEntity::getIsConceal, StatusEnum.FALSE)
.eq(TopicEntity::getDeleteTag, StatusEnum.FALSE));
}
}
......@@ -372,4 +372,24 @@ public class ConvertUtil {
}).collect(Collectors.toList());
}
public static List<ThemeSimpleQo> themeEntity2Discussion(List<ThemeEntity> themeEntities, Map<String, UserInfoResp> nameMap) {
if (CollectionUtils.isEmpty(themeEntities)) return Collections.emptyList();
return themeEntities.stream().map(o->{
ThemeQo themeQo = themeEntityToQo(o);
ThemeSimpleQo themeSimpleQo = new ThemeSimpleQo();
BeanUtils.copyProperties(themeQo,themeSimpleQo);
String authorId = themeSimpleQo.getAuthorId();
if (nameMap.containsKey(authorId)) {
UserInfoResp userInfo = nameMap.get(authorId);
themeSimpleQo.setNickName(userInfo.getNickName());
themeSimpleQo.setUserImg(userInfo.getHeadImageUrl());
}
themeSimpleQo.setFormatTime(TimeUtils.calUpToNowTime(o.getUpdateTime()));
themeSimpleQo.setContent(themeQo.getContent().get(0).getValue());
return themeSimpleQo;
}).collect(Collectors.toList());
}
}
......@@ -19,7 +19,9 @@ public class TimeUtils {
return LocalDateTime.ofInstant(instant, zone);
}
//计算迄今时间
/**
* 计算迄今时间
*/
public static String calUpToNowTime(LocalDateTime start) {
Duration between = Duration.between(start, LocalDateTime.now());
long duration = between.toMinutes();
......@@ -37,7 +39,20 @@ public class TimeUtils {
return start.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
}
//格式化时间
/**
* 格式化话题列表时间
*/
public static String formatTopicListTime(LocalDateTime start) {
Duration between = Duration.between(start, LocalDateTime.now());
long duration = between.toMinutes();
if (duration < 60 * 24) {
return start.format(DateTimeFormatter.ofPattern(" HH:mm"));
} else if (duration < 60 * 48) {
return start.format(DateTimeFormatter.ofPattern("昨天 HH:mm"));
}
return start.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日"));
}
public static String format(LocalDateTime start) {
return start.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
}
......
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