123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- package dao
- import (
- "time"
- )
- type CaptureUnit struct {
- ID int `gorm:"primary_key" json:"id"`
- CaptureName string `gorm:"type:varchar(64)" json:"captureName"`
- CaptureSn string `gorm:"type:varchar(60)" json:"captureSn"`
- PointId int `gorm:"type:int" json:"pointId"`
- LampPoleId int `gorm:"type:int" json:"lampPoleId"`
- WayName string `gorm:"type:varchar(64)" json:"wayName"`
- CaptureDirection int `gorm:"type:int" json:"captureDirection"`
- InstallTime time.Time `gorm:"type:date" json:"installTime"`
- TerrainClearance float32 `gorm:"type:float(10,1);default 0.0" json:"terrainClearance"`
- CaptureLane string `gorm:"type:varchar(120)" json:"captureLane"`
- VidiconPixel int `gorm:"type:int" json:"vidiconPixel"`
- VidiconSpecification string `gorm:"type:varchar(255)" json:"vidiconSpecification"`
- RadarCount int `gorm:"type:int" json:"radarCount"`
- RadarSpecification string `gorm:"type:varchar(255)" json:"radarSpecification"`
- SuggestSpeed int `gorm:"type:int" json:"suggestSpeed"`
- FillLightCount int `gorm:"type:int" json:"fillLightCount"`
- FillLightSpecification string `gorm:"type:varchar(255)" json:"fillLightSpecification"`
- PowerSpecification string `gorm:"type:varchar(255)" json:"powerSpecification"`
- CaptureIp string `gorm:"type:varchar(60)" json:"captureIp"`
- CapturePort int `gorm:"type:int" json:"capturePort"`
- GatewayId int `gorm:"type:int" json:"gatewayId"`
- GatewayName string `gorm:"type:varchar(80)" json:"gatewayName"`
- GatewaySn string `gorm:"type:varchar(30)" json:"gatewaySn"`
- TenantId string `gorm:"type:varchar(12)" json:"tenantId"`
- CreateTime time.Time `gorm:"type:datetime" json:"createTime"`
- CreateUser int64 `gorm:"type:bigint" json:"createUser"`
- UpdateTime time.Time `gorm:"type:datetime" json:"updateTime"`
- UpdateUser int64 `gorm:"type:bigint" json:"updateUser"`
- IsDeleted int `gorm:"type:int;default 0" json:"isDeleted"`
- }
- func (CaptureUnit) TableName() string {
- return "device_capture_unit"
- }
- func (c CaptureUnit) IsExistedBySN() bool {
- var count int64
- _ = Db.Debug().Model(&c).Where("capture_sn = ? and is_deleted = ?",
- c.CaptureSn, c.IsDeleted).Count(&count).Error
- return count > 0
- }
- func (c *CaptureUnit) Create() error {
- return Db.Debug().Model(&c).Save(&c).Error
- }
- func (c *CaptureUnit) Update() error {
- return Db.Debug().Model(&c).Where(" id = ? ", c.ID).Updates(&c).Error
- }
- func (c *CaptureUnit) GetDevice() error {
- err := Db.Debug().Model(&c).Where(" id = ? ", c.ID).First(&c).Error
- return err
- }
- func (c CaptureUnit) GetDevices(offset, limit int) ([]CaptureUnit, int64, error) {
- var Captures []CaptureUnit
- var count int64
- db := Db.Debug().Model(&c)
- if c.CaptureSn != "" {
- db = db.Where("capture_name like ? or capture_sn like ?", "%"+c.CaptureSn+"%", "%"+c.CaptureSn+"%")
- }
- db = db.Where("is_deleted = 0")
- db.Count(&count)
- err := db.Offset(offset).Limit(limit).Find(&Captures).Error
- return Captures, count, err
- }
- func (c *CaptureUnit) Delete() error {
- return Db.Debug().Model(&c).Where("id = ?", c.ID).Updates(map[string]interface{}{"update_time": c.UpdateTime,
- "update_user": c.UpdateUser, "is_deleted": c.IsDeleted}).Error
- }
- func (c CaptureUnit) GetAllDevices() ([]*CaptureUnit, error) {
- var Captures []*CaptureUnit
- err := Db.Debug().Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantId, c.IsDeleted).Scan(&Captures).Error
- return Captures, err
- }
- func (c CaptureUnit) GetDevicesByGateway() []CaptureUnit {
- var devices []CaptureUnit
- Db.Debug().Model(&c).Where(" gateway_id = ? and is_deleted = 0",
- c.GatewayId).Find(&devices)
- return devices
- }
- func (c CaptureUnit) GetDevicesByLampPole() []CaptureUnit {
- var devices []CaptureUnit
- Db.Debug().Model(&c).Where("lamp_pole_id = ? and is_deleted = 0",
- c.LampPoleId).Find(&devices)
- return devices
- }
|