multiplesavemsglogic.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. showBuoyValue, _ := msgInfo["showBuoy"].(json.Number).Int64()
  40. _, err := lsi.MultipleSaveMsg(l.ctx, &messageclient.MultipleSaveMsgReq{
  41. Appid: util.ObjToString(msgInfo["appid"]),
  42. SendUserId: util.ObjToString(msgInfo["sendUserId"]),
  43. SendName: util.ObjToString(msgInfo["sendName"]),
  44. Title: util.ObjToString(msgInfo["title"]),
  45. Content: util.ObjToString(msgInfo["content"]),
  46. MsgType: int64(util.IntAll(msgInfo["msgType"])),
  47. Link: util.ObjToString(msgInfo["link"]),
  48. CiteId: 0,
  49. UserIds: req.UserIds,
  50. UserNames: req.UserNames,
  51. MsgLogId: int64(util.IntAll(msgInfo["msgLogId"])),
  52. ShowBuoy: showBuoyValue,
  53. ShowContent: util.ObjToString(msgInfo["showContent"]),
  54. })
  55. if err != nil {
  56. errCount++
  57. }
  58. return &types.MultipleSaveMsgResp{
  59. Code: 1,
  60. Message: "保存成功",
  61. ErrCount: int64(errCount),
  62. }, nil
  63. }