ReadyReadService.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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.ReadyReadMapper;
  9. import com.qxgmat.data.dao.entity.ReadyRead;
  10. import org.slf4j.Logger;
  11. import org.slf4j.LoggerFactory;
  12. import org.springframework.stereotype.Service;
  13. import javax.annotation.Resource;
  14. import java.util.Collection;
  15. import java.util.List;
  16. @Service
  17. public class ReadyReadService extends AbstractService {
  18. private static final Logger logger = LoggerFactory.getLogger(ReadyReadService.class);
  19. @Resource
  20. private ReadyReadMapper readyReadMapper;
  21. public Page<ReadyRead> listAdmin(int page, int size, String plate, String order, DirectionStatus direction){
  22. Example example = new Example(ReadyRead.class);
  23. if (plate != null)
  24. example.and(
  25. example.createCriteria()
  26. .andEqualTo("plate", plate)
  27. );
  28. if(order == null || order.isEmpty()) order = "id";
  29. switch(direction){
  30. case ASC:
  31. example.orderBy(order).asc();
  32. break;
  33. case DESC:
  34. default:
  35. example.orderBy(order).desc();
  36. }
  37. return select(readyReadMapper, example, page, size);
  38. }
  39. public Page<ReadyRead> list(int page, int size, String plate, String order, DirectionStatus direction){
  40. Example example = new Example(ReadyRead.class);
  41. if (plate != null)
  42. example.and(
  43. example.createCriteria()
  44. .andEqualTo("plate", plate)
  45. );
  46. if(order == null || order.isEmpty()) order = "id";
  47. switch(direction){
  48. case ASC:
  49. example.orderBy(order).asc();
  50. break;
  51. case DESC:
  52. default:
  53. example.orderBy(order).desc();
  54. }
  55. return select(readyReadMapper, example, page, size);
  56. }
  57. public ReadyRead add(ReadyRead entity){
  58. int result = insert(readyReadMapper, entity);
  59. entity = one(readyReadMapper, entity.getId());
  60. if(entity == null){
  61. throw new SystemException("阅读添加失败");
  62. }
  63. return entity;
  64. }
  65. public ReadyRead edit(ReadyRead entity){
  66. ReadyRead in = one(readyReadMapper, entity.getId());
  67. if(in == null){
  68. throw new ParameterException("阅读不存在");
  69. }
  70. int result = update(readyReadMapper, entity);
  71. return entity;
  72. }
  73. public boolean delete(Number id){
  74. ReadyRead in = one(readyReadMapper, id);
  75. if(in == null){
  76. throw new ParameterException("阅读不存在");
  77. }
  78. int result = delete(readyReadMapper, id);
  79. return result > 0;
  80. }
  81. public ReadyRead get(Number id){
  82. ReadyRead in = one(readyReadMapper, id);
  83. if(in == null){
  84. throw new ParameterException("阅读不存在");
  85. }
  86. return in;
  87. }
  88. public Page<ReadyRead> select(int page, int pageSize){
  89. return select(readyReadMapper, page, pageSize);
  90. }
  91. public Page<ReadyRead> select(Integer[] ids){
  92. return page(()->select(readyReadMapper, ids), 1, ids.length);
  93. }
  94. public List<ReadyRead> select(Collection ids){
  95. return select(readyReadMapper, ids);
  96. }
  97. }