create_sop_task_logic.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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.BaseMsgResp, error) {
  25. // 判断 planEndTime 和 planStartTime 是否非空,且 planEndTime 是否大于 planStartTime
  26. if req.PlanEndTime != nil && req.PlanStartTime != nil && (*req.PlanEndTime <= *req.PlanStartTime) {
  27. return nil, dberrorhandler.DefaultEntError(l.Logger, fmt.Errorf("planEndTime must be greater than planStartTime"), req)
  28. }
  29. currentUserID, _ := l.ctx.Value("userId").(string)
  30. fmt.Printf("ctx: %s\n\n", currentUserID)
  31. _, err := l.svcCtx.DB.SopTask.Create().
  32. SetNotNilStatus(req.Status).
  33. SetNotNilName(req.Name).
  34. SetNotNilBotWxidList(req.BotWxidList).
  35. SetNotNilType(req.Type).
  36. SetNotNilPlanStartTime(pointy.GetTimeMilliPointer(req.PlanStartTime)).
  37. SetNotNilPlanEndTime(pointy.GetTimeMilliPointer(req.PlanEndTime)).
  38. SetNotNilCreatorID(&currentUserID).
  39. Save(l.ctx)
  40. if err != nil {
  41. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  42. }
  43. return &types.BaseMsgResp{Msg: errormsg.CreateSuccess}, nil
  44. }