package com.zfire.jiasm.syncdata.upload.worker;

import com.zfire.jiasm.syncdata.constant.TaskConfigEnum;
import com.zfire.jiasm.syncdata.service.UploadWorkerTOGreeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**  这里用于新建或是更新时与总部进行证件同步 更新过后就不再对本地网点证件表写数据   所以不能做为师傅入驻使用
 *   差内容（师傅入驻新网点时这些证件需提前准备好）根据师傅入驻的网点看网点表内有无对应的证件，无时取证件同步并写入表
 *
 * 同步师傅信息到格力总部 (这里所有的证件所有网点都上传一次，证件从各网点表中取) 证件需要在各网点中准备好
 *     UploadWorkBx 与 UploadWorkeCertificate 已完成并同步到总部与写入了本地表
 *
 *
 * .eq(OutWorkerUpload::getSyncStatus,0)
 * .or(wrapper->wrapper.eq(OutWorkerUpload::getSyncStatus,99)
 * .le(OutWorkerUpload::getSyncTimes,10));
 *
 * 网点证件表提取证件信息 同步成功后修改 out_worker_upload.sync_status
 */
@Slf4j
@Component
public class UploadWorkerTOGree {
    @Value("${workerceruploadc}")
    private String workerceruploadc = "";
    @Value("${workerrzc}")
    private String workerrzc = "";
    @Value("${inbeforec}")
    private String inbeforec = "";

    @Autowired
    UploadWorkerTOGreeService uploadWorkerTOGreeService;



    /** 更新师傅证件信息到格力总部 - 更新所有证件(这里只做更新同步，取证件照路径)
     * 无论新增或是修改-所有证件都必须重新上传一次
     * 师傅所在网点都要上传一次
     */
    @Scheduled(fixedDelayString = "${workercerupload}")
    public void workUpdateProcess() throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (workerceruploadc.equals(TaskConfigEnum.FALSE.getCode())){
            return;
        }

        log.info("开始更新师傅证件信息到格力总部: \uF0B7{}",sdf.format(new Date()));

        uploadWorkerTOGreeService.procesUpdateWorker();

        log.info("更新师傅证件信息到格力总部完成: \uF0B7{}",sdf.format(new Date()));
        return;
    }

    // 师傅入驻格力新网点前 同步证件数据(保险 + 其他证件照 + 人脸面像)  已同步过无需再同步证件
    @Scheduled(fixedDelayString = "${inbefore}")
    public void workAddCertProcess() throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (inbeforec.equals(TaskConfigEnum.FALSE.getCode())){
            return;
        }

        log.info("开始新增师傅入驻新网点证件信息到格力总部: \uF0B7{}",sdf.format(new Date()));

        uploadWorkerTOGreeService.procesAddCertWorker();

        log.info("同步新增师傅入驻新网点证件信息到格力总部完成: \uF0B7{}",sdf.format(new Date()));
        return;
    }


    // 师傅入驻格力新网点
    @Scheduled(fixedDelayString = "${workerrz}")
    public void workAddProcess() throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (workerrzc.equals(TaskConfigEnum.FALSE.getCode())){
            return;
        }

        log.info("开始新增师傅入驻新网点信息到格力总部: \uF0B7{}",sdf.format(new Date()));

        uploadWorkerTOGreeService.procesAddWorker();

        log.info("同步新增师傅入驻新网点信息到格力总部完成: \uF0B7{}",sdf.format(new Date()));
        return;
    }



}
