package com.zcloud.fire.check.plan;

import com.jjb.saas.framework.job.Job;
import com.jjb.saas.framework.job.annotation.JobRegister;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.zcloud.fire.check.api.FireCheckListServiceI;
import com.zcloud.fire.check.domain.enums.ListManagerCheckPeriodEnum;
import com.zcloud.fire.check.domain.model.DateTimeE;
import com.zcloud.fire.check.domain.model.FireCheckListE;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

@RequiredArgsConstructor
@Component
@Slf4j
public class FireCheckRecordPlanQuarterlyJob implements Job {

    @Autowired
    private FireCheckListServiceI fireCheckListServiceI;

    @Override
    @JobRegister(cron = "0 5 0 1 1,4,7,10 ?", jobDesc = "每季度超期未检查记录",triggerStatus = 1)
    @XxlJob("com.zcloud.fire.check.plan.CheckRecordPlanQuarterlyJob")
    public ReturnT<String> execute(String param) {
        XxlJobHelper.log( "============开始定时每季度超期未检查记录==========");
        Map<String, Object> params =new HashMap<>();
        FireCheckListE fireCheckListE = new FireCheckListE();
        DateTimeE checkRecordInterval = fireCheckListE.getCheckRecordInterval(LocalDateTime.now().minusDays(1));
        params.put("startDate", checkRecordInterval.getQuarterlyStartTime());
        params.put("endDate", checkRecordInterval.getQuarterlyEndTime());
        params.put("checkType", ListManagerCheckPeriodEnum.QUARTERLY.getCode());
        fireCheckListServiceI.overTimeRecord(params);
        XxlJobHelper.log( "============结束定时每季度超期未检查记录==========");
        return ReturnT.SUCCESS;
    }
}
