123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- package com.qxgmat.service.inline;
- import com.github.pagehelper.Page;
- import com.nuliji.tools.AbstractService;
- import com.nuliji.tools.exception.ParameterException;
- import com.nuliji.tools.exception.SystemException;
- import com.nuliji.tools.mybatis.Example;
- import com.qxgmat.data.constants.enums.status.DirectionStatus;
- import com.qxgmat.data.dao.ReadyArticleCategoryMapper;
- import com.qxgmat.data.dao.ReadyArticleMapper;
- import com.qxgmat.data.dao.entity.ReadyArticle;
- import com.qxgmat.data.dao.entity.ReadyArticleCategory;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.stereotype.Service;
- import javax.annotation.Resource;
- import java.util.Collection;
- import java.util.List;
- @Service
- public class ReadyArticleCategoryService extends AbstractService {
- private static final Logger logger = LoggerFactory.getLogger(ReadyArticleCategoryService.class);
- @Resource
- private ReadyArticleCategoryMapper readyArticleCategoryMapper;
- public List<ReadyArticleCategory> all(){
- Example example = new Example(ReadyArticleCategory.class);
- example.setOrderByClause("id asc");
- return select(readyArticleCategoryMapper);
- }
- public ReadyArticleCategory getCategory(String title, Integer parentId){
- Example example = new Example(ReadyArticleCategory.class);
- example.and(
- example.createCriteria()
- .andEqualTo("title", title)
- .andEqualTo("parentId", parentId)
- );
- return one(readyArticleCategoryMapper, example);
- }
- public ReadyArticleCategory addCategory(String title, Integer parentId){
- ReadyArticleCategory in = getCategory(title, parentId);
- if (in == null){
- return add(ReadyArticleCategory.builder()
- .parentId(parentId)
- .title(title)
- .build());
- }
- return in;
- }
- public ReadyArticleCategory add(ReadyArticleCategory entity){
- int result = insert(readyArticleCategoryMapper, entity);
- entity = one(readyArticleCategoryMapper, entity.getId());
- if(entity == null){
- throw new SystemException("文章分类添加失败");
- }
- return entity;
- }
- public ReadyArticleCategory edit(ReadyArticleCategory entity){
- ReadyArticleCategory in = one(readyArticleCategoryMapper, entity.getId());
- if(in == null){
- throw new ParameterException("文章分类不存在");
- }
- int result = update(readyArticleCategoryMapper, entity);
- return entity;
- }
- public boolean delete(Number id){
- ReadyArticleCategory in = one(readyArticleCategoryMapper, id);
- if(in == null){
- throw new ParameterException("文章分类不存在");
- }
- int result = delete(readyArticleCategoryMapper, id);
- return result > 0;
- }
- public ReadyArticleCategory get(Number id){
- ReadyArticleCategory in = one(readyArticleCategoryMapper, id);
- if(in == null){
- throw new ParameterException("文章分类不存在");
- }
- return in;
- }
- public Page<ReadyArticleCategory> select(int page, int pageSize){
- return select(readyArticleCategoryMapper, page, pageSize);
- }
- public Page<ReadyArticleCategory> select(Integer[] ids){
- return page(()->select(readyArticleCategoryMapper, ids), 1, ids.length);
- }
- public List<ReadyArticleCategory> select(Collection ids){
- return select(readyArticleCategoryMapper, ids);
- }
- }
|