forked from free-lancers/electricity_bill_calc_service
fix(park):修复园区不能搜索的问题。
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user