package bhomedbapi import ( "basic.com/pubsub/protomsg.git" jsoniter "github.com/json-iterator/go" ) type TimePgnApi struct { } func (api TimePgnApi) SaveCameraPolygon(paramBody map[string]interface{}) (bool, interface{}) { url := DATA_URL_PREFIX + "/polygon/save" netNode := getNetNode(url2Topic(Topic_Scene_Service, url)) client := NewClient(WithNodes(netNode)) body, err := client.DoPostRequest(url, CONTENT_TYPE_JSON, paramBody, nil, nil) if err != nil { return false, nil } var json = jsoniter.ConfigCompatibleWithStandardLibrary var res Result if err = json.Unmarshal(body, &res); err != nil { logPrint(err) return false, nil } return res.Success, res.Data } func (api TimePgnApi) DeleteCameraPolygon(id string) (bool, interface{}) { url := DATA_URL_PREFIX + "/polygon/delete" netNode := getNetNode(url2Topic(Topic_Scene_Service, url)) client := NewClient(WithNodes(netNode)) paramQuery := make(map[string]string, 0) paramQuery["id"] = id body, err := client.DoGetRequest(url, paramQuery, nil) if err != nil { return false, nil } var json = jsoniter.ConfigCompatibleWithStandardLibrary var res Result if err = json.Unmarshal(body, &res); err != nil { return false, nil } return res.Success, res.Data } func (api TimePgnApi) FindAllPolygons() []protomsg.CameraPolygon { url := DATA_URL_PREFIX + "/polygon/findAll" netNode := getNetNode(url2Topic(Topic_Scene_Service, url)) polygons := make([]protomsg.CameraPolygon, 0) client := NewClient(WithNodes(netNode)) body, err := client.DoGetRequest(url, nil, nil) if err != nil { return nil } var json = jsoniter.ConfigCompatibleWithStandardLibrary var res Result if err = json.Unmarshal(body, &res); err != nil { return nil } dataBytes, _ := json.Marshal(res.Data) if err := json.Unmarshal(dataBytes, &polygons); err != nil { return nil } return polygons } func (api TimePgnApi) FindPolygonsByCameraId(cameraId string) (bool, interface{}) { url := DATA_URL_PREFIX + "/polygon/findByCameraId" netNode := getNetNode(url2Topic(Topic_Scene_Service, url)) client := NewClient(WithNodes(netNode)) paramQuery := make(map[string]string, 0) paramQuery["cameraId"] = cameraId body, err := client.DoGetRequest(url, paramQuery, nil) if err != nil { return false, nil } var json = jsoniter.ConfigCompatibleWithStandardLibrary var res Result if err = json.Unmarshal(body, &res); err != nil { return false, nil } return true, res.Data } //新增或更新时间规则 func (api TimePgnApi) SaveCameraTimerule(paramBody map[string]interface{}) (bool, interface{}) { url := DATA_URL_PREFIX + "/cameraTimerule/save" netNode := getNetNode(url2Topic(Topic_Scene_Service, url)) client := NewClient(WithNodes(netNode)) body, err := client.DoPostRequest(url, CONTENT_TYPE_JSON, paramBody, nil, nil) if err != nil { return false, nil } var json = jsoniter.ConfigCompatibleWithStandardLibrary var res Result if err = json.Unmarshal(body, &res); err != nil { logPrint(err) return false, nil } return res.Success, res.Data } func (api TimePgnApi) DeleteCameraTimerule(id string) bool { url := DATA_URL_PREFIX + "/cameraTimerule/delete" netNode := getNetNode(url2Topic(Topic_Scene_Service, url)) client := NewClient(WithNodes(netNode)) paramQuery := make(map[string]string, 0) paramQuery["id"] = id body, err := client.DoGetRequest(url, paramQuery, nil) if err != nil { return false } var json = jsoniter.ConfigCompatibleWithStandardLibrary var res Result if err = json.Unmarshal(body, &res); err != nil { return false } return res.Success } //根据摄像机id查找所有的时间规则 func (api TimePgnApi) FindAllTimeRules() (flag bool, rules []protomsg.CameraTimerule) { url := DATA_URL_PREFIX + "/cameraTimerule/findAll" netNode := getNetNode(url2Topic(Topic_Scene_Service, url)) client := NewClient(WithNodes(netNode)) body, err := client.DoGetRequest(url, nil, nil) if err != nil { return false, nil } var json = jsoniter.ConfigCompatibleWithStandardLibrary var res Result if err = json.Unmarshal(body, &res); err != nil { return false, nil } dataBytes, _ := json.Marshal(res.Data) if err := json.Unmarshal(dataBytes, &rules); err != nil { return false, nil } return true, rules } func (api TimePgnApi) UpdateDefenceStateByPolygonId(polygonId string, state string) (bool, interface{}) { url := DATA_URL_PREFIX + "/polygon/updateDefenceStateByPolygonId" netNode := getNetNode(url2Topic(Topic_Scene_Service, url)) client := NewClient(WithNodes(netNode)) paramQuery := make(map[string]string, 0) paramQuery["polygonId"] = polygonId paramQuery["defence_state"] = state body, err := client.DoGetRequest(url, paramQuery, nil) if err != nil { return false, nil } var json = jsoniter.ConfigCompatibleWithStandardLibrary var res Result if err = json.Unmarshal(body, &res); err != nil { return false, nil } return true, res.Data } func (api TimePgnApi) UpdateDefenceStateByCameraId(cameraId string, state string) (bool, interface{}) { url := DATA_URL_PREFIX + "/polygon/updateDefenceStateByCameraId" netNode := getNetNode(url2Topic(Topic_Scene_Service, url)) client := NewClient(WithNodes(netNode)) paramQuery := make(map[string]string, 0) paramQuery["cameraId"] = cameraId paramQuery["defence_state"] = state body, err := client.DoGetRequest(url, paramQuery, nil) if err != nil { return false, nil } var json = jsoniter.ConfigCompatibleWithStandardLibrary var res Result if err = json.Unmarshal(body, &res); err != nil { return false, nil } return true, res.Data }