完成表单设计的开发
This commit is contained in:
@@ -62,8 +62,8 @@ public class ArticleController extends BaseController {
|
||||
article.setActualViews(article.getActualViews() + 1);
|
||||
articleService.updateById(article);
|
||||
// 附加文字内容
|
||||
if(article != null){
|
||||
ArticleContent content = articleContentService.getOne(new LambdaQueryWrapper<ArticleContent>().eq(ArticleContent::getArticleId,article.getArticleId()));
|
||||
ArticleContent content = articleContentService.getOne(new LambdaQueryWrapper<ArticleContent>().eq(ArticleContent::getArticleId,article.getArticleId()).last("limit 1"));
|
||||
if(content != null){
|
||||
article.setContent(content.getContent());
|
||||
}
|
||||
return success(article);
|
||||
@@ -127,8 +127,10 @@ public class ArticleController extends BaseController {
|
||||
ArticleContent content = new ArticleContent();
|
||||
content.setArticleId(article.getArticleId());
|
||||
content.setContent(article.getContent());
|
||||
if(articleContentService.count(new LambdaQueryWrapper<ArticleContent>().eq(ArticleContent::getArticleId,article.getArticleId())) > 0){
|
||||
articleContentService.updateById(content);
|
||||
ArticleContent one = articleContentService.getOne(new LambdaQueryWrapper<ArticleContent>().eq(ArticleContent::getArticleId, article.getArticleId()).last("limit 1"));
|
||||
if(one != null){
|
||||
one.setContent(article.getContent());
|
||||
articleContentService.updateById(one);
|
||||
}else {
|
||||
articleContentService.save(content);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
package com.gxwebsoft.cms.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.gxwebsoft.cms.entity.Form;
|
||||
import com.gxwebsoft.cms.param.FormParam;
|
||||
import com.gxwebsoft.cms.service.FormService;
|
||||
import com.gxwebsoft.common.core.web.*;
|
||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -24,6 +30,8 @@ import java.util.List;
|
||||
public class FormController extends BaseController {
|
||||
@Resource
|
||||
private FormService formService;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@ApiOperation("分页查询表单设计表")
|
||||
@GetMapping("/page")
|
||||
@@ -42,6 +50,12 @@ public class FormController extends BaseController {
|
||||
@ApiOperation("根据id查询表单设计表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Form> get(@PathVariable("id") Integer id) {
|
||||
String key = "FormId:" + id;
|
||||
final String formInfo = redisUtil.get(key);
|
||||
// 从缓存读取信息
|
||||
if(StrUtil.isNotBlank(formInfo)){
|
||||
return success(JSONObject.parseObject(formInfo, Form.class));
|
||||
}
|
||||
// 使用关联查询
|
||||
return success(formService.getByIdRel(id));
|
||||
}
|
||||
@@ -64,6 +78,10 @@ public class FormController extends BaseController {
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Form form) {
|
||||
if (formService.updateById(form)) {
|
||||
if (form.getClearCache() != null) {
|
||||
String key = "FormId:" + form.getFormId();
|
||||
redisUtil.set(key,form);
|
||||
}
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
|
||||
@@ -24,8 +24,11 @@ import java.util.Date;
|
||||
public class ArticleContent implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "主键ID")
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "文章ID")
|
||||
@TableId(value = "article_id", type = IdType.AUTO)
|
||||
private Integer articleId;
|
||||
|
||||
@ApiModelProperty(value = "文章内容")
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package com.gxwebsoft.cms.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
@@ -76,4 +73,8 @@ public class Form implements Serializable {
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
@ApiModelProperty(value = "是否更新缓存")
|
||||
@TableField(exist = false)
|
||||
private Integer clearCache;
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
SELECT a.*
|
||||
FROM cms_article_content a
|
||||
<where>
|
||||
<if test="param.id != null">
|
||||
AND a.id = #{param.idd}
|
||||
</if>
|
||||
<if test="param.articleId != null">
|
||||
AND a.article_id = #{param.articleId}
|
||||
</if>
|
||||
|
||||
@@ -22,8 +22,10 @@ import lombok.EqualsAndHashCode;
|
||||
public class ArticleContentParam extends BaseParam {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "文章ID")
|
||||
@ApiModelProperty(value = "ID")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer id;
|
||||
|
||||
private Integer articleId;
|
||||
|
||||
@ApiModelProperty(value = "文章内容")
|
||||
|
||||
@@ -40,7 +40,7 @@ public class ArticleContentServiceImpl extends ServiceImpl<ArticleContentMapper,
|
||||
@Override
|
||||
public ArticleContent getByIdRel(Integer id) {
|
||||
ArticleContentParam param = new ArticleContentParam();
|
||||
param.setArticleId(id);
|
||||
param.setId(id);
|
||||
return param.getOne(baseMapper.selectListRel(param));
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ public class FormServiceImpl extends ServiceImpl<FormMapper, Form> implements Fo
|
||||
@Override
|
||||
public PageResult<Form> pageRel(FormParam param) {
|
||||
PageParam<Form, FormParam> page = new PageParam<>(param);
|
||||
//page.setDefaultOrder("create_time desc");
|
||||
page.setDefaultOrder("create_time desc");
|
||||
List<Form> list = baseMapper.selectPageRel(page, param);
|
||||
return new PageResult<>(list, page.getTotal());
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public class FormServiceImpl extends ServiceImpl<FormMapper, Form> implements Fo
|
||||
List<Form> list = baseMapper.selectListRel(param);
|
||||
// 排序
|
||||
PageParam<Form, FormParam> page = new PageParam<>();
|
||||
//page.setDefaultOrder("create_time desc");
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return page.sortRecords(list);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user