ReadyArticleCategoryService.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package com.qxgmat.service.inline;
  2. import com.github.pagehelper.Page;
  3. import com.nuliji.tools.AbstractService;
  4. import com.nuliji.tools.exception.ParameterException;
  5. import com.nuliji.tools.exception.SystemException;
  6. import com.nuliji.tools.mybatis.Example;
  7. import com.qxgmat.data.constants.enums.status.DirectionStatus;
  8. import com.qxgmat.data.dao.ReadyArticleCategoryMapper;
  9. import com.qxgmat.data.dao.ReadyArticleMapper;
  10. import com.qxgmat.data.dao.entity.ReadyArticle;
  11. import com.qxgmat.data.dao.entity.ReadyArticleCategory;
  12. import org.slf4j.Logger;
  13. import org.slf4j.LoggerFactory;
  14. import org.springframework.stereotype.Service;
  15. import javax.annotation.Resource;
  16. import java.util.Collection;
  17. import java.util.List;
  18. @Service
  19. public class ReadyArticleCategoryService extends AbstractService {
  20. private static final Logger logger = LoggerFactory.getLogger(ReadyArticleCategoryService.class);
  21. @Resource
  22. private ReadyArticleCategoryMapper readyArticleCategoryMapper;
  23. public List<ReadyArticleCategory> all(){
  24. Example example = new Example(ReadyArticleCategory.class);
  25. example.setOrderByClause("id asc");
  26. return select(readyArticleCategoryMapper);
  27. }
  28. public ReadyArticleCategory getCategory(String title, Integer parentId){
  29. Example example = new Example(ReadyArticleCategory.class);
  30. example.and(
  31. example.createCriteria()
  32. .andEqualTo("title", title)
  33. .andEqualTo("parentId", parentId)
  34. );
  35. return one(readyArticleCategoryMapper, example);
  36. }
  37. public ReadyArticleCategory addCategory(String title, Integer parentId){
  38. ReadyArticleCategory in = getCategory(title, parentId);
  39. if (in == null){
  40. return add(ReadyArticleCategory.builder()
  41. .parentId(parentId)
  42. .title(title)
  43. .build());
  44. }
  45. return in;
  46. }
  47. public ReadyArticleCategory add(ReadyArticleCategory entity){
  48. int result = insert(readyArticleCategoryMapper, entity);
  49. entity = one(readyArticleCategoryMapper, entity.getId());
  50. if(entity == null){
  51. throw new SystemException("文章分类添加失败");
  52. }
  53. return entity;
  54. }
  55. public ReadyArticleCategory edit(ReadyArticleCategory entity){
  56. ReadyArticleCategory in = one(readyArticleCategoryMapper, entity.getId());
  57. if(in == null){
  58. throw new ParameterException("文章分类不存在");
  59. }
  60. int result = update(readyArticleCategoryMapper, entity);
  61. return entity;
  62. }
  63. public boolean delete(Number id){
  64. ReadyArticleCategory in = one(readyArticleCategoryMapper, id);
  65. if(in == null){
  66. throw new ParameterException("文章分类不存在");
  67. }
  68. int result = delete(readyArticleCategoryMapper, id);
  69. return result > 0;
  70. }
  71. public ReadyArticleCategory get(Number id){
  72. ReadyArticleCategory in = one(readyArticleCategoryMapper, id);
  73. if(in == null){
  74. throw new ParameterException("文章分类不存在");
  75. }
  76. return in;
  77. }
  78. public Page<ReadyArticleCategory> select(int page, int pageSize){
  79. return select(readyArticleCategoryMapper, page, pageSize);
  80. }
  81. public Page<ReadyArticleCategory> select(Integer[] ids){
  82. return page(()->select(readyArticleCategoryMapper, ids), 1, ids.length);
  83. }
  84. public List<ReadyArticleCategory> select(Collection ids){
  85. return select(readyArticleCategoryMapper, ids);
  86. }
  87. }