123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- package devices
- import (
- "gorm.io/gorm"
- "server/global"
- "server/model/common/request"
- "time"
- )
- type Screens struct {
- ID int `gorm:"primarykey" json:"ID"` //主键ID
- ScreensName string `gorm:"type:varchar(64)" json:"screensName"` //设备名称
- ScreensCode string `gorm:"type:varchar(64)" json:"screensCode"` //设备编码
- Sn string `gorm:"type:varchar(64)" json:"sn"` //设备sn
- Network int `gorm:"type:int" json:"network"` //组网方式 0代表网关 1代表4G模块
- GatewayId int `gorm:"type:int" json:"gatewayId"` //所属网关
- ScreensBrand string `gorm:"type:varchar(60)" json:"screensBrand"` //屏幕品牌
- ScreensModel string `gorm:"type:varchar(60)" json:"screensModel"` //屏幕型号
- IPAddress string `gorm:"type:varchar(40)" json:"ipAddress"` //IP地址
- InstallTime time.Time `gorm:"type:date" json:"installTime"` //安装时间
- Shunt int `gorm:"type:int" json:"shunt"` //所属分路 1主路,2支路
- ShuntDescribe string `gorm:"type:varchar(60)" json:"shuntDescribe"` //分路描述
- ResolutionId int `gorm:"type:int" json:"resolutionId"` //分辨率
- ScreensSizeId int `gorm:"type:int" json:"screensSizeId"` //信息屏尺寸
- IsDeleted gorm.DeletedAt `gorm:"default:null" json:"isDeleted"` //是否删除
- Status int `gorm:"type:int;default:0" json:"status"` //在线状态 0=离线,1=在线
- PlayStatus int `gorm:"type:int;default:0" json:"playStatus"` //播放状态
- DisplayStatus int `gorm:"type:int;default:0" json:"displayStatus"` //显示模板状态
- SourceStatus int `gorm:"type:int;default:0" json:"sourceStatus"` //素材状态
- DayBright int `gorm:"type:int;default:100" json:"dayBright"` //白天亮度
- NightBright int `gorm:"type:int;default:30" json:"nightBright"` //晚上亮度
- GateWay GateWay `gorm:"foreignkey:GatewayId"`
- Resolution Resolution `gorm:"foreignkey:ResolutionId"`
- ScreensSize ScreensSize `gorm:"foreignkey:ScreensSizeId"`
- }
- func (Screens) TableName() string {
- return "dev_screens"
- }
- func (s Screens) DelScreens(id int) error {
- err := global.GVA_DB.Model(&s).Where("id = ?", id).Delete(&s).Error
- return err
- }
- func (s Screens) IsExistedByCode() error {
- err := global.GVA_DB.Model(&Screens{}).Where("screens_code = ?", s.ScreensCode).First(&s).Error
- return err
- }
- func (s Screens) AddScreens() error {
- err := global.GVA_DB.Model(&Screens{}).Create(&s).Error
- return err
- }
- func (s Screens) UpdateScreens() error {
- err := global.GVA_DB.Model(&s).
- Select("screens_name", "screens_code", "sn", "network", "gateway_id", "screens_brand", "screens_model", "ip_address", "install_time", "shunt", "shunt_describe", "resolution_id", "screens_size_id").
- Where("id=?", s.ID).
- Updates(map[string]interface{}{
- "screens_name": s.ScreensName,
- "screens_code": s.ScreensCode,
- "sn": s.Sn,
- "network": s.Network,
- "gateway_id": s.GatewayId,
- "screens_brand": s.ScreensBrand,
- "screens_model": s.ScreensModel,
- "ip_address": s.IPAddress,
- "install_time": s.InstallTime,
- "shunt": s.Shunt,
- "shunt_describe": s.ShuntDescribe,
- "resolution_id": s.ResolutionId,
- "screens_size_id": s.ScreensSizeId,
- }).Error
- return err
- }
- func QueryScreensInfoList(limit, offset int, keyword, shunt string) (screensList []Screens, total int64, err error) {
- db := global.GVA_DB.Model(&Screens{})
- if keyword != "" {
- db.Where("screens_name like ? or screens_code like ?", "%"+keyword+"%", "%"+keyword+"%")
- }
- if shunt != "" {
- db.Where("shunt = ?", shunt)
- }
- err = db.Count(&total).Error
- if err != nil {
- return
- }
- err = db.Limit(limit).Offset(offset).Preload("GateWay").Preload("Resolution").Preload("ScreensSize").Find(&screensList).Error
- return
- }
- func QueryScreensToDetail(id int) (screensList []Screens, err error) {
- db := global.GVA_DB.Model(&Screens{})
- err = db.Where("gateway_id = ?", id).Find(&screensList).Error
- return
- }
- func UpdateScreensStatusByGatewayId(id, status int) error {
- var screens Screens
- err := global.GVA_DB.Model(&screens).
- Select("status", "play_status", "display_status", "source_status").
- Where("gateway_id = ?", id).
- Updates(map[string]interface{}{
- "status": status,
- "play_status": status,
- "display_status": status,
- "source_status": status,
- }).Error
- return err
- }
- func UpdateScreensStatus(code string, sta request.DeviceStatus) error {
- var screens Screens
- return global.GVA_DB.Model(&screens).Select("status", "play_status", "display_status", "source_status").
- Where("screens_code = ?", code).Updates(map[string]interface{}{
- "status": sta.Status,
- "play_status": sta.PlayStatus,
- "display_status": sta.DisplayStatus,
- "source_status": sta.SourceStatus,
- }).Error
- }
- // 根据sn查询设备是否存在
- func QueryScreenBySn(sn string) (screens Screens, err error) {
- err = global.GVA_DB.Model(&screens).Where("sn = ?", sn).First(&screens).Error
- if err != nil {
- return Screens{}, err
- }
- return screens, nil
- }
- // 根据sn更新白天晚上亮度
- func (s Screens) UpdateBrightnessBySn(sn string, dayBright, nightBright int) error {
- err := global.GVA_DB.Model(&s).
- Select("day_bright", "night_bright").
- Where("sn = ?", sn).
- Updates(map[string]interface{}{
- "day_bright": dayBright,
- "night_bright": nightBright,
- }).Error
- return err
- }
- // 获取在线的led屏幕
- func (s Screens) QueryOnlineScreens() (screensList []Screens, err error) {
- err = global.GVA_DB.Model(&Screens{}).Where("status =?", 1).Find(&screensList).Error
- return
- }
|