对接海康明眸门禁设备-周计划模板

对接海康明眸门禁设备-周计划模板

注意:一天最多支持八个时间段。
设备支持的模板数 和周计划数,通过设备能力集获取。

设置周计划模板

 /**
 *设置周计划模板
 *lUserID 登录句柄
 *weekDateList 自定义时间集合
 *iPlanTemplateNumber 模板id
 *templateName 模板名称
 *List paramLis 自定义人员信息集合
 */
hikvisionDeviceApiService.setWeeklyPlan(lUserID,weekDateList,iPlanTemplateNumber,templateName);
List<IotAddFaceParam> paramList = new ArrayList<>();
    // 修改人员信息  具体看前面文章添加用户(添加用户信息)
hikvisionDeviceApiService.addUserInfo(paramList,lUserID,String.valueOf(iPlanTemplateNumber));

修改用户采用的是添加用户方法:
URL为一下:
该方法用户存在时修改,不存在时新增。
具体看前面文章添加用户(添加用户信息)

String strUserInBuffer = "PUT /ISAPI/AccessControl/UserInfo/SetUp?format=json";

周计划权限

/**
     *设备周计划权限
     * 每一个计划模板可以关联一个周计划和一个假日组计划,假日计划的优先级高于周计划。
     * 周计划可以配置周一到周日的时间段,每天支持配置8个不同的时间段
     * @param lUserID              用户登录句柄
     * @param iPlanTemplateNumber 计划模板编号,从1开始,最大值从门禁能力集获取
     * templateName 模板名称
     * weekDateList 自定义时间集合
     *
     */
    public void setWeeklyPlan(int lUserID, List<IotWeekInfoParam> weekDateList, int iPlanTemplateNumber, String templateName) {
        if (lUserID == -1) {
            log.warn("登录失败,错误码为 :{}", hCNetSDK.NET_DVR_GetLastError());
        }
        //计划模板编号,从1开始,最大值从门禁能力集获取
//        int iPlanTemplateNumber = 6;
        //模板名称
//        String templateName = "周权限设置模板";
        //设置卡权限计划模板参数
        NET_DVR_PLAN_TEMPLATE_COND struPlanCond = new NET_DVR_PLAN_TEMPLATE_COND();
        struPlanCond.dwSize = struPlanCond.size();
        struPlanCond.dwPlanTemplateNumber = iPlanTemplateNumber;//计划模板编号,从1开始,最大值从门禁能力集获取
        struPlanCond.wLocalControllerID = 0;//就地控制器序号[1,64],0表示门禁主机
        struPlanCond.write();

        NET_DVR_PLAN_TEMPLATE struPlanTemCfg = new NET_DVR_PLAN_TEMPLATE();
        struPlanTemCfg.dwSize = struPlanTemCfg.size();
        struPlanTemCfg.byEnable = 1; //是否使能:0- 否,1- 是
        struPlanTemCfg.dwWeekPlanNo = 1;//周计划编号,0表示无效
        struPlanTemCfg.dwHolidayGroupNo[0] = 0;//假日组编号,按值表示,采用紧凑型排列,中间遇到0则后续无效
        byte[] byTemplateName;
        byTemplateName = templateName.getBytes(StandardCharsets.UTF_8);
        //计划模板名称
        for (int i = 0; i < IotHikNetConstant.NAME_LEN; i++) {
            struPlanTemCfg.byTemplateName[i] = 0;
        }
        System.arraycopy(byTemplateName, 0, struPlanTemCfg.byTemplateName, 0, byTemplateName.length);
        struPlanTemCfg.write();
        IntByReference pInt = new IntByReference(0);
        Pointer lpStatusList = pInt.getPointer();
        if (!hCNetSDK.NET_DVR_SetDeviceConfig(lUserID, IotHikNetConstant.NET_DVR_SET_CARD_RIGHT_PLAN_TEMPLATE_V50, 1, struPlanCond.getPointer(), struPlanCond.size(), lpStatusList, struPlanTemCfg.getPointer(), struPlanTemCfg.size())) {
            //设置模板参数失败
            log.warn("NET_DVR_SET_CARD_RIGHT_PLAN_TEMPLATE_V50失败,错误号:{},{}", hCNetSDK.NET_DVR_GetLastError(),IotHkExceptionEnum.getMsg(hCNetSDK.NET_DVR_GetLastError()));
        }

        //获取卡权限周计划参数
        NET_DVR_WEEK_PLAN_COND struWeekPlanCond = new NET_DVR_WEEK_PLAN_COND();
        struWeekPlanCond.dwSize = struWeekPlanCond.size();
        struWeekPlanCond.dwWeekPlanNumber = 2;
        struWeekPlanCond.wLocalControllerID = 0;
        NET_DVR_WEEK_PLAN_CFG struWeekPlanCfg = new NET_DVR_WEEK_PLAN_CFG();
        struWeekPlanCond.write();
        struWeekPlanCfg.write();
        Pointer lpCond = struWeekPlanCond.getPointer();
        Pointer lpInbuferCfg = struWeekPlanCfg.getPointer();
        if (!hCNetSDK.NET_DVR_GetDeviceConfig(lUserID, IotHikNetConstant.NET_DVR_GET_CARD_RIGHT_WEEK_PLAN_V50, 1, lpCond, struWeekPlanCond.size(), lpStatusList, lpInbuferCfg, struWeekPlanCfg.size())) {
            //获取周计划模板失败
            log.warn("NET_DVR_GET_CARD_RIGHT_WEEK_PLAN_V50失败,错误号:{},{}",hCNetSDK.NET_DVR_GetLastError(),IotHkExceptionEnum.getMsg(hCNetSDK.NET_DVR_GetLastError()));
            return;
        }
        struWeekPlanCfg.read();
        struWeekPlanCfg.byEnable = 1; //是否使能:0- 否,1- 是

        /**避免时间段交叉,先初始化, 七天八小时*/
        for (int i = 0; i < 7; i++) {
            for (int j = 0; j < 8; j++) {
                struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].byEnable = 0;
                struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].struTimeSegment.struBeginTime.byHour = 0;
                struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].struTimeSegment.struBeginTime.byMinute = 0;
                struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].struTimeSegment.struBeginTime.bySecond = 0;
                struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].struTimeSegment.struEndTime.byHour = 0;
                struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].struTimeSegment.struEndTime.byMinute = 0;
                struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].struTimeSegment.struEndTime.bySecond = 0;
            }
        }
        weekDateList.stream().sorted(Comparator.comparing(IotWeekInfoParam::getWeekNum));
        Map<Integer, IotWeekInfoParam> listMap = weekDateList.stream().collect(AbsCollector.toMap(IotWeekInfoParam::getWeekNum));
        // 一周七天
        for (int i = 0; i < 7; i++) {
            IotWeekInfoParam weekParam = listMap.get(i+1);
            if(ObjectUtil.isNull(weekParam)){
                defaultDateData(i,struWeekPlanCfg);
            } else {
                List<IotTimeQuanInfoParam> timeQuans = weekParam.getTimeQuan();
                if(CollUtil.isEmpty(timeQuans)){
                    defaultDateData(i,struWeekPlanCfg);
                }
                // 每天时间段
                for (int j= 0; j< timeQuans.size(); j++) {
                    IotTimeQuanInfoParam timeQuan = timeQuans.get(j);
                    if (ObjectUtil.isNull(timeQuan.getType()) || timeQuan.getType() == 2) {
                        struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].byEnable = 0;
                    } else {
                        struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].byEnable = 1;
                    }
                    List<Byte> startTimes = Arrays.stream(timeQuan.getStartTime().split(":")).map(Byte::valueOf).collect(Collectors.toList());
                    List<Byte> stopTimes = Arrays.stream(timeQuan.getStopTime().split(":")).map(Byte::valueOf).collect(Collectors.toList());
                    struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].struTimeSegment.struBeginTime.byHour = startTimes.get(0);
                    struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].struTimeSegment.struBeginTime.byMinute = startTimes.get(1);
                    struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].struTimeSegment.struBeginTime.bySecond = 0;
                    struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].struTimeSegment.struEndTime.byHour = stopTimes.get(0);
                    struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].struTimeSegment.struEndTime.byMinute = stopTimes.get(1);
                    struWeekPlanCfg.struPlanCfg[i].struPlanCfgDay[j].struTimeSegment.struEndTime.bySecond = 59;
                }
            }
        }

        struWeekPlanCfg.write();
        //设置卡权限周计划参数
        if (!hCNetSDK.NET_DVR_SetDeviceConfig(lUserID, IotHikNetConstant.NET_DVR_SET_CARD_RIGHT_WEEK_PLAN_V50, 1, lpCond, struWeekPlanCond.size(), lpStatusList, lpInbuferCfg, struWeekPlanCfg.size())) {
            //设置周计划参数失败
            log.info("NET_DVR_SET_CARD_RIGHT_WEEK_PLAN_V50失败,错误号:{},{}", hCNetSDK.NET_DVR_GetLastError(),IotHkExceptionEnum.getMsg(hCNetSDK.NET_DVR_GetLastError()));
        } else {info
            log.info("NET_DVR_SET_CARD_RIGHT_WEEK_PLAN_V50成功!");
        }

    }
public class IotWeekInfoParam implements Serializable {

    /**
     * 周 1-2-3
     */
    private Integer weekNum;

    /**
     * 时间
     */
    private List<IotTimeQuanInfoParam> timeQuan;

}
public class IotTimeQuanInfoParam implements Serializable {

    /**
     * 开始时间
     */
    private String startTime;
    /**
     * 结束时间
     */
    private String stopTime;
    /**
     * int 1表示允许通过  2禁止通行
     */
    private Integer type;

}

你可能感兴趣的:(海康,java)