NanoServiceImpl.java 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package com.cyksj.service.nano.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.date.DateTime;
  4. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  5. import com.cyksj.common.constant.Constant;
  6. import com.cyksj.mapper.GroupsMapper;
  7. import com.cyksj.mapper.GroupsRelationMapper;
  8. import com.cyksj.mapper.NanoUserQuotaMapper;
  9. import com.cyksj.mapper.vip.VipUserMapper;
  10. import com.cyksj.model.entity.GroupsRelation;
  11. import com.cyksj.model.entity.GroupsTrips;
  12. import com.cyksj.model.entity.NanoUserQuota;
  13. import com.cyksj.model.entity.VipUser;
  14. import com.cyksj.model.manage.views.GroupsRelationView;
  15. import com.cyksj.model.views.NanoUserQuotaInfoView;
  16. import com.cyksj.service.nano.NanoService;
  17. import com.cyksj.service.user.UserBindRelationService;
  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 org.springframework.stereotype.Service;
  23. import java.util.List;
  24. /**
  25. * Nano服务实现
  26. */
  27. @Service
  28. @RequiredArgsConstructor
  29. public class NanoServiceImpl implements NanoService {
  30. private final UserBindRelationService userBindRelationService;
  31. private final NanoUserQuotaMapper nanoUserQuotaMapper;
  32. private final GroupsRelationMapper groupsRelationMapper;
  33. private final GroupsMapper groupsMapper;
  34. private final VipUserMapper vipUserMapper;
  35. private final BeanSearcher beanSearcher;
  36. @Override
  37. public NanoUserQuotaInfoView getUserSubsInfo(long userId) {
  38. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  39. VipUser vipUser = vipUserMapper.selectOne(Wrappers.lambdaQuery(VipUser.class).in(VipUser::getUserId, userIdList).gt(VipUser::getExpiryTime, DateTime.now()));
  40. Boolean isVip = vipUser != null;
  41. NanoUserQuota nanoUserQuota = null;
  42. if (isVip) {
  43. GroupsRelationView groupsRelationView = beanSearcher.searchFirst(GroupsRelationView.class, MapUtils.builder()
  44. .field(GroupsRelationView::getIsVip, Boolean.TRUE)
  45. .field(GroupsRelationView::getUserId, userIdList).op(Operator.InList)
  46. .field(GroupsRelationView::getGoodsId, Constant.NANO_GOODS_ID)
  47. .build());
  48. if (groupsRelationView != null) {
  49. nanoUserQuota = nanoUserQuotaMapper.selectOne(Wrappers.lambdaQuery(NanoUserQuota.class).eq(NanoUserQuota::getRelationId, groupsRelationView.getId()).last("limit 1"));
  50. }
  51. }
  52. if (nanoUserQuota == null) {
  53. nanoUserQuota = nanoUserQuotaMapper.selectOne(Wrappers.lambdaQuery(NanoUserQuota.class).in(NanoUserQuota::getUid, userIdList).orderByDesc(NanoUserQuota::getTotalQuota).orderByDesc(NanoUserQuota::getRemainingQuota).last("limit 1"));
  54. }
  55. if (nanoUserQuota != null) {
  56. NanoUserQuotaInfoView nanoUserQuotaInfoView = new NanoUserQuotaInfoView();
  57. nanoUserQuotaInfoView.setIsVip(vipUser != null);
  58. GroupsRelation relation = groupsRelationMapper.selectById(nanoUserQuota.getRelationId());
  59. GroupsTrips groupsTrips = groupsMapper.selectById(relation.getGroupsId());
  60. BeanUtil.copyProperties(nanoUserQuota, nanoUserQuotaInfoView);
  61. nanoUserQuotaInfoView.setSkuId(groupsTrips.getSkuId());
  62. return nanoUserQuotaInfoView;
  63. }
  64. return null;
  65. }
  66. @Override
  67. public Long getUserTokenByNanoToken(String usertoken) {
  68. NanoUserQuota nanoUserQuota = nanoUserQuotaMapper.selectOne(Wrappers.lambdaQuery(NanoUserQuota.class).eq(NanoUserQuota::getUserToken, usertoken).last("limit 1"));
  69. if (nanoUserQuota != null) {
  70. return nanoUserQuota.getUid();
  71. }
  72. return null;
  73. }
  74. }