123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package garden
- import (
- "context"
- "encoding/json"
- "fmt"
- "git.getensh.com/common/gopkgs/database"
- "git.getensh.com/common/gopkgs/logger"
- "go.uber.org/zap"
- "google.golang.org/grpc/status"
- "property-garden/errors"
- "property-garden/model"
- pb_v1 "property-garden/pb/v1"
- "property-garden/utils"
- )
- func GardenHouseIsIn(ctx context.Context, req *pb_v1.GardenHouseIsInRequest) (reply *pb_v1.GardenHouseIsInReply, err error) {
- reply = &pb_v1.GardenHouseIsInReply{}
- // 捕获各个task中的异常并返回给调用者
- defer func() {
- if r := recover(); r != nil {
- err = fmt.Errorf("%+v", r)
- e := &status.Status{}
- if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
- logger.Error("err",
- zap.String("system_err", err.Error()),
- zap.Stack("stacktrace"))
- }
- }
- }()
- dbname := utils.GetGardenDbName(req.GardenId)
- h := model.NewHouseApprovedGarden(dbname)
- where := map[string]interface{}{}
- count, err := h.Count(database.DB(), where, nil)
- if err != nil {
- return nil, errors.DataBaseError
- }
- if count > 0 {
- reply.In = true
- }
- return reply, nil
- }
|