multiplesavemsglogic.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. "log"
  11. )
  12. type MultipleSaveMsgLogic struct {
  13. logx.Logger
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. }
  17. func NewMultipleSaveMsgLogic(ctx context.Context, svcCtx *svc.ServiceContext) MultipleSaveMsgLogic {
  18. return MultipleSaveMsgLogic{
  19. Logger: logx.WithContext(ctx),
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. }
  23. }
  24. func (l *MultipleSaveMsgLogic) MultipleSaveMsg(req types.MultipleSaveMsgReq) (*types.MultipleSaveMsgResp, error) {
  25. errCount := 0
  26. lsi := l.svcCtx.MessageCenter
  27. msgInfo := req.MsgInfo
  28. var showBuoyValue int64 = 0
  29. if value, ok := msgInfo["showBuoy"].(json.Number); ok {
  30. showBuoyValue, _ = value.Int64()
  31. }
  32. _, err := lsi.MultipleSaveMsg(l.ctx, &messageclient.MultipleSaveMsgReq{
  33. Appid: util.ObjToString(msgInfo["appid"]),
  34. SendUserId: util.ObjToString(msgInfo["sendUserId"]),
  35. SendName: util.ObjToString(msgInfo["sendName"]),
  36. Title: util.ObjToString(msgInfo["title"]),
  37. Content: util.ObjToString(msgInfo["content"]),
  38. MsgType: int64(util.IntAll(msgInfo["msgType"])),
  39. Link: util.ObjToString(msgInfo["link"]),
  40. CiteId: 0,
  41. UserIds: req.UserIds,
  42. UserNames: req.UserNames,
  43. MsgLogId: int64(util.IntAll(msgInfo["msgLogId"])),
  44. ShowBuoy: showBuoyValue,
  45. ShowContent: util.ObjToString(msgInfo["showContent"]),
  46. PositionIds: req.PositionIds,
  47. })
  48. if err != nil {
  49. log.Println("-------------", err)
  50. errCount++
  51. }
  52. return &types.MultipleSaveMsgResp{
  53. Code: 1,
  54. Message: "保存成功",
  55. ErrCount: int64(errCount),
  56. }, nil
  57. }