package cn.com.ty.lift.batch.applet.util;

import cn.com.ty.lift.batch.applet.constants.DataStatisticsConstants;
import cn.com.ty.lift.batch.applet.dao.model.request.CommonRequest;
import cn.com.ty.lift.batch.applet.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author huangyuan
 * @date 2020/2/10
 * @description 数据初始化工具
 */
@Component
@Slf4j
public class DataInitUtil {

    @Resource
    private MaintenanceDataService maintenanceDataService;

    @Resource
    private EmergencyRepairDataService emergencyRepairDataService;

    @Resource
    private PaymentDataService paymentDataService;

    @Resource
    private LiftDataService liftDataService;

    @Resource
    private ContractDataService contractDataService;

    @Resource
    private AnnualInspectionDataService annualInspectionDataService;

    /**
     * @param
     * @return
     * @description 小程序初始化放入缓存中
     * @date 2020/2/10 11:55 上午
     */
    public void initAppletData() {
        //除维保以外其他统计类数据获取数据时间段: 3年前 - 当前时间
        CommonRequest otherCommonRequest = DataStatisticsUtil.initCommonRequest(-3L,
                DataStatisticsConstants.INTERVAL_TYPE_YEAR);
        //初始化急修数据
        emergencyRepairDataService.putEmergencyRepairDataListToRedis(otherCommonRequest);
        log.info("初始化急修数据成功");
        //初始化收款数据
        paymentDataService.putPaymentDataToRedis(otherCommonRequest);
        log.info("初始化收款数据成功");
        //初始化电梯数据
        liftDataService.putLiftDataListToRedis(otherCommonRequest);
        log.info("初始化电梯数据成功");
        //初始化合同数据
        contractDataService.putContractDataToRedis(otherCommonRequest);
        log.info("初始化合同数据成功");
        //初始化年检数据
        annualInspectionDataService.putAnnualInspectionDataToRedis(otherCommonRequest);
        log.info("初始化年检数据成功");
        //维保数据获取数据的时间段: 1年前 - 当前时间
        //测试数据 3个月前 - 当前时间
        CommonRequest maintenanceCommonRequest = DataStatisticsUtil.initCommonRequest(-30L,
                DataStatisticsConstants.INTERVAL_TYPE_DAY);
        maintenanceDataService.putMaintenanceDataListToRedis(maintenanceCommonRequest);
        log.info("初始化维保数据成功");
    }

}