sqlite的api,便于内部使用
liuxiaolong
2020-11-02 5a9b7c4a4f926aaf79fbcc6356fe9e2a77cd248d
areaApi.go
@@ -2,25 +2,41 @@
import (
   "encoding/json"
   "fmt"
   "strconv"
)
type AreaApi struct {
   Ip string
   Port int
}
func (api AreaApi) getBasicUrl() string {
   if api.Ip == "" {
      return BASIC_URL
   }
   if api.Ip == "" {
      api.Ip = DEFAULT_IP
   }
   if api.Port == 0 {
      api.Port = DEFAULT_PORT
   }
   return "http://"+api.Ip+":"+strconv.Itoa(api.Port)
}
//parentId 要查寻的目录树的根节点id
//searchType(0:全部,1:分析摄像机,2:监控摄像机)
//cameraName(摄像机名称)
func (api AreaApi) GetLocalCameraTree(parentId string, searchType string, cameraName string,treeType string) []TreeMenu {
func (api AreaApi) GetLocalCameraTree(parentId string, searchType string, cameraName string, isPlatform int) []TreeMenu {
   var result []TreeMenu
   client := NewClient()
   url := BASIC_URL + DATA_URL_PREFIX + "/area/localmenu"
   url := api.getBasicUrl() + DATA_URL_PREFIX + "/area/localmenu"
   params := make(map[string]string, 0)
   params["parentId"] = parentId
   params["searchType"] = searchType
   params["cameraName"] = cameraName
   params["isPlatform"] = strconv.Itoa(isPlatform)
   respBody, err := client.DoGetRequest(url, params, nil)
   if err != nil {
@@ -39,10 +55,77 @@
   return result
}
//parentId 要查寻的目录树的根节点id
//searchType(0:全部,1:分析摄像机,2:监控摄像机)
//cameraName(摄像机名称)
func (api AreaApi) GetGb28181CameraTree(parentId string, searchType string, cameraName string, isPlatform int) []TreeMenu {
   var result []TreeMenu
   client := NewClient()
   url := api.getBasicUrl() + DATA_URL_PREFIX + "/area/gb28181Tree"
   params := make(map[string]string, 0)
   params["parentId"] = parentId
   params["searchType"] = searchType
   params["cameraName"] = cameraName
   params["isPlatform"] = strconv.Itoa(isPlatform)
   respBody, err := client.DoGetRequest(url, params, nil)
   if err != nil {
      return nil
   }
   var res Result
   if err = json.Unmarshal(respBody, &res); err != nil {
      return nil
   }
   bytes, _ := json.Marshal(res.Data)
   if err = json.Unmarshal(bytes, &result);err !=nil{
      return nil
   }
   return result
}
func (api AreaApi) Gb28181TreeRefresh(id string) bool {
   flag := false
   url := api.getBasicUrl() + DATA_URL_PREFIX + "/area/gb28181TreeRefresh"
   client := NewClient()
   paramBody := map[string]interface{}{
      "id":id,
   }
   respBody, err := client.DoPostRequest(url, CONTENT_TYPE_FORM, paramBody, nil, nil)
   if err != nil {
      return flag
   }
   var res Result
   if err = json.Unmarshal(respBody, &res); err != nil {
      return flag
   }
   flag = res.Success
   return flag
}
func (api AreaApi) Gb28181TreeDelete() bool {
   flag := false
   url := api.getBasicUrl() + DATA_URL_PREFIX + "/area/gb28181TreeDelete"
   client := NewClient()
   respBody, err := client.DoPostRequest(url, CONTENT_TYPE_FORM, nil, nil, nil)
   if err != nil {
      return flag
   }
   var res Result
   if err = json.Unmarshal(respBody, &res); err != nil {
      return flag
   }
   flag = res.Success
   return flag
}
//添加目录节点
func (api AreaApi) AreaAdd(paramBody map[string]interface{}) bool {
   flag := false
   url := BASIC_URL + DATA_URL_PREFIX + "/area/add"
   url := api.getBasicUrl() + DATA_URL_PREFIX + "/area/add"
   client := NewClient()
   respBody, err := client.DoPostRequest(url, CONTENT_TYPE_FORM, paramBody, nil, nil)
   if err != nil {
@@ -59,7 +142,7 @@
//目录更新
func (api AreaApi) AreaUpdate(paramBody map[string]interface{}) bool {
   flag := false
   url := BASIC_URL + DATA_URL_PREFIX + "/area/update"
   url := api.getBasicUrl() + DATA_URL_PREFIX + "/area/update"
   client := NewClient()
   respBody, err := client.DoPostRequest(url, CONTENT_TYPE_FORM, paramBody,nil, nil)
@@ -68,7 +151,7 @@
   }
   var res Result
   if err = json.Unmarshal(respBody, &res); err != nil {
      fmt.Println(err)
      logPrint(err)
      return flag
   }
   flag = res.Success
@@ -81,7 +164,7 @@
   if id == "" {
      return flag
   }
   url := BASIC_URL + DATA_URL_PREFIX + "/area/del"
   url := api.getBasicUrl() + DATA_URL_PREFIX + "/area/del"
   client := NewClient()
   paramBody := make(map[string]interface{}, 0)
   paramBody["id"] = id