package com.huimv.admin.controller;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import com.hikvision.cms.api.common.util.Digests;
import com.huimv.admin.common.utils.HttpClientSSLUtils;
import com.huimv.admin.common.utils.Result;
import com.huimv.admin.common.utils.ResultCode;
import com.huimv.admin.entity.CameraBase;
import com.huimv.admin.entity.hkwsdto.*;
import com.huimv.admin.service.ICameraAreaService;
import com.huimv.admin.service.ICameraBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/admin/cameraHKVSSync")
public class CameraHKVSSync {

    @Autowired
    private ICameraAreaService cameraAreaService;

    @Autowired
    private ICameraBaseService cameraBaseService;

    @PostMapping("/sync")
    @Transactional
    public Result sync(@RequestBody Map<String, Integer> params) throws Exception {
        Integer farmId = params.get("farmId");
        String region = "";
        if (farmId == 21){
            //获取默认控制中心  正康区域 的上级，暂时不用
//        System.out.println(testGetDefaultUnit());
            //根据中心UUID分页获取下级区  正康猪业id:1048576
            String unitUuid = testGetRegionsByUnitUuid(1048576);
            HkvsUnitDto hkvsUnitDto = JSONUtil.toBean(unitUuid, HkvsUnitDto.class);
            if (ObjectUtil.isNotEmpty(hkvsUnitDto) && hkvsUnitDto.getErrorCode() == 0) {
                List<UnitDto1> list = hkvsUnitDto.getData().getList();
                if (ObjectUtil.isNotEmpty(list)) {
                    cameraAreaService.sync(params, list);
                }
            } else {
                return new Result(10001, hkvsUnitDto.getErrorMessage(), false);
            }
            //获取监控点
            String cameras = testGetCameras();
            HkvsCameraDto hkvsCameraDto = JSONUtil.toBean(cameras, HkvsCameraDto.class);
            if (ObjectUtil.isNotEmpty(hkvsCameraDto) && hkvsCameraDto.getErrorCode() == 0) {
                List<CameraDto1> list = hkvsCameraDto.getData().getList();
                if (ObjectUtil.isNotEmpty(list)) {
                    cameraBaseService.sync(params, list);
                }
            } else {
                return new Result(10001, hkvsUnitDto.getErrorMessage(), false);
            }
            return new Result(10000, "同步成功", false);
        }else {
            switch (farmId){
                case 22:
                    region = XSD_REGION;
                    break;
                case 23:
                    region = PJ_REGION;
                    break;
                case 24:
                    region = DY_REGION;
                    break;
                case 26:
                    region = HL_REGION;
                    break;
                case 27:
                    region = TT_REGION;
                    break;
                case 28:
                    region = PW_REGION;
                    break;
                case 39:
                    region = YQ_REGION;
                    break;
                default:
                    return new Result(10001,"该牧场无服务",false);
            }
//          海康新平台
            String callPostApiGetSubRegions = callPostApiGetSubRegions(region);
            HkvsRegionDto hkvsRegionDto = JSONUtil.toBean(callPostApiGetSubRegions, HkvsRegionDto.class);
            if (ObjectUtil.isNotEmpty(hkvsRegionDto) && "0".equals(hkvsRegionDto.getCode())) {
                List<RegionDto> hkvsRegionDtoData = hkvsRegionDto.getData();
                for (RegionDto hkvsRegionDtoDatum : hkvsRegionDtoData) {
                    List<RegionDetailDto> hkvsRegionDtoDatumList = hkvsRegionDtoDatum.getList();
                    if (ObjectUtil.isNotEmpty(hkvsRegionDtoDatumList)){
                        cameraAreaService.NewSync(params,hkvsRegionDtoDatumList);
                    }
                }
            }
            //获取监控点
            String callPostApiGetCameras = callPostApiGetCameras(region);
            HkvsNewCameraDto hkvsNewCameraDto = JSONUtil.toBean(callPostApiGetCameras, HkvsNewCameraDto.class);
            if (ObjectUtil.isNotEmpty(hkvsNewCameraDto) && "0".equals(hkvsNewCameraDto.getCode())) {
                List<NewCameraDto> hkvsNewCameraDtoData = hkvsNewCameraDto.getData();
                for (NewCameraDto hkvsNewCameraDtoDatum : hkvsNewCameraDtoData) {
                    List<CameraDetailDto> hkvsNewCameraDtoDatumList = hkvsNewCameraDtoDatum.getList();
                    if (ObjectUtil.isNotEmpty(hkvsNewCameraDtoDatumList)){
                        cameraBaseService.NewSync(params,hkvsNewCameraDtoDatumList);
                    }
                }
            }else {
                return new Result(10001, hkvsNewCameraDto.getMsg(), false);
            }
            return new Result(10000, "同步成功", false);
        }
    }

    @PostMapping("/getVideo")
    public Result getVideo(@RequestBody Map<String, String> params) throws Exception {
        String cameraUuid = params.get("cameraUuid");
        CameraBase cameraBase = cameraBaseService.getOne(new QueryWrapper<CameraBase>().lambda().eq(CameraBase::getCameraUuid,cameraUuid));
        String callPostApiGetPreviewURLs = callPostApiGetPreviewURLs(cameraUuid);
        HkvsPreviewDto hkvsPreviewDto = JSONUtil.toBean(callPostApiGetPreviewURLs, HkvsPreviewDto.class);
        if (!hkvsPreviewDto.getCode().equals("0")) {
            return new Result(10001,hkvsPreviewDto.getMsg(),false);
        }else {
            String url = hkvsPreviewDto.getData().getUrl();
            if (ObjectUtil.isNotEmpty(url)){
                cameraBase.setUrl(url);
                cameraBaseService.updateById(cameraBase);
                return new Result(ResultCode.SUCCESS,url);
            }else {
                return Result.ERROR();
            }
        }
    }

    private static final String PREVIEW_PATH = "/api/video/v2/cameras/previewURLs";

    public static String callPostApiGetPreviewURLs(String cameraIndexCode) throws Exception {
        /**
         * https://ip:port/artemis/api/video/v2/cameras/previewURLs
         * 根据指定的区域编号获取该区域下的监控点列表信息，返回结果分页展示。
         * 注：返回的监控点不包括下级区域的。
         */
        ArtemisConfig config = new ArtemisConfig();
        config.setHost(OPENAPI_IP); // 代理API网关nginx服务器ip端口
        config.setAppKey(NEW_APPKEY);  // 秘钥appkey
        config.setAppSecret(NEW_SECRET);// 秘钥appSecret
        final String getCamsApi = ARTEMIS_PATH + PREVIEW_PATH;
        Map<String, Object> paramMap = new HashMap<String, Object>();// post请求Form表单参数
        paramMap.put("cameraIndexCode",cameraIndexCode);
        paramMap.put("streamType",0);
//        paramMap.put("protocol","wss");
        paramMap.put("protocol","ws");
        paramMap.put("transmode",1);
        paramMap.put("expand","streamform=rtp");
        String body = JSON.toJSON(paramMap).toString();
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", getCamsApi);
            }
        };
        String s = ArtemisHttpUtil.doPostStringArtemis(config, path, body, null, null, "application/json");
        System.out.println("---->"+s);

        return s;
    }

    /**
     * APPKEY需要到部署的平台服务器上生成。
     * <p>
     * 调用Openpai的操作码，需要去平台上生成，详见《海康威视iVMS-8700平台SDKV2.*.* HTTP-OpenAPI使用说明书.chm》中[获取AppKey和Secret]章节说明
     * </p>
     * <p>
     * 《海康威视iVMS-8700平台SDKV2.*.* HTTP-OpenAPI使用说明书.chm》 该文档请找技术支持或者交付的同事提供
     * </p>
     */
    private static final String APPKEY = "1c9ee657";

    /**
     * SECRET需要到部署的平台服务器上生成。
     * <p>
     * 调用Openpai的操作码，需要去平台上生成，详见《海康威视iVMS-8700平台SDKV2.*.* HTTP-OpenAPI使用说明书.chm》中[获取AppKey和Secret]章节说明
     * </p>
     * <p>
     * 《海康威视iVMS-8700平台SDKV2.*.* HTTP-OpenAPI使用说明书.chm》 该文档请找技术支持或者交付的同事提供
     * </p>
     */
    private static final String SECRET = "a5d723941c804a429447e71db2707ce8";


    /**
     * http请求地址
     * <p>openapi的地址,默认情况下openapi的IP端口与基础应用的IP端口是一致的</p>
     * <p>请将地址配置正确.</p>
     * <p>默认情况下是127.0.0.1:80 ，如果地址不通请根据实际情况修改IP端口</p>
     */
//    private static final String OPENAPI_IP_PORT_HTTP = "http://61.153.248.106:100";
    private static final String OPENAPI_IP_PORT_HTTP = "http://61.153.248.106:100";
//    private static final String OPENAPI_IP_PORT_HTTP = "http://172.21.90:80";

    /**
     * https请求地址
     * <p>openapi的地址,默认情况下openapi的IP端口与基础应用的IP端口是一致的</p>
     * <p>请将地址配置正确.</p>
     * <p>默认情况下是127.0.0.1:443 ，如果地址不通请根据实际情况修改IP端口</p>
     */
    private static final String OPENAPI_IP_PORT_HTTPS = "https://61.153.248.106:4430";
//    private static final String OPENAPI_IP_PORT_HTTPS = "https://172.21.90:443";

    /**
     * 获取默认用户UUID的接口地址，此地址可以从《海康威视iVMS-8700平台SDKV2.*.* HTTP-OpenAPI使用说明书.chm》中具体的接口说明上获取
     */
    private static final String ITF_ADDRESS_GET_DEFAULT_USER_UUID = "/openapi/service/base/user/getDefaultUserUuid";

    /**
     * 分页获取监控点信息的接口地址，此地址可以从《海康威视iVMS-8700平台SDKV2.*.* HTTP-OpenAPI使用说明书.chm》中具体的接口说明上获取
     */
    private static final String ITF_ADDRESS_GET_CAMERAS = "/openapi/service/vss/res/getCameras";

    /**
     * 获取部门
     */
    private static final String ITF_ADDRESS_GET_DEPTINFOS = "/openapi/service/base/dept/getDeptInfos";

    /**
     * 获取网域
     */
    private static final String ITF_ADDRESS_GET_NETZONES = "/openapi/service/base/netZone/getNetZones";

    /**
     * 获取默认控制中心
     */
    private static final String ITF_ADDRESS_GET_DEFAULT_UNIT = "/openapi/service/base/org/getDefaultUnit";

    /**
     * 获取子系统
     */
    private static final String ITF_ADDRESS_GET_PLAT_SUBSYTEM = "/openapi/service/base/res/getPlatSubsytem";

    /**
     * 根据中心UUID分页获取下级区域
     */
    private static final String ITF_ADDRESS_GET_REGIONS_BY_UNIT_UUID = "/openapi/service/base/org/getRegionsByUnitUuid";

    /**
     * <p>操作用户UUID，即用户UUID，首次使用操作用户UUID可以通过接口 [获取默认用户UUID]来获取</p>
     * <p>也可以通过接口[分页获取用户]来获取</p>
     */
    private static final String OP_USER_UUID = "5b2eb534696b11e89c2e438f92627767";

    /**
     * 测试方法
     *
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {

        /***http方式调用***/
        //获取 默认用户id 初始化用
//        System.out.println(testGetDefaultUserUUID());
//
//        //获取部门
//        System.out.println(testGetDeptInfos());
//        //获取网域
//        System.out.println(testGetNetZones());
//        //获取子系统
//        System.out.println(testGetPlatSubsytem());
//        //获取默认控制中心
//        System.out.println(testGetDefaultUnit());
//        //根据中心UUID分页获取下级区
//        System.out.println(testGetRegionsByUnitUuid(1048576));
//        //获取监控点
//        System.out.println(testGetCameras());
//        /***https方式调用***/
//        System.out.println(testGetDefaultUserUUID_Https());
//        System.out.println(testGetCameras_Https());

        /***http方式调用(海康新平台)***/
//        String callPostApiGetSubRegions = callPostApiGetSubRegions("500d8b6a-2554-43f3-bda7-e686577eb741");
//        System.out.println(callPostApiGetSubRegions);
//        HkvsRegionDto hkvsRegionDto = JSONUtil.toBean(callPostApiGetSubRegions, HkvsRegionDto.class);
//        if (ObjectUtil.isNotEmpty(hkvsRegionDto) && "0".equals(hkvsRegionDto.getCode())) {
//            List<RegionDto> hkvsRegionDtoData = hkvsRegionDto.getData();
//            for (RegionDto hkvsRegionDtoDatum : hkvsRegionDtoData) {
//                List<RegionDetailDto> hkvsRegionDtoDatumList = hkvsRegionDtoDatum.getList();
//                System.out.println(hkvsRegionDtoDatumList);
//            }
//        }
//        String callPostApiGetCameras = callPostApiGetCameras("901343d5-182e-4777-98fb-5451c153e61e");
//        System.out.println(callPostApiGetCameras);
//        HkvsNewCameraDto hkvsNewCameraDto = JSONUtil.toBean(callPostApiGetCameras, HkvsNewCameraDto.class);
//        if (ObjectUtil.isNotEmpty(hkvsNewCameraDto) && "0".equals(hkvsNewCameraDto.getCode())) {
//            List<NewCameraDto> hkvsNewCameraDtoData = hkvsNewCameraDto.getData();
//            for (NewCameraDto hkvsNewCameraDtoDatum : hkvsNewCameraDtoData) {
//                List<CameraDetailDto> hkvsNewCameraDtoDatumList = hkvsNewCameraDtoDatum.getList();
//                System.out.println(hkvsNewCameraDtoDatumList);
//            }
//        }
        System.out.println(callPostApiGetPreviewURLs("83af6ee1565c46c9b096c7552cf75a51"));

    }

    /**
     * HTTP方式
     * 获取子系统
     *
     * @return
     * @throws Exception
     */
    private static String testGetRegionsByUnitUuid(Integer unitUuid) throws Exception {
        String url = OPENAPI_IP_PORT_HTTP + ITF_ADDRESS_GET_REGIONS_BY_UNIT_UUID;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("appkey", APPKEY);//设置APPKEY
        map.put("time", System.currentTimeMillis());//设置时间参数
        map.put("pageNo", 1);//设置分页参数
        map.put("pageSize", 1000);//设置分页参数
        map.put("opUserUuid", OP_USER_UUID);//设置操作用户UUID
        map.put("parentUuid", unitUuid);// 根据父id查下面栋舍
        map.put("allChildren", 1);//获取子系统
        String params = JSON.toJSONString(map);
        System.out.println(" ====== getCameras请求参数：【" + params + "】");
        String data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, null, SECRET), params);
        System.out.println(" ====== getCameras请求返回结果：【{" + data + "}】");

        return data;
    }

    /**
     * HTTP方式
     * 获取默认控制中心
     *
     * @return
     * @throws Exception
     */
    private static String testGetDefaultUnit() throws Exception {
        String url = OPENAPI_IP_PORT_HTTP + ITF_ADDRESS_GET_DEFAULT_UNIT;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("appkey", APPKEY);//设置APPKEY
        map.put("time", System.currentTimeMillis());//设置时间参数
        map.put("pageNo", 1);//设置分页参数
        map.put("pageSize", 1000);//设置分页参数
        map.put("opUserUuid", OP_USER_UUID);//设置操作用户UUID
        map.put("subSystemCode", 1048576);//设置子系统编码  （视频）
        String params = JSON.toJSONString(map);
        System.out.println(" ====== getCameras请求参数：【" + params + "】");
        String data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, null, SECRET), params);
        System.out.println(" ====== getCameras请求返回结果：【{" + data + "}】");

        return data;
    }

    /**
     * HTTP方式
     * 获取子系统
     *
     * @return
     * @throws Exception
     */
    private static String testGetPlatSubsytem() throws Exception {
        String url = OPENAPI_IP_PORT_HTTP + ITF_ADDRESS_GET_PLAT_SUBSYTEM;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("appkey", APPKEY);//设置APPKEY
        map.put("time", System.currentTimeMillis());//设置时间参数
        map.put("pageNo", 1);//设置分页参数
        map.put("pageSize", 1000);//设置分页参数
        map.put("opUserUuid", OP_USER_UUID);//设置操作用户UUID
        String params = JSON.toJSONString(map);
        System.out.println(" ====== getCameras请求参数：【" + params + "】");
        String data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, null, SECRET), params);
        System.out.println(" ====== getCameras请求返回结果：【{" + data + "}】");

        return data;
    }


   /* private static String test() throws Exception{
        String baseUrl = "test.htpig.cn";
        String login = "/user/login";
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("user_name", APPKEY);//
        map.put("password", APPKEY);//
        String params = JSON.toJSONString(map);
        System.out.println(" ====== getCameras请求参数：【" + params + "】");
        String data = HttpClientSSLUtils.doGet("http://test.htpig.cn/rest/user/login?user_name=test&password=e10adc3949ba59abbe56e057f20f883e&db_name=MSSQL");
        System.out.println(" ====== getCameras请求返回结果：【{" + data + "}】");

        return data;
    }*/


    /**
     * HTTP方式
     * 获取默认用户UUID 测试
     *
     * @return
     * @throws Exception
     */
    private static String testGetDefaultUserUUID() throws Exception {
        String url = OPENAPI_IP_PORT_HTTP + ITF_ADDRESS_GET_DEFAULT_USER_UUID;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("appkey", APPKEY);//设置APPKEY
        map.put("time", System.currentTimeMillis());//设置时间参数
        String params = JSON.toJSONString(map);
        System.out.println(" ====== testGetDefaultUserUUID 请求参数：【" + params + "】");
        String data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, null, SECRET), params);
        System.out.println(" ====== testGetDefaultUserUUID 请求返回结果：【{" + data + "}】");

        return data;
    }

    /**
     * HTTP方式
     * 分页获取监控点信息 测试
     *
     * @return
     * @throws Exception
     */
    private static String testGetCameras() throws Exception {
        String url = OPENAPI_IP_PORT_HTTP + ITF_ADDRESS_GET_CAMERAS;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("appkey", APPKEY);//设置APPKEY
        map.put("time", System.currentTimeMillis());//设置时间参数
        map.put("pageNo", 1);//设置分页参数
        map.put("pageSize", 1000);//设置分页参数
        map.put("opUserUuid", OP_USER_UUID);//设置操作用户UUID
        String params = JSON.toJSONString(map);
        System.out.println(" ====== getCameras请求参数：【" + params + "】");
        String data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, null, SECRET), params);
        System.out.println(" ====== getCameras请求返回结果：【{" + data + "}】");

        return data;
    }

    /**
     * HTTP方式
     * 分页获取部门 测试
     *
     * @return
     * @throws Exception
     */
    private static String testGetDeptInfos() throws Exception {
        String url = OPENAPI_IP_PORT_HTTP + ITF_ADDRESS_GET_DEPTINFOS;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("appkey", APPKEY);//设置APPKEY
        map.put("time", System.currentTimeMillis());//设置时间参数
        map.put("pageNo", 1);//设置分页参数
        map.put("pageSize", 1000);//设置分页参数
        map.put("opUserUuid", OP_USER_UUID);//设置操作用户UUID
        String params = JSON.toJSONString(map);
        System.out.println(" ====== getCameras请求参数：【" + params + "】");
        String data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, null, SECRET), params);
        System.out.println(" ====== getCameras请求返回结果：【{" + data + "}】");

        return data;
    }

    /**
     * HTTP方式
     * 分页获取网域 测试
     *
     * @return
     * @throws Exception
     */
    private static String testGetNetZones() throws Exception {
        String url = OPENAPI_IP_PORT_HTTP + ITF_ADDRESS_GET_NETZONES;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("appkey", APPKEY);//设置APPKEY
        map.put("time", System.currentTimeMillis());//设置时间参数
        map.put("pageNo", 1);//设置分页参数
        map.put("pageSize", 1000);//设置分页参数
        map.put("opUserUuid", OP_USER_UUID);//设置操作用户UUID
        String params = JSON.toJSONString(map);
        System.out.println(" ====== getCameras请求参数：【" + params + "】");
        String data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, null, SECRET), params);
        System.out.println(" ====== getCameras请求返回结果：【{" + data + "}】");

        return data;
    }

    /**
     * HTTPS方式
     * 获取默认用户UUID 测试
     *
     * @return
     * @throws Exception
     */
    private static String testGetDefaultUserUUID_Https() throws Exception {
        String url = OPENAPI_IP_PORT_HTTPS + ITF_ADDRESS_GET_DEFAULT_USER_UUID;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("appkey", APPKEY);//设置APPKEY
        map.put("time", System.currentTimeMillis());//设置时间参数
        String params = JSON.toJSONString(map);
        System.out.println("============" + params + "============");
        String data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, null, SECRET), params);
        System.out.println("============" + data + "============");

        return data;
    }

    /**
     * HTTPS方式
     * 分页获取监控点信息 测试
     *
     * @return
     * @throws Exception
     */
    private static String testGetCameras_Https() throws Exception {
        String url = OPENAPI_IP_PORT_HTTPS + ITF_ADDRESS_GET_CAMERAS;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("appkey", APPKEY);//设置APPKEY
        map.put("time", System.currentTimeMillis());//设置时间参数
        map.put("pageNo", 1);//设置分页参数
        map.put("pageSize", 5);//设置分页参数
        map.put("opUserUuid", OP_USER_UUID);//设置操作用户UUID
        String params = JSON.toJSONString(map);
        System.out.println(" ====== getCameras请求参数：【" + params + "】");
        String data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, null, SECRET), params);
        System.out.println(" ====== getCameras请求返回结果：【{" + data + "}】");

        return data;
    }

    /**
     * API网关的后端服务上下文为：/artemis
     */
    private static final String ARTEMIS_PATH = "/artemis";

    private static final String SUBREGIONS_PATH = "/api/resource/v2/regions/subRegions";

    private static final String CAMERAS_PATH = "/api/resource/v2/camera/search";

    private static final String NEW_APPKEY = "27546900";

    private static final String NEW_SECRET = "S5qgrKdBd75M0NZRzGAh";

//    private static final String OPENAPI_IP = "61.153.248.109";
    private static final String OPENAPI_IP = "www.htzj.fun";

    private static final String ZK_REGION = "500d8b6a-2554-43f3-bda7-e686577eb741";

    private static final String PJ_REGION = "70405f14-1cb5-4413-8bef-38e4a365cbee";

    private static final String XSD_REGION= "5c23fa9b-ee7e-4201-851d-340b0f6f320e";

    private static final String PW_REGION = "66096289-bd19-4390-a5d5-71a31e970b0b";

    private static final String DY_REGION = "a09ba2d8-8236-4de6-8e53-9008912d7b72";

    private static final String TT_REGION = "d64e2029-75bb-4214-8cc4-e93deace9ea4";

    private static final String HL_REGION = "b540a5d0-ff1c-4275-bdab-af24d50eb1a7";

    private static final String YQ_REGION = "6b0c78e2-763f-40c3-94d0-0d247649ad68";

    /**
     * 调用POST请求类型接口，这里以分页获取区域列表为例
     * 接口实际url：https://ip:port/artemis/api/api/resource/v1/regions
     *
     * @return
     */
    public static String callPostApiGetSubRegions(String region) throws Exception {
        /**
         * https://ip:port/artemis/api/resource/v2/regions/subRegions
         * 根据区域编号获取下一级区域列表v2
         *
         * 描述:根据用户请求的资源类型和资源权限获取父区域的下级区域列表，主要用于逐层获取父区域的下级区域信息，
         * 例如监控点预览业务的区域树的逐层获取。下级区域只包括直接下级子区域。
         * 注：查询区域管理权限（resourceType为region），若父区域的子区域无权限、但是其孙区域有权限时，会返回该无权限的子区域，但是该区域的available标记为false（表示无权限）
         */
        ArtemisConfig config = new ArtemisConfig();
        config.setHost(OPENAPI_IP); // 代理API网关nginx服务器ip端口
        config.setAppKey(NEW_APPKEY);  // 秘钥appkey
        config.setAppSecret(NEW_SECRET);// 秘钥appSecret

        final String getCamsApi = ARTEMIS_PATH + SUBREGIONS_PATH;
        Map<String, Object> paramMap = new HashMap<String, Object>();// post请求Form表单参数
        paramMap.put("resourceType", "camera");
//		正康:500d8b6a-2554-43f3-bda7-e686577eb741  浦江:70405f14-1cb5-4413-8bef-38e4a365cbee  平望:66096289-bd19-4390-a5d5-71a31e970b0b
        paramMap.put("parentIndexCode", region);
        paramMap.put("pageNo", 1);
        paramMap.put("pageSize", 1000);
        String body = JSON.toJSON(paramMap).toString();
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", getCamsApi);
            }
        };
        return ArtemisHttpUtil.doPostStringArtemis(config, path, body, null, null, "application/json");
    }

    public static String callPostApiGetCameras(String region) throws Exception {
        /**
         * https://ip:port/artemis/api/resource/v1/regions/regionIndexCode/cameras
         * 根据指定的区域编号获取该区域下的监控点列表信息，返回结果分页展示。
         * 注：返回的监控点不包括下级区域的。
         */
        ArtemisConfig config = new ArtemisConfig();
        config.setHost(OPENAPI_IP); // 代理API网关nginx服务器ip端口
        config.setAppKey(NEW_APPKEY);  // 秘钥appkey
        config.setAppSecret(NEW_SECRET);// 秘钥appSecret
        final String getCamsApi = ARTEMIS_PATH + CAMERAS_PATH;
        Map<String, Object> paramMap = new HashMap<String, Object>();// post请求Form表单参数
        String[] regionIndexCodes = {region};
        paramMap.put("regionIndexCodes",regionIndexCodes);
        paramMap.put("isSubRegion",true);
        paramMap.put("pageNo",1);
        paramMap.put("pageSize",1000);
        String body = JSON.toJSON(paramMap).toString();
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", getCamsApi);
            }
        };
        return ArtemisHttpUtil.doPostStringArtemis(config,path, body, null, null, "application/json");
    }
}