250522
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package com.gxwebsoft.cms.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.cms.entity.ArticleCategory;
|
||||
import com.gxwebsoft.cms.service.ArticleCategoryService;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.cms.service.ArticleService;
|
||||
import com.gxwebsoft.cms.entity.Article;
|
||||
@@ -16,6 +19,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -30,6 +34,8 @@ import java.util.List;
|
||||
public class ArticleController extends BaseController {
|
||||
@Resource
|
||||
private ArticleService articleService;
|
||||
@Resource
|
||||
private ArticleCategoryService articleCategoryService;
|
||||
|
||||
@ApiOperation("根据id查询文章记录表")
|
||||
@PostMapping("/info")
|
||||
@@ -48,16 +54,28 @@ public class ArticleController extends BaseController {
|
||||
return success(articleService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:article:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部文章记录表")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Article>> list(ArticleParam param) {
|
||||
PageParam<Article, ArticleParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("sort_number asc, create_time desc");
|
||||
return success(articleService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(articleService.listRel(param));
|
||||
LambdaQueryWrapper<Article> queryWrapper = new LambdaQueryWrapper<>();
|
||||
List<Integer> categoryIds = new ArrayList<>();
|
||||
if (param.getCategoryId() != null) {
|
||||
List<ArticleCategory> childCateList = articleCategoryService.childList(param.getCategoryId());
|
||||
if (!childCateList.isEmpty()) {
|
||||
for (ArticleCategory cate : childCateList) {
|
||||
categoryIds.add(cate.getCategoryId());
|
||||
}
|
||||
}
|
||||
categoryIds.add(param.getCategoryId());
|
||||
}
|
||||
queryWrapper.orderByAsc(Article::getSortNumber)
|
||||
.orderByDesc(Article::getCreateTime);
|
||||
if (!categoryIds.isEmpty()) {
|
||||
queryWrapper.in(Article::getCategoryId, categoryIds);
|
||||
}
|
||||
List<Article> articleList = articleService.list(queryWrapper);
|
||||
return success(articleList);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:article:list')")
|
||||
@@ -69,7 +87,7 @@ public class ArticleController extends BaseController {
|
||||
// 使用关联查询
|
||||
Article article = articleService.getByIdRel(id);
|
||||
article.setArticleId(id);
|
||||
article.setVirtualViews(article.getVirtualViews()+1);
|
||||
article.setVirtualViews(article.getVirtualViews() + 1);
|
||||
articleService.saveOrUpdate(article);
|
||||
return success(article);
|
||||
}
|
||||
@@ -82,7 +100,7 @@ public class ArticleController extends BaseController {
|
||||
// 记录当前登录用户id、租户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
article.setUserId(loginUser.getUserId());
|
||||
article.setUserId(loginUser.getUserId());
|
||||
}
|
||||
if (articleService.save(article)) {
|
||||
return success("添加成功");
|
||||
|
||||
Reference in New Issue
Block a user