修复:cmsArticle模块的bug
This commit is contained in:
@@ -48,7 +48,7 @@ public class CmsArticleCategoryController extends BaseController {
|
||||
//return success(cmsArticleCategoryService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:cmsArticleCategory:list')")
|
||||
@PreAuthorize("hasAuthority('cms:articleCategory:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询文章分类表")
|
||||
@GetMapping("/{id}")
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.gxwebsoft.cms.controller;
|
||||
|
||||
import com.alipay.api.domain.Article;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.cms.entity.CmsArticleContent;
|
||||
import com.gxwebsoft.cms.service.CmsArticleContentService;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.cms.service.CmsArticleService;
|
||||
import com.gxwebsoft.cms.entity.CmsArticle;
|
||||
@@ -30,6 +34,8 @@ import java.util.List;
|
||||
public class CmsArticleController extends BaseController {
|
||||
@Resource
|
||||
private CmsArticleService cmsArticleService;
|
||||
@Resource
|
||||
private CmsArticleContentService articleContentService;
|
||||
|
||||
@ApiOperation("分页查询文章")
|
||||
@GetMapping("/page")
|
||||
@@ -41,37 +47,46 @@ public class CmsArticleController extends BaseController {
|
||||
@ApiOperation("查询全部文章")
|
||||
@GetMapping()
|
||||
public ApiResult<List<CmsArticle>> list(CmsArticleParam param) {
|
||||
PageParam<CmsArticle, CmsArticleParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(cmsArticleService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(cmsArticleService.listRel(param));
|
||||
return success(cmsArticleService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:cmsArticle:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询文章")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<CmsArticle> get(@PathVariable("id") Integer id) {
|
||||
return success(cmsArticleService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(cmsArticleService.getByIdRel(id));
|
||||
// 使用关联查询
|
||||
CmsArticle article = cmsArticleService.getByIdRel(id);
|
||||
// 更新阅读数量
|
||||
article.setActualViews(article.getActualViews() + 1);
|
||||
cmsArticleService.updateById(article);
|
||||
// 附加文字内容
|
||||
CmsArticleContent content = articleContentService.getOne(new LambdaQueryWrapper<CmsArticleContent>().eq(CmsArticleContent::getArticleId,article.getArticleId()).last("limit 1"));
|
||||
if(content != null){
|
||||
article.setContent(content.getContent());
|
||||
}
|
||||
return success(article);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:cmsArticle:save')")
|
||||
@ApiOperation("添加文章")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody CmsArticle cmsArticle) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
cmsArticle.setUserId(loginUser.getUserId());
|
||||
}
|
||||
if (cmsArticleService.save(cmsArticle)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
public ApiResult<?> save(@RequestBody CmsArticle article) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
article.setUserId(loginUser.getUserId());
|
||||
}
|
||||
if (cmsArticleService.save(article)) {
|
||||
// 保存文章内容
|
||||
final CmsArticleContent content = new CmsArticleContent();
|
||||
content.setArticleId(article.getArticleId());
|
||||
content.setContent(article.getContent());
|
||||
articleContentService.save(content);
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:cmsArticle:update')")
|
||||
@ApiOperation("修改文章")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody CmsArticle cmsArticle) {
|
||||
@@ -81,6 +96,7 @@ public class CmsArticleController extends BaseController {
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:cmsArticle:remove')")
|
||||
@ApiOperation("删除文章")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
@@ -90,6 +106,7 @@ public class CmsArticleController extends BaseController {
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:cmsArticle:save')")
|
||||
@ApiOperation("批量添加文章")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<CmsArticle> list) {
|
||||
@@ -99,6 +116,7 @@ public class CmsArticleController extends BaseController {
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:cmsArticle:update')")
|
||||
@ApiOperation("批量修改文章")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<CmsArticle> batchParam) {
|
||||
@@ -108,6 +126,7 @@ public class CmsArticleController extends BaseController {
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:cmsArticle:remove')")
|
||||
@ApiOperation("批量删除文章")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
@@ -117,4 +136,30 @@ public class CmsArticleController extends BaseController {
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@ApiOperation("读取上一篇")
|
||||
@GetMapping("/getPrevious/{id}")
|
||||
public ApiResult<CmsArticle> getPrevious(@PathVariable("id") Integer id) {
|
||||
LambdaQueryWrapper<CmsArticle> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.lt(CmsArticle::getArticleId,id);
|
||||
wrapper.eq(CmsArticle::getStatus,0);
|
||||
wrapper.eq(CmsArticle::getType,0);
|
||||
wrapper.orderByDesc(CmsArticle::getArticleId);
|
||||
wrapper.last("limit 1");
|
||||
final CmsArticle article = cmsArticleService.getOne(wrapper);
|
||||
return success(article);
|
||||
}
|
||||
|
||||
@ApiOperation("读取下一篇")
|
||||
@GetMapping("/getNext/{id}")
|
||||
public ApiResult<CmsArticle> getNext(@PathVariable("id") Integer id) {
|
||||
LambdaQueryWrapper<CmsArticle> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.gt(CmsArticle::getArticleId,id);
|
||||
wrapper.eq(CmsArticle::getStatus,0);
|
||||
wrapper.eq(CmsArticle::getType,0);
|
||||
wrapper.orderByAsc(CmsArticle::getArticleId);
|
||||
wrapper.last("limit 1");
|
||||
final CmsArticle article = cmsArticleService.getOne(wrapper);
|
||||
return success(article);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -54,8 +54,6 @@ public class CmsNavigationController extends BaseController {
|
||||
return success(cmsNavigationService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:cmsNavigation:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询网站导航记录表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<CmsNavigation> get(@PathVariable("id") Integer id) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.gxwebsoft.cms.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.util.Date;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
@@ -46,6 +47,18 @@ public class CmsArticle implements Serializable {
|
||||
@ApiModelProperty(value = "文章分类ID")
|
||||
private Integer categoryId;
|
||||
|
||||
@ApiModelProperty(value = "当前分类")
|
||||
@TableField(exist = false)
|
||||
private String categoryName;
|
||||
|
||||
@ApiModelProperty(value = "父级分类ID")
|
||||
@TableField(exist = false)
|
||||
private Integer parentId;
|
||||
|
||||
@ApiModelProperty(value = "父级分类")
|
||||
@TableField(exist = false)
|
||||
private String parentName;
|
||||
|
||||
@ApiModelProperty(value = "封面图")
|
||||
private String image;
|
||||
|
||||
@@ -100,6 +113,14 @@ public class CmsArticle implements Serializable {
|
||||
@ApiModelProperty(value = "用户ID")
|
||||
private Integer userId;
|
||||
|
||||
@ApiModelProperty(value = "昵称")
|
||||
@TableField(exist = false)
|
||||
private String nickname;
|
||||
|
||||
@ApiModelProperty(value = "头像")
|
||||
@TableField(exist = false)
|
||||
private String avatar;
|
||||
|
||||
@ApiModelProperty(value = "排序(数字越小越靠前)")
|
||||
private Integer sortNumber;
|
||||
|
||||
@@ -122,4 +143,8 @@ public class CmsArticle implements Serializable {
|
||||
@ApiModelProperty(value = "修改时间")
|
||||
private Date updateTime;
|
||||
|
||||
@ApiModelProperty(value = "文章内容")
|
||||
@TableField(exist = false)
|
||||
private String content;
|
||||
|
||||
}
|
||||
|
||||
@@ -4,9 +4,12 @@
|
||||
|
||||
<!-- 关联查询sql -->
|
||||
<sql id="selectSql">
|
||||
SELECT a.*
|
||||
SELECT a.*,b.title as categoryName,b.parent_Id as parentId,c.title as parentName,d.nickname,d.avatar
|
||||
FROM cms_article a
|
||||
<where>
|
||||
LEFT JOIN cms_article_category b ON a.category_id = b.category_id
|
||||
LEFT JOIN cms_article_category c ON c.category_id = b.parent_id
|
||||
LEFT JOIN sys_user d ON d.user_id = a.user_id
|
||||
<where>
|
||||
<if test="param.articleId != null">
|
||||
AND a.article_id = #{param.articleId}
|
||||
</if>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.XmlUtil;
|
||||
@@ -11,7 +10,6 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alipay.api.internal.util.file.IOUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.google.gson.Gson;
|
||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||
import com.gxwebsoft.common.core.utils.JSONUtil;
|
||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||
@@ -25,19 +23,16 @@ import com.gxwebsoft.common.system.service.UserOauthService;
|
||||
import com.gxwebsoft.common.system.service.UserRoleService;
|
||||
import com.gxwebsoft.common.system.service.UserService;
|
||||
import com.gxwebsoft.common.system.vo.WxOfficialButton;
|
||||
import com.gxwebsoft.common.system.vo.WxOfficialMenu;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
Reference in New Issue
Block a user