update_server_logic.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package WechatServer
  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 UpdateServerLogic struct {
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. logx.Logger
  14. }
  15. func NewUpdateServerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateServerLogic {
  16. return &UpdateServerLogic{
  17. ctx: ctx,
  18. svcCtx: svcCtx,
  19. Logger: logx.WithContext(ctx),
  20. }
  21. }
  22. func (l *UpdateServerLogic) UpdateServer(req *types.ServerInfo) (*types.BaseMsgResp, error) {
  23. err := l.svcCtx.DB.Server.UpdateOneID(*req.Id).
  24. SetNotNilStatus(req.Status).
  25. SetNotNilName(req.Name).
  26. SetNotNilPublicIP(req.PublicIp).
  27. SetNotNilPrivateIP(req.PrivateIp).
  28. SetNotNilAdminPort(req.AdminPort).
  29. Exec(l.ctx)
  30. if err != nil {
  31. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  32. }
  33. data := map[string]interface{}{
  34. "private_ip": req.PrivateIp,
  35. "admin_port": req.AdminPort,
  36. }
  37. l.svcCtx.Rds.HSet(l.ctx, "server_info", req.Id, data)
  38. l.svcCtx.Rds.Del(l.ctx, "crontask_wx_server_info")
  39. return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
  40. }