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

import lombok.extern.slf4j.Slf4j;


/**
 * 省、市、区、镇、数据同步
 */
@Slf4j
// @Component
public class ProvinceCityAreaTown {
 /*   @Value("${baseurl}")
    private String baseurl = "";
    @Value("${sxc}")
    private String sxc = "";
    @Value("${ssxc}")
    private String ssxc = "";
    @Value("${qxc}")
    private String qxc = "";
    @Value("${zxc}")
    private String zxc = "";

    @Resource
    TokenCenter tokenCenter;
    @Resource
    ProvinceCityAreaTownService provinceCityAreaTownService;
    @Resource
    CityService cityService;
    @Resource
    ProvinceService provinceService;



    *//**
     * 省份基础资料信息同步
     * @return
     *//*
    @Scheduled(fixedDelayString = "${sx}")
    public void process() throws Exception {
        if (sxc.equals(TaskConfigEnum.FALSE.getCode())){
            return;
        }

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

        req.add(InterFaceTypeEnum.TBL_PROVINCE.getCode());
        req.add(InterFaceTypeEnum.TBL_CITY.getCode());
        req.add(InterFaceTypeEnum.TBL_COUNTY.getCode());
        req.add(InterFaceTypeEnum.TBL_CITY_JDXZ.getCode());

        log.info("开始下载地理位置基础资料信息: \uF0B7{}",sdf.format(new Date()));

        Token token = tokenCenter.getCurrentToken();
        for (String bc :req){
            try {

                if (bc.equals(InterFaceTypeEnum.TBL_CITY.getCode())){
                    // 提取省份信息
                    List<Province> provinceRec =  provinceService.lambdaQuery().list();
                    // 省份信息未同步时先不同步
                    if (CollectionUtils.isEmpty(provinceRec)){
                        provinceRec.clear();
                        continue;
                    }
                }

                if (bc.equals(InterFaceTypeEnum.TBL_COUNTY.getCode()) ||
                        bc.equals(InterFaceTypeEnum.TBL_CITY_JDXZ.getCode()) ){
                    // 提取市信息
                    List<City> cityRec =  cityService.lambdaQuery().list();
                    // 市信息未同步时先不同步
                    if (CollectionUtils.isEmpty(cityRec)){
                        cityRec.clear();
                        continue;
                    }
                }

                String url = baseurl + bc + "/querylist";
                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());
                    continue;
                }

                JSONArray jsonArray = (JSONArray) jsonResult.getData();
                if (jsonArray != null) {
                    log.info("下载了{}条数据",jsonArray.size());

                    if (bc.equals(InterFaceTypeEnum.TBL_PROVINCE.getCode())){
                        provinceCityAreaTownService.extractedProvince(jsonArray);
                    } else if (bc.equals(InterFaceTypeEnum.TBL_CITY.getCode())){
                        provinceCityAreaTownService.extractedCity(jsonArray);
                    } else if (bc.equals(InterFaceTypeEnum.TBL_COUNTY.getCode())){
                        provinceCityAreaTownService.extractedCounty(jsonArray);
                    } else if (bc.equals(InterFaceTypeEnum.TBL_CITY_JDXZ.getCode())){
                        provinceCityAreaTownService.extractedStreet(jsonArray);
                    }
                    jsonArray.clear();
                }else {
                    log.info("["+url+"]无数据");
                }
            } catch (Exception ex) {
                log.info("地理位置基础资料信息处理失败");
                ex.printStackTrace();
            }
        }

        log.info("地理位置基础资料信息处理完成: \uF0B7{}",sdf.format(new Date()));
    }*/

}
