mch_id.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package company
  4. import (
  5. "context"
  6. "encoding/json"
  7. "fmt"
  8. "git.getensh.com/common/gopkgs/database"
  9. "git.getensh.com/common/gopkgs/logger"
  10. "go.uber.org/zap"
  11. "google.golang.org/grpc/status"
  12. "gorm.io/gorm"
  13. "property-company/errors"
  14. dbmodel "property-company/model"
  15. pb_v1 "property-company/pb/v1"
  16. )
  17. //
  18. func CompanyMchIdSet(ctx context.Context, req *pb_v1.CompanyMchIdSetRequest) (reply *pb_v1.CompanyMchIdSetReply, err error) {
  19. // 捕获各个task中的异常并返回给调用者
  20. defer func() {
  21. if r := recover(); r != nil {
  22. err = fmt.Errorf("%+v", r)
  23. e := &status.Status{}
  24. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  25. logger.Error("err",
  26. zap.String("system_err", err.Error()),
  27. zap.Stack("stacktrace"))
  28. }
  29. }
  30. }()
  31. if req.Cid < 1 {
  32. return nil, errors.ParamsError
  33. }
  34. p := dbmodel.TCompany{}
  35. where := map[string]interface{}{
  36. "id":req.Cid,
  37. }
  38. err = p.Find(database.DB(), where)
  39. if err != nil && err != gorm.ErrRecordNotFound {
  40. return nil, errors.DataBaseError
  41. }
  42. if p.ID == 0 {
  43. return nil, errors.ErrRecordNotFound
  44. }
  45. values := map[string]interface{}{
  46. "mch_id":req.MchId,
  47. }
  48. err = p.Update(database.DB(), where, values)
  49. if err != nil {
  50. return nil, errors.DataBaseError
  51. }
  52. reply = &pb_v1.CompanyMchIdSetReply{}
  53. return reply, nil
  54. }