house_is_in.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package garden
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "git.getensh.com/common/gopkgs/database"
  7. "git.getensh.com/common/gopkgs/logger"
  8. "go.uber.org/zap"
  9. "google.golang.org/grpc/status"
  10. "property-garden/errors"
  11. "property-garden/model"
  12. pb_v1 "property-garden/pb/v1"
  13. "property-garden/utils"
  14. )
  15. func GardenHouseIsIn(ctx context.Context, req *pb_v1.GardenHouseIsInRequest) (reply *pb_v1.GardenHouseIsInReply, err error) {
  16. reply = &pb_v1.GardenHouseIsInReply{}
  17. // 捕获各个task中的异常并返回给调用者
  18. defer func() {
  19. if r := recover(); r != nil {
  20. err = fmt.Errorf("%+v", r)
  21. e := &status.Status{}
  22. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  23. logger.Error("err",
  24. zap.String("system_err", err.Error()),
  25. zap.Stack("stacktrace"))
  26. }
  27. }
  28. }()
  29. dbname := utils.GetGardenDbName(req.GardenId)
  30. h := model.NewHouseApprovedGarden(dbname)
  31. where := map[string]interface{}{}
  32. count, err := h.Count(database.DB(), where, nil)
  33. if err != nil {
  34. return nil, errors.DataBaseError
  35. }
  36. if count > 0 {
  37. reply.In = true
  38. }
  39. return reply, nil
  40. }