Forráskód Böngészése

Merge branch 'feature/v1.2.15' into feature/v1.2.16

wangchuanjin 2 éve
szülő
commit
27ed4754b6

+ 28 - 0
api/internal/handler/getentuserinfobypositonidhandler.go

@@ -0,0 +1,28 @@
+package handler
+
+import (
+	"net/http"
+
+	"bp.jydev.jianyu360.cn/BaseService/userCenter/api/internal/logic"
+	"bp.jydev.jianyu360.cn/BaseService/userCenter/api/internal/svc"
+	"bp.jydev.jianyu360.cn/BaseService/userCenter/api/internal/types"
+	"github.com/zeromicro/go-zero/rest/httpx"
+)
+
+func GetEntUserInfoByPositonIdHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.GetUserInfoByPIdReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewGetEntUserInfoByPositonIdLogic(r.Context(), svcCtx)
+		resp, err := l.GetEntUserInfoByPositonId(&req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 5 - 0
api/internal/handler/routes.go

@@ -82,6 +82,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 				Path:    "/userCenter/ent/userInfo",
 				Handler: GetEntUserInfoHandler(serverCtx),
 			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/userCenter/ent/getUserInfoByPId",
+				Handler: GetEntUserInfoByPositonIdHandler(serverCtx),
+			},
 		},
 	)
 

+ 42 - 0
api/internal/logic/getentuserinfobypositonidlogic.go

@@ -0,0 +1,42 @@
+package logic
+
+import (
+	"context"
+
+	"app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/encrypt"
+	"bp.jydev.jianyu360.cn/BaseService/userCenter/api/internal/svc"
+	"bp.jydev.jianyu360.cn/BaseService/userCenter/api/internal/types"
+	"bp.jydev.jianyu360.cn/BaseService/userCenter/entity"
+	. "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/usercenter"
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type GetEntUserInfoByPositonIdLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewGetEntUserInfoByPositonIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetEntUserInfoByPositonIdLogic {
+	return &GetEntUserInfoByPositonIdLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *GetEntUserInfoByPositonIdLogic) GetEntUserInfoByPositonId(req *types.GetUserInfoByPIdReq) (resp *types.Resp, err error) {
+	positionId := encrypt.SE.Decode4Hex(req.PositionId)
+	res, err := entity.UserCenterRpc.IdentityByPositionId(l.ctx, &IdentityReq{
+		Id: common.Int64All(positionId),
+	})
+
+	return &types.Resp{
+		Error_code: 0,
+		Error_msg:  "",
+		Data: map[string]interface{}{
+			"name": res.EntUserName,
+		},
+	}, err
+}

+ 7 - 1
api/internal/logic/getentuserinfologic.go

@@ -31,9 +31,15 @@ func NewGetEntUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
 func (l *GetEntUserInfoLogic) GetEntUserInfo(req *types.EntUserReq) (resp *types.Resp, err error) {
 	// todo: add your logic here and delete this line
 	resp = &types.Resp{Data: nil}
+	entUserid := req.HeaderEntUserId
+	//优先取传的参数,没有的话取header里的取自己的
+	if req.EntUserId > 0 {
+		entUserid = req.EntUserId
+	}
 	res, err := entity.UserCenterRpc.GetEntUserInfo(l.ctx, &pb.EntUserReq{
 		AppId:     req.AppId,
-		EntUserId: req.EntUserId,
+		EntUserId: entUserid,
+		EntId:     req.EntId,
 	})
 	if res == nil {
 		resp = &types.Resp{Data: nil, Error_msg: "暂无数据", Error_code: -1}

+ 9 - 2
api/internal/types/types.go

@@ -194,8 +194,10 @@ type UserReq struct {
 }
 
 type EntUserReq struct {
-	AppId     string `header:"appId,default=10000"`
-	EntUserId int64  `json:"entUserId"`
+	AppId           string `header:"appId,default=10000"`
+	EntUserId       int64  `json:"entUserId,optional"`
+	HeaderEntUserId int64  `header:"entUserId,optional"`
+	EntId           int64  `header:"entId,optional"`
 }
 
 type UserAddReq struct {
@@ -287,3 +289,8 @@ type UserIdentityReq struct {
 	NewUserId int64  `json:"newUserId"`
 	EntId     int64  `json:"entId,optional"`
 }
+
+type GetUserInfoByPIdReq struct {
+	AppId      string `header:"appId"`
+	PositionId string `json:"positionId"` //职位id
+}

+ 11 - 2
api/userCenter.api

@@ -207,8 +207,10 @@ type (
 	}
 
 	EntUserReq {
-		AppId     string `header:"appId,default=10000"`
-		EntUserId int64  `json:"entUserId"`
+		AppId           string `header:"appId,default=10000"`
+		EntUserId       int64  `json:"entUserId,optional"`
+		HeaderEntUserId int64  `header:"entUserId,optional"`
+		EntId           int64  `header:"entId,optional"`
 	}
 
 	UserAddReq {
@@ -302,6 +304,11 @@ type (
 		NewUserId int64  `json:"newUserId"`
 		EntId     int64  `json:"entId,optional"`
 	}
+
+	GetUserInfoByPIdReq {
+		AppId      string `header:"appId"`
+		PositionId string `json:"positionId"` //职位id
+	}
 )
 
 service userCenter-api {
@@ -335,6 +342,8 @@ service userCenter-api {
 	post /userCenter/user/getUserInfo (UserReq) returns (resp)
 	@handler GetEntUserInfo
 	post /userCenter/ent/userInfo (EntUserReq) returns (resp)
+	@handler GetEntUserInfoByPositonId
+	post /userCenter/ent/getUserInfoByPId (GetUserInfoByPIdReq) returns (resp)
 }
 
 @server(

+ 54 - 33
entity/jyUser.go

@@ -137,32 +137,37 @@ func (rpc *JyUser) AddUserInfo(info *CompletionUserInfo, res *Resp) error {
 			Mgo.Save("user", data)
 			//个人职位
 			//职位表添加
-			userPositionMap := map[string]interface{}{
-				"ent_id":       0,
-				"user_id":      userId,
-				"account_id":   userAccountId,
-				"person_name":  personName,
-				"account_name": accountName,
-				"type":         0,
-			}
-			userPositionId = BaseMysql.Insert(BasePosition, userPositionMap)
-			if userPositionId == 0 {
-				return false
+			if !ExistDecide(0, int64(0), userId, entAccountId) {
+				userPositionMap := map[string]interface{}{
+					"ent_id":       0,
+					"user_id":      userId,
+					"account_id":   userAccountId,
+					"person_name":  personName,
+					"account_name": accountName,
+					"type":         0,
+				}
+				userPositionId = BaseMysql.Insert(BasePosition, userPositionMap)
+				if userPositionId == 0 {
+					return false
+				}
 			}
 			//企业职位
 			//职位表添加
-			entPositionMap := map[string]interface{}{
-				"ent_id":       info.EntId,
-				"user_id":      userId,
-				"account_id":   entAccountId,
-				"person_name":  personName,
-				"account_name": accountName,
-				"type":         1,
-			}
-			entPositionId = BaseMysql.Insert(BasePosition, entPositionMap)
-			if entPositionId == 0 {
-				return false
+			if !ExistDecide(1, common.Int64All(info.EntId), userId, entAccountId) {
+				entPositionMap := map[string]interface{}{
+					"ent_id":       info.EntId,
+					"user_id":      userId,
+					"account_id":   entAccountId,
+					"person_name":  personName,
+					"account_name": accountName,
+					"type":         1,
+				}
+				entPositionId = BaseMysql.Insert(BasePosition, entPositionMap)
+				if entPositionId == 0 {
+					return false
+				}
 			}
+
 		} else {
 			personId = common.Int64All((*userData)["person_id"])
 			userId = common.Int64All((*userData)["id"])
@@ -209,17 +214,19 @@ func (rpc *JyUser) AddUserInfo(info *CompletionUserInfo, res *Resp) error {
 			}
 			personName = common.InterfaceToStr((*personData)["name"])
 			//职位表添加
-			positionMap := map[string]interface{}{
-				"ent_id":       info.EntId,
-				"user_id":      userId,
-				"account_id":   entAccountId,
-				"person_name":  personName,
-				"account_name": accountName,
-				"type":         1,
-			}
-			entPositionId = BaseMysql.Insert(BasePosition, positionMap)
-			if entPositionId == 0 {
-				return false
+			if !ExistDecide(1, common.Int64All(info.EntId), userId, entAccountId) {
+				positionMap := map[string]interface{}{
+					"ent_id":       info.EntId,
+					"user_id":      userId,
+					"account_id":   entAccountId,
+					"person_name":  personName,
+					"account_name": accountName,
+					"type":         1,
+				}
+				entPositionId = BaseMysql.Insert(BasePosition, positionMap)
+				if entPositionId == 0 {
+					return false
+				}
 			}
 			//个人职位信息查询
 			userPositionData := BaseMysql.FindOne(BasePosition, map[string]interface{}{
@@ -241,3 +248,17 @@ func (rpc *JyUser) AddUserInfo(info *CompletionUserInfo, res *Resp) error {
 	res.UserPositionId = userPositionId
 	return nil
 }
+
+//判断某个人之前是否在企业里边
+func ExistDecide(userType, entId, user_id, account_id int64) bool {
+	if count := BaseMysql.Count(BasePosition, map[string]interface{}{
+		"ent_id":     entId,
+		"user_id":    user_id,
+		"account_id": account_id,
+		"type":       userType,
+	}); count > 0 {
+		return true
+	}
+	return false
+
+}

+ 1 - 0
rpc/internal/logic/getentuserinfologic.go

@@ -29,6 +29,7 @@ func (l *GetEntUserInfoLogic) GetEntUserInfo(in *pb.EntUserReq) (*pb.EntUserResp
 	/// todo: add your logic here and delete this line
 	resp := &pb.EntUserResp{}
 	ret, msg := Entservice.GetEntUserInfo(in)
+	fmt.Println(in.EntId, in.EntUserId, "####")
 	if msg != "" {
 		l.Error(fmt.Sprintf("%+v", in), msg)
 		resp.ErrorMsg = msg