From 17fb77e84ae586ad1c46fc0867518c275c50a7d5 Mon Sep 17 00:00:00 2001 From: henry Date: Tue, 12 Oct 2021 17:27:41 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E5=AE=8C=E5=96=84=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/basic/api/base.go | 7 ++++++ app/common/model/manage_expert.go | 2 +- app/common/model/manage_laboratory.go | 2 +- app/common/model/technology_instance.go | 1 + app/common/model/technology_paper.go | 1 + app/enterprise/api/user.go | 22 +++++++------------ .../controller/technology/instance.go | 16 +++++++++----- app/enterprise/controller/technology/paper.go | 17 +++++++++----- app/enterprise/controller/user/instance.go | 21 +++++++++--------- config/const.go | 1 + 10 files changed, 54 insertions(+), 36 deletions(-) diff --git a/app/basic/api/base.go b/app/basic/api/base.go index 6ac5ad3..1ed203b 100644 --- a/app/basic/api/base.go +++ b/app/basic/api/base.go @@ -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 { return func(c *gin.Context) interface{} { var err error diff --git a/app/common/model/manage_expert.go b/app/common/model/manage_expert.go index 140a304..1c3ab17 100644 --- a/app/common/model/manage_expert.go +++ b/app/common/model/manage_expert.go @@ -8,8 +8,8 @@ import ( // ManageExpert 专家入驻信息管理 type ManageExpert struct { Model - Local ModelTenant + Local UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"` Area Position string `gorm:"column:position;type:varchar(50);default:null;comment:坐标" json:"-"` diff --git a/app/common/model/manage_laboratory.go b/app/common/model/manage_laboratory.go index ac7eddd..1a816f9 100644 --- a/app/common/model/manage_laboratory.go +++ b/app/common/model/manage_laboratory.go @@ -7,8 +7,8 @@ import ( // ManageLaboratory 实验室信息管理 type ManageLaboratory struct { Model - Local ModelTenant + Local 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"` Code string `gorm:"column:code;type:varchar(30);default:null;comment:信用代码" json:"code"` diff --git a/app/common/model/technology_instance.go b/app/common/model/technology_instance.go index ba3d72e..396ba01 100644 --- a/app/common/model/technology_instance.go +++ b/app/common/model/technology_instance.go @@ -6,6 +6,7 @@ import "SciencesServer/utils" type TechnologyInstance struct { Model ModelTenant + Local 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"` Title string `gorm:"column:title;type:varchar(30);default:null;comment:名称" json:"title"` diff --git a/app/common/model/technology_paper.go b/app/common/model/technology_paper.go index 60ab2f7..b993974 100644 --- a/app/common/model/technology_paper.go +++ b/app/common/model/technology_paper.go @@ -9,6 +9,7 @@ import ( type TechnologyPaper struct { Model ModelTenant + Local 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"` Ext string `gorm:"column:ext;type:varchar(30);default:null;comment:引用格式" json:"ext"` diff --git a/app/enterprise/api/user.go b/app/enterprise/api/user.go index 6df73bc..2445f9a 100644 --- a/app/enterprise/api/user.go +++ b/app/enterprise/api/user.go @@ -14,25 +14,19 @@ func (a *User) Info(c *gin.Context) { 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 { - Name string `json:"name" form:"name" 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" ` // 固定电话 + Identity int `json:"identity" form:"identity" binding:"required"` }{} if err := api.Bind(form)(c); err != nil { api.APIFailure(err.(error))(c) return } - err := user.NewTenant()(api.GetSession()(c).(*service.SessionEnterprise)).Perfect(&user.TenantPerfectParams{ - TenantBasicParams: &user.TenantBasicParams{ - Name: form.Name, Email: form.Email, Job: form.Job, FixedPhone: form.FixedPhone, - }, - }) + err := user.NewInstance()(api.GetSession()(c).(*service.SessionEnterprise)).SwitchIdentity(form.Identity) api.APIResponse(err) } - -func (a *User) SwitchIdentity(c *gin.Context) { - -} diff --git a/app/enterprise/controller/technology/instance.go b/app/enterprise/controller/technology/instance.go index 850e735..55c2845 100644 --- a/app/enterprise/controller/technology/instance.go +++ b/app/enterprise/controller/technology/instance.go @@ -10,9 +10,12 @@ import ( ) // 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 ( // InstanceInfo 详细信息 @@ -77,7 +80,6 @@ func (c *Instance) Form(params *InstanceParams) error { return errors.New("操作错误,当前状态不允许修改") } } - mTechnologyInstance.UID = c.TenantUID mTechnologyInstance.PatentID = params.PatentID mTechnologyInstance.Title = params.Title mTechnologyInstance.Company = params.Company @@ -103,6 +105,10 @@ func (c *Instance) Form(params *InstanceParams) error { mTechnologyInstance.UpdatedAt = time.Now() 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) } @@ -151,7 +157,7 @@ func (c *Instance) Delete(id uint64) error { } func NewInstance() InstanceHandle { - return func(enterprise *service.SessionEnterprise) *Instance { - return &Instance{enterprise} + return func(enterprise *service.SessionEnterprise, local uint64) *Instance { + return &Instance{enterprise, local} } } diff --git a/app/enterprise/controller/technology/paper.go b/app/enterprise/controller/technology/paper.go index a0297a6..49974ac 100644 --- a/app/enterprise/controller/technology/paper.go +++ b/app/enterprise/controller/technology/paper.go @@ -11,9 +11,12 @@ import ( ) // 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 ( PaperInfo struct { @@ -35,6 +38,8 @@ func (c *Paper) List(title string, page, pageSize int) (*controller.ReturnPages, where := []*model2.ModelWhereOrder{&model2.ModelWhereOrder{ Where: model2.NewWhere("tenant_id", c.TenantID), Order: model2.NewOrder("id", model2.OrderModeToDesc), + }, &model2.ModelWhereOrder{ + Where: model2.NewWhere("local", c.local), }} if 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("无权限操作") } } - mTechnologyPaper.UID = c.TenantUID mTechnologyPaper.Title = params.Title mTechnologyPaper.Ext = params.Ext mTechnologyPaper.Author = params.Author @@ -79,6 +83,9 @@ func (c *Paper) Form(params *PaperParams) error { mTechnologyPaper.Remark = params.Remark if params.ID <= 0 { + mTechnologyPaper.TenantID = c.TenantID + mTechnologyPaper.UID = c.TenantUID + mTechnologyPaper.Local.Local = c.local return model2.Create(mTechnologyPaper.TechnologyPaper) } mTechnologyPaper.UpdatedAt = time.Now() @@ -106,7 +113,7 @@ func (c *Paper) Delete(id uint64) error { } func NewPaper() PaperHandle { - return func(enterprise *service.SessionEnterprise) *Paper { - return &Paper{enterprise} + return func(enterprise *service.SessionEnterprise, local uint64) *Paper { + return &Paper{enterprise, local} } } diff --git a/app/enterprise/controller/user/instance.go b/app/enterprise/controller/user/instance.go index 8d7fe6b..c7cc15c 100644 --- a/app/enterprise/controller/user/instance.go +++ b/app/enterprise/controller/user/instance.go @@ -38,7 +38,7 @@ func (c *Instance) Info() *InstanceInfo { } // 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}} mUserTenant := model.NewUserTenant() @@ -47,18 +47,19 @@ func (c *Instance) Detail() *InstanceDetailInfo { "email", "job", "fixed_phone", "other"}, model2.NewWhere("uid", c.UID), model2.NewWhere("identity", c.SelectIdentity)) - if err != nil || !isExist { - return resp + if err != nil { + 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 - resp.Email = mUserTenant.Email - resp.Job = mUserTenant.Job - resp.FixedPhone = mUserTenant.FixedPhone - return resp + return resp, nil } -// Switch 切换身份 -func (c *Instance) Switch(identity int) error { +// SwitchIdentity 切换身份 +func (c *Instance) SwitchIdentity(identity int) error { if _, has := config.TenantUserIdentityData[identity]; !has { return errors.New("未知的身份信息") } diff --git a/config/const.go b/config/const.go index 19ce655..d9338cc 100644 --- a/config/const.go +++ b/config/const.go @@ -14,6 +14,7 @@ const ( const ( TokenForUID string = "uid" TokenForSession string = "session" + ContentForLocal string = "local" ) const (