package com.zfire.jiasm.syncdata.download.basedata;

import lombok.extern.slf4j.Slf4j;

/** 线程太多，合并线程
 * 格力品牌广佛网点维修工基础资料下载（销售与售后网点维修工）
 * 1: 落下载表 存在修改不存在新增
 * 新增或修改生成 worker:师傅信息表，
 * 商户网点与平台网点存在对应关系时 同步师傅数据到网点表 websit_worker:网点师傅信息表， worker_brand_account：师傅网点对应品牌网点信息表
 */
@Slf4j
// @Component
public class GLPPGFWebsitWorkerbak {
    /*
    @Value("${baseurl}")
    private String baseurl = "";
    @Value("${fsxwxgc}")
    private String fsxwxgc = "";
    @Value("${gzxwxgc}")
    private String gzxwxgc = "";
    @Value("${fsswxgc}")
    private String fsswxgc = "";
    @Value("${gzswxgc}")
    private String gzswxgc = "";
    @Value("${gfwwwc}")
    private String gfwwwc = "";



    @Resource
    TokenCenter tokenCenter;
    @Resource
    GLPPGFWebsitWorkerService glppgfWebsitWorkerService;

    // X2300000 佛山销售网点维修工基础资料下载
    @Scheduled(fixedDelayString = "${fsxwxg}")
    public void processFSXSWDTask() throws Exception {
        if (fsxwxgc.equals(TaskConfigEnum.FALSE.getCode())){
            return;
        }

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Map<String, String> paramMap = new HashMap<String, String>();

        log.info("开始下载佛山销售网点维修工基础资料信息: \uF0B7{}",sdf.format(new Date()));

        Token token = tokenCenter.getCurrentToken();
        String url = baseurl + InterFaceTypeEnum.GLXSSH_WEBSIT_WORK.getCode() + "/querylist";
        paramMap.put("belongCompany", InterFaceTypeEnum.FSXS_WEBSIT_CODE.getCode());
        String paramJson= JSON.toJSONString(paramMap);

        JSONResult jsonResult = HttpUtil.httpRequestWithToken(url, "POST", paramJson, token);
        if (jsonResult.getStatus() == null || !jsonResult.getStatus().toString().equals("200")) {
            log.info("下载佛山销售网点维修工基础资料信息失败！: {}",jsonResult.getMessage());
            return;
        }

        JSONArray jsonArray = (JSONArray) jsonResult.getData();
        if (jsonArray != null) {
            log.info("佛山销售网点维修工下载了{}条数据",jsonArray.size());

            glppgfWebsitWorkerService.extractedFSXS(jsonArray);

            log.info("佛山销售网点维修工基础资料信息处理完成: \uF0B7{}",sdf.format(new Date()));
        }else {
            log.info("["+url+"]无数据");
        }
    }

    // X2100000 广州销售网点维修工基础资料下载
    @Scheduled(fixedDelayString = "${gzxwxg}")
    public void processGZXSWDTask() throws Exception {
        if (gzxwxgc.equals(TaskConfigEnum.FALSE.getCode())){
            return;
        }

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Map<String, String> paramMap = new HashMap<String, String>();

        log.info("开始下载广州销售网点维修工基础资料信息: \uF0B7{}",sdf.format(new Date()));

        Token token = tokenCenter.getCurrentToken();
        String url = baseurl + InterFaceTypeEnum.GLXSSH_WEBSIT_WORK.getCode() + "/querylist";
        paramMap.put("belongCompany", InterFaceTypeEnum.GZXS_WEBSIT_CODE.getCode());
        String paramJson= JSON.toJSONString(paramMap);

        JSONResult jsonResult = HttpUtil.httpRequestWithToken(url, "POST", paramJson, token);
        if (jsonResult.getStatus() == null || !jsonResult.getStatus().toString().equals("200")) {
            log.info("下载广州销售网点维修工基础资料信息失败！: {}",jsonResult.getMessage());
            return;
        }
        JSONArray jsonArray = (JSONArray) jsonResult.getData();

        if (jsonArray != null) {
            log.info("广州销售网点维修工下载了{}条数据",jsonArray.size());

            glppgfWebsitWorkerService.extractedGZXS(jsonArray);

            log.info("广州销售网点维修工基础资料信息处理完成: \uF0B7{}",sdf.format(new Date()));
        }else {
            log.info("["+url+"]无数据");
        }
    }

    // S9219807 佛山售后网点维修工基础资料下载
    @Scheduled(fixedDelayString = "${fsswxg}")
    public void processFSSHWDTask() throws Exception {
        if (fsswxgc.equals(TaskConfigEnum.FALSE.getCode())){
            return;
        }

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Map<String, String> paramMap = new HashMap<String, String>();

        log.info("开始下载佛山售后网点维修工基础资料信息: \uF0B7{}",sdf.format(new Date()));

        Token token = tokenCenter.getCurrentToken();
        String url = baseurl + InterFaceTypeEnum.GLXSSH_WEBSIT_WORK.getCode() + "/querylist";
        paramMap.put("belongCompany", InterFaceTypeEnum.FSSH_WEBSIT_CODE.getCode());
        String paramJson= JSON.toJSONString(paramMap);

        JSONResult jsonResult = HttpUtil.httpRequestWithToken(url, "POST", paramJson, token);
        if (jsonResult.getStatus() == null || !jsonResult.getStatus().toString().equals("200")) {
            log.info("下载佛山售后网点维修工基础资料信息失败！: {}",jsonResult.getMessage());
            return;
        }
        JSONArray jsonArray = (JSONArray) jsonResult.getData();

        if (jsonArray != null) {
            log.info("佛山售后网点维修工下载了{}条数据",jsonArray.size());

            glppgfWebsitWorkerService.extractedFSSH(jsonArray);

            log.info("佛山售后网点维修工基础资料信息处理完成: \uF0B7{}",sdf.format(new Date()));
        }else {
            log.info("["+url+"]无数据");
        }
    }

    // S9219801 广州售后网点维修工基础资料下载
    @Scheduled(fixedDelayString = "${gzswxg}")
    public void processGZSHWDTask() throws Exception {
        if (gzswxgc.equals(TaskConfigEnum.FALSE.getCode())){
            return;
        }

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Map<String, String> paramMap = new HashMap<String, String>();

        log.info("开始下载广州售后网点维修工基础资料信息: \uF0B7{}",sdf.format(new Date()));

        Token token = tokenCenter.getCurrentToken();
        String url = baseurl + InterFaceTypeEnum.GLXSSH_WEBSIT_WORK.getCode() + "/querylist";
        paramMap.put("belongCompany", InterFaceTypeEnum.GSSH_WEBSIT_CODE.getCode());
        String paramJson= JSON.toJSONString(paramMap);

        JSONResult jsonResult = HttpUtil.httpRequestWithToken(url, "POST", paramJson, token);
        if (jsonResult.getStatus() == null || !jsonResult.getStatus().toString().equals("200")) {
            log.info("下载广州售后网点维修工基础资料信息失败！: {}",jsonResult.getMessage());
            return;
        }
        JSONArray jsonArray = (JSONArray) jsonResult.getData();

        if (jsonArray != null) {
            log.info("广州售后网点维修工下载了{}条数据",jsonArray.size());

            glppgfWebsitWorkerService.extractedGZSH(jsonArray);

            log.info("广州售后网点维修工基础资料信息处理完成: \uF0B7{}",sdf.format(new Date()));
        }else {
            log.info("["+url+"]无数据");
        }
    }


    // 数据同步到本地表(worker:师傅信息表 + worker_brand_account：师傅网点对应品牌网点信息表 + websit_worker:网点师傅信息表)
    // 师傅信息一定新增
    // 品牌网点与平台网点有对应关系才会同步生成相应的网点数据
    @Scheduled(fixedDelayString = "${gfwww}")
    private void process() {
        if (gfwwwc.equals(TaskConfigEnum.FALSE.getCode())){
            return;
        }

        glppgfWebsitWorkerService.inputData();
    }*/


}
