|
@@ -1,7 +1,12 @@
|
|
|
package service
|
|
|
|
|
|
import (
|
|
|
+ elastic "app.yhyue.com/moapp/jybase/esv1"
|
|
|
"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/entity"
|
|
|
+ "bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/medical"
|
|
|
+ "fmt"
|
|
|
+ "log"
|
|
|
+ "strings"
|
|
|
)
|
|
|
|
|
|
type InstitutionService struct{}
|
|
@@ -14,3 +19,186 @@ func (b InstitutionService) GetFilterItem() (levelList, typeList *[]map[string]i
|
|
|
typeList = entity.Mysql.Find(entity.CODE_MEDICAL_INSTITUTION_TYPE, nil, "*", "", -1, -1)
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+//医疗机构搜索条件
|
|
|
+func (b InstitutionService) Institution(in *medical.SearchInstitutionReq) (dataList []map[string]interface{}) {
|
|
|
+ //先查询医疗机构
|
|
|
+ //医疗机构查询拼接
|
|
|
+ query := `{"query":{"bool":{"must":[%s],"minimum_should_match": %d}}, "from": %d,"size": %d}`
|
|
|
+ musts := []string{}
|
|
|
+ //省份处理
|
|
|
+ if in.AreaCode != "" {
|
|
|
+ areaQuery := entity.SplicingString("area", in.AreaCode)
|
|
|
+ musts = append(musts, areaQuery)
|
|
|
+ }
|
|
|
+ //城市处理
|
|
|
+ if in.CityCode != "" {
|
|
|
+ cityQuery := entity.SplicingString("city", in.CityCode)
|
|
|
+ musts = append(musts, 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 != 0 {
|
|
|
+ businessTypeQuery := entity.SplicingString("business_type", fmt.Sprint(in.AreaCode))
|
|
|
+ musts = append(musts, businessTypeQuery)
|
|
|
+ }
|
|
|
+ //机构名称处理
|
|
|
+ if in.CompanyName != "" {
|
|
|
+ companyNameQuery := entity.SplicingString("p_miname", in.CompanyName)
|
|
|
+ musts = append(musts, companyNameQuery)
|
|
|
+ }
|
|
|
+ //业务范围处理
|
|
|
+ if in.SdequipmentCode != "" {
|
|
|
+ sdequipmentQuery := entity.SplicingString("sdequipment", in.SdequipmentCode)
|
|
|
+ musts = append(musts, sdequipmentQuery)
|
|
|
+ }
|
|
|
+ queryStr := fmt.Sprintf(query, strings.Join(musts, ","), len(musts), 0, 500)
|
|
|
+ //再根据医疗机构名称查找项目金额总数
|
|
|
+ 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 {
|
|
|
+ for key, value := range *companyList {
|
|
|
+ if key > 0 {
|
|
|
+ companyName += `,`
|
|
|
+ }
|
|
|
+ companyName += `"` + fmt.Sprint(value["mi_name"]) + `"`
|
|
|
+ companyMap[fmt.Sprint(value["mi_name"])] = value
|
|
|
+ }
|
|
|
+ } 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"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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)
|
|
|
+ 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])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+//经销商搜索
|
|
|
+func (b InstitutionService) Distributor(in *medical.SearchDistributorReq) (dataList []map[string]interface{}) {
|
|
|
+ //先查询医疗机构
|
|
|
+ //医疗机构查询拼接
|
|
|
+ query := `{"query":{"bool":{"must":[%s],"minimum_should_match": %d}}, "from": %d,"size": %d}`
|
|
|
+ musts := []string{}
|
|
|
+ //省份处理
|
|
|
+ if in.AreaCode != "" {
|
|
|
+ areaQuery := entity.SplicingString("area", in.AreaCode)
|
|
|
+ musts = append(musts, areaQuery)
|
|
|
+ }
|
|
|
+ //城市处理
|
|
|
+ if in.CityCode != "" {
|
|
|
+ cityQuery := entity.SplicingString("city", in.CityCode)
|
|
|
+ musts = append(musts, cityQuery)
|
|
|
+ }
|
|
|
+ //业务范围处理
|
|
|
+ if in.BusinessScope != "" {
|
|
|
+ businessScopeQuery := entity.SplicingString("productlist.name", in.BusinessScope)
|
|
|
+ musts = append(musts, businessScopeQuery)
|
|
|
+ }
|
|
|
+ //品牌处理
|
|
|
+ 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 != "" {
|
|
|
+ companyNameQuery := entity.SplicingString("p_supplier", in.CompanyName)
|
|
|
+ musts = append(musts, companyNameQuery)
|
|
|
+ }
|
|
|
+ queryStr := fmt.Sprintf(query, strings.Join(musts, ","), len(musts), 0, 500)
|
|
|
+ //再根据医疗机构名称查找项目金额总数
|
|
|
+ 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 {
|
|
|
+ for key, value := range *companyList {
|
|
|
+ if key > 0 {
|
|
|
+ companyIds += `,`
|
|
|
+ }
|
|
|
+ companyIds += `"` + fmt.Sprint(value["company_id"]) + `"`
|
|
|
+ companyMap[fmt.Sprint(value["company_id"])] = value
|
|
|
+ }
|
|
|
+ } 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"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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)
|
|
|
+ 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])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|