fix(park):修复园区不能搜索的问题。

This commit is contained in:
徐涛
2022-09-06 15:28:27 +08:00
parent 954285e426
commit 8aa4e38760
2 changed files with 18 additions and 6 deletions

View File

@@ -73,19 +73,29 @@ func (_ParkService) DeletePark(uid, pid string) error {
return nil
}
func (_ParkService) ListAllParkBelongsTo(uid string) ([]model.Park, error) {
if parks, _ := cache.RetreiveSearch[[]model.Park]("park", "belong", uid); parks != nil {
func (_ParkService) ListAllParkBelongsTo(uid, keyword string) ([]model.Park, error) {
if parks, _ := cache.RetreiveSearch[[]model.Park]("park", "belong", uid, keyword); parks != nil {
return *parks, nil
}
cond := builder.NewCond().And(builder.Eq{"user_id": uid})
if len(keyword) > 0 {
cond = cond.And(
builder.Like{"name", keyword}.
Or(builder.Like{"abbr", keyword}).
Or(builder.Like{"address", keyword}).
Or(builder.Like{"contact", keyword}).
Or(builder.Like{"phone", keyword}),
)
}
parks := make([]model.Park, 0)
err := global.DBConn.
Where(builder.Eq{"user_id": uid}).
Where(cond).
NoAutoCondition().
Find(&parks)
if err != nil {
return make([]model.Park, 0), err
}
cache.CacheSearch(parks, []string{"park"}, "park", "belong", uid)
cache.CacheSearch(parks, []string{"park"}, "park", "belong", uid, keyword)
return parks, nil
}