|
@@ -4,64 +4,68 @@ import "time"
|
|
|
|
|
|
|
|
|
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"`
|
|
|
- GatewayId string `gorm:"type:varchar(32)"`
|
|
|
- LampPoleId int `gorm:"type:int"`
|
|
|
- LampPoleName string `gorm:"type:varchar(64)"`
|
|
|
- LampPoleSn string `gorm:"type:varchar(64)"`
|
|
|
- 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"`
|
|
|
- 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)"`
|
|
|
- IPAddress string `gorm:"type:varchar(40)"`
|
|
|
- InstallTime time.Time `gorm:"type:date"`
|
|
|
- TenantId string `gorm:"type:varchar(12)"`
|
|
|
- CreateTime time.Time `gorm:"type:datetime"`
|
|
|
- CreateUser string `gorm:"type:varchar(60)"`
|
|
|
- UpdateTime time.Time `gorm:"type:datetime"`
|
|
|
- UpdateUser string `gorm:"type:varchar(60)"`
|
|
|
- IsDeleted int `gorm:"type:int;default 0"`
|
|
|
- Status int `gorm:"type:int"`
|
|
|
- Tag string `gorm:"type:varchar(255)"`
|
|
|
- IsEnable int `gorm:"type:int;default 2"`
|
|
|
- StreamId string `gorm:"type:varchar(100)"`
|
|
|
+ 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"`
|
|
|
+ GatewayId string `gorm:"type:varchar(32)" json:"gatewayId"`
|
|
|
+ LampPoleId int `gorm:"type:int" json:"lampPoleId"`
|
|
|
+ LampPoleName string `gorm:"type:varchar(64)" json:"lampPoleName"`
|
|
|
+ LampPoleSn string `gorm:"type:varchar(64)" json:"lampPoleSn"`
|
|
|
+ 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"`
|
|
|
+ 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"`
|
|
|
+ IPAddress string `gorm:"type:varchar(40)" json:"ipAddress"`
|
|
|
+ InstallTime time.Time `gorm:"type:date" json:"installTime"`
|
|
|
+ TenantId string `gorm:"type:varchar(12)" json:"tenantId"`
|
|
|
+ CreateTime time.Time `gorm:"type:datetime" json:"createTime"`
|
|
|
+ CreateUser string `gorm:"type:varchar(60)" json:"createUser"`
|
|
|
+ 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"`
|
|
|
+ Status int `gorm:"type:int" json:"status"`
|
|
|
+ Tag string `gorm:"type:varchar(255)" json:"tag"`
|
|
|
+ IsEnable int `gorm:"type:int;default 2" json:"isEnable"`
|
|
|
+ StreamId int `gorm:"type:int" json:"stream_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
|
|
|
+}
|