update_wx_logic.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package Wx
  2. import (
  3. "context"
  4. "wechat-api/ent/wx"
  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 UpdateWxLogic struct {
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. logx.Logger
  15. }
  16. func NewUpdateWxLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateWxLogic {
  17. return &UpdateWxLogic{
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. Logger: logx.WithContext(ctx),
  21. }
  22. }
  23. func (l *UpdateWxLogic) UpdateWx(req *types.WxInfo) (*types.BaseMsgResp, error) {
  24. organizationId := l.ctx.Value("organizationId").(uint64)
  25. err := l.svcCtx.DB.Wx.UpdateOneID(*req.Id).
  26. Where(wx.OrganizationID(organizationId)).
  27. SetNotNilStatus(req.Status).
  28. SetNotNilServerID(req.ServerId).
  29. SetNotNilPort(req.Port).
  30. SetNotNilProcessID(req.ProcessId).
  31. SetNotNilCallback(req.Callback).
  32. SetNotNilWxid(req.Wxid).
  33. SetNotNilAccount(req.Account).
  34. SetNotNilNickname(req.Nickname).
  35. SetNotNilTel(req.Tel).
  36. SetNotNilHeadBig(req.HeadBig).
  37. SetNotNilAgentID(req.AgentId).
  38. Exec(l.ctx)
  39. if err != nil {
  40. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  41. }
  42. return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
  43. }