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.

45 lines
1.2 KiB

  1. package dbModel
  2. import (
  3. "gin-vue-admin/controller/servers"
  4. "gin-vue-admin/init/qmsql"
  5. "gin-vue-admin/model/modelInterface"
  6. "github.com/jinzhu/gorm"
  7. )
  8. type ExaFileUploadAndDownload struct {
  9. gorm.Model
  10. Name string `json:"name"`
  11. Url string `json:"url"`
  12. Tag string `json:"tag"`
  13. Key string `json:"key"`
  14. }
  15. func (f *ExaFileUploadAndDownload) Upload() error {
  16. err := qmsql.DEFAULTDB.Create(f).Error
  17. return err
  18. }
  19. func (f *ExaFileUploadAndDownload) DeleteFile() error {
  20. err := qmsql.DEFAULTDB.Where("id = ?", f.ID).Unscoped().Delete(f).Error
  21. return err
  22. }
  23. func (f *ExaFileUploadAndDownload) FindFile() (error, ExaFileUploadAndDownload) {
  24. var file ExaFileUploadAndDownload
  25. err := qmsql.DEFAULTDB.Where("id = ?", f.ID).First(&file).Error
  26. return err, file
  27. }
  28. // 分页获取数据 需要分页实现这个接口即可
  29. func (f *ExaFileUploadAndDownload) GetInfoList(info modelInterface.PageInfo) (err error, list interface{}, total int) {
  30. // 封装分页方法 调用即可 传入 当前的结构体和分页信息
  31. err, db, total := servers.PagingServer(f, info)
  32. if err != nil {
  33. return
  34. } else {
  35. var fileLists []ExaFileUploadAndDownload
  36. err = db.Order("updated_at desc").Find(&fileLists).Error
  37. return err, fileLists, total
  38. }
  39. }