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.

62 lines
1.8 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. // @title Upload
  14. // @description 删除文件切片记录
  15. // @auth (2020/04/05 20:22 )
  16. // @return error
  17. func (f *ExaFileUploadAndDownload) Upload() error {
  18. err := global.GVA_DB.Create(f).Error
  19. return err
  20. }
  21. // @title DeleteFile
  22. // @description 删除文件切片记录
  23. // @auth (2020/04/05 20:22 )
  24. // @return error
  25. func (f *ExaFileUploadAndDownload) DeleteFile() error {
  26. err := global.GVA_DB.Where("id = ?", f.ID).Unscoped().Delete(f).Error
  27. return err
  28. }
  29. // @title FindFile
  30. // @description 删除文件切片记录
  31. // @auth (2020/04/05 20:22 )
  32. // @return error
  33. func (f *ExaFileUploadAndDownload) FindFile() (error, ExaFileUploadAndDownload) {
  34. var file ExaFileUploadAndDownload
  35. err := global.GVA_DB.Where("id = ?", f.ID).First(&file).Error
  36. return err, file
  37. }
  38. // @title GetInfoList
  39. // @description 分页获取数据
  40. // @auth (2020/04/05 20:22 )
  41. // @param info PageInfo
  42. // @return err error
  43. // @return list error
  44. // @return total error
  45. func (f *ExaFileUploadAndDownload) GetInfoList(info PageInfo) (err error, list interface{}, total int) {
  46. limit := info.PageSize
  47. offset := info.PageSize * (info.Page - 1)
  48. db := global.GVA_DB
  49. if err != nil {
  50. return
  51. } else {
  52. var fileLists []ExaFileUploadAndDownload
  53. err = db.Limit(limit).Offset(offset).Order("updated_at desc").Find(&fileLists).Error
  54. return err, fileLists, total
  55. }
  56. }