本文主要是介绍对接海康明眸门禁设备-周计划模板,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
对接海康明眸门禁设备-周计划模板
注意:一天最多支持八个时间段。
设备支持的模板数 和周计划数,通过设备能力集获取。
设置周计划模板
/***设置周计划模板*lUserID 登录句柄*weekDateList 自定义时间集合*iPlanTemplateNumber 模板id*templateName 模板名称*List<IotAddFaceParam> 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 {infolog.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;}
这篇关于对接海康明眸门禁设备-周计划模板的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!