| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- package entity
- import (
- "context"
- "gorm.io/gorm"
- "yx-dataset-server/app/schema"
- )
- // GetUserDB 获取User存储
- func GetUserDB(ctx context.Context, defDB *gorm.DB) *gorm.DB {
- return getDBWithModel(ctx, defDB, User{})
- }
- // SchemaUser User对象
- type SchemaUser schema.User
- // ToUser 转换为User实体
- func (a SchemaUser) ToUser() *User {
- item := &User{
- RecordID: a.RecordID,
- UserName: a.UserName,
- RealName: a.RealName,
- OrgId: a.OrgId,
- RoleId: a.RoleId,
- Phone: a.Phone,
- Password: a.Password,
- Photo: a.Photo,
- Status: a.Status,
- CreatorId: a.CreatorId,
- }
- return item
- }
- // ToSchemaUser 转换为User对象
- func (a User) ToSchemaUser() *schema.User {
- item := &schema.User{
- RecordID: a.RecordID,
- UserName: a.UserName,
- RealName: a.RealName,
- OrgId: a.OrgId,
- RoleId: a.RoleId,
- Phone: a.Phone,
- Password: a.Password,
- Photo: a.Photo,
- Status: a.Status,
- CreatedAt: a.CreatedAt,
- CreatorId: a.CreatorId,
- }
- return item
- }
- // User User实体
- type User struct {
- gorm.Model
- RecordID string `gorm:"column:record_id;size:32;index;"`
- UserName string `gorm:"column:user_name;size:20;"`
- RealName string `gorm:"column:real_name;size:20;"`
- RoleId string `gorm:"column:role_id;size:32;index;"`
- OrgId string `gorm:"column:org_id;size:32;index;"`
- Phone string `gorm:"column:phone;size:20;"`
- Password string `gorm:"column:password;size:100;"`
- Photo string `gorm:"column:photo;size:200;"`
- Status bool `gorm:"column:status;"`
- CreatorId string `gorm:"column:creator_id;size:32;"`
- }
- // Users User列表
- type Users []*User
- // ToSchemaUsers 转换为User对象列表
- func (a Users) ToSchemaUsers() []*schema.User {
- list := make([]*schema.User, len(a))
- for i, item := range a {
- list[i] = item.ToSchemaUser()
- }
- return list
- }
|