125 lines
3.9 KiB
Go
125 lines
3.9 KiB
Go
package model
|
|
|
|
import (
|
|
"SciencesServer/app/basic/config"
|
|
"SciencesServer/utils"
|
|
"gorm.io/gorm"
|
|
"time"
|
|
)
|
|
|
|
// UserManage 用户管理信息
|
|
type UserManage struct {
|
|
Model
|
|
ModelTenant
|
|
UID uint64 `gorm:"column:uid;index:idx_user_manage_uid;type:int;default:0;comment:用户表UUID" json:"-"`
|
|
UUID uint64 `gorm:"column:uuid;uniqueIndex:idx_user_manage_uuid;type:int;default:0;comment:用户唯一UUID" json:"-"`
|
|
Name string `gorm:"column:name;type:varchar(20);default:null;comment:真实姓名" json:"name"`
|
|
Email string `gorm:"column:email;type:varchar(50);default:null;comment:邮箱" json:"email"`
|
|
Job string `gorm:"column:job;type:varchar(50);default:null;comment:职务" json:"job"`
|
|
FixedPhone string `gorm:"column:fixed_phone;type:varchar(20);default:null;comment:固定电话" json:"fixed_phone"`
|
|
Address string `gorm:"column:address;type:varchar(255);default:null;comment:详细地址" json:"address"`
|
|
Identity int `gorm:"column:identity;type:tinyint(3);default:0;comment:身份" json:"-"`
|
|
IdentityInfo string `gorm:"column:identity_info;type:varchar(255);default:null;comment:身份信息" json:"-"`
|
|
IsSelected UserManageSelected `gorm:"column:is_selected;type:tinyint(1);default:0;comment:最后一次选中的身份状态,用于下次登陆展示" json:"-"`
|
|
ModelDeleted
|
|
ModelAt
|
|
}
|
|
|
|
type IUserIdentity interface {
|
|
Analysis(src string) interface{}
|
|
}
|
|
|
|
type (
|
|
// UserIdentityForCompany 公司信息
|
|
UserIdentityForCompany struct {
|
|
Industry string `json:"industry"`
|
|
Keyword string `json:"keyword"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
// UserIdentityForExpert 专家信息
|
|
UserIdentityForExpert struct {
|
|
Industry string `json:"industry"`
|
|
Keyword string `json:"keyword"`
|
|
Research string `json:"research"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
// UserIdentityForResearch 研究机构信息
|
|
UserIdentityForResearch struct {
|
|
Name string `json:"name"`
|
|
Industry string `json:"industry"`
|
|
Keyword string `json:"keyword"`
|
|
Research string `json:"research"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
// UserIdentityForLaboratory 实验室信息
|
|
UserIdentityForLaboratory struct {
|
|
Name string `json:"name"`
|
|
Industry string `json:"industry"`
|
|
Keyword string `json:"keyword"`
|
|
Research string `json:"research"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
)
|
|
|
|
func (this *UserIdentityForCompany) Analysis(src string) interface{} {
|
|
utils.FromJSON(src, this)
|
|
return this
|
|
}
|
|
|
|
func (this *UserIdentityForExpert) Analysis(src string) interface{} {
|
|
utils.FromJSON(src, this)
|
|
return this
|
|
}
|
|
|
|
func (this *UserIdentityForResearch) Analysis(src string) interface{} {
|
|
utils.FromJSON(src, this)
|
|
return this
|
|
}
|
|
|
|
func (this *UserIdentityForLaboratory) Analysis(src string) interface{} {
|
|
utils.FromJSON(src, this)
|
|
return this
|
|
}
|
|
|
|
type UserManageSelected int
|
|
|
|
const (
|
|
// UserManageSelectedForNo 未选中
|
|
UserManageSelectedForNo UserManageSelected = iota
|
|
// UserManageSelectedForYes 已选中
|
|
UserManageSelectedForYes
|
|
)
|
|
|
|
func (m *UserManage) TableName() string {
|
|
return m.NewTableName("user_manage")
|
|
}
|
|
|
|
func (m *UserManage) BeforeCreate(db *gorm.DB) error {
|
|
snowflake, _ := utils.NewSnowflake(1)
|
|
m.UUID = uint64(snowflake.GetID())
|
|
m.CreatedAt = time.Now()
|
|
return nil
|
|
}
|
|
|
|
func (m *UserManage) GetIdentityInfoAttribute() interface{} {
|
|
var manage IUserIdentity
|
|
|
|
switch m.Identity {
|
|
case config.TenantUserIdentityForCompany:
|
|
manage = new(UserIdentityForCompany)
|
|
break
|
|
case config.TenantUserIdentityForExpert:
|
|
manage = new(UserIdentityForExpert)
|
|
break
|
|
}
|
|
return manage.Analysis(m.IdentityInfo)
|
|
}
|
|
|
|
func (m *UserManage) SetIdentityInfoAttribute(src IUserIdentity) {
|
|
m.IdentityInfo = utils.AnyToJSON(src)
|
|
}
|
|
|
|
func NewUserManage() *UserManage {
|
|
return &UserManage{}
|
|
}
|