e_demo.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package entity
  2. import (
  3. "context"
  4. "gorm.io/gorm"
  5. "gxt-file-server/app/schema"
  6. )
  7. // GetDemoDB 获取demo存储
  8. func GetDemoDB(ctx context.Context, defDB *gorm.DB) *gorm.DB {
  9. return getDBWithModel(ctx, defDB, Demo{})
  10. }
  11. // SchemaDemo demo对象
  12. type SchemaDemo schema.Demo
  13. // ToDemo 转换为demo实体
  14. func (a SchemaDemo) ToDemo() *Demo {
  15. item := &Demo{
  16. RecordID: a.RecordID,
  17. Code: &a.Code,
  18. Name: &a.Name,
  19. Memo: &a.Memo,
  20. Status: &a.Status,
  21. Creator: &a.Creator,
  22. }
  23. return item
  24. }
  25. // ToSchemaDemo 转换为demo对象
  26. func (a Demo) ToSchemaDemo() *schema.Demo {
  27. item := &schema.Demo{
  28. RecordID: a.RecordID,
  29. Code: *a.Code,
  30. Name: *a.Name,
  31. Memo: *a.Memo,
  32. Status: *a.Status,
  33. Creator: *a.Creator,
  34. CreatedAt: a.CreatedAt,
  35. }
  36. return item
  37. }
  38. // Demo demo实体
  39. type Demo struct {
  40. gorm.Model
  41. RecordID string `gorm:"column:record_id;size:32;index;"` // 记录内码
  42. Code *string `gorm:"column:code;size:50;index;"` // 编号
  43. Name *string `gorm:"column:name;size:100;index;"` // 名称
  44. Memo *string `gorm:"column:memo;size:200;"` // 备注
  45. Status *int `gorm:"column:status;index;"` // 状态(1:启用 2:停用)
  46. Creator *string `gorm:"column:creator;size:32;"` // 创建者
  47. }
  48. // Demos demo列表
  49. type Demos []*Demo
  50. // ToSchemaDemos 转换为demo对象列表
  51. func (a Demos) ToSchemaDemos() []*schema.Demo {
  52. list := make([]*schema.Demo, len(a))
  53. for i, item := range a {
  54. list[i] = item.ToSchemaDemo()
  55. }
  56. return list
  57. }