增加文章/分类的状态切换接口
This commit is contained in:
parent
f7c1eb85f5
commit
e8bcc62d4b
|
|
@ -99,4 +99,19 @@ public class ArticleController {
|
|||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 文章状态
|
||||
*
|
||||
* @author fzr
|
||||
* @param articleParam 文章参数
|
||||
* @return Object
|
||||
*/
|
||||
@Log(title = "文章状态")
|
||||
@PostMapping("/change")
|
||||
public Object change(@Validated(value = ArticleParam.change.class)
|
||||
@RequestBody ArticleParam articleParam) {
|
||||
iArticleArchivesService.change(articleParam.getId());
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,4 +110,19 @@ public class CategoryController {
|
|||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 分类状态
|
||||
*
|
||||
* @author fzr
|
||||
* @param categoryParam 分类参数
|
||||
* @return Object
|
||||
*/
|
||||
@Log(title = "文章分类状态")
|
||||
@PostMapping("/change")
|
||||
public Object change(@Validated(value = CategoryParam.change.class)
|
||||
@RequestBody CategoryParam categoryParam) {
|
||||
iArticleCategoryService.change(categoryParam.getId());
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,4 +55,12 @@ public interface IArticleArchivesService {
|
|||
*/
|
||||
void del(Integer id);
|
||||
|
||||
/**
|
||||
* 文章状态
|
||||
*
|
||||
* @author fzr
|
||||
* @param id 文章主键
|
||||
*/
|
||||
void change(Integer id);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,4 +63,12 @@ public interface IArticleCategoryService {
|
|||
*/
|
||||
void del(Integer id);
|
||||
|
||||
/**
|
||||
* 分类状态
|
||||
*
|
||||
* @author fzr
|
||||
* @param id 分类ID
|
||||
*/
|
||||
void change(Integer id);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -172,6 +172,7 @@ public class ArticleArchivesServiceImpl implements IArticleArchivesService {
|
|||
public void del(Integer id) {
|
||||
Article article = articleMapper.selectOne(
|
||||
new QueryWrapper<Article>()
|
||||
.select("id,is_show")
|
||||
.eq("id", id)
|
||||
.eq("is_delete", 0));
|
||||
|
||||
|
|
@ -182,4 +183,25 @@ public class ArticleArchivesServiceImpl implements IArticleArchivesService {
|
|||
articleMapper.updateById(article);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文章状态
|
||||
*
|
||||
* @author fzr
|
||||
* @param id 文章主键
|
||||
*/
|
||||
@Override
|
||||
public void change(Integer id) {
|
||||
Article article = articleMapper.selectOne(
|
||||
new QueryWrapper<Article>()
|
||||
.select("id,is_show")
|
||||
.eq("id", id)
|
||||
.eq("is_delete", 0));
|
||||
|
||||
Assert.notNull(article, "文章不存在!");
|
||||
|
||||
article.setIsShow(article.getIsShow()==0?1:0);
|
||||
article.setUpdateTime(TimeUtil.timestamp());
|
||||
articleMapper.updateById(article);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,10 @@ import com.mdd.admin.validate.article.CategoryParam;
|
|||
import com.mdd.admin.validate.common.PageParam;
|
||||
import com.mdd.admin.vo.article.ArticleCateVo;
|
||||
import com.mdd.common.core.PageResult;
|
||||
import com.mdd.common.entity.article.Article;
|
||||
import com.mdd.common.entity.article.ArticleCategory;
|
||||
import com.mdd.common.mapper.article.ArticleCategoryMapper;
|
||||
import com.mdd.common.mapper.article.ArticleMapper;
|
||||
import com.mdd.common.utils.TimeUtil;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -29,6 +31,9 @@ public class ArticleCategoryServiceImpl implements IArticleCategoryService {
|
|||
@Resource
|
||||
ArticleCategoryMapper articleCategoryMapper;
|
||||
|
||||
@Resource
|
||||
ArticleMapper articleMapper;
|
||||
|
||||
/**
|
||||
* 分类所有
|
||||
*
|
||||
|
|
@ -84,6 +89,11 @@ public class ArticleCategoryServiceImpl implements IArticleCategoryService {
|
|||
ArticleCateVo vo = new ArticleCateVo();
|
||||
BeanUtils.copyProperties(category, vo);
|
||||
|
||||
Integer number = articleMapper.selectCount(new QueryWrapper<Article>()
|
||||
.eq("cid", category.getId())
|
||||
.eq("is_delete", 0));
|
||||
|
||||
vo.setNumber(number);
|
||||
vo.setCreateTime(TimeUtil.timestampToDate(vo.getCreateTime()));
|
||||
vo.setUpdateTime(TimeUtil.timestampToDate(vo.getUpdateTime()));
|
||||
list.add(vo);
|
||||
|
|
@ -170,9 +180,7 @@ public class ArticleCategoryServiceImpl implements IArticleCategoryService {
|
|||
public void del(Integer id) {
|
||||
ArticleCategory model = articleCategoryMapper.selectOne(
|
||||
new QueryWrapper<ArticleCategory>()
|
||||
.select(ArticleCategory.class, info->
|
||||
!info.getColumn().equals("is_delete") &&
|
||||
!info.getColumn().equals("delete_time"))
|
||||
.select("id,is_show")
|
||||
.eq("id", id)
|
||||
.eq("is_delete", 0));
|
||||
|
||||
|
|
@ -183,5 +191,25 @@ public class ArticleCategoryServiceImpl implements IArticleCategoryService {
|
|||
articleCategoryMapper.updateById(model);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分类状态
|
||||
*
|
||||
* @author fzr
|
||||
* @param id 分类ID
|
||||
*/
|
||||
@Override
|
||||
public void change(Integer id) {
|
||||
ArticleCategory model = articleCategoryMapper.selectOne(
|
||||
new QueryWrapper<ArticleCategory>()
|
||||
.select("id,is_show")
|
||||
.eq("id", id)
|
||||
.eq("is_delete", 0));
|
||||
|
||||
Assert.notNull(model, "分类不存在");
|
||||
|
||||
model.setIsShow(model.getIsShow()==0?1:0);
|
||||
model.setUpdateTime(TimeUtil.timestamp());
|
||||
articleCategoryMapper.updateById(model);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,8 +25,9 @@ public class ArticleParam implements Serializable {
|
|||
public interface create{}
|
||||
public interface update{}
|
||||
public interface delete{}
|
||||
public interface change{}
|
||||
|
||||
@IDMust(message = "id参数必传且需大于0", groups = {update.class, delete.class})
|
||||
@IDMust(message = "id参数必传且需大于0", groups = {update.class, delete.class, change.class})
|
||||
private Integer id;
|
||||
|
||||
@IDMust(message = "id参数必传且需大于0", groups = {create.class, update.class})
|
||||
|
|
|
|||
|
|
@ -25,8 +25,9 @@ public class CategoryParam implements Serializable {
|
|||
public interface create{}
|
||||
public interface update{}
|
||||
public interface delete{}
|
||||
public interface change{}
|
||||
|
||||
@IDMust(message = "id参数必传且需大于0", groups = {ArticleParam.create.class, ArticleParam.delete.class})
|
||||
@IDMust(message = "id参数必传且需大于0", groups = {create.class, delete.class, change.class})
|
||||
private Integer id;
|
||||
|
||||
@NotEmpty(message = "分类名称不能为空", groups = {create.class, update.class})
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ public class ArticleCateVo implements Serializable {
|
|||
|
||||
private Integer id; // 主键
|
||||
private String name; // 分类名称
|
||||
private Integer number; // 文章数量
|
||||
private Integer sort; // 排序编号
|
||||
private Integer isShow; // 是否显示
|
||||
private String createTime; // 创建时间
|
||||
|
|
|
|||
Loading…
Reference in New Issue