package com.community.commom.hk;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile;

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

/**
 * 海康 API
 * @author weiximei
 */
@Slf4j
public class HKOpenApi {

    /**
     * 根据
     * 组织中心UUID集 ,第几页, 一页多少行
     *
     * 获取  监控点 数据列表
     * @return
     */
    public static String getMonitoryPoint(Map<String,Object> map){
        Map<String,Object> parMap = Maps.newHashMap();
        String url = (map.get("openapi_ip_port_http") == null ? HKConstant.OPENAPI_IP_PORT_HTTP : map.get("openapi_ip_port_http")) + HKConstant.ITF_MONITORY_POINT;
        //设置APPKEY
        parMap.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        //设置时间参数
        parMap.put("time", System.currentTimeMillis());
        parMap.put("pageNo",map.get("pageNo"));
        parMap.put("pageSize",map.get("pageSize"));
        parMap.put("opUserUuid",map.get("opUserUuid") == null?HKConstant.OP_USER_UUID:map.get("opUserUuid"));
        parMap.put("unitUuids",map.get("unitUuids"));
        String params =  JSON.toJSONString(parMap);
        log.info("获取 监控列表 请求参数：{}", params);
        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params,map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("获取 监控列表 请求返回结果：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("获取监控列表失败!",e);
            throw new RuntimeException("获取监控列表失败!");
        }

        return data;
    }

    /**
     * 根据部门名称分页获取部门
     *      第几页, 一页多少行, 操作用户uuid
     * @param map
     * @return
     */
    public static String getDeptName(Map<String,Object> map){
        Map<String,Object> parMap = Maps.newHashMap();
        String url = (map.get("openapi_ip_port_http") == null ? HKConstant.OPENAPI_IP_PORT_HTTP : map.get("openapi_ip_port_http")) + HKConstant.ITF_LIKE_DEPT_NAME;
        //设置APPKEY
        parMap.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        //设置时间参数
        parMap.put("time", System.currentTimeMillis());
        parMap.put("pageNo",map.get("pageNo"));
        parMap.put("pageSize",map.get("pageSize"));
        parMap.put("opUserUuid",map.get("opUserUuid") == null?HKConstant.OP_USER_UUID:map.get("opUserUuid"));
        parMap.put("deptName",map.get("deptName"));
        String params =  JSON.toJSONString(parMap);
        log.info("根据部门名称分页获取部门 请求参数：{}", params);
        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params,map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("根据部门名称分页获取部门 请求返回结果：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("根据部门名称分页获取部门失败!",e);
            throw new RuntimeException("根据部门名称分页获取部门失败!");
        }

        return data;
    }


    /**
     * 添加人员
     *
     *      比如 住户
     * @return
     */
    public static String addUser(Map<String,Object> map){
        Map<String,Object> parMap = Maps.newHashMap();
        String url = (map.get("openapi_ip_port_http") == null ? HKConstant.OPENAPI_IP_PORT_HTTP : map.get("openapi_ip_port_http")) + HKConstant.ITF_ADD_USER;
        //设置APPKEY获取中心信息
        parMap.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        //设置时间参数
        parMap.put("time", System.currentTimeMillis());
        parMap.put("opUserUuid",map.get("opUserUuid") == null?HKConstant.OP_USER_UUID:map.get("opUserUuid"));
        parMap.put("personNo",map.get("personNo"));
        parMap.put("personName",map.get("personName"));
        parMap.put("phoneNo",map.get("phoneNo"));
        parMap.put("deptUuid",map.get("deptUuid"));
        // parMap.put("cardNo",map.get("cardNo"));
        String params =  JSON.toJSONString(parMap);
        log.info("添加人员 请求参数：{}", params);
        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params,map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("添加人员 请求返回结果：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("添加人员失败!",e);
            throw new RuntimeException("添加人员失败!");
        }

        return data;
    }

    /**
     * 批量开卡
     *
     * 其中参数 cardAndPerson 形式为“卡号，人员ID”，开卡数量不得超过50个，若没有该卡号，则添加一张新卡进行绑定 List<String>
     * @return
     */
    public static String openCard(Map<String,Object> map){
        Map<String,Object> parMap = Maps.newHashMap();
        String url = (map.get("openapi_ip_port_http") == null ? HKConstant.OPENAPI_IP_PORT_HTTP : map.get("openapi_ip_port_http")) + HKConstant.ITF_OPEN_CARD;
        //设置APPKEY
        parMap.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        //设置时间参数
        parMap.put("time", System.currentTimeMillis());
        parMap.put("opUserUuid",map.get("opUserUuid") == null?HKConstant.OP_USER_UUID:map.get("opUserUuid"));
        parMap.put("cardAndPerson",map.get("cardAndPerson"));
        parMap.put("startTime",map.get("startTime"));
        parMap.put("endTime",map.get("endTime"));
        parMap.put("subSystems","1048576,3145728,2097152,9437184,25165824,10485760");
        String params =  JSON.toJSONString(parMap);
        log.info("批量开卡 请求参数：{}", params);
        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params,map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("批量开卡 请求返回结果：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("批量开卡失败!",e);
            throw new RuntimeException("批量开卡失败!");
        }

        return data;
    }

    /**
     * 根据中心UUID集获取中心下的门禁设备信息
     *
     * @return
     */
    public static String getACDevicesByUnitUuids(Map<String, Object> map){
        Map<String,Object> parMap = Maps.newHashMap();
        String url = (map.get("openapi_ip_port_http") == null ? HKConstant.OPENAPI_IP_PORT_HTTP : map.get("openapi_ip_port_http")) + HKConstant.ITF_MONITORY_POINT;
        //设置APPKEY
        parMap.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        //设置时间参数
        parMap.put("time", System.currentTimeMillis());
        parMap.put("pageNo",1);
        parMap.put("pageSize",10);
        parMap.put("opUserUuid", map.get("opUserUuid") == null ? HKConstant.OP_USER_UUID : map.get("opUserUuid"));
        parMap.put("unitUuids","1048576");
        String params =  JSON.toJSONString(parMap);
        log.info("获取中心UUID集获取中心下的门禁设备请求参数：{}", params);
        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params,map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("获取 中心UUID集获取中心下的门禁设备 请求返回结果：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("获取失败!",e);
            throw new RuntimeException("获取失败!");
        }

        return data;
    }

    /**
     * 分页获取门禁点信息。
     *
     * @return
     */
    public static String getDoors(Map<String,Object> map){
        Map<String,Object> parMap = Maps.newHashMap();
        String url = (map.get("openapi_ip_port_http") == null ? HKConstant.OPENAPI_IP_PORT_HTTP : map.get("openapi_ip_port_http")) + HKConstant.GET_DOORS; // HKConstant.ITF_MONITORY_POINT;
        //设置APPKEY
        parMap.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        //设置时间参数
        parMap.put("time", System.currentTimeMillis());
        parMap.put("pageNo",1);
        parMap.put("pageSize",10);
        parMap.put("opUserUuid", map.get("opUserUuid") == null ? HKConstant.OP_USER_UUID : map.get("opUserUuid"));
        String params =  JSON.toJSONString(parMap);
        log.info("分页获取门禁点信息请求参数：{}", params);
        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params,map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("分页获取门禁点信息 请求返回结果：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("获取失败!",e);
            throw new RuntimeException("获取失败!");
        }

        return data;
    }

    /**
     * 批量获取控制中心信息，多个中心的UUID用“,”分割组成的字符串。
     *
     * @return
     */
    public static String getUnitsByUuids(Map<String,Object> map){
        Map<String,Object> parMap = Maps.newHashMap();
        String url = (map.get("openapi_ip_port_http") == null ? HKConstant.OPENAPI_IP_PORT_HTTP : map.get("openapi_ip_port_http")) + HKConstant.ITF_MONITORY_POINT;
        //设置APPKEY
        parMap.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        //设置时间参数
        parMap.put("time", System.currentTimeMillis());
        parMap.put("pageNo",1);
        parMap.put("pageSize",10);
        parMap.put("opUserUuid", map.get("opUserUuid") == null ? HKConstant.OP_USER_UUID : map.get("opUserUuid"));
        parMap.put("unitUuids","1048576");
        String params =  JSON.toJSONString(parMap);
        log.info("获取控制中心信息请求参数：{}", params);
        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params,map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("获取控制中心信息 请求返回结果：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("获取控制中心信息失败!",e);
            throw new RuntimeException("获取控制中心信息失败!");
        }

        return data;
    }

    /**
     *  根据中心UUID分页获取下级区域
     * @return
     */
    public static String getRegionsByUnitUuid(Map<String,Object> map){
        Map<String,Object> parMap = Maps.newHashMap();
        String url = (map.get("openapi_ip_port_http") == null ? HKConstant.OPENAPI_IP_PORT_HTTP : map.get("openapi_ip_port_http")) + HKConstant.ITF_MONITORY_POINT;
        //设置APPKEY
        parMap.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        //设置时间参数
        parMap.put("time", System.currentTimeMillis());
        parMap.put("pageNo",1);
        parMap.put("pageSize",10);
        parMap.put("opUserUuid", map.get("opUserUuid") == null ? HKConstant.OP_USER_UUID : map.get("opUserUuid"));
        parMap.put("parentUuid","1048576");
        parMap.put("allChildren",1);
        String params =  JSON.toJSONString(parMap);
        log.info("根据中心UUID分页获取下级区域请求参数：{}", params);
        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params,map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("根据中心UUID分页获取下级区域 请求返回结果：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("根据中心UUID分页获取下级区域获取失败!",e);
            throw new RuntimeException("根据中心UUID分页获取下级区域获取失败!");
        }

        return data;
    }

    /**
     * 根据区域UUID集获取门禁点
     * @return
     */
    public static String getDoorsByRegionUuids(Map<String,Object> map){
        Map<String,Object> parMap = Maps.newHashMap();
        String url = (map.get("openapi_ip_port_http") == null ? HKConstant.OPENAPI_IP_PORT_HTTP : map.get("openapi_ip_port_http")) + HKConstant.DOORS_BY_REGION_UUIDS;
        //设置APPKEY
        parMap.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        //设置时间参数
        parMap.put("time", System.currentTimeMillis());
        parMap.put("opUserUuid", map.get("opUserUuid") == null ? HKConstant.OP_USER_UUID : map.get("opUserUuid"));
        parMap.put("regionUuids","2a36878c9a4a49d290d253ac1b4746dc");
        String params =  JSON.toJSONString(parMap);
        log.info("根据区域UUID集获取门禁点请求参数：{}", params);
        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params,map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("根据区域UUID集获取门禁点 请求返回结果：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("根据区域UUID集获取门禁点获取失败!",e);
            throw new RuntimeException("根据区域UUID集获取门禁点获取失败!");
        }

        return data;
    }

    /**
     * 根据人员ID集添加权限
     * @return
     */
    public static String addAuthoritiesByPersonIds(Map<String, Object> map){
        Map<String,Object> parMap = Maps.newHashMap();
        String url = (map.get("openapi_ip_port_http") == null ? HKConstant.OPENAPI_IP_PORT_HTTP : map.get("openapi_ip_port_http")) + HKConstant.ADD_AUTHORITIES_BY_PERSONIDS;
        //设置APPKEY
        parMap.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        //设置时间参数
        parMap.put("time", System.currentTimeMillis());
        parMap.put("opUserUuid", map.get("opUserUuid") == null ? HKConstant.OP_USER_UUID : map.get("opUserUuid"));
        parMap.put("personIds",map.get("personIds"));
        parMap.put("doorGroupUuids","");
        // TODO 目前写死
        // parMap.put("doorUuids","91b8ce635b634d468cde925af6e4274c,d40b23e316364bb5a276b99bb6327181,7f866e918ab8452f9eb1d8a25e481530,8b8256fc605d428c9dc797451e3dc432,84d619c5e84942f68047f0bca93fc041");
        parMap.put("doorUuids",map.get("doorUuids"));
        String params =  JSON.toJSONString(parMap);
        log.info("根据人员ID集添加权限请求参数：{}", params);
        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params, map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("根据人员ID集添加权限 请求返回结果：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("根据人员ID集添加权限!",e);
            throw new RuntimeException("根据人员ID集添加权限!");
        }

        return data;
    }

    /**
     * 根据设备UUID集异动下载门禁权限
     * @return
     */
    public static String downloadAuthorityByDeviceUuids(Map<String,Object> map){
        Map<String,Object> parMap = Maps.newHashMap();
        String url = (map.get("openapi_ip_port_http") == null ? HKConstant.OPENAPI_IP_PORT_HTTP : map.get("openapi_ip_port_http")) + HKConstant.DOWNLOAD_AUTHORITY_BY_DEVICEUUIDS;
        //设置APPKEY
        parMap.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        //设置时间参数
        parMap.put("time", System.currentTimeMillis());
        parMap.put("opUserUuid", map.get("opUserUuid") == null ? HKConstant.OP_USER_UUID : map.get("opUserUuid"));
        // TODO 目前写死
        parMap.put("deviceUuids","fe471fe7c95f408a9e41e029dc0687cf,fe471fe7c95f408a9e41e029dc0687cf,992f53f2c87b4d2a87cf517e7b57366f,a792802b88f749c9b4c6fbf8a610111e,3bff3477889c4b3c983871ea46b66605");
        String params =  JSON.toJSONString(parMap);
        log.info("根据设备UUID集异动下载门禁权限请求参数：{}", params);
        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params, map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("根据设备UUID集异动下载门禁权限 请求返回结果：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("根据设备UUID集异动下载门禁权限获取失败!",e);
            throw new RuntimeException("根据设备UUID集异动下载门禁权限获取失败!");
        }

        return data;
    }

    /**
     * 指定人员的门禁权限下载
     *
     * @param map
     * @return
     */
    public static String downloadAuthorityByPersonIds(Map<String,Object> map){
        Map<String,Object> parMap = Maps.newHashMap();
        String url = (map.get("openapi_ip_port_http") == null ? HKConstant.OPENAPI_IP_PORT_HTTP : map.get("openapi_ip_port_http")) + HKConstant.DOWNLOAD_AUTHORITY_BY_PERSONIDS;
        //设置APPKEY
        parMap.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        //设置时间参数
        parMap.put("time", System.currentTimeMillis());
        parMap.put("opUserUuid", map.get("opUserUuid") == null ? HKConstant.OP_USER_UUID : map.get("opUserUuid"));
        parMap.put("personIds",map.get("personIds"));
        // parMap.put("doorUuids","efcb9a3fe4e64e2f9c0f546c54465524,94bac7e217fb4a698ad086876d347c6a,369b49476a364f87b1c50e99435ecca8,22d8a043cd3f41c5bf1bd976ab5ee65d");
        parMap.put("doorUuids",map.get("doorUuids"));
        parMap.put("planUuid","plan0000000000000000000000000001");
        parMap.put("operateType",map.get("operateType"));
        parMap.put("includeFinger",map.get("includeFinger"));
        String params =  JSON.toJSONString(parMap);
        log.info("指定人员的门禁权限下载请求参数：{}", params);
        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params, map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("指定人员的门禁权限下载 请求返回结果：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("指定人员的门禁权限下载获取失败!",e);
            throw new RuntimeException("指定人员的门禁权限下载获取失败!");
        }

        return data;
    }

    /**
     * 分页获取计划模板
     *
     * @param pageNo 第几页
     * @param pageSize 一页多少行
     * @return
     */
    public static String getPlans(Integer pageNo, Integer pageSize, Map<String, Object> map) {

        Map<String,Object> parMap = Maps.newHashMap();
        String url = (map.get("openapi_ip_port_http") == null ? HKConstant.OPENAPI_IP_PORT_HTTP : map.get("openapi_ip_port_http")) + HKConstant.GETPLANS;
        //设置APPKEY
        parMap.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        //设置时间参数
        parMap.put("time", System.currentTimeMillis());
        parMap.put("opUserUuid", map.get("opUserUuid") == null ? HKConstant.OP_USER_UUID : map.get("opUserUuid"));
        parMap.put("pageNo",pageNo);
        parMap.put("pageSize",pageSize);
        String params =  JSON.toJSONString(parMap);
        log.info("分页获取计划模板请求参数：{}", params);
        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params,map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("获取 分页获取计划模板 请求返回结果：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("分页获取计划模板获取失败!",e);
            throw new RuntimeException("分页获取计划模板获取失败!");
        }

        return data;
    }

    /**
     * 指定人员人脸/指纹权限下载
     * @return
     */
    public static String downloadFaceAndFingerInfos(Map<String, Object> map){
        Map<String,Object> parMap = Maps.newHashMap();
        String url = (map.get("openapi_ip_port_http") == null ? HKConstant.OPENAPI_IP_PORT_HTTP : map.get("openapi_ip_port_http")) + HKConstant.DOWNLOAD_FACE_AND_FINGERINFOS;
        //设置APPKEY
        parMap.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        //设置时间参数
        parMap.put("time", System.currentTimeMillis());
        parMap.put("opUserUuid", map.get("opUserUuid") == null ? HKConstant.OP_USER_UUID : map.get("opUserUuid"));
        // TODO 目前写死的
        // parMap.put("deviceUuids","992f53f2c87b4d2a87cf517e7b57366f,a792802b88f749c9b4c6fbf8a610111e,3bff3477889c4b3c983871ea46b66605");
        parMap.put("deviceUuids",map.get("deviceUuids"));
        parMap.put("personIds",map.get("personIds"));
        parMap.put("type",map.get("type"));
        String params =  JSON.toJSONString(parMap);
        log.info("指定人员人脸/指纹权限下载 请求参数：{}", params);
        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params,map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("指定人员人脸/指纹权限下载 请求返回结果：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("指定人员人脸/指纹权限下载获取失败!",e);
            throw new RuntimeException("指定人员人脸/指纹权限下载获取失败!");
        }

        return data;
    }
    /**
     * 添加人脸
     * faceImg 图片
     * personNo 人员编号
     * personName 名称
     * @return
     */
    public static String HKpersonGroupId(MultipartFile faceImg,Integer personNo,String personName, String openapi_ip_port_http){
        String url = (openapi_ip_port_http == null ? HKConstant.OPENAPI_IP_PORT_HTTP : openapi_ip_port_http) + HKConstant.ITF_ADD_USER;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        map.put("time", System.currentTimeMillis());
        map.put("token", map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret")));
        map.put("opUserUuid", map.get("opUserUuid") == null ? HKConstant.OP_USER_UUID : map.get("opUserUuid"));
        map.put("personNo",personNo);
        map.put("personName",personName);
        String params =  JSON.toJSONString(map);
        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params,map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("添加人脸失败!");
        }
        return data;
    }


    /**
     * 修改人脸
     * faceImg 图片
     * personId人员ID
     * personNo 人员编号
     * personName 名称
     *  * personName 卡号
     * @return
     */
    public static String HKpersonGroupId(MultipartFile faceImg,Integer personId,Long personNo,String personName,String cardNo, String  appkey, String secret, String openapi_ip_port_http) {
        byte [] fileByte = new byte[0];
        try {
            if (null!=faceImg) {
                fileByte = faceImg.getBytes();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        byte[] imgs=PicUtils.compressPicForScale(fileByte,99L,"x");

        String img = PicUtils.getImgStr(imgs);
        String url = openapi_ip_port_http == null  ? HKConstant.OPENAPI_IP_PORT_HTTP : openapi_ip_port_http + HKConstant.ITF_UPDATE_USER;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("appkey", appkey == null?HKConstant.APPKEY:appkey);
        map.put("time", System.currentTimeMillis());
//        map.put("token",map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret")));
        map.put("opUserUuid", HKConstant.OP_USER_UUID);
        map.put("personId", personId);
        map.put("personNo", personNo);
        map.put("personName", personName);
        map.put("facePhoto", img);
        map.put("cardNo", cardNo);
        String params = JSON.toJSONString(map);
        log.info("修改人脸 请求参数：{}",params);
        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params, secret == null ? HKConstant.SECRET : secret), params);
            log.info("修改人脸请求结果：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("修改人脸 请求失败：{}",e);
            throw new RuntimeException("修改人脸失败!");
        }

        return data;
    }

    /**
     * 修改人员
     *
     *  比如 住户
     *
     * @return
     */
    public static String updateUser(Map<String,Object> map) {
        String url = (map.get("openapi_ip_port_http") == null ? HKConstant.OPENAPI_IP_PORT_HTTP : map.get("openapi_ip_port_http")) + HKConstant.ITF_UPDATE_USER;
        Map<String, Object> parMap = new HashMap<String, Object>();
        //设置APPKEY
        parMap.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        //设置时间参数
        parMap.put("time", System.currentTimeMillis());
        parMap.put("opUserUuid",map.get("opUserUuid") == null?HKConstant.OP_USER_UUID:map.get("opUserUuid"));
        parMap.put("personNo",map.get("personNo"));
        parMap.put("personId",map.get("personId"));
        parMap.put("personName",map.get("personName"));
        parMap.put("phoneNo",map.get("phoneNo"));
        parMap.put("deptUuid",map.get("deptUuid"));
        String params =  JSON.toJSONString(parMap);
        log.info("修改人员 请求参数：{}", params);
        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params,map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("修改人员 请求返回结果：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("修改加人员失败!",e);
            throw new RuntimeException("修改加人员失败!");
        }
        return data;
    }


    /**
     * 未预约登记
     * @param visitorName 访客姓名
     * @param phoneNo 联系电话
     * @param personNum 来访人数
     * @param startTime 来访时间
     * @param endTime 离开时间
     * @param personId 被访人ID
     * @return
     */
    public static String temporaryRegister(String visitorName, String phoneNo,Integer personNum,Long startTime,Long endTime,Integer personId, String opUserUuid, String appkey, String secret, String openapi_ip_port_http){
        Map<String,Object> parMap = Maps.newHashMap();
        String url = (openapi_ip_port_http == null ? HKConstant.OPENAPI_IP_PORT_HTTP : openapi_ip_port_http) + HKConstant.TEMPORARY_REGISTER;
        //设置APPKEY
        parMap.put("appkey", appkey == null?HKConstant.APPKEY:appkey);
        //设置时间参数
        parMap.put("time", System.currentTimeMillis());
        parMap.put("opUserUuid", opUserUuid == null ? HKConstant.OP_USER_UUID : opUserUuid);
        
        parMap.put("visitorName",visitorName);
        parMap.put("gender",1);
        parMap.put("identityType",0);
        parMap.put("phoneNo",phoneNo);
        parMap.put("personNum",personNum);
        parMap.put("startTime",startTime);
        parMap.put("endTime",endTime);
        parMap.put("isVip",0);
        parMap.put("personId",personId);
        String params =  JSON.toJSONString(parMap);
        log.info("未预约登记 请求参数：{}", params);
        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params, secret == null ? HKConstant.SECRET : secret), params);
            log.info("未预约登记 请求返回结果：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("获取失败!",e);
            throw new RuntimeException("获取失败!");
        }
    
        return data;
    }


    /**
     * 修改电话推送海康
     * @param personId 人员ID
     * @param personNo 人员编号
     * @param personName 姓名
     * @param phoneNo 电话
     * @return
     */
    public static String HKpersonPhone(Integer personId,Long personNo,String personName,String phoneNo, String openapi_ip_port_http) {

        String url = (openapi_ip_port_http == null ? HKConstant.OPENAPI_IP_PORT_HTTP : openapi_ip_port_http) + HKConstant.ITF_UPDATE_USER;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        map.put("time", System.currentTimeMillis());
//        map.put("token", HKConstant.SECRET);
        map.put("opUserUuid", HKConstant.OP_USER_UUID);
        map.put("personId", personId);
        map.put("personNo", personNo);
        map.put("personName", personName);
        map.put("phoneNo", phoneNo);
        String params = JSON.toJSONString(map);
        log.info("修改电话 请求参数：{}",params);
        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params, map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("修改电话请求结果：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("修改电话 请求失败：{}",e);
            throw new RuntimeException("修改电话失败!");
        }
        return data;
    }

    /**
     * 可视对讲 根据中心UUID集分页获取门口机
     *
     * pageNo 当前页码
     *
     * pageSize 每页数据记录数 建议400以下，不超过1000
     *
     * opUserUuid 操作用户UUID 详见opUserUuid的获取
     *
     * unitUuids 单元中心UUID集 以“,”分割，详见组织管理
     *
     *
     * @param map
     * @return
     */
    public static String HKgetDoorDevicesByUnitUuids(Map<String, Object> map){

        String url = (map.get("openapi_ip_port_http") == null ? HKConstant.OPENAPI_IP_PORT_HTTP : map.get("openapi_ip_port_http")) + HKConstant.GETDOORDEVICESBYUNITUUIDS;
        Map<String, Object> parMap = new HashMap<>();
        parMap.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        parMap.put("time", System.currentTimeMillis());
        parMap.put("pageNo", map.get("pageNo"));
        parMap.put("pageSize", map.get("pageSize"));
        parMap.put("opUserUuid", map.get("opUserUuid") == null?HKConstant.OP_USER_UUID:map.get("opUserUuid"));
        parMap.put("unitUuids", map.get("unitUuids"));

        String params = JSON.toJSONString(parMap);
        log.info("可视对讲 根据中心UUID集分页获取门口机 请求参数：{}",params);

        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params,map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("可视对讲 根据中心UUID集分页获取门口机：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("可视对讲 根据中心UUID集分页获取门口机 请求失败：{}",e);
            throw new RuntimeException("可视对讲 根据中心UUID集分页获取门口机失败!");
        }
        return data;

    }

    /**
     * 可视对讲 异步反控开门【V2.8.2】
     *
     * opUserUuid 操作用户UUID 详见opUserUuid的获取
     *
     * longNums 设备编号集 门口机设备编号集，以“,”分割
     *
     *
     * @param map
     * @return
     */
    public static String syncControl(Map<String, Object> map) {
        String url =  (map.get("openapi_ip_port_http") == null ? HKConstant.OPENAPI_IP_PORT_HTTP : map.get("openapi_ip_port_http")) +  HKConstant.SYNCCONTROL;
        Map<String, Object> parMap = new HashMap<>();
        parMap.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        parMap.put("time", System.currentTimeMillis());
        parMap.put("opUserUuid", map.get("opUserUuid") == null?HKConstant.OP_USER_UUID:map.get("opUserUuid"));
        parMap.put("longNums", map.get("longNums"));

        String params = JSON.toJSONString(parMap);
        log.info("可视对讲 异步反控开门 请求参数：{}",params);

        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params,map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("可视对讲 异步反控开门：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("可视对讲 异步反控开门 请求失败：{}",e);
            throw new RuntimeException("可视对讲 异步反控开门失败!");
        }
        return data;
    }

    /**
     * 可视对讲人脸权限下发
     * @param opUserUuid
     * @param opType
     * @param personIds
     * @param longNums
     * @return
     */
    public static String visualIntercom(String opUserUuid, Integer opType,List<Integer> personIds,List<String> longNums, String appkey, String secret, String openapi_ip_port_http) {
        String url = (openapi_ip_port_http == null ? HKConstant.OPENAPI_IP_PORT_HTTP : openapi_ip_port_http) + HKConstant.DOWNLOADFACE;
        HashMap map = new HashMap<>();
        map.put("appkey", appkey == null?HKConstant.APPKEY:appkey);
        map.put("time", System.currentTimeMillis());
        map.put("opUserUuid", opUserUuid == null ? HKConstant.OP_USER_UUID : opUserUuid);
        map.put("opType", opType);
        map.put("personIds", personIds);
        map.put("longNums", longNums);
        String param = JSON.toJSONString(map);
        log.info("人脸下发请求参数:" + param);
        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + param, param,secret == null ? HKConstant.SECRET : secret), param);
            log.info("可视对讲人脸权限下发：{}", data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("可视对讲人脸权限下发错误：{}", e);
            throw new RuntimeException("下发错误!");
        }
        return null;
    }
    /**
     * 可视对讲 根据人员 ID 集添加权限并下发
     *
     * opUserUuid 操作用户 UUID String 是
     * authName 权限组名称 String 是
     * personIds 人员 ID 集合 List<Integer>是 不超过 400
     * longNums 设备长号集合 List<String>是 不超过 400
     *
     * @param map
     * @return
     */
    public static String addOutDoorAuth(Map<String, Object> map) {
        String url = (map.get("openapi_ip_port_http") == null ? HKConstant.OPENAPI_IP_PORT_HTTP : map.get("openapi_ip_port_http")) + HKConstant.ADDOUTDOORAUTH;

        Map<String, Object> parMap = new HashMap<>();
        parMap.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        parMap.put("time", System.currentTimeMillis());
        parMap.put("opUserUuid", map.get("opUserUuid") == null?HKConstant.OP_USER_UUID:map.get("opUserUuid"));
        parMap.put("authName", map.get("authName"));
        parMap.put("personIds", map.get("personIds"));
        parMap.put("longNums", map.get("longNums"));

        String params = JSON.toJSONString(parMap);
        log.info("可视对讲 根据人员 ID 集添加权限并下发 请求参数：{}",params);

        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params,map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("可视对讲 根据人员 ID 集添加权限并下发：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("可视对讲 根据人员 ID 集添加权限并下发 请求失败：{}",e);
            throw new RuntimeException("可视对讲 根据人员 ID 集添加权限并下发失败!");
        }
        return data;
    }

    /**
     * 可视对讲 根据人员 ID 集删除权限并下发
     *
     * opUserUuid 操作用户 UUID String 是
     * operateType  操作类型 Integer 是 2 为根据人员-门口机删除权限 (忽略不写, 方法里面已经写上)
     * personIds 人员 ID 集合 List<Integer>是 不超过 400
     * longNums 设备长号集合 List<String>是 不超过 400
     *
     * @param map
     * @return
     */
    public static String delOutDoorAuth(Map<String, Object> map) {
        String url = (map.get("openapi_ip_port_http") == null ? HKConstant.OPENAPI_IP_PORT_HTTP : map.get("openapi_ip_port_http")) + HKConstant.DELOUTDOORAUTH;

        Map<String, Object> parMap = new HashMap<>();
        parMap.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        parMap.put("time", System.currentTimeMillis());
        parMap.put("opUserUuid", map.get("opUserUuid") == null?HKConstant.OP_USER_UUID:map.get("opUserUuid"));
        parMap.put("operateType", 2);
        parMap.put("personIds", map.get("personIds"));
        parMap.put("longNums", map.get("longNums"));

        String params = JSON.toJSONString(parMap);
        log.info("可视对讲 根据人员 ID 集删除权限并下发 请求参数：{}",params);

        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params,map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("可视对讲 根据人员 ID 集删除权限并下发：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("可视对讲 根据人员 ID 集删除权限并下发 请求失败：{}",e);
            throw new RuntimeException("可视对讲 根据人员 ID 集删除权限并下发失败!");
        }
        return data;
    }

    /**
     * 可视对讲 指定人员指纹权限下载
     *
     * opUserUuid 操作用户 UUID String 是
     * opType 操作类型 Integer 是 1 为下发权限；2 为删除权限
     * personIds 人员 ID 集合 List<Integer>是 不超过 400
     * longNums 设备长号集合 List<String>是 不超过 400
     *
     * @param map
     * @return
     */
    public static String downloadFinger(Map<String, Object> map) {
        String url = (map.get("openapi_ip_port_http") == null ? HKConstant.OPENAPI_IP_PORT_HTTP : map.get("openapi_ip_port_http")) + HKConstant.DOWNLOADFINGER;

        Map<String, Object> parMap = new HashMap<>();
        parMap.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        parMap.put("time", System.currentTimeMillis());
        parMap.put("opUserUuid", map.get("opUserUuid") == null?HKConstant.OP_USER_UUID:map.get("opUserUuid"));
        parMap.put("opType", map.get("opType"));
        parMap.put("personIds", map.get("personIds"));
        parMap.put("longNums", map.get("longNums"));

        String params = JSON.toJSONString(parMap);
        log.info("可视对讲 指定人员指纹权限下载 请求参数：{}",params);

        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params,map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("可视对讲 指定人员指纹权限下载：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("可视对讲 指定人员指纹权限下载 请求失败：{}",e);
            throw new RuntimeException("可视对讲 指定人员指纹权限下载失败!");
        }
        return data;
    }

    /**
     * 分页获取用户
     * @param map
     * @return
     */
    public static String getUsers(Map<String, Object> map){
        String url = (map.get("openapi_ip_port_http") == null ? HKConstant.OPENAPI_IP_PORT_HTTP : map.get("openapi_ip_port_http")) + HKConstant.GETUSERS;
        Map<String, Object> parMap = new HashMap<>();
        parMap.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        parMap.put("time", System.currentTimeMillis());
        parMap.put("opUserUuid", map.get("opUserUuid") == null?HKConstant.OP_USER_UUID:map.get("opUserUuid"));
        parMap.put("pageNo", map.get("pageNo"));
        parMap.put("pageSize", map.get("pageSize"));

        String params = JSON.toJSONString(parMap);
        log.info("分页获取用户 请求参数：{}",params);

        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params,map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("分页获取用户下载：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("分页获取用户 请求失败：{}",e);
            throw new RuntimeException("分页获取用户失败!");
        }
        return data;
    }

    /**
     * 分页获取人员
     * @param map
     * @return
     */
    public static String getPersonInfosEx(Map<String, Object> map){
        String url = (map.get("openapi_ip_port_http") == null ? HKConstant.OPENAPI_IP_PORT_HTTP : map.get("openapi_ip_port_http")) + HKConstant.GETPERSONINFOSEX;
        Map<String, Object> parMap = new HashMap<>();
        parMap.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        parMap.put("time", System.currentTimeMillis());
        parMap.put("opUserUuid", map.get("opUserUuid") == null?HKConstant.OP_USER_UUID:map.get("opUserUuid"));
        parMap.put("pageNo", map.get("pageNo"));
        parMap.put("pageSize", map.get("pageSize"));

        String params = JSON.toJSONString(parMap);
        log.info("分页获取人员 请求参数：{}",params);

        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params,map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("分页获取人员下载：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("分页获取人员 请求失败：{}",e);
            throw new RuntimeException("分页获取人员失败!");
        }
        return data;
    }

    /**
     *  获取默认用户UUID
     * @return
     */
    public static String getDefaultUserUuid(String appkey, String secret, String openapi_ip_port_http){
        Map<String,Object> parMap = Maps.newHashMap();
        String url = (openapi_ip_port_http == null ? HKConstant.OPENAPI_IP_PORT_HTTP : openapi_ip_port_http) + HKConstant.ITF_ADDRESS_GET_DEFAULT_USER_UUID;
        //设置APPKEY
        parMap.put("appkey", appkey == null?HKConstant.APPKEY:appkey);
        //设置时间参数
        parMap.put("time", System.currentTimeMillis());
        String params =  JSON.toJSONString(parMap);
        log.info("获取 获取默认用户UUID 请求参数：{}", params);
        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params, secret == null ? HKConstant.SECRET :  secret), params);
            log.info("获取 获取默认用户UUID 请求返回结果：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("获取获取默认用户UUID失败!",e);
            throw new RuntimeException("获取获取默认用户UUID失败!");
        }

        return data;
    }

    public static void main(String[] args) {
        // getDefaultUserUuid();
        //Map<String,Object> parMap = Maps.newHashMap();
        //String url = "http://pingtai.vipgz1.idcfengye.com" + HKConstant.ITF_MONITORY_POINT;
        ////设置APPKEY
        //parMap.put("appkey", "d30396a0");
        ////设置时间参数
        //parMap.put("time", System.currentTimeMillis());
        //parMap.put("pageNo","1");
        //parMap.put("pageSize","100");
        //parMap.put("opUserUuid","5b2eb534696b11e89c2e438f92627767");
        //parMap.put("unitUuids","1048576");
        //String params =  JSON.toJSONString(parMap);
        //log.info("获取 监控列表 请求参数：{}", params);
        //String data = null;
        //try {
        //    data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params, "6a939cf0b2914004a2755e70c6c96e02"), params);
        //    log.info("获取 监控列表 请求返回结果：{}",data);
        //} catch (Exception e) {
        //    e.printStackTrace();
        //    log.error("获取监控列表失败!",e);
        //    throw new RuntimeException("获取监控列表失败!");
        //}
        //getDoorsByRegionUuids();
    }
    /**
     *     删除当前人脸设备信息
     */
    public static String deleteUser(Map<String,Object> map) {
        String url = (map.get("openapi_ip_port_http") == null ? HKConstant.OPENAPI_IP_PORT_HTTP : map.get("openapi_ip_port_http")) + HKConstant.ITF_DELETE_USER;
        Map<String, Object> parMap = new HashMap<String, Object>();
        //设置APPKEY
        parMap.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        //设置时间参数
        parMap.put("time", System.currentTimeMillis());
        parMap.put("opUserUuid", map.get("opUserUuid") == null ? HKConstant.OP_USER_UUID : map.get("opUserUuid"));
        parMap.put("personIds",map.get("personIds"));
        // parMap.put("doorUuids","91b8ce635b634d468cde925af6e4274c,d40b23e316364bb5a276b99bb6327181,7f866e918ab8452f9eb1d8a25e481530,8b8256fc605d428c9dc797451e3dc432,84d619c5e84942f68047f0bca93fc041");
        parMap.put("doorUuids",map.get("doorUuids"));
        String params =  JSON.toJSONString(parMap);
        log.info("删除人脸 请求参数：{}", params);
        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params,map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("删除人脸 请求返回结果：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("删除人脸失败!",e);
            throw new RuntimeException("删除人脸失败!");
        }
        return data;
    }


    /**
     *     查询当前人脸设备信息
     */
    public static String selectUserFace(Map<String,Object> map) {
        String url = (map.get("openapi_ip_port_http") == null ? HKConstant.OPENAPI_IP_PORT_HTTP : map.get("openapi_ip_port_http")) + HKConstant.ITF_SELECT_USER;
        Map<String, Object> parMap = new HashMap<String, Object>();
        //设置APPKEY
        parMap.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        //设置时间参数
        parMap.put("time", System.currentTimeMillis());
        parMap.put("pageNo",1);
        parMap.put("pageSize",300);
        parMap.put("opUserUuid", map.get("opUserUuid") == null ? HKConstant.OP_USER_UUID : map.get("opUserUuid"));
        parMap.put("personIds",map.get("personIds"));
        String params =  JSON.toJSONString(parMap);
        log.info("查询设备人脸 请求参数：{}", params);
        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params,map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("查询设备人脸 请求返回结果：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("查询设备人脸失败!",e);
            throw new RuntimeException("查询设备人脸失败!");
        }
        return data;
    }

    /**
     * 人员异动（同步硬件）
     * @return
     */
    public static String selectUserSynchronization(Map<String,Object> map) {
        String url = (map.get("openapi_ip_port_http") == null ? HKConstant.OPENAPI_IP_PORT_HTTP : map.get("openapi_ip_port_http")) + HKConstant.ITF_SELECT_USER_SDH;
        Map<String, Object> parMap = new HashMap<String, Object>();
        //设置APPKEY
        parMap.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        //设置时间参数
        parMap.put("time", System.currentTimeMillis());
        parMap.put("opUserUuid", map.get("opUserUuid") == null ? HKConstant.OP_USER_UUID : map.get("opUserUuid"));
        parMap.put("deviceUuids","91b8ce635b634d468cde925af6e4274c,d40b23e316364bb5a276b99bb6327181,7f866e918ab8452f9eb1d8a25e481530,8b8256fc605d428c9dc797451e3dc432,84d619c5e84942f68047f0bca93fc041");
        String params =  JSON.toJSONString(parMap);
        log.info("人员异动 请求参数：{}", params);
        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params,map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("人员异动 请求返回结果：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("人员异动失败!",e);
            throw new RuntimeException("人员异动失败!");
        }
        return data;
    }

    /**
     * 指定人员的门禁权限下载 == 人员异动 - 风险太大不可控（同步硬件）
     * @return
     */
    public static String appointJurisdiction(Map<String,Object> map) {
        String url = (map.get("openapi_ip_port_http") == null ? HKConstant.OPENAPI_IP_PORT_HTTP : map.get("openapi_ip_port_http")) + HKConstant.ITF_SELECT_APPOIN;
        Map<String, Object> parMap = new HashMap<String, Object>();
        //设置APPKEY
        parMap.put("appkey", map.get("appkey") == null?HKConstant.APPKEY:map.get("appkey"));
        //设置时间参数
        parMap.put("time", System.currentTimeMillis());
        parMap.put("opUserUuid", map.get("opUserUuid") == null ? HKConstant.OP_USER_UUID : map.get("opUserUuid"));
        parMap.put("personIds", map.get("personIds"));
        // parMap.put("doorUuids","91b8ce635b634d468cde925af6e4274c,d40b23e316364bb5a276b99bb6327181,7f866e918ab8452f9eb1d8a25e481530,8b8256fc605d428c9dc797451e3dc432,84d619c5e84942f68047f0bca93fc041");
        parMap.put("doorUuids", map.get("doorUuids"));
        parMap.put("planUuid","plan0000000000000000000000000001");
//        parMap.put("operateType",3);
//        parMap.put("includeFinger",0);
        parMap.put("operateType",map.get("operateType"));
        parMap.put("includeFinger",map.get("includeFinger"));
        String params =  JSON.toJSONString(parMap);
        log.info("指定人员的门禁权限下载(同步设备) 请求参数：{}", params);
        String data = null;
        try {
            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params, map.get("secret") == null ? HKConstant.SECRET : String.valueOf(map.get("secret"))), params);
            log.info("指定人员的门禁权限下载(同步设备)：{}",data);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("指定人员的门禁权限下载(同步设备)失败!",e);
            throw new RuntimeException("指定人员的门禁权限下载(同步设备)异动失败!");
        }
        return data;
    }

}