Sfoglia il codice sorgente

fix:1v1会话职位获取

duxin 2 anni fa
parent
commit
c78f5c2004

+ 28 - 0
api/messagecenter/internal/handler/oneuserpositionhandler.go

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

+ 44 - 0
api/messagecenter/internal/logic/oneuserpositionlogic.go

@@ -0,0 +1,44 @@
+package logic
+
+import (
+	quitl "app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/encrypt"
+	"bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/messagecenter"
+	"context"
+
+	"bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/api/messagecenter/internal/svc"
+	"bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/api/messagecenter/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type OneUserPositionLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewOneUserPositionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OneUserPositionLogic {
+	return &OneUserPositionLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *OneUserPositionLogic) OneUserPosition(req *types.OneUserPositionReq) (resp *types.CommonRes, err error) {
+	oneUserPositionReq := &messagecenter.OneUserPositionReq{
+		EntId:      req.EntId,
+		PositionId: quitl.Int64All(encrypt.SE.Decode4Hex(req.PositionId)),
+		Appid:      req.Appid,
+	}
+	oneResp, err := l.svcCtx.Message.OneUserPosition(l.ctx, oneUserPositionReq)
+	if err != nil {
+		return nil, err
+	}
+	return &types.CommonRes{
+		Error_msg:  oneResp.ErrorMsg,
+		Error_code: int(oneResp.ErrorCode),
+		Data:       oneResp.Position,
+	}, nil
+}

+ 60 - 0
rpc/messagecenter/internal/logic/oneuserpositionlogic.go

@@ -0,0 +1,60 @@
+package logic
+
+import (
+	"app.yhyue.com/moapp/jybase/common"
+	util "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/entity"
+	IC "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/init"
+	"context"
+	"fmt"
+	"log"
+
+	"bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/internal/svc"
+	"bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/messagecenter"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type OneUserPositionLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewOneUserPositionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OneUserPositionLogic {
+	return &OneUserPositionLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+// 1v1会话职位
+func (l *OneUserPositionLogic) OneUserPosition(in *messagecenter.OneUserPositionReq) (*messagecenter.OneUserPositionResp, error) {
+	// 1v1聊条职位
+	log.Println("1v1会话职位", in.EntId, in.PositionId)
+	ids := IC.BaseMysql.SelectBySql(fmt.Sprintf("select b.id,b.user_id,a.phone  from  %s a INNER JOIN  base_position b  on  b.type=1  and  b.ent_id=%d and b.id=%d and  a.id=b.user_id ", util.BASE_USER, in.EntId, in.PositionId))
+	if ids == nil || len(*ids) != 1 {
+		return &messagecenter.OneUserPositionResp{}, nil
+	}
+	var phone, positionName string
+	for _, v := range *ids {
+		phone = common.InterfaceToStr(v["phone"])
+	}
+	idName := IC.MainMysql.SelectBySql(fmt.Sprintf(`SELECT a.id,c.name,d.role_id,a.phone,e.name as roleName  FROM entniche_user a
+    				INNER JOIN entniche_department_user b on a.id = b.user_id
+					INNER JOIN entniche_department c on c.id = b.dept_id
+    				INNER JOIN entniche_user_role d on a.ent_id=%d and a.phone = %s and a.id = d.user_id
+					INNER JOIN entniche_role e on e.id = d.role_id
+					`, in.EntId, phone))
+	if idName == nil || len(*idName) != 1 {
+		return &messagecenter.OneUserPositionResp{}, nil
+	}
+	userPosition := (*idName)[0]
+	switch common.IntAll(userPosition["role_id"]) {
+	case 2:
+		positionName = fmt.Sprintf("%s%s", common.InterfaceToStr(userPosition["name"]), common.InterfaceToStr(userPosition["roleName"]))
+	case 1:
+		positionName = "管理员"
+	}
+	return &messagecenter.OneUserPositionResp{Position: positionName}, nil
+}