multiplesavemsglogic.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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/tal-tech/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. // todo: add your logic here and delete this line
  26. log.Println("请求参数:", req)
  27. //var reqData = []map[string]interface{}{}
  28. //err := json.Unmarshal([]byte(req.SaveData), reqData)
  29. //if err != nil {
  30. // return &types.MultipleSaveMsgResp{
  31. // Code: 0,
  32. // Message: "失败",
  33. // ErrCount: 0,
  34. // }, nil
  35. //}
  36. errCount := 0
  37. lsi := l.svcCtx.MessageCenter
  38. msgInfo := req.MsgInfo
  39. var showBuoyValue int64 = 0
  40. if value, ok := msgInfo["showBuoy"].(json.Number); ok {
  41. showBuoyValue, _ = value.Int64()
  42. }
  43. _, err := lsi.MultipleSaveMsg(l.ctx, &messageclient.MultipleSaveMsgReq{
  44. Appid: util.ObjToString(msgInfo["appid"]),
  45. SendUserId: util.ObjToString(msgInfo["sendUserId"]),
  46. SendName: util.ObjToString(msgInfo["sendName"]),
  47. Title: util.ObjToString(msgInfo["title"]),
  48. Content: util.ObjToString(msgInfo["content"]),
  49. MsgType: int64(util.IntAll(msgInfo["msgType"])),
  50. Link: util.ObjToString(msgInfo["link"]),
  51. CiteId: 0,
  52. UserIds: req.UserIds,
  53. UserNames: req.UserNames,
  54. MsgLogId: int64(util.IntAll(msgInfo["msgLogId"])),
  55. ShowBuoy: showBuoyValue,
  56. ShowContent: util.ObjToString(msgInfo["showContent"]),
  57. })
  58. if err != nil {
  59. errCount++
  60. }
  61. return &types.MultipleSaveMsgResp{
  62. Code: 1,
  63. Message: "保存成功",
  64. ErrCount: int64(errCount),
  65. }, nil
  66. }