package com.zcloud.util;

import com.zcloud.entity.PageData;
import com.zcloud.service.bus.CorpTimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
@Component
public class OverCorpScheduled {

    @Autowired
    private CorpTimeService corpTimeService;


    @Scheduled(cron ="0 30 0 * * ?")//每天12点30
//     @Scheduled(cron ="0/30 * * * * ?")//测试
    public void scheduled(){
        try {
            System.out.println("============定时修改企业试用期情况==========");
            PageData pd = new PageData();
            List<PageData> corpList = corpTimeService.getInTimeList(pd);
            // 将所有有效期都改为0
            corpTimeService.editOutPeriod(pd);
            if(corpList != null && corpList.size() > 0){
                // 将在期限内的有效期改为1
                for(PageData corp : corpList){
                    corpTimeService.editInPeriod(corp);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
