wangchuanjin 2 سال پیش
والد
کامیت
4b3d25ce9b
3فایلهای تغییر یافته به همراه22 افزوده شده و 2 حذف شده
  1. 4 0
      middleground/middleground.go
  2. 6 2
      middleground/powercheckcenter.go
  3. 12 0
      middleground/usercenter.go

+ 4 - 0
middleground/middleground.go

@@ -20,3 +20,7 @@ func (m *Middleground) RegPowerCheckCenter(key string) *Middleground {
 	m.PowerCheckCenter = newPowerCheckCenter(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")
+}

+ 6 - 2
middleground/powercheckcenter.go

@@ -1,12 +1,13 @@
 package middleground
 
 import (
+	"context"
+	"log"
+
 	"bp.jydev.jianyu360.cn/BaseService/powerCheckCenter/rpc/pb"
 	"bp.jydev.jianyu360.cn/BaseService/powerCheckCenter/rpc/powercheck"
-	"context"
 	"github.com/zeromicro/go-zero/core/discov"
 	"github.com/zeromicro/go-zero/zrpc"
-	"log"
 )
 
 type powerCheckCenter struct {
@@ -37,6 +38,9 @@ func (p *powerCheckCenter) newClient() zrpc.Client {
 
 func (p *powerCheckCenter) Check(appid, userId string, baseUserId, accountId, entId, positionType, positionId int64) *pb.CheckResp {
 	client := p.newClient()
+	if client == nil {
+		return nil
+	}
 	defer client.Conn().Close()
 	resp, err := powercheck.NewPowerCheck(client).Check(context.Background(), &pb.CheckReq{
 		Appid:        appid,

+ 12 - 0
middleground/usercenter.go

@@ -39,6 +39,9 @@ func (u *userCenter) newClient() zrpc.Client {
 //获取身份列表
 func (u *userCenter) IdentityList(userId int64) []*pb.Identity {
 	client := u.newClient()
+	if client == nil {
+		return nil
+	}
 	defer client.Conn().Close()
 	resp, err := usercenter.NewUserCenter(client).IdentityList(context.Background(), &pb.IdentityReq{
 		Id: userId,
@@ -53,6 +56,9 @@ func (u *userCenter) IdentityList(userId int64) []*pb.Identity {
 //获取账号id获取个人身份信息
 func (u *userCenter) IdentityByUserId(userId int64) *pb.Identity {
 	client := u.newClient()
+	if client == nil {
+		return nil
+	}
 	defer client.Conn().Close()
 	resp, err := usercenter.NewUserCenter(client).IdentityByUserId(context.Background(), &pb.IdentityReq{
 		Id: userId,
@@ -67,6 +73,9 @@ func (u *userCenter) IdentityByUserId(userId int64) *pb.Identity {
 //根据职位id获取身份信息
 func (u *userCenter) IdentityByPositionId(positionId int64) *pb.Identity {
 	client := u.newClient()
+	if client == nil {
+		return nil
+	}
 	defer client.Conn().Close()
 	resp, err := usercenter.NewUserCenter(client).IdentityByPositionId(context.Background(), &pb.IdentityReq{
 		Id: positionId,
@@ -81,6 +90,9 @@ func (u *userCenter) IdentityByPositionId(positionId int64) *pb.Identity {
 //根据企业员工id获取身份信息
 func (u *userCenter) IdentityByEntUserId(entUserId int64) *pb.Identity {
 	client := u.newClient()
+	if client == nil {
+		return nil
+	}
 	defer client.Conn().Close()
 	resp, err := usercenter.NewUserCenter(client).IdentityByEntUserId(context.Background(), &pb.IdentityReq{
 		Id: entUserId,