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