e_file_chunk.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package entity
  2. import (
  3. "context"
  4. "gorm.io/gorm"
  5. "gxt-file-server/app/schema"
  6. "time"
  7. )
  8. // GetFileChunkDB 获取demo存储
  9. func GetFileChunkDB(ctx context.Context, defDB *gorm.DB) *gorm.DB {
  10. return getDBWithModel(ctx, defDB, FileChunk{})
  11. }
  12. // SchemaFileChunk demo对象
  13. type SchemaFileChunk schema.FileChunk
  14. // ToFileChunk 转换为demo实体
  15. func (a SchemaFileChunk) ToFileChunk() *FileChunk {
  16. item := &FileChunk{
  17. RecordID: a.RecordID,
  18. Hash: a.Hash,
  19. Path: a.Path,
  20. Name: a.Name,
  21. Total: a.Total,
  22. Current: a.Current,
  23. Size: a.Size,
  24. Creator: &a.Creator,
  25. FileHash: a.FileHash,
  26. PastTime: a.PastTime,
  27. }
  28. return item
  29. }
  30. // ToSchemaFileChunk 转换为demo对象
  31. func (a FileChunk) ToSchemaFileChunk() *schema.FileChunk {
  32. item := &schema.FileChunk{
  33. RecordID: a.RecordID,
  34. Hash: a.Hash,
  35. Path: a.Path,
  36. Name: a.Name,
  37. Total: a.Total,
  38. Current: a.Current,
  39. Size: a.Size,
  40. Creator: *a.Creator,
  41. CreatedAt: a.CreatedAt,
  42. FileHash: a.FileHash,
  43. PastTime: a.PastTime,
  44. }
  45. return item
  46. }
  47. // FileChunk demo实体
  48. type FileChunk struct {
  49. gorm.Model
  50. RecordID string `gorm:"column:record_id;size:32;index;"` // 记录内码
  51. Hash string `gorm:"column:hash;size:36;index"`
  52. FileHash string `gorm:"column:file_hash;size:36;index"`
  53. Path string `gorm:"column:path;size:250"`
  54. Name string `gorm:"column:name;size:200"`
  55. Total int `gorm:"column:total"`
  56. Current int `gorm:"column:current"`
  57. Size int64 `gorm:"column:size"`
  58. Creator *string `gorm:"column:creator;size:32;"` // 创建者
  59. PastTime time.Time `gorm:"column:past_time;"` //文件块过期的时间
  60. }
  61. // FileChunks demo列表
  62. type FileChunks []*FileChunk
  63. // ToSchemaFileChunks 转换为demo对象列表
  64. func (a FileChunks) ToSchemaFileChunks() []*schema.FileChunk {
  65. list := make([]*schema.FileChunk, len(a))
  66. for i, item := range a {
  67. list[i] = item.ToSchemaFileChunk()
  68. }
  69. return list
  70. }