Browse Source

覆盖率修改

WH01243 3 years ago
parent
commit
246d4c39d1

+ 3 - 3
rpc/medical/init/init.go

@@ -1,24 +1,24 @@
 package init
 
 import (
-	"flag"
-	"log"
 	elastic "app.yhyue.com/moapp/jybase/esv1"
 	"app.yhyue.com/moapp/jybase/mongodb"
 	"app.yhyue.com/moapp/jybase/mysql"
 	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/entity"
 	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/internal/config"
 	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/resource"
+	"flag"
 	_ "github.com/go-sql-driver/mysql"
 	"github.com/zeromicro/go-zero/core/conf"
 	"github.com/zeromicro/go-zero/core/discov"
 	"github.com/zeromicro/go-zero/core/logx"
 	"github.com/zeromicro/go-zero/zrpc"
+	"log"
 )
 
+var logFile = flag.String("lf", "etc/logs.yaml", "the config file")
 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
 

+ 5 - 1
rpc/medical/internal/logic/distributorlogic.go

@@ -4,6 +4,7 @@ import (
 	quitl "app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/encrypt"
 	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/entity"
+	IC "bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/init"
 	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/internal/svc"
 	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/medical"
 	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/service"
@@ -30,7 +31,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{}
+	m := service.InstitutionService{
+		Bidfield:   IC.C.Bidfield,
+		BasesqlCon: entity.BaseMysql,
+	}
 	dataList := m.Distributor(in)
 	result := &medical.CompanyResp{}
 	companyList := []*medical.CompanyData{}

+ 3 - 1
rpc/medical/internal/logic/getfilteritemlogic.go

@@ -28,7 +28,9 @@ func NewGetFilterItemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Get
 // 获取医疗机构筛选条件
 func (l *GetFilterItemLogic) GetFilterItem(in *medical.Zero) (*medical.FilterItemResp, error) {
 	// todo: add your logic here and delete this line
-	m := service.InstitutionService{}
+	m := service.InstitutionService{
+		MysqlConn: entity.Mysql,
+	}
 	levelList, typeList := m.GetFilterItem()
 	result := &medical.FilterItemResp{}
 	levelData := []*medical.LevelCode{}

+ 5 - 1
rpc/medical/internal/logic/institutionlogic.go

@@ -4,6 +4,7 @@ import (
 	quitl "app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/encrypt"
 	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/entity"
+	IC "bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/init"
 	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/service"
 	"context"
 	"strconv"
@@ -30,7 +31,10 @@ func NewInstitutionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Insti
 
 // 搜索医疗机构
 func (l *InstitutionLogic) Institution(in *medical.SearchInstitutionReq) (*medical.CompanyResp, error) {
-	m := service.InstitutionService{}
+	m := service.InstitutionService{
+		Bidfield:   IC.C.Bidfield,
+		BasesqlCon: entity.BaseMysql,
+	}
 	dataList := m.Institution(in)
 	result := &medical.CompanyResp{}
 	companyList := []*medical.CompanyData{}

+ 6 - 1
rpc/medical/internal/logic/userauthinfologic.go

@@ -3,6 +3,7 @@ package logic
 import (
 	quitl "app.yhyue.com/moapp/jybase/common"
 	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/entity"
+	IC "bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/init"
 	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/service"
 	"context"
 
@@ -29,7 +30,11 @@ func NewUserAuthInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *User
 // 获取用户认证信息
 func (l *UserAuthInfoLogic) UserAuthInfo(in *medical.CommonReq) (*medical.UserInfoResp, error) {
 	// todo: add your logic here and delete this line
-	m := service.AuthService{}
+	m := service.AuthService{
+		GoodsSpecId: IC.C.GoodsSpecId,
+		GoodsCode:   IC.C.GoodsCode,
+		BasesqlConn: entity.BaseMysql,
+	}
 	data := m.UserAuthInfo(in)
 	result := &medical.UserInfoResp{}
 	if data != nil {

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

@@ -28,7 +28,9 @@ func NewUserAuthInfoSaveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
 // 用户认证信息保存
 func (l *UserAuthInfoSaveLogic) UserAuthInfoSave(in *medical.UserInfo) (*medical.CommonResp, error) {
 	// todo: add your logic here and delete this line
-	m := service.AuthService{}
+	m := service.AuthService{
+		BasesqlConn: entity.BaseMysql,
+	}
 	errcode, msg := m.UserAuthInfoSave(in)
 	result := &medical.CommonResp{}
 	if errcode {

+ 0 - 3
rpc/medical/medical.go

@@ -7,15 +7,12 @@ import (
 	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/internal/server"
 	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/internal/svc"
 	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/medical"
-	"flag"
 	"fmt"
 	"github.com/zeromicro/go-zero/zrpc"
 	"google.golang.org/grpc"
 	"log"
 )
 
-var configFile = flag.String("f", "etc/medical.yaml", "the config file")
-
 func main() {
 	go func() {
 		err := endless.ListenAndServe(":"+mc.InterfaceToStr(IC.C.WebRpcPort), nil, func() {})

+ 13 - 9
service/AuthService.go

@@ -2,8 +2,8 @@ package service
 
 import (
 	"app.yhyue.com/moapp/jybase/go-xweb/log"
+	"app.yhyue.com/moapp/jybase/mysql"
 	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/entity"
-	IC "bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/init"
 	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/medical"
 	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/resource"
 	"context"
@@ -12,12 +12,16 @@ import (
 	"time"
 )
 
-type AuthService struct{}
+type AuthService struct {
+	GoodsCode   string
+	GoodsSpecId int64
+	BasesqlConn *mysql.Mysql
+}
 
 //认证信息保存
 func (b AuthService) UserAuthInfoSave(in *medical.UserInfo) (bool, string) {
 	//先判断用户是否存在
-	user := entity.BaseMysql.FindOne(entity.DOMAIN_CAPITAL_RETENTION, map[string]interface{}{
+	user := b.BasesqlConn.FindOne(entity.DOMAIN_CAPITAL_RETENTION, map[string]interface{}{
 		"user_id": in.UserId, "appid": in.Appid,
 	}, "id", "")
 	if user != nil {
@@ -41,7 +45,7 @@ func (b AuthService) UserAuthInfoSave(in *medical.UserInfo) (bool, string) {
 			"ent_name":   in.EntName,
 			"source":     entity.MEDICALDOMAIN,
 		}
-		ok1 := entity.BaseMysql.Update(entity.DOMAIN_CAPITAL_RETENTION, map[string]interface{}{"user_id": in.UserId, "appid": in.Appid, "source": entity.MEDICALDOMAIN}, data)
+		ok1 := b.BasesqlConn.Update(entity.DOMAIN_CAPITAL_RETENTION, map[string]interface{}{"user_id": in.UserId, "appid": in.Appid, "source": entity.MEDICALDOMAIN}, data)
 		if ok1 {
 			return true, ""
 		} else {
@@ -63,8 +67,8 @@ func (b AuthService) UserAuthInfoSave(in *medical.UserInfo) (bool, string) {
 			"source":      entity.MEDICALDOMAIN,
 		}
 		msg := ""
-		ok := entity.BaseMysql.ExecTx("认证信息保存", func(tx *sql.Tx) bool {
-			ok1 := entity.BaseMysql.InsertByTx(tx, entity.DOMAIN_CAPITAL_RETENTION, data)
+		ok := b.BasesqlConn.ExecTx("认证信息保存", func(tx *sql.Tx) bool {
+			ok1 := b.BasesqlConn.InsertByTx(tx, entity.DOMAIN_CAPITAL_RETENTION, data)
 			if ok1 <= 0 {
 				log.Println(fmt.Sprintf("认证失败:参数:%v", data))
 				msg = "认证信息保存失败"
@@ -73,8 +77,8 @@ func (b AuthService) UserAuthInfoSave(in *medical.UserInfo) (bool, string) {
 			//开通权益
 			req := &resource.PowerReq{
 				Appid:       in.Appid,
-				GoodsCode:   IC.C.GoodsCode,
-				GoodsSpecId: IC.C.GoodsSpecId,
+				GoodsCode:   b.GoodsCode,
+				GoodsSpecId: b.GoodsSpecId,
 				EntId:       0,
 				UserId:      in.UserId,
 				BuyNum:      1,
@@ -95,7 +99,7 @@ func (b AuthService) UserAuthInfoSave(in *medical.UserInfo) (bool, string) {
 //认证信息查询
 func (b AuthService) UserAuthInfo(in *medical.CommonReq) *map[string]interface{} {
 	//先判断用户是否存在
-	user := entity.BaseMysql.FindOne(entity.DOMAIN_CAPITAL_RETENTION, map[string]interface{}{
+	user := b.BasesqlConn.FindOne(entity.DOMAIN_CAPITAL_RETENTION, map[string]interface{}{
 		"user_id": in.UserId, "appid": in.Appid, "source": entity.MEDICALDOMAIN,
 	}, "*", "")
 	return user

+ 2 - 4
service/AuthService_test.go

@@ -39,8 +39,7 @@ func TestAuthService_UserAuthInfo(t *testing.T) {
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			b := AuthService{}
-			if got := b.UserAuthInfo(tt.args.in); !reflect.DeepEqual(got, tt.want) {
+			if got := authService.UserAuthInfo(tt.args.in); !reflect.DeepEqual(got, tt.want) {
 				t.Errorf("UserAuthInfo() = %v, want %v", got, tt.want)
 			}
 		})
@@ -124,8 +123,7 @@ func TestAuthService_UserAuthInfoSave(t *testing.T) {
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			b := AuthService{}
-			got, got1 := b.UserAuthInfoSave(tt.args.in)
+			got, got1 := authService.UserAuthInfoSave(tt.args.in)
 			if got != tt.want {
 				t.Errorf("UserAuthInfoSave() got = %v, want %v", got, tt.want)
 			}

+ 14 - 10
service/InstitutionService.go

@@ -3,24 +3,28 @@ 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"
-	IC "bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/init"
 	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/medical"
 	"fmt"
 	"log"
 	"strings"
 )
 
-type InstitutionService struct{}
+type InstitutionService struct {
+	Bidfield   string
+	BasesqlCon *mysql.Mysql
+	MysqlConn  *mysql.Mysql
+}
 
 // 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 = entity.Mysql.SelectBySql(levelSql)
+	levelList = b.MysqlConn.SelectBySql(levelSql)
 	//医院等级
 	typeSql := fmt.Sprintf("select  * from %s where  name!='%s' and  level=1", entity.CODE_MEDICAL_INSTITUTION_TYPE, "其它")
-	typeList = entity.Mysql.SelectBySql(typeSql)
+	typeList = b.MysqlConn.SelectBySql(typeSql)
 	return
 }
 
@@ -97,7 +101,7 @@ func (b InstitutionService) Institution(in *medical.SearchInstitutionReq) (dataL
 	companyMap := make(map[string]map[string]interface{})
 	if len(*companyList) > 0 && companyList != nil {
 		//认领数据查询
-		companyIdMap := ClaimCompanyData(in.Appid, in.NewUserId, entity.TypeDistributor)
+		companyIdMap := b.ClaimCompanyData(in.Appid, in.NewUserId, entity.TypeDistributor)
 		for key, value := range *companyList {
 			if key > 0 {
 				companyName += `,`
@@ -122,7 +126,7 @@ func (b InstitutionService) Institution(in *medical.SearchInstitutionReq) (dataL
 	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, IC.C.Bidfield, orderField, orderType)
+	aggStr := fmt.Sprintf(`{"query":{"bool":{"must":[{"terms":{"buyer":[%s]}},{"terms":{"bidstatus":["中标","成交","合同"]}},{"term":{"bid_field":"%s"}}],"minimum_should_match":0}},"aggs":{"group_field":{"terms":{"field":"buyer","order":[{"%s":"%s"}]},"aggs":{"count":{"sum":{"field":"bidamount"}}}}},"size":0}`, companyName, b.Bidfield, orderField, orderType)
 	log.Println(aggStr)
 	countList := entity.GetAggs(entity.PROJECTSET_INDEX, entity.PROJECTSET_TYPE, aggStr)
 	//
@@ -210,7 +214,7 @@ func (b InstitutionService) Distributor(in *medical.SearchDistributorReq) (dataL
 	companyMap := make(map[string]map[string]interface{})
 	if len(*companyList) > 0 && companyList != nil {
 		//认领数据查询
-		companyIdMap := ClaimCompanyData(in.Appid, in.NewUserId, entity.TypeDistributor)
+		companyIdMap := b.ClaimCompanyData(in.Appid, in.NewUserId, entity.TypeDistributor)
 		for key, value := range *companyList {
 			if key > 0 {
 				companyIds += `,`
@@ -234,7 +238,7 @@ func (b InstitutionService) Distributor(in *medical.SearchDistributorReq) (dataL
 	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, IC.C.Bidfield, orderField, orderType)
+	aggStr := fmt.Sprintf(`{"query":{"bool":{"must":[{"terms":{"entidlist":[%s]}},{"terms":{"bidstatus":["中标","成交","合同"]}},{"term":{"bid_field":"%s"}}],"minimum_should_match":0}},"aggs":{"group_field":{"terms":{"field":"entidlist","order":[{"%s":"%s"}]},"aggs":{"count":{"sum":{"field":"bidamount"}}}}},"size":0}`, companyIds, b.Bidfield, orderField, orderType)
 	log.Println(aggStr)
 	countList := entity.GetAggs(entity.PROJECTSET_INDEX, entity.PROJECTSET_TYPE, aggStr)
 	if len(countList) > 0 && countList != nil {
@@ -259,8 +263,8 @@ func (b InstitutionService) Distributor(in *medical.SearchDistributorReq) (dataL
 // @param  appId 用户标识
 // @param  newUserId 用户标识
 // @param  claimType 数据类型
-func ClaimCompanyData(appId string, newUserId, claimType int64) map[string]map[string]interface{} {
-	claimList := entity.BaseMysql.Find(entity.TableDomainEntClaim, map[string]interface{}{
+func (b InstitutionService) ClaimCompanyData(appId string, newUserId, claimType int64) map[string]map[string]interface{} {
+	claimList := b.MysqlConn.Find(entity.TableDomainEntClaim, map[string]interface{}{
 		"user_id": newUserId,
 		"status":  1,
 		"type":    claimType,

+ 17 - 10
service/InstitutionService_test.go

@@ -13,10 +13,12 @@ import (
 )
 
 var EntClaimSrv EntClaimService
+var institutionService InstitutionService
+var authService AuthService
 
 func init() {
 	//医疗机构配置
-	entity.Mysql = &mysql.Mysql{
+	MysqlConn := &mysql.Mysql{
 		Address:      "192.168.3.217:4000",
 		UserName:     "root",
 		PassWord:     "=PDT49#80Z!RVv52_z",
@@ -24,8 +26,8 @@ func init() {
 		MaxOpenConns: 5,
 		MaxIdleConns: 5,
 	}
+	MysqlConn.Init()
 	//基本信息配置
-	entity.Mysql.Init()
 	BaseMysqlConn := &mysql.Mysql{
 		Address:      "192.168.3.217:4000",
 		UserName:     "root",
@@ -46,7 +48,7 @@ func init() {
 	}
 	CommonMysqlConn.Init()
 	MyConn := entity.Conn{
-		Mysql:            entity.Mysql,
+		Mysql:            MysqlConn,
 		BaseMysql:        BaseMysqlConn,
 		GlobalCommonData: CommonMysqlConn,
 	}
@@ -61,6 +63,14 @@ func init() {
 		},
 	})
 	entity.ResourceLib = resource.NewResource(resourceClient)
+	//医疗机构搜索
+	institutionService.Bidfield = "0101"
+	institutionService.BasesqlCon = BaseMysqlConn
+	institutionService.MysqlConn = MysqlConn
+	//认证需要参数
+	authService.GoodsCode = "lyh"
+	authService.GoodsSpecId = 13
+	authService.BasesqlConn = BaseMysqlConn
 }
 func TestInstitutionService_GetFilterItem(t *testing.T) {
 	tests := []struct {
@@ -75,8 +85,7 @@ func TestInstitutionService_GetFilterItem(t *testing.T) {
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			b := InstitutionService{}
-			gotLevelList, gotTypeList := b.GetFilterItem()
+			gotLevelList, gotTypeList := institutionService.GetFilterItem()
 			if !reflect.DeepEqual(gotLevelList, tt.wantLevelList) {
 				t.Errorf("GetFilterItem() gotLevelList = %v, want %v", gotLevelList, tt.wantLevelList)
 			}
@@ -116,8 +125,7 @@ func TestInstitutionService_Institution(t *testing.T) {
 	}
 	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) {
+			if gotLevelList := institutionService.Institution(tt.args.in); !reflect.DeepEqual(gotLevelList, tt.wantLevelList) {
 				t.Errorf("Institution() = %v, want %v", gotLevelList, tt.wantLevelList)
 			}
 		})
@@ -154,8 +162,7 @@ func TestInstitutionService_Distributor(t *testing.T) {
 	}
 	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) {
+			if gotDataList := institutionService.Distributor(tt.args.in); !reflect.DeepEqual(gotDataList, tt.wantDataList) {
 				t.Errorf("Distributor() = %v, want %v", gotDataList, tt.wantDataList)
 			}
 		})
@@ -206,7 +213,7 @@ func TestClaimCompanyData(t *testing.T) {
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			if got := ClaimCompanyData(tt.args.appId, tt.args.newUserId, tt.args.claimType); !reflect.DeepEqual(got, tt.want) {
+			if got := institutionService.ClaimCompanyData(tt.args.appId, tt.args.newUserId, tt.args.claimType); !reflect.DeepEqual(got, tt.want) {
 				t.Errorf("ClaimCompanyData() = %v, want %v", got, tt.want)
 			}
 		})