ReadyDataService.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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.ReadyDataMapper;
  9. import com.qxgmat.data.dao.ReadyRoomMapper;
  10. import com.qxgmat.data.dao.entity.ReadyData;
  11. import com.qxgmat.data.dao.entity.ReadyRoom;
  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 ReadyDataService extends AbstractService {
  20. private static final Logger logger = LoggerFactory.getLogger(ReadyDataService.class);
  21. @Resource
  22. private ReadyDataMapper readyDataMapper;
  23. public Page<ReadyData> listAdmin(int page, int size, Boolean isOfficial, String order, DirectionStatus direction){
  24. Example example = new Example(ReadyData.class);
  25. if (isOfficial != null)
  26. example.and(
  27. example.createCriteria()
  28. .andEqualTo("isOfficial", isOfficial)
  29. );
  30. if(order == null || order.isEmpty()) order = "id";
  31. switch(direction){
  32. case ASC:
  33. example.orderBy(order).asc();
  34. break;
  35. case DESC:
  36. default:
  37. example.orderBy(order).desc();
  38. }
  39. return select(readyDataMapper, example, page, size);
  40. }
  41. public List<ReadyData> all(Boolean isOfficial){
  42. Example example = new Example(ReadyData.class);
  43. if (isOfficial != null)
  44. example.and(
  45. example.createCriteria()
  46. .andEqualTo("isOfficial", isOfficial)
  47. );
  48. return select(readyDataMapper, example);
  49. }
  50. public ReadyData add(ReadyData entity){
  51. int result = insert(readyDataMapper, entity);
  52. entity = one(readyDataMapper, entity.getId());
  53. if(entity == null){
  54. throw new SystemException("考场添加失败");
  55. }
  56. return entity;
  57. }
  58. public ReadyData edit(ReadyData entity){
  59. ReadyData in = one(readyDataMapper, entity.getId());
  60. if(in == null){
  61. throw new ParameterException("考场不存在");
  62. }
  63. int result = update(readyDataMapper, entity);
  64. return entity;
  65. }
  66. public boolean delete(Number id){
  67. ReadyData in = one(readyDataMapper, id);
  68. if(in == null){
  69. throw new ParameterException("考场不存在");
  70. }
  71. int result = delete(readyDataMapper, id);
  72. return result > 0;
  73. }
  74. public ReadyData get(Number id){
  75. ReadyData in = one(readyDataMapper, id);
  76. if(in == null){
  77. throw new ParameterException("考场不存在");
  78. }
  79. return in;
  80. }
  81. public Page<ReadyData> select(int page, int pageSize){
  82. return select(readyDataMapper, page, pageSize);
  83. }
  84. public Page<ReadyData> select(Integer[] ids){
  85. return page(()->select(readyDataMapper, ids), 1, ids.length);
  86. }
  87. public List<ReadyData> select(Collection ids){
  88. return select(readyDataMapper, ids);
  89. }
  90. }