super_user_update.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package organization
  4. import (
  5. "context"
  6. "cp-system-management/errors"
  7. "cp-system-management/pb"
  8. pb_v1 "cp-system-management/pb/v1"
  9. "encoding/json"
  10. "fmt"
  11. "github.com/jaryhe/gopkgs/logger"
  12. "go.uber.org/zap"
  13. "google.golang.org/grpc/status"
  14. )
  15. //
  16. func OrganizationUserUpdate(ctx context.Context, req *pb_v1.OrganizationUserUpdateRequest) (reply *pb_v1.OrganizationUserUpdateReply, err error) {
  17. reply = &pb_v1.OrganizationUserUpdateReply{}
  18. // 捕获各个task中的异常并返回给调用者
  19. defer func() {
  20. if r := recover(); r != nil {
  21. err = fmt.Errorf("%+v", r)
  22. e := &status.Status{}
  23. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  24. logger.Error("err",
  25. zap.String("system_err", err.Error()),
  26. zap.Stack("stacktrace"))
  27. }
  28. }
  29. }()
  30. if req.Id == 0 || req.OrganizationCode == "" || req.Username == "" {
  31. return nil, errors.ParamsError
  32. }
  33. rReq := &pb_v1.ManagementSuperUserUpdateRequest{
  34. OrganizationCode: req.OrganizationCode,
  35. Email:req.Email,
  36. Id:req.Id,
  37. Phone:req.Phone,
  38. Username:req.Username,
  39. }
  40. mreply, err := pb.Organization.ManagementSuperUserUpdate(ctx, rReq)
  41. if err != nil {
  42. return reply, errors.ServiceError
  43. }
  44. reply.Origin = &pb_v1.OrganizationUserUpdateRequest{
  45. OrganizationCode: mreply.Origin.OrganizationCode,
  46. Username:mreply.Origin.Username,
  47. Phone: mreply.Origin.Phone,
  48. Email:mreply.Origin.Email,
  49. Id:mreply.Origin.Id,
  50. Password:req.Password,
  51. }
  52. return reply, nil
  53. }