Files

104 lines
2.9 KiB
Go
Raw Normal View History

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
2022-01-15 16:48:49 +08:00
tenantID uint64
2021-12-02 15:23:48 +08:00
}
2022-01-15 16:48:49 +08:00
type InstanceHandle func(session *session.Enterprise, tenantID uint64) *Instance
2021-12-02 15:23:48 +08:00
2021-12-06 14:55:41 +08:00
type InstanceInfo struct {
2021-12-07 16:10:12 +08:00
Identity int `json:"identity"` // 所有身份
ExamineIdentity map[int]*InstanceExamineInfo `json:"examine_identity"` // 审核中信息
SelectIdentity int `json:"select_identity"` // 当前选择的身份
2021-12-06 14:55:41 +08:00
}
2021-12-07 16:10:12 +08:00
type InstanceExamineInfo struct {
Status model2.ExamineStatusKind `json:"status"`
Remark string `json:"remark"`
}
func (c *Instance) company() (bool, *model2.Examine, error) {
2021-12-06 14:55:41 +08:00
mUserCompany := model.NewUserCompany()
2021-12-09 16:17:23 +08:00
out, err := mUserCompany.Settled(c.UID)
2021-12-07 16:10:12 +08:00
return out.ID > 0, out.Examine, err
2021-12-06 14:55:41 +08:00
}
2021-12-07 16:10:12 +08:00
func (c *Instance) expert() (bool, *model2.Examine, error) {
2021-12-06 14:55:41 +08:00
mUserExpert := model.NewUserExpert()
2021-12-09 16:17:23 +08:00
out, err := mUserExpert.Settled(c.UID)
2021-12-07 16:10:12 +08:00
return out.ID > 0, out.Examine, err
2021-12-06 14:55:41 +08:00
}
2021-12-07 16:10:12 +08:00
func (c *Instance) research() (bool, *model2.Examine, error) {
2021-12-06 14:55:41 +08:00
mUserResearch := model.NewUserResearch()
2021-12-09 16:17:23 +08:00
out, err := mUserResearch.Settled(c.UID)
2021-12-07 16:10:12 +08:00
return out.ID > 0, out.Examine, err
2021-12-06 14:55:41 +08:00
}
2021-12-02 15:23:48 +08:00
2021-12-07 16:10:12 +08:00
func (c *Instance) laboratory() (bool, *model2.Examine, error) {
2021-12-06 14:55:41 +08:00
mUserLaboratory := model.NewUserLaboratory()
2021-12-09 16:17:23 +08:00
out, err := mUserLaboratory.Settled(c.UID)
2021-12-07 16:10:12 +08:00
return out.ID > 0, out.Examine, err
2021-12-06 14:55:41 +08:00
}
2021-12-07 16:10:12 +08:00
func (c *Instance) agent() (bool, *model2.Examine, error) {
2021-12-06 14:55:41 +08:00
mUserAgent := model.NewUserAgent()
2021-12-09 16:17:23 +08:00
out, err := mUserAgent.Settled(c.UID)
2021-12-07 16:10:12 +08:00
return out.ID > 0, out.Examine, err
2021-12-06 14:55:41 +08:00
}
func (c *Instance) Index() (*InstanceInfo, error) {
out := &InstanceInfo{
Identity: c.Identity,
2021-12-07 16:10:12 +08:00
ExamineIdentity: make(map[int]*InstanceExamineInfo, 0),
2021-12-06 14:55:41 +08:00
SelectIdentity: c.SelectIdentity,
}
isExist := false
2021-12-07 16:10:12 +08:00
examine := new(model2.Examine)
2021-12-06 14:55:41 +08:00
var err error
// 查询其他信息
for k := range config.TenantUserIdentityData {
if k&c.SelectIdentity > 0 {
continue
}
if k == config.TenantUserIdentityForCompany {
2021-12-07 16:10:12 +08:00
isExist, examine, err = c.company()
2021-12-06 14:55:41 +08:00
} else if k == config.TenantUserIdentityForExpert {
2021-12-07 16:10:12 +08:00
isExist, examine, err = c.expert()
2021-12-06 14:55:41 +08:00
} else if k == config.TenantUserIdentityForResearch {
2021-12-07 16:10:12 +08:00
isExist, examine, err = c.research()
2021-12-06 14:55:41 +08:00
} else if k == config.TenantUserIdentityForLaboratory {
2021-12-07 16:10:12 +08:00
isExist, examine, err = c.laboratory()
2021-12-06 14:55:41 +08:00
} else if k == config.TenantUserIdentityForAgent {
2021-12-07 16:10:12 +08:00
isExist, examine, err = c.agent()
2021-12-06 14:55:41 +08:00
}
if err != nil {
return nil, err
}
if !isExist {
continue
}
2021-12-07 16:10:12 +08:00
out.ExamineIdentity[k] = &InstanceExamineInfo{
Status: examine.ExamineStatus,
Remark: examine.ExamineRemark,
}
2021-12-06 14:55:41 +08:00
}
return out, nil
2021-12-02 15:23:48 +08:00
}
func NewInstance() InstanceHandle {
2022-01-15 16:48:49 +08:00
return func(session *session.Enterprise, tenantID uint64) *Instance {
return &Instance{Enterprise: session, tenantID: tenantID}
2021-12-02 15:23:48 +08:00
}
}