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.query.OrgMatchSyncService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class OrgMatchSyncJob implements Job {
    private final OrgMatchSyncService orgMatchSyncService;

    @Override
    @JobRegister(cron = "0 */10 * * * ?", jobDesc = "FindS组织架构映射同步", author = "系统", triggerStatus = 1)
    @XxlJob("com.zcloud.personnel.positioning.plan.OrgMatchSyncJob")
    public ReturnT<String> execute(String param) {
        try {
            int total = orgMatchSyncService.syncAll();
            String message = "FindS组织架构映射同步完成，组织快照总数=" + total;
            XxlJobHelper.log(message);
            return new ReturnT<>(ReturnT.SUCCESS_CODE, message);
        } catch (Exception e) {
            String message = "FindS组织架构映射同步失败：" + e.getMessage();
            XxlJobHelper.log(message);
            return new ReturnT<>(ReturnT.FAIL_CODE, message);
        }
    }
}
