e_user.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package entity
  2. import (
  3. "context"
  4. "gorm.io/gorm"
  5. "yx-dataset-server/app/schema"
  6. )
  7. // GetUserDB 获取User存储
  8. func GetUserDB(ctx context.Context, defDB *gorm.DB) *gorm.DB {
  9. return getDBWithModel(ctx, defDB, User{})
  10. }
  11. // SchemaUser User对象
  12. type SchemaUser schema.User
  13. // ToUser 转换为User实体
  14. func (a SchemaUser) ToUser() *User {
  15. item := &User{
  16. RecordID: a.RecordID,
  17. UserName: a.UserName,
  18. RealName: a.RealName,
  19. OrgId: a.OrgId,
  20. RoleId: a.RoleId,
  21. Phone: a.Phone,
  22. Password: a.Password,
  23. Photo: a.Photo,
  24. Status: a.Status,
  25. CreatorId: a.CreatorId,
  26. }
  27. return item
  28. }
  29. // ToSchemaUser 转换为User对象
  30. func (a User) ToSchemaUser() *schema.User {
  31. item := &schema.User{
  32. RecordID: a.RecordID,
  33. UserName: a.UserName,
  34. RealName: a.RealName,
  35. OrgId: a.OrgId,
  36. RoleId: a.RoleId,
  37. Phone: a.Phone,
  38. Password: a.Password,
  39. Photo: a.Photo,
  40. Status: a.Status,
  41. CreatedAt: a.CreatedAt,
  42. CreatorId: a.CreatorId,
  43. }
  44. return item
  45. }
  46. // User User实体
  47. type User struct {
  48. gorm.Model
  49. RecordID string `gorm:"column:record_id;size:32;index;"`
  50. UserName string `gorm:"column:user_name;size:20;"`
  51. RealName string `gorm:"column:real_name;size:20;"`
  52. RoleId string `gorm:"column:role_id;size:32;index;"`
  53. OrgId string `gorm:"column:org_id;size:32;index;"`
  54. Phone string `gorm:"column:phone;size:20;"`
  55. Password string `gorm:"column:password;size:100;"`
  56. Photo string `gorm:"column:photo;size:200;"`
  57. Status bool `gorm:"column:status;"`
  58. CreatorId string `gorm:"column:creator_id;size:32;"`
  59. }
  60. // Users User列表
  61. type Users []*User
  62. // ToSchemaUsers 转换为User对象列表
  63. func (a Users) ToSchemaUsers() []*schema.User {
  64. list := make([]*schema.User, len(a))
  65. for i, item := range a {
  66. list[i] = item.ToSchemaUser()
  67. }
  68. return list
  69. }