update_contact_logic.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package contact
  2. import (
  3. "context"
  4. "wechat-api/ent/contact"
  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/zeromicro/go-zero/core/logx"
  10. )
  11. type UpdateContactLogic struct {
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. logx.Logger
  15. }
  16. func NewUpdateContactLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateContactLogic {
  17. return &UpdateContactLogic{
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. Logger: logx.WithContext(ctx),
  21. }
  22. }
  23. func (l *UpdateContactLogic) UpdateContact(req *types.ContactInfo) (*types.BaseMsgResp, error) {
  24. organizationId := l.ctx.Value("organizationId").(uint64)
  25. err := l.svcCtx.DB.Contact.UpdateOneID(*req.Id).
  26. Where(contact.OrganizationID(organizationId)).
  27. SetNotNilStatus(req.Status).
  28. SetNotNilWxWxid(req.WxWxid).
  29. SetNotNilType(req.Type).
  30. SetNotNilWxid(req.Wxid).
  31. SetNotNilAccount(req.Account).
  32. SetNotNilNickname(req.Nickname).
  33. SetNotNilMarkname(req.Markname).
  34. SetNotNilHeadimg(req.Headimg).
  35. SetNotNilSex(req.Sex).
  36. SetNotNilStarrole(req.Starrole).
  37. SetNotNilDontseeit(req.Dontseeit).
  38. SetNotNilDontseeme(req.Dontseeme).
  39. SetNotNilLag(req.Lag).
  40. SetNotNilGid(req.Gid).
  41. SetNotNilGname(req.Gname).
  42. SetNotNilV3(req.V3).
  43. Exec(l.ctx)
  44. if err != nil {
  45. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  46. }
  47. return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
  48. }