From 4620271fa5439232da93d4d188f00ba3286957e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B6=9B?= Date: Mon, 19 Sep 2022 14:56:12 +0800 Subject: [PATCH] =?UTF-8?q?fix(report):=E5=9F=BA=E6=9C=AC=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E5=85=AC=E7=A4=BA=E6=8A=A5=E8=A1=A8=E6=A3=80=E7=B4=A2?= =?UTF-8?q?=E9=83=A8=E5=88=86=E7=9A=84=E6=9F=A5=E8=AF=A2=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/report.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/service/report.go b/service/report.go index 77370a2..6725192 100644 --- a/service/report.go +++ b/service/report.go @@ -528,9 +528,7 @@ func (_ReportService) SearchReport(requestUser, requestPark, requestKeyword stri reports = make([]model.Report, 0) cond = global.DB.NewSelect(). Model(&reports). - Relation("Park", func(q *bun.SelectQuery) *bun.SelectQuery { - return q.Relation("Enterprise") - }) + Relation("Park").Relation("Park.Enterprise") ) conditions = append(conditions, strconv.Itoa(requestPage)) if onlyPublished { @@ -538,11 +536,11 @@ func (_ReportService) SearchReport(requestUser, requestPark, requestKeyword stri } conditions = append(conditions, strconv.FormatBool(onlyPublished)) if len(requestUser) > 0 { - cond = cond.Where("p.user_id = ?", requestUser) + cond = cond.Where("park.user_id = ?", requestUser) conditions = append(conditions, requestUser) } if len(requestPark) > 0 { - cond = cond.Where("p.id = ?", requestPark) + cond = cond.Where("park.id = ?", requestPark) conditions = append(conditions, requestPark) } if requestPeriod != nil { @@ -552,12 +550,12 @@ func (_ReportService) SearchReport(requestUser, requestPark, requestKeyword stri if len(requestKeyword) > 0 { keywordCond := "%" + requestKeyword + "%" cond = cond.WhereGroup(" and ", func(q *bun.SelectQuery) *bun.SelectQuery { - return q.Where("p.name like ?", keywordCond). - WhereOr("d.name like ?", keywordCond). - WhereOr("d.abbr like ?", keywordCond). - WhereOr("p.abbr like ?", keywordCond). - WhereOr("d.address like ?", keywordCond). - WhereOr("p.address like ?", keywordCond) + return q.Where("park.name like ?", keywordCond). + WhereOr("park__enterprise.name like ?", keywordCond). + WhereOr("park__enterprise.abbr like ?", keywordCond). + WhereOr("park.abbr like ?", keywordCond). + WhereOr("park__enterprise.address like ?", keywordCond). + WhereOr("park.address like ?", keywordCond) }) conditions = append(conditions, requestKeyword) }