package com.huiju.estateagents.job;

import com.huiju.estateagents.base.BaseController;
import com.huiju.estateagents.service.ITaPersonFromRecordService;
import com.huiju.estateagents.statistic.service.ITsCustomerGenderStatisticService;
import com.huiju.estateagents.statistic.service.ITsCustomerStatisticDailyService;
import com.huiju.estateagents.statistic.service.ITsCustomerStatisticMonthlyService;
import com.huiju.estateagents.statistic.service.ITsUserBehaviorStatisticService;
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 fxf
 * @Title: CustomerStatisticTimeJob
 * @Description: 盘客数据分析统计
 * @date 2019/11/08
 */
@Component
@Configuration
@EnableScheduling
public class CustomerStatisticTimeJob extends BaseController {

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

    @Autowired
    private ITsCustomerStatisticDailyService customerStatisticDailyService;
    
    @Autowired
    private ITsCustomerGenderStatisticService taCustomerGenderStatisticService;
    
    @Autowired
    private ITsCustomerStatisticMonthlyService customerStatisticMonthlyService;

    @Autowired
    public ITaPersonFromRecordService iTaPersonFromRecordService;

    @Autowired
    private ITsUserBehaviorStatisticService iTsUserBehaviorStatisticService;

    /**
     *
     * 盘客工具数据统计
     *
     * 开启定时任务，每天23:50执行
     */
    @Scheduled(cron = "59 50 23 * * ?")
//    @Scheduled(cron = "* 0/1 * * * ?")
    private void configureTasks() {
        LocalDateTime nowDate = LocalDateTime.now();

        //每天的新增客户统计并入表
        customerStatisticDailyService.newCustomerStatisticDaily(nowDate);

        //每天的跟进客户统计并入表
        customerStatisticDailyService.followUpStatisticDaily(nowDate);

        //每天的到访客户统计并入表
        customerStatisticDailyService.visiteStatisticDaily(nowDate);

        //每天的新增客户性别统计并入表
        taCustomerGenderStatisticService.newCustomerSexStatisticDaily(nowDate);

        //每天的跟进客户性别统计并入表
        taCustomerGenderStatisticService.followUpSexStatisticDaily(nowDate);

        //每天的到访客户性别统计并入表
        taCustomerGenderStatisticService.visiteSexStatisticDaily(nowDate);

        //每月的新增客户统计并入表,但是每天都更新
        customerStatisticMonthlyService.newCustomerStatisticMonthly(nowDate);

        //每月的跟进客户统计并入表,但是每天都更新
        customerStatisticMonthlyService.followUpStatisticMonthly(nowDate);

        //每月的到访客户统计并入表,但是每天都更新
        customerStatisticMonthlyService.visiteStatisticMonthly(nowDate);

        //统计新增来源用户
        iTaPersonFromRecordService.personFromStatistic();

        //统计用户行为数据
        iTsUserBehaviorStatisticService.userBehaviorStatustic();
    }

}