get_sop_task_by_id_logic.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package sop_task
  2. import (
  3. "context"
  4. "wechat-api/ent/soptask"
  5. "wechat-api/internal/svc"
  6. "wechat-api/internal/types"
  7. "wechat-api/internal/utils/dberrorhandler"
  8. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  9. "github.com/suyuan32/simple-admin-common/utils/pointy"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type GetSopTaskByIdLogic struct {
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. logx.Logger
  16. }
  17. func NewGetSopTaskByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSopTaskByIdLogic {
  18. return &GetSopTaskByIdLogic{
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. Logger: logx.WithContext(ctx),
  22. }
  23. }
  24. func (l *GetSopTaskByIdLogic) GetSopTaskById(req *types.IDReq) (*types.SopTaskInfoResp, error) {
  25. data, err := l.svcCtx.DB.SopTask.Query().
  26. Where(soptask.ID(req.Id)).
  27. WithTaskStages().
  28. Only(l.ctx)
  29. if err != nil {
  30. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  31. }
  32. stageList := make([]types.SopStageInfo, 0)
  33. if data.Edges.TaskStages != nil {
  34. for _, ts := range data.Edges.TaskStages {
  35. stageList = append(stageList, types.SopStageInfo{
  36. BaseIDInfo: types.BaseIDInfo{
  37. Id: &ts.ID,
  38. },
  39. Status: &ts.Status,
  40. TaskId: &ts.TaskID,
  41. Name: &ts.Name,
  42. ConditionType: &ts.ConditionType,
  43. ConditionOperator: &ts.ConditionOperator,
  44. IndexSort: &ts.IndexSort,
  45. })
  46. }
  47. }
  48. return &types.SopTaskInfoResp{
  49. BaseDataInfo: types.BaseDataInfo{
  50. Code: 0,
  51. Msg: errormsg.Success,
  52. },
  53. Data: types.SopTaskInfo{
  54. BaseIDInfo: types.BaseIDInfo{
  55. Id: &data.ID,
  56. CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
  57. UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
  58. },
  59. Status: &data.Status,
  60. Name: &data.Name,
  61. BotWxidList: data.BotWxidList,
  62. Type: &data.Type,
  63. PlanStartTime: pointy.GetUnixMilliPointer(data.PlanStartTime.UnixMilli()),
  64. PlanEndTime: pointy.GetUnixMilliPointer(data.PlanEndTime.UnixMilli()),
  65. CreatorId: &data.CreatorID,
  66. StageList: stageList,
  67. },
  68. }, nil
  69. }