package com.ruoyi.web.controller.parkLot;


import com.alibaba.fastjson2.JSONObject;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import com.ruoyi.common.utils.StringUtils;

import java.util.HashMap;
import java.util.Map;
/**
 * @Author: tjf
 * @Date: 2023/1/3 15:01
 * @Describe:
 */
public class GetCameraPreviewURL {


    /**
     * 提供给皖事通剩余地面车位数量
     * @return
     */
    public static String GetCameraPreviewURL() {
        /**
         * STEP1：设置平台参数，根据实际情况,设置host appkey appsecret 三个参数.
         */
        ArtemisConfig.host = "114.99.51.58:442"; // 平台的ip端口
        ArtemisConfig.appKey = "26665995";  // 密钥appkey
        ArtemisConfig.appSecret = "P9y9211M5ftH8P1Xrcef";// 密钥appSecret

        /**
         * STEP2：设置OpenAPI接口的上下文
         */
        final String ARTEMIS_PATH = "/artemis";
        /**
         * STEP3：设置接口的URI地址
         */
        final String previewURLsApi = ARTEMIS_PATH + "/api/pms/v1/park/remainSpaceNum";
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
            }
        };

        /**
         * STEP4：设置参数提交方式
         */
        String contentType = "application/json";

        /**
         * STEP5：组装请求参数
         */
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("parkSyscode", "v45gh45gergf34g34g354g35ger");
        String body = jsonBody.toJSONString();
        /**
         * STEP6：调用接口
         */
        String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , null);// post请求application/json类型参数
        System.out.println(result);
        /**
         * {
         *     "code": "0",
         *     "msg": "success",
         *     "data": [
         *         {
         *             "parkSyscode": "h45h3gh3g34g324g345",
         *             "parkName": "停车库1",
         *             "parentParkSyscode": "g354g45g345g35g2345gh5",
         *             "totalPlace": 5000,
         *             "totalPermPlace": 5000,
         *             "totalReservePlace": 0,
         *             "leftPlace": 0,
         *             "leftPermPlace": 0,
         *             "leftReservePlace": 0
         *         }
         *     ]
         * }
         */
        return result;
    }

    /**
     * 获取实时地面停车场场内车数据
     * @return
     */
    public static String GetTempCarInRecordsURL(String plateNo,String startTime,String endTime,String pageNo,String pageSize) {
        /**
         * STEP1：设置平台参数，根据实际情况,设置host appkey appsecret 三个参数.
         */
        ArtemisConfig.host = "114.99.51.58:442"; // 平台的ip端口
        ArtemisConfig.appKey = "26665995";  // 密钥appkey
        ArtemisConfig.appSecret = "P9y9211M5ftH8P1Xrcef";// 密钥appSecret

        /**
         * STEP2：设置OpenAPI接口的上下文
         */
        final String ARTEMIS_PATH = "/artemis";
        /**
         * STEP3：设置接口的URI地址
         */
        final String previewURLsApi = ARTEMIS_PATH + "/api/pms/v1/tempCarInRecords/page";
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
            }
        };

        /**
         * STEP4：设置参数提交方式
         */
        String contentType = "application/json";

        /**
         * STEP5：组装请求参数
         */
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("pageNo",1);
        jsonBody.put("pageSize",1000);
        if (StringUtils.isNotBlank(plateNo)){
            jsonBody.put("plateNo", plateNo);
        }
        if (StringUtils.isNotBlank(startTime)){
            jsonBody.put("startTime", startTime);
            jsonBody.put("endTime", endTime);
        }
        if (StringUtils.isNotBlank(pageNo)){
            jsonBody.put("pageNo",pageNo);
            jsonBody.put("pageSize",pageSize);
        }
        String body = jsonBody.toJSONString();
        /**
         * STEP6：调用接口
         */
        String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , null);// post请求application/json类型参数
        System.out.println(result);
        /**
         * {
         *     "code": "0",
         *     "msg": "success",
         *     "data": {
         *         "total": 1,
         *         "pageNo": 1,
         *         "pageSize": 15,
         *         "list": [
         *             {
         *                 "inRecordSyscode": "h45h45h45ghhn45tg245g45r",
         *                 "vehiclePicUri": "/pic?=d7ei703i10cd*73a-d5108a--22c6592ai2b4*=3d4id=",
         *                 "cardNo": "613453453",
         *                 "inTime": "2018-07-26T15:00:00+08:00",
         *                 "parkTime": "1天1小时1分钟",
         *                 "parkSyscode": "hju56jyt54h4h245g2345g345fg",
         *                 "parkName": "停车库1",
         *                 "plateNoPicUri": "/pic?=d7ei703i10cd*73a-d5108a--22c592ai2b4*=3",
         *                 "aswSyscode": "g45ghertg34fh4hy245tgy234tg5",
         *                 "plateNo": "浙A12345"
         *             }
         *         ]
         *     }
         * }
         */
        return result;
    }

    /**
     * 查询车辆包期信息
     * @return
     */
    public static String GetChargeURL(String startTime,String endTime,String pageNo,String pageSize) {
        /**
         * STEP1：设置平台参数，根据实际情况,设置host appkey appsecret 三个参数.
         */
        ArtemisConfig.host = "114.99.51.58:442"; // 平台的ip端口
        ArtemisConfig.appKey = "26665995";  // 密钥appkey
        ArtemisConfig.appSecret = "P9y9211M5ftH8P1Xrcef";// 密钥appSecret

        /**
         * STEP2：设置OpenAPI接口的上下文
         */
        final String ARTEMIS_PATH = "/artemis";
        /**
         * STEP3：设置接口的URI地址
         */
        final String previewURLsApi = ARTEMIS_PATH + "/api/pms/v1/car/charge/page";
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
            }
        };

        /**
         * STEP4：设置参数提交方式
         */
        String contentType = "application/json";

        /**
         * STEP5：组装请求参数
         */
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("pageNo",1);
        jsonBody.put("pageSize",1000);
        if (StringUtils.isNotBlank(startTime)){
            jsonBody.put("startTime", startTime);
            jsonBody.put("endTime", endTime);
        }
        if (StringUtils.isNotBlank(pageNo)){
            jsonBody.put("pageNo",pageNo);
            jsonBody.put("pageSize",pageSize);
        }
        String body = jsonBody.toJSONString();
        /**
         * STEP6：调用接口
         */
        String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , null);// post请求application/json类型参数
        System.out.println(result);
        /**
         * {
         *     "code": "0",
         *     "msg": "success",
         *     "data": {
         *         "total": 1,
         *         "pageNo": 1,
         *         "pageSize": 15,
         *         "list": [
         *             {
         *                 "regionIndexCode": "s7f0wef9-weuf0we0f",
         *                 "vehicleId": "as78da790sd99u29u9129uddav90s",
         *                 "plateNo": "浙A12345",
         *                 "cardNo": "6518959562033",
         *                 "personId": "as9du12d9219d1-2ud012d22d",
         *                 "personName": "Jack",
         *                 "categoryCode": "0ff8231a93604c4d849dad519451fb03",
         *                 "categoryName": "VIP车辆"
         *                 "validity": [
         *                     {
         *                         "parkSyscode": "gqwerg354g345g35g",
         *                         "parkName": "停车库1",
         *                         "functionTime": [
         *                             {
         *                                 "startTime": "2018-07-26",
         *                                 "endTime": "2018-07-27"
         *                             }
         *                         ]
         *                     }
         *                 ]
         *             }
         *         ]
         *     }
         * }
         */
        return result;
    }
}

