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 }