UserTextbookEnrollService.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.dao.UserTextbookEnrollMapper;
  8. import com.qxgmat.data.dao.entity.UserTextbookEnroll;
  9. import com.qxgmat.data.relation.UserTextbookEnrollRelationMapper;
  10. import com.qxgmat.data.relation.entity.MonthNumberRelation;
  11. import org.slf4j.Logger;
  12. import org.slf4j.LoggerFactory;
  13. import org.springframework.stereotype.Service;
  14. import javax.annotation.Resource;
  15. import java.util.Collection;
  16. import java.util.List;
  17. @Service
  18. public class UserTextbookEnrollService extends AbstractService {
  19. private static final Logger logger = LoggerFactory.getLogger(UserTextbookEnrollService.class);
  20. @Resource
  21. private UserTextbookEnrollMapper userTextbookEnrollMapper;
  22. @Resource
  23. private UserTextbookEnrollRelationMapper userTextbookEnrollRelationMapper;
  24. public List<UserTextbookEnroll> allByUser(Integer userId, String startTime, String endTime){
  25. Example example = new Example(UserTextbookEnroll.class);
  26. example.and(
  27. example.createCriteria()
  28. .andEqualTo("userId", userId)
  29. .andGreaterThanOrEqualTo("date", startTime)
  30. .andLessThan("date", endTime)
  31. );
  32. example.orderBy("date").asc();
  33. return select(userTextbookEnrollMapper, example);
  34. }
  35. public List<MonthNumberRelation> groupByMonth(String startTime, String endTime){
  36. return userTextbookEnrollRelationMapper.groupByMonth(startTime, endTime);
  37. }
  38. public UserTextbookEnroll getByUser(Integer userId){
  39. Example example = new Example(UserTextbookEnroll.class);
  40. example.and(
  41. example.createCriteria()
  42. .andEqualTo("userId", userId)
  43. );
  44. return one(userTextbookEnrollMapper, example);
  45. }
  46. public UserTextbookEnroll add(UserTextbookEnroll ad){
  47. int result = insert(userTextbookEnrollMapper, ad);
  48. ad = one(userTextbookEnrollMapper, ad.getId());
  49. if(ad == null){
  50. throw new SystemException("记录添加失败");
  51. }
  52. return ad;
  53. }
  54. public UserTextbookEnroll edit(UserTextbookEnroll ad){
  55. UserTextbookEnroll in = one(userTextbookEnrollMapper, ad.getId());
  56. if(in == null){
  57. throw new ParameterException("记录不存在");
  58. }
  59. int result = update(userTextbookEnrollMapper, ad);
  60. return ad;
  61. }
  62. public boolean delete(Number id){
  63. UserTextbookEnroll in = one(userTextbookEnrollMapper, id);
  64. if(in == null){
  65. throw new ParameterException("记录不存在");
  66. }
  67. int result = delete(userTextbookEnrollMapper, id);
  68. return result > 0;
  69. }
  70. public UserTextbookEnroll get(Number id){
  71. UserTextbookEnroll in = one(userTextbookEnrollMapper, id);
  72. if(in == null){
  73. throw new ParameterException("记录不存在");
  74. }
  75. return in;
  76. }
  77. public Page<UserTextbookEnroll> select(int page, int pageSize){
  78. return select(userTextbookEnrollMapper, page, pageSize);
  79. }
  80. public Page<UserTextbookEnroll> select(Integer[] ids){
  81. return page(()->select(userTextbookEnrollMapper, ids), 1, ids.length);
  82. }
  83. public List<UserTextbookEnroll> select(Collection ids){
  84. return select(userTextbookEnrollMapper, ids);
  85. }
  86. }