libraryDao.go 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package dao
  2. import (
  3. "time"
  4. )
  5. type Library struct {
  6. ID int `gorm:"primary_key" json:"id"` //编号
  7. MaterialAddress string `gorm:"type:varchar(10000)" json:"materialAddress"` //素材地址
  8. LibName string `gorm:"type:varchar(64)" json:"libName"` //素材名称
  9. LibExplain string `gorm:"type:varchar(255)" json:"libExplain"` //素材说明
  10. LibType int `gorm:"type:int" json:"libType"` //素材类型:1-视频,2-图片,3-文字,4-音频
  11. Resolution string `gorm:"type:varchar(64)" json:"resolution"` //分辨率
  12. FileSize int64 `gorm:"type:bigint" json:"fileSize"` //文件大小
  13. LibDuration int `gorm:"type:int;default 0" json:"libDuration"` //获取视频时长
  14. FileId string `gorm:"type:varchar(255)" json:"fileId"` //文件ID,系统类型为广播系统时使用
  15. TalkSpeed int `gorm:"type:int;default 0" json:"talkSpeed"` //语速(用于文字广播):0-正常,1-快一些,2-很快
  16. TenantId int `gorm:"type:int" json:"tenantId"` //租户ID
  17. CreateTime time.Time `gorm:"type:datetime" json:"createTime"` //新增时间
  18. CreateUser int64 `gorm:"type:bigint" json:"createUser"` //新增记录操作用户ID
  19. UpdateTime time.Time `gorm:"type:datetime" json:"updateTime"` //修改时间
  20. UpdateUser int64 `gorm:"type:bigint" json:"updateUser"` //修改用户
  21. IsDeleted int `gorm:"type:int;default 0" json:"isDeleted"` //是否删除 0=未删除,1=删除
  22. }
  23. func (Library) TableName() string {
  24. return "media_library"
  25. }
  26. func (c *Library) Create() error {
  27. return Db.Debug().Model(&c).Save(c).Error
  28. }
  29. func (c *Library) GetLibraries(offset, limit int) ([]Library, error) {
  30. var libraries []Library
  31. db := Db.Debug().Model(&c)
  32. if c.LibName != "" {
  33. db = db.Where("lib_name like ?", "%"+c.LibName+"%")
  34. }
  35. err := db.Where("is_deleted = 0 and tenant_id = ?", c.TenantId).Offset(offset).Limit(limit).Find(&libraries).Error
  36. return libraries, err
  37. }
  38. func (c *Library) Get() error {
  39. return Db.Debug().Model(&c).Where("is_deleted = 0 and id = ?", c.ID).Find(&c).Error
  40. }
  41. func (c *Library) 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 *Library) GetAll() ([]Library, error) {
  46. var libraries []Library
  47. db := Db.Debug().Model(&c).Where("tenant_id = ?", c.TenantId)
  48. if c.LibName != "" {
  49. db = db.Where("lib_name like ?", "%"+c.LibName+"%")
  50. }
  51. if c.LibType > 0 {
  52. db = db.Where("lib_type = ?", c.LibType)
  53. }
  54. err := db.Find(&libraries).Order("create_time").Error
  55. return libraries, err
  56. }
  57. func (c *Library) Update() error {
  58. return Db.Debug().Model(&c).Where(" id = ? ", c.ID).Update(&c).Error
  59. }
  60. func (c *Library) GetLibrariesByIds(ids []int) ([]Library, error) {
  61. var libraries []Library
  62. err := Db.Debug().Model(&c).Where("is_deleted = 0 and tenant_id = ? and id in (?)",
  63. c.TenantId, ids).Find(&libraries).Error
  64. return libraries, err
  65. }