feat:完善信息,优化入驻接口
This commit is contained in:
@ -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中
|
||||
|
Reference in New Issue
Block a user