You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.1 KiB

  1. package model
  2. import (
  3. "gin-vue-admin/global"
  4. "github.com/jinzhu/gorm"
  5. )
  6. type ExaFileUploadAndDownload struct {
  7. gorm.Model
  8. Name string `json:"name"`
  9. Url string `json:"url"`
  10. Tag string `json:"tag"`
  11. Key string `json:"key"`
  12. }
  13. func (f *ExaFileUploadAndDownload) Upload() error {
  14. err := global.GVA_DB.Create(f).Error
  15. return err
  16. }
  17. func (f *ExaFileUploadAndDownload) DeleteFile() error {
  18. err := global.GVA_DB.Where("id = ?", f.ID).Unscoped().Delete(f).Error
  19. return err
  20. }
  21. func (f *ExaFileUploadAndDownload) FindFile() (error, ExaFileUploadAndDownload) {
  22. var file ExaFileUploadAndDownload
  23. err := global.GVA_DB.Where("id = ?", f.ID).First(&file).Error
  24. return err, file
  25. }
  26. // 分页获取数据
  27. func (f *ExaFileUploadAndDownload) GetInfoList(info PageInfo) (err error, list interface{}, total int) {
  28. limit := info.PageSize
  29. offset := info.PageSize * (info.Page - 1)
  30. db := global.GVA_DB
  31. if err != nil {
  32. return
  33. } else {
  34. var fileLists []ExaFileUploadAndDownload
  35. err = db.Limit(limit).Offset(offset).Order("updated_at desc").Find(&fileLists).Error
  36. return err, fileLists, total
  37. }
  38. }