|
@@ -4,64 +4,68 @@ import "time"
|
|
|
|
|
|
//CameraDevice 网关下挂载的设备, 摄像头
|
|
|
type CameraDevice struct {
|
|
|
- ID int `gorm:"primary_key"` //编号
|
|
|
- DeviceName string `gorm:"type:varchar(64)"` //设备名称
|
|
|
- DeviceSN string `gorm:"type:varchar(64)"` //设备序列号
|
|
|
- CameraType int `gorm:"type:int"` //摄像机类型 0=枪机,1=球机
|
|
|
- GatewayId string `gorm:"type:varchar(32)"` //所属网关
|
|
|
- LampPoleId int `gorm:"type:int"` //归属灯杆 灯杆ID
|
|
|
- LampPoleName string `gorm:"type:varchar(64)"` //灯杆名称
|
|
|
- LampPoleSn string `gorm:"type:varchar(64)"` //灯杆sn
|
|
|
- LampPoleLocation string `gorm:"type:varchar(255)"` //灯杆安装位置
|
|
|
- LampLat float64 `gorm:"type:double(17,14)"` //经度
|
|
|
- LampLng float64 `gorm:"type:double(17,14)"` //纬度
|
|
|
- GroupId int `gorm:"type:int"` //灯杆分组ID
|
|
|
- BrandId int `gorm:"type:int"` //设备品牌
|
|
|
- ModelId int `gorm:"type:int"` //设备型号
|
|
|
- RatedPower float32 `gorm:"type:float(8,2);default 0.00"` //功率
|
|
|
- MonitorAddress string `gorm:"type:varchar(255)"` //监控地址 ip:端口
|
|
|
- IPAddress string `gorm:"type:varchar(40)"` //IP地址
|
|
|
- InstallTime time.Time `gorm:"type:date"` //安装时间
|
|
|
- TenantId string `gorm:"type:varchar(12)"` //租户ID
|
|
|
- CreateTime time.Time `gorm:"type:datetime"` //新增时间
|
|
|
- CreateUser string `gorm:"type:varchar(60)"` //新增记录操作用户ID
|
|
|
- UpdateTime time.Time `gorm:"type:datetime"` //修改时间
|
|
|
- UpdateUser string `gorm:"type:varchar(60)"` //修改用户
|
|
|
- IsDeleted int `gorm:"type:int;default 0"` //是否删除 0=未删除,1=删除
|
|
|
- Status int `gorm:"type:int"` //状态 0=正常,1=异常
|
|
|
- Tag string `gorm:"type:varchar(255)"` //标签,(备用,逗号区分)
|
|
|
- IsEnable int `gorm:"type:int;default 2"` //启用禁用:1启用,2禁用
|
|
|
- StreamId string `gorm:"type:varchar(100)"` //流id
|
|
|
+ ID int `gorm:"primary_key" json:"id"` //编号
|
|
|
+ DeviceName string `gorm:"type:varchar(64)" json:"deviceName"` //设备名称
|
|
|
+ DeviceSN string `gorm:"type:varchar(64)" json:"deviceSn"` //设备序列号
|
|
|
+ CameraType int `gorm:"type:int" json:"cameraType"` //摄像机类型 0=枪机,1=球机
|
|
|
+ GatewayId string `gorm:"type:varchar(32)" json:"gatewayId"` //所属网关
|
|
|
+ LampPoleId int `gorm:"type:int" json:"lampPoleId"` //归属灯杆 灯杆ID
|
|
|
+ LampPoleName string `gorm:"type:varchar(64)" json:"lampPoleName"` //灯杆名称
|
|
|
+ LampPoleSn string `gorm:"type:varchar(64)" json:"lampPoleSn"` //灯杆sn
|
|
|
+ LampPoleLocation string `gorm:"type:varchar(255)" json:"lampPoleLocation"` //灯杆安装位置
|
|
|
+ LampLat float64 `gorm:"type:double(17,14)" json:"lampLat"` //经度
|
|
|
+ LampLng float64 `gorm:"type:double(17,14)" json:"lampLng"` //纬度
|
|
|
+ GroupId int `gorm:"type:int" json:"groupId"` //灯杆分组ID
|
|
|
+ BrandId int `gorm:"type:int" json:"brandId"` //设备品牌
|
|
|
+ ModelId int `gorm:"type:int" json:"modelId"` //设备型号
|
|
|
+ RatedPower float32 `gorm:"type:float(8,2);default 0.00" json:"ratedPower"` //功率
|
|
|
+ MonitorAddress string `gorm:"type:varchar(255)" json:"monitorAddress"` //监控地址 ip:端口
|
|
|
+ IPAddress string `gorm:"type:varchar(40)" json:"ipAddress"` //IP地址
|
|
|
+ InstallTime time.Time `gorm:"type:date" json:"installTime"` //安装时间
|
|
|
+ TenantId string `gorm:"type:varchar(12)" json:"tenantId"` //租户ID
|
|
|
+ CreateTime time.Time `gorm:"type:datetime" json:"createTime"` //新增时间
|
|
|
+ CreateUser string `gorm:"type:varchar(60)" json:"createUser"` //新增记录操作用户ID
|
|
|
+ UpdateTime time.Time `gorm:"type:datetime" json:"updateTime"` //修改时间
|
|
|
+ UpdateUser string `gorm:"type:varchar(60)" json:"updateUser"` //修改用户
|
|
|
+ IsDeleted int `gorm:"type:int;default 0" json:"isDeleted"` //是否删除 0=未删除,1=删除
|
|
|
+ Status int `gorm:"type:int" json:"status"` //状态 0=正常,1=异常
|
|
|
+ Tag string `gorm:"type:varchar(255)" json:"tag"` //标签,(备用,逗号区分)
|
|
|
+ IsEnable int `gorm:"type:int;default 2" json:"isEnable"` //启用禁用:1启用,2禁用
|
|
|
+ StreamId int `gorm:"type:int" json:"stream_id"` //流id
|
|
|
}
|
|
|
|
|
|
func (CameraDevice) TableName() string {
|
|
|
return "t_dev_camera"
|
|
|
}
|
|
|
|
|
|
-func (c CameraDevice) Delete() error {
|
|
|
- return GDb.Model(&c).Updates(map[string]interface{}{"state": 0}).Error
|
|
|
+func (c CameraDevice) IsExistedBySN() bool {
|
|
|
+ var count = 0
|
|
|
+ _ = GDb.Model(&c).Where("device_sn = ? and is_deleted = ?",
|
|
|
+ c.DeviceSN, c.IsDeleted).Count(&count).Error
|
|
|
+ return count > 0
|
|
|
}
|
|
|
|
|
|
-func (c CameraDevice) IsExistedByCode() (bool, error) {
|
|
|
- var count = 0
|
|
|
- err := GDb.Model(&c).Where(" id = ? ", c.ID).Count(&count).Error
|
|
|
- return count > 0, err
|
|
|
+func (c *CameraDevice) Create() error {
|
|
|
+ return GDb.Model(&c).Save(&c).Error
|
|
|
}
|
|
|
|
|
|
-func (c CameraDevice) SaveFromWeb() error {
|
|
|
- has, err := c.IsExistedByCode()
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- if has { //更新
|
|
|
- return GDb.Model(&c).Updates(map[string]interface{}{"device_name": c.DeviceName, "gateway_id": c.GatewayId,
|
|
|
- "tenant_id": c.TenantId, "status": c.Status}).Error
|
|
|
- } else { //插入
|
|
|
- return GDb.Create(&c).Error
|
|
|
- }
|
|
|
+func (c *CameraDevice) Update() error {
|
|
|
+ return GDb.Model(&c).Where(" id = ? ", c.ID).Update(&c).Error
|
|
|
}
|
|
|
|
|
|
-func (c CameraDevice) GetCameraDevice() error {
|
|
|
- err := GDb.Model(&c).Where(" id = ? ", c.ID).Scan(&c).Error
|
|
|
+func (c *CameraDevice) GetDevice() error {
|
|
|
+ err := GDb.Model(&c).Where(" id = ? ", c.ID).First(&c).Error
|
|
|
return err
|
|
|
}
|
|
|
+
|
|
|
+func (c CameraDevice) GetDevices(offset, limit int) ([]Gateway, error) {
|
|
|
+ var devices []Gateway
|
|
|
+ db := GDb.Model(&c)
|
|
|
+ if c.DeviceSN != "" {
|
|
|
+ db = db.Where("(device_name like ? or device_sn like ?) and is_deleted = 0", "%"+c.DeviceSN+"%",
|
|
|
+ "%"+c.DeviceSN+"%")
|
|
|
+ }
|
|
|
+
|
|
|
+ err := db.Offset(offset).Limit(limit).Find(&devices).Error
|
|
|
+ return devices, err
|
|
|
+}
|