新增:上一篇下一篇文章接口
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
package com.gxwebsoft.cms.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.cms.entity.Article;
|
||||
import com.gxwebsoft.cms.entity.ArticleCategory;
|
||||
import com.gxwebsoft.cms.param.ArticleParam;
|
||||
import com.gxwebsoft.cms.service.ArticleCategoryService;
|
||||
import com.gxwebsoft.cms.service.ArticleService;
|
||||
import com.gxwebsoft.common.core.web.*;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
@@ -24,6 +28,8 @@ import java.util.List;
|
||||
public class ArticleController extends BaseController {
|
||||
@Resource
|
||||
private ArticleService articleService;
|
||||
@Resource
|
||||
private ArticleCategoryService articleCategoryService;
|
||||
|
||||
@ApiOperation("分页查询文章记录表")
|
||||
@GetMapping("/page")
|
||||
@@ -50,6 +56,35 @@ public class ArticleController extends BaseController {
|
||||
public ApiResult<Article> get(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
Article article = articleService.getByIdRel(id);
|
||||
// 更新阅读数量
|
||||
article.setActualViews(article.getActualViews() + 1);
|
||||
articleService.updateById(article);
|
||||
return success(article);
|
||||
}
|
||||
|
||||
@ApiOperation("读取上一篇")
|
||||
@GetMapping("/getPrevious/{id}")
|
||||
public ApiResult<Article> getPrevious(@PathVariable("id") Integer id) {
|
||||
LambdaQueryWrapper<Article> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.lt(Article::getArticleId,id);
|
||||
wrapper.eq(Article::getStatus,0);
|
||||
wrapper.eq(Article::getType,0);
|
||||
wrapper.orderByDesc(Article::getArticleId);
|
||||
wrapper.last("limit 1");
|
||||
final Article article = articleService.getOne(wrapper);
|
||||
return success(article);
|
||||
}
|
||||
|
||||
@ApiOperation("读取下一篇")
|
||||
@GetMapping("/getNext/{id}")
|
||||
public ApiResult<Article> getNext(@PathVariable("id") Integer id) {
|
||||
LambdaQueryWrapper<Article> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.gt(Article::getArticleId,id);
|
||||
wrapper.eq(Article::getStatus,0);
|
||||
wrapper.eq(Article::getType,0);
|
||||
wrapper.orderByAsc(Article::getArticleId);
|
||||
wrapper.last("limit 1");
|
||||
final Article article = articleService.getOne(wrapper);
|
||||
return success(article);
|
||||
}
|
||||
|
||||
@@ -61,8 +96,11 @@ public class ArticleController extends BaseController {
|
||||
if (loginUser != null) {
|
||||
article.setUserId(loginUser.getUserId());
|
||||
}
|
||||
// 同步类型
|
||||
final ArticleCategory category = articleCategoryService.getById(article.getCategoryId());
|
||||
article.setType(category.getType());
|
||||
if (articleService.save(article)) {
|
||||
return success("添加成功");
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
@@ -71,6 +109,8 @@ public class ArticleController extends BaseController {
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Article article) {
|
||||
if (articleService.updateById(article)) {
|
||||
article.setUpdateTime(DateUtil.date());
|
||||
articleService.updateById(article);
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
|
||||
@@ -164,7 +164,6 @@ public class WebsiteController extends BaseController {
|
||||
@ApiOperation("清除缓存")
|
||||
@DeleteMapping("/clearSiteInfo/{key}")
|
||||
public ApiResult<?> clearSiteInfo(@PathVariable("key") String key) {
|
||||
System.out.println("key = " + key);
|
||||
final String siteInfo = redisUtil.get(key);
|
||||
if(StrUtil.isNotBlank(siteInfo)){
|
||||
redisUtil.delete(key);
|
||||
|
||||
@@ -29,6 +29,9 @@ public class Article implements Serializable {
|
||||
@ApiModelProperty(value = "文章标题")
|
||||
private String title;
|
||||
|
||||
@ApiModelProperty(value = "类型 0列表 1页面 2外链")
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty(value = "列表显示方式(10小图展示 20大图展示)")
|
||||
private Integer showType;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user