|
@@ -1,291 +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
|
|
|
- DefaultIinstitution string
|
|
|
- DefaultDistributor string
|
|
|
+ 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{}
|
|
|
- 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{}))...)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ //先查询医疗机构
|
|
|
+ //医疗机构查询拼接
|
|
|
+ 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 {
|
|
|
- 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)
|
|
|
- }
|
|
|
+ //省份处理
|
|
|
+ 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)
|
|
|
+ }
|
|
|
|
|
|
- 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\""))
|
|
|
- }
|
|
|
+ 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\""))
|
|
|
+ }
|
|
|
|
|
|
- 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
|
|
|
- }
|
|
|
+ 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
|
|
|
+ } 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
|
|
|
+ }
|
|
|
+ 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{}
|
|
|
- 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
|
|
|
+ //先查询医疗机构
|
|
|
+ //医疗机构查询拼接
|
|
|
+ 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 已认领企业查询处理
|
|
@@ -296,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
|
|
|
}
|