liuxiaolong
2022-06-28 ef5b487f6cad063a6c5a885f43f203a651c412f6
cameraApi.go
@@ -3,7 +3,6 @@
import (
   "basic.com/pubsub/protomsg.git"
   "encoding/json"
   "errors"
   "strconv"
)
@@ -14,9 +13,6 @@
func (api CameraApi) CameraAdd(paramBody map[string]interface{}) (bool,interface{}) {
   url := DATA_URL_PREFIX + "/camera/add"
   netNode := getNetNode(url2Topic(Topic_Camera_Service, url))
   if netNode == nil {
      return false,nil
   }
   client := NewClient(WithNodes(netNode))
   body, err := client.DoPostRequest(url,CONTENT_TYPE_JSON,paramBody,nil,nil)
   if err != nil {
@@ -33,9 +29,6 @@
func (api CameraApi) CameraUpdate(paramBody map[string]interface{}) bool {
   url := DATA_URL_PREFIX + "/camera/update"
   netNode := getNetNode(url2Topic(Topic_Camera_Service, url))
   if netNode == nil {
      return false
   }
   client := NewClient(WithNodes(netNode))
   body, err := client.DoPutRequest(url,CONTENT_TYPE_JSON,paramBody,nil)
   if err != nil {
@@ -52,9 +45,6 @@
func (api CameraApi) UpdateSnapshotUrl(cameraId string, snapshot string) bool {
   url := DATA_URL_PREFIX + "/camera/updateSnapshot"
   netNode := getNetNode(url2Topic(Topic_Camera_Service, url))
   if netNode == nil {
      return false
   }
   client := NewClient(WithNodes(netNode))
   paramBody :=make(map[string]interface{},0)
   paramBody["snapshot"] = snapshot
@@ -76,13 +66,10 @@
func (api CameraApi) CameraDelete(cid string) bool {
   url := DATA_URL_PREFIX + "/camera/del"
   netNode := getNetNode(url2Topic(Topic_Camera_Service, url))
   if netNode == nil {
      return false
   }
   client := NewClient(WithNodes(netNode))
   paramMap := make(map[string]string,0)
   paramMap["cid"] = cid
   body, err := client.DoDeleteRequest(url,CONTENT_TYPE_FORM,nil,paramMap)
   paramMap["id"] = cid
   body, err := client.DoGetRequest(url,paramMap,nil)
   if err != nil {
      return false
   }
@@ -98,12 +85,11 @@
func (api CameraApi) GetCameraById(cameraId string) (camera protomsg.Camera, err error) {
   url := DATA_URL_PREFIX + "/camera/show"
   netNode := getNetNode(url2Topic(Topic_Camera_Service, url))
   if netNode == nil {
      return camera,errors.New("camera-service not found")
   }
   client := NewClient(WithNodes(netNode))
   body, err := client.DoGetRequest(url, nil, nil)
   paramQuery := map[string]string {
      "id": cameraId,
   }
   body, err := client.DoGetRequest(url, paramQuery, nil)
   if err != nil {
      return camera, err
   }
@@ -122,9 +108,6 @@
func (api CameraApi) UpdateCameraArea(cameraId string, areaId string) bool {
   url := DATA_URL_PREFIX + "/camera/updateCameraArea"
   netNode := getNetNode(url2Topic(Topic_Camera_Service, url))
   if netNode == nil {
      return false
   }
    client := NewClient(WithNodes(netNode))
    paramBody := map[string]interface{} {
        "cameraId": cameraId,
@@ -143,15 +126,18 @@
    return res.Success
}
func (api CameraApi) FindAll() (cameras []protomsg.Camera) {
func (api CameraApi) FindAll(cameraName string, runType string, cameraId string, areaId string) (cameras []protomsg.Camera) {
   url := DATA_URL_PREFIX + "/camera/showAll"
   netNode := getNetNode(url2Topic(Topic_Camera_Service, url))
   if netNode == nil {
      return nil
   }
   client := NewClient(WithNodes(netNode))
   paramQuery := map[string]string {
      "cameraName": cameraName,
      "runType": runType,
      "cameraId": cameraId,
      "areaId": areaId,
   }
   body, err := client.DoGetRequest(url, nil, nil)
   body, err := client.DoGetRequest(url, paramQuery, nil)
   if err != nil {
      return nil
   }
@@ -171,9 +157,6 @@
func (api CameraApi) GetAllCamerasByServer(serverId string,cameraName string) (b bool,cams []protomsg.Camera) {
   url := DATA_URL_PREFIX + "/camera/getAllCamerasByServer"
   netNode := getNetNode(url2Topic(Topic_Camera_Service, url))
   if netNode == nil {
      return false,nil
   }
   client := NewClient(WithNodes(netNode))
   paramQuery := make(map[string]string,0)
   paramQuery["serverId"] = serverId
@@ -221,9 +204,6 @@
func (api CameraApi) GetCamerasByRunType(runType int,cameraName string)(flag bool,cameras []protomsg.Camera){
   url := DATA_URL_PREFIX + "/camera/getCamerasByRunType"
   netNode := getNetNode(url2Topic(Topic_Camera_Service, url))
   if netNode == nil {
      return false,nil
   }
   client := NewClient(WithNodes(netNode))
   paramQuery := make(map[string]string,2)
   paramQuery["runType"]=strconv.Itoa(runType)
@@ -252,9 +232,6 @@
func (api CameraApi) UpdateRunEnable(cameraId string,runEnable bool) (bool,interface{}){
   url := DATA_URL_PREFIX + "/camera/updateRunEnable"
   netNode := getNetNode(url2Topic(Topic_Camera_Service, url))
   if netNode == nil {
      return false, nil
   }
   client := NewClient(WithNodes(netNode))
   paramBody :=make(map[string]interface{},0)
   paramBody["cameraId"] = cameraId
@@ -276,9 +253,6 @@
func (api CameraApi) UpdateIsRunningState(cameraId string,isRunning bool) (bool,interface{}){
   url := DATA_URL_PREFIX + "/camera/updateIsRunningState"
   netNode := getNetNode(url2Topic(Topic_Camera_Service, url))
   if netNode == nil {
      return false,nil
   }
   client := NewClient(WithNodes(netNode))
   paramBody :=make(map[string]interface{},0)
   paramBody["cameraId"] = cameraId
@@ -300,9 +274,6 @@
func (api CameraApi) UpdateIsRunningAll(cameraIds []string) (bool,interface{}){
   url := DATA_URL_PREFIX + "/camera/updateIsRunningAll"
   netNode := getNetNode(url2Topic(Topic_Camera_Service, url))
   if netNode == nil {
      return false,nil
   }
   client := NewClient(WithNodes(netNode))
   paramBody :=make(map[string]interface{},0)
   paramBody["cameraIds"] = cameraIds
@@ -324,9 +295,6 @@
func (api CameraApi) ChangeRunType(paramBody map[string]interface{}) (bool,interface{}){
   url := DATA_URL_PREFIX + "/camera/changeRunType"
   netNode := getNetNode(url2Topic(Topic_Camera_Service, url))
   if netNode == nil {
      return false,nil
   }
   client := NewClient(WithNodes(netNode))
   body,err := client.DoPostRequest(url,CONTENT_TYPE_JSON, paramBody,nil,nil)
   if err != nil {
@@ -345,9 +313,6 @@
func (api CameraApi) StatisticRunInfo() (bool,interface{}){
   url := DATA_URL_PREFIX + "/camera/statisticRunInfo"
   netNode := getNetNode(url2Topic(Topic_Camera_Service, url))
   if netNode == nil {
      return false,nil
   }
   client := NewClient(WithNodes(netNode))
   body, err := client.DoGetRequest(url, nil, nil)
   if err != nil {
@@ -364,9 +329,6 @@
func (api CameraApi) FindAllCameraLink() (b bool,list []protomsg.CameraLink){
   url := DATA_URL_PREFIX + "/camera/findAllCameraLink"
   netNode := getNetNode(url2Topic(Topic_Camera_Service, url))
   if netNode == nil {
      return false,nil
   }
   client := NewClient(WithNodes(netNode))
   body, err := client.DoGetRequest(url, nil, nil)
   if err != nil {
@@ -387,9 +349,6 @@
func (api CameraApi) FindOnMap(isOnMap bool, floor int, cameraName string) (b bool, cams []protomsg.Camera) {
   url := DATA_URL_PREFIX + "/camera/findOnMap"
   netNode := getNetNode(url2Topic(Topic_Camera_Service, url))
   if netNode == nil {
      return false,nil
   }
   client := NewClient(WithNodes(netNode))
   paramBody:= map[string]interface{}{
      "isOnMap":    isOnMap,
@@ -419,9 +378,6 @@
func (api CameraApi) UpdatePos(id string, floor int, longitude float32, latitude float32) bool {
   url := DATA_URL_PREFIX + "/camera/updatePos"
   netNode := getNetNode(url2Topic(Topic_Camera_Service, url))
   if netNode == nil {
      return false
   }
   client := NewClient(WithNodes(netNode))
   paramBody:= map[string]interface{}{
      "id":    id,
@@ -446,9 +402,6 @@
func (api CameraApi) NodeCamera() (bool, interface{}) {
   url := DATA_URL_PREFIX + "/camera/nodeCamera"
   netNode := getNetNode(url2Topic(Topic_Camera_Service, url))
   if netNode == nil {
      return false,nil
   }
   client := NewClient(WithNodes(netNode))
   body, err := client.DoGetRequest(url, nil, nil)
   if err != nil {
@@ -465,9 +418,6 @@
func (api CameraApi) Coord(cameraId string) (bool, interface{}) {
   url := DATA_URL_PREFIX + "/camera/coord"
   netNode := getNetNode(url2Topic(Topic_Camera_Service, url))
   if netNode == nil {
      return false,nil
   }
   client := NewClient(WithNodes(netNode))
   paramQuery := map[string]string {
      "cameraId": cameraId,
@@ -487,9 +437,6 @@
func (api CameraApi) UpdateCoord(paramBody map[string]interface{}) bool {
   url := DATA_URL_PREFIX + "/camera/updateCoord"
   netNode := getNetNode(url2Topic(Topic_Camera_Service, url))
   if netNode == nil {
      return false
   }
   client := NewClient(WithNodes(netNode))
   body,err := client.DoPostRequest(url,CONTENT_TYPE_JSON, paramBody,nil,nil)
   if err != nil {
@@ -503,4 +450,22 @@
   }
   return res.Success
}
}
func (api CameraApi) SaveNotExistOrUpdate(paramBody map[string]interface{}) bool {
   url := DATA_URL_PREFIX + "/camera/saveNotExistOrUpdate"
   netNode := getNetNode(url2Topic(Topic_Camera_Service, url))
   client := NewClient(WithNodes(netNode))
   body,err := client.DoPostRequest(url,CONTENT_TYPE_JSON, paramBody,nil,nil)
   if err != nil {
      return false
   }
   var res Result
   if err = json.Unmarshal(body, &res); err != nil {
      logPrint(err)
      return false
   }
   return res.Success
}