update_contact_logic.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. SetNotNilCname(req.Cname).
  44. SetNotNilCarea(req.Carea).
  45. SetNotNilCage(req.Cage).
  46. SetNotNilCbirthday(req.Cbirthday).
  47. SetNotNilCbirtharea(req.Cbirtharea).
  48. SetNotNilCc(req.Cc).
  49. SetNotNilPhone(req.Phone).
  50. SetNotNilCidcardNo(req.CidcardNo).
  51. SetNotNilCtitle(req.Ctitle).
  52. Exec(l.ctx)
  53. if err != nil {
  54. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  55. }
  56. return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
  57. }