瀏覽代碼

业务范围精准查询修改

WH01243 2 年之前
父節點
當前提交
ae4e64ab9f

+ 3 - 0
rpc/medical/etc/medical.yaml

@@ -45,3 +45,6 @@ Mongo:
     dbName: qfw
     size: 50
     address: 192.168.3.206:27080
+DefaultIinstitution: "武汉市中心医院,甘肃省人民医院,荆州市第一人民医院,衡阳市中心医院,四川省骨科医院,佛山市中医院,德州市人民医院,丽水市中心医院,邯郸市中心医院,佛山市妇幼保健院"
+DefaultDistributor: "国网信息通信产业集团有限公司,分众传媒信息技术股份有限公司,东方财富信息股份有限公司,联通信息导航有限公司,上海阑途信息技术有限公司,中国科学院空天信息创新研究院,江苏省广电有线信息网络股份有限公司,网神信息技术(北京)股份有限公司,中国电子科技网络信息安全有限公司,中国信息通信研究院"
+DefaultDistributor1: "上海宝信软件股份有限公司,北京嘉和美康信息技术有限公司,中电科信息产业有限公司,浙江和仁科技股份有限公司,福建顶点软件股份有限公司,泰豪软件股份有限公司,双翊科技有限公司,成都索贝数码科技股份有限公司,武汉中地数码科技有限公司,浙江创联信息技术股份有限公司,武汉荣御信息技术有限公司,云南智讯达科技开发有限公司,上海帕科信息科技有限公司,南京苏迪科技有限公司,杭州中房信息科技有限公司,山东弘盛信息科技有限公司,深圳市雅码科技有限公司,内蒙古新联信息产业有限公司,北京数慧时空信息技术有限公司,北京惠泽智信科技有限公司,南京南软科技有限公司"

+ 2 - 0
rpc/medical/internal/config/config.go

@@ -19,4 +19,6 @@ type Config struct {
 	Mongo              struct {
 		Main *entity.MongoStruct
 	}
+	DefaultIinstitution string
+	DefaultDistributor  string
 }

+ 4 - 2
rpc/medical/internal/logic/distributorlogic.go

@@ -32,8 +32,10 @@ func NewDistributorLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Distr
 func (l *DistributorLogic) Distributor(in *medical.SearchDistributorReq) (*medical.CompanyResp, error) {
 	// todo: add your logic here and delete this line
 	m := service.InstitutionService{
-		Bidfield:   IC.C.Bidfield,
-		BasesqlCon: entity.BaseMysql,
+		Bidfield:            IC.C.Bidfield,
+		BasesqlCon:          entity.BaseMysql,
+		DefaultIinstitution: IC.C.DefaultIinstitution,
+		DefaultDistributor:  IC.C.DefaultDistributor,
 	}
 	dataList := m.Distributor(in)
 	result := &medical.CompanyResp{}

+ 4 - 2
rpc/medical/internal/logic/institutionlogic.go

@@ -32,8 +32,10 @@ func NewInstitutionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Insti
 // 搜索医疗机构
 func (l *InstitutionLogic) Institution(in *medical.SearchInstitutionReq) (*medical.CompanyResp, error) {
 	m := service.InstitutionService{
-		Bidfield:   IC.C.Bidfield,
-		BasesqlCon: entity.BaseMysql,
+		Bidfield:            IC.C.Bidfield,
+		BasesqlCon:          entity.BaseMysql,
+		DefaultIinstitution: IC.C.DefaultIinstitution,
+		DefaultDistributor:  IC.C.DefaultDistributor,
 	}
 	dataList := m.Institution(in)
 	result := &medical.CompanyResp{}

+ 333 - 304
service/InstitutionService.go

@@ -1,262 +1,291 @@
 package service
 
 import (
-	quitl "app.yhyue.com/moapp/jybase/common"
-	elastic "app.yhyue.com/moapp/jybase/esv1"
-	"app.yhyue.com/moapp/jybase/mysql"
-	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/entity"
-	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/medical"
-	"fmt"
-	"log"
-	"strings"
+    quitl "app.yhyue.com/moapp/jybase/common"
+    elastic "app.yhyue.com/moapp/jybase/esv1"
+    "app.yhyue.com/moapp/jybase/mysql"
+    "bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/entity"
+    "bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/medical"
+    "fmt"
+    "log"
+    "strings"
 )
 
 type InstitutionService struct {
-	Bidfield   string
-	BasesqlCon *mysql.Mysql
-	MysqlConn  *mysql.Mysql
+    Bidfield            string
+    BasesqlCon          *mysql.Mysql
+    MysqlConn           *mysql.Mysql
+    DefaultIinstitution string
+    DefaultDistributor  string
 }
 
 // GetFilterItem 医疗机构搜索条件
 func (b InstitutionService) GetFilterItem() (levelList, typeList *[]map[string]interface{}) {
-	//机构类型
-	levelSql := fmt.Sprintf("select  * from %s where  name!='%s'", entity.CODE_MEDICAL_INSTITUTION_LEVEL, "其它")
-	levelList = b.MysqlConn.SelectBySql(levelSql)
-	//医院等级
-	typeSql := fmt.Sprintf("select  * from %s where  name!='%s' and  level=1", entity.CODE_MEDICAL_INSTITUTION_TYPE, "其它")
-	typeList = b.MysqlConn.SelectBySql(typeSql)
-	return
+    //机构类型
+    levelSql := fmt.Sprintf("select  * from %s where  name!='%s'", entity.CODE_MEDICAL_INSTITUTION_LEVEL, "其它")
+    levelList = b.MysqlConn.SelectBySql(levelSql)
+    //医院等级
+    typeSql := fmt.Sprintf("select  * from %s where  name!='%s' and  level=1", entity.CODE_MEDICAL_INSTITUTION_TYPE, "其它")
+    typeList = b.MysqlConn.SelectBySql(typeSql)
+    return
 }
 
 // Institution 医疗机构搜索条件
 func (b InstitutionService) Institution(in *medical.SearchInstitutionReq) (dataList []map[string]interface{}) {
-	//先查询医疗机构
-	//医疗机构查询拼接
-	query := `{"query":{"bool":{"must":[%s],"must_not": [{"term": {"p_miname": ""}}],"should":[%s],"minimum_should_match": %d}},"sort":{"id":{"order":"desc"}}, "from": %d,"size": %d}`
-	shouldQuery := `{"bool":{"should":[%s],"minimum_should_match": %d}}`
-	multi_match := `{"multi_match": {"query": %s,"type": "phrase", "fields": [%s]}}`
-	musts := []string{}
-	var query_bool_must_and = `{"bool": {"must": [%s]%s}}`
-	shoulds := []string{}
-	bools := []string{}
-	//省份处理
-	cityArr := []string{}
-	areaArr := []string{}
-	if in.AreaCode != "" {
-		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{}))...)
-			}
-		}
-	}
+    //先查询医疗机构
+    //医疗机构查询拼接
+    query := `{"query":{"bool":{"must":[%s],"must_not": [{"term": {"p_miname": ""}}],"should":[%s],"minimum_should_match": %d}},"sort":{"id":{"order":"desc"}}, "from": %d,"size": %d}`
+    shouldQuery := `{"bool":{"should":[%s],"minimum_should_match": %d}}`
+    multi_match := `{"multi_match": {"query": %s,"type": "phrase", "fields": [%s]}}`
+    musts := []string{}
+    var query_bool_must_and = `{"bool": {"must": [%s]%s}}`
+    shoulds := []string{}
+    bools := []string{}
+    //省份处理
+    cityArr := []string{}
+    areaArr := []string{}
+    fool := true
+    if in.AreaCode != "" {
+        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 len(cityArr) > 0 {
-		cityQuery := entity.SplicingArr("city", cityArr)
-		shoulds = append(shoulds, cityQuery)
-	}
-	//医疗等级处理
-	if in.LevelCode != "" {
-		levelQuery := entity.SplicingString("level_code", in.LevelCode)
-		musts = append(musts, levelQuery)
-	}
-	//机构类型处理
-	if in.MiTypeCode != "" {
-		miTyprQuery := entity.SplicingString("mi_type_code", in.MiTypeCode)
-		musts = append(musts, miTyprQuery)
-	}
-	//经营性质处理
-	if in.BusinessTypeCode != "" {
-		businessTypeQuery := entity.SplicingString("business_type", in.BusinessTypeCode)
-		musts = append(musts, businessTypeQuery)
-	}
-	//机构名称处理
-	if in.CompanyName != "" {
-		/*companyNameQuery := entity.SplicingString("p_miname", in.CompanyName)
-		  musts = append(musts, companyNameQuery)*/
-		musts = append(musts, fmt.Sprintf(multi_match, "\""+in.CompanyName+"\"", "\"p_miname\""))
-	}
-	//业务范围处理
-	boolsNum, bools := BusinessScopehandle(in.SdequipmentCode, multi_match, `"sdequipment"`, query_bool_must_and, bools)
-	shouldNumber := 0
-	if len(shoulds) > 0 {
-		shouldNumber = 1
-	}
-	shouldStr := fmt.Sprintf(shouldQuery, strings.Join(shoulds, ","), shouldNumber)
-	musts = append(musts, shouldStr)
-	queryStr := fmt.Sprintf(query, strings.Join(musts, ","), strings.Join(bools, ","), boolsNum, 0, in.ResourceUseCount)
-	//医疗机构查找
-	companyList := elastic.Get(entity.INSTITUTION_INDEX, entity.INSTITUTION_TYPE, queryStr)
-	log.Println(queryStr)
-	//再根据医疗机构名称查找项目金额总数
-	companyName := ""
-	companyMap := make(map[string]map[string]interface{})
-	if len(*companyList) > 0 && companyList != nil {
-		//认领数据查询
-		companyIdMap := b.ClaimCompanyData(in.Appid, in.NewUserId, entity.TypeInstitution)
-		for key, value := range *companyList {
-			if key > 0 {
-				companyName += `,`
-			}
-			companyName += `"` + fmt.Sprint(value["mi_name"]) + `"`
-			value["project_money"] = float64(0.00)
-			value["project_count"] = 0
-			if companyIdMap[fmt.Sprint(value["company_id"])] == nil {
-				value["isClaim"] = false
-			} else {
-				value["isClaim"] = true
-			}
-			companyMap[fmt.Sprint(value["mi_name"])] = value
-		}
+    //省份处理
+    if len(areaArr) > 0 {
+        fool = false
+        areaQuery := entity.SplicingArr("area", areaArr)
+        shoulds = append(shoulds, areaQuery)
+    }
+    //城市处理
+    if len(cityArr) > 0 {
+        fool = false
+        cityQuery := entity.SplicingArr("city", cityArr)
+        shoulds = append(shoulds, cityQuery)
+    }
+    //医疗等级处理
+    if in.LevelCode != "" {
+        fool = false
+        levelQuery := entity.SplicingString("level_code", in.LevelCode)
+        musts = append(musts, levelQuery)
+    }
+    //机构类型处理
+    if in.MiTypeCode != "" {
+        fool = false
+        miTyprQuery := entity.SplicingString("mi_type_code", in.MiTypeCode)
+        musts = append(musts, miTyprQuery)
+    }
+    //经营性质处理
+    if in.BusinessTypeCode != "" {
+        fool = false
+        businessTypeQuery := entity.SplicingString("business_type", in.BusinessTypeCode)
+        musts = append(musts, businessTypeQuery)
+    }
 
-	} else {
-		return
-	}
-	orderField := "_count"
-	orderType := "desc"
-	//排序处理
-	if in.Sort == 1 {
-		orderField = "count"
-	}
-	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, b.Bidfield, orderField, orderType)
-	log.Println(aggStr)
-	countList := entity.GetAggs(entity.PROJECTSET_INDEX, entity.PROJECTSET_TYPE, aggStr)
-	//
-	if len(countList) > 0 && countList != nil {
-		for _, value := range countList {
-			if companyMap[value.CompanyName] != nil {
-				companyMap[value.CompanyName]["project_money"] = value.ProjectMoney
-				companyMap[value.CompanyName]["project_count"] = value.ProjectCount
-				dataList = append(dataList, companyMap[value.CompanyName])
-				delete(companyMap, value.CompanyName)
-			}
-		}
-		for _, value := range companyMap {
-			dataList = append(dataList, value)
-		}
-	} else {
-		dataList = *companyList
+    if len(in.BusinessTypeCode) > 0 {
+        fool = false
+    }
+    //业务范围处理
+    boolsNum, bools := BusinessScopehandle(in.SdequipmentCode, multi_match, `"sdequipment"`, query_bool_must_and, bools)
+    shouldNumber := 0
+    if len(shoulds) > 0 {
+        shouldNumber = 1
+    }
+    //机构名称处理
+    if in.CompanyName != "" {
+        fool = false
+        musts = append(musts, fmt.Sprintf(multi_match, "\""+in.CompanyName+"\"", "\"p_miname\""))
+    }
 
-	}
-	return
+    if fool {
+        nameQuery := entity.SplicingString("mi_name", b.DefaultIinstitution)
+        musts = append(musts, nameQuery)
+    }
+    shouldStr := fmt.Sprintf(shouldQuery, strings.Join(shoulds, ","), shouldNumber)
+    musts = append(musts, shouldStr)
+    queryStr := fmt.Sprintf(query, strings.Join(musts, ","), strings.Join(bools, ","), boolsNum, 0, in.ResourceUseCount)
+    //医疗机构查找
+    companyList := elastic.Get(entity.INSTITUTION_INDEX, entity.INSTITUTION_TYPE, queryStr)
+    log.Println(queryStr)
+    //再根据医疗机构名称查找项目金额总数
+    companyName := ""
+    companyMap := make(map[string]map[string]interface{})
+    if len(*companyList) > 0 && companyList != nil {
+        //认领数据查询
+        companyIdMap := b.ClaimCompanyData(in.Appid, in.NewUserId, entity.TypeInstitution)
+        for key, value := range *companyList {
+	  if key > 0 {
+	      companyName += `,`
+	  }
+	  companyName += `"` + fmt.Sprint(value["mi_name"]) + `"`
+	  value["project_money"] = float64(0.00)
+	  value["project_count"] = 0
+	  if companyIdMap[fmt.Sprint(value["company_id"])] == nil {
+	      value["isClaim"] = false
+	  } else {
+	      value["isClaim"] = true
+	  }
+	  companyMap[fmt.Sprint(value["mi_name"])] = value
+        }
+
+    } else {
+        return
+    }
+    orderField := "_count"
+    orderType := "desc"
+    //排序处理
+    if in.Sort == 1 {
+        orderField = "count"
+    }
+    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"},"size":%d]},"aggs":{"count":{"sum":{"field":"bidamount"}}}}},"size":0}`, companyName, b.Bidfield, orderField, orderType, in.ResourceUseCount)
+    log.Println(aggStr)
+    countList := entity.GetAggs(entity.PROJECTSET_INDEX, entity.PROJECTSET_TYPE, aggStr)
+    //
+    if len(countList) > 0 && countList != nil {
+        for _, value := range countList {
+	  if companyMap[value.CompanyName] != nil {
+	      companyMap[value.CompanyName]["project_money"] = value.ProjectMoney
+	      companyMap[value.CompanyName]["project_count"] = value.ProjectCount
+	      dataList = append(dataList, companyMap[value.CompanyName])
+	      delete(companyMap, value.CompanyName)
+	  }
+        }
+        for _, value := range companyMap {
+	  dataList = append(dataList, value)
+        }
+    } else {
+        dataList = *companyList
+
+    }
+    return
 }
 
 // Distributor 经销商搜索
 func (b InstitutionService) Distributor(in *medical.SearchDistributorReq) (dataList []map[string]interface{}) {
-	//先查询医疗机构
-	//医疗机构查询拼接
-	query := `{"query":{"bool":{"must":[%s],"must_not": [{"term": {"p_supplier": ""}}],"should":[%s],"minimum_should_match": %d}}, "sort":{"id":{"order":"desc"}},"from": %d,"size": %d}`
-	shouldQuery := `{"bool":{"should":[%s],"minimum_should_match": %d}}`
-	multi_match := `{"multi_match": {"query": %s,"type": "phrase", "fields": [%s]}}`
-	var query_bool_must_and = `{"bool": {"must": [%s]%s}}`
-	musts := []string{}
-	shoulds := []string{}
-	bools := []string{}
-	//省份处理
-	cityArr := []string{}
-	areaArr := []string{}
-	if in.AreaCode != "" {
-		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 len(cityArr) > 0 {
-		cityQuery := entity.SplicingArr("city", cityArr)
-		shoulds = append(shoulds, cityQuery)
-	}
-	//业务范围处理
-	boolsNum, bools := BusinessScopehandle(in.BusinessScope, multi_match, `"productlist.name"`, query_bool_must_and, bools)
-	//品牌处理
-	if in.Brand != "" {
-		brandQuery := entity.SplicingString("productlist.brand", in.Brand)
-		musts = append(musts, brandQuery)
-	}
-	//产品型号处理
-	if in.ProductModel != "" {
-		productModelQuery := entity.SplicingString("productlist.model", in.ProductModel)
-		musts = append(musts, productModelQuery)
-	}
-	//机构名称处理
-	if in.CompanyName != "" {
-		musts = append(musts, fmt.Sprintf(multi_match, "\""+in.CompanyName+"\"", "\"p_supplier\""))
-	}
-	shouldNumber := 0
-	if len(shoulds) > 0 {
-		shouldNumber = 1
-	}
-	shouldStr := fmt.Sprintf(shouldQuery, strings.Join(shoulds, ","), shouldNumber)
-	musts = append(musts, shouldStr)
-	queryStr := fmt.Sprintf(query, strings.Join(musts, ","), strings.Join(bools, ","), boolsNum, 0, in.ResourceUseCount)
-	//医疗机构查找
-	companyList := elastic.Get(entity.SUPPLIER_PRODUCT_INDEX, entity.SUPPLIER_PRODUCT_TYPE, queryStr)
-	log.Println(queryStr)
-	//再根据医疗机构名称查找项目金额总数
-	companyIds := ""
-	companyMap := make(map[string]map[string]interface{})
-	if len(*companyList) > 0 && companyList != nil {
-		//认领数据查询
-		companyIdMap := b.ClaimCompanyData(in.Appid, in.NewUserId, entity.TypeDistributor)
-		for key, value := range *companyList {
-			if key > 0 {
-				companyIds += `,`
-			}
-			companyIds += `"` + fmt.Sprint(value["company_id"]) + `"`
-			value["project_money"] = float64(0.00)
-			value["project_count"] = 0
-			if companyIdMap[fmt.Sprint(value["company_id"])] == nil {
-				value["isClaim"] = false
-			} else {
-				value["isClaim"] = true
-			}
-			companyMap[fmt.Sprint(value["company_id"])] = value
-		}
-	} else {
-		return
-	}
-	//排序处理
-	orderField := "_count"
-	orderType := "desc"
-	if in.Sort == 1 {
-		orderField = "count"
-	}
-	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, b.Bidfield, orderField, orderType)
-	log.Println(aggStr)
-	countList := entity.GetAggs(entity.PROJECTSET_INDEX, entity.PROJECTSET_TYPE, aggStr)
-	if len(countList) > 0 && countList != nil {
-		for _, value := range countList {
-			if companyMap[value.CompanyName] != nil {
-				companyMap[value.CompanyName]["project_money"] = value.ProjectMoney
-				companyMap[value.CompanyName]["project_count"] = value.ProjectCount
-				dataList = append(dataList, companyMap[value.CompanyName])
-				delete(companyMap, value.CompanyName)
-			}
-		}
-		for _, value := range companyMap {
-			dataList = append(dataList, value)
-		}
-	} else {
-		dataList = *companyList
-	}
-	return
+    //先查询医疗机构
+    //医疗机构查询拼接
+    query := `{"query":{"bool":{"must":[%s],"must_not": [{"term": {"p_supplier": ""}}],"should":[%s],"minimum_should_match": %d}}, "sort":{"id":{"order":"desc"}},"from": %d,"size": %d}`
+    shouldQuery := `{"bool":{"should":[%s],"minimum_should_match": %d}}`
+    multi_match := `{"multi_match": {"query": %s,"type": "phrase", "fields": [%s]}}`
+    var query_bool_must_and = `{"bool": {"must": [%s]%s}}`
+    musts := []string{}
+    shoulds := []string{}
+    bools := []string{}
+    //省份处理
+    cityArr := []string{}
+    areaArr := []string{}
+    fool := true
+    if in.AreaCode != "" {
+        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 {
+        fool = false
+        areaQuery := entity.SplicingArr("area", areaArr)
+        shoulds = append(shoulds, areaQuery)
+    }
+    //城市处理
+    if len(cityArr) > 0 {
+        fool = false
+        cityQuery := entity.SplicingArr("city", cityArr)
+        shoulds = append(shoulds, cityQuery)
+    }
+    //业务范围处理
+    boolsNum, bools := BusinessScopehandle(in.BusinessScope, multi_match, `"productlist.name"`, query_bool_must_and, bools)
+    if len(in.BusinessScope) > 0 {
+        fool = false
+    }
+    //品牌处理
+    if in.Brand != "" {
+        fool = false
+        brandQuery := entity.SplicingString("productlist.brand", in.Brand)
+        musts = append(musts, brandQuery)
+    }
+    //产品型号处理
+    if in.ProductModel != "" {
+        fool = false
+        productModelQuery := entity.SplicingString("productlist.model", in.ProductModel)
+        musts = append(musts, productModelQuery)
+    }
+    //机构名称处理
+    if in.CompanyName != "" {
+        fool = false
+        musts = append(musts, fmt.Sprintf(multi_match, "\""+in.CompanyName+"\"", "\"p_supplier\""))
+    }
+    shouldNumber := 0
+    if len(shoulds) > 0 {
+        shouldNumber = 1
+    }
+    if fool {
+        nameQuery := entity.SplicingString("supplier", b.DefaultDistributor)
+        musts = append(musts, nameQuery)
+    }
+    shouldStr := fmt.Sprintf(shouldQuery, strings.Join(shoulds, ","), shouldNumber)
+    musts = append(musts, shouldStr)
+    queryStr := fmt.Sprintf(query, strings.Join(musts, ","), strings.Join(bools, ","), boolsNum, 0, in.ResourceUseCount)
+    //医疗机构查找
+    companyList := elastic.Get(entity.SUPPLIER_PRODUCT_INDEX, entity.SUPPLIER_PRODUCT_TYPE, queryStr)
+    log.Println(queryStr)
+    //再根据医疗机构名称查找项目金额总数
+    companyIds := ""
+    companyMap := make(map[string]map[string]interface{})
+    if len(*companyList) > 0 && companyList != nil {
+        //认领数据查询
+        companyIdMap := b.ClaimCompanyData(in.Appid, in.NewUserId, entity.TypeDistributor)
+        for key, value := range *companyList {
+	  if key > 0 {
+	      companyIds += `,`
+	  }
+	  companyIds += `"` + fmt.Sprint(value["company_id"]) + `"`
+	  value["project_money"] = float64(0.00)
+	  value["project_count"] = 0
+	  if companyIdMap[fmt.Sprint(value["company_id"])] == nil {
+	      value["isClaim"] = false
+	  } else {
+	      value["isClaim"] = true
+	  }
+	  companyMap[fmt.Sprint(value["company_id"])] = value
+        }
+    } else {
+        return
+    }
+    //排序处理
+    orderField := "_count"
+    orderType := "desc"
+    if in.Sort == 1 {
+        orderField = "count"
+    }
+    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"}],,"size":500},"aggs":{"count":{"sum":{"field":"bidamount"}}}}},"size":0}`, companyIds, b.Bidfield, orderField, orderType)
+    log.Println(aggStr)
+    countList := entity.GetAggs(entity.PROJECTSET_INDEX, entity.PROJECTSET_TYPE, aggStr)
+    if len(countList) > 0 && countList != nil {
+        for _, value := range countList {
+	  if companyMap[value.CompanyName] != nil {
+	      companyMap[value.CompanyName]["project_money"] = value.ProjectMoney
+	      companyMap[value.CompanyName]["project_count"] = value.ProjectCount
+	      dataList = append(dataList, companyMap[value.CompanyName])
+	      delete(companyMap, value.CompanyName)
+	  }
+        }
+        for _, value := range companyMap {
+	  dataList = append(dataList, value)
+        }
+    } else {
+        dataList = *companyList
+    }
+    return
 }
 
 //  ClaimCompanyData 已认领企业查询处理
@@ -267,77 +296,77 @@ func (b InstitutionService) Distributor(in *medical.SearchDistributorReq) (dataL
 //  @return map[string]map[string]interface{} 认领的企业信息
 //
 func (b InstitutionService) ClaimCompanyData(appId string, newUserId, claimType int64) map[string]map[string]interface{} {
-	claimList := b.BasesqlCon.Find(entity.TableDomainEntClaim, map[string]interface{}{
-		"user_id": newUserId,
-		"status":  1,
-		"type":    claimType,
-		"appid":   appId,
-	}, "ent_id", "", -1, -1)
-	companyIdMap := make(map[string]map[string]interface{})
-	if claimList == nil || len(*claimList) == 0 {
-		return companyIdMap
-	}
-	for _, m := range *claimList {
-		companyIdMap[quitl.InterfaceToStr(m["ent_id"])] = m
-	}
-	return companyIdMap
+    claimList := b.BasesqlCon.Find(entity.TableDomainEntClaim, map[string]interface{}{
+        "user_id": newUserId,
+        "status":  1,
+        "type":    claimType,
+        "appid":   appId,
+    }, "ent_id", "", -1, -1)
+    companyIdMap := make(map[string]map[string]interface{})
+    if claimList == nil || len(*claimList) == 0 {
+        return companyIdMap
+    }
+    for _, m := range *claimList {
+        companyIdMap[quitl.InterfaceToStr(m["ent_id"])] = m
+    }
+    return companyIdMap
 }
 
 // BusinessScopehandle 业务范围处理
 func BusinessScopehandle(BusinessScope []*medical.Business_Scope, multi_match, findfields, query_bool_must_and string, bools []string) (int, []string) {
-	boolsNum := 0
-	if len(BusinessScope) > 0 {
-		boolsNum = 1
-		BusinessScope := BuyerContentStruct(BusinessScope)
-		multi_match = fmt.Sprintf(multi_match, "%s", findfields)
-		for _, v := range BusinessScope {
-			businessShoulds := []string{}
-			businessMust_not := []string{}
-			//关键词
-			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 len(businessShoulds) > 0 {
-				notStr := ""
-				if len(businessShoulds) > 0 {
-					notStr = fmt.Sprintf(`,"must_not":[%s]`, strings.Join(businessMust_not, ","))
-				}
-				bools = append(bools, fmt.Sprintf(query_bool_must_and, strings.Join(businessShoulds, ","), notStr))
-			}
-		}
-	}
-	return boolsNum, bools
+    boolsNum := 0
+    if len(BusinessScope) > 0 {
+        boolsNum = 1
+        BusinessScope := BuyerContentStruct(BusinessScope)
+        multi_match = fmt.Sprintf(multi_match, "%s", findfields)
+        for _, v := range BusinessScope {
+	  businessShoulds := []string{}
+	  businessMust_not := []string{}
+	  //关键词
+	  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 len(businessShoulds) > 0 {
+	      notStr := ""
+	      if len(businessShoulds) > 0 {
+		notStr = fmt.Sprintf(`,"must_not":[%s]`, strings.Join(businessMust_not, ","))
+	      }
+	      bools = append(bools, fmt.Sprintf(query_bool_must_and, strings.Join(businessShoulds, ","), notStr))
+	  }
+        }
+    }
+    return boolsNum, bools
 }
 
 func BuyerContentStruct(BC []*medical.Business_Scope) (arr []*medical.Business_Scope) {
-	if len(BC) > 0 {
-		for _, kw := range BC {
-			if kw.Matchway == 1 {
-				for _, kk := range kw.Key {
-					arr = append(arr, &medical.Business_Scope{
-						Key:    []string{kk},
-						Notkey: kw.Notkey,
-					})
-				}
-				for _, kk := range kw.Appendkey {
-					arr = append(arr, &medical.Business_Scope{
-						Key:    []string{kk},
-						Notkey: kw.Notkey,
-					})
-				}
-			} else {
-				arr = append(arr, kw)
-			}
-		}
-	}
-	return arr
+    if len(BC) > 0 {
+        for _, kw := range BC {
+	  if kw.Matchway == 1 {
+	      for _, kk := range kw.Key {
+		arr = append(arr, &medical.Business_Scope{
+		    Key:    []string{kk},
+		    Notkey: kw.Notkey,
+		})
+	      }
+	      for _, kk := range kw.Appendkey {
+		arr = append(arr, &medical.Business_Scope{
+		    Key:    []string{kk},
+		    Notkey: kw.Notkey,
+		})
+	      }
+	  } else {
+	      arr = append(arr, kw)
+	  }
+        }
+    }
+    return arr
 }