create_label_logic.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package label
  2. import (
  3. "context"
  4. "wechat-api/internal/svc"
  5. "wechat-api/internal/types"
  6. "wechat-api/internal/utils/dberrorhandler"
  7. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  8. "github.com/zeromicro/go-zero/core/logx"
  9. )
  10. type CreateLabelLogic struct {
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. logx.Logger
  14. }
  15. func NewCreateLabelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateLabelLogic {
  16. return &CreateLabelLogic{
  17. ctx: ctx,
  18. svcCtx: svcCtx,
  19. Logger: logx.WithContext(ctx),
  20. }
  21. }
  22. func (l *CreateLabelLogic) CreateLabel(req *types.LabelInfo) (*types.BaseMsgResp, error) {
  23. l.Logger.Infof("CreateLabel req: %v", req)
  24. var conditions = "{}"
  25. //if *req.Conditions == "" {
  26. // conditions = "{}"
  27. //} else {
  28. // conditions = *req.Conditions
  29. //}
  30. _, err := l.svcCtx.DB.Label.Create().
  31. SetNotNilStatus(req.Status).
  32. SetNotNilType(req.Type).
  33. SetNotNilName(req.Name).
  34. SetNotNilFrom(req.From).
  35. SetNotNilMode(req.Mode).
  36. SetNotNilConditions(&conditions).
  37. Save(l.ctx)
  38. if err != nil {
  39. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  40. }
  41. return &types.BaseMsgResp{Msg: errormsg.CreateSuccess}, nil
  42. }