-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
56da7b7
commit 222481d
Showing
5 changed files
with
142 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/com/swpu/uchain/blog/service/TypesService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.swpu.uchain.blog.service; | ||
|
||
import com.swpu.uchain.blog.form.InsertTypesForm; | ||
import com.swpu.uchain.blog.form.UpdateTypesForm; | ||
import com.swpu.uchain.blog.vo.ResultVO; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* @author hobo | ||
* @description | ||
*/ | ||
public interface TypesService { | ||
|
||
/*** | ||
* 添加分类 | ||
* @param form 添加分类表单 | ||
* @return com.swpu.uchain.blog.vo.ResultVO | ||
*/ | ||
ResultVO insertTypes(InsertTypesForm form); | ||
|
||
/** | ||
* 修改分类 | ||
* @param form 更新分类表单 | ||
* @return com.swpu.uchain.blog.vo.ResultVO | ||
*/ | ||
ResultVO updateTypes(UpdateTypesForm form); | ||
|
||
/** | ||
* 删除分类 | ||
* @param id 分类id | ||
* @return com.swpu.uchain.blog.vo.ResultVO | ||
*/ | ||
ResultVO deleteTypes(Integer id); | ||
|
||
/*** | ||
* 查询所有分类 | ||
* @return com.swpu.uchain.blog.vo.ResultVO | ||
*/ | ||
ResultVO selectAllTypes(); | ||
} |
89 changes: 89 additions & 0 deletions
89
src/main/java/com/swpu/uchain/blog/service/impl/TypesServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.swpu.uchain.blog.service.impl; | ||
|
||
import com.swpu.uchain.blog.dao.ArticleMapper; | ||
import com.swpu.uchain.blog.dao.TypesMapper; | ||
import com.swpu.uchain.blog.entity.Article; | ||
import com.swpu.uchain.blog.entity.Types; | ||
import com.swpu.uchain.blog.enums.DefaultEnum; | ||
import com.swpu.uchain.blog.enums.ResultEnum; | ||
import com.swpu.uchain.blog.form.InsertTypesForm; | ||
import com.swpu.uchain.blog.form.UpdateTypesForm; | ||
import com.swpu.uchain.blog.service.ArticleService; | ||
import com.swpu.uchain.blog.service.TypesService; | ||
import com.swpu.uchain.blog.util.ResultVOUtil; | ||
import com.swpu.uchain.blog.util.TimeUtil; | ||
import com.swpu.uchain.blog.vo.ResultVO; | ||
import org.springframework.beans.BeanUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author hobo | ||
* @description | ||
*/ | ||
@Service | ||
public class TypesServiceImpl implements TypesService { | ||
|
||
@Autowired | ||
private TypesMapper typesMapper; | ||
|
||
@Autowired | ||
private ArticleMapper articleMapper; | ||
|
||
@Autowired | ||
private ArticleService articleService; | ||
|
||
@Override | ||
public ResultVO insertTypes(InsertTypesForm form) { | ||
if (typesMapper.selectByTypeMsg(form.getTypeMsg()) != null) { | ||
return ResultVOUtil.error(ResultEnum.TYPE_IS_ALREADY_EXIST); | ||
} | ||
Types types = new Types(); | ||
BeanUtils.copyProperties(form, types); | ||
types.setCreatTime(TimeUtil.getNowTime()); | ||
if (typesMapper.insert(types) == 1) { | ||
return ResultVOUtil.success(types); | ||
} | ||
return ResultVOUtil.error(ResultEnum.SERVER_ERROR); | ||
} | ||
|
||
@Override | ||
public ResultVO updateTypes(UpdateTypesForm form) { | ||
if (typesMapper.selectByPrimaryKey(form.getId()) == null) { | ||
return ResultVOUtil.error(ResultEnum.TYPE_NOT_EXIST); | ||
} | ||
Types types = new Types(); | ||
BeanUtils.copyProperties(form, types); | ||
if (typesMapper.updateByPrimaryKey(types) == 1) { | ||
return ResultVOUtil.success(types); | ||
} | ||
return ResultVOUtil.error(ResultEnum.SERVER_ERROR); | ||
} | ||
|
||
@Override | ||
public ResultVO deleteTypes(Integer id) { | ||
if (id.equals(DefaultEnum.TYPE_DEFAULT_ENUM.getValue())) { | ||
return ResultVOUtil.error(ResultEnum.DEFAULT_GROUP_CAN_NOT_DELETE); | ||
} | ||
if (typesMapper.selectByPrimaryKey(id) == null) { | ||
return ResultVOUtil.error(ResultEnum.TYPE_NOT_EXIST); | ||
} | ||
List<Article> articles = articleMapper.selectByTypeId(id); | ||
if (typesMapper.deleteByPrimaryKey(id) == 1) { | ||
for (Article article : articles) { | ||
article.setTypeId(DefaultEnum.TYPE_DEFAULT_ENUM.getValue()); | ||
articleService.update(article); | ||
} | ||
return ResultVOUtil.success(); | ||
} | ||
return ResultVOUtil.error(ResultEnum.SERVER_ERROR); | ||
} | ||
|
||
@Override | ||
public ResultVO selectAllTypes() { | ||
List<Types> types = typesMapper.selectAll(); | ||
return ResultVOUtil.success(types); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters