get_sop_task_by_id_logic.go 2.2 KB

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