get_batch_msg_by_id_logic.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package batch_msg
  2. import (
  3. "context"
  4. "github.com/zeromicro/go-zero/core/errorx"
  5. "wechat-api/ent"
  6. "wechat-api/ent/batchmsg"
  7. "wechat-api/internal/svc"
  8. "wechat-api/internal/types"
  9. "wechat-api/internal/utils/dberrorhandler"
  10. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  11. "github.com/suyuan32/simple-admin-common/utils/pointy"
  12. "github.com/zeromicro/go-zero/core/logx"
  13. )
  14. type GetBatchMsgByIdLogic struct {
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. logx.Logger
  18. }
  19. func NewGetBatchMsgByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetBatchMsgByIdLogic {
  20. return &GetBatchMsgByIdLogic{
  21. ctx: ctx,
  22. svcCtx: svcCtx,
  23. Logger: logx.WithContext(ctx),
  24. }
  25. }
  26. func (l *GetBatchMsgByIdLogic) GetBatchMsgById(req *types.IDReq) (*types.BatchMsgInfoResp, error) {
  27. organizationId := l.ctx.Value("organizationId").(uint64)
  28. data, err := l.svcCtx.DB.BatchMsg.Query().Where(batchmsg.ID(req.Id), batchmsg.OrganizationID(organizationId)).First(l.ctx)
  29. if err != nil {
  30. if ent.IsNotFound(err) {
  31. return nil, errorx.NewInvalidArgumentError("群发消息不存在")
  32. }
  33. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  34. }
  35. return &types.BatchMsgInfoResp{
  36. BaseDataInfo: types.BaseDataInfo{
  37. Code: 0,
  38. Msg: errormsg.Success,
  39. },
  40. Data: types.BatchMsgInfo{
  41. BaseIDInfo: types.BaseIDInfo{
  42. Id: &data.ID,
  43. CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
  44. UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
  45. },
  46. Status: &data.Status,
  47. BatchNo: &data.BatchNo,
  48. TaskName: &data.TaskName,
  49. Fromwxid: &data.Fromwxid,
  50. Msg: &data.Msg,
  51. Tag: &data.Tag,
  52. Total: &data.Total,
  53. Success: &data.Success,
  54. Fail: &data.Fail,
  55. Type: &data.Type,
  56. StartTime: pointy.GetUnixMilliPointer(data.StartTime.UnixMilli()),
  57. StopTime: pointy.GetUnixMilliPointer(data.StopTime.UnixMilli()),
  58. StartTimeStr: pointy.GetPointer(data.StartTime.Format("2006-01-02 15:04:05")),
  59. },
  60. }, nil
  61. }