create_label_logic.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. organizationId := l.ctx.Value("organizationId").(uint64)
  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. SetOrganizationID(organizationId).
  38. Save(l.ctx)
  39. if err != nil {
  40. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  41. }
  42. return &types.BaseMsgResp{Msg: errormsg.CreateSuccess}, nil
  43. }