|
@@ -1,6 +1,7 @@
|
|
|
package service
|
|
|
|
|
|
import (
|
|
|
+ quitl "app.yhyue.com/moapp/jybase/common"
|
|
|
elastic "app.yhyue.com/moapp/jybase/esv1"
|
|
|
"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/entity"
|
|
|
"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/medical"
|
|
@@ -24,17 +25,34 @@ func (b InstitutionService) GetFilterItem() (levelList, typeList *[]map[string]i
|
|
|
func (b InstitutionService) Institution(in *medical.SearchInstitutionReq) (dataList []map[string]interface{}) {
|
|
|
//先查询医疗机构
|
|
|
//医疗机构查询拼接
|
|
|
- query := `{"query":{"bool":{"must":[%s],"minimum_should_match": %d}}, "from": %d,"size": %d}`
|
|
|
+ query := `{"query":{"bool":{"must":[%s],"must_not": [%s],"should":[%s],"minimum_should_match": %d}}, "from": %d,"size": %d}`
|
|
|
+ shouldQuery := `{"bool":{"should":[%s],"minimum_should_match": %d}}`
|
|
|
+ multi_match := `{"multi_match": {"query": %s,"type": "phrase", "fields": [%s]}}`
|
|
|
musts := []string{}
|
|
|
+ shoulds := []string{}
|
|
|
//省份处理
|
|
|
+ cityArr := []string{}
|
|
|
+ areaArr := []string{}
|
|
|
if in.AreaCode != "" {
|
|
|
- areaQuery := entity.SplicingString("area", in.AreaCode)
|
|
|
- musts = append(musts, areaQuery)
|
|
|
+ areaCode := quitl.ObjToMap(in.AreaCode)
|
|
|
+ for k, v := range *areaCode {
|
|
|
+ if len(quitl.ObjArrToStringArr(v.([]interface{}))) == 0 {
|
|
|
+ areaArr = append(areaArr, k)
|
|
|
+ } else {
|
|
|
+ cityArr = append(cityArr, quitl.ObjArrToStringArr(v.([]interface{}))...)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //省份处理
|
|
|
+ if len(areaArr) > 0 {
|
|
|
+ areaQuery := entity.SplicingArr("area", areaArr)
|
|
|
+ shoulds = append(shoulds, areaQuery)
|
|
|
}
|
|
|
//城市处理
|
|
|
- if in.CityCode != "" {
|
|
|
- cityQuery := entity.SplicingString("city", in.CityCode)
|
|
|
- musts = append(musts, cityQuery)
|
|
|
+ if len(cityArr) > 0 {
|
|
|
+ cityQuery := entity.SplicingArr("city", cityArr)
|
|
|
+ shoulds = append(shoulds, cityQuery)
|
|
|
}
|
|
|
//医疗等级处理
|
|
|
if in.LevelCode != "" {
|
|
@@ -57,11 +75,42 @@ func (b InstitutionService) Institution(in *medical.SearchInstitutionReq) (dataL
|
|
|
musts = append(musts, companyNameQuery)
|
|
|
}
|
|
|
//业务范围处理
|
|
|
- if in.SdequipmentCode != "" {
|
|
|
- sdequipmentQuery := entity.SplicingString("sdequipment", in.SdequipmentCode)
|
|
|
- musts = append(musts, sdequipmentQuery)
|
|
|
+ boolsNum := 0
|
|
|
+ businessShoulds := []string{}
|
|
|
+ businessMust_not := []string{}
|
|
|
+ if len(in.SdequipmentCode) > 0 {
|
|
|
+ boolsNum = 1
|
|
|
+ findfields := `"sdequipment"`
|
|
|
+ multi_match = fmt.Sprintf(multi_match, "%s", findfields)
|
|
|
+ for _, v := range in.SdequipmentCode {
|
|
|
+ //关键词
|
|
|
+ for _, keyV := range v.Key {
|
|
|
+ businessShoulds = append(businessShoulds, fmt.Sprintf(multi_match, "\""+keyV+"\""))
|
|
|
+ }
|
|
|
+ //附加词
|
|
|
+ for _, AppendV := range v.Appendkey {
|
|
|
+ businessShoulds = append(businessShoulds, fmt.Sprintf(multi_match, "\""+AppendV+"\""))
|
|
|
+ }
|
|
|
+ //排除词
|
|
|
+ for _, notV := range v.Notkey {
|
|
|
+ businessMust_not = append(businessMust_not, fmt.Sprintf(multi_match, "\""+notV+"\""))
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- queryStr := fmt.Sprintf(query, strings.Join(musts, ","), len(musts), 0, 500)
|
|
|
+ shouldNumber := 0
|
|
|
+ if len(shoulds) > 0 {
|
|
|
+ shouldNumber = 1
|
|
|
+ }
|
|
|
+ shouldStr := fmt.Sprintf(shouldQuery, strings.Join(shoulds, ","), shouldNumber)
|
|
|
+ musts = append(musts, shouldStr)
|
|
|
+ //添加
|
|
|
+ notStr := ""
|
|
|
+ if len(businessShoulds) > 0 {
|
|
|
+ if len(businessMust_not) > 0 {
|
|
|
+ notStr = fmt.Sprintf(`,"must_not":[%s]`, strings.Join(businessMust_not, ","))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ queryStr := fmt.Sprintf(query, strings.Join(musts, ","), notStr, strings.Join(businessShoulds, ","), boolsNum, 0, 500)
|
|
|
//再根据医疗机构名称查找项目金额总数
|
|
|
companyList := elastic.Get(entity.INSTITUTION_INDEX, entity.INSTITUTION_TYPE, queryStr)
|
|
|
log.Println(queryStr)
|
|
@@ -79,25 +128,13 @@ func (b InstitutionService) Institution(in *medical.SearchInstitutionReq) (dataL
|
|
|
return
|
|
|
}
|
|
|
orderField := "_count"
|
|
|
- orderType := "asc"
|
|
|
+ orderType := "desc"
|
|
|
//排序处理
|
|
|
- if in.CountOrder != 0 {
|
|
|
- orderField = "_count"
|
|
|
- if in.CountOrder == 1 {
|
|
|
- orderType = "desc"
|
|
|
- } else {
|
|
|
- orderType = "asc"
|
|
|
- }
|
|
|
+ if in.Sort == 1 {
|
|
|
+ orderField = "count"
|
|
|
}
|
|
|
- if in.MoneyOrder != 0 {
|
|
|
- orderField = "_count"
|
|
|
- if in.CountOrder == 1 {
|
|
|
- orderType = "desc"
|
|
|
- } else {
|
|
|
- orderType = "asc"
|
|
|
- }
|
|
|
- }
|
|
|
- aggStr := fmt.Sprintf(`{"query":{"bool":{"must":[{"terms":{"buyer":[%s]}},{"terms":{"bidstatus":["中标","成交","合同"]}}],"minimum_should_match":2}},"aggs":{"group_field":{"terms":{"field":"buyer","order":[{"%s":"%s"}]},"aggs":{"count":{"sum":{"field":"bidamount"}}}}},"size":0}`, companyName, orderField, orderType)
|
|
|
+
|
|
|
+ aggStr := fmt.Sprintf(`{"query":{"bool":{"must":[{"terms":{"buyer":[%s]}},{"terms":{"bidstatus":["中标","成交","合同"]}},{"term":{"bid_field":"%s"}}],"minimum_should_match":0}},"aggs":{"group_field":{"terms":{"field":"buyer","order":[{"%s":"%s"}]},"aggs":{"count":{"sum":{"field":"bidamount"}}}}},"size":0}`, companyName, entity.BIDFIELD, orderField, orderType)
|
|
|
log.Println(aggStr)
|
|
|
countList := entity.GetAggs(entity.PROJECTSET_INDEX, entity.PROJECTSET_TYPE, aggStr)
|
|
|
if len(countList) > 0 && countList != nil {
|
|
@@ -118,22 +155,61 @@ func (b InstitutionService) Institution(in *medical.SearchInstitutionReq) (dataL
|
|
|
func (b InstitutionService) Distributor(in *medical.SearchDistributorReq) (dataList []map[string]interface{}) {
|
|
|
//先查询医疗机构
|
|
|
//医疗机构查询拼接
|
|
|
- query := `{"query":{"bool":{"must":[%s],"minimum_should_match": %d}}, "from": %d,"size": %d}`
|
|
|
+ query := `{"query":{"bool":{"must":[%s],"must_not": [%s],"should":[%s],"minimum_should_match": %d}}, "from": %d,"size": %d}`
|
|
|
+ shouldQuery := `{"bool":{"should":[%s],"minimum_should_match": %d}}`
|
|
|
+ multi_match := `{"multi_match": {"query": %s,"type": "phrase", "fields": [%s]}}`
|
|
|
musts := []string{}
|
|
|
+ shoulds := []string{}
|
|
|
//省份处理
|
|
|
+ cityArr := []string{}
|
|
|
+ areaArr := []string{}
|
|
|
if in.AreaCode != "" {
|
|
|
- areaQuery := entity.SplicingString("area", in.AreaCode)
|
|
|
- musts = append(musts, areaQuery)
|
|
|
+ areaCode := quitl.ObjToMap(in.AreaCode)
|
|
|
+ for k, v := range *areaCode {
|
|
|
+ if len(quitl.ObjArrToStringArr(v.([]interface{}))) == 0 {
|
|
|
+ areaArr = append(areaArr, k)
|
|
|
+ } else {
|
|
|
+ cityArr = append(cityArr, quitl.ObjArrToStringArr(v.([]interface{}))...)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //省份处理
|
|
|
+ if len(areaArr) > 0 {
|
|
|
+ areaQuery := entity.SplicingArr("area", areaArr)
|
|
|
+ shoulds = append(shoulds, areaQuery)
|
|
|
}
|
|
|
//城市处理
|
|
|
- if in.CityCode != "" {
|
|
|
- cityQuery := entity.SplicingString("city", in.CityCode)
|
|
|
- musts = append(musts, cityQuery)
|
|
|
+ if len(cityArr) > 0 {
|
|
|
+ cityQuery := entity.SplicingArr("city", cityArr)
|
|
|
+ shoulds = append(shoulds, cityQuery)
|
|
|
}
|
|
|
//业务范围处理
|
|
|
- if in.BusinessScope != "" {
|
|
|
+ /* if in.BusinessScope != "" {
|
|
|
businessScopeQuery := entity.SplicingString("productlist.name", in.BusinessScope)
|
|
|
musts = append(musts, businessScopeQuery)
|
|
|
+ }*/
|
|
|
+ boolsNum := 0
|
|
|
+ businessShoulds := []string{}
|
|
|
+ businessMust_not := []string{}
|
|
|
+ if len(in.BusinessScope) > 0 {
|
|
|
+ boolsNum = 1
|
|
|
+ findfields := `"productlist.name"`
|
|
|
+ multi_match = fmt.Sprintf(multi_match, "%s", findfields)
|
|
|
+ for _, v := range in.BusinessScope {
|
|
|
+ //关键词
|
|
|
+ for _, keyV := range v.Key {
|
|
|
+ businessShoulds = append(businessShoulds, fmt.Sprintf(multi_match, "\""+keyV+"\""))
|
|
|
+ }
|
|
|
+ //附加词
|
|
|
+ for _, AppendV := range v.Appendkey {
|
|
|
+ businessShoulds = append(businessShoulds, fmt.Sprintf(multi_match, "\""+AppendV+"\""))
|
|
|
+ }
|
|
|
+ //排除词
|
|
|
+ for _, notV := range v.Notkey {
|
|
|
+ businessMust_not = append(businessMust_not, fmt.Sprintf(multi_match, "\""+notV+"\""))
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
//品牌处理
|
|
|
if in.Brand != "" {
|
|
@@ -150,7 +226,20 @@ func (b InstitutionService) Distributor(in *medical.SearchDistributorReq) (dataL
|
|
|
companyNameQuery := entity.SplicingString("p_supplier", in.CompanyName)
|
|
|
musts = append(musts, companyNameQuery)
|
|
|
}
|
|
|
- queryStr := fmt.Sprintf(query, strings.Join(musts, ","), len(musts), 0, 500)
|
|
|
+ shouldNumber := 0
|
|
|
+ if len(shoulds) > 0 {
|
|
|
+ shouldNumber = 1
|
|
|
+ }
|
|
|
+ shouldStr := fmt.Sprintf(shouldQuery, strings.Join(shoulds, ","), shouldNumber)
|
|
|
+ musts = append(musts, shouldStr)
|
|
|
+ //添加
|
|
|
+ notStr := ""
|
|
|
+ if len(businessShoulds) > 0 {
|
|
|
+ if len(businessMust_not) > 0 {
|
|
|
+ notStr = fmt.Sprintf(`,"must_not":[%s]`, strings.Join(businessMust_not, ","))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ queryStr := fmt.Sprintf(query, strings.Join(musts, ","), notStr, strings.Join(businessShoulds, ","), boolsNum, 0, 500)
|
|
|
//再根据医疗机构名称查找项目金额总数
|
|
|
companyList := elastic.Get(entity.SUPPLIER_PRODUCT_INDEX, entity.SUPPLIER_PRODUCT_TYPE, queryStr)
|
|
|
log.Println(queryStr)
|
|
@@ -167,26 +256,13 @@ func (b InstitutionService) Distributor(in *medical.SearchDistributorReq) (dataL
|
|
|
} else {
|
|
|
return
|
|
|
}
|
|
|
- orderField := "_count"
|
|
|
- orderType := "asc"
|
|
|
//排序处理
|
|
|
- if in.CountOrder != 0 {
|
|
|
- orderField = "_count"
|
|
|
- if in.CountOrder == 1 {
|
|
|
- orderType = "desc"
|
|
|
- } else {
|
|
|
- orderType = "asc"
|
|
|
- }
|
|
|
- }
|
|
|
- if in.MoneyOrder != 0 {
|
|
|
- orderField = "_count"
|
|
|
- if in.CountOrder == 1 {
|
|
|
- orderType = "desc"
|
|
|
- } else {
|
|
|
- orderType = "asc"
|
|
|
- }
|
|
|
+ orderField := "_count"
|
|
|
+ orderType := "desc"
|
|
|
+ if in.Sort == 1 {
|
|
|
+ orderField = "count"
|
|
|
}
|
|
|
- aggStr := fmt.Sprintf(`{"query":{"bool":{"must":[{"terms":{"entidlist":[%s]}},{"terms":{"bidstatus":["中标","成交","合同"]}}],"minimum_should_match":2}},"aggs":{"group_field":{"terms":{"field":"entidlist","order":[{"%s":"%s"}]},"aggs":{"count":{"sum":{"field":"bidamount"}}}}},"size":0}`, companyIds, orderField, orderType)
|
|
|
+ aggStr := fmt.Sprintf(`{"query":{"bool":{"must":[{"terms":{"entidlist":[%s]}},{"terms":{"bidstatus":["中标","成交","合同"]}},{"term":{"bid_field":"%s"}}],"minimum_should_match":0}},"aggs":{"group_field":{"terms":{"field":"entidlist","order":[{"%s":"%s"}]},"aggs":{"count":{"sum":{"field":"bidamount"}}}}},"size":0}`, companyIds, entity.BIDFIELD, orderField, orderType)
|
|
|
log.Println(aggStr)
|
|
|
countList := entity.GetAggs(entity.PROJECTSET_INDEX, entity.PROJECTSET_TYPE, aggStr)
|
|
|
if len(countList) > 0 && countList != nil {
|