programDao.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package dao
  2. import (
  3. "time"
  4. )
  5. type Program struct {
  6. ID int `gorm:"primary_key" json:"id"` //编号
  7. Name string `gorm:"type:varchar(64)" json:"name"` //名称
  8. Resolution int `gorm:"type:int" json:"resolution"` //分辨率 枚举编号
  9. Duration int64 `gorm:"type:bigint" json:"duration"` //统计总时长
  10. FileSize int64 `gorm:"type:bigint" json:"fileSize"` //统计文件总大小
  11. ImgDuration int `gorm:"type:int;default 0" json:"imgDuration"` //图片播放时长(毫秒)
  12. Remarks string `gorm:"type:varchar(4000)" json:"remarks"` //备注
  13. SysType int `gorm:"type:int" json:"sysType"` //系统类型:0-信息发布系统,1-广播系统
  14. TenantId int `gorm:"type:int" json:"tenantId"` //租户ID
  15. CreateTime time.Time `gorm:"type:datetime" json:"createTime"` //新增时间
  16. CreateUser int64 `gorm:"type:bigint" json:"createUser"` //新增记录操作用户ID
  17. UpdateTime time.Time `gorm:"type:datetime" json:"updateTime"` //修改时间
  18. UpdateUser int64 `gorm:"type:bigint" json:"updateUser"` //修改用户
  19. IsDeleted int `gorm:"type:int;default 0" json:"isDeleted"` //是否删除 0=未删除,1=删除
  20. }
  21. func (Program) TableName() string {
  22. return "media_program"
  23. }
  24. func (c *Program) Create() error {
  25. return Db.Debug().Model(&c).Save(c).Error
  26. }
  27. func (c *Program) Remove() error {
  28. return Db.Debug().Model(&c).Where("id = ?", c.ID).Delete(c).Error
  29. }
  30. func (c *Program) GetPrograms(offset, limit int) ([]Program, error) {
  31. var Programs []Program
  32. db := Db.Debug().Model(&c)
  33. if c.Name != "" {
  34. db = db.Where("name like ?", "%"+c.Name+"%")
  35. }
  36. if c.SysType == 0 || c.SysType == 1 {
  37. db = db.Where("sys_type = ?", c.SysType)
  38. }
  39. err := db.Where("is_deleted = 0 and tenant_id = ?", c.TenantId).Offset(offset).Limit(limit).Find(&Programs).Error
  40. return Programs, err
  41. }
  42. func (c *Program) Get() error {
  43. return Db.Debug().Model(&c).Where("is_deleted = 0 and id = ?", c.ID).Find(&c).Error
  44. }
  45. func (c *Program) Delete() error {
  46. return Db.Debug().Model(&c).Where("id = ?", c.ID).Updates(map[string]interface{}{"update_time": c.UpdateTime,
  47. "update_user": c.UpdateUser, "is_deleted": c.IsDeleted}).Error
  48. }
  49. func (c *Program) GetAll() ([]Program, error) {
  50. var Programs []Program
  51. db := Db.Debug().Model(&c).Where("tenant_id = ?", c.TenantId)
  52. if c.Name != "" {
  53. db = db.Where("name like ?", "%"+c.Name+"%")
  54. }
  55. err := db.Find(&Programs).Order("create_time").Error
  56. return Programs, err
  57. }
  58. func (c *Program) Update() error {
  59. return Db.Debug().Model(&c).Where(" id = ? ", c.ID).Update(&c).Error
  60. }