create_sop_task_logic.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package sop_task
  2. import (
  3. "context"
  4. "fmt"
  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 CreateSopTaskLogic struct {
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. logx.Logger
  16. }
  17. func NewCreateSopTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateSopTaskLogic {
  18. return &CreateSopTaskLogic{
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. Logger: logx.WithContext(ctx),
  22. }
  23. }
  24. func (l *CreateSopTaskLogic) CreateSopTask(req *types.SopTaskInfo) (*types.SopTaskCreateResp, error) {
  25. organizationId := l.ctx.Value("organizationId").(uint64)
  26. //departmentId := l.ctx.Value("departmentId").(uint64)
  27. // 判断 planEndTime 和 planStartTime 是否非空,且 planEndTime 是否大于 planStartTime
  28. if req.PlanEndTime != nil && req.PlanStartTime != nil && (*req.PlanEndTime <= *req.PlanStartTime) {
  29. return nil, dberrorhandler.DefaultEntError(l.Logger, fmt.Errorf("planEndTime must be greater than planStartTime"), req)
  30. }
  31. currentUserID, _ := l.ctx.Value("userId").(string)
  32. fmt.Printf("ctx: %s\n\n", currentUserID)
  33. newTask, err := l.svcCtx.DB.SopTask.Create().
  34. SetNotNilStatus(req.Status).
  35. SetNotNilName(req.Name).
  36. SetNotNilBotWxidList(req.BotWxidList).
  37. SetNotNilType(req.Type).
  38. SetNotNilPlanStartTime(pointy.GetTimeMilliPointer(req.PlanStartTime)).
  39. SetNotNilPlanEndTime(pointy.GetTimeMilliPointer(req.PlanEndTime)).
  40. SetNotNilCreatorID(&currentUserID).
  41. SetOrganizationID(organizationId).
  42. Save(l.ctx)
  43. if err != nil {
  44. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  45. }
  46. return &types.SopTaskCreateResp{BaseDataInfo: types.BaseDataInfo{Msg: errormsg.CreateSuccess}, Data: newTask.ID}, nil
  47. }