package com.zfire.jiasm.syncdata.service.impl;

import com.zfire.jiasm.syncdata.constant.TaskConfigEnum;
import com.zfire.jiasm.syncdata.service.UploadWorkeCertificateService;
import com.zfire.jiasm.syncdata.service.UploadWorkerTOGreeService;
import com.zfire.jiasm.syncdata.service.WorkerUploadService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

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

@Slf4j
@Service
public class WorkerUploadServiceImpl implements WorkerUploadService {
    @Value("${workercertificatec}")
    private String workercertificatec = "";
    @Value("${workerceruploadc}")
    private String workerceruploadc = "";

    @Autowired
    UploadWorkeCertificateService uploadWorkeCertificateService;


    @Autowired
    UploadWorkerTOGreeService uploadWorkerTOGreeService;


    // 这里已不再使用
    @Override
    public void syncData() throws Exception {

        processUploadTask();

        uploadWorkProcess();

    }






    // 师傅证件照同步到格力总部
    public void processUploadTask(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (workercertificatec.equals(TaskConfigEnum.FALSE.getCode())){
            return;
        }

        log.info("开始同步师傅证件信息: \uF0B7{}",sdf.format(new Date()));

        uploadWorkeCertificateService.procesUploadWorkeCert();

        log.info("同步师傅证件信息结束: \uF0B7{}",sdf.format(new Date()));
    }


    /** 同步师傅信息到格力总部
     * 无论新增或是修改-所有证件都必须重新上传一次
     * 师傅所在网点都要上传一次
     * @throws Exception
     */
    public void uploadWorkProcess() 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;
    }





}
