|
@@ -0,0 +1,93 @@
|
|
|
+package middleground
|
|
|
+
|
|
|
+import (
|
|
|
+ "context"
|
|
|
+ "log"
|
|
|
+
|
|
|
+ "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
|
|
|
+ "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/usercenter"
|
|
|
+ "github.com/zeromicro/go-zero/core/discov"
|
|
|
+ "github.com/zeromicro/go-zero/zrpc"
|
|
|
+)
|
|
|
+
|
|
|
+type userCenter struct {
|
|
|
+ hosts []string
|
|
|
+ key string
|
|
|
+}
|
|
|
+
|
|
|
+func newUserCenter(hosts []string, key string) *userCenter {
|
|
|
+ return &userCenter{
|
|
|
+ hosts: hosts,
|
|
|
+ key: key,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func (u *userCenter) newClient() zrpc.Client {
|
|
|
+ client, err := zrpc.NewClient(zrpc.RpcClientConf{
|
|
|
+ Etcd: discov.EtcdConf{
|
|
|
+ Hosts: u.hosts,
|
|
|
+ Key: u.key,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ log.Println(err)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ return client
|
|
|
+}
|
|
|
+
|
|
|
+//获取身份列表
|
|
|
+func (u *userCenter) IdentityList(userId int64) []*pb.Identity {
|
|
|
+ client := u.newClient()
|
|
|
+ defer client.Conn().Close()
|
|
|
+ resp, err := usercenter.NewUserCenter(client).IdentityList(context.Background(), &pb.IdentityReq{
|
|
|
+ Id: userId,
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ log.Println(err)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ return resp.Identitys
|
|
|
+}
|
|
|
+
|
|
|
+//获取账号id获取个人身份信息
|
|
|
+func (u *userCenter) IdentityByUserId(userId int64) *pb.Identity {
|
|
|
+ client := u.newClient()
|
|
|
+ defer client.Conn().Close()
|
|
|
+ resp, err := usercenter.NewUserCenter(client).IdentityByUserId(context.Background(), &pb.IdentityReq{
|
|
|
+ Id: userId,
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ log.Println(err)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ return resp
|
|
|
+}
|
|
|
+
|
|
|
+//根据职位id获取身份信息
|
|
|
+func (u *userCenter) IdentityByPositionId(positionId int64) *pb.Identity {
|
|
|
+ client := u.newClient()
|
|
|
+ defer client.Conn().Close()
|
|
|
+ resp, err := usercenter.NewUserCenter(client).IdentityByPositionId(context.Background(), &pb.IdentityReq{
|
|
|
+ Id: positionId,
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ log.Println(err)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ return resp
|
|
|
+}
|
|
|
+
|
|
|
+//根据企业员工id获取身份信息
|
|
|
+func (u *userCenter) IdentityByEntUserId(entUserId int64) *pb.Identity {
|
|
|
+ client := u.newClient()
|
|
|
+ defer client.Conn().Close()
|
|
|
+ resp, err := usercenter.NewUserCenter(client).IdentityByEntUserId(context.Background(), &pb.IdentityReq{
|
|
|
+ Id: entUserId,
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ log.Println(err)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ return resp
|
|
|
+}
|