GroupRelationFrontServiceImpl.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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.toolkit.Wrappers;
  6. import com.cyksj.common.exception.BusinessRuntimeException;
  7. import com.cyksj.enums.GatewayApiCode;
  8. import com.cyksj.mapper.GroupsRelationMapper;
  9. import com.cyksj.mapper.UserMapper;
  10. import com.cyksj.mapper.corp.CorpUserMapper;
  11. import com.cyksj.model.entity.*;
  12. import com.cyksj.model.views.CorpUserFollowView;
  13. import com.cyksj.model.views.GoodsDonViews;
  14. import com.cyksj.model.views.RenewalView;
  15. import com.cyksj.service.mange.coupon.CouponCommonService;
  16. import com.cyksj.service.relation.GroupRelationFrontService;
  17. import com.cyksj.service.user.UserService;
  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 UserService userService;
  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. if (u.getIsBlack()) {
  48. return new ArrayList<>();
  49. }
  50. List<Long> userIds = userService.getRelationUserIdList(userId, u);
  51. List<RenewalView> list = beanSearcher.searchAll(RenewalView.class, MapUtils.builder()
  52. .field(RenewalView::getUserId, 0).op(Operator.GreaterThan)
  53. .field(RenewalView::getUserId, userIds).op(Operator.InList)
  54. .field(RenewalView::getStatus, List.of("validity", "overdue", "outside")).op(Operator.InList)
  55. .orderBy(RenewalView::getExpiryTime).asc()
  56. .build());
  57. //过滤邀请制、已失效的车位
  58. DateTime now = DateTime.now();
  59. List<RenewalView> collect = list.stream().filter(ticket -> {
  60. if (ticket.getExpiryTime() != null && ticket.getExpiryTime().before(now)) {
  61. return false;
  62. }
  63. if (ticket.getGoodsId() == 18 && ticket.getSkuNum() > 1) {
  64. ticket.setPassword(null);
  65. }
  66. if (ticket.getSecondType() == 1) {
  67. ticket.setAccount(null);
  68. ticket.setPassword(null);
  69. }
  70. if (isLoginPopularize != null && isLoginPopularize) {
  71. GoodsDonViews views = beanSearcher.searchFirst(GoodsDonViews.class, MapUtils.builder().field(GoodsDonViews::getId, ticket.getGoodsId()).build());
  72. views.setSpecs(beanSearcher.searchFirst(GoodsDonSpec.class, MapUtils.builder().field(GoodsDonSpec::getGoodsId, views.getId()).build()));
  73. views.setSkuList(beanSearcher.searchAll(GoodsDonSku.class, MapUtils.builder().field(GoodsDonSku::getGoodsId, views.getId()).field(GoodsDonSku::getStatus, true).build()));
  74. ticket.setGoodsDonViews(views);
  75. }
  76. return true;
  77. }).collect(Collectors.toList());
  78. return collect;
  79. }
  80. @Override
  81. public Boolean isJoinCorpWx(Long userId, Boolean isJoin, Boolean noCoupon) {
  82. if (!isJoin) {
  83. User user = userMapper.selectById(userId);
  84. if (user == null || StrUtil.isEmpty(user.getUnionid())) {
  85. return true;
  86. }
  87. // CorpUser corpUser = corpUserMapper.selectOne(Wrappers.lambdaQuery(CorpUser.class)
  88. // .ne(CorpUser::getUnionid, "")
  89. // .eq(CorpUser::getUnionid, user.getUnionid())
  90. // .last("limit 1")
  91. // .select(CorpUser::getId)
  92. // );
  93. CorpUserFollowView corpUserFollowView = beanSearcher.searchFirst(CorpUserFollowView.class, MapUtils.builder()
  94. .field(CorpUserFollowView::getUnionId, user.getUnionid())
  95. .field(CorpUserFollowView::getStatus, 1).build());
  96. if (corpUserFollowView == null) {
  97. return false;
  98. }
  99. }
  100. //用户是否买了奈飞车票
  101. Number number = beanSearcher.searchCount(RenewalView.class, MapUtils.builder()
  102. .field(RenewalView::getUserId, userId)
  103. .field(RenewalView::getGoodsId, 1)
  104. .field(RenewalView::getStatus, List.of("validity", "overdue")).op(Operator.InList)
  105. .build());
  106. if (number.intValue() > 0 && !noCoupon) {
  107. couponCommonService.sendCouponToUser(userId, 34l, 0l, 0l, 0l, CouponUser.Channel.wxCorp);
  108. }
  109. return true;
  110. }
  111. @Override
  112. public GroupsRelation getSimilarExpiredGroupRelation(Long skuId, Integer days, Integer months, List<Long> errorsRelationIds) {
  113. DateTime expiryTime = null;
  114. if (days != null && days > 0) {
  115. expiryTime = DateUtil.offsetDay(DateTime.now(), days);
  116. } else {
  117. expiryTime = DateUtil.offsetMonth(DateTime.now(), months);
  118. }
  119. DateTime minExpiryTime = DateUtil.offsetDay(expiryTime, -5);
  120. Long groupsId = groupsRelationMapper.selectSimilarExpiredRelation(skuId, minExpiryTime);
  121. if (groupsId == null) {
  122. log.info("暂无相似过期时间车队");
  123. return null;
  124. }
  125. GroupsRelation relation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
  126. .notIn(errorsRelationIds != null && errorsRelationIds.size() > 0, GroupsRelation::getId, errorsRelationIds)
  127. .eq(GroupsRelation::getGroupsId, groupsId)
  128. .eq(GroupsRelation::getStatus, GroupsRelation.Status.none)
  129. .eq(GroupsRelation::getUserId, 0)
  130. .orderByAsc(GroupsRelation::getNum)
  131. .last("limit 1"));
  132. if (relation != null) {
  133. log.info("用户userId:{},获取相似车队的车位relationId:{}", relation.getId());
  134. }
  135. return relation;
  136. }
  137. }