8 changed files with 264 additions and 1 deletions
@ -0,0 +1,28 @@ |
|||
package handler |
|||
|
|||
import ( |
|||
"net/http" |
|||
|
|||
"demo/internal/logic" |
|||
"demo/internal/svc" |
|||
"demo/internal/types" |
|||
"github.com/zeromicro/go-zero/rest/httpx" |
|||
) |
|||
|
|||
func EsProFromJavaSearchDistrictHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
|||
return func(w http.ResponseWriter, r *http.Request) { |
|||
var req types.EsProQueryName |
|||
if err := httpx.Parse(r, &req); err != nil { |
|||
httpx.ErrorCtx(r.Context(), w, err) |
|||
return |
|||
} |
|||
|
|||
l := logic.NewEsProFromJavaSearchDistrictLogic(r.Context(), svcCtx) |
|||
resp, err := l.EsProFromJavaSearchDistrict(&req) |
|||
if err != nil { |
|||
httpx.ErrorCtx(r.Context(), w, err) |
|||
} else { |
|||
httpx.OkJsonCtx(r.Context(), w, resp) |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,132 @@ |
|||
package logic |
|||
|
|||
import ( |
|||
"context" |
|||
"fmt" |
|||
|
|||
"demo/internal/svc" |
|||
"demo/internal/types" |
|||
es "demo/model/es_dev" |
|||
|
|||
"github.com/zeromicro/go-zero/core/logx" |
|||
) |
|||
|
|||
type EsProFromJavaSearchDistrictLogic struct { |
|||
logx.Logger |
|||
ctx context.Context |
|||
svcCtx *svc.ServiceContext |
|||
} |
|||
|
|||
func NewEsProFromJavaSearchDistrictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EsProFromJavaSearchDistrictLogic { |
|||
return &EsProFromJavaSearchDistrictLogic{ |
|||
Logger: logx.WithContext(ctx), |
|||
ctx: ctx, |
|||
svcCtx: svcCtx, |
|||
} |
|||
} |
|||
|
|||
func (l *EsProFromJavaSearchDistrictLogic) EsProFromJavaSearchDistrict(req *types.EsProQueryName) (resp *types.Response, err error) { |
|||
// es 查询语句
|
|||
esQuery := ` |
|||
{ |
|||
"query": { |
|||
"bool":{ |
|||
"must":[ |
|||
{ |
|||
"bool": { |
|||
"must": [ |
|||
{"match": |
|||
{ |
|||
"districtName": "%s" |
|||
} |
|||
}, |
|||
{"term": |
|||
{ |
|||
"districtCode": "%s" |
|||
} |
|||
}, |
|||
{"term": |
|||
{ |
|||
"year": "%s" |
|||
} |
|||
}, |
|||
{"term": |
|||
{ |
|||
"lotType":"%s" |
|||
} |
|||
} |
|||
], |
|||
"must_not": [ |
|||
{ |
|||
"bool": { |
|||
"must":[ |
|||
{ |
|||
"bool": { |
|||
"should":[ |
|||
{"term": |
|||
{ |
|||
"schoolId":"" |
|||
} |
|||
}, |
|||
{"bool": |
|||
{ |
|||
"mustNot": [ |
|||
{ |
|||
"exists": { |
|||
"field": "schoolId" |
|||
} |
|||
} |
|||
] |
|||
} |
|||
} |
|||
] |
|||
} |
|||
}, |
|||
{ |
|||
"bool": { |
|||
"should":[ |
|||
{"term": |
|||
{ |
|||
"schoolName":"" |
|||
} |
|||
}, |
|||
{"bool": |
|||
{ |
|||
"mustNot": [ |
|||
{ |
|||
"exists": { |
|||
"field": "schoolName" |
|||
} |
|||
} |
|||
] |
|||
} |
|||
} |
|||
] |
|||
} |
|||
} |
|||
] |
|||
} |
|||
} |
|||
] |
|||
} |
|||
} |
|||
] |
|||
} |
|||
} |
|||
} |
|||
` |
|||
// es 查询
|
|||
esQueryStr := fmt.Sprintf(esQuery, req.Name, req.Code, req.Year, req.LotType) |
|||
doc, err := es.EsServiceApp.EsSearchDocWithStrAndIndex(l.ctx, esQueryStr, int(req.Page), int(req.Size), "thoroughly_districts_xw") |
|||
|
|||
if err != nil { |
|||
return nil, err |
|||
} |
|||
|
|||
return &types.Response{ |
|||
Success: true, |
|||
Message: "success", |
|||
Result: doc, |
|||
}, nil |
|||
|
|||
} |
Loading…
Reference in new issue