multiplesavemsglogic.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/MessageCenter/api/internal/svc"
  4. "app.yhyue.com/moapp/MessageCenter/api/internal/types"
  5. "app.yhyue.com/moapp/MessageCenter/rpc/messageclient"
  6. "app.yhyue.com/moapp/MessageCenter/util"
  7. "context"
  8. "encoding/json"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type MultipleSaveMsgLogic struct {
  12. logx.Logger
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. }
  16. func NewMultipleSaveMsgLogic(ctx context.Context, svcCtx *svc.ServiceContext) MultipleSaveMsgLogic {
  17. return MultipleSaveMsgLogic{
  18. Logger: logx.WithContext(ctx),
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. }
  22. }
  23. func (l *MultipleSaveMsgLogic) MultipleSaveMsg(req types.MultipleSaveMsgReq) (*types.MultipleSaveMsgResp, error) {
  24. errCount := 0
  25. lsi := l.svcCtx.MessageCenter
  26. msgInfo := req.MsgInfo
  27. var showBuoyValue int64 = 0
  28. if value, ok := msgInfo["showBuoy"].(json.Number); ok {
  29. showBuoyValue, _ = value.Int64()
  30. }
  31. _, err := lsi.MultipleSaveMsg(l.ctx, &messageclient.MultipleSaveMsgReq{
  32. Appid: util.ObjToString(msgInfo["appid"]),
  33. SendUserId: util.ObjToString(msgInfo["sendUserId"]),
  34. SendName: util.ObjToString(msgInfo["sendName"]),
  35. Title: util.ObjToString(msgInfo["title"]),
  36. Content: util.ObjToString(msgInfo["content"]),
  37. MsgType: int64(util.IntAll(msgInfo["msgType"])),
  38. Link: util.ObjToString(msgInfo["link"]),
  39. CiteId: 0,
  40. UserIds: req.UserIds,
  41. UserNames: req.UserNames,
  42. MsgLogId: int64(util.IntAll(msgInfo["msgLogId"])),
  43. ShowBuoy: showBuoyValue,
  44. ShowContent: util.ObjToString(msgInfo["showContent"]),
  45. PositionIds: req.PositionIds,
  46. })
  47. if err != nil {
  48. errCount++
  49. }
  50. return &types.MultipleSaveMsgResp{
  51. Code: 1,
  52. Message: "保存成功",
  53. ErrCount: int64(errCount),
  54. }, nil
  55. }