GroupRelationFrontServiceImpl.java 6.6 KB

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