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.api.FireCheckRecordServiceI;
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 com.zcloud.fire.check.domain.model.FireCheckRecordE;
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 FireCheckRecordPlanDayJob implements Job {

     @Autowired
     private FireCheckListServiceI fireCheckListServiceI;

    @Override
    @JobRegister(cron = "0 10 0 * * ?", jobDesc = "每半年超期未检查记录",triggerStatus = 1)
    @XxlJob("com.zcloud.fire.check.plan.FireCheckRecordPlanDayJob")
    public ReturnT<String> execute(String param) {

        System.out.println("开始执行计划任务");
        XxlJobHelper.log( "============每日超期消息提醒(消防点检)==========");
        log.info( "============每日超期消息提醒(消防点检)==========开始");
        Map<String, Object> params =new HashMap<>();
        FireCheckListE fireCheckListE = new FireCheckListE();
        DateTimeE checkRecordInterval = fireCheckListE.getCheckRecordInterval(LocalDateTime.now().minusDays(1));
        params.put("startDate", checkRecordInterval.getDayStartTime());
        params.put("endDate", checkRecordInterval.getDayEndTime());
        params.put("checkType", ListManagerCheckPeriodEnum.DAILY.getCode());
        fireCheckListServiceI.overTimeRecord(params);
        log.info( "============每日超期消息提醒(消防点检)==========结束");
        return ReturnT.SUCCESS;
    }
}
