libraryDao.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. SysType int `gorm:"type:int" json:"sysType"` //系统类型:0-信息发布系统,1-广播系统
  17. TenantId string `gorm:"type:varchar(12)" json:"tenantId"` //租户ID
  18. CreateTime time.Time `gorm:"type:datetime" json:"createTime"` //新增时间
  19. CreateUser int `gorm:"type:int" json:"createUser"` //新增记录操作用户ID
  20. UpdateTime time.Time `gorm:"type:datetime" json:"updateTime"` //修改时间
  21. UpdateUser int `gorm:"type:int" json:"updateUser"` //修改用户
  22. IsDeleted int `gorm:"type:int;default 0" json:"isDeleted"` //是否删除 0=未删除,1=删除
  23. }
  24. func (Library) TableName() string {
  25. return "media_library"
  26. }
  27. func (c *Library) Create() error {
  28. return Db.Model(&c).Save(c).Error
  29. }
  30. func (c *Library) GetLibraries(offset, limit int) ([]Library, int64, error) {
  31. var libraries []Library
  32. var count int64
  33. db := Db.Model(&c)
  34. if c.LibName != "" {
  35. db = db.Where("lib_name like ?", "%"+c.LibName+"%")
  36. }
  37. if c.SysType == 0 || c.SysType == 1 {
  38. db = db.Where("sys_type = ?", c.SysType)
  39. }
  40. if c.LibType >= 1 {
  41. db = db.Where("lib_type = ?", c.LibType)
  42. }
  43. db = db.Where("is_deleted = 0 and tenant_id = ?", c.TenantId)
  44. db.Count(&count)
  45. err := db.Offset(offset).Limit(limit).Find(&libraries).Error
  46. return libraries, count, err
  47. }
  48. func (c *Library) Get() error {
  49. return Db.Model(&c).Where("is_deleted = 0 and id = ?", c.ID).Find(&c).Error
  50. }
  51. func (c *Library) Delete() error {
  52. return Db.Model(&c).Where("id = ?", c.ID).Updates(map[string]interface{}{"update_time": c.UpdateTime,
  53. "update_user": c.UpdateUser, "is_deleted": c.IsDeleted}).Error
  54. }
  55. func (c *Library) GetAll() ([]Library, error) {
  56. var libraries []Library
  57. db := Db.Model(&c).Where("is_deleted=0 and tenant_id = ?", c.TenantId)
  58. if c.LibName != "" {
  59. db = db.Where("lib_name like ?", "%"+c.LibName+"%")
  60. }
  61. if c.LibType > 0 {
  62. db = db.Where("lib_type = ?", c.LibType)
  63. }
  64. if c.SysType == 0 || c.SysType == 1 {
  65. db = db.Where("sys_type = ?", c.SysType)
  66. }
  67. err := db.Find(&libraries).Order("create_time").Error
  68. return libraries, err
  69. }
  70. func (c *Library) Update() error {
  71. return Db.Model(&c).Where(" id = ? ", c.ID).Updates(&c).Error
  72. }
  73. func (c *Library) GetLibrariesByIds(ids []int) ([]Library, error) {
  74. var libraries []Library
  75. //err := Db.Model(&c).Where("is_deleted = 0 and tenant_id = ? and id in (?)",
  76. err := Db.Model(&c).Where("tenant_id = ? and id in (?)",
  77. c.TenantId, ids).Find(&libraries).Error
  78. return libraries, err
  79. }