|
@@ -3,6 +3,7 @@ package com.my.bigevent.service.impl;
|
|
import com.my.bigevent.mapper.ArticleMapper;
|
|
import com.my.bigevent.mapper.ArticleMapper;
|
|
import com.my.bigevent.mapper.CategoryMapper;
|
|
import com.my.bigevent.mapper.CategoryMapper;
|
|
import com.my.bigevent.pojo.Category;
|
|
import com.my.bigevent.pojo.Category;
|
|
|
|
+import com.my.bigevent.pojo.Result;
|
|
import com.my.bigevent.service.CategoryService;
|
|
import com.my.bigevent.service.CategoryService;
|
|
import com.my.bigevent.utils.ThreadLocalUtil;
|
|
import com.my.bigevent.utils.ThreadLocalUtil;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -21,8 +22,18 @@ public class CategoryServiceImpl implements CategoryService
|
|
@Autowired
|
|
@Autowired
|
|
ArticleMapper articleMapper;
|
|
ArticleMapper articleMapper;
|
|
@Override
|
|
@Override
|
|
- public void add(Category category)
|
|
|
|
|
|
+ public Result add(Category category)
|
|
{
|
|
{
|
|
|
|
+ if(null==category.getCategoryName()||category.getCategoryName().isEmpty()){
|
|
|
|
+ return Result.error("分类名称不能为空");
|
|
|
|
+ }
|
|
|
|
+ if(null==category.getCategoryAlias()||category.getCategoryAlias().isEmpty()){
|
|
|
|
+ return Result.error("分类别名不能为空");
|
|
|
|
+ }
|
|
|
|
+ Integer count=categoryMapper.selectCountByName(category.getCategoryName());
|
|
|
|
+ if(count>0){
|
|
|
|
+ return Result.error("标签名称重复");
|
|
|
|
+ }
|
|
// 补充属性值,数据库里规定 category 的字段都不为 null
|
|
// 补充属性值,数据库里规定 category 的字段都不为 null
|
|
category.setCreateTime(LocalDateTime.now());
|
|
category.setCreateTime(LocalDateTime.now());
|
|
category.setUpdateTime(LocalDateTime.now());
|
|
category.setUpdateTime(LocalDateTime.now());
|
|
@@ -32,6 +43,8 @@ public class CategoryServiceImpl implements CategoryService
|
|
category.setCreateUser(userId);
|
|
category.setCreateUser(userId);
|
|
|
|
|
|
categoryMapper.add(category);
|
|
categoryMapper.add(category);
|
|
|
|
+
|
|
|
|
+ return Result.success("新增分类成功!");
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -54,4 +67,9 @@ public class CategoryServiceImpl implements CategoryService
|
|
{
|
|
{
|
|
categoryMapper.delete(id);
|
|
categoryMapper.delete(id);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Integer selectArticleCountByCategoryId(String id) {
|
|
|
|
+ return categoryMapper.selectArticleCountByCategoryId(id);
|
|
|
|
+ }
|
|
}
|
|
}
|