create_label_relationship_logic.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package label_relationship
  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 CreateLabelRelationshipLogic struct {
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. logx.Logger
  14. }
  15. func NewCreateLabelRelationshipLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateLabelRelationshipLogic {
  16. return &CreateLabelRelationshipLogic{
  17. ctx: ctx,
  18. svcCtx: svcCtx,
  19. Logger: logx.WithContext(ctx),
  20. }
  21. }
  22. func (l *CreateLabelRelationshipLogic) CreateLabelRelationship(req *types.LabelRelationshipInfo) (*types.BaseMsgResp, error) {
  23. organizationId := l.ctx.Value("organizationId").(uint64)
  24. _, err := l.svcCtx.DB.LabelRelationship.Create().
  25. SetNotNilStatus(req.Status).
  26. SetNotNilLabelID(req.LabelId).
  27. SetNotNilContactID(req.ContactId).
  28. SetOrganizationID(organizationId).
  29. Save(l.ctx)
  30. if err != nil {
  31. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  32. }
  33. return &types.BaseMsgResp{Msg: errormsg.CreateSuccess}, nil
  34. }