GroupRelationFrontServiceImpl.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. package com.cyksj.service.relation.impl;
  2. import cn.hutool.core.date.DateTime;
  3. import cn.hutool.core.date.DateUtil;
  4. import cn.hutool.core.util.StrUtil;
  5. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  6. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  7. import com.cyksj.common.exception.BusinessRuntimeException;
  8. import com.cyksj.enums.GatewayApiCode;
  9. import com.cyksj.mapper.GroupsRelationMapper;
  10. import com.cyksj.mapper.UserMapper;
  11. import com.cyksj.mapper.corp.CorpUserMapper;
  12. import com.cyksj.mapper.market.task.UserBindDetailMapper;
  13. import com.cyksj.model.entity.*;
  14. import com.cyksj.model.views.GoodsDonViews;
  15. import com.cyksj.model.views.RenewalView;
  16. import com.cyksj.service.mange.coupon.CouponCommonService;
  17. import com.cyksj.service.relation.GroupRelationFrontService;
  18. import com.ejlchina.searcher.BeanSearcher;
  19. import com.ejlchina.searcher.param.Operator;
  20. import com.ejlchina.searcher.util.MapUtils;
  21. import lombok.RequiredArgsConstructor;
  22. import lombok.extern.slf4j.Slf4j;
  23. import org.springframework.stereotype.Service;
  24. import java.util.ArrayList;
  25. import java.util.List;
  26. import java.util.stream.Collectors;
  27. /*
  28. *项目名: netflix
  29. *文件名: GroupRelationFrontServiceImpl
  30. *创建者: JavaZou
  31. *创建时间:2022/12/29 15:42
  32. */
  33. @Service
  34. @RequiredArgsConstructor
  35. @Slf4j
  36. public class GroupRelationFrontServiceImpl implements GroupRelationFrontService {
  37. private final UserBindDetailMapper UserBindDetailMapper;
  38. private final UserMapper userMapper;
  39. private final BeanSearcher beanSearcher;
  40. private final CorpUserMapper corpUserMapper;
  41. private final CouponCommonService couponCommonService;
  42. private final GroupsRelationMapper groupsRelationMapper;
  43. @Override
  44. public List<RenewalView> getMyTicket(long userId, Boolean isLoginPopularize) {
  45. User u = userMapper.selectById(userId);
  46. if (u == null) throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
  47. Boolean isPcUser = false;
  48. if (StrUtil.isNotBlank(u.getLoginPhone())) {
  49. isPcUser = true;
  50. }
  51. if (u.getIsBlack()) {
  52. return new ArrayList<>();
  53. }
  54. //是否绑定过手机号
  55. LambdaQueryWrapper<UserBindDetail> wrapper = Wrappers.lambdaQuery(UserBindDetail.class).last("limit 1");
  56. if (isPcUser) {
  57. wrapper.eq(UserBindDetail::getPhone, u.getLoginPhone());
  58. } else {
  59. wrapper.eq(UserBindDetail::getUserId, userId);
  60. }
  61. UserBindDetail userBindDetail = UserBindDetailMapper.selectOne(wrapper);
  62. Long otherUserId = 0l;
  63. if (userBindDetail != null) {
  64. if (isPcUser) {
  65. otherUserId = userBindDetail.getUserId();
  66. } else {
  67. if (StrUtil.isNotBlank(userBindDetail.getPhone())) {
  68. User user = userMapper.selectOne(Wrappers.lambdaQuery(User.class)
  69. .eq(User::getLoginPhone, userBindDetail.getPhone()).last("limit 1"));
  70. if (user != null) {
  71. if (user.getIsBlack()) {
  72. return new ArrayList<>();
  73. }
  74. otherUserId = user.getId();
  75. }
  76. }
  77. }
  78. }
  79. List<RenewalView> list = beanSearcher.searchAll(RenewalView.class, MapUtils.builder()
  80. .field(RenewalView::getUserId, 0).op(Operator.GreaterThan)
  81. .field(RenewalView::getUserId, userId, otherUserId).op(Operator.InList)
  82. .field(RenewalView::getStatus, List.of("validity", "overdue")).op(Operator.InList)
  83. .orderBy(RenewalView::getExpiryTime).asc()
  84. .build());
  85. //过滤邀请制、已失效的车位
  86. DateTime now = DateTime.now();
  87. List<RenewalView> collect = list.stream().filter(ticket -> {
  88. if (ticket.getExpiryTime() != null && ticket.getExpiryTime().before(now)) {
  89. return false;
  90. }
  91. if (ticket.getSecondType() == 1) {
  92. ticket.setAccount(null);
  93. ticket.setPassword(null);
  94. }
  95. if (isLoginPopularize != null && isLoginPopularize) {
  96. GoodsDonViews views = beanSearcher.searchFirst(GoodsDonViews.class, MapUtils.builder().field(GoodsDonViews::getId, ticket.getGoodsId()).build());
  97. views.setSpecs(beanSearcher.searchFirst(GoodsDonSpec.class, MapUtils.builder().field(GoodsDonSpec::getGoodsId, views.getId()).build()));
  98. views.setSkuList(beanSearcher.searchAll(GoodsDonSku.class, MapUtils.builder().field(GoodsDonSku::getGoodsId, views.getId()).field(GoodsDonSku::getStatus, true).build()));
  99. ticket.setGoodsDonViews(views);
  100. }
  101. return true;
  102. }).collect(Collectors.toList());
  103. return collect;
  104. }
  105. @Override
  106. public Boolean isJoinCorpWx(Long userId, Boolean isJoin, Boolean noCoupon) {
  107. if (!isJoin) {
  108. User user = userMapper.selectById(userId);
  109. if (user == null || StrUtil.isEmpty(user.getUnionid())) {
  110. return true;
  111. }
  112. CorpUser corpUser = corpUserMapper.selectOne(Wrappers.lambdaQuery(CorpUser.class)
  113. .ne(CorpUser::getUnionid, "")
  114. .eq(CorpUser::getUnionid, user.getUnionid())
  115. .last("limit 1")
  116. .select(CorpUser::getId)
  117. );
  118. if (corpUser == null) {
  119. return false;
  120. }
  121. }
  122. //用户是否买了奈飞车票
  123. Number number = beanSearcher.searchCount(RenewalView.class, MapUtils.builder()
  124. .field(RenewalView::getUserId, userId)
  125. .field(RenewalView::getGoodsId, 1)
  126. .field(RenewalView::getStatus, List.of("validity", "overdue")).op(Operator.InList)
  127. .build());
  128. if (number.intValue() > 0 && !noCoupon) {
  129. couponCommonService.sendCouponToUser(userId, 34l, 0l, 0l, 0l, CouponUser.Channel.wxCorp);
  130. }
  131. return true;
  132. }
  133. @Override
  134. public GroupsRelation getSimilarExpiredGroupRelation(Long skuId, Integer months, List<Long> errorsRelationIds) {
  135. DateTime expiryTime = DateUtil.offsetMonth(DateTime.now(), months);
  136. DateTime minExpiryTime = DateUtil.offsetDay(expiryTime, -5);
  137. Long groupsId = groupsRelationMapper.selectSimilarExpiredRelation(skuId, minExpiryTime);
  138. if (groupsId == null) {
  139. log.info("暂无相似过期时间车队");
  140. return null;
  141. }
  142. GroupsRelation relation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
  143. .notIn(errorsRelationIds != null && errorsRelationIds.size() > 0, GroupsRelation::getId, errorsRelationIds)
  144. .eq(GroupsRelation::getGroupsId, groupsId)
  145. .eq(GroupsRelation::getStatus, GroupsRelation.Status.none)
  146. .eq(GroupsRelation::getUserId, 0)
  147. .orderByAsc(GroupsRelation::getNum)
  148. .last("limit 1"));
  149. if (relation != null) {
  150. log.info("用户userId:{},获取相似车队的车位relationId:{}", relation.getId());
  151. }
  152. return relation;
  153. }
  154. }