|
@@ -5,6 +5,7 @@ import (
|
|
|
|
|
|
. "app.yhyue.com/moapp/jybase/common"
|
|
|
"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
|
+ . "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
. "app.yhyue.com/moapp/jypkg/middleground"
|
|
|
"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
|
|
|
)
|
|
@@ -38,7 +39,7 @@ func NewIdentityInfo(i *pb.Identity) *IdentityInfo {
|
|
|
}
|
|
|
|
|
|
//切换身份
|
|
|
-func (i *IdentityInfo) Switch(sess *httpsession.Session) bool {
|
|
|
+func (i *IdentityInfo) Switch(sess *httpsession.Session, mgo *MongodbSim) bool {
|
|
|
ok := false
|
|
|
m := map[string]interface{}{
|
|
|
"personId": i.PersonId,
|
|
@@ -47,9 +48,10 @@ func (i *IdentityInfo) Switch(sess *httpsession.Session) bool {
|
|
|
"positionId": i.PositionId,
|
|
|
"positionType": i.PositionType,
|
|
|
}
|
|
|
+ mgoUserId, _ := sess.Get("mgoUserId").(string)
|
|
|
if i.PositionType == 0 {
|
|
|
if sess.Del("entId", "entName", "entUserId", "entUserName", "entAccountId") {
|
|
|
- m["userId"] = sess.Get("mgoUserId")
|
|
|
+ m["userId"] = mgoUserId
|
|
|
ok = true
|
|
|
}
|
|
|
} else {
|
|
@@ -64,11 +66,16 @@ func (i *IdentityInfo) Switch(sess *httpsession.Session) bool {
|
|
|
ok = true
|
|
|
}
|
|
|
sess.SetMultiple(m)
|
|
|
+ go mgo.UpdateById("user", mgoUserId, map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ "login_positionid": i.PositionId,
|
|
|
+ },
|
|
|
+ })
|
|
|
return ok
|
|
|
}
|
|
|
|
|
|
//切换到最优身份
|
|
|
-func SwitchToBest(userId int64, sess *httpsession.Session, mgd *Middleground) bool {
|
|
|
+func SwitchToBest(userId int64, sess *httpsession.Session, mgd *Middleground, mgo *MongodbSim) bool {
|
|
|
list := mgd.UserCenter.IdentityList(userId)
|
|
|
if list == nil || len(list) == 0 {
|
|
|
return false
|
|
@@ -76,7 +83,7 @@ func SwitchToBest(userId int64, sess *httpsession.Session, mgd *Middleground) bo
|
|
|
if beforePositionId := Int64All(sess.Get("beforePositionId")); beforePositionId > 0 {
|
|
|
for _, v := range list {
|
|
|
if v.PositionId == beforePositionId {
|
|
|
- return NewIdentityInfo(v).Switch(sess)
|
|
|
+ return NewIdentityInfo(v).Switch(sess, mgo)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -90,14 +97,14 @@ func SwitchToBest(userId int64, sess *httpsession.Session, mgd *Middleground) bo
|
|
|
if resp := mgd.EntManageApplication.EmpowerUserIds(reqIds); len(resp.Ids) > 0 {
|
|
|
for _, v := range list {
|
|
|
if v.PositionType == 1 && v.EntUserId == resp.Ids[0] {
|
|
|
- return NewIdentityInfo(v).Switch(sess)
|
|
|
+ return NewIdentityInfo(v).Switch(sess, mgo)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
for _, v := range list {
|
|
|
if v.PositionType == 0 {
|
|
|
- return NewIdentityInfo(v).Switch(sess)
|
|
|
+ return NewIdentityInfo(v).Switch(sess, mgo)
|
|
|
}
|
|
|
}
|
|
|
return false
|