get_batch_msg_by_id_logic.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package batch_msg
  2. import (
  3. "context"
  4. "wechat-api/internal/svc"
  5. "wechat-api/internal/types"
  6. "wechat-api/internal/utils/dberrorhandler"
  7. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  8. "github.com/suyuan32/simple-admin-common/utils/pointy"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type GetBatchMsgByIdLogic struct {
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. logx.Logger
  15. }
  16. func NewGetBatchMsgByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetBatchMsgByIdLogic {
  17. return &GetBatchMsgByIdLogic{
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. Logger: logx.WithContext(ctx),
  21. }
  22. }
  23. func (l *GetBatchMsgByIdLogic) GetBatchMsgById(req *types.IDReq) (*types.BatchMsgInfoResp, error) {
  24. data, err := l.svcCtx.DB.BatchMsg.Get(l.ctx, req.Id)
  25. if err != nil {
  26. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  27. }
  28. return &types.BatchMsgInfoResp{
  29. BaseDataInfo: types.BaseDataInfo{
  30. Code: 0,
  31. Msg: errormsg.Success,
  32. },
  33. Data: types.BatchMsgInfo{
  34. BaseIDInfo: types.BaseIDInfo{
  35. Id: &data.ID,
  36. CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
  37. UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
  38. },
  39. Status: &data.Status,
  40. BatchNo: &data.BatchNo,
  41. TaskName: &data.TaskName,
  42. Fromwxid: &data.Fromwxid,
  43. Msg: &data.Msg,
  44. Tag: &data.Tag,
  45. Total: &data.Total,
  46. Success: &data.Success,
  47. Fail: &data.Fail,
  48. StartTime: pointy.GetUnixMilliPointer(data.StartTime.UnixMilli()),
  49. StopTime: pointy.GetUnixMilliPointer(data.StopTime.UnixMilli()),
  50. SendTime: pointy.GetUnixMilliPointer(data.SendTime.UnixMilli()),
  51. },
  52. }, nil
  53. }