e_user.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. H5AssistantId: a.H5AssistantId,
  27. }
  28. return item
  29. }
  30. // ToSchemaUser 转换为User对象
  31. func (a User) ToSchemaUser() *schema.User {
  32. item := &schema.User{
  33. RecordID: a.RecordID,
  34. UserName: a.UserName,
  35. RealName: a.RealName,
  36. OrgId: a.OrgId,
  37. RoleId: a.RoleId,
  38. Phone: a.Phone,
  39. Password: a.Password,
  40. Photo: a.Photo,
  41. Status: a.Status,
  42. CreatedAt: a.CreatedAt,
  43. CreatorId: a.CreatorId,
  44. H5AssistantId: a.H5AssistantId,
  45. }
  46. return item
  47. }
  48. // User User实体
  49. type User struct {
  50. gorm.Model
  51. RecordID string `gorm:"column:record_id;size:32;index;"`
  52. UserName string `gorm:"column:user_name;size:20;"`
  53. RealName string `gorm:"column:real_name;size:20;"`
  54. RoleId string `gorm:"column:role_id;size:32;index;"`
  55. OrgId string `gorm:"column:org_id;size:32;index;"`
  56. Phone string `gorm:"column:phone;size:20;"`
  57. Password string `gorm:"column:password;size:100;"`
  58. Photo string `gorm:"column:photo;size:200;"`
  59. Status bool `gorm:"column:status;"`
  60. CreatorId string `gorm:"column:creator_id;size:32;"`
  61. H5AssistantId string `gorm:"column:h5_assistant_id;size:32;"`
  62. }
  63. // Users User列表
  64. type Users []*User
  65. // ToSchemaUsers 转换为User对象列表
  66. func (a Users) ToSchemaUsers() []*schema.User {
  67. list := make([]*schema.User, len(a))
  68. for i, item := range a {
  69. list[i] = item.ToSchemaUser()
  70. }
  71. return list
  72. }