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

import lombok.extern.slf4j.Slf4j;

/** 线程太多合到到一个线程中处理
 * 格力品牌广佛网点基础资料下载(销售与售后)
 */
@Slf4j
// @Component
public class GLPPGFWebsitBak {
    /*
    @Value("${baseurl}")
    private String baseurl = "";
    @Value("${netfsxc}")
    private String netfsxc = "";
    @Value("${netgzsc}")
    private String netgzsc = "";
    @Value("${netgzxc}")
    private String netgzxc = "";
    @Value("${netfssc}")
    private String netfssc = "";

    @Resource
    TokenCenter tokenCenter;
    @Resource
    GLPPGFWebsitService glppgfWebsitService;
    @Resource
    BrandService brandService;


    // X2300000 佛山销售网点基础资料下载
    @Scheduled(fixedDelayString = "${netfsx}")
    public void processFSXSWDTask() throws Exception {
        if (netfsxc.equals(TaskConfigEnum.FALSE.getCode())){
            return;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Map<String, String> paramMap = new HashMap<String, String>();

        // 提取品牌信息
        Brand record = brandService.lambdaQuery().eq(Brand::getBrand,"格力").one();
        if (record == null){
            log.info("格力品牌信息不存在【brand】");
            return;
        }

        String synTaskNo = UUID.randomUUID().toString();


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

        Token token = tokenCenter.getCurrentToken();
        String url = baseurl + InterFaceTypeEnum.GLXSSH_WEBSIT.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());

            glppgfWebsitService.extractedFSXS(jsonArray, record, synTaskNo);

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

    // X2100000 广州销售网点基础资料下载
    @Scheduled(fixedDelayString = "${netgzx}")
    public void processGZXSWDTask() throws Exception {


        if (netgzxc.equals(TaskConfigEnum.FALSE.getCode())){
            return;
        }

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

        // 提取品牌信息
        Brand record = brandService.lambdaQuery().eq(Brand::getBrand,"格力").one();
        if (record == null){
            log.info("格力品牌信息不存在【brand】");
            return;
        }

        String synTaskNo = UUID.randomUUID().toString();

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

        Token token = tokenCenter.getCurrentToken();
        String url = baseurl + InterFaceTypeEnum.GLXSSH_WEBSIT.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());

            glppgfWebsitService.extractedGZXS(jsonArray, record, synTaskNo);

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

    // S9219807 佛山售后网点基础资料下载
    @Scheduled(fixedDelayString = "${netfss}")
    public void processFSSHWDTask() throws Exception {


        if (netfssc.equals(TaskConfigEnum.FALSE.getCode())){
            return;
        }

        // 提取品牌信息
        Brand record = brandService.lambdaQuery().eq(Brand::getBrand,"格力").one();
        if (record == null){
            log.info("格力品牌信息不存在【brand】");
            return;
        }

        String synTaskNo = UUID.randomUUID().toString();

        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.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());

            glppgfWebsitService.extractedFSSH(jsonArray, record, synTaskNo);

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


    // S9219801 广州售后网点基础资料下载
    @Scheduled(fixedDelayString = "${netgzs}")
    public void processGZSHWDTask() throws Exception {

        if (netgzsc.equals(TaskConfigEnum.FALSE.getCode())){
            return;
        }

        // 提取品牌信息
        Brand record = brandService.lambdaQuery().eq(Brand::getBrand,"格力").one();
        if (record == null){
            log.info("格力品牌信息不存在【brand】");
            return;
        }

        String synTaskNo = UUID.randomUUID().toString();

        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.getCode() + "/querylist";
        paramMap.put("belongCompany",InterFaceTypeEnum.GSSH_WEBSIT_CODE.getCode());
        String paramJson= JSON.toJSONString(paramMap);

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

        if (!StringUtils.isEmpty(jsonArray)) {
            log.info("广州售后网点下载了{}条数据",jsonArray.size());

            glppgfWebsitService.extractedGZSH(jsonArray, record, synTaskNo);

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

}
