浏览代码

医疗结构搜索

WH01243 3 年之前
父节点
当前提交
3dbd384dfa

+ 1 - 0
api/medical/etc/medical-api.yaml

@@ -2,6 +2,7 @@ Name: medical-api
 Host: 0.0.0.0
 Port: 8888
 WebRpcPort: 8016
+Timeout: 10000
 Medical:
   Etcd:
     Hosts:

+ 2 - 2
api/medical/internal/handler/routes.go

@@ -91,12 +91,12 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 		[]rest.Route{
 			{
 				Method:  http.MethodPost,
-				Path:    "/domain/userAuthInfoSave",
+				Path:    "/userAuthInfoSave",
 				Handler: auth.UserAuthInfoSaveHandler(serverCtx),
 			},
 			{
 				Method:  http.MethodPost,
-				Path:    "/domain/userAuthInfo",
+				Path:    "/userAuthInfo",
 				Handler: auth.UserAuthInfoHandler(serverCtx),
 			},
 		},

+ 1 - 0
api/medical/internal/logic/auth/userauthinfologic.go

@@ -26,6 +26,7 @@ func NewUserAuthInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *User
 
 func (l *UserAuthInfoLogic) UserAuthInfo(req *types.CommonReq) (*types.CommonRes, error) {
 	// todo: add your logic here and delete this line
+
 	resp, err := l.svcCtx.Medical.UserAuthInfo(l.ctx, &medical.CommonReq{
 		UserId: req.NewUserId,
 		Appid:  req.AppId,

+ 17 - 3
api/medical/internal/logic/distributor/searchdistributorlogic.go

@@ -1,6 +1,7 @@
 package distributor
 
 import (
+	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/medical"
 	"context"
 
 	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/api/medical/internal/svc"
@@ -23,8 +24,21 @@ func NewSearchDistributorLogic(ctx context.Context, svcCtx *svc.ServiceContext)
 	}
 }
 
-func (l *SearchDistributorLogic) SearchDistributor(req *types.SearchDistributorReq) (resp *types.CommonRes, err error) {
+//搜索经销商请求
+func (l *SearchDistributorLogic) SearchDistributor(req *types.SearchDistributorReq) (*types.CommonRes, error) {
 	// todo: add your logic here and delete this line
-
-	return
+	resp, _ := l.svcCtx.Medical.Distributor(l.ctx, &medical.SearchDistributorReq{
+		CompanyName:   req.CompanyName,
+		AreaCode:      req.AreaCode,
+		BusinessScope: req.BusinessScope,
+		Brand:         req.Brand,
+		ProductModel:  req.ProductModel,
+		CountOrder:    int64(req.CountOrder),
+		MoneyOrder:    int64(req.MoneyOrder),
+	})
+	return &types.CommonRes{
+		Error_msg:  resp.ErrorMsg,
+		Error_code: int(resp.ErrorCode),
+		Data:       resp.Data,
+	}, nil
 }

+ 18 - 4
api/medical/internal/logic/institution/searchinstitutionlogic.go

@@ -1,6 +1,7 @@
 package institution
 
 import (
+	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/medical"
 	"context"
 
 	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/api/medical/internal/svc"
@@ -23,8 +24,21 @@ func NewSearchInstitutionLogic(ctx context.Context, svcCtx *svc.ServiceContext)
 	}
 }
 
-func (l *SearchInstitutionLogic) SearchInstitution(req *types.SearchInstitutionReq) (resp *types.CommonRes, err error) {
-	// todo: add your logic here and delete this line
-
-	return
+//医疗机构搜索
+func (l *SearchInstitutionLogic) SearchInstitution(req *types.SearchInstitutionReq) (*types.CommonRes, error) {
+	resp, _ := l.svcCtx.Medical.Institution(l.ctx, &medical.SearchInstitutionReq{
+		CompanyName:      req.CompanyName,
+		AreaCode:         req.AreaCode,
+		LevelCode:        req.LevelCode,
+		MiTypeCode:       req.MiTypeCode,
+		BusinessTypeCode: int64(req.BusinessTypeCode),
+		SdequipmentCode:  req.SdequipmentCode,
+		CountOrder:       int64(req.CountOrder),
+		MoneyOrder:       int64(req.MoneyOrder),
+	})
+	return &types.CommonRes{
+		Error_msg:  resp.ErrorMsg,
+		Error_code: int(resp.ErrorCode),
+		Data:       resp.Data,
+	}, nil
 }

+ 24 - 28
api/medical/internal/types/types.go

@@ -8,34 +8,25 @@ type CommonRes struct {
 	State      bool        `json:"state"`
 }
 
-type CommonReq struct {
-	NewUserId int64  `header:"newUserId"`
-	AppId     string `header:"appId"`
-}
-
 type SearchInstitutionReq struct {
-	CompanyName      string `json:"company_name,optional"`     // 要搜索的医疗机构
-	AreaCode         string `json:"area_code,optional"`        // 区域代码
-	LevelCode        string `json:"level_code,optional"`       // 医院等级代码
-	MiTypeCode       string `json:"mi_type_code,optional"`     // 机构类型
-	BusinessTypeCode int    `json:"business_type_code"`        // 经营性质 1-公立 2-民营 3-其他
-	SdequipmentCode  string `json:"sdequipment_code,optional"` // 业务范围
-	CountOrder       string `json:"count_order,optional"`      // 项目数量排序 0-不排序 1-数量倒序
-	MoneyOrder       string `json:"money_order,optional"`      // 金额数量排序:0- 不参与排序  1-按金额倒序
-	Page             int    `json:"page,optional"`
-	PageSize         int    `json:"page_size,optional"`
+	CompanyName      string `json:"company_name,optional"`       // 要搜索的医疗机构
+	AreaCode         string `json:"area_code,optional"`          // 区域代码
+	LevelCode        string `json:"level_code,optional"`         // 医院等级代码
+	MiTypeCode       string `json:"mi_type_code,optional"`       // 机构类型
+	BusinessTypeCode int    `json:"business_type_code,optional"` // 经营性质 1-公立 2-民营 3-其他
+	SdequipmentCode  string `json:"sdequipment_code,optional"`   // 业务范围
+	CountOrder       int    `json:"count_order,optional"`        // 项目数量排序 0-不排序 1-数量倒序
+	MoneyOrder       int    `json:"money_order,optional"`        // 金额数量排序:0- 不参与排序  1-按金额倒序
 }
 
 type SearchDistributorReq struct {
 	CompanyName   string `json:"company_name,optional"`   // 要搜索的经销商
 	AreaCode      string `json:"area_code,optional"`      // 区域代码
 	BusinessScope string `json:"business_scope,optional"` // 业务范围
-	Brand         string `json:"brand,optional"`          // 品牌
+	Brand         string `json:"brand,optional,optional"` // 品牌
 	ProductModel  string `json:"product_model,optional"`  // 产品型号
-	CountOrder    string `json:"count_order,optional"`    // 项目数量排序 0-不排序 1-数量倒序
-	MoneyOrder    string `json:"money_order,optional"`    // 金额数量排序:0- 不参与排序  1-按金额倒序
-	Page          int    `json:"page,optional"`           // 页码
-	PageSize      int    `json:"page_size,optional"`      // 每页条数
+	CountOrder    int    `json:"count_order,optional"`    // 项目数量排序 0-不排序 1-数量倒序
+	MoneyOrder    int    `json:"money_order,optional"`    // 金额数量排序:0- 不参与排序  1-按金额倒序
 }
 
 type PortraitReq struct {
@@ -81,14 +72,19 @@ type IsClaimedReq struct {
 }
 
 type UserInfoReq struct {
-	Name          string `json:"name"`             // 姓名
-	Phone         string `json:"phone"`            // 手机号
-	Position      string `json:"position"`         // 个人职务
-	Department    string `json:"department"`       // 所在部门
-	EntCode       string `header:"ent_code"`       // 企业标识
-	EntName       string `header:"ent_name"`       // 企业名称
-	Mail          string `header:"mail"`           // 邮箱
-	OperationType string `header:"operation_type"` // add新增 update 修改
+	Name          string `json:"name"`           // 姓名
+	Phone         string `json:"phone"`          // 手机号
+	Position      string `json:"position"`       // 个人职务
+	Department    string `json:"department"`     // 所在部门
+	EntCode       string `json:"ent_code"`       // 企业标识
+	EntName       string `json:"ent_name"`       // 企业名称
+	Mail          string `json:"mail"`           // 邮箱
+	OperationType string `json:"operation_type"` // add新增 update 修改
 	NewUserId     int64  `header:"newUserId"`
 	AppId         string `header:"appId"`
 }
+
+type CommonReq struct {
+	NewUserId int64  `json:"newUserId"`
+	AppId     string `json:"appId"`
+}

+ 28 - 30
api/medical/medical.api

@@ -5,34 +5,27 @@ type CommonRes {
 	Data       interface{} `json:"data"`
 	State      bool        `json:"state"`
 }
-type CommonReq {
-	NewUserId int64  `header:"newUserId"`
-	AppId     string `header:"appId"`
-}
+
 // 搜索医疗机构
 type SearchInstitutionReq {
-	CompanyName      string `json:"company_name,optional"`     // 要搜索的医疗机构
-	AreaCode         string `json:"area_code,optional"`        // 区域代码
-	LevelCode        string `json:"level_code,optional"`       // 医院等级代码
-	MiTypeCode       string `json:"mi_type_code,optional"`     // 机构类型
-	BusinessTypeCode int    `json:"business_type_code"`        // 经营性质 1-公立 2-民营 3-其他
-	SdequipmentCode  string `json:"sdequipment_code,optional"` // 业务范围
-	CountOrder       string `json:"count_order,optional"`      // 项目数量排序 0-不排序 1-数量倒序
-	MoneyOrder       string `json:"money_order,optional"`      // 金额数量排序:0- 不参与排序  1-按金额倒序
-	Page             int    `json:"page,optional"`
-	PageSize         int    `json:"page_size,optional"`
+	CompanyName      string `json:"company_name,optional"`       // 要搜索的医疗机构
+	AreaCode         string `json:"area_code,optional"`          // 区域代码
+	LevelCode        string `json:"level_code,optional"`         // 医院等级代码
+	MiTypeCode       string `json:"mi_type_code,optional"`       // 机构类型
+	BusinessTypeCode int    `json:"business_type_code,optional"` // 经营性质 1-公立 2-民营 3-其他
+	SdequipmentCode  string `json:"sdequipment_code,optional"`   // 业务范围
+	CountOrder       int    `json:"count_order,optional"`        // 项目数量排序 0-不排序 1-数量倒序
+	MoneyOrder       int    `json:"money_order,optional"`        // 金额数量排序:0- 不参与排序  1-按金额倒序
 }
 // 搜索经销商请求
 type SearchDistributorReq {
 	CompanyName   string `json:"company_name,optional"`   // 要搜索的经销商
 	AreaCode      string `json:"area_code,optional"`      // 区域代码
 	BusinessScope string `json:"business_scope,optional"` // 业务范围
-	Brand         string `json:"brand,optional"`          // 品牌
+	Brand         string `json:"brand,optional,optional"` // 品牌
 	ProductModel  string `json:"product_model,optional"`  // 产品型号
-	CountOrder    string `json:"count_order,optional"`    // 项目数量排序 0-不排序 1-数量倒序
-	MoneyOrder    string `json:"money_order,optional"`    // 金额数量排序:0- 不参与排序  1-按金额倒序
-	Page          int    `json:"page,optional"`           // 页码
-	PageSize      int    `json:"page_size,optional"`      // 每页条数
+	CountOrder    int    `json:"count_order,optional"`    // 项目数量排序 0-不排序 1-数量倒序
+	MoneyOrder    int    `json:"money_order,optional"`    // 金额数量排序:0- 不参与排序  1-按金额倒序
 }
 
 // 获取机构信息请求
@@ -130,18 +123,21 @@ service medical-api {
 }
 
 type UserInfoReq {
-	Name          string `json:"name"`             // 姓名
-	Phone         string `json:"phone"`            // 手机号
-	Position      string `json:"position"`         // 个人职务
-	Department    string `json:"department"`       // 所在部门
-	EntCode       string `header:"ent_code"`       // 企业标识
-	EntName       string `header:"ent_name"`       // 企业名称
-	Mail          string `header:"mail"`           // 邮箱
-	OperationType string `header:"operation_type"` // add新增 update 修改
+	Name          string `json:"name"`           // 姓名
+	Phone         string `json:"phone"`          // 手机号
+	Position      string `json:"position"`       // 个人职务
+	Department    string `json:"department"`     // 所在部门
+	EntCode       string `json:"ent_code"`       // 企业标识
+	EntName       string `json:"ent_name"`       // 企业名称
+	Mail          string `json:"mail"`           // 邮箱
+	OperationType string `json:"operation_type"` // add新增 update 修改
 	NewUserId     int64  `header:"newUserId"`
 	AppId         string `header:"appId"`
 }
-
+type CommonReq {
+	NewUserId int64  `json:"newUserId"`
+	AppId     string `json:"appId"`
+}
 // 认证
 @server(
 	group : auth
@@ -149,7 +145,9 @@ type UserInfoReq {
 )
 service medical-api {
 	@handler userAuthInfoSave
-	post /domain/userAuthInfoSave (UserInfoReq) returns (CommonRes); 	// 用户认证信息保存
+	// 用户认证信息保存
+	post /userAuthInfoSave (UserInfoReq) returns (CommonRes);
 	@handler userAuthInfo
-	post /domain/userAuthInfo (CommonReq) returns (CommonRes); // 获取用户认证信息
+	// 用户认证信息查询
+	post /userAuthInfo (CommonReq) returns (CommonRes);
 }

+ 2 - 4
entity/db.go

@@ -13,10 +13,8 @@ type MysqlMainStruct struct {
 	MaxIdleConns int    `json:"maxIdleConns"`
 }
 type EsStruct struct {
-	Addr  string `json:"addr"`
-	Size  int    `json:"size"`
-	Index string `json:"index"`
-	Type  string `json:"type"`
+	Addr string `json:"addr"`
+	Size int    `json:"size"`
 }
 
 var (

+ 97 - 0
entity/util.go

@@ -0,0 +1,97 @@
+package entity
+
+import (
+	quitl "app.yhyue.com/moapp/jybase/common"
+	elastic "app.yhyue.com/moapp/jybase/esv1"
+	_ "encoding"
+	"encoding/json"
+	"log"
+	"runtime"
+	"strings"
+)
+
+const (
+	INSTITUTION_INDEX      = "medical_institution_v1"
+	INSTITUTION_TYPE       = "medical_institution"
+	PROJECTSET_INDEX       = "projectset"
+	PROJECTSET_TYPE        = "projectset"
+	SUPPLIER_PRODUCT_INDEX = "supplier_product_v1"
+	SUPPLIER_PRODUCT_TYPE  = "supplier_product"
+)
+
+type AggressJson struct {
+	CompanyName  string
+	ProjectMoney float64
+	ProjectCount int
+}
+type Bucket struct {
+	ScopeclassName string `json:"key"` //行业
+	Count          struct {
+		Value float64 `json:"value"` //项目金额
+	} `json:"count"`
+	ProjectCount int `json:"doc_count"` //项目数量
+}
+
+//条件拼接
+func SplicingString(name, str string) string {
+	qury := `{"terms":{"` + name + `":[`
+	for key, value := range strings.Split(str, ",") {
+		if key > 0 {
+			qury += `,`
+		}
+		qury += `"` + value + `"`
+	}
+	qury += `]}}`
+	return qury
+}
+
+func GetAggs(P_INDEX, P_TYPE, potComQ string) []AggressJson {
+	regList := []AggressJson{}
+	defer quitl.Catch()
+	client := elastic.GetEsConn()
+	defer func() {
+		go elastic.DestoryEsConn(client)
+	}()
+	if client != nil {
+		defer func() {
+			if r := recover(); r != nil {
+				log.Println("[E]", r)
+				for skip := 1; ; skip++ {
+					_, file, line, ok := runtime.Caller(skip)
+					if !ok {
+						break
+					}
+					go log.Printf("%v,%v\n", file, line)
+				}
+			}
+		}()
+		searchResult, err := client.Search().Index(P_INDEX).Type(P_TYPE).Source(potComQ).Do()
+		if searchResult.TimedOut {
+			//请求超时
+			log.Println(err, "____________:::", searchResult.TimedOut)
+			return regList
+		}
+		if err != nil {
+			log.Println("从ES查询出错", err.Error())
+		}
+		aggs := searchResult.Aggregations
+		if aggs != nil {
+			if aggs_g, ok := aggs.Children("group_field"); ok {
+				bs, _ := aggs_g.Aggregations["buckets"].MarshalJSON()
+				if len(bs) > 0 {
+					var aggsMap []Bucket
+					json.Unmarshal(bs, &aggsMap)
+					for _, value := range aggsMap {
+						regList = append(regList, AggressJson{
+							CompanyName:  value.ScopeclassName,
+							ProjectMoney: value.Count.Value,
+							ProjectCount: value.ProjectCount,
+						})
+					}
+				}
+			}
+		}
+	}
+
+	return regList
+}

+ 1 - 0
go.mod

@@ -8,4 +8,5 @@ require (
 	github.com/zeromicro/go-zero v1.4.0
 	google.golang.org/grpc v1.48.0
 	google.golang.org/protobuf v1.28.1
+	gopkg.in/olivere/elastic.v1 v1.0.1
 )

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

@@ -1,11 +1,12 @@
 Name: medical.rpc
 ListenOn: 127.0.0.1:8080
+Timeout: 10000
 Etcd:
   Hosts:
   - 127.0.0.1:2379
   Key: medical.rpc
 MysqlMain:
-  dbName: field_medical_data
+  dbName: medical_fileld_data
   address: 192.168.3.217:4000
   userName: root
   passWord: =PDT49#80Z!RVv52_z
@@ -19,7 +20,5 @@ BaseMysqlMain:
   maxOpenConns: 5
   maxIdleConns: 5
 Es:
-  addr: http://192.168.3.204:1500
+  addr: http://192.168.3.206:9800
   size: 5
-  index: smart_new
-  type: smart

+ 22 - 21
rpc/medical/init/init.go

@@ -1,6 +1,7 @@
 package init
 
 import (
+	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/internal/config"
@@ -8,12 +9,12 @@ import (
 	"fmt"
 	_ "github.com/go-sql-driver/mysql"
 	"github.com/zeromicro/go-zero/core/conf"
+	"github.com/zeromicro/go-zero/core/logx"
 	"log"
 )
 
 var configF = flag.String("ff", "etc/medical.yaml", "the config file")
 
-//
 var logFile = flag.String("lf", "etc/logs.yaml", "the config file")
 var logc entity.Logc
 var C config.Config
@@ -50,24 +51,24 @@ func init() {
 
 	fmt.Println()
 	//初始化 elasticsearch
-	//es := C.Es
-	//if es.Addr != "" {
-	//	log.Println("--初始化 elasticsearch--")
-	//	log.Println(es.Addr, es.Size)
-	//	elastic.InitElasticSize(es.Addr, es.Size)
-	//
-	//	//初始化日志信息
-	//	conf.MustLoad(*logFile, &logc)
-	//	if len(logc.Level) > 0 {
-	//		for _, v := range logc.Level {
-	//			logx.MustSetup(logx.LogConf{
-	//				Mode:     logc.Mode,
-	//				Path:     logc.Path,
-	//				Level:    v,
-	//				KeepDays: logc.KeepDays,
-	//			})
-	//			logx.Info(v, "--日志记录")
-	//		}
-	//	}
-	//}
+	es := C.Es
+	if es.Addr != "" {
+		log.Println("--初始化 elasticsearch--")
+		log.Println(es.Addr, es.Size)
+		elastic.InitElasticSize(es.Addr, es.Size)
+
+		//初始化日志信息
+		conf.MustLoad(*logFile, &logc)
+		if len(logc.Level) > 0 {
+			for _, v := range logc.Level {
+				logx.MustSetup(logx.LogConf{
+					Mode:     logc.Mode,
+					Path:     logc.Path,
+					Level:    v,
+					KeepDays: logc.KeepDays,
+				})
+				logx.Info(v, "--日志记录")
+			}
+		}
+	}
 }

+ 1 - 1
rpc/medical/internal/config/config.go

@@ -9,5 +9,5 @@ type Config struct {
 	zrpc.RpcServerConf
 	MysqlMain     entity.MysqlMainStruct
 	BaseMysqlMain entity.MysqlMainStruct
-	//Es            entity.EsStruct
+	Es            entity.EsStruct
 }

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

@@ -1,6 +1,9 @@
 package logic
 
 import (
+	quitl "app.yhyue.com/moapp/jybase/common"
+	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/entity"
+	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/service"
 	"context"
 
 	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/internal/svc"
@@ -26,6 +29,22 @@ 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
-
-	return &medical.CompanyResp{}, nil
+	m := service.InstitutionService{}
+	dataList := m.Distributor(in)
+	result := &medical.CompanyResp{}
+	companyList := []*medical.CompanyData{}
+	for _, value := range dataList {
+		data := medical.CompanyData{
+			CompanyId:    quitl.InterfaceToStr(value["company_id"]),
+			CompanyName:  quitl.InterfaceToStr(value["supplier"]),
+			Area:         quitl.InterfaceToStr(value["area"]),
+			City:         quitl.InterfaceToStr(value["city"]),
+			ProjectMoney: quitl.InterfaceToStr(value["project_money"]),
+			ProjectCount: quitl.Int64All(value["project_count"]),
+		}
+		companyList = append(companyList, &data)
+	}
+	result.Data = companyList
+	result.ErrorCode = entity.SUCCESSCODE
+	return result, nil
 }

+ 10 - 4
rpc/medical/internal/logic/getfilteritemlogic.go

@@ -31,23 +31,29 @@ func (l *GetFilterItemLogic) GetFilterItem(in *medical.Zero) (*medical.FilterIte
 	m := service.InstitutionService{}
 	levelList, typeList := m.GetFilterItem()
 	result := &medical.FilterItemResp{}
+	levelData := []*medical.LevelCode{}
+	miTypeData := []*medical.MiTypeCode{}
 	for _, value := range *levelList {
-		levelData := medical.LevelCode{
+		level := medical.LevelCode{
 			Code:  quitl.InterfaceToStr(value["code"]),
 			Pcode: quitl.InterfaceToStr(value["pcode"]),
 			Name:  quitl.InterfaceToStr(value["name"]),
 			Level: quitl.InterfaceToStr(value["level"]),
 		}
-		result.Data.LevelCode = append(result.Data.LevelCode, &levelData)
+		levelData = append(levelData, &level)
 	}
 	for _, value := range *typeList {
-		typeData := medical.MiTypeCode{
+		miType := medical.MiTypeCode{
 			Code:  quitl.InterfaceToStr(value["code"]),
 			Pcode: quitl.InterfaceToStr(value["pcode"]),
 			Name:  quitl.InterfaceToStr(value["name"]),
 			Level: quitl.InterfaceToStr(value["level"]),
 		}
-		result.Data.MiTypeCode = append(result.Data.MiTypeCode, &typeData)
+		miTypeData = append(miTypeData, &miType)
+	}
+	result.Data = &medical.FilterItem{
+		LevelCode:  levelData,
+		MiTypeCode: miTypeData,
 	}
 	result.ErrorCode = entity.SUCCESSCODE
 	return result, nil

+ 21 - 3
rpc/medical/internal/logic/institutionlogic.go

@@ -1,6 +1,9 @@
 package logic
 
 import (
+	quitl "app.yhyue.com/moapp/jybase/common"
+	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/entity"
+	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/service"
 	"context"
 
 	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/internal/svc"
@@ -25,7 +28,22 @@ func NewInstitutionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Insti
 
 // 搜索医疗机构
 func (l *InstitutionLogic) Institution(in *medical.SearchInstitutionReq) (*medical.CompanyResp, error) {
-	// todo: add your logic here and delete this line
-
-	return &medical.CompanyResp{}, nil
+	m := service.InstitutionService{}
+	dataList := m.Institution(in)
+	result := &medical.CompanyResp{}
+	companyList := []*medical.CompanyData{}
+	for _, value := range dataList {
+		data := medical.CompanyData{
+			CompanyId:    quitl.InterfaceToStr(value["company_id"]),
+			CompanyName:  quitl.InterfaceToStr(value["mi_name"]),
+			Area:         quitl.InterfaceToStr(value["area"]),
+			City:         quitl.InterfaceToStr(value["city"]),
+			ProjectMoney: quitl.InterfaceToStr(value["project_money"]),
+			ProjectCount: quitl.Int64All(value["project_count"]),
+		}
+		companyList = append(companyList, &data)
+	}
+	result.Data = companyList
+	result.ErrorCode = entity.SUCCESSCODE
+	return result, nil
 }

+ 1 - 1
rpc/medical/internal/logic/userauthinfosavelogic.go

@@ -32,7 +32,7 @@ func (l *UserAuthInfoSaveLogic) UserAuthInfoSave(in *medical.UserInfo) (*medical
 	errcode, msg := m.UserAuthInfoSave(in)
 	result := &medical.CommonResp{}
 	if errcode {
-		result.ErrorCode = entity.ERRORCODE
+		result.ErrorCode = entity.SUCCESSCODE
 	} else {
 		result.ErrorCode = entity.ERRORCODE
 		result.ErrorMsg = msg

+ 16 - 22
rpc/medical/medical.proto

@@ -25,27 +25,25 @@ message  Zero{
 
 }
 message SearchInstitutionReq {
-  string      companyName      =1;    // 要搜索的医疗机构
-  string      areaCode         =2;       // 区域代码
+  string      companyName      =1;      // 要搜索的医疗机构
+  string      areaCode         =2;      // 区域代码
   string      levelCode        =3;      // 医院等级代码
-  string      miTypeCode       =4;     // 机构类型
-  int64       businessTypeCode =5;        // 经营性质 1-公立 2-民营 3-其他
-  string      sdequipmentCode  =6; // 业务范围
-  string      countOrder       =7;      // 项目数量排序 0-不排序 1-数量倒序
-  string      moneyOrder       =8;      // 金额数量排序:0- 不参与排序  1-按金额倒序
-  int64       page             =9;
-  int64       pageSize        =10;
+  string      miTypeCode       =4;      // 机构类型
+  int64       businessTypeCode =5;      // 经营性质 1-公立 2-民营 3-其他
+  string      sdequipmentCode  =6;      // 业务范围
+  int64       countOrder       =7;      // 项目数量排序 0-不排序 1-数量倒序
+  int64       moneyOrder       =8;      // 金额数量排序:0- 不参与排序  1-按金额倒序
+  string      cityCode         =9;      // 区域代码
 }
 message SearchDistributorReq {
   string      companyName     =1;          // 要搜索的经销商
   string      areaCode        =2;          // 区域代码
-  string      BusinessScope   =3;          // 业务范围
+  string      businessScope   =3;          // 业务范围
   string      brand           =4;          // 品牌
-  string       ProductModel    =5;        // 产品型号
-  string      countOrder      =6;          // 项目数量排序 0-不排序 1-数量倒序
-  string      moneyOrder      =7;          // 金额数量排序:0- 不参与排序  1-按金额倒序
-  int64       page            =8;
-  int64       pageSize        =9;
+  string      ProductModel    =5;          // 产品型号
+  int64      countOrder       =6;          // 项目数量排序 0-不排序 1-数量倒序
+  int64      moneyOrder       =7;          // 金额数量排序:0- 不参与排序  1-按金额倒序
+  string      cityCode        =8;          // 区域代码
 }
 message CompanyData {
   string      company_id     =1;          // 唯一标识
@@ -53,17 +51,13 @@ message CompanyData {
   string      area           =3;          // 区域
   string      project_money  =4;          // 项目总金额
   int64       project_count  =5;          // 项目总数
-  int64       follow         =6;          // 是否关注 1-关注 0:-未关注
+  string      city           =6;
 }
-message CompanyDataList {
-  repeated     CompanyData list     =1;   // 唯一标识
-  int64        total                =2;   // 总数
 
-}
 message CompanyResp {
   int64           error_code=1;
   string          error_msg   =2;
-  CompanyDataList  data       =3;
+  repeated     CompanyData  data       =3;
 }
 //医院等级
 message LevelCode {
@@ -106,7 +100,7 @@ message UserInfoResp{
   int64           error_code  =1;          // 唯一标识
   string          error_msg   =2;        // 机构名称
   UserInfo        data        =3;
-  bool            status=4;
+  bool            status      =4;
 }
 //医疗机构画像入参
 message PortraitReq{

+ 188 - 0
service/InstitutionService.go

@@ -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
+}

+ 74 - 1
service/InstitutionService_test.go

@@ -1,8 +1,10 @@
 package service
 
 import (
+	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"
 	"reflect"
 	"testing"
 )
@@ -14,7 +16,7 @@ func init() {
 		Address:      "192.168.3.217:4000",
 		UserName:     "root",
 		PassWord:     "=PDT49#80Z!RVv52_z",
-		DBName:       "field_medical_data",
+		DBName:       "medical_fileld_data",
 		MaxOpenConns: 5,
 		MaxIdleConns: 5,
 	}
@@ -33,6 +35,7 @@ func init() {
 		BaseMysql: BaseMysqlConn,
 	}
 	EntClaimSrv = *NewEntClaimSrv(&MyConn)
+	elastic.InitElasticSize("http://192.168.3.206:9800", 5)
 }
 func TestInstitutionService_GetFilterItem(t *testing.T) {
 	tests := []struct {
@@ -58,3 +61,73 @@ func TestInstitutionService_GetFilterItem(t *testing.T) {
 		})
 	}
 }
+
+func TestInstitutionService_Institution(t *testing.T) {
+	type args struct {
+		in *medical.SearchInstitutionReq
+	}
+	tests := []struct {
+		name          string
+		args          args
+		wantLevelList *[]map[string]interface{}
+	}{
+		// TODO: Add test cases.
+		{
+			name: "医疗机构搜索",
+			args: args{
+				&medical.SearchInstitutionReq{
+					CompanyName:      "医院",
+					AreaCode:         "河南",
+					CityCode:         "郑州市",
+					LevelCode:        "0104,0201,0202",
+					MiTypeCode:       "17,03",
+					SdequipmentCode:  "装置,电动",
+					BusinessTypeCode: 0,
+					CountOrder:       0,
+				}},
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			b := InstitutionService{}
+			if gotLevelList := b.Institution(tt.args.in); !reflect.DeepEqual(gotLevelList, tt.wantLevelList) {
+				t.Errorf("Institution() = %v, want %v", gotLevelList, tt.wantLevelList)
+			}
+		})
+	}
+}
+
+func TestInstitutionService_Distributor(t *testing.T) {
+	type args struct {
+		in *medical.SearchDistributorReq
+	}
+	tests := []struct {
+		name         string
+		args         args
+		wantDataList []map[string]interface{}
+	}{
+		// TODO: Add test cases.
+		{
+			name: "经销商查询",
+			args: args{
+				&medical.SearchDistributorReq{
+					CompanyName:   "",
+					AreaCode:      "江苏",
+					BusinessScope: "",
+					Brand:         "",
+					ProductModel:  "",
+					CountOrder:    0,
+					MoneyOrder:    0,
+					CityCode:      "扬州市",
+				}},
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			b := InstitutionService{}
+			if gotDataList := b.Distributor(tt.args.in); !reflect.DeepEqual(gotDataList, tt.wantDataList) {
+				t.Errorf("Distributor() = %v, want %v", gotDataList, tt.wantDataList)
+			}
+		})
+	}
+}