feat:完善信息,优化入驻接口

This commit is contained in:
henry
2022-01-28 16:59:15 +08:00
parent 4c57ca2878
commit aafff0f3fd
22 changed files with 275 additions and 137 deletions

View File

@ -107,9 +107,8 @@ func (c *Company) Form(params *BasicParams, other *config.IdentityForCompany) er
return errors.New("操作错误,无权限操作")
}
} else {
if mManageCompany.TenantID != params.TenantID {
if isExist, err = params.isExist(mManageCompany.ManageCompany, model2.NewWhere("tenant_id", params.TenantID),
model2.NewWhere("code", params.Code)); err != nil {
if params.Code != mManageCompany.Code {
if isExist, err = params.isExist(mManageCompany.ManageCompany, model2.NewWhere("code", params.Code)); err != nil {
return err
} else if isExist {
return errors.New("操作错误,当前站点下已存在同一公司组织机构代码")
@ -143,11 +142,11 @@ func (c *Company) Form(params *BasicParams, other *config.IdentityForCompany) er
mManageCompany.ExamineStatus = model2.ExamineStatusForAgree
mManageCompany.ExamineRemark = "主动创建,无需审核"
if isExist, err := params.isExist(mManageCompany.ManageCompany, model2.NewWhere("tenant_id", params.TenantID),
if isExist, err := params.isExist(mManageCompany.ManageCompany,
model2.NewWhere("code", params.Code)); err != nil {
return err
} else if isExist {
return errors.New("操作错误,当前站点下已存在同一公司组织机构代码")
return errors.New("操作错误,已存在同一公司组织机构代码")
}
return model2.Create(mManageCompany.ManageCompany)
}

View File

@ -4,9 +4,14 @@ import (
"SciencesServer/app/api/admin/model"
"SciencesServer/app/basic/config"
model2 "SciencesServer/app/common/model"
"SciencesServer/app/service"
"SciencesServer/app/session"
config2 "SciencesServer/config"
cache2 "SciencesServer/serve/cache"
"SciencesServer/serve/orm"
"encoding/json"
"errors"
"fmt"
"gorm.io/gorm"
"time"
)
@ -31,6 +36,7 @@ var examineHandle = map[int]func(id, tenantID uint64) (*ExamineManageInfo, error
config.TenantUserIdentityForExpert: examineExpert,
config.TenantUserIdentityForResearch: examineResearch,
config.TenantUserIdentityForLaboratory: examineLaboratory,
config.TenantUserIdentityForAgent: examineAgent,
}
func checkManage(IModel model2.IModel, id uint64) error {
@ -87,8 +93,8 @@ func examineExpert(id, tenantID uint64) (*ExamineManageInfo, error) {
model2.NewWhere("invalid_status", model2.InvalidStatusForNot)); err != nil {
return nil, err
}
return &ExamineManageInfo{IModel: mManageExpert.ManageExpert, UIDs: uids,
Name: mManageExpert.Name, Industrys: mManageExpert.GetIndustryAttribute(),
return &ExamineManageInfo{IModel: mManageExpert.ManageExpert, IUserModel: mUserExpert.UserExpert,
UIDs: uids, Name: mManageExpert.Name, Industrys: mManageExpert.GetIndustryAttribute(),
Keywords: mManageExpert.GetKeywordAttribute(), Researchs: mManageExpert.GetResearchAttribute()}, nil
}
@ -112,7 +118,7 @@ func examineResearch(id, tenantID uint64) (*ExamineManageInfo, error) {
model2.NewWhere("invalid_status", model2.InvalidStatusForNot)); err != nil {
return nil, err
}
return &ExamineManageInfo{IModel: mManageResearch.ManageResearch, UIDs: uids,
return &ExamineManageInfo{IModel: mManageResearch.ManageResearch, IUserModel: mUserResearch.UserResearch, UIDs: uids,
Name: mManageResearch.Name, Industrys: mManageResearch.GetIndustryAttribute(),
Keywords: mManageResearch.GetKeywordAttribute(), Researchs: mManageResearch.GetResearchAttribute()}, nil
}
@ -137,7 +143,7 @@ func examineLaboratory(id, tenantID uint64) (*ExamineManageInfo, error) {
model2.NewWhere("invalid_status", model2.InvalidStatusForNot)); err != nil {
return nil, err
}
return &ExamineManageInfo{IModel: mManageLaboratory.ManageLaboratory, UIDs: uids,
return &ExamineManageInfo{IModel: mManageLaboratory.ManageLaboratory, IUserModel: mUserLaboratory.UserLaboratory, UIDs: uids,
Name: mManageLaboratory.Name, Industrys: mManageLaboratory.GetIndustryAttribute(),
Keywords: mManageLaboratory.GetKeywordAttribute(), Researchs: mManageLaboratory.GetResearchAttribute()}, nil
}
@ -162,7 +168,7 @@ func examineAgent(id, tenantID uint64) (*ExamineManageInfo, error) {
model2.NewWhere("invalid_status", model2.InvalidStatusForNot)); err != nil {
return nil, err
}
return &ExamineManageInfo{IModel: mManageAgent.ManageAgent, UIDs: uids,
return &ExamineManageInfo{IModel: mManageAgent.ManageAgent, IUserModel: mUserAgent.UserAgent, UIDs: uids,
Name: mManageAgent.Name, Industrys: mManageAgent.GetIndustryAttribute(),
Keywords: mManageAgent.GetKeywordAttribute()}, nil
}
@ -186,8 +192,7 @@ func (c *Examine) Launch(id uint64, identity, status int, remark string, params
}
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
values := map[string]interface{}{
"examine_status": status,
"examine_remark": remark, "updated_at": time.Now()}
"examine_status": status, "examine_remark": remark, "updated_at": time.Now()}
if params != nil && len(params) > 0 {
if identity == config.TenantUserIdentityForCompany {
@ -213,23 +218,35 @@ func (c *Examine) Launch(id uint64, identity, status int, remark string, params
return nil
}
mUserInstance := model.NewUserInstance()
// 客户端用户信息
users := make([]*model2.UserInstance, 0)
if err = model2.ScanFields(mUserInstance.UserInstance, &users, []string{"id", "uuid", "identity"},
if err = model2.ScanFields(mUserInstance.UserInstance, &users, []string{"id", "uuid", "name", "identity"},
&model2.ModelWhereOrder{Where: model2.NewWhereIn("uuid", data.UIDs)}); err != nil {
return err
}
userIdentitys := make([]*model2.UserIdentity, 0)
now := time.Now()
mUserIdentity := model.NewUserIdentity()
for _, v := range users {
userIdentitys = append(userIdentitys, &model2.UserIdentity{
var count int64
if err = model2.Count(mUserIdentity.UserIdentity, &count, model2.NewWhere("uid", v.UUID)); err != nil {
return err
}
userIdentity := &model2.UserIdentity{
Name: v.Name,
UID: v.UUID,
Identity: identity,
ModelAt: model2.ModelAt{CreatedAt: now, UpdatedAt: now},
})
}
if count <= 0 {
userIdentity.IsSelected = model2.UserIdentitySelectedForYes
}
if err = model2.Create(userIdentity, tx); err != nil {
return err
}
if err = model2.UpdatesWhere(mUserInstance.UserInstance, map[string]interface{}{
"identity": mUserInstance.Identity | identity, "updated_at": now,
}, []*model2.ModelWhere{
@ -237,11 +254,22 @@ func (c *Examine) Launch(id uint64, identity, status int, remark string, params
}, tx); err != nil {
return err
}
// TODO需要同步redis
}
if len(userIdentitys) > 0 {
if err = model2.Creates(model.NewUserIdentity().UserIdentity, userIdentitys, tx); err != nil {
return err
// 需要同步redis库
cache, _ := cache2.Cache.HGet(config2.RedisKeyForAccountEnterprise, fmt.Sprintf("%v", v.UUID))
if cache != "" {
_session := new(session.Enterprise)
if err := json.Unmarshal([]byte(cache), _session); err != nil {
return err
}
_session.Identity = mUserInstance.Identity | identity
if userIdentity.IsSelected == model2.UserIdentitySelectedForYes {
_session.SelectIdentity = identity
}
service.Publish(config2.EventForRedisHashProduce, config2.RedisKeyForAccountEnterprise, _session.GetStringUID(), _session)
}
}
// 存放es中

View File

@ -143,9 +143,8 @@ func (c *Expert) Form(params *BasicParams, other *config.IdentityForExpert) erro
return errors.New("操作错误,无权限操作")
}
} else {
if mManageExpert.TenantID != params.TenantID {
if isExist, err = params.isExist(mManageExpert.ManageExpert, model2.NewWhere("tenant_id", params.TenantID),
model2.NewWhere("mobile", params.Mobile)); err != nil {
if mManageExpert.Mobile != params.Mobile {
if isExist, err = params.isExist(mManageExpert.ManageExpert, model2.NewWhere("mobile", params.Mobile)); err != nil {
return err
} else if isExist {
return errors.New("操作错误,当前站点下已存在相同手机号码")
@ -185,11 +184,11 @@ func (c *Expert) Form(params *BasicParams, other *config.IdentityForExpert) erro
mManageExpert.ExamineStatus = model2.ExamineStatusForAgree
mManageExpert.ExamineRemark = "主动创建,无需审核"
if isExist, err := params.isExist(mManageExpert.ManageExpert, model2.NewWhere("tenant_id", params.TenantID),
if isExist, err := params.isExist(mManageExpert.ManageExpert,
model2.NewWhere("mobile", params.Mobile)); err != nil {
return err
} else if isExist {
return errors.New("操作错误,当前站点下已存在相同手机号码")
return errors.New("操作错误,已存在相同手机号码")
}
return model2.Create(mManageExpert.ManageExpert)
}

View File

@ -131,8 +131,8 @@ func (c *Laboratory) Form(params *BasicParams, other *config.IdentityForLaborato
return errors.New("操作错误,无权限操作")
}
} else {
if mManageLaboratory.TenantID != params.TenantID {
if isExist, err = params.isExist(mManageLaboratory.ManageLaboratory, model2.NewWhere("tenant_id", params.TenantID),
if mManageLaboratory.Code != params.Code {
if isExist, err = params.isExist(mManageLaboratory.ManageLaboratory,
model2.NewWhere("code", params.Code)); err != nil {
return err
} else if isExist {
@ -166,11 +166,11 @@ func (c *Laboratory) Form(params *BasicParams, other *config.IdentityForLaborato
mManageLaboratory.ExamineStatus = model2.ExamineStatusForAgree
mManageLaboratory.ExamineRemark = "主动创建,无需审核"
if isExist, err := params.isExist(mManageLaboratory.ManageLaboratory, model2.NewWhere("tenant_id", params.TenantID),
if isExist, err := params.isExist(mManageLaboratory.ManageLaboratory,
model2.NewWhere("code", params.Code)); err != nil {
return err
} else if isExist {
return errors.New("操作错误,当前站点下已存在同一实验室机构代码")
return errors.New("操作错误,已存在同一实验室机构代码")
}
return model2.Create(mManageLaboratory.ManageLaboratory)

View File

@ -101,9 +101,14 @@ func (c *Research) Select(tenantID uint64) ([]*ResearchSelect, error) {
out := make([]*model2.ManageResearch, 0)
if err := model2.ScanFields(mManageResearch.ManageResearch, &out, []string{"id", "name"}, &model2.ModelWhereOrder{
Where: model2.NewWhere("tenant_id", tenantID)}, &model2.ModelWhereOrder{
Where: model2.NewWhere("examine_status", model2.ExamineStatusForAgree)}); err != nil {
where := []*model2.ModelWhereOrder{
&model2.ModelWhereOrder{Where: model2.NewWhere("examine_status", model2.ExamineStatusForAgree)},
}
if tenantID > 0 {
where = append(where, &model2.ModelWhereOrder{Where: model2.NewWhere("tenant_id", tenantID)})
}
if err := model2.ScanFields(mManageResearch.ManageResearch, &out, []string{"id", "name"}, where...); err != nil {
return nil, err
}
list := make([]*ResearchSelect, 0)
@ -135,8 +140,8 @@ func (c *Research) Form(params *BasicParams, other *config.IdentityForResearch)
return errors.New("操作错误,无权限操作")
}
} else {
if mManageResearch.TenantID != params.TenantID {
if isExist, err = params.isExist(mManageResearch.ManageResearch, model2.NewWhere("tenant_id", params.TenantID),
if mManageResearch.Code != params.Code {
if isExist, err = params.isExist(mManageResearch.ManageResearch,
model2.NewWhere("code", params.Code)); err != nil {
return err
} else if isExist {
@ -169,11 +174,10 @@ func (c *Research) Form(params *BasicParams, other *config.IdentityForResearch)
mManageResearch.ExamineStatus = model2.ExamineStatusForAgree
mManageResearch.ExamineRemark = "主动创建,无需审核"
if isExist, err := params.isExist(mManageResearch.ManageResearch, model2.NewWhere("tenant_id", params.TenantID),
model2.NewWhere("code", params.Code)); err != nil {
if isExist, err := params.isExist(mManageResearch.ManageResearch, model2.NewWhere("code", params.Code)); err != nil {
return err
} else if isExist {
return errors.New("操作错误,当前站点下已存在同一研究机构代码")
return errors.New("操作错误,已存在同一研究机构代码")
}
return model2.Create(mManageResearch.ManageResearch)
}