feat:完善信息

This commit is contained in:
henry
2021-10-12 17:27:41 +08:00
parent eccd71809d
commit 17fb77e84a
10 changed files with 54 additions and 36 deletions

View File

@ -30,6 +30,13 @@ func GetSession() ApiHandle {
} }
} }
func GetLocal() ApiHandle {
return func(c *gin.Context) interface{} {
value, _ := c.Get(config.ContentForLocal)
return value
}
}
func Bind(req interface{}) ApiHandle { func Bind(req interface{}) ApiHandle {
return func(c *gin.Context) interface{} { return func(c *gin.Context) interface{} {
var err error var err error

View File

@ -8,8 +8,8 @@ import (
// ManageExpert 专家入驻信息管理 // ManageExpert 专家入驻信息管理
type ManageExpert struct { type ManageExpert struct {
Model Model
Local
ModelTenant ModelTenant
Local
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"` UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
Area Area
Position string `gorm:"column:position;type:varchar(50);default:null;comment:坐标" json:"-"` Position string `gorm:"column:position;type:varchar(50);default:null;comment:坐标" json:"-"`

View File

@ -7,8 +7,8 @@ import (
// ManageLaboratory 实验室信息管理 // ManageLaboratory 实验室信息管理
type ManageLaboratory struct { type ManageLaboratory struct {
Model Model
Local
ModelTenant ModelTenant
Local
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"` UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
Name string `gorm:"column:name;type:varchar(30);default:null;comment:名称" json:"name"` Name string `gorm:"column:name;type:varchar(30);default:null;comment:名称" json:"name"`
Code string `gorm:"column:code;type:varchar(30);default:null;comment:信用代码" json:"code"` Code string `gorm:"column:code;type:varchar(30);default:null;comment:信用代码" json:"code"`

View File

@ -6,6 +6,7 @@ import "SciencesServer/utils"
type TechnologyInstance struct { type TechnologyInstance struct {
Model Model
ModelTenant ModelTenant
Local
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"` UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
PatentID uint64 `gorm:"column:patent_id;type:int;default:0;comment:代表专利" json:"patent_id"` PatentID uint64 `gorm:"column:patent_id;type:int;default:0;comment:代表专利" json:"patent_id"`
Title string `gorm:"column:title;type:varchar(30);default:null;comment:名称" json:"title"` Title string `gorm:"column:title;type:varchar(30);default:null;comment:名称" json:"title"`

View File

@ -9,6 +9,7 @@ import (
type TechnologyPaper struct { type TechnologyPaper struct {
Model Model
ModelTenant ModelTenant
Local
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"` UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
Title string `gorm:"column:title;type:varchar(100);default:null;comment:题目" json:"title"` Title string `gorm:"column:title;type:varchar(100);default:null;comment:题目" json:"title"`
Ext string `gorm:"column:ext;type:varchar(30);default:null;comment:引用格式" json:"ext"` Ext string `gorm:"column:ext;type:varchar(30);default:null;comment:引用格式" json:"ext"`

View File

@ -14,25 +14,19 @@ func (a *User) Info(c *gin.Context) {
api.APISuccess(data) api.APISuccess(data)
} }
func (a *User) Perfect(c *gin.Context) { func (a *User) Detail(c *gin.Context) {
data, err := user.NewInstance()(api.GetSession()(c).(*service.SessionEnterprise)).Detail()
api.APIResponse(err, data)
}
func (a *User) SwitchIdentity(c *gin.Context) {
form := &struct { form := &struct {
Name string `json:"name" form:"name" binding:"required"` // 名称 Identity int `json:"identity" form:"identity" binding:"required"`
Email string `json:"email" form:"email" binding:"required"` // 邮箱
Job string `json:"job" form:"job" binding:"required"` // 职务
FixedPhone string `json:"fixed_phone" form:"fixed_phone" ` // 固定电话
}{} }{}
if err := api.Bind(form)(c); err != nil { if err := api.Bind(form)(c); err != nil {
api.APIFailure(err.(error))(c) api.APIFailure(err.(error))(c)
return return
} }
err := user.NewTenant()(api.GetSession()(c).(*service.SessionEnterprise)).Perfect(&user.TenantPerfectParams{ err := user.NewInstance()(api.GetSession()(c).(*service.SessionEnterprise)).SwitchIdentity(form.Identity)
TenantBasicParams: &user.TenantBasicParams{
Name: form.Name, Email: form.Email, Job: form.Job, FixedPhone: form.FixedPhone,
},
})
api.APIResponse(err) api.APIResponse(err)
} }
func (a *User) SwitchIdentity(c *gin.Context) {
}

View File

@ -10,9 +10,12 @@ import (
) )
// Instance 技术管理 // Instance 技术管理
type Instance struct{ *service.SessionEnterprise } type Instance struct {
*service.SessionEnterprise
local uint64
}
type InstanceHandle func(enterprise *service.SessionEnterprise) *Instance type InstanceHandle func(enterprise *service.SessionEnterprise, local uint64) *Instance
type ( type (
// InstanceInfo 详细信息 // InstanceInfo 详细信息
@ -77,7 +80,6 @@ func (c *Instance) Form(params *InstanceParams) error {
return errors.New("操作错误,当前状态不允许修改") return errors.New("操作错误,当前状态不允许修改")
} }
} }
mTechnologyInstance.UID = c.TenantUID
mTechnologyInstance.PatentID = params.PatentID mTechnologyInstance.PatentID = params.PatentID
mTechnologyInstance.Title = params.Title mTechnologyInstance.Title = params.Title
mTechnologyInstance.Company = params.Company mTechnologyInstance.Company = params.Company
@ -103,6 +105,10 @@ func (c *Instance) Form(params *InstanceParams) error {
mTechnologyInstance.UpdatedAt = time.Now() mTechnologyInstance.UpdatedAt = time.Now()
return model2.Updates(mTechnologyInstance.TechnologyInstance, mTechnologyInstance.TechnologyInstance) return model2.Updates(mTechnologyInstance.TechnologyInstance, mTechnologyInstance.TechnologyInstance)
} }
mTechnologyInstance.UID = c.TenantUID
mTechnologyInstance.Local.Local = c.local
mTechnologyInstance.TenantID = c.TenantID
return model2.Create(mTechnologyInstance.TechnologyInstance) return model2.Create(mTechnologyInstance.TechnologyInstance)
} }
@ -151,7 +157,7 @@ func (c *Instance) Delete(id uint64) error {
} }
func NewInstance() InstanceHandle { func NewInstance() InstanceHandle {
return func(enterprise *service.SessionEnterprise) *Instance { return func(enterprise *service.SessionEnterprise, local uint64) *Instance {
return &Instance{enterprise} return &Instance{enterprise, local}
} }
} }

View File

@ -11,9 +11,12 @@ import (
) )
// Paper 论文管理 // Paper 论文管理
type Paper struct{ *service.SessionEnterprise } type Paper struct {
*service.SessionEnterprise
local uint64
}
type PaperHandle func(enterprise *service.SessionEnterprise) *Paper type PaperHandle func(enterprise *service.SessionEnterprise, local uint64) *Paper
type ( type (
PaperInfo struct { PaperInfo struct {
@ -35,6 +38,8 @@ func (c *Paper) List(title string, page, pageSize int) (*controller.ReturnPages,
where := []*model2.ModelWhereOrder{&model2.ModelWhereOrder{ where := []*model2.ModelWhereOrder{&model2.ModelWhereOrder{
Where: model2.NewWhere("tenant_id", c.TenantID), Where: model2.NewWhere("tenant_id", c.TenantID),
Order: model2.NewOrder("id", model2.OrderModeToDesc), Order: model2.NewOrder("id", model2.OrderModeToDesc),
}, &model2.ModelWhereOrder{
Where: model2.NewWhere("local", c.local),
}} }}
if title != "" { if title != "" {
where = append(where, &model2.ModelWhereOrder{Where: model2.NewWhereLike("title", title)}) where = append(where, &model2.ModelWhereOrder{Where: model2.NewWhereLike("title", title)})
@ -69,7 +74,6 @@ func (c *Paper) Form(params *PaperParams) error {
return errors.New("无权限操作") return errors.New("无权限操作")
} }
} }
mTechnologyPaper.UID = c.TenantUID
mTechnologyPaper.Title = params.Title mTechnologyPaper.Title = params.Title
mTechnologyPaper.Ext = params.Ext mTechnologyPaper.Ext = params.Ext
mTechnologyPaper.Author = params.Author mTechnologyPaper.Author = params.Author
@ -79,6 +83,9 @@ func (c *Paper) Form(params *PaperParams) error {
mTechnologyPaper.Remark = params.Remark mTechnologyPaper.Remark = params.Remark
if params.ID <= 0 { if params.ID <= 0 {
mTechnologyPaper.TenantID = c.TenantID
mTechnologyPaper.UID = c.TenantUID
mTechnologyPaper.Local.Local = c.local
return model2.Create(mTechnologyPaper.TechnologyPaper) return model2.Create(mTechnologyPaper.TechnologyPaper)
} }
mTechnologyPaper.UpdatedAt = time.Now() mTechnologyPaper.UpdatedAt = time.Now()
@ -106,7 +113,7 @@ func (c *Paper) Delete(id uint64) error {
} }
func NewPaper() PaperHandle { func NewPaper() PaperHandle {
return func(enterprise *service.SessionEnterprise) *Paper { return func(enterprise *service.SessionEnterprise, local uint64) *Paper {
return &Paper{enterprise} return &Paper{enterprise, local}
} }
} }

View File

@ -38,7 +38,7 @@ func (c *Instance) Info() *InstanceInfo {
} }
// Detail 详细信息 // Detail 详细信息
func (c *Instance) Detail() *InstanceDetailInfo { func (c *Instance) Detail() (*InstanceDetailInfo, error) {
resp := &InstanceDetailInfo{InstanceInfo: InstanceInfo{Name: c.Name, Identity: c.Identity, SelectIdentity: c.SelectIdentity}} resp := &InstanceDetailInfo{InstanceInfo: InstanceInfo{Name: c.Name, Identity: c.Identity, SelectIdentity: c.SelectIdentity}}
mUserTenant := model.NewUserTenant() mUserTenant := model.NewUserTenant()
@ -47,18 +47,19 @@ func (c *Instance) Detail() *InstanceDetailInfo {
"email", "job", "fixed_phone", "other"}, "email", "job", "fixed_phone", "other"},
model2.NewWhere("uid", c.UID), model2.NewWhere("identity", c.SelectIdentity)) model2.NewWhere("uid", c.UID), model2.NewWhere("identity", c.SelectIdentity))
if err != nil || !isExist { if err != nil {
return resp return nil, err
} else if isExist {
resp.Name = mUserTenant.Name
resp.Email = mUserTenant.Email
resp.Job = mUserTenant.Job
resp.FixedPhone = mUserTenant.FixedPhone
} }
resp.Name = mUserTenant.Name return resp, nil
resp.Email = mUserTenant.Email
resp.Job = mUserTenant.Job
resp.FixedPhone = mUserTenant.FixedPhone
return resp
} }
// Switch 切换身份 // SwitchIdentity 切换身份
func (c *Instance) Switch(identity int) error { func (c *Instance) SwitchIdentity(identity int) error {
if _, has := config.TenantUserIdentityData[identity]; !has { if _, has := config.TenantUserIdentityData[identity]; !has {
return errors.New("未知的身份信息") return errors.New("未知的身份信息")
} }

View File

@ -14,6 +14,7 @@ const (
const ( const (
TokenForUID string = "uid" TokenForUID string = "uid"
TokenForSession string = "session" TokenForSession string = "session"
ContentForLocal string = "local"
) )
const ( const (