UserOrderCheckoutService.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package com.qxgmat.service.inline;
  2. import com.github.pagehelper.Page;
  3. import com.nuliji.tools.AbstractService;
  4. import com.nuliji.tools.Tools;
  5. import com.nuliji.tools.Transform;
  6. import com.nuliji.tools.exception.ParameterException;
  7. import com.nuliji.tools.exception.SystemException;
  8. import com.nuliji.tools.mybatis.Example;
  9. import com.qxgmat.data.constants.enums.ServiceKey;
  10. import com.qxgmat.data.constants.enums.module.CourseModule;
  11. import com.qxgmat.data.constants.enums.module.ProductType;
  12. import com.qxgmat.data.constants.enums.status.DirectionStatus;
  13. import com.qxgmat.data.dao.UserOrderCheckoutMapper;
  14. import com.qxgmat.data.dao.UserOrderRecordMapper;
  15. import com.qxgmat.data.dao.entity.UserOrder;
  16. import com.qxgmat.data.dao.entity.UserOrderCheckout;
  17. import com.qxgmat.data.dao.entity.UserOrderRecord;
  18. import org.slf4j.Logger;
  19. import org.slf4j.LoggerFactory;
  20. import org.springframework.stereotype.Service;
  21. import javax.annotation.Resource;
  22. import java.util.Collection;
  23. import java.util.Date;
  24. import java.util.List;
  25. @Service
  26. public class UserOrderCheckoutService extends AbstractService {
  27. private static final Logger logger = LoggerFactory.getLogger(UserOrderCheckoutService.class);
  28. @Resource
  29. private UserOrderCheckoutMapper userOrderCheckoutMapper;
  30. public List<UserOrderCheckout> allByUser(Integer userId, Integer orderId){
  31. Example example = new Example(UserOrderCheckout.class);
  32. example.and(
  33. example.createCriteria()
  34. .andEqualTo("userId", userId)
  35. .andEqualTo("orderId", orderId)
  36. );
  37. return select(userOrderCheckoutMapper, example);
  38. }
  39. /**
  40. * 列出对应类型的购物信息
  41. * @param userId
  42. * @param productType
  43. * @param productIds
  44. * @return
  45. */
  46. public List<UserOrderCheckout> listWithProduct(Integer userId, ProductType productType, Collection productIds){
  47. Example example = new Example(UserOrderCheckout.class);
  48. example.and(
  49. example.createCriteria()
  50. .andEqualTo("orderId", 0)
  51. .andEqualTo("userId", userId)
  52. .andEqualTo("productType", productType.key)
  53. .andIn("productId", productIds)
  54. );
  55. return select(userOrderCheckoutMapper, example);
  56. }
  57. public UserOrderCheckout getWithProduct(Integer userId, ProductType productType, Integer productId){
  58. Example example = new Example(UserOrderCheckout.class);
  59. example.and(
  60. example.createCriteria()
  61. .andEqualTo("orderId", 0)
  62. .andEqualTo("userId", userId)
  63. .andEqualTo("productType", productType.key)
  64. .andEqualTo("productId", productId)
  65. );
  66. return one(userOrderCheckoutMapper, example);
  67. }
  68. public boolean changeByUser(Integer userId, Integer orderId, UserOrderCheckout checkout){
  69. Example example = new Example(UserOrderCheckout.class);
  70. example.and(
  71. example.createCriteria()
  72. .andEqualTo("userId", userId)
  73. .andEqualTo("orderId", orderId)
  74. );
  75. return update(userOrderCheckoutMapper, example, checkout) > 0;
  76. }
  77. public boolean deleteByUser(Integer userId, Integer orderId){
  78. Example example = new Example(UserOrderCheckout.class);
  79. example.and(
  80. example.createCriteria()
  81. .andEqualTo("userId", userId)
  82. .andEqualTo("orderId", orderId)
  83. );
  84. return delete(userOrderCheckoutMapper, example) > 0;
  85. }
  86. public UserOrderCheckout add(UserOrderCheckout record){
  87. int result = insert(userOrderCheckoutMapper, record);
  88. record = one(userOrderCheckoutMapper, record.getId());
  89. if(record == null){
  90. throw new SystemException("服务记录添加失败");
  91. }
  92. return record;
  93. }
  94. public UserOrderCheckout edit(UserOrderCheckout service){
  95. UserOrderCheckout in = one(userOrderCheckoutMapper, service.getId());
  96. if(in == null){
  97. throw new ParameterException("服务记录不存在");
  98. }
  99. int result = update(userOrderCheckoutMapper, service);
  100. return service;
  101. }
  102. public boolean delete(Number id){
  103. UserOrderCheckout in = one(userOrderCheckoutMapper, id);
  104. if(in == null){
  105. throw new ParameterException("服务记录不存在");
  106. }
  107. int result = delete(userOrderCheckoutMapper, id);
  108. return result > 0;
  109. }
  110. public UserOrderCheckout get(Number id){
  111. UserOrderCheckout in = one(userOrderCheckoutMapper, id);
  112. if(in == null){
  113. throw new ParameterException("服务记录不存在");
  114. }
  115. return in;
  116. }
  117. public Page<UserOrderCheckout> select(int page, int pageSize){
  118. return select(userOrderCheckoutMapper, page, pageSize);
  119. }
  120. public Page<UserOrderCheckout> select(Integer[] ids){
  121. return page(()->select(userOrderCheckoutMapper, ids), 1, ids.length);
  122. }
  123. public List<UserOrderCheckout> select(Collection ids){
  124. return select(userOrderCheckoutMapper, ids);
  125. }
  126. }