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.

59 lines
1.8 KiB

  1. package service
  2. import (
  3. "gin-vue-admin/global"
  4. "gin-vue-admin/model"
  5. "gin-vue-admin/model/request"
  6. )
  7. // @title Upload
  8. // @description 创建文件上传记录
  9. // @param file model.ExaFileUploadAndDownload
  10. // @auth (2020/04/05 20:22)
  11. // @return error
  12. func Upload(file model.ExaFileUploadAndDownload) error {
  13. err := global.GVA_DB.Create(&file).Error
  14. return err
  15. }
  16. // @title FindFile
  17. // @description 删除文件切片记录
  18. // @auth (2020/04/05 20:22)
  19. // @param id uint
  20. // @return error
  21. func FindFile(id uint) (error, model.ExaFileUploadAndDownload) {
  22. var file model.ExaFileUploadAndDownload
  23. err := global.GVA_DB.Where("id = ?", id).First(&file).Error
  24. return err, file
  25. }
  26. // @title DeleteFile
  27. // @description 删除文件记录
  28. // @auth (2020/04/05 20:22)
  29. // @param file model.ExaFileUploadAndDownload
  30. // @return error
  31. func DeleteFile(file model.ExaFileUploadAndDownload) error {
  32. err := global.GVA_DB.Where("id = ?", file.ID).Unscoped().Delete(file).Error
  33. return err
  34. }
  35. // @title GetFileRecordInfoList
  36. // @description 分页获取数据
  37. // @auth (2020/04/05 20:22)
  38. // @param info PageInfo
  39. // @return err error
  40. // @return list error
  41. // @return total error
  42. func GetFileRecordInfoList(info request.PageInfo) (err error, list interface{}, total int64) {
  43. limit := info.PageSize
  44. offset := info.PageSize * (info.Page - 1)
  45. db := global.GVA_DB
  46. var fileLists []model.ExaFileUploadAndDownload
  47. err = db.Find(&fileLists).Count(&total).Error
  48. err = db.Limit(limit).Offset(offset).Order("updated_at desc").Find(&fileLists).Error
  49. return err, fileLists, total
  50. }