oneuserpositionlogic.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. util "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/entity"
  5. IC "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/init"
  6. "context"
  7. "fmt"
  8. "log"
  9. "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/internal/svc"
  10. "bp.jydev.jianyu360.cn/SocialPlatform/messageCenter/rpc/messagecenter/messagecenter"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  13. type OneUserPositionLogic struct {
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. logx.Logger
  17. }
  18. func NewOneUserPositionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OneUserPositionLogic {
  19. return &OneUserPositionLogic{
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. Logger: logx.WithContext(ctx),
  23. }
  24. }
  25. // 1v1会话职位
  26. func (l *OneUserPositionLogic) OneUserPosition(in *messagecenter.OneUserPositionReq) (*messagecenter.OneUserPositionResp, error) {
  27. // 1v1聊条职位
  28. log.Println("1v1会话职位", in.EntId, in.PositionId)
  29. 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))
  30. if ids == nil || len(*ids) != 1 {
  31. return &messagecenter.OneUserPositionResp{}, nil
  32. }
  33. var phone, positionName string
  34. for _, v := range *ids {
  35. phone = common.InterfaceToStr(v["phone"])
  36. }
  37. idName := IC.MainMysql.SelectBySql(fmt.Sprintf(`SELECT a.id,c.name,d.role_id,a.phone,e.name as roleName FROM entniche_user a
  38. INNER JOIN entniche_department_user b on a.id = b.user_id
  39. INNER JOIN entniche_department c on c.id = b.dept_id
  40. INNER JOIN entniche_user_role d on a.ent_id=%d and a.phone = %s and a.id = d.user_id
  41. INNER JOIN entniche_role e on e.id = d.role_id
  42. `, in.EntId, phone))
  43. if idName == nil || len(*idName) != 1 {
  44. return &messagecenter.OneUserPositionResp{}, nil
  45. }
  46. userPosition := (*idName)[0]
  47. switch common.IntAll(userPosition["role_id"]) {
  48. case 2:
  49. positionName = fmt.Sprintf("%s%s", common.InterfaceToStr(userPosition["name"]), common.InterfaceToStr(userPosition["roleName"]))
  50. case 1:
  51. positionName = "管理员"
  52. }
  53. return &messagecenter.OneUserPositionResp{Position: positionName}, nil
  54. }