qixiaoning
2025-09-11 397468ddc1191bf0ce9339e544ff345d1d4e6786
camera-service/controllers/camera.go
@@ -7,6 +7,7 @@
   "fmt"
   "image"
   "path/filepath"
   "time"
   // "fmt"
   // "io/ioutil"
@@ -85,7 +86,26 @@
   }
   logger.Debug("update sensors:", camVo.Sensors)
   sv := service.CameraService{}
   ok, cam := sv.GetById(camVo.Id)
   if b, err := sv.CameraUpdate(camVo); b {
      //更新分辨率
      if ok {
         logger.Debug("DoPostRequest:", camVo)
         if cam.IsRunning && (cam.ResolutionWidth != camVo.ResolutionWidth && cam.ResolutionHeight != camVo.ResolutionHeight) {
            header := map[string]string{}
            paramBody := map[string]interface{}{
               "isOpen":    1,
               "videoId":   camVo.Id,
               "videoType": 0,
            }
            res, err := util.DoPostRequest("http://127.0.0.1:8088/v1/task/openAnalysis", util.CONTENT_TYPE_JSON, paramBody, nil, header, time.Second*10)
            if err != nil {
               logger.Debug("DoPostRequest err:", err)
            }
            logger.Debug("DoPostRequest:", res)
         }
      }
      cc.addDbChangeMsg(h.Bk, protomsg.TableChanged_T_Camera, camVo.Id, protomsg.DbAction_Update, "")
      _, _ = service2.DoBusReq("/data/api-v/saas/syncCamera", config.Server.AnalyServerId, aiot.RequestMethod_Post, aiot.RequestContentType_ApplicationJson, map[string]interface{}{})
      return &bhomeclient.Reply{Success: true, Data: camVo.Copy2Camera()}
@@ -109,6 +129,13 @@
   if cid == "" {
      return &bhomeclient.Reply{Msg: "参数有误,摄像机id不能为空"}
   }
   //判断是否有配置任务
   total, _ := models.GetTaskTotal(cid)
   if total > 0 {
      return &bhomeclient.Reply{Success: false, Msg: "请先删除配置的任务"}
   }
   rows, _ := cam.Delete(cid)
   if rows == 0 {
      return &bhomeclient.Reply{Success: true, Msg: "记录不存在"}
@@ -166,10 +193,14 @@
   }
   m["resolutions"] = []models.Resolution{dRe0, dRe1, dRe2}
   //获取督查任务
   tasks := models.GetTasks()
   //处理摄像机的状态
   var crApi bhomedbapi.CameraRuleApi
   //var crApi bhomedbapi.CameraRuleApi
   if cam.RunType == models.TYPE_RUNTYPE_POLL || cam.RunType == models.TYPE_RUNTYPE_REALTIME {
      if crApi.ExistRunningTask(cam.Id) {
      //if crApi.ExistRunningTask(cam.Id) {
      if taskInfo, ok := tasks[cam.Id]; ok && taskInfo != nil && len(taskInfo) > 0 {
         if cam.IsRunning {
            m["status"] = models.Camera_Status_Doing
         } else {
@@ -1019,6 +1050,7 @@
   pageSize := info.PageSize
   idsStr := info.Ids
   TaskIds := info.TaskIds
   TaskName := info.TaskName
   videoIdStr := info.VideoIds
   Warning := info.Warning
@@ -1045,7 +1077,7 @@
         }
      }
      //根据id查询视频id
      var vids []int
      var vids []int64
      cameras, _ := models.GetCameraIds(videoIds)
      for _, camera := range cameras {
         if len(camera.Id) > 0 {
@@ -1054,7 +1086,7 @@
      }
      idStr := make([]string, len(vids))
      for i, id := range vids {
         idStr[i] = strconv.Itoa(id)
         idStr[i] = strconv.FormatInt(id, 10)
      }
      filter += fmt.Sprintf(" and %s in [%s]", "video_point_id", strings.Join(idStr, ","))
   }
@@ -1062,6 +1094,19 @@
   //根据任务查询
   if len(TaskIds) > 0 {
      filter += fmt.Sprintf(" and array_contains(task_id, %d)", TaskIds[0])
   }
   //根据任务名称
   if len(TaskName) > 0 {
      quotedNames := make([]string, len(TaskName))
      for i, name := range TaskName {
         quotedNames[i] = "'" + name + "'" // 每个元素加单引号
      }
      filter += fmt.Sprintf(" and %s in [%s]", "task_name", strings.Join(quotedNames, ","))
   } else {
      if Warning > 0 {
         return &bhomeclient.Reply{Success: true, Msg: "获取成功", Data: nil}
      }
   }
   //是否预警
@@ -1121,6 +1166,9 @@
         Content:         v.CameraName,
         PicDate:         v.PicDate,
         LikeDate:        v.LikeDate,
         VideoName:       v.CameraName,
         CameraAddr:      v.CameraName,
         CameraName:      v.CameraName,
      }
      //任务名称
@@ -1128,9 +1176,9 @@
      temp.TaskNames = items
      //视频内容
      items4, _ := models.GetVideoById(v.VideoPointId)
      temp.VideoName = items4.Name
      temp.CameraAddr = items4.Addr
      // items4, _ := models.GetVideoById(v.VideoPointId)
      // temp.VideoName = items4.Name
      // temp.CameraAddr = items4.Addr
      //检查内容
      items2, _ := models.GetCheckByIds(v.DetectId)
@@ -1193,3 +1241,14 @@
   return &bhomeclient.Reply{Success: true, Msg: "获取成功", Data: tasks}
}
// 获取所有
func (cc CameraController) GetAllTasks(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
   //绑定json和结构体
   var tasks []models.TaskAggregate
   tasks, _ = models.GetAllTask()
   return &bhomeclient.Reply{Success: true, Msg: "获取成功", Data: tasks}
}