package com.waner.primary.web.controller;
import com.google.common.collect.Lists;
import com.waner.primary.common.exception.GlobalException;
import com.waner.primary.common.result.Response;
import com.waner.primary.web.dto.TopMap;
import com.waner.primary.web.entity.TravelEssay;
import com.waner.primary.web.entity.TravelQuestion;
import com.waner.primary.web.entity.TravelRecommend;
import com.waner.primary.web.service.EssayCommentService;
import com.waner.primary.web.service.QuestionResolverService;
import com.waner.primary.web.service.RecommendService;
import com.waner.primary.web.service.TravelEssayService;
import com.waner.primary.web.service.impl.RedisService;
import com.waner.primary.web.vo.ArticleWithTag;
import com.waner.primary.web.vo.ResponseWithTag;
import com.waner.primary.web.vo.SearchInfoWithTag;
import com.waner.primary.web.vo.TableResult;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* Common usage to list the user's pushed articles, also include common top viewed articles.
*
* @author Monster
* @since 1.0.0-SNAPSHOT
*/
@Controller
@RequestMapping("common")
public class CommonController {
private final TravelEssayService travelEssayService;
private final QuestionResolverService questionResolverService;
private final EssayCommentService essayCommentService;
private final RecommendService recommendService;
private final TravelEssayService essayService;
private final RedisService redisService;
public CommonController(
TravelEssayService travelEssayService,
QuestionResolverService questionResolverService,
EssayCommentService essayCommentService,
RecommendService recommendService,
TravelEssayService essayService,
RedisService redisService) {
this.travelEssayService = travelEssayService;
this.questionResolverService = questionResolverService;
this.essayCommentService = essayCommentService;
this.recommendService = recommendService;
this.essayService = essayService;
this.redisService = redisService;
}
// -------------------------------------------------------------------------
// 个人信息列表获取
// -------------------------------------------------------------------------
/**
* 获取撰写的内容列表
*
* @param userId
* @param page
* @param limit
* @return
*/
@GetMapping("articles")
@ResponseBody
public TableResult<List<ArticleWithTag>> getMyArticles(
@RequestParam(value = "userId") Integer userId, int page, int limit) {
if (userId == null) {
throw new GlobalException("空参数", 500100);
}
List<ArticleWithTag> articlesWithTag = Lists.newArrayList();
List<TravelEssay> essays = travelEssayService.queryEssayByUser(userId);
List<TravelQuestion> questions = questionResolverService.queryQuestionByUser(userId);
essays.forEach(
article -> {
ArticleWithTag articleWithTag = ArticleWithTag.builder().build();
BeanUtils.copyProperties(article, articleWithTag);
articleWithTag.setTag("essay");
articlesWithTag.add(articleWithTag);
});
questions.forEach(
article -> {
ArticleWithTag articleWithTag = ArticleWithTag.builder().build();
BeanUtils.copyProperties(article, articleWithTag);
articleWithTag.setTag("question");
articlesWithTag.add(articleWithTag);
});
articlesWithTag.sort((a1, a2) -> a2.getCreateTime().compareTo(a1.getCreateTime()));
int start = (page - 1) * limit;
int end = page * limit - 1;
List<ArticleWithTag> result = Lists.newArrayList();
for (int i = start; i <= end; i++) {
if (i > articlesWithTag.size() - 1) {
break;
}
result.add(articlesWithTag.get(i));
}
return new TableResult<>(200, "", articlesWithTag.size(), result);
}
/**
* 获取收藏列表
*
* @param userId
* @param page
* @param limit
* @return
*/
@GetMapping("collections")
@ResponseBody
public TableResult<List<ArticleWithTag>> getCollections(
@RequestParam(value = "userId") Integer userId, int page, int limit) {
if (userId == null) {
throw new GlobalException("空参数", 500100);
}
List<ArticleWithTag> articlesWithTag = Lists.newArrayList();
Map<String, List<Integer>> withTagArticleIds = redisService.getCollectionArticlesId(userId);
List<Integer> recommendIds = withTagArticleIds.get("recommend");
List<Integer> essayIds = withTagArticleIds.get("essay");
List<Integer> questionIds = withTagArticleIds.get("question");
List<ArticleWithTag> recommends = recommendService.getListByIds(recommendIds);
List<ArticleWithTag> essays = essayService.getListByIds(essayIds);
List<ArticleWithTag> questions = questionResolverService.getListByIds(questionIds);
if (recommends != null) {
articlesWithTag.addAll(recommends);
}
if (essays != null) {
articlesWithTag.addAll(essays);
}
if (questions != null) {
articlesWithTag.addAll(questions);
}
articlesWithTag.sort((a1, a2) -> a2.getCreateTime().compareTo(a1.getCreateTime()));
int start = (page - 1) * limit;
int end = page * limit - 1;
List<ArticleWithTag> result = Lists.newArrayList();
for (int i = start; i <= end; i++) {
if (i > articlesWithTag.size() - 1) {
break;
}
result.add(articlesWithTag.get(i));
}
return new TableResult<>(200, "", articlesWithTag.size(), result);
}
/**
* 获取回复内容列表
*
* @param userId
* @param page
* @param limit
* @return
*/
@GetMapping("responses")
@ResponseBody
public TableResult<List<ResponseWithTag>> getMyResponses(
@RequestParam(value = "userId") Integer userId, int page, int limit) {
if (userId == null) {
throw new GlobalException("空参数", 500100);
}
List<ResponseWithTag> responsesWithTag = Lists.newArrayList();
List<ResponseWithTag> answersWithTag = questionResolverService.queryAnswersByUser(userId);
List<ResponseWithTag> replysWithTag = essayCommentService.queryReplysByUser(userId);
responsesWithTag.addAll(answersWithTag);
responsesWithTag.addAll(replysWithTag);
List<ResponseWithTag> sortedList =
responsesWithTag
.parallelStream()
.sorted((r1, r2) -> r2.getResponseCreateTime().compareTo(r1.getResponseCreateTime()))
.collect(Collectors.toList());
int start = (page - 1) * limit;
int end = page * limit - 1;
List<ResponseWithTag> results = Lists.newArrayList();
for (int i = start; i <= end; i++) {
if (i > sortedList.size() - 1) {
break;
}
results.add(sortedList.get(i));
}
return new TableResult<>(200, "", sortedList.size(), results);
}
/**
* 根据搜索的内容进行匹配
*
* @param pattern 匹配模式
* @return
*/
@GetMapping("search-list")
@ResponseBody
public TableResult<List<SearchInfoWithTag>> getSearchList(String pattern, int page, int limit) {
List<SearchInfoWithTag> searchs = Lists.newArrayList();
List<TravelRecommend> recommends = recommendService.getL
没有合适的资源?快使用搜索试试~ 我知道了~
基于JavaScript+SpringBoot的重庆旅游推荐网站项目源码(含项目界面截图+sql数据).zip
共312个文件
java:81个
gif:75个
js:42个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 196 浏览量
2024-05-12
23:14:36
上传
评论
收藏 2.2MB ZIP 举报
温馨提示
基于JavaScript+SpringBoot的重庆旅游推荐网站项目源码(含项目界面截图+sql数据).zip基于JavaScript+SpringBoot的重庆旅游推荐网站项目源码(含项目界面截图+sql数据).zip基于JavaScript+SpringBoot的重庆旅游推荐网站项目源码(含项目界面截图+sql数据).zip基于JavaScript+SpringBoot的重庆旅游推荐网站项目源码(含项目界面截图+sql数据).zip 【备注】 1.项目代码功能经验证ok,确保稳定可靠运行。欢迎下载使用!在使用过程中,如有问题或建议,请及时私信沟通。 2.主要针对各个计算机相关专业,包括计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网等领域的在校学生、专业教师或企业员工使用。 3.项目具有丰富的拓展空间,不仅可作为入门进阶,也可直接作为毕设、课程设计、大作业、初期项目立项演示等用途。 4.当然也鼓励大家基于此进行二次开发。 5.期待你能在项目中找到乐趣和灵感,也欢迎你的分享和反馈!
资源推荐
资源详情
资源评论
收起资源包目录
基于JavaScript+SpringBoot的重庆旅游推荐网站项目源码(含项目界面截图+sql数据).zip (312个子文件)
layui.css 87KB
admin.css 29KB
main.css 17KB
layim.css 15KB
layer.css 14KB
template.css 14KB
layui.mobile.css 10KB
layim.css 9KB
laydate.css 7KB
login.css 3KB
code.css 1KB
font.css 512B
iconfont.eot 40KB
59.gif 10KB
22.gif 10KB
24.gif 8KB
13.gif 7KB
16.gif 7KB
39.gif 6KB
64.gif 6KB
63.gif 6KB
50.gif 6KB
loading-0.gif 6KB
4.gif 6KB
1.gif 5KB
42.gif 5KB
71.gif 5KB
21.gif 5KB
20.gif 5KB
29.gif 5KB
70.gif 4KB
5.gif 4KB
17.gif 4KB
27.gif 4KB
9.gif 4KB
44.gif 4KB
11.gif 4KB
8.gif 4KB
3.gif 4KB
23.gif 4KB
34.gif 4KB
41.gif 4KB
38.gif 4KB
65.gif 3KB
32.gif 3KB
45.gif 3KB
7.gif 3KB
12.gif 3KB
26.gif 3KB
60.gif 3KB
2.gif 3KB
40.gif 3KB
25.gif 3KB
19.gif 3KB
66.gif 3KB
18.gif 3KB
46.gif 3KB
10.gif 3KB
28.gif 3KB
51.gif 3KB
57.gif 3KB
67.gif 3KB
0.gif 3KB
48.gif 3KB
43.gif 3KB
30.gif 2KB
61.gif 2KB
33.gif 2KB
69.gif 2KB
14.gif 2KB
47.gif 2KB
36.gif 2KB
49.gif 2KB
58.gif 2KB
6.gif 2KB
54.gif 2KB
53.gif 2KB
56.gif 2KB
62.gif 2KB
31.gif 2KB
55.gif 2KB
35.gif 2KB
15.gif 2KB
loading-2.gif 2KB
37.gif 1KB
68.gif 1KB
52.gif 777B
loading-1.gif 701B
persInfo.html 18KB
essay-details.html 11KB
question-detail.html 11KB
index.html 11KB
essay-list.html 9KB
forget.html 9KB
index.html 9KB
question-list.html 9KB
recommend-details.html 9KB
info-form.html 8KB
search.html 8KB
reg.html 7KB
共 312 条
- 1
- 2
- 3
- 4
资源评论
z同学的编程之路
- 粉丝: 2727
- 资源: 2135
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功