package com.yunzhi.marketing.job;

import com.yunzhi.marketing.base.BaseController;
import com.yunzhi.marketing.common.DateUtils;
import com.yunzhi.marketing.drainage.service.ITaDrainageService;
import com.yunzhi.marketing.service.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @author admin
 * @Title: JudglActivityTimeJob
 * @Description: TODO
 * @date 2019/10/21
 */
@Component
@Configuration
@EnableScheduling
public class JudglActivityTimeJob extends BaseController {

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

    @Autowired
    private ITaBuildingDynamicService iTaBuildingDynamicService;

    @Autowired
    private ITaShareActivityService iTaShareActivityService;

    @Autowired
    private IHelpActivityService iHelpActivityService;

    @Autowired
    private ITaShareRecordService iTaShareRecordService;

    @Autowired
    private ITaShareChildRecordService iTaShareChildRecordService;

    @Autowired
    private IHelpInitiateRecordService iHelpInitiateRecordService;

    @Autowired
    private IHelpRecordService iHelpRecordService;

    @Autowired
    private ITaDrainageService iTaDrainageService;

    /**
     * 开启定时任务，每天12：30执行
     */
    @Scheduled(cron = "0 0/1 * * * ?")
    private void configureTasks() {
        String time = DateUtils.cutSecond(LocalDateTime.now());

        //判断活动是否开始
        iTaBuildingDynamicService.updateActivityToUnStart(time);
        //未开始活动更新为已开始
        iTaBuildingDynamicService.updateUnStartActivity(time);
        //进行中活动更新为已结束
        iTaBuildingDynamicService.updateProcessingActivity();

//        //判断拼团活动是否开始
//        iTaShareActivityService.updateActivityToUnStart();
//        //未开始拼团活动更新为已开始
//        iTaShareActivityService.updateUnStartGroupActivity();
//        //进行中拼团活动更新为已结束
//        iTaShareActivityService.updateProcessingGroupActivity();
//
//        //更新拼团者和参团者数据为已结束
//        iTaShareRecordService.updateActivityProcessToEnd();
//        iTaShareChildRecordService.updateActivityProcessToEnd();
//
//        //判断助力活动是否开始
//        iHelpActivityService.updateActivityToUnStart();
//        //未开始助力活动更新为已开始
//        iHelpActivityService.updateUnStartHelpActivity();
//        //进行中助力活动更新为已结束
//        iHelpActivityService.updateProcessingHelpActivity();
//
//        //更新助力者和发起者数据为已结束
//        iHelpInitiateRecordService.updateHelpActivityProcessToEnd();
//
//        //更新H5活动状态为已结束
//        iTaDrainageService.updateDrainageToEnd();
    }

}