programDao.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. TenantId int `gorm:"type:int" json:"tenantId"` //租户ID
  14. CreateTime time.Time `gorm:"type:datetime" json:"createTime"` //新增时间
  15. CreateUser int64 `gorm:"type:bigint" json:"createUser"` //新增记录操作用户ID
  16. UpdateTime time.Time `gorm:"type:datetime" json:"updateTime"` //修改时间
  17. UpdateUser int64 `gorm:"type:bigint" json:"updateUser"` //修改用户
  18. IsDeleted int `gorm:"type:int;default 0" json:"isDeleted"` //是否删除 0=未删除,1=删除
  19. }
  20. func (Program) TableName() string {
  21. return "media_program"
  22. }
  23. func (c *Program) Create() error {
  24. return Db.Debug().Model(&c).Save(c).Error
  25. }
  26. func (c *Program) Remove() error {
  27. return Db.Debug().Model(&c).Where("id = ?", c.ID).Delete(c).Error
  28. }
  29. func (c *Program) GetPrograms(offset, limit int) ([]Program, error) {
  30. var Programs []Program
  31. db := Db.Debug().Model(&c)
  32. if c.Name != "" {
  33. db = db.Where("name like ?", "%"+c.Name+"%")
  34. }
  35. err := db.Where("is_deleted = 0 and tenant_id = ?", c.TenantId).Offset(offset).Limit(limit).Find(&Programs).Error
  36. return Programs, err
  37. }
  38. func (c *Program) Get() error {
  39. return Db.Debug().Model(&c).Where("is_deleted = 0 and id = ?", c.ID).Find(&c).Error
  40. }
  41. func (c *Program) Delete() error {
  42. return Db.Debug().Model(&c).Where("id = ?", c.ID).Updates(map[string]interface{}{"update_time": c.UpdateTime,
  43. "update_user": c.UpdateUser, "is_deleted": c.IsDeleted}).Error
  44. }
  45. func (c *Program) GetAll() ([]Program, error) {
  46. var Programs []Program
  47. db := Db.Debug().Model(&c).Where("tenant_id = ?", c.TenantId)
  48. if c.Name != "" {
  49. db = db.Where("name like ?", "%"+c.Name+"%")
  50. }
  51. err := db.Find(&Programs).Order("create_time").Error
  52. return Programs, err
  53. }
  54. func (c *Program) Update() error {
  55. return Db.Debug().Model(&c).Where(" id = ? ", c.ID).Update(&c).Error
  56. }