package com.cool.store.job;

import com.cool.store.service.EnterpriseSyncService;
import com.cool.store.service.HyPartnerInterviewPlanService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author zhangchenbiao
 * @FileName: JobHandler
 * @Description:
 * @date 2023-06-14 16:07
 */
@Slf4j
@Service
public class JobHandler {

    @Resource
    private EnterpriseSyncService enterpriseSyncService;

    @Autowired
    private HyPartnerInterviewPlanService hyPartnerInterviewPlanService;

    @XxlJob("syncOrganization")
    public void syncOrganization(){
        log.info("组织架构定时同步开始");
        enterpriseSyncService.syncAll();
        log.info("组织架构同步结束");
        XxlJobHelper.handleSuccess();
    }

    /**
     * 更新面试预约超时状态
     */
    @XxlJob("updateInterviewOverTime")
    public void updateInterviewOverTime(){
        try {
            log.info("面试超时预约定时任务开始");
            hyPartnerInterviewPlanService.updateInterviewOverTime();
            log.info("面试超时预约定时任务结束");
            XxlJobHelper.handleSuccess();
        }catch (Exception e){
            log.error("面试超时定时任务异常",e);
            XxlJobHelper.log("面试超时定时任务异常"+e.getMessage());
        }
    }

    @XxlJob("openInterviewRoom")
    public void openInterviewRoom(){
        try {
            log.info("房间状态开启定时任务开始");
            hyPartnerInterviewPlanService.openInterviewRoom();
            log.info("房间状态开启定时任务结束");
            XxlJobHelper.handleSuccess();
        }catch (Exception e){
            log.error("房间状态开启定时任务异常",e);
            XxlJobHelper.log("房间状态开启定时任务异常"+e.getMessage());
        }
    }

    @XxlJob("approvalReminder")
    public void approvalReminder(){
        try {
            log.info("审批即将超时提醒开始");
            hyPartnerInterviewPlanService.approvalReminder();
            log.info("审批即将超时提醒结束");
            XxlJobHelper.handleSuccess();
        }catch (Exception e){
            log.error("审批即将超时提醒定时任务异常",e);
            XxlJobHelper.log("审批即将超时提醒定时任务异常"+e.getMessage());
        }
    }

}
