2021-12-02 15:23:48 +08:00
|
|
|
package settled
|
|
|
|
|
2021-12-06 14:55:41 +08:00
|
|
|
import (
|
|
|
|
"SciencesServer/app/api/enterprise/model"
|
|
|
|
"SciencesServer/app/basic/config"
|
|
|
|
model2 "SciencesServer/app/common/model"
|
|
|
|
"SciencesServer/app/session"
|
|
|
|
)
|
2021-12-02 15:23:48 +08:00
|
|
|
|
2021-12-06 14:55:41 +08:00
|
|
|
// Instance 首页信息
|
2021-12-02 15:23:48 +08:00
|
|
|
type Instance struct {
|
|
|
|
*session.Enterprise
|
|
|
|
local string
|
|
|
|
}
|
|
|
|
|
|
|
|
type InstanceHandle func(session *session.Enterprise, local string) *Instance
|
|
|
|
|
2021-12-06 14:55:41 +08:00
|
|
|
type InstanceInfo struct {
|
|
|
|
Identity int `json:"identity"` // 所有身份
|
|
|
|
ExamineIdentity map[int]model2.ExamineStatusKind `json:"examine_identity"` // 审核中信息
|
|
|
|
SelectIdentity int `json:"select_identity"` // 当前选择的身份
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Instance) company() (bool, model2.ExamineStatusKind, error) {
|
|
|
|
mUserCompany := model.NewUserCompany()
|
|
|
|
out, err := mUserCompany.Company(c.UID)
|
|
|
|
return out.ID > 0, out.ExamineStatus, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Instance) expert() (bool, model2.ExamineStatusKind, error) {
|
|
|
|
mUserExpert := model.NewUserExpert()
|
|
|
|
out, err := mUserExpert.Expert(c.UID)
|
|
|
|
return out.ID > 0, out.ExamineStatus, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Instance) research() (bool, model2.ExamineStatusKind, error) {
|
|
|
|
mUserResearch := model.NewUserResearch()
|
|
|
|
out, err := mUserResearch.Research(c.UID)
|
|
|
|
return out.ID > 0, out.ExamineStatus, err
|
|
|
|
}
|
2021-12-02 15:23:48 +08:00
|
|
|
|
2021-12-06 14:55:41 +08:00
|
|
|
func (c *Instance) laboratory() (bool, model2.ExamineStatusKind, error) {
|
|
|
|
mUserLaboratory := model.NewUserLaboratory()
|
|
|
|
out, err := mUserLaboratory.Laboratory(c.UID)
|
|
|
|
return out.ID > 0, out.ExamineStatus, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Instance) agent() (bool, model2.ExamineStatusKind, error) {
|
|
|
|
mUserAgent := model.NewUserAgent()
|
|
|
|
out, err := mUserAgent.Agent(c.UID)
|
|
|
|
return out.ID > 0, out.ExamineStatus, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Instance) Index() (*InstanceInfo, error) {
|
|
|
|
out := &InstanceInfo{
|
|
|
|
Identity: c.Identity,
|
|
|
|
ExamineIdentity: make(map[int]model2.ExamineStatusKind, 0),
|
|
|
|
SelectIdentity: c.SelectIdentity,
|
|
|
|
}
|
|
|
|
isExist := false
|
|
|
|
var kind model2.ExamineStatusKind
|
|
|
|
var err error
|
|
|
|
|
|
|
|
// 查询其他信息
|
|
|
|
for k := range config.TenantUserIdentityData {
|
|
|
|
if k&c.SelectIdentity > 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if k == config.TenantUserIdentityForCompany {
|
|
|
|
isExist, kind, err = c.company()
|
|
|
|
} else if k == config.TenantUserIdentityForExpert {
|
|
|
|
isExist, kind, err = c.expert()
|
|
|
|
} else if k == config.TenantUserIdentityForResearch {
|
|
|
|
isExist, kind, err = c.research()
|
|
|
|
} else if k == config.TenantUserIdentityForLaboratory {
|
|
|
|
isExist, kind, err = c.laboratory()
|
|
|
|
} else if k == config.TenantUserIdentityForAgent {
|
|
|
|
isExist, kind, err = c.agent()
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if !isExist {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
out.ExamineIdentity[k] = kind
|
|
|
|
}
|
|
|
|
return out, nil
|
2021-12-02 15:23:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewInstance() InstanceHandle {
|
|
|
|
return func(session *session.Enterprise, local string) *Instance {
|
|
|
|
return &Instance{Enterprise: session, local: local}
|
|
|
|
}
|
|
|
|
}
|