qixiaoning
2025-10-29 9b17a8dcbc1f94eb117a37b3b24ca9dae0d2d588
camera-common/models/camera.go
@@ -29,7 +29,8 @@
)
type Camera struct {
   Id          string  `gorm:"primary_key;column:id;type:varchar(100);unique;" json:"id"`
   VideoId     int64   `gorm:"-;primaryKey;autoIncrement"` //摄像机id
   Id          string  `gorm:"column:id;type:varchar(100);unique;" json:"id"`
   Name        string  `gorm:"column:name" json:"name"  bind:"required"`
   Alias       string  `gorm:"column:alias" json:"alias"`               //摄像机的别名
   SnapshotUrl string  `gorm:"column:snapshot_url" json:"snapshot_url"` //快照地址
@@ -56,7 +57,39 @@
   VoiceEnable    bool   `gorm:"column:voiceEnable;default:0" json:"voiceEnable"`
   VoiceId        string `gorm:"column:voiceId" json:"voiceId"`
   CoordTransform string `gorm:"column:coordTransform" json:"coordTransform"` //坐标转换,长春追踪reid用
   VideoId        int    `gorm:"column:video_id" json:"video_id"`             //摄像机id
}
type CameraDto struct {
   VideoId     int64   `gorm:"primaryKey;autoIncrement"` //摄像机id
   Id          string  `gorm:"column:id;type:varchar(100);unique;" json:"id"`
   Name        string  `gorm:"column:name" json:"name"  bind:"required"`
   Alias       string  `gorm:"column:alias" json:"alias"`               //摄像机的别名
   SnapshotUrl string  `gorm:"column:snapshot_url" json:"snapshot_url"` //快照地址
   Type        int     `gorm:"column:type" json:"type" `
   Addr        string  `gorm:"column:addr" json:"addr"`
   Longitude   float32 `gorm:"column:longitude" json:"longitude"`
   Latitude    float32 `gorm:"column:latitude" json:"latitude"`
   Floor       int     `gorm:"column:floor" json:"floor"` //楼层
   Rtsp        string  `gorm:"column:rtsp" json:"rtsp"`
   Ip          string  `gorm:"column:ip" json:"ip"`
   Port        int     `gorm:"column:port" json:"port"`
   Username    string  `gorm:"column:username" json:"username"`
   Password    string  `gorm:"column:password" json:"password"`
   Brand       string  `gorm:"column:brand" json:"brand"`
   Reserved    string  `gorm:"column:reserved" json:"reserved"`
   IsRunning   bool    `gorm:"column:is_running" json:"is_running"`       //是否正在解码
   RunEnable   bool    `gorm:"column:run_enable" json:"run_enable"`       //控制实时处理或轮询处理的开关
   RunType     int     `gorm:"column:run_type" json:"run_type"`           //处理类型:0:轮询,1:实时,-1:无任务,不做分析或者分析任务被关了
   RunServerId string  `gorm:"column:run_server_id" json:"run_server_id"` //当前正在处理的分析服务器id
   ResolutionWidth  int `gorm:"column:resolution_width;default:0" json:"resolution_width"`   //分辨率宽
   ResolutionHeight int `gorm:"column:resolution_height;default:0" json:"resolution_height"` //分辨率高
   VoiceEnable    bool   `gorm:"column:voiceEnable;default:0" json:"voiceEnable"`
   VoiceId        string `gorm:"column:voiceId" json:"voiceId"`
   CoordTransform string `gorm:"column:coordTransform" json:"coordTransform"` //坐标转换,长春追踪reid用
}
func (Camera) TableName() string {
@@ -298,6 +331,41 @@
   return result.RowsAffected > 0
}
func (camera *Camera) DelLink(id int64) (err error) {
   //删除关联检测内容
   dbdel1 := db.Exec("delete from mal_task_check_link where task_id=?", id)
   err = dbdel1.Error
   if err != nil || dbdel1.RowsAffected == 0 {
      return err
   }
   //删除关联预警规则
   dbdel2 := db.Exec("delete from mal_task_rule_link where task_id=?", id)
   err = dbdel2.Error
   if err != nil || dbdel2.RowsAffected == 0 {
      return err
   }
   //删除关联摄像机任务
   dbdel3 := db.Exec("delete from mal_task_video_link where task_id=?", id)
   err = dbdel3.Error
   if err != nil || dbdel3.RowsAffected == 0 {
      return err
   }
   //删除关联工作时间
   dbdel4 := db.Exec("delete from mal_task_work_time_link where task_id=?", id)
   err = dbdel4.Error
   if err != nil || dbdel4.RowsAffected == 0 {
      return err
   }
   //删除关联知识库
   dbdel5 := db.Exec("delete from mal_knowledge_link where task_id=?", id)
   err = dbdel5.Error
   if err != nil || dbdel5.RowsAffected == 0 {
      return err
   }
   return
}
func (camera *Camera) Delete(cid string) (int64, error) {
   var err error
   tx := GetDB().Begin()
@@ -374,3 +442,27 @@
   }
   pub.AddDbMessage(&dbMsg)
}
type VideoLink struct {
   ID      int    `gorm:"column:id"       json:"id"`
   VideoId string `gorm:"column:video_id" json:"videoId"`
   TaskId  int    `gorm:"column:task_id"  json:"taskId"`
}
func GetTasks() map[string][]interface{} {
   var lists []VideoLink
   sqlStr := `select id,video_id,task_id from mal_task_video_link`
   if err := db.Raw(sqlStr).Scan(&lists).Error; err != nil {
      fmt.Println(err.Error())
      return nil
   }
   checkMap := make(map[string][]interface{})
   for _, d2 := range lists {
      if d2.VideoId != "" {
         checkMap[d2.VideoId] = append(checkMap[d2.VideoId], d2)
      }
   }
   return checkMap
}