Browse Source

增加中台

wangchuanjin 2 years ago
parent
commit
8954e36a70
5 changed files with 96 additions and 4 deletions
  1. 1 0
      go.mod
  2. 2 0
      go.sum
  3. 30 0
      identity/identity.go
  4. 54 0
      middleground/entmanageapplication.go
  5. 9 4
      middleground/middleground.go

+ 1 - 0
go.mod

@@ -5,6 +5,7 @@ go 1.18
 require (
 	app.yhyue.com/moapp/jybase v0.0.0-20230117032034-ad7c00ffe11a
 	app.yhyue.com/moapp/message v0.0.0-20221223100203-6402e389d9ae
+	bp.jydev.jianyu360.cn/BaseService/entManageApplication v0.0.0-20230209051900-1e7dcb8f83b7
 	bp.jydev.jianyu360.cn/BaseService/powerCheckCenter v0.0.0-20230207054315-b05f3dd4c4d3
 	bp.jydev.jianyu360.cn/BaseService/resourceCenter v0.0.4
 	bp.jydev.jianyu360.cn/BaseService/userCenter v0.0.0-20230129060002-f69424aa14ba

+ 2 - 0
go.sum

@@ -16,6 +16,8 @@ app.yhyue.com/moapp/jybase v0.0.0-20230117032034-ad7c00ffe11a/go.mod h1:zB47XTeJ
 app.yhyue.com/moapp/message v0.0.0-20221223100203-6402e389d9ae h1:6rDDaz6yxvE8viTSzEBwKYOFWq14TMfuBivSazUZMz4=
 app.yhyue.com/moapp/message v0.0.0-20221223100203-6402e389d9ae/go.mod h1:b0zZHev3gmJao1Fo+2Z2KPVjsuLOJVvVxf+kCnu9WkA=
 bp.jydev.jianyu360.cn/BP/jynsq v0.0.0-20220222052708-ebc43af90698/go.mod h1:ojo/AUH9Yr1wzarEjOaNMkj1Cet/9r8IgLyba64Z52E=
+bp.jydev.jianyu360.cn/BaseService/entManageApplication v0.0.0-20230209051900-1e7dcb8f83b7 h1:cw/PdRypNFcYOk4iWAfHjIFoMzIlXUfl9XAmWujBOPY=
+bp.jydev.jianyu360.cn/BaseService/entManageApplication v0.0.0-20230209051900-1e7dcb8f83b7/go.mod h1:7Xhygw0KBuL4h0G76FnFg4otQcA9bmOO0c8M0FCjAyQ=
 bp.jydev.jianyu360.cn/BaseService/gateway v0.0.0-20220419090715-88ddb32961be/go.mod h1:Yj4oabIGItuMoF0BXYLz2XAnF581kxgXBrvlUtIJrkI=
 bp.jydev.jianyu360.cn/BaseService/gateway v1.3.4/go.mod h1:BMLd/5wb3BIEGhnEgF9y1sJN9P5/Dw9kYsoiE9V8I9g=
 bp.jydev.jianyu360.cn/BaseService/powerCheckCenter v0.0.0-20230207054315-b05f3dd4c4d3 h1:jeItQ6RM1T6yPWc/5i4R6h3kViD+Rm2VnIEsc1gCFJA=

+ 30 - 0
identity/identity.go

@@ -4,6 +4,7 @@ import (
 	"strconv"
 
 	"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
+	. "app.yhyue.com/moapp/jypkg/middleground"
 	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
 )
 
@@ -64,3 +65,32 @@ func (i *IdentityInfo) Switch(sess *httpsession.Session) bool {
 	sess.SetMultiple(m)
 	return ok
 }
+
+//切换到最优身份
+func SwitchToBest(userId int64, sess *httpsession.Session, mgd *Middleground) bool {
+	list := mgd.UserCenter.IdentityList(userId)
+	if list == nil || len(list) == 0 {
+		return false
+	}
+	reqIds := []int64{}
+	for _, v := range list {
+		if v.PositionType == 1 {
+			reqIds = append(reqIds, v.EntUserId)
+		}
+	}
+	if len(reqIds) > 0 {
+		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)
+				}
+			}
+		}
+	}
+	for _, v := range list {
+		if v.PositionType == 0 {
+			return NewIdentityInfo(v).Switch(sess)
+		}
+	}
+	return false
+}

+ 54 - 0
middleground/entmanageapplication.go

@@ -0,0 +1,54 @@
+package middleground
+
+import (
+	"context"
+	"log"
+
+	"bp.jydev.jianyu360.cn/BaseService/entManageApplication/rpc/entmanageapplication"
+	"bp.jydev.jianyu360.cn/BaseService/entManageApplication/rpc/pb"
+	"github.com/zeromicro/go-zero/core/discov"
+	"github.com/zeromicro/go-zero/zrpc"
+)
+
+type entManageApplication struct {
+	hosts []string
+	key   string
+}
+
+func newEntManageApplication(hosts []string, key string) *entManageApplication {
+	return &entManageApplication{
+		hosts: hosts,
+		key:   key,
+	}
+}
+
+func (e *entManageApplication) newClient() zrpc.Client {
+	client, err := zrpc.NewClient(zrpc.RpcClientConf{
+		Etcd: discov.EtcdConf{
+			Hosts: e.hosts,
+			Key:   e.key,
+		},
+	})
+	if err != nil {
+		log.Println(err)
+		return nil
+	}
+	return client
+}
+
+//
+func (e *entManageApplication) EmpowerUserIds(ids []int64) *pb.EmpowerUserIds {
+	client := e.newClient()
+	if client == nil {
+		return nil
+	}
+	defer client.Conn().Close()
+	resp, err := entmanageapplication.NewEntManageApplication(client).EmpowerUserIds(context.Background(), &pb.EmpowerUserIds{
+		Ids: ids,
+	})
+	if err != nil {
+		log.Println(err)
+		return nil
+	}
+	return resp
+}

+ 9 - 4
middleground/middleground.go

@@ -1,10 +1,11 @@
 package middleground
 
 type Middleground struct {
-	hosts            []string
-	UserCenter       *userCenter
-	ResourceCenter   *resourceCenter
-	PowerCheckCenter *powerCheckCenter
+	hosts                []string
+	UserCenter           *userCenter
+	ResourceCenter       *resourceCenter
+	PowerCheckCenter     *powerCheckCenter
+	EntManageApplication *entManageApplication
 }
 
 func NewMiddleground(hosts []string) *Middleground {
@@ -24,6 +25,10 @@ func (m *Middleground) RegPowerCheckCenter(key string) *Middleground {
 	m.PowerCheckCenter = newPowerCheckCenter(m.hosts, key)
 	return m
 }
+func (m *Middleground) RegEntManageApplication(key string) *Middleground {
+	m.EntManageApplication = newEntManageApplication(m.hosts, key)
+	return m
+}
 func main() {
 	//userId: 63d498bb6ae0e1ea2170e03d -baseUserId: 366251 -accountId: 13485 -entId: 15419 -positionType: 0 -baseUserId: 366251 -accountId: 13485 -entId: 15419 -positionType: 0 -positionId: 932
 	NewMiddleground([]string{"192.168.3.206:2379"}).RegPowerCheckCenter("powercheck.rpc")