| | |
| | | "aps_crm/pkg/mysqlx" |
| | | "fmt" |
| | | "gorm.io/gorm" |
| | | "gorm.io/gorm/clause" |
| | | ) |
| | | |
| | | type ( |
| | | // User token里边把用户ID、父用户ID、角色都带上 |
| | | User struct { |
| | | ID int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | UUID string `json:"uuid" gorm:"primaryKey;type:varchar(255);comment:用户ID"` |
| | | UUID string `json:"uuid" gorm:"unique;type:varchar(255);comment:用户ID"` |
| | | Username string `json:"username" gorm:"index;type:varchar(255);comment:用户登录名"` |
| | | UserType constvar.UserType `json:"userType" gorm:"type:int(11);comment:用户类型 1超级管理员 2主账户 3子账户"` |
| | | Password string `json:"-" gorm:"type:varchar(255);comment:用户登录密码"` |
| | |
| | | return records, nil |
| | | } |
| | | |
| | | func (slf *UserSearch) FirstOrCreate(record User) error { |
| | | func (slf *UserSearch) Upsert(record User) error { |
| | | var db = slf.build() |
| | | |
| | | if err := db.FirstOrCreate(&User{}, record).Error; err != nil { |
| | | if err := db.Clauses(clause.OnConflict{ |
| | | Columns: []clause.Column{{Name: "uuid"}}, |
| | | DoUpdates: clause.AssignmentColumns([]string{"uuid", "username", "user_type", "nick_name"}), |
| | | }).Create(&record).Error; err != nil { |
| | | return fmt.Errorf("first or create err: %v, record: %+v", err, record) |
| | | } |
| | | |