package com.sv.api.task;


import com.enums.VipTypeEnum;
import com.sv.entity.MemberCard;
import com.sv.service.api.MemberCardService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Controller - 修改用户会员卡
 *
 * @author lihong
 * @since 2018-08-25
 */
@Component
public class MemberCardUpdate {

    private final Logger logger = LoggerFactory.getLogger(MemberCardUpdate.class);

    @Resource
    private MemberCardService memberCardService;


    @Scheduled(cron = "0 0 0 * * ?")
    @Transactional
    public void execute(){
        // 查询用户已过期的会员卡
        List<MemberCard> cards = memberCardService.findAllCard();
        // 查询出用户顺延的会员卡，正好是今日
        List<MemberCard> memberCards = memberCardService.findAllMemberCard(cards);

        //修改过期的会员卡为未激活
        memberCardService.updateStatus(cards,0);

        //修改用户默认会员卡
       for (MemberCard memberCard : memberCards){
            MemberCard lists =  memberCardService.findMemberCardByVenue(memberCard.getMemberId(),memberCard.getVenueId(),memberCard.getVeneuType());
            lists.setStatus(1);
            memberCardService.update(lists);
        }
    }
}
