1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- package dao
- import "time"
- //CameraDevice 网关下挂载的设备, 摄像头
- type CameraDevice struct {
- ID string `gorm:"type:int;comment '编号';primary_key"`
- Name string `gorm:"type:varchar(64);comment '设备名称'"`
- GatewayId string `gorm:"type:varchar(32);comment '所属网关'"`
- IP string `gorm:"type:varchar(40);null;comment 'IP地址'"`
- SN string `gorm:"type:varchar(64);comment '设备序列号'"`
- CameraType int `gorm:"type:int;null;comment '摄像机类型 0=枪机,1=球机'"`
- Brand int `gorm:"type:int;null; comment '设备品牌'"`
- Model int `gorm:"type:int;null; comment '设备型号'"`
- GroupId int `gorm:"type:int;null;comment '灯杆分组ID'"`
- LampPoleId int `gorm:"type:int;null;comment '归属灯杆 灯杆ID'"`
- LampPoleName string `gorm:"type:varchar(64);null;comment '灯杆名称'"`
- LampPoleSn string `gorm:"type:varchar(64);null;comment '灯杆sn'"`
- LampPoleLocation string `gorm:"type:varchar(255);null;comment '灯杆安装位置'"`
- LampLat float64 `gorm:"type:double(17,14);null; comment '经度'"`
- LampLng float64 `gorm:"type:double(17,14) null; comment '纬度'"`
- RatedPower float32 `gorm:"type:float(8,2) null; comment '功率'"`
- MonitorAddress string `gorm:"type:varchar(255);null;comment '监控地址 ip:端口'"`
- DevType int `gorm:"type:int;null;comment '3摄像机'"`
- Tenant string `gorm:"type:varchar(8);null;comment '租户ID"`
- InstallTime time.Time `gorm:"type:date;null;comment '安装时间'"`
- CreateTime time.Time `gorm:"type:datetime;null;comment '新增时间'"`
- CreateUser string `gorm:"type:varchar(60);null;comment '新增记录操作用户ID'"`
- UpdateTime time.Time `gorm:"type:datetime;null;comment '修改时间'"`
- UpdateUser string `gorm:"type:varchar(60)"` //修改用户
- IsDeleted int `gorm:"type:int"` //是否删除 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
- }
- 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) IsExistedByCode() (bool, error) {
- var count = 0
- err := GDb.Model(&c).Where(" id = ? ", c.ID).Count(&count).Error
- return count > 0, err
- }
- func (c CameraDevice) SaveFromWeb() error {
- has, err := c.IsExistedByCode()
- if err != nil {
- return err
- }
- if has { //更新
- return GDb.Model(&c).Updates(map[string]interface{}{"name": c.Name, "gateway_id": c.GatewayId,
- "dev_type": c.DevType, "tenant": c.Tenant, "state": c.Status}).Error
- } else { //插入
- return GDb.Create(&c).Error
- }
- }
- func (c CameraDevice) GetCameraDevice() error {
- err := GDb.Model(&c).Where(" id = ? ", c.ID).Scan(&c).Error
- return err
- }
|