380 lines
12 KiB
Go
380 lines
12 KiB
Go
package iot
|
||
|
||
import (
|
||
"encoding/json"
|
||
"fmt"
|
||
|
||
"myschools.me/suguo/hikvision/iot/model"
|
||
)
|
||
|
||
// 周计划模板添加/更新 customPlanId不存在 新增,存在更新
|
||
func PLANWeekTempleteCreateOrUpdate(customplanid string, enable bool, weekplan []model.PlanWeek) (*model.Hikvision, error) {
|
||
req := &model.PlanWeekRow{
|
||
CustomPlanId: customplanid,
|
||
Enable: enable,
|
||
WeekPlan: weekplan,
|
||
}
|
||
|
||
resp, err := hikvisionRequest("POST", "/api/v1/open/access/plans/weeks", req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result *model.Hikvision
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return result, nil
|
||
}
|
||
|
||
// 获取所有周计划模板
|
||
func PLANWeekTempleteGetAll(pageNo, pageSize int) (*model.PlanWeekDetail, error) {
|
||
url := fmt.Sprintf("/api/v1/open/access/plans/weeks?pageNo=%d&pageSize=%d", pageNo, pageSize)
|
||
resp, err := hikvisionRequest("GET", url, nil)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result = &model.PlanWeekDetail{}
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return result, nil
|
||
}
|
||
|
||
// 周计划模板删除
|
||
func PLANWeekTempleteDelete(customplanid string) (*model.Hikvision, error) {
|
||
url := fmt.Sprintf("/api/v1/open/access/plans/weeks?customPlanId=%s", customplanid)
|
||
resp, err := hikvisionRequest("DELETE", url, nil)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result = &model.Hikvision{}
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return result, nil
|
||
}
|
||
|
||
// 假日计划模板添加/更新 时间格式为 2019-08-09
|
||
func PLANHolidayTempleteCreateOrUpdate(customplanid string, enable bool, begindate, enddate string, plan []model.PlanPort) (*model.Hikvision, error) {
|
||
req := &model.PlanHolidayRow{
|
||
CustomPlanId: customplanid,
|
||
Enable: enable,
|
||
BeginDate: begindate,
|
||
EndDate: enddate,
|
||
HolidayPlan: plan,
|
||
}
|
||
|
||
resp, err := hikvisionRequest("POST", "/api/v1/open/access/plans/holidays", req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result *model.Hikvision
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return result, nil
|
||
}
|
||
|
||
// 假日计划模板获取
|
||
func PLANHolidayTempleteGetAll(pageNo, pageSize int) (*model.PlanHolidayDetail, error) {
|
||
url := fmt.Sprintf("/api/v1/open/access/plans/holidays?pageNo=%d&pageSize=%d", pageNo, pageSize)
|
||
resp, err := hikvisionRequest("GET", url, nil)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result = &model.PlanHolidayDetail{}
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return result, nil
|
||
}
|
||
|
||
// 假日计划模板删除
|
||
func PLANHolidayTempleteDelete(customplanid string) (*model.Hikvision, error) {
|
||
url := fmt.Sprintf("/api/v1/open/access/plans/holidays?customPlanId=%s", customplanid)
|
||
resp, err := hikvisionRequest("DELETE", url, nil)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result = &model.Hikvision{}
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return result, nil
|
||
}
|
||
|
||
// 周计划配置
|
||
//
|
||
// 配置设备的周计划
|
||
func PlanWeekConfigSet(configtype, deviceid string, planno int, customplanid string) (*model.Hikvision, error) {
|
||
req := &struct {
|
||
ConfigType string `json:"configType"` //userRight-人员权限
|
||
DeviceId string `json:"deviceId"` //设备id
|
||
PlanNo int `json:"planNo"` //周计划编号
|
||
CustomPlanId string `json:"customPlanId"`
|
||
}{
|
||
ConfigType: configtype,
|
||
DeviceId: deviceid,
|
||
PlanNo: planno,
|
||
CustomPlanId: customplanid,
|
||
}
|
||
|
||
resp, err := hikvisionRequest("POST", "/api/v1/open/access/plans/weeks/config", req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result *model.Hikvision
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return result, nil
|
||
}
|
||
|
||
// 周计划获取
|
||
//
|
||
// 根据周计划编号获取设备上的周计划
|
||
func PlanWeekConfigGet(configtype, deviceid string, planno int) (*model.PlanWeekRes, error) {
|
||
|
||
url := fmt.Sprintf("/api/v1/open/access/plans/weeks/config?configType=%s&deviceId=%s&planNo=%d", configtype, deviceid, planno)
|
||
resp, err := hikvisionRequest("GET", url, nil)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
var result = &model.PlanWeekRes{}
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return result, nil
|
||
}
|
||
|
||
// 假日计划配置
|
||
//
|
||
// 配置设备的假日计划 configtype: userRight-人员权限
|
||
func PlanHolidayConfigSet(configtype, deviceid string, planno int, customplanid string) (*model.Hikvision, error) {
|
||
req := &struct {
|
||
ConfigType string `json:"configType"`
|
||
DeviceId string `json:"deviceId"`
|
||
PlanNo int `json:"planNo"`
|
||
CustomPlanId string `json:"customPlanId"`
|
||
}{
|
||
ConfigType: configtype,
|
||
DeviceId: deviceid,
|
||
PlanNo: planno,
|
||
CustomPlanId: customplanid,
|
||
}
|
||
|
||
resp, err := hikvisionRequest("POST", "/api/v1/open/access/plans/holidays/config", req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result *model.Hikvision
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return result, nil
|
||
}
|
||
|
||
// 假日计划获取
|
||
//
|
||
// 根据假日计划编号获取设备上的假日计划
|
||
func PlanHolidayConfigGet(configtype, deviceid string, planno int) (*model.PlanHolidayRowRes, error) {
|
||
|
||
url := fmt.Sprintf("/api/v1/open/access/plans/holidays/config?configType=%s&deviceId=%s&planNo=%d", configtype, deviceid, planno)
|
||
resp, err := hikvisionRequest("GET", url, nil)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result = &model.PlanHolidayRowRes{}
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return result, nil
|
||
}
|
||
|
||
// 假日组计划配置
|
||
//
|
||
// 配置设备的假日组计划,假日组计划即为多个假日计划的组合
|
||
func PlanHolidayGroupConfigSet(configtype, deviceid string, groupno int, enable bool, groupname, holidayplanno string) (*model.Hikvision, error) {
|
||
req := &struct {
|
||
ConfigType string `json:"configType"` //userRight-人员权限
|
||
DeviceId string `json:"deviceId"`
|
||
GroupNo int `json:"groupNo"` //假日组编号,从1开始
|
||
Enable bool `json:"enable"`
|
||
GroupName string `json:"groupName"` //假日组名称
|
||
HolidayPlanNo string `json:"holidayPlanNo"` //假日计划编号,多个以英文逗号分隔
|
||
}{
|
||
ConfigType: configtype,
|
||
DeviceId: deviceid,
|
||
GroupNo: groupno,
|
||
Enable: enable,
|
||
GroupName: groupname,
|
||
HolidayPlanNo: holidayplanno,
|
||
}
|
||
|
||
resp, err := hikvisionRequest("POST", "/api/v1/open/access/plans/holidays/groups/config", req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result *model.Hikvision
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return result, nil
|
||
}
|
||
|
||
// 假日组计划获取
|
||
//
|
||
// 根据假日组编号获取设备上的假日组计划,假日组计划即为多个假日计划的组合
|
||
func PlanHolidayGroupConfigGet(configtype, deviceid string, groupno int) (*model.PlanGroupConfig, error) {
|
||
|
||
url := fmt.Sprintf("/api/v1/open/access/plans/holidays/groups/config?configType=%s&deviceId=%s&groupNo=%d", configtype, deviceid, groupno)
|
||
resp, err := hikvisionRequest("GET", url, nil)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result = &model.PlanGroupConfig{}
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return result, nil
|
||
}
|
||
|
||
// 门禁计划配置 需要先配置周计划、假日计划、假日组计划
|
||
//
|
||
// 配置设备的门禁计划,门禁计划为周计划和假日组计划的组合,假日计划生效优先级高于周计划
|
||
func PlanGlobalConfigSet(configtype, deviceid string, templateno int, enable bool, templetename string, weekplanno int, holidayplanno string) (*model.Hikvision, error) {
|
||
req := &struct {
|
||
ConfigType string `json:"configType"` //userRight-人员权限
|
||
DeviceId string `json:"deviceId"`
|
||
TemplateNo int `json:"templateNo"`
|
||
Enable bool `json:"enable"`
|
||
TemplateName string `json:"templateName"`
|
||
WeekPlanNo int `json:"weekPlanNo"` //周计划编号
|
||
HolidayGroupNo string `json:"holidayGroupNo"` //假日组计划编号,多个以英文逗号分隔
|
||
}{
|
||
ConfigType: configtype,
|
||
DeviceId: deviceid,
|
||
TemplateNo: templateno,
|
||
Enable: enable,
|
||
TemplateName: templetename,
|
||
WeekPlanNo: weekplanno,
|
||
HolidayGroupNo: holidayplanno,
|
||
}
|
||
|
||
resp, err := hikvisionRequest("POST", "/api/v1/open/access/plans/templates/config", req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result *model.Hikvision
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return result, nil
|
||
}
|
||
|
||
// 门禁计划聚合配置 无需单独配置周计划、假日计划、假日组计划
|
||
//
|
||
// 配置设备的门禁计划,门禁计划为周计划和假日组计划的组合,假日计划生效优先级高于周计划
|
||
func PlanGlobalPolymerizationConfig(configtype, deviceid string, templateno int, enable bool, templetename string, weekplanno model.PlanChild, holidayplanno []model.PlanHolidayGroup) (*model.Hikvision, error) {
|
||
req := &struct {
|
||
ConfigType string `json:"configType"`
|
||
DeviceId string `json:"deviceId"`
|
||
TemplateNo int `json:"templateNo"`
|
||
Enable bool `json:"enable"`
|
||
TemplateName string `json:"templateName"`
|
||
WeekPlan model.PlanChild `json:"weekPlan"`
|
||
HolidayPlanGroup []model.PlanHolidayGroup `json:"holidayPlanGroup"`
|
||
}{
|
||
ConfigType: configtype,
|
||
DeviceId: deviceid,
|
||
TemplateNo: templateno,
|
||
Enable: enable,
|
||
TemplateName: templetename,
|
||
WeekPlan: weekplanno,
|
||
HolidayPlanGroup: holidayplanno,
|
||
}
|
||
|
||
resp, err := hikvisionRequest("POST", "/api/v1/open/access/plans/templates/config/polymerization", req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result *model.Hikvision
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return result, nil
|
||
}
|
||
|
||
// 门禁计划获取
|
||
//
|
||
// 获取设备上的门禁计划 templateNo计划编号,从1开始
|
||
func PlanGlobalConfigGet(configtype, deviceid string, templateno int) (*model.PlanGlobalConfig, error) {
|
||
|
||
url := fmt.Sprintf("/api/v1/open/access/plans/templates/config?configType=%s&deviceId=%s&templateNo=%d", configtype, deviceid, templateno)
|
||
resp, err := hikvisionRequest("GET", url, nil)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result = &model.PlanGlobalConfig{}
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return result, nil
|
||
}
|
||
|
||
// 清空门禁计划
|
||
//
|
||
// 清空设备上的门禁计划
|
||
func PlanGlobalConfigClear(deviceid string, userRightWeekPlan, userRightHolidayPlan, userRightHolidayGroup, userRightTemplate bool) (*model.Hikvision, error) {
|
||
|
||
req := &struct {
|
||
DeviceId string `json:"deviceId"`
|
||
ClearPlan struct {
|
||
UserRightWeekPlan bool `json:"userRightWeekPlan"`
|
||
UserRightHolidayPlan bool `json:"userRightHolidayPlan"`
|
||
UserRightHolidayGroup bool `json:"userRightHolidayGroup"`
|
||
UserRightTemplate bool `json:"userRightTemplate"`
|
||
} `json:"clearPlan"`
|
||
}{
|
||
DeviceId: deviceid,
|
||
ClearPlan: struct {
|
||
UserRightWeekPlan bool "json:\"userRightWeekPlan\""
|
||
UserRightHolidayPlan bool "json:\"userRightHolidayPlan\""
|
||
UserRightHolidayGroup bool "json:\"userRightHolidayGroup\""
|
||
UserRightTemplate bool "json:\"userRightTemplate\""
|
||
}{
|
||
UserRightWeekPlan: userRightWeekPlan,
|
||
UserRightHolidayPlan: userRightHolidayPlan,
|
||
UserRightHolidayGroup: userRightHolidayGroup,
|
||
UserRightTemplate: userRightTemplate,
|
||
},
|
||
}
|
||
resp, err := hikvisionRequest("DELETE", "/api/v1/open/access/plans/clear", req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
var result = &model.Hikvision{}
|
||
if err := json.Unmarshal(resp, &result); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return result, nil
|
||
|
||
}
|