From 2d17bd5f0d635085e185a1b9697ac0de058fae65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B6=9B?= Date: Thu, 8 Jun 2023 22:23:56 +0800 Subject: [PATCH] =?UTF-8?q?fix(park):=E4=BF=AE=E6=AD=A3=E5=9B=AD=E5=8C=BA?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=A3=80=E7=B4=A2=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/park.go | 4 ++-- repository/park.go | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/controller/park.go b/controller/park.go index 0415709..68f27c2 100644 --- a/controller/park.go +++ b/controller/park.go @@ -57,7 +57,7 @@ func listParksBelongsToCurrentUser(c *fiber.Ctx) error { return result.Unauthorized(err.Error()) } parkLog.Info("列出当前用户下的全部园区", zap.String("user id", session.Uid)) - parks, err := repository.ParkRepository.RetrieveParkbelongs(session.Uid) + parks, err := repository.ParkRepository.ListAllParks(session.Uid) if err != nil { parkLog.Error("无法获取园区列表。", zap.String("user id", session.Uid)) return result.Error(http.StatusInternalServerError, err.Error()) @@ -70,7 +70,7 @@ func listParksBelongsTo(c *fiber.Ctx) error { result := response.NewResult(c) userId := c.Params("userId") parkLog.Info("列出指定用户下的全部园区", zap.String("user id", userId)) - parks, err := repository.ParkRepository.RetrieveParkbelongs(userId) + parks, err := repository.ParkRepository.RetrieveParkBelongs(userId) if err != nil { parkLog.Error("无法获取园区列表。", zap.String("user id", userId)) return result.Error(http.StatusInternalServerError, err.Error()) diff --git a/repository/park.go b/repository/park.go index 03f7f4a..0e83697 100644 --- a/repository/park.go +++ b/repository/park.go @@ -40,9 +40,15 @@ func (pr _ParkRepository) ListAllParks(uid string) ([]*model.Park, error) { ctx, cancel := global.TimeoutContext() defer cancel() - var parks []*model.Park + var parks = make([]*model.Park, 0) parkQuerySql, parkParams, _ := pr.ds. From("park"). + Select( + "id", "user_id", "name", "area", "tenement_quantity", "capacity", "category", + "meter_04kv_type", "region", "address", "contact", "phone", "enabled", "price_policy", "tax_rate", + "basic_pooled", "adjust_pooled", "loss_pooled", "public_pooled", "created_at", "last_modified_at", + "deleted_at", + ). Where( goqu.I("user_id").Eq(uid), goqu.I("deleted_at").IsNull(), @@ -160,7 +166,7 @@ func (pr _ParkRepository) RetrieveParkDetail(pid string) (*model.Park, error) { } // 获取园区对应的用户ID -func (pr _ParkRepository) RetrieveParkbelongs(pid string) (string, error) { +func (pr _ParkRepository) RetrieveParkBelongs(pid string) (string, error) { pr.log.Info("获取园区对应的用户ID", zap.String("pid", pid)) if uid, err := cache.RetrieveEntity[string]("park_belongs", pid); err == nil && uid != nil { pr.log.Info("已经从缓存获取到了园区对应的用户ID。")