get_sop_task_by_id_logic.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. organizationId := l.ctx.Value("organizationId").(uint64)
  26. data, err := l.svcCtx.DB.SopTask.Query().
  27. Where(soptask.ID(req.Id), soptask.OrganizationIDEQ(organizationId)).
  28. WithTaskStages().
  29. Only(l.ctx)
  30. if err != nil {
  31. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  32. }
  33. stageList := make([]types.SopStageInfo, 0)
  34. if data.Edges.TaskStages != nil {
  35. for _, ts := range data.Edges.TaskStages {
  36. stageList = append(stageList, types.SopStageInfo{
  37. BaseIDInfo: types.BaseIDInfo{
  38. Id: &ts.ID,
  39. },
  40. Status: &ts.Status,
  41. TaskId: &ts.TaskID,
  42. Name: &ts.Name,
  43. ConditionType: &ts.ConditionType,
  44. ConditionOperator: &ts.ConditionOperator,
  45. IndexSort: &ts.IndexSort,
  46. })
  47. }
  48. }
  49. return &types.SopTaskInfoResp{
  50. BaseDataInfo: types.BaseDataInfo{
  51. Code: 0,
  52. Msg: errormsg.Success,
  53. },
  54. Data: types.SopTaskInfo{
  55. BaseIDInfo: types.BaseIDInfo{
  56. Id: &data.ID,
  57. CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
  58. UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
  59. },
  60. Status: &data.Status,
  61. Name: &data.Name,
  62. BotWxidList: data.BotWxidList,
  63. Type: &data.Type,
  64. PlanStartTime: pointy.GetUnixMilliPointer(data.PlanStartTime.UnixMilli()),
  65. PlanEndTime: pointy.GetUnixMilliPointer(data.PlanEndTime.UnixMilli()),
  66. CreatorId: &data.CreatorID,
  67. StageList: stageList,
  68. },
  69. }, nil
  70. }