|  | @@ -1,21 +1,21 @@
 | 
	
		
			
				|  |  |  package com.yonge.cooleshow.biz.dal.service.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.core.metadata.IPage;
 | 
	
		
			
				|  |  | +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dao.MemberPriceSettingsDao;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dto.search.VipRecordSearch;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.entity.ActivityReward;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.entity.MemberPriceSettings;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.entity.Student;
 | 
	
		
			
				|  |  | -import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
 | 
	
		
			
				|  |  | -import com.yonge.cooleshow.biz.dal.enums.MessageTypeEnum;
 | 
	
		
			
				|  |  | -import com.yonge.cooleshow.biz.dal.enums.PeriodEnum;
 | 
	
		
			
				|  |  | -import com.yonge.cooleshow.biz.dal.enums.SourceTypeEnum;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.enums.*;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.service.*;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.vo.*;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.wrapper.VipCardRecordWrapper;
 | 
	
		
			
				|  |  |  import com.yonge.toolset.base.page.PageInfo;
 | 
	
		
			
				|  |  |  import com.yonge.toolset.mybatis.support.PageUtil;
 | 
	
		
			
				|  |  |  import com.yonge.toolset.thirdparty.message.MessageSenderPluginContext;
 | 
	
		
			
				|  |  | +import com.yonge.toolset.utils.date.DateUtil;
 | 
	
		
			
				|  |  |  import org.slf4j.Logger;
 | 
	
		
			
				|  |  |  import org.slf4j.LoggerFactory;
 | 
	
		
			
				|  |  |  import org.springframework.beans.BeanUtils;
 | 
	
	
		
			
				|  | @@ -27,6 +27,7 @@ import com.yonge.cooleshow.biz.dal.dao.VipCardRecordDao;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import java.util.*;
 | 
	
		
			
				|  |  |  import java.util.concurrent.CompletableFuture;
 | 
	
		
			
				|  |  | +import java.util.stream.Collectors;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  @Service
 | 
	
	
		
			
				|  | @@ -228,6 +229,79 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 获取生效中的会员记录
 | 
	
		
			
				|  |  | +     * @param userId
 | 
	
		
			
				|  |  | +     * @param clientEnum
 | 
	
		
			
				|  |  | +     * @return
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public List<VipCardRecord> getEfficientVipRecord(Long userId, ClientEnum clientEnum) {
 | 
	
		
			
				|  |  | +        return this.lambdaQuery()
 | 
	
		
			
				|  |  | +            .eq(VipCardRecord::getUserId, userId)
 | 
	
		
			
				|  |  | +            .eq(VipCardRecord::getEfficientFlag, true)
 | 
	
		
			
				|  |  | +            .eq(VipCardRecord::getClientType, clientEnum.name())
 | 
	
		
			
				|  |  | +            .and(wrapper -> wrapper
 | 
	
		
			
				|  |  | +                .gt(VipCardRecord::getEndTime, new Date())
 | 
	
		
			
				|  |  | +                .or()
 | 
	
		
			
				|  |  | +                .isNull(VipCardRecord::getEndTime)
 | 
	
		
			
				|  |  | +            )
 | 
	
		
			
				|  |  | +            .list();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 用户会员信息
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @param userId
 | 
	
		
			
				|  |  | +     * @param clientEnum
 | 
	
		
			
				|  |  | +     * @return
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public VipCardRecordWrapper.UserVip UserVipInfo (Long userId, ClientEnum clientEnum) {
 | 
	
		
			
				|  |  | +        // 获取生效中的会员记录
 | 
	
		
			
				|  |  | +        VipCardRecordWrapper.UserVip userVip = new VipCardRecordWrapper.UserVip();
 | 
	
		
			
				|  |  | +        List<VipCardRecord> vipCardRecords = this.getEfficientVipRecord(userId,clientEnum);
 | 
	
		
			
				|  |  | +        if (CollectionUtils.isEmpty(vipCardRecords)) {
 | 
	
		
			
				|  |  | +            userVip.setVipType(EVipType.NOT_VIP);
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            // 存在没有结束时间的SVIP记录 永久SVIP
 | 
	
		
			
				|  |  | +            List<VipCardRecord> svipList = vipCardRecords.stream().filter(o -> o.getVipType() == EVipType.SVIP).collect(Collectors.toList());
 | 
	
		
			
				|  |  | +            if (CollectionUtils.isNotEmpty(svipList)) {
 | 
	
		
			
				|  |  | +                userVip.setVipType(EVipType.SVIP);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                Optional<VipCardRecord> first = svipList.stream().filter(o -> o.getEndTime() == null).findFirst();
 | 
	
		
			
				|  |  | +                if (first.isPresent()) {
 | 
	
		
			
				|  |  | +                    userVip.setVipType(EVipType.PERMANENT_SVIP);
 | 
	
		
			
				|  |  | +                } else {
 | 
	
		
			
				|  |  | +                    Optional<VipCardRecord> max = svipList.stream().max(Comparator.comparing(VipCardRecord::getEndTime));
 | 
	
		
			
				|  |  | +                    max.ifPresent(vipCardRecord -> userVip.setSvipEndDate(vipCardRecord.getEndTime()));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            // 过滤出VIP数据
 | 
	
		
			
				|  |  | +            List<VipCardRecord> vipList = vipCardRecords.stream().filter(o -> o.getVipType() == EVipType.VIP).collect(Collectors.toList());
 | 
	
		
			
				|  |  | +            if (CollectionUtils.isNotEmpty(vipList)) {
 | 
	
		
			
				|  |  | +                if (userVip.getVipType() == null) {
 | 
	
		
			
				|  |  | +                    userVip.setVipType(EVipType.VIP);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                Optional<VipCardRecord> max = vipList.stream().max(Comparator.comparing(VipCardRecord::getEndTime));
 | 
	
		
			
				|  |  | +                max.ifPresent(vipCardRecord -> userVip.setVipEndDate(vipCardRecord.getEndTime()));
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 设置剩余天数
 | 
	
		
			
				|  |  | +        if (userVip.getVipEndDate() != null) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            int num = DateUtil.daysBetween(new Date(), userVip.getVipEndDate());
 | 
	
		
			
				|  |  | +            userVip.setVipEndDays(Math.max(num, 0));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (userVip.getSvipEndDate() != null) {
 | 
	
		
			
				|  |  | +            int num = DateUtil.daysBetween(new Date(), userVip.getSvipEndDate());
 | 
	
		
			
				|  |  | +            userVip.setSvipEndDays(Math.max(num, 0));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return userVip;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      // 发送会员到期3天消息推送
 | 
	
		
			
				|  |  |      private void temporary3DaysSend(Long userId, String phone, ClientEnum clientType) {
 | 
	
		
			
				|  |  |          Map<Long, String> receivers = new HashMap<>();
 |