package com.bocloud.ims.service.resource.azure.prices;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bocloud.cmp.params.azure.AzureListPriceParams;
import com.bocloud.common.model.*;
import com.bocloud.common.utils.DateTools;
import com.bocloud.common.utils.ResultTools;
import com.bocloud.ims.entity.common.Dictionary;
import com.bocloud.ims.entity.resource.Flavor;
import com.bocloud.ims.entity.resource.azure.db.AzureDatabaseServer;
import com.bocloud.ims.entity.resource.azure.price.AzureResourcePrice;
import com.bocloud.ims.interfaces.resource.azure.prices.AzurePriceService;
import com.bocloud.ims.repository.resource.DictionaryRepository;
import com.bocloud.ims.repository.resource.FlavorRepository;
import com.bocloud.ims.repository.resource.azure.db.AzureResourcePriceRepository;
import com.bocloud.ims.service.resource.azure.utils.AzurePriceProviderUtils;
import com.bocloud.ims.service.utils.ExcelExporter;
import com.bocloud.service.lock.BocloudACLock;
import com.bocloud.service.lock.LockFactory;
import com.google.common.collect.Maps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * @Company: 博云 www.bocloud.com
 * @ClassName: AzurePriceServiceImpl
 * @Description:
 * @author: zhenpingLi/李振平
 * @date: 2021/1/6 15:14
 */
@Service("azurePriceService")
public class AzurePriceServiceImpl implements AzurePriceService {

    private static final Logger logger = LoggerFactory.getLogger(AzurePriceServiceImpl.class);
    @Autowired
    private AzurePriceProviderUtils priceProvider;
    @Autowired
    private FlavorRepository flavorRepository;
    @Autowired
    private AzureResourcePriceRepository azureResourcePriceRepository;
    @Autowired
    private LockFactory lockFactory;
    @Autowired
    private DictionaryRepository dictionaryRepository;

    @Override
    public BocloudResult<GridBean<AzureResourcePrice>> list(Pager pager, RequestContext context) {
        List<Param> params = Optional.ofNullable(pager.getParams()).orElse(new ArrayList<>());
        Map<String, String> sorter = Optional.ofNullable(pager.getSorter()).orElse(Maps.newHashMap());
        Boolean simple = Optional.ofNullable(pager.getSimple()).orElse(false);
        Integer page = Optional.ofNullable(pager.getPage()).orElse(1);
        Integer rows = Optional.ofNullable(pager.getRows()).orElse(10);
        try {
            GridBean<AzureResourcePrice> gridBean;
            int total = azureResourcePriceRepository.count(params);
            List<AzureResourcePrice> list = this.azureResourcePriceRepository.list(page, rows, params, sorter);
            for (AzureResourcePrice azureResourcePrice : list) {
                azureResourcePrice.setRegionName(this.getName(azureResourcePrice.getRegionId()));
            }
            gridBean = new GridBean<>(page, rows, total, list);
            return new BocloudResult<>(true, gridBean, "查询成功");
        } catch (Exception e) {
            logger.error("list resourcePrice error!", e);
            return new BocloudResult<>(false, "查询失败:" + e.getMessage());
        }

    }

    @Override
    public BocloudResult create(AzureResourcePrice entityParams, RequestContext context) {
        try {
            azureResourcePriceRepository.save(entityParams);
            return new BocloudResult(true, "创建成功");
        } catch (Exception e) {
            logger.error("create resourcePrice error!", e);
            return new BocloudResult(false, "创建失败:" + e.getMessage());
        }
    }

    @Override
    public BocloudResult remove(Long id, RequestContext context) {
        String path = AzureDatabaseServer.class.getSimpleName() + "_" + id;
        try (BocloudACLock lock = lockFactory.getACLock(path)) {
            Assert.isTrue(lock.acquire(10, TimeUnit.SECONDS), "请求超时");
            AzureResourcePrice entity = azureResourcePriceRepository.query(id);
            if (null == entity) {
                logger.error("The data doesn't exist");
                return new BocloudResult(false, "数据不存在");
            }
            azureResourcePriceRepository.delete(id);
            return new BocloudResult(true, "删除成功！");
        } catch (Exception e) {
            logger.error("remove resourcePrice error!", e);
            return new BocloudResult(false, "删除失败:" + e.getMessage());
        }
    }

    @Override
    public BocloudResult modify(AzureResourcePrice entityParams, RequestContext context) {
        try {
            BigDecimal unitPrice = entityParams.getUnitPrice();
            AzureResourcePrice resourcePrice = azureResourcePriceRepository.query(entityParams.getId());
            if (ObjectUtils.isEmpty(resourcePrice)) {
                return new BocloudResult(false, "数据不存在");
            }
            resourcePrice.setUnitPrice(unitPrice);
            azureResourcePriceRepository.update(resourcePrice);
            return new BocloudResult(true, "修改成功！");
        } catch (Exception e) {
            logger.error("modify resourcePrice error!", e);
            return new BocloudResult(false, "修改失败:" + e.getMessage());

        }
    }

    @Override
    public BocloudResult importCreate(List<AzureResourcePrice> prices) {
        try {
            int successNum = 0;
            int failureNum = 0;
            List<AzureResourcePrice> oldPrices = azureResourcePriceRepository.list();
            if (CollectionUtils.isEmpty(oldPrices)) {
                oldPrices = new ArrayList<>();
            }
            List<AzureResourcePrice> oldStorage = new ArrayList<>();
            List<AzureResourcePrice> oldEip = new ArrayList<>();
            for (AzureResourcePrice oldPrice : oldPrices) {
                if (oldPrice.getProductType().equalsIgnoreCase("STORAGE")) {
                    oldStorage.add(oldPrice);
                } else if (oldPrice.getProductType().equalsIgnoreCase("EIP")) {
                    oldEip.add(oldPrice);
                }
            }

            Map<String, AzureResourcePrice> oldStorageMap = new HashMap<>();
            for (AzureResourcePrice price : oldStorage) {
                oldStorageMap.put(price.getRegionId() + price.getResourceType() + price.getResourceSize(), price);
            }
            Map<String, AzureResourcePrice> oldEipMap = new HashMap<>();
            for (AzureResourcePrice price : oldEip) {
                oldEipMap.put(price.getRegionId() + price.getResourceType(), price);
            }
            for (AzureResourcePrice newPrice : prices) {
                AzureResourcePrice price = new AzureResourcePrice();
                if (newPrice.getProductType().equalsIgnoreCase("STORAGE")) {
                    if (oldStorageMap.containsKey(newPrice.getRegionId() + newPrice.getResourceType() + newPrice.getResourceSize())) {
                        price = oldStorageMap.get(newPrice.getRegionId() + newPrice.getResourceType() + newPrice.getResourceSize());
                        price.setUnitPrice(newPrice.getUnitPrice());
                        try {
                            azureResourcePriceRepository.update(price);
                            successNum++;
                        } catch (Exception e) {
                            failureNum++;
                        }
                    } else {
                        BeanUtils.copyProperties(newPrice, price);
                        try {
                            azureResourcePriceRepository.save(price);
                            successNum++;
                        } catch (Exception e) {
                            failureNum++;
                        }
                    }
                    oldStorageMap.remove(newPrice.getRegionId() + newPrice.getResourceType() + newPrice.getResourceSize());
                } else if (newPrice.getProductType().equalsIgnoreCase("EIP")) {
                    if (oldEipMap.containsKey(newPrice.getRegionId() + newPrice.getResourceType())) {
                        price = oldEipMap.get(newPrice.getRegionId() + newPrice.getResourceType());
                        price.setUnitPrice(newPrice.getUnitPrice());
                        try {
                            azureResourcePriceRepository.update(price);
                            successNum++;
                        } catch (Exception e) {
                            failureNum++;
                        }
                    } else {
                        BeanUtils.copyProperties(newPrice, price);
                        try {
                            successNum++;
                            azureResourcePriceRepository.save(price);
                        } catch (Exception e) {
                            failureNum++;
                        }
                    }
                    oldEipMap.remove(newPrice.getRegionId() + newPrice.getResourceType());
                }

            }
            //todo 先不删除多余数据
//            for (Map.Entry<String, AzureResourcePrice> entry : oldStorageMap.entrySet()) {
//                azureResourcePriceRepository.delete(entry.getValue().getId());
//            }
//            for (Map.Entry<String, AzureResourcePrice> entry : oldEipMap.entrySet()) {
//                azureResourcePriceRepository.delete(entry.getValue().getId());
//            }

            String message = new StringBuffer().append(" Excel总数据：")
                    .append(prices.size())
                    .append(" 导入成功数量:")
                    .append(successNum)
                    .append(" 导入失败数量:")
                    .append(failureNum).toString();

            Map<String, String> map = new HashMap<>();
            map.put("data", message);
            return new BocloudResult(true, map, message);
        } catch (Exception e) {
            logger.error("importCreate resourcePrice error!", e);
            return new BocloudResult(false, "导入失败:" + e.getMessage());
        }
    }

    @Override
    public BocloudResult batchRemove(String params, RequestContext context) {
        try {
            JSONObject object = JSONObject.parseObject(params);
            if (null == object) {
                return ResultTools.formatErrResult();
            }
            List<Long> ids = JSONArray.parseArray(object.getString("ids"), Long.class);
            for (Long id : ids) {
                azureResourcePriceRepository.delete(id);
            }
            return new BocloudResult(true, "批量删除成功");
        } catch (Exception e) {
            logger.error("batchRemove error:", e);
            return new BocloudResult(false, "批量删除失败");
        }
    }

    @Override
    public void downloadTemplate(HttpServletResponse response) {
        List<List<Object>> firstFewRows = new ArrayList<>();
        // excel标题行
        String[] headers = new String[]{"产品分类", "资源分类", "可用域", "单价", "名称", "容量", "计费周期"};
        String[] dataColumns = new String[]{"product_type", "resource_type", "region_id", "unit_price", "name", "resource_size", "period"};

        // 样例数据
        List<Map<String, Object>> allRows = new ArrayList<>();
        Map<String, Object> row;

        row = new HashMap<>(7);
        row.put(dataColumns[0], "STORAGE");
        row.put(dataColumns[1], "Standard_LRS");
        row.put(dataColumns[2], "eastus2");
        row.put(dataColumns[3], "0.0144657534");
        row.put(dataColumns[4], "S4");
        row.put(dataColumns[5], "32");
        row.put(dataColumns[6], "Hours");
        allRows.add(row);

        // 文件名
        String timeStr = DateTools.formatTime2String(new Date(), "yyyy-MM-dd-HH-mm-ss");
        String fileName = "price-template-" + timeStr + ".xls";

        String header = "attachment; filename=\"" + fileName + "\"";
        response.setContentType("application/octet-stream");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-Disposition", header);
        try {
            List<Dictionary> dictionaries = dictionaryRepository.listChildren("AZURE");
            String[] regions = new String[dictionaries.size()];
            for (int i = 0; i < dictionaries.size(); i++) {
                regions[i] = dictionaries.get(i).getValue();
            }
            OutputStream out = response.getOutputStream();
            ExcelExporter.azurePriceExport("Sheet", firstFewRows, headers, dataColumns, allRows, out, "yyyy-MM-dd HH:mm:ss", regions);
            out.flush();
            out.close();
            logger.info("模板下载成功！");
        } catch (Exception e) {
            logger.error("export excel file fails.", e);
        }
    }


    @Override
    public BocloudResult mysqlStorage(AzureListPriceParams params) {
        try {
            String dbFlavorUuid = params.getUuid();
            String regionId = params.getRegionId();
            String skuName;
            switch (dbFlavorUuid) {
                case "Basic":
                    skuName = "Basic";
                    break;
                case "GeneralPurpose":
                    skuName = "General Purpose";
                    break;
                case "MemoryOptimized":
                    skuName = "General Purpose";
                    break;
                default:
                    skuName = "General Purpose";
                    break;

            }
            String productName;
            switch (dbFlavorUuid) {
                case "Basic":
                    productName = "Azure Database for MySQL Single Server Basic - Storage";
                    break;
                case "GeneralPurpose":
                    productName = "Azure Database for MySQL Single Server General Purpose - Storage";
                    break;
                case "MemoryOptimized":
                    productName = "Azure Database for MySQL Single Server General Purpose - Storage";
                    break;
                default:
                    productName = "Azure Database for MySQL Single Server Basic - Storage";
                    break;

            }
            String api = "/api/retail/prices";
            String queryParams = new StringBuffer()
                    .append("serviceName eq 'Azure Database for MySQL'")
                    .append(" and priceType eq 'Consumption'")
                    .append(" and armRegionName eq ")
                    .append("'")
                    .append(regionId)
                    .append("'")
                    .append(" and skuName eq ")
                    .append("'")
                    .append(skuName)
                    .append("'")
                    .append(" and productName eq ")
                    .append("'")
                    .append(productName)
                    .append("'")
                    .append("  and unitOfMeasure eq '1 GB/Month' ")
                    .toString();
            JSONObject paramsJson = new JSONObject();
            paramsJson.put("$filter", queryParams);
            String response = priceProvider.request(AzurePriceProviderUtils.RequestStatus.GET, api, paramsJson.toJSONString());
            List<JSONObject> objects = Optional.ofNullable(JSONObject.parseObject(response))
                    .map(responseJson -> Optional.ofNullable(responseJson.getJSONArray("Items")).map(items -> items.stream()
                            .map(JSONArray::toJSONString)
                            .map(JSONObject::parseObject)
                            .collect(Collectors.toList())).orElse(new ArrayList<>())
                    ).orElse(new ArrayList<>());
            return new BocloudResult(true, objects, "查询成功");
        } catch (Exception e) {
            logger.error("Query error:", e);
            return new BocloudResult(false, "查询失败");
        }
    }

    @Override
    public BocloudResult mysqlVcore(AzureListPriceParams params) {
        try {
            String dbFlavorUuid = params.getUuid();
            String regionId = params.getRegionId();
            String skuName = params.getSkuName();

            String productName;
            switch (dbFlavorUuid) {
                case "Basic":
                    productName = " and productName eq  'Azure Database for MySQL Single Server Basic - Compute Gen5'";
                    break;
                case "GeneralPurpose":
                    productName = " and productName eq 'Azure Database for MySQL Single Server General Purpose - Compute Gen5'";
                    break;
                case "MemoryOptimized":
                    productName = " and productName eq 'Azure Database for MySQL Single Server Memory Optimized - Compute Gen5'";
                    break;
                default:
                    productName = " and productName eq  'Azure Database for MySQL Single Server Basic - Compute Gen5'";
                    break;

            }
            String api = "/api/retail/prices";
            String queryParams = new StringBuffer()
                    .append("serviceName eq 'Azure Database for MySQL'")
                    .append(" and priceType eq 'Consumption'")
                    .append(" and armRegionName eq ")
                    .append("'")
                    .append(regionId)
                    .append("'")
                    .append(" and skuName eq ")
                    .append("'")
                    .append(skuName)
                    .append("'")
                    .append(" and meterName eq 'vCore'")
                    .append(productName)
                    .toString();
            JSONObject paramsJson = new JSONObject();
            paramsJson.put("$filter", queryParams);
            String response = priceProvider.request(AzurePriceProviderUtils.RequestStatus.GET, api, paramsJson.toJSONString());
            List<JSONObject> objects = Optional.ofNullable(JSONObject.parseObject(response))
                    .map(responseJson -> Optional.ofNullable(responseJson.getJSONArray("Items")).map(items -> items.stream()
                            .map(JSONArray::toJSONString)
                            .map(JSONObject::parseObject)
                            .collect(Collectors.toList())).orElse(new ArrayList<>())
                    ).orElse(new ArrayList<>());
            return new BocloudResult(true, objects, "查询成功");
        } catch (Exception e) {
            logger.error("Query error:", e);
            return new BocloudResult(false, "查询失败");
        }
    }

    @Override
    public BocloudResult flavors(AzureListPriceParams params) {
        try {
            Long flavorId = params.getFlavorId();
            Flavor flavor = flavorRepository.query(flavorId);
            String osCategory = params.getOsCategory();
            if (ObjectUtils.isEmpty(flavor)) {
                return new BocloudResult(false, "规格找不到");
            }
            String armRegionName = flavor.getRegionId();
            String armSkuName = flavor.getName();

            String api = "/api/retail/prices";
            //eg:serviceName eq 'Virtual Machines' and armRegionName eq 'eastus2' and armSkuName eq 'Standard_B2s' and priceType eq 'Consumption' and skuName eq 'B2s'
            String queryParams = new StringBuffer()
                    .append("serviceName eq 'Virtual Machines'")
                    .append(" and priceType eq 'Consumption'")
                    .append(" and armRegionName eq ")
                    .append("'")
                    .append(armRegionName)
                    .append("'")
                    .append(" and armSkuName eq ")
                    .append("'")
                    .append(armSkuName)
                    .append("'")
                    .toString();
            JSONObject paramsJson = new JSONObject();
            paramsJson.put("$filter", queryParams);
            String response = priceProvider.request(AzurePriceProviderUtils.RequestStatus.GET, api, paramsJson.toJSONString());
            List<JSONObject> objects = Optional.ofNullable(JSONObject.parseObject(response))
                    .map(responseJson -> Optional.ofNullable(responseJson.getJSONArray("Items")).map(items -> items.stream()
                            .map(JSONArray::toJSONString)
                            .map(JSONObject::parseObject)
                            .collect(Collectors.toList())).orElse(new ArrayList<>())
                    ).orElse(new ArrayList<>());

            //数据二次处理
            List<JSONObject> newObject = new ArrayList<>();
            for (JSONObject jsonObject : objects) {
                if (jsonObject.getString("skuName").contains("Low") || jsonObject.getString("skuName").contains("Spot")) {
                    continue;
                }
                if (osCategory.equalsIgnoreCase("WINDOWS")) {
                    if (jsonObject.getString("productName").contains("Windows")) {
                        newObject.add(jsonObject);
                    }
                } else {
                    if (!jsonObject.getString("productName").contains("Windows")) {
                        newObject.add(jsonObject);
                    }
                }
            }
            return new BocloudResult(true, newObject, "查询成功");
        } catch (Exception e) {
            logger.error("Query error:", e);
            return new BocloudResult(false, "查询失败");
        }
    }

    @Override
    public BocloudResult volumes(AzureListPriceParams params) {
        try {
            Map<String, String> map = new HashMap<String, String>() {{
                //标准 HDD
                put("Standard_LRS", "Standard HDD Managed Disks");
                //标准 SSD
                put("StandardSSD_LRS", "Standard SSD Managed Disks");
                //高级 SSD
                put("Premium_LRS", "Premium SSD Managed Disks");
            }};
            String skuPattern = "^[PES]([0-9]|[0-9][0-9])\\sLRS";
            String meterPattern = "^[PES]([0-9]|[0-9][0-9])\\sDisks";
            Map<String, Integer> maps = new HashMap<String, Integer>() {{
                put("1", 4);
                put("2", 8);
                put("3", 16);
                put("4", 32);
                put("6", 64);
                put("10", 128);
                put("15", 256);
                put("20", 512);
                put("30", 1024);
                put("40", 2048);
                put("50", 4096);
                put("60", 8192);
                put("70", 16384);
                put("80", 32768);
            }};
            String category = params.getCategory();
            String regionId = params.getRegionId();
            String api = "/api/retail/prices";
            String queryParams = new StringBuffer()
                    .append("serviceName eq 'Storage'")
                    .append(" and priceType eq 'Consumption'")
                    .append(" and armRegionName eq ")
                    .append("'")
                    .append(regionId)
                    .append("'")
                    .append(" and productName eq ")
                    .append("'")
                    .append(map.get(category))
                    .append("'")
                    .append(" and isPrimaryMeterRegion eq true ")
                    .toString();
            JSONObject paramsJson = new JSONObject();
            paramsJson.put("$filter", queryParams);
            String response = priceProvider.request(AzurePriceProviderUtils.RequestStatus.GET, api, paramsJson.toJSONString());
            List<JSONObject> objects = Optional.ofNullable(JSONObject.parseObject(response))
                    .map(responseJson -> Optional.ofNullable(responseJson.getJSONArray("Items")).map(items -> items.stream()
                            .map(JSONArray::toJSONString)
                            .map(JSONObject::parseObject)
                            .collect(Collectors.toList())).orElse(new ArrayList<>())
                    ).orElse(new ArrayList<>());

            //数据过滤
            List<JSONObject> newObjects = new ArrayList<>();
            for (JSONObject jsonObject : objects) {
                boolean b = Pattern.matches(skuPattern, jsonObject.getString("skuName"));
                boolean m = Pattern.matches(meterPattern, jsonObject.getString("meterName"));
                if (b && m) {
                    jsonObject.put("size", this.getVolumeSize(jsonObject.getString("skuName"), maps));
                    newObjects.add(jsonObject);
                }
            }

            //数据排序
            for (int i = 0; i < newObjects.size(); i++) {
                for (int j = newObjects.size() - 1; j > i; j--) {
                    JSONObject objectI = newObjects.get(i);
                    JSONObject objectJ = newObjects.get(j);
                    Integer getI = objectI.getInteger("size");
                    Integer getJ = objectJ.getInteger("size");
                    if (getI > getJ) {
                        newObjects.set(i, objectJ);
                        newObjects.set(j, objectI);
                    }
                }
            }
            return new BocloudResult(true, newObjects, "查询成功");
        } catch (Exception e) {
            logger.error("Query error:", e);
            return new BocloudResult(false, "查询失败");
        }
    }

    @Override
    public BocloudResult eips(AzureListPriceParams params) {
        try {
            String category = params.getCategory();
            String regionId = params.getRegionId();
            String sku = params.getSku();

            Map<String, String> map = new HashMap<String, String>() {{
                //静态eip
                put("static", "Static Public IP");
                //动态eip
                put("dynamic", "Dynamic Public IP");
            }};

            String api = "/api/retail/prices";
            String queryParams = new StringBuffer()
                    .append("serviceName eq 'Virtual Network'")
                    .append(" and priceType eq 'Consumption'")
                    .append(" and armRegionName eq ")
                    .append("'")
                    .append(regionId)
                    .append("'")
                    .append(" and meterName eq ")
                    .append("'")
                    .append(map.get(category))
                    .append("'")
                    .append(" and skuName eq ")
                    .append("'")
                    .append(sku)
                    .append("'")
                    .toString();
            JSONObject paramsJson = new JSONObject();
            paramsJson.put("$filter", queryParams);
            String response = priceProvider.request(AzurePriceProviderUtils.RequestStatus.GET, api, paramsJson.toJSONString());
            List<JSONObject> objects = Optional.ofNullable(JSONObject.parseObject(response))
                    .map(responseJson -> Optional.ofNullable(responseJson.getJSONArray("Items")).map(items -> items.stream()
                            .map(JSONArray::toJSONString)
                            .map(JSONObject::parseObject)
                            .collect(Collectors.toList())).orElse(new ArrayList<>())
                    ).orElse(new ArrayList<>());
            return new BocloudResult(true, objects, "查询成功");
        } catch (Exception e) {
            logger.error("Query error:", e);
            return new BocloudResult(false, "查询失败");
        }
    }

    @Override
    public BocloudResult redis(AzureListPriceParams params) {
        try {
            String skuPattern = "^[CP]([0-9])";
            String meterPattern = "^[CP]([0-9])\\sCache";
            String regionId = params.getRegionId();
            String skuName = params.getSkuName();
            String productName = params.getProductName();
            String api = "/api/retail/prices";
            String queryParams = new StringBuffer()
                    .append("serviceName eq 'Redis Cache'")
                    .append(" and priceType eq 'Consumption'")
                    .append(" and armRegionName eq ")
                    .append("'")
                    .append(regionId)
                    .append("'")
                    .append(" and skuName eq ")
                    .append("'")
                    .append(skuName)
                    .append("'")
                    .append(" and productName eq ")
                    .append("'")
                    .append(productName)
                    .append("'")
                    .toString();
            JSONObject paramsJson = new JSONObject();
            paramsJson.put("$filter", queryParams);
            String response = priceProvider.request(AzurePriceProviderUtils.RequestStatus.GET, api, paramsJson.toJSONString());
            List<JSONObject> objects = Optional.ofNullable(JSONObject.parseObject(response))
                    .map(responseJson -> Optional.ofNullable(responseJson.getJSONArray("Items")).map(items -> items.stream()
                            .map(JSONArray::toJSONString)
                            .map(JSONObject::parseObject)
                            .collect(Collectors.toList())).orElse(new ArrayList<>())
                    ).orElse(new ArrayList<>());

            //数据过滤
            List<JSONObject> newObjects = new ArrayList<>();
            for (JSONObject jsonObject : objects) {
                boolean b = Pattern.matches(skuPattern, jsonObject.getString("skuName"));
                boolean m = Pattern.matches(meterPattern, jsonObject.getString("meterName"));
                if (b && m) {
                    newObjects.add(jsonObject);
                }
            }
            return new BocloudResult(true, newObjects, "查询成功");
        } catch (Exception e) {
            logger.error("Query error:", e);
            return new BocloudResult(false, "查询失败");
        }
    }

    private Integer getVolumeSize(String skuName, Map<String, Integer> maps) {
        String pattern = "[^0-9]";
        Pattern p = Pattern.compile(pattern);
        Matcher m = p.matcher(skuName);
        String trim = m.replaceAll("").trim();
        return maps.get(trim);
    }

    private String getName(String key) {
        String regionJsonValue = "[{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/eastusstg\",\"name\":\"eastusstg\",\"displayName\":\"East US STG\",\"regionalDisplayName\":\"(US) East US STG\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Recommended\",\"geographyGroup\":\"US\",\"longitude\":\"-79.8164\",\"latitude\":\"37.3719\",\"physicalLocation\":\"Virginia\",\"pairedRegion\":[{\"name\":\"southcentralusstg\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/southcentralusstg\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/southcentralusstg\",\"name\":\"southcentralusstg\",\"displayName\":\"South Central US STG\",\"regionalDisplayName\":\"(US) South Central US STG\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Recommended\",\"geographyGroup\":\"US\",\"longitude\":\"-98.5\",\"latitude\":\"29.4167\",\"physicalLocation\":\"Texas\",\"pairedRegion\":[{\"name\":\"eastusstg\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/eastusstg\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/eastus\",\"name\":\"eastus\",\"displayName\":\"美国东部\",\"regionalDisplayName\":\"(US) 美国东部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Recommended\",\"geographyGroup\":\"US\",\"longitude\":\"-79.8164\",\"latitude\":\"37.3719\",\"physicalLocation\":\"Virginia\",\"pairedRegion\":[{\"name\":\"westus\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/westus\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/eastus2\",\"name\":\"eastus2\",\"displayName\":\"美国东部2（弗吉尼亚州）\",\"regionalDisplayName\":\"(US) 美国东部 2\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Recommended\",\"geographyGroup\":\"US\",\"longitude\":\"-78.3889\",\"latitude\":\"36.6681\",\"physicalLocation\":\"Virginia\",\"pairedRegion\":[{\"name\":\"centralus\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/centralus\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/westus2\",\"name\":\"westus2\",\"displayName\":\"美国西部2（华盛顿州）\",\"regionalDisplayName\":\"(US) 美国西部 2\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Recommended\",\"geographyGroup\":\"US\",\"longitude\":\"-119.852\",\"latitude\":\"47.233\",\"physicalLocation\":\"Washington\",\"pairedRegion\":[{\"name\":\"westcentralus\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/westcentralus\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/southcentralus\",\"name\":\"southcentralus\",\"displayName\":\"美国中南部\",\"regionalDisplayName\":\"(US) 美国中南部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Recommended\",\"geographyGroup\":\"US\",\"longitude\":\"-98.5\",\"latitude\":\"29.4167\",\"physicalLocation\":\"Texas\",\"pairedRegion\":[{\"name\":\"northcentralus\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/northcentralus\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/australiaeast\",\"name\":\"australiaeast\",\"displayName\":\"澳大利亚东部\",\"regionalDisplayName\":\"(Asia Pacific) 澳大利亚东部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Recommended\",\"geographyGroup\":\"Asia Pacific\",\"longitude\":\"151.2094\",\"latitude\":\"-33.86\",\"physicalLocation\":\"New South Wales\",\"pairedRegion\":[{\"name\":\"australiasoutheast\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/australiasoutheast\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/southeastasia\",\"name\":\"southeastasia\",\"displayName\":\"东南亚（新加坡）\",\"regionalDisplayName\":\"(Asia Pacific) 东南亚\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Recommended\",\"geographyGroup\":\"Asia Pacific\",\"longitude\":\"103.833\",\"latitude\":\"1.283\",\"physicalLocation\":\"Singapore\",\"pairedRegion\":[{\"name\":\"eastasia\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/eastasia\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/northeurope\",\"name\":\"northeurope\",\"displayName\":\"北欧\",\"regionalDisplayName\":\"(Europe) 北欧\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Recommended\",\"geographyGroup\":\"Europe\",\"longitude\":\"-6.2597\",\"latitude\":\"53.3478\",\"physicalLocation\":\"Ireland\",\"pairedRegion\":[{\"name\":\"westeurope\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/westeurope\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/westeurope\",\"name\":\"westeurope\",\"displayName\":\"西欧（荷兰）\",\"regionalDisplayName\":\"(Europe) 西欧\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Recommended\",\"geographyGroup\":\"Europe\",\"longitude\":\"4.9\",\"latitude\":\"52.3667\",\"physicalLocation\":\"Netherlands\",\"pairedRegion\":[{\"name\":\"northeurope\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/northeurope\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/uksouth\",\"name\":\"uksouth\",\"displayName\":\"英国南部\",\"regionalDisplayName\":\"(Europe) 英国南部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Recommended\",\"geographyGroup\":\"Europe\",\"longitude\":\"-0.799\",\"latitude\":\"50.941\",\"physicalLocation\":\"London\",\"pairedRegion\":[{\"name\":\"ukwest\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/ukwest\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/westus\",\"name\":\"westus\",\"displayName\":\"美国西部\",\"regionalDisplayName\":\"(US) 美国西部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Recommended\",\"geographyGroup\":\"US\",\"longitude\":\"-122.417\",\"latitude\":\"37.783\",\"physicalLocation\":\"California\",\"pairedRegion\":[{\"name\":\"eastus\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/eastus\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/northcentralus\",\"name\":\"northcentralus\",\"displayName\":\"美国中北部\",\"regionalDisplayName\":\"(US) 美国中北部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Recommended\",\"geographyGroup\":\"US\",\"longitude\":\"-87.6278\",\"latitude\":\"41.8819\",\"physicalLocation\":\"Illinois\",\"pairedRegion\":[{\"name\":\"southcentralus\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/southcentralus\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/centralus\",\"name\":\"centralus\",\"displayName\":\"美国中部\",\"regionalDisplayName\":\"(US) 美国中部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Recommended\",\"geographyGroup\":\"US\",\"longitude\":\"-93.6208\",\"latitude\":\"41.5908\",\"physicalLocation\":\"Iowa\",\"pairedRegion\":[{\"name\":\"eastus2\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/eastus2\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/southafricanorth\",\"name\":\"southafricanorth\",\"displayName\":\"南非北部\",\"regionalDisplayName\":\"(Africa) 南非北部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Recommended\",\"geographyGroup\":\"Africa\",\"longitude\":\"28.218370\",\"latitude\":\"-25.731340\",\"physicalLocation\":\"Johannesburg\",\"pairedRegion\":[{\"name\":\"southafricawest\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/southafricawest\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/eastasia\",\"name\":\"eastasia\",\"displayName\":\"东亚\",\"regionalDisplayName\":\"(Asia Pacific) 东亚\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Recommended\",\"geographyGroup\":\"Asia Pacific\",\"longitude\":\"114.188\",\"latitude\":\"22.267\",\"physicalLocation\":\"Hong Kong\",\"pairedRegion\":[{\"name\":\"southeastasia\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/southeastasia\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/koreacentral\",\"name\":\"koreacentral\",\"displayName\":\"韩国中部（首尔）\",\"regionalDisplayName\":\"(Asia Pacific) 韩国中部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Recommended\",\"geographyGroup\":\"Asia Pacific\",\"longitude\":\"126.9780\",\"latitude\":\"37.5665\",\"physicalLocation\":\"Seoul\",\"pairedRegion\":[{\"name\":\"koreasouth\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/koreasouth\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/japaneast\",\"name\":\"japaneast\",\"displayName\":\"日本东部（东京）\",\"regionalDisplayName\":\"(Asia Pacific) 日本东部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Recommended\",\"geographyGroup\":\"Asia Pacific\",\"longitude\":\"139.77\",\"latitude\":\"35.68\",\"physicalLocation\":\"Tokyo, Saitama\",\"pairedRegion\":[{\"name\":\"japanwest\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/japanwest\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/centralindia\",\"name\":\"centralindia\",\"displayName\":\"印度中部（普纳）\",\"regionalDisplayName\":\"(Asia Pacific) 印度中部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Recommended\",\"geographyGroup\":\"Asia Pacific\",\"longitude\":\"73.9197\",\"latitude\":\"18.5822\",\"physicalLocation\":\"Pune\",\"pairedRegion\":[{\"name\":\"southindia\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/southindia\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/canadacentral\",\"name\":\"canadacentral\",\"displayName\":\"加拿大中部\",\"regionalDisplayName\":\"(Canada) 加拿大中部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Recommended\",\"geographyGroup\":\"Canada\",\"longitude\":\"-79.383\",\"latitude\":\"43.653\",\"physicalLocation\":\"Toronto\",\"pairedRegion\":[{\"name\":\"canadaeast\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/canadaeast\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/germanywestcentral\",\"name\":\"germanywestcentral\",\"displayName\":\"德国中西部（法兰克福）\",\"regionalDisplayName\":\"(Europe) 德国中西部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Recommended\",\"geographyGroup\":\"Europe\",\"longitude\":\"8.682127\",\"latitude\":\"50.110924\",\"physicalLocation\":\"Frankfurt\",\"pairedRegion\":[{\"name\":\"germanynorth\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/germanynorth\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/francecentral\",\"name\":\"francecentral\",\"displayName\":\"法国中部\",\"regionalDisplayName\":\"(Europe) 法国中部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Recommended\",\"geographyGroup\":\"Europe\",\"longitude\":\"2.3730\",\"latitude\":\"46.3772\",\"physicalLocation\":\"Paris\",\"pairedRegion\":[{\"name\":\"francesouth\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/francesouth\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/norwayeast\",\"name\":\"norwayeast\",\"displayName\":\"挪威东部\",\"regionalDisplayName\":\"(Europe) 挪威东部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Recommended\",\"geographyGroup\":\"Europe\",\"longitude\":\"10.752245\",\"latitude\":\"59.913868\",\"physicalLocation\":\"Norway\",\"pairedRegion\":[{\"name\":\"norwaywest\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/norwaywest\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/switzerlandnorth\",\"name\":\"switzerlandnorth\",\"displayName\":\"瑞士北部\",\"regionalDisplayName\":\"(Europe) 瑞士北部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Recommended\",\"geographyGroup\":\"Europe\",\"longitude\":\"8.564572\",\"latitude\":\"47.451542\",\"physicalLocation\":\"Zurich\",\"pairedRegion\":[{\"name\":\"switzerlandwest\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/switzerlandwest\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/uaenorth\",\"name\":\"uaenorth\",\"displayName\":\"阿联酋北部（迪拜）\",\"regionalDisplayName\":\"(Middle East) 阿联酋北部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Recommended\",\"geographyGroup\":\"Middle East\",\"longitude\":\"55.316666\",\"latitude\":\"25.266666\",\"physicalLocation\":\"Dubai\",\"pairedRegion\":[{\"name\":\"uaecentral\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/uaecentral\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/brazilsouth\",\"name\":\"brazilsouth\",\"displayName\":\"巴西南部（圣保罗）\",\"regionalDisplayName\":\"(South America) 巴西南部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Recommended\",\"geographyGroup\":\"South America\",\"longitude\":\"-46.633\",\"latitude\":\"-23.55\",\"physicalLocation\":\"Sao Paulo State\",\"pairedRegion\":[{\"name\":\"southcentralus\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/southcentralus\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/eastus2stage\",\"name\":\"eastus2stage\",\"displayName\":\"美国东部 2 (阶段)\",\"regionalDisplayName\":\"(US) 美国东部 2 (阶段)\",\"metadata\":{\"regionType\":\"Logical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"US\"}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/eastusstage\",\"name\":\"eastusstage\",\"displayName\":\"美国东部(阶段)\",\"regionalDisplayName\":\"(US) 美国东部(阶段)\",\"metadata\":{\"regionType\":\"Logical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"US\"}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/westus2stage\",\"name\":\"westus2stage\",\"displayName\":\"美国西部 2 (阶段)\",\"regionalDisplayName\":\"(US) 美国西部 2 (阶段)\",\"metadata\":{\"regionType\":\"Logical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"US\"}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/westusstage\",\"name\":\"westusstage\",\"displayName\":\"美国西部(阶段)\",\"regionalDisplayName\":\"(US) 美国西部(阶段)\",\"metadata\":{\"regionType\":\"Logical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"US\"}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/northcentralusstage\",\"name\":\"northcentralusstage\",\"displayName\":\"美国中北部(阶段)\",\"regionalDisplayName\":\"(US) 美国中北部(阶段)\",\"metadata\":{\"regionType\":\"Logical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"US\"}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/centralusstage\",\"name\":\"centralusstage\",\"displayName\":\"美国中部(阶段)\",\"regionalDisplayName\":\"(US) 美国中部(阶段)\",\"metadata\":{\"regionType\":\"Logical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"US\"}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/southcentralusstage\",\"name\":\"southcentralusstage\",\"displayName\":\"美国中南部(阶段)\",\"regionalDisplayName\":\"(US) 美国中南部(阶段)\",\"metadata\":{\"regionType\":\"Logical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"US\"}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/australia\",\"name\":\"australia\",\"displayName\":\"澳大利亚\",\"regionalDisplayName\":\"澳大利亚\",\"metadata\":{\"regionType\":\"Logical\",\"regionCategory\":\"Other\"}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/brazil\",\"name\":\"brazil\",\"displayName\":\"巴西\",\"regionalDisplayName\":\"巴西\",\"metadata\":{\"regionType\":\"Logical\",\"regionCategory\":\"Other\"}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/canada\",\"name\":\"canada\",\"displayName\":\"加拿大\",\"regionalDisplayName\":\"加拿大\",\"metadata\":{\"regionType\":\"Logical\",\"regionCategory\":\"Other\"}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/unitedstates\",\"name\":\"unitedstates\",\"displayName\":\"美国\",\"regionalDisplayName\":\"美国\",\"metadata\":{\"regionType\":\"Logical\",\"regionCategory\":\"Other\"}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/europe\",\"name\":\"europe\",\"displayName\":\"欧洲\",\"regionalDisplayName\":\"欧洲\",\"metadata\":{\"regionType\":\"Logical\",\"regionCategory\":\"Other\"}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/global\",\"name\":\"global\",\"displayName\":\"全球\",\"regionalDisplayName\":\"全球\",\"metadata\":{\"regionType\":\"Logical\",\"regionCategory\":\"Other\"}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/japan\",\"name\":\"japan\",\"displayName\":\"日本\",\"regionalDisplayName\":\"日本\",\"metadata\":{\"regionType\":\"Logical\",\"regionCategory\":\"Other\"}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/asiapacific\",\"name\":\"asiapacific\",\"displayName\":\"亚太\",\"regionalDisplayName\":\"亚太\",\"metadata\":{\"regionType\":\"Logical\",\"regionCategory\":\"Other\"}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/asia\",\"name\":\"asia\",\"displayName\":\"亚洲\",\"regionalDisplayName\":\"亚洲\",\"metadata\":{\"regionType\":\"Logical\",\"regionCategory\":\"Other\"}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/india\",\"name\":\"india\",\"displayName\":\"印度\",\"regionalDisplayName\":\"印度\",\"metadata\":{\"regionType\":\"Logical\",\"regionCategory\":\"Other\"}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/uk\",\"name\":\"uk\",\"displayName\":\"英国\",\"regionalDisplayName\":\"英国\",\"metadata\":{\"regionType\":\"Logical\",\"regionCategory\":\"Other\"}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/southeastasiastage\",\"name\":\"southeastasiastage\",\"displayName\":\"东南亚(阶段)\",\"regionalDisplayName\":\"(Asia Pacific) 东南亚(阶段)\",\"metadata\":{\"regionType\":\"Logical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"Asia Pacific\"}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/eastasiastage\",\"name\":\"eastasiastage\",\"displayName\":\"东亚(阶段)\",\"regionalDisplayName\":\"(Asia Pacific) 东亚(阶段)\",\"metadata\":{\"regionType\":\"Logical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"Asia Pacific\"}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/eastus2euap\",\"name\":\"eastus2euap\",\"displayName\":\"美国东部 2 EUAP\",\"regionalDisplayName\":\"(US) 美国东部 2 EUAP\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"US\",\"longitude\":\"-78.3889\",\"latitude\":\"36.6681\",\"pairedRegion\":[{\"name\":\"centraluseuap\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/centraluseuap\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/centraluseuap\",\"name\":\"centraluseuap\",\"displayName\":\"美国中部 EUAP\",\"regionalDisplayName\":\"(US) 美国中部 EUAP\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"US\",\"longitude\":\"-93.6208\",\"latitude\":\"41.5908\",\"pairedRegion\":[{\"name\":\"eastus2euap\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/eastus2euap\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/westcentralus\",\"name\":\"westcentralus\",\"displayName\":\"美国中西部\",\"regionalDisplayName\":\"(US) 美国中西部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"US\",\"longitude\":\"-110.234\",\"latitude\":\"40.890\",\"physicalLocation\":\"Wyoming\",\"pairedRegion\":[{\"name\":\"westus2\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/westus2\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/southafricawest\",\"name\":\"southafricawest\",\"displayName\":\"南非西部\",\"regionalDisplayName\":\"(Africa) 南非西部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"Africa\",\"longitude\":\"18.843266\",\"latitude\":\"-34.075691\",\"physicalLocation\":\"Cape Town\",\"pairedRegion\":[{\"name\":\"southafricanorth\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/southafricanorth\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/australiasoutheast\",\"name\":\"australiasoutheast\",\"displayName\":\"澳大利亚东南部\",\"regionalDisplayName\":\"(Asia Pacific) 澳大利亚东南部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"Asia Pacific\",\"longitude\":\"144.9631\",\"latitude\":\"-37.8136\",\"physicalLocation\":\"Victoria\",\"pairedRegion\":[{\"name\":\"australiaeast\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/australiaeast\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/australiacentral\",\"name\":\"australiacentral\",\"displayName\":\"澳大利亚中部\",\"regionalDisplayName\":\"(Asia Pacific) 澳大利亚中部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"Asia Pacific\",\"longitude\":\"149.1244\",\"latitude\":\"-35.3075\",\"physicalLocation\":\"Canberra\",\"pairedRegion\":[{\"name\":\"australiacentral\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/australiacentral\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/australiacentral2\",\"name\":\"australiacentral2\",\"displayName\":\"澳大利亚中部 2\",\"regionalDisplayName\":\"(Asia Pacific) 澳大利亚中部 2\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"Asia Pacific\",\"longitude\":\"149.1244\",\"latitude\":\"-35.3075\",\"physicalLocation\":\"Canberra\",\"pairedRegion\":[{\"name\":\"australiacentral2\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/australiacentral2\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/koreasouth\",\"name\":\"koreasouth\",\"displayName\":\"韩国南部\",\"regionalDisplayName\":\"(Asia Pacific) 韩国南部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"Asia Pacific\",\"longitude\":\"129.0756\",\"latitude\":\"35.1796\",\"physicalLocation\":\"Busan\",\"pairedRegion\":[{\"name\":\"koreacentral\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/koreacentral\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/japanwest\",\"name\":\"japanwest\",\"displayName\":\"日本西部\",\"regionalDisplayName\":\"(Asia Pacific) 日本西部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"Asia Pacific\",\"longitude\":\"135.5022\",\"latitude\":\"34.6939\",\"physicalLocation\":\"Osaka\",\"pairedRegion\":[{\"name\":\"japaneast\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/japaneast\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/southindia\",\"name\":\"southindia\",\"displayName\":\"印度南部\",\"regionalDisplayName\":\"(Asia Pacific) 印度南部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"Asia Pacific\",\"longitude\":\"80.1636\",\"latitude\":\"12.9822\",\"physicalLocation\":\"Chennai\",\"pairedRegion\":[{\"name\":\"centralindia\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/centralindia\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/westindia\",\"name\":\"westindia\",\"displayName\":\"印度西部\",\"regionalDisplayName\":\"(Asia Pacific) 印度西部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"Asia Pacific\",\"longitude\":\"72.868\",\"latitude\":\"19.088\",\"physicalLocation\":\"Mumbai\",\"pairedRegion\":[{\"name\":\"southindia\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/southindia\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/canadaeast\",\"name\":\"canadaeast\",\"displayName\":\"加拿大东部\",\"regionalDisplayName\":\"(Canada) 加拿大东部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"Canada\",\"longitude\":\"-71.217\",\"latitude\":\"46.817\",\"physicalLocation\":\"Quebec\",\"pairedRegion\":[{\"name\":\"canadacentral\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/canadacentral\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/germanynorth\",\"name\":\"germanynorth\",\"displayName\":\"德国北部\",\"regionalDisplayName\":\"(Europe) 德国北部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"Europe\",\"longitude\":\"8.806422\",\"latitude\":\"53.073635\",\"physicalLocation\":\"Berlin\",\"pairedRegion\":[{\"name\":\"germanywestcentral\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/germanywestcentral\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/francesouth\",\"name\":\"francesouth\",\"displayName\":\"法国南部\",\"regionalDisplayName\":\"(Europe) 法国南部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"Europe\",\"longitude\":\"2.1972\",\"latitude\":\"43.8345\",\"physicalLocation\":\"Marseille\",\"pairedRegion\":[{\"name\":\"francecentral\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/francecentral\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/norwaywest\",\"name\":\"norwaywest\",\"displayName\":\"挪威西部\",\"regionalDisplayName\":\"(Europe) 挪威西部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"Europe\",\"longitude\":\"5.733107\",\"latitude\":\"58.969975\",\"physicalLocation\":\"Norway\",\"pairedRegion\":[{\"name\":\"norwayeast\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/norwayeast\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/switzerlandwest\",\"name\":\"switzerlandwest\",\"displayName\":\"瑞士西部\",\"regionalDisplayName\":\"(Europe) 瑞士西部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"Europe\",\"longitude\":\"6.143158\",\"latitude\":\"46.204391\",\"physicalLocation\":\"Geneva\",\"pairedRegion\":[{\"name\":\"switzerlandnorth\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/switzerlandnorth\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/ukwest\",\"name\":\"ukwest\",\"displayName\":\"英国西部\",\"regionalDisplayName\":\"(Europe) 英国西部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"Europe\",\"longitude\":\"-3.084\",\"latitude\":\"53.427\",\"physicalLocation\":\"Cardiff\",\"pairedRegion\":[{\"name\":\"uksouth\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/uksouth\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/uaecentral\",\"name\":\"uaecentral\",\"displayName\":\"阿联酋中部\",\"regionalDisplayName\":\"(Middle East) 阿联酋中部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"Middle East\",\"longitude\":\"54.366669\",\"latitude\":\"24.466667\",\"physicalLocation\":\"Abu Dhabi\",\"pairedRegion\":[{\"name\":\"uaenorth\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/uaenorth\"}]}},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/chinanorth\",\"name\":\"chinanorth\",\"displayName\":\"中国北部\",\"regionalDisplayName\":\"中国北部\"},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/chinanorth2\",\"name\":\"chinanorth2\",\"displayName\":\"中国北部2\",\"regionalDisplayName\":\"中国北部2\"},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/chinaeast\",\"name\":\"chinaeast\",\"displayName\":\"中国东部\",\"regionalDisplayName\":\"中国东部\"},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/chinaeast2\",\"name\":\"chinaeast2\",\"displayName\":\"中国东部2\",\"regionalDisplayName\":\"2中国东部2\"},{\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/brazilsoutheast\",\"name\":\"brazilsoutheast\",\"displayName\":\"巴西东南部\",\"regionalDisplayName\":\"(South America) 巴西东南部\",\"metadata\":{\"regionType\":\"Physical\",\"regionCategory\":\"Other\",\"geographyGroup\":\"South America\",\"longitude\":\"-43.2075\",\"latitude\":\"-22.90278\",\"physicalLocation\":\"Rio\",\"pairedRegion\":[{\"name\":\"brazilsouth\",\"id\":\"/subscriptions/66d2a4f8-6290-4d7d-ab07-d584fc31db3e/locations/brazilsouth\"}]}}]";
        JSONArray array = JSONArray.parseArray(regionJsonValue);
        Map<String, String> stringMap = array.stream().map(JSONObject::toJSONString).map(JSONObject::parseObject).collect(Collectors.toMap(obj -> obj.getString("name"), obj -> obj.getString("displayName")));
        return stringMap.get(key);

    }
}