package models
|
|
//摄像机区域之间的对应关系,目前主要是给长春跟踪使用
|
type CameraPolygonRelation struct {
|
Id string `gorm:"primary_key;column:id" json:"id"`
|
GroupId string `gorm:"column:group_id" json:"group_id"` //分组id
|
SourceCameraId string `gorm:"column:source_camera_id" json:"source_camera_id"` //摄像机id
|
SourcePolygonId string `gorm:"column:source_polygon_id" json:"source_polygon_id"` //区域id
|
TargetCameraId string `gorm:"column:target_camera_id" json:"target_camera_id"` //摄像机id
|
TargetPolygonId string `gorm:"column:target_polygon_id" json:"target_polygon_id"` //区域id
|
}
|
|
func (CameraPolygonRelation) TableName() string {
|
return "camera_polygon_relation"
|
}
|
|
func (cpr *CameraPolygonRelation) FindAll() (arr []CameraPolygonRelation) {
|
if err := db.Table(cpr.TableName()).Scan(&arr).Error;err !=nil {
|
return nil
|
}
|
return arr
|
}
|
|
func (cpr *CameraPolygonRelation) FindAllMap() map[string]CameraPolygonRelation {
|
m := make(map[string]CameraPolygonRelation,0)
|
arr := cpr.FindAll()
|
if arr !=nil {
|
for _,p :=range arr {
|
m[p.Id] = p
|
}
|
}
|
return m
|
}
|
|
func (cpr *CameraPolygonRelation) SelectById(id string) (model CameraPolygonRelation,flag bool) {
|
exist := db.Table(cpr.TableName()).First(&model,"id=?",id).RecordNotFound()
|
return model,!exist
|
}
|
|
func (cpr *CameraPolygonRelation) FindByGroupId(groupId string) (arr []CameraPolygonRelation, err error) {
|
if err := db.Table(cpr.TableName()).Where("group_id=?", groupId).Scan(&arr).Error;err !=nil {
|
return nil, err
|
}
|
return arr,nil
|
}
|
|
func (cpr *CameraPolygonRelation) FindAllByCameraId(cameraId string) (arr []CameraPolygonRelation, err error) {
|
if err := db.Table(cpr.TableName()).Where("source_camera_id = ? or target_camera_id=?", cameraId).Scan(&arr).Error;err !=nil {
|
return nil, err
|
}
|
return arr,nil
|
}
|
|
func (cpr *CameraPolygonRelation) FindRelations(sourceCameraId string, targetCameraId string) (arr []CameraPolygonRelation, err error) {
|
if err := db.Table(cpr.TableName()).Where("(source_camera_id=? and target_camera_id=?) or (source_camera_id=? and target_camera_id=?)", sourceCameraId, targetCameraId, targetCameraId, sourceCameraId).Scan(&arr).Error;err !=nil {
|
return nil, err
|
}
|
return arr,nil
|
}
|
|
func (cpr *CameraPolygonRelation) Insert() (result bool, err error) {
|
if err = db.Table(cpr.TableName()).Save(&cpr).Error; err != nil {
|
return false, err
|
}
|
return true, nil
|
}
|
|
func (cpr *CameraPolygonRelation) Update() (bool,error) {
|
result := db.Table(cpr.TableName()).Where("id=?",cpr.Id).Save(&cpr)
|
if result.Error != nil {
|
return false, err
|
}
|
return result.RowsAffected > 0, nil
|
}
|
|
func (cpr CameraPolygonRelation) Exist(sourceCamId string, sourcePgnId string, targetCamId string, targetPgnId string) (model CameraPolygonRelation, exist bool) {
|
exist = db.Table(cpr.TableName()).First(&model, "(source_camera_id=? and source_polygon_id=? and target_camera_id=? and target_polygon_id=?) or (source_camera_id=? and source_polygon_id=? and target_camera_id=? and target_polygon_id=?)", sourceCamId, sourcePgnId, targetCamId, targetPgnId,targetCamId, targetPgnId, sourceCamId, sourcePgnId).RecordNotFound()
|
return model, !exist
|
}
|
|
//Delete 删除摄像机区域关联关系
|
func (cpr *CameraPolygonRelation) Delete(id string) bool {
|
if err := db.Table(cpr.TableName()).Where("id=?",id).Delete(&CameraPolygonRelation{}).Error; err != nil {
|
return false
|
}
|
|
return true
|
}
|
|
func (cpr *CameraPolygonRelation) DeleteByGroupId(groupId string) bool {
|
if err := db.Table(cpr.TableName()).Where("group_id=?",groupId).Delete(&CameraPolygonRelation{}).Error; err != nil {
|
return false
|
}
|
|
return true
|
}
|