create_sop_task_logic.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. currentUserID, _ := l.ctx.Value("userId").(string)
  26. fmt.Printf("ctx: %s\n\n", currentUserID)
  27. _, err := l.svcCtx.DB.SopTask.Create().
  28. SetNotNilStatus(req.Status).
  29. SetNotNilName(req.Name).
  30. SetNotNilBotWxidList(req.BotWxidList).
  31. SetNotNilType(req.Type).
  32. SetNotNilPlanStartTime(pointy.GetTimeMilliPointer(req.PlanStartTime)).
  33. SetNotNilPlanEndTime(pointy.GetTimeMilliPointer(req.PlanEndTime)).
  34. SetNotNilCreatorID(&currentUserID).
  35. Save(l.ctx)
  36. if err != nil {
  37. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  38. }
  39. return &types.BaseMsgResp{Msg: errormsg.CreateSuccess}, nil
  40. }