GroupRelationFrontServiceImpl.java 7.4 KB

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