pushmsglogic.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package logic
  2. import (
  3. "context"
  4. "log"
  5. "strings"
  6. "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
  7. cm "bp.jydev.jianyu360.cn/CRM/application/api/common"
  8. "bp.jydev.jianyu360.cn/CRM/application/api/internal/svc"
  9. "bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
  10. "bp.jydev.jianyu360.cn/CRM/application/service"
  11. "github.com/gogf/gf/v2/util/gconv"
  12. "github.com/zeromicro/go-zero/core/logx"
  13. )
  14. type PushMsgLogic struct {
  15. logx.Logger
  16. ctx context.Context
  17. svcCtx *svc.ServiceContext
  18. }
  19. func NewPushMsgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PushMsgLogic {
  20. return &PushMsgLogic{
  21. Logger: logx.WithContext(ctx),
  22. ctx: ctx,
  23. svcCtx: svcCtx,
  24. }
  25. }
  26. func (l *PushMsgLogic) PushMsg(req *types.PushMsgReq) (resp *types.Reply, err error) {
  27. resp = &types.Reply{}
  28. status := -1
  29. baseUserIdArr := []int64{}
  30. for _, v := range req.User {
  31. resp, err := cm.UserCenterRpc.IdentityByEntUserId(l.ctx, &pb.IdentityReq{
  32. Id: v,
  33. })
  34. if err != nil {
  35. log.Println("获取用户职位id信息出错", v, "的信息出错", err)
  36. continue
  37. } else if resp == nil {
  38. log.Println("entuser用户", v, "没有找到职位信息")
  39. continue
  40. }
  41. baseUserIdArr = append(baseUserIdArr, resp.UserId)
  42. //查询mgo
  43. }
  44. u := &service.User{
  45. BaseUserIds: baseUserIdArr,
  46. }
  47. m := u.GetUserId(req.EntId)
  48. for k, v := range m {
  49. var kb strings.Builder
  50. var vb strings.Builder
  51. kb.WriteString(k + ",")
  52. vb.WriteString(gconv.String(v) + ",")
  53. userId := strings.TrimRight(kb.String(), ",")
  54. positionId := strings.TrimRight(vb.String(), ",")
  55. ok := service.StationMailPush(userId, positionId, req.Title, strings.Replace(req.Content, " ", "%20", -1), req.PcHref, req.MobileHref, req.MsgType)
  56. if ok {
  57. status = 1
  58. }
  59. }
  60. resp.Data = map[string]interface{}{
  61. "status": status,
  62. }
  63. return
  64. }