package com.zcloud.personnel.positioning.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.personnel.positioning.command.AlarmRecordFindsPullService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class FindsAlarmIncrementalSyncJob implements Job {
    private final AlarmRecordFindsPullService alarmRecordFindsPullService;

    @Override
    @JobRegister(cron = "0 */2 * * * ?", jobDesc = "FindS告警增量拉取", author = "申智丹", triggerStatus = 1)
    @XxlJob("com.zcloud.personnel.positioning.plan.FindsAlarmIncrementalSyncJob")
    public ReturnT<String> execute(String param) {
        try {
            int pulledCount = alarmRecordFindsPullService.syncIncremental();
            String message = "FindS告警增量拉取完成，本次处理 " + pulledCount + " 条";
            XxlJobHelper.log(message);
            return new ReturnT<>(ReturnT.SUCCESS_CODE, message);
        } catch (Exception e) {
            XxlJobHelper.log("FindS告警增量拉取失败: " + e.getMessage());
            return new ReturnT<>(ReturnT.FAIL_CODE, e.getMessage());
        }
    }
}
