e_file_history.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package entity
  2. import (
  3. "context"
  4. "gorm.io/gorm"
  5. "gxt-file-server/app/schema"
  6. )
  7. // GetFileHistoryDB 获取demo存储
  8. func GetFileHistoryDB(ctx context.Context, defDB *gorm.DB) *gorm.DB {
  9. return getDBWithModel(ctx, defDB, FileHistory{})
  10. }
  11. // SchemaFileHistory demo对象
  12. type SchemaFileHistory schema.FileHistory
  13. // ToFileHistory 转换为demo实体
  14. func (a SchemaFileHistory) ToFileHistory() *FileHistory {
  15. item := &FileHistory{
  16. RecordID: a.RecordID,
  17. Hash: a.Hash,
  18. Path: a.Path,
  19. FileName: a.FileName,
  20. FileSize: a.FileSize,
  21. IsPersistent: a.IsPersistent,
  22. Creator: &a.Creator,
  23. FileHash: a.FileHash,
  24. }
  25. return item
  26. }
  27. // ToSchemaFileHistory 转换为demo对象
  28. func (a FileHistory) ToSchemaFileHistory() *schema.FileHistory {
  29. item := &schema.FileHistory{
  30. RecordID: a.RecordID,
  31. Creator: *a.Creator,
  32. Hash: a.Hash,
  33. Path: a.Path,
  34. FileName: a.FileName,
  35. FileSize: a.FileSize,
  36. IsPersistent: a.IsPersistent,
  37. CreatedAt: a.CreatedAt,
  38. FileHash: a.FileHash,
  39. }
  40. return item
  41. }
  42. // FileHistory demo实体
  43. type FileHistory struct {
  44. gorm.Model
  45. RecordID string `gorm:"column:record_id;size:32;index;"` // 记录内码
  46. Hash string `gorm:"column:hash;index;"`
  47. Path string `gorm:"column:path;size:250"`
  48. FileSize int64 `gorm:"column:file_size"`
  49. FileName string `gorm:"column:file_name;size:200"`
  50. IsPersistent int `gorm:"column:is_persistent"` // 是否持久化
  51. Creator *string `gorm:"column:creator;size:32;"` // 创建者
  52. FileHash string `gorm:"column:file_hash;"`
  53. }
  54. // FileHistories demo列表
  55. type FileHistories []*FileHistory
  56. // ToSchemaFileHistories 转换为demo对象列表
  57. func (a FileHistories) ToSchemaFileHistories() []*schema.FileHistory {
  58. list := make([]*schema.FileHistory, len(a))
  59. for i, item := range a {
  60. list[i] = item.ToSchemaFileHistory()
  61. }
  62. return list
  63. }