create_contact_logic.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package contact
  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 CreateContactLogic struct {
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. logx.Logger
  14. }
  15. func NewCreateContactLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateContactLogic {
  16. return &CreateContactLogic{
  17. ctx: ctx,
  18. svcCtx: svcCtx,
  19. Logger: logx.WithContext(ctx),
  20. }
  21. }
  22. func (l *CreateContactLogic) CreateContact(req *types.ContactInfo) (*types.BaseMsgResp, error) {
  23. organizationId := l.ctx.Value("organizationId").(uint64)
  24. _, err := l.svcCtx.DB.Contact.Create().
  25. SetNotNilStatus(req.Status).
  26. SetNotNilWxWxid(req.WxWxid).
  27. SetNotNilType(req.Type).
  28. SetNotNilWxid(req.Wxid).
  29. SetNotNilAccount(req.Account).
  30. SetNotNilNickname(req.Nickname).
  31. SetNotNilMarkname(req.Markname).
  32. SetNotNilHeadimg(req.Headimg).
  33. SetNotNilSex(req.Sex).
  34. SetNotNilStarrole(req.Starrole).
  35. SetNotNilDontseeit(req.Dontseeit).
  36. SetNotNilDontseeme(req.Dontseeme).
  37. SetNotNilLag(req.Lag).
  38. SetNotNilGid(req.Gid).
  39. SetNotNilGname(req.Gname).
  40. SetNotNilV3(req.V3).
  41. SetOrganizationID(organizationId).
  42. Save(l.ctx)
  43. if err != nil {
  44. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  45. }
  46. return &types.BaseMsgResp{Msg: errormsg.CreateSuccess}, nil
  47. }