ReadyRoomService.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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.ReadyArticleMapper;
  9. import com.qxgmat.data.dao.ReadyRoomMapper;
  10. import com.qxgmat.data.dao.entity.ReadyArticle;
  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 ReadyRoomService extends AbstractService {
  20. private static final Logger logger = LoggerFactory.getLogger(ReadyRoomService.class);
  21. @Resource
  22. private ReadyRoomMapper readyRoomMapper;
  23. public Page<ReadyRoom> list(int page, int size, String keyword, Integer areaId, String order, DirectionStatus direction){
  24. Example example = new Example(ReadyRoom.class);
  25. if (keyword != null)
  26. example.and(
  27. example.createCriteria()
  28. .orLike("address", "%"+keyword+"%")
  29. .orLike("title", "%"+keyword+"%")
  30. .orLike("description", "%"+keyword+"%")
  31. );
  32. if (areaId != null)
  33. example.and(
  34. example.createCriteria()
  35. .andEqualTo("areaId", areaId)
  36. );
  37. if(order == null || order.isEmpty()) order = "id";
  38. switch(direction){
  39. case ASC:
  40. example.orderBy(order).asc();
  41. break;
  42. case DESC:
  43. default:
  44. example.orderBy(order).desc();
  45. }
  46. return select(readyRoomMapper, example, page, size);
  47. }
  48. public Page<ReadyRoom> listAdmin(int page, int size, String position, Integer areaId, String order, DirectionStatus direction){
  49. Example example = new Example(ReadyRoom.class);
  50. if (position != null)
  51. example.and(
  52. example.createCriteria()
  53. .andEqualTo("position", position)
  54. );
  55. if (areaId != null)
  56. example.and(
  57. example.createCriteria()
  58. .andEqualTo("areaId", areaId)
  59. );
  60. if(order == null || order.isEmpty()) order = "id";
  61. switch(direction){
  62. case ASC:
  63. example.orderBy(order).asc();
  64. break;
  65. case DESC:
  66. default:
  67. example.orderBy(order).desc();
  68. }
  69. return select(readyRoomMapper, example, page, size);
  70. }
  71. public ReadyRoom add(ReadyRoom entity){
  72. int result = insert(readyRoomMapper, entity);
  73. entity = one(readyRoomMapper, entity.getId());
  74. if(entity == null){
  75. throw new SystemException("考场添加失败");
  76. }
  77. return entity;
  78. }
  79. public ReadyRoom edit(ReadyRoom entity){
  80. ReadyRoom in = one(readyRoomMapper, entity.getId());
  81. if(in == null){
  82. throw new ParameterException("考场不存在");
  83. }
  84. int result = update(readyRoomMapper, entity);
  85. return entity;
  86. }
  87. public boolean delete(Number id){
  88. ReadyRoom in = one(readyRoomMapper, id);
  89. if(in == null){
  90. throw new ParameterException("考场不存在");
  91. }
  92. int result = delete(readyRoomMapper, id);
  93. return result > 0;
  94. }
  95. public ReadyRoom get(Number id){
  96. ReadyRoom in = one(readyRoomMapper, id);
  97. if(in == null){
  98. throw new ParameterException("考场不存在");
  99. }
  100. return in;
  101. }
  102. public Page<ReadyRoom> select(int page, int pageSize){
  103. return select(readyRoomMapper, page, pageSize);
  104. }
  105. public Page<ReadyRoom> select(Integer[] ids){
  106. return page(()->select(readyRoomMapper, ids), 1, ids.length);
  107. }
  108. public List<ReadyRoom> select(Collection ids){
  109. return select(readyRoomMapper, ids);
  110. }
  111. }