增加文章/分类的状态切换接口

This commit is contained in:
TinyAnts 2022-08-23 10:18:14 +08:00
parent f7c1eb85f5
commit e8bcc62d4b
9 changed files with 104 additions and 5 deletions

View File

@ -99,4 +99,19 @@ public class ArticleController {
return AjaxResult.success(); 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();
}
} }

View File

@ -110,4 +110,19 @@ public class CategoryController {
return AjaxResult.success(); 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();
}
} }

View File

@ -55,4 +55,12 @@ public interface IArticleArchivesService {
*/ */
void del(Integer id); void del(Integer id);
/**
* 文章状态
*
* @author fzr
* @param id 文章主键
*/
void change(Integer id);
} }

View File

@ -63,4 +63,12 @@ public interface IArticleCategoryService {
*/ */
void del(Integer id); void del(Integer id);
/**
* 分类状态
*
* @author fzr
* @param id 分类ID
*/
void change(Integer id);
} }

View File

@ -172,6 +172,7 @@ public class ArticleArchivesServiceImpl implements IArticleArchivesService {
public void del(Integer id) { public void del(Integer id) {
Article article = articleMapper.selectOne( Article article = articleMapper.selectOne(
new QueryWrapper<Article>() new QueryWrapper<Article>()
.select("id,is_show")
.eq("id", id) .eq("id", id)
.eq("is_delete", 0)); .eq("is_delete", 0));
@ -182,4 +183,25 @@ public class ArticleArchivesServiceImpl implements IArticleArchivesService {
articleMapper.updateById(article); 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);
}
} }

View File

@ -8,8 +8,10 @@ import com.mdd.admin.validate.article.CategoryParam;
import com.mdd.admin.validate.common.PageParam; import com.mdd.admin.validate.common.PageParam;
import com.mdd.admin.vo.article.ArticleCateVo; import com.mdd.admin.vo.article.ArticleCateVo;
import com.mdd.common.core.PageResult; import com.mdd.common.core.PageResult;
import com.mdd.common.entity.article.Article;
import com.mdd.common.entity.article.ArticleCategory; import com.mdd.common.entity.article.ArticleCategory;
import com.mdd.common.mapper.article.ArticleCategoryMapper; import com.mdd.common.mapper.article.ArticleCategoryMapper;
import com.mdd.common.mapper.article.ArticleMapper;
import com.mdd.common.utils.TimeUtil; import com.mdd.common.utils.TimeUtil;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -29,6 +31,9 @@ public class ArticleCategoryServiceImpl implements IArticleCategoryService {
@Resource @Resource
ArticleCategoryMapper articleCategoryMapper; ArticleCategoryMapper articleCategoryMapper;
@Resource
ArticleMapper articleMapper;
/** /**
* 分类所有 * 分类所有
* *
@ -84,6 +89,11 @@ public class ArticleCategoryServiceImpl implements IArticleCategoryService {
ArticleCateVo vo = new ArticleCateVo(); ArticleCateVo vo = new ArticleCateVo();
BeanUtils.copyProperties(category, vo); 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.setCreateTime(TimeUtil.timestampToDate(vo.getCreateTime()));
vo.setUpdateTime(TimeUtil.timestampToDate(vo.getUpdateTime())); vo.setUpdateTime(TimeUtil.timestampToDate(vo.getUpdateTime()));
list.add(vo); list.add(vo);
@ -170,9 +180,7 @@ public class ArticleCategoryServiceImpl implements IArticleCategoryService {
public void del(Integer id) { public void del(Integer id) {
ArticleCategory model = articleCategoryMapper.selectOne( ArticleCategory model = articleCategoryMapper.selectOne(
new QueryWrapper<ArticleCategory>() new QueryWrapper<ArticleCategory>()
.select(ArticleCategory.class, info-> .select("id,is_show")
!info.getColumn().equals("is_delete") &&
!info.getColumn().equals("delete_time"))
.eq("id", id) .eq("id", id)
.eq("is_delete", 0)); .eq("is_delete", 0));
@ -183,5 +191,25 @@ public class ArticleCategoryServiceImpl implements IArticleCategoryService {
articleCategoryMapper.updateById(model); 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);
}
} }

View File

@ -25,8 +25,9 @@ public class ArticleParam implements Serializable {
public interface create{} public interface create{}
public interface update{} public interface update{}
public interface delete{} 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; private Integer id;
@IDMust(message = "id参数必传且需大于0", groups = {create.class, update.class}) @IDMust(message = "id参数必传且需大于0", groups = {create.class, update.class})

View File

@ -25,8 +25,9 @@ public class CategoryParam implements Serializable {
public interface create{} public interface create{}
public interface update{} public interface update{}
public interface delete{} 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; private Integer id;
@NotEmpty(message = "分类名称不能为空", groups = {create.class, update.class}) @NotEmpty(message = "分类名称不能为空", groups = {create.class, update.class})

View File

@ -14,6 +14,7 @@ public class ArticleCateVo implements Serializable {
private Integer id; // 主键 private Integer id; // 主键
private String name; // 分类名称 private String name; // 分类名称
private Integer number; // 文章数量
private Integer sort; // 排序编号 private Integer sort; // 排序编号
private Integer isShow; // 是否显示 private Integer isShow; // 是否显示
private String createTime; // 创建时间 private String createTime; // 创建时间