programDao.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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:"sysTrecordype"` //系统类型:0-信息发布系统,1-广播系统
  14. TenantId string `gorm:"type:varchar(12)" json:"tenantId"` //租户ID
  15. CreateTime time.Time `gorm:"type:datetime" json:"createTime"` //新增时间
  16. CreateUser int `gorm:"type:int" json:"createUser"` //新增记录操作用户ID
  17. UpdateTime time.Time `gorm:"type:datetime" json:"updateTime"` //修改时间
  18. UpdateUser int `gorm:"type:int" 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.Model(&c).Save(c).Error
  26. }
  27. func (c *Program) Remove() error {
  28. return Db.Model(&c).Where("id = ?", c.ID).Delete(c).Error
  29. }
  30. func (c *Program) GetPrograms(offset, limit int) ([]Program, int64, error) {
  31. var Programs []Program
  32. var count int64
  33. db := Db.Model(&c)
  34. if c.Name != "" {
  35. db = db.Where("name like ?", "%"+c.Name+"%")
  36. }
  37. if c.SysType == 0 || c.SysType == 1 {
  38. db = db.Where("sys_type = ?", c.SysType)
  39. }
  40. db = db.Where("is_deleted = 0 and tenant_id = ?", c.TenantId)
  41. db.Count(&count)
  42. err := db.Offset(offset).Limit(limit).Order("id desc").Find(&Programs).Error
  43. return Programs, count, err
  44. }
  45. func (c *Program) Get() error {
  46. return Db.Model(&c).Where("is_deleted = 0 and id = ?", c.ID).Find(&c).Error
  47. }
  48. func (c *Program) Delete() error {
  49. return Db.Model(&c).Where("id = ?", c.ID).Updates(map[string]interface{}{"update_time": c.UpdateTime,
  50. "update_user": c.UpdateUser, "is_deleted": c.IsDeleted}).Error
  51. }
  52. func (c *Program) GetAll() ([]Program, error) {
  53. var Programs []Program
  54. db := Db.Model(&c).Where("tenant_id = ?", c.TenantId)
  55. if c.Name != "" {
  56. db = db.Where("name like ?", "%"+c.Name+"%")
  57. }
  58. err := db.Find(&Programs).Order("create_time").Error
  59. return Programs, err
  60. }
  61. func (c *Program) Update() error {
  62. return Db.Model(&c).Where(" id = ? ", c.ID).Updates(&c).Error
  63. }