Sfoglia il codice sorgente

wip: claim 提交认领service

fuwencai 3 anni fa
parent
commit
51791ba7ed

+ 7 - 1
entity/code.go

@@ -4,7 +4,7 @@ package entity
 const (
 	CODE_MEDICAL_INSTITUTION_LEVEL = "code_medical_institution_level"
 	CODE_MEDICAL_INSTITUTION_TYPE  = "code_medical_institution_type"
-	DOMAIN_ENT_FOLLOW              = "domain_ent_follow"
+	TableDomainEntClaim            = "domain_ent_claim"
 )
 
 //返回状态
@@ -18,3 +18,9 @@ const (
 	TypeInstitution = 1 // 医疗机构
 	TypeDistributor = 2 // 经销商
 )
+
+// 认领状态
+const (
+	StatusClaimed   = 1  // 认领
+	StatusUnClaimed = -1 // 取消认领
+)

+ 5 - 0
entity/db.go

@@ -23,3 +23,8 @@ var (
 	Mysql     *mysql.Mysql
 	BaseMysql *mysql.Mysql
 )
+
+type Conn struct {
+	Mysql     *mysql.Mysql
+	BaseMysql *mysql.Mysql
+}

+ 17 - 0
entity/model.go

@@ -0,0 +1,17 @@
+package entity
+
+type EntClaim struct {
+	Id              string `json:"id,omitempty"`          // id
+	AppId           string `json:"appid"`                 // appid
+	UserId          int    `json:"user_id"`               // 用户id
+	EntId           string `json:"ent_id"`                // 企业id
+	EntName         string `json:"ent_name"`              // 企业名称
+	Status          int    `json:"status"`                // '状态;-1:取消认领 1:认领'
+	Type            int    `json:"type"`                  // '类型;1:医疗机构 2:经销商'
+	Address         string `json:"address"`               // 企业地址
+	EstablishDate   string `json:"establish_date"`        // 成立日期
+	RegisterCapital string `json:"regist_capital"`        // 注册资本
+	Phone           string `json:"phone"`                 // 联系方式
+	UpdateTime      string `json:"update_time,omitempty"` // 修改时间
+	CreateTime      string `json:"create_time"`           // 创建时间
+}

+ 24 - 23
rpc/medical/init/init.go

@@ -1,14 +1,13 @@
 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"
 	"flag"
+	"fmt"
 	_ "github.com/go-sql-driver/mysql"
 	"github.com/zeromicro/go-zero/core/conf"
-	"github.com/zeromicro/go-zero/core/logx"
 	"log"
 )
 
@@ -38,7 +37,7 @@ func init() {
 	nn := C.BaseMysqlMain
 	if nn.Address != "" {
 		log.Println("--初始化 mysql--")
-		entity.Mysql = &mysql.Mysql{
+		entity.BaseMysql = &mysql.Mysql{
 			Address:      nn.Address,
 			UserName:     nn.UserName,
 			PassWord:     nn.PassWord,
@@ -48,25 +47,27 @@ func init() {
 		}
 		entity.BaseMysql.Init()
 	}
-	//初始化 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, "--日志记录")
-			}
-		}
-	}
+	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, "--日志记录")
+	//		}
+	//	}
+	//}
 }

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

+ 54 - 0
rpc/medical/internal/logic/claimeddistributorlistlogic.go

@@ -0,0 +1,54 @@
+package logic
+
+import (
+	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/entity"
+	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/internal/svc"
+	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/medical"
+	"context"
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type ClaimedDistributorListLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewClaimedDistributorListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClaimedDistributorListLogic {
+	return &ClaimedDistributorListLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+// ClaimedDistributorList 我认领的经销商列表
+func (l *ClaimedDistributorListLogic) ClaimedDistributorList(in *medical.ClaimedReq) (*medical.CommonResp, error) {
+	//rs, total := l.svcCtx.EntClaimSrv.DistributorList(int(in.UserId), in.AppId, int(in.Page), int(in.PageSize))
+	//resultList := []medical.ClaimReq{}
+	//if rs!=nil{
+	//	//for i:=0;i<len(*rs);i++{
+	//	//	resultList = append(resultList,
+	//	//		medical.ClaimReq{
+	//	//		Id: common.Int64All((*rs)[i]["id"]),
+	//	//		AppId: (*rs)[i]["appid"],
+	//	//		Id: common.Int64All((*rs)[i]["ent_id"]),
+	//	//		Id: common.Int64All((*rs)[i]["ent_name"]),
+	//	//		Id: common.Int64All((*rs)[i]["address"]),
+	//	//		Id: common.Int64All((*rs)[i]["establish_date"]),
+	//	//		Id: common.Int64All((*rs)[i]["regist_capital"]),
+	//	//		Id: common.Int64All((*rs)[i]["phone"]),
+	//	//		Id: common.Int64All((*rs)[i]["update_time"]),
+	//	//		: common.Int64All((*rs)[i]["create_time"]),
+	//	//
+	//	//		}
+	//	//		)
+	//	//}
+	//}
+
+	return &medical.CommonResp{
+		ErrorMsg:  "",
+		ErrorCode: entity.ERRORCODE,
+		Data:      nil,
+	}, nil
+}

+ 31 - 0
rpc/medical/internal/logic/claimedinstitutionlistlogic.go

@@ -0,0 +1,31 @@
+package logic
+
+import (
+	"context"
+
+	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/internal/svc"
+	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/medical"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type ClaimedInstitutionListLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewClaimedInstitutionListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClaimedInstitutionListLogic {
+	return &ClaimedInstitutionListLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+// ClaimedInstitutionList 我认领的医疗机构列表
+func (l *ClaimedInstitutionListLogic) ClaimedInstitutionList(in *medical.ClaimedReq) (*medical.CommonResp, error) {
+	// todo: add your logic here and delete this line
+
+	return &medical.CommonResp{}, nil
+}

+ 54 - 0
rpc/medical/internal/logic/claimlogic.go

@@ -0,0 +1,54 @@
+package logic
+
+import (
+	"app.yhyue.com/moapp/jybase/date"
+	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/entity"
+	"context"
+
+	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/internal/svc"
+	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/medical"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type ClaimLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewClaimLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClaimLogic {
+	return &ClaimLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+// Claim 认领(经销商/医疗机构)
+func (l *ClaimLogic) Claim(in *medical.ClaimReq) (*medical.CommonResp, error) {
+
+	rs := l.svcCtx.EntClaimSrv.Claim(&entity.EntClaim{
+		AppId:           in.AppId,
+		UserId:          int(in.UserId),
+		EntId:           in.EntId,
+		EntName:         in.EntName,
+		Status:          entity.StatusClaimed,
+		Type:            int(in.Type),
+		Address:         in.Address,
+		EstablishDate:   in.EstablishDate,
+		RegisterCapital: in.RegisterCapital,
+		Phone:           in.Phone,
+		CreateTime:      date.NowFormat(date.Date_Full_Layout),
+	})
+	if !rs {
+		return &medical.CommonResp{
+			ErrorMsg:  "操作失败",
+			ErrorCode: entity.ERRORCODE,
+		}, nil
+	}
+	return &medical.CommonResp{
+		ErrorMsg:  "",
+		ErrorCode: entity.ERRORCODE,
+	}, nil
+}

+ 6 - 5
rpc/medical/internal/logic/pinglogic.go → rpc/medical/internal/logic/isclaimedlogic.go

@@ -9,22 +9,23 @@ import (
 	"github.com/zeromicro/go-zero/core/logx"
 )
 
-type PingLogic struct {
+type IsClaimedLogic struct {
 	ctx    context.Context
 	svcCtx *svc.ServiceContext
 	logx.Logger
 }
 
-func NewPingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PingLogic {
-	return &PingLogic{
+func NewIsClaimedLogic(ctx context.Context, svcCtx *svc.ServiceContext) *IsClaimedLogic {
+	return &IsClaimedLogic{
 		ctx:    ctx,
 		svcCtx: svcCtx,
 		Logger: logx.WithContext(ctx),
 	}
 }
 
-func (l *PingLogic) Ping(in *medical.Request) (*medical.Response, error) {
+//  是否认领(经销商/医疗机构)
+func (l *IsClaimedLogic) IsClaimed(in *medical.IsClaimedReq) (*medical.CommonResp, error) {
 	// todo: add your logic here and delete this line
 
-	return &medical.Response{}, nil
+	return &medical.CommonResp{}, nil
 }

+ 6 - 5
rpc/medical/internal/logic/pingelogic.go → rpc/medical/internal/logic/unclaimedlogic.go

@@ -9,22 +9,23 @@ import (
 	"github.com/zeromicro/go-zero/core/logx"
 )
 
-type PingeLogic struct {
+type UnClaimedLogic struct {
 	ctx    context.Context
 	svcCtx *svc.ServiceContext
 	logx.Logger
 }
 
-func NewPingeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PingeLogic {
-	return &PingeLogic{
+func NewUnClaimedLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UnClaimedLogic {
+	return &UnClaimedLogic{
 		ctx:    ctx,
 		svcCtx: svcCtx,
 		Logger: logx.WithContext(ctx),
 	}
 }
 
-func (l *PingeLogic) Pinge(in *medical.Request) (*medical.Response, error) {
+//  取消认领(经销商/医疗机构)
+func (l *UnClaimedLogic) UnClaimed(in *medical.UnclaimedReq) (*medical.CommonResp, error) {
 	// todo: add your logic here and delete this line
 
-	return &medical.Response{}, nil
+	return &medical.CommonResp{}, nil
 }

+ 30 - 0
rpc/medical/internal/server/medicalserver.go

@@ -39,3 +39,33 @@ func (s *MedicalServer) Distributor(ctx context.Context, in *medical.SearchDistr
 	l := logic.NewDistributorLogic(ctx, s.svcCtx)
 	return l.Distributor(in)
 }
+
+//  认领(经销商/医疗机构)
+func (s *MedicalServer) Claim(ctx context.Context, in *medical.ClaimReq) (*medical.CommonResp, error) {
+	l := logic.NewClaimLogic(ctx, s.svcCtx)
+	return l.Claim(in)
+}
+
+//  取消认领(经销商/医疗机构)
+func (s *MedicalServer) UnClaimed(ctx context.Context, in *medical.UnclaimedReq) (*medical.CommonResp, error) {
+	l := logic.NewUnClaimedLogic(ctx, s.svcCtx)
+	return l.UnClaimed(in)
+}
+
+//  是否认领(经销商/医疗机构)
+func (s *MedicalServer) IsClaimed(ctx context.Context, in *medical.IsClaimedReq) (*medical.CommonResp, error) {
+	l := logic.NewIsClaimedLogic(ctx, s.svcCtx)
+	return l.IsClaimed(in)
+}
+
+//  我认领的经销商列表
+func (s *MedicalServer) ClaimedDistributorList(ctx context.Context, in *medical.ClaimedReq) (*medical.CommonResp, error) {
+	l := logic.NewClaimedDistributorListLogic(ctx, s.svcCtx)
+	return l.ClaimedDistributorList(in)
+}
+
+//  我认领的医疗机构列表
+func (s *MedicalServer) ClaimedInstitutionList(ctx context.Context, in *medical.ClaimedReq) (*medical.CommonResp, error) {
+	l := logic.NewClaimedInstitutionListLogic(ctx, s.svcCtx)
+	return l.ClaimedInstitutionList(in)
+}

+ 11 - 3
rpc/medical/internal/svc/servicecontext.go

@@ -1,13 +1,21 @@
 package svc
 
-import "bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/internal/config"
+import (
+	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/entity"
+	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/internal/config"
+	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/service"
+	"fmt"
+)
 
 type ServiceContext struct {
-	Config config.Config
+	Config      config.Config
+	EntClaimSrv *service.EntClaimService
 }
 
 func NewServiceContext(c config.Config) *ServiceContext {
+	fmt.Println(entity.BaseMysql, entity.BaseMysql == nil)
 	return &ServiceContext{
-		Config: c,
+		Config:      c,
+		EntClaimSrv: service.NewEntClaimSrv(&entity.Conn{Mysql: entity.Mysql, BaseMysql: entity.BaseMysql}), // 手动添加 认领相关
 	}
 }

+ 1 - 0
rpc/medical/medical.go

@@ -9,6 +9,7 @@ import (
 	"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/rpc/medical/init"
 	"github.com/zeromicro/go-zero/core/conf"
 	"github.com/zeromicro/go-zero/core/service"
 	"github.com/zeromicro/go-zero/zrpc"

+ 101 - 51
rpc/medical/medical.proto

@@ -1,84 +1,124 @@
 syntax = "proto3";
 
 package medical;
-option go_package="./medical";
+option go_package = "./medical";
+import "google/protobuf/any.proto";
 
-message Request {
-  string ping = 1;
-}
-
-message Response {
-  string pong = 1;
-}
 
 message SearchInstitutionReq {
-  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      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;
 }
 message SearchDistributorReq {
-  string      companyName     =1;          // 要搜索的经销商
-  string      areaCode        =2;          // 区域代码
-  string      BusinessScope   =3;          // 业务范围
-  string      brand           =4;          // 品牌
-  int64         ProductModel    =5;        // 产品型号
-  string      countOrder      =6;          // 项目数量排序 0-不排序 1-数量倒序
-  string      moneyOrder      =7;          // 金额数量排序:0- 不参与排序  1-按金额倒序
-  int64         page            =8;
-  int64         pageSize        =9;
+  string      companyName = 1;          // 要搜索的经销商
+  string      areaCode = 2;          // 区域代码
+  string      BusinessScope = 3;          // 业务范围
+  string      brand = 4;          // 品牌
+  int64         ProductModel = 5;        // 产品型号
+  string      countOrder = 6;          // 项目数量排序 0-不排序 1-数量倒序
+  string      moneyOrder = 7;          // 金额数量排序:0- 不参与排序  1-按金额倒序
+  int64         page = 8;
+  int64         pageSize = 9;
 }
 message CompanyData {
-  string      company_id     =1;          // 唯一标识
-  string      company_name   =2;          // 机构名称
-  string      area           =3;          // 区域
-  string      project_money  =4;          // 项目总金额
-  int64         project_count  =5;          // 项目总数
-  int64         follow         =6;          // 是否关注 1-关注 0:-未关注
+  string      company_id = 1;          // 唯一标识
+  string      company_name = 2;          // 机构名称
+  string      area = 3;          // 区域
+  string      project_money = 4;          // 项目总金额
+  int64         project_count = 5;          // 项目总数
+  int64         follow = 6;          // 是否关注 1-关注 0:-未关注
 }
 message CompanyDataList {
-  repeated     CompanyData list     =1;   // 唯一标识
-  int64          total                =2;   // 总数
+  repeated     CompanyData list = 1;   // 唯一标识
+  int64          total = 2;   // 总数
 
 }
 message CompanyResp {
-  int64             error_code=1;          // 唯一标识
-  string          error_msg   =2;        // 机构名称
-  CompanyDataList  data       =3;    // 区域
+  int64             error_code = 1;          // 唯一标识
+  string          error_msg = 2;        // 机构名称
+  CompanyDataList  data = 3;    // 区域
 }
 //医院等级
 message LevelCode {
-  string             code     =1;          // 代码
-  string             pcode    =2;          // 父级代码
-  string             level    =3;
-  string             name     =4;          // 名称
+  string             code = 1;          // 代码
+  string             pcode = 2;          // 父级代码
+  string             level = 3;
+  string             name = 4;          // 名称
 }
 //机构类型
 message MiTypeCode {
-  string             code     =1;          // 代码
-  string             pcode    =2;          // 父级代码
-  string             level    =3;
-  string             name     =4;          // 名称
+  string             code = 1;          // 代码
+  string             pcode = 2;          // 父级代码
+  string             level = 3;
+  string             name = 4;          // 名称
 }
 message FilterItem{
-  repeated LevelCode level_code=1;
-  repeated MiTypeCode mi_type_code=2;
+  repeated LevelCode level_code = 1;
+  repeated MiTypeCode mi_type_code = 2;
 }
 
 message FilterItemResp{
-  int64           error_code  =1;          // 唯一标识
-  string          error_msg   =2;        // 机构名称
-  FilterItem      data        =3;
+  int64           error_code = 1;          // 唯一标识
+  string          error_msg = 2;        // 机构名称
+  FilterItem      data = 3;
 }
 message  Zero{
 
 }
+// 认领
+message ClaimReq{
+  int64 Id = 10;
+  int64 UserId = 1 ;// 用户id
+  string EntId = 2 ;// 公司id
+  string EntName = 3 ;// 公司名称
+  int64 Type = 4 ;// 类型;1:医疗机构 2:经销商'
+  string Address = 5 ;// 企业地址
+  string EstablishDate = 6 ;// 成立日期
+  string RegisterCapital = 7 ;// 注册资本
+  string Phone = 8 ;// 联系方式
+  string AppId = 9 ;//appid
+}
+// 取消认领
+message UnclaimedReq{
+  int64  UserId = 1 ;// 用户id
+  int64  Id = 2; // 认领记录id
+  string AppId = 3 ;//appid
+}
+// 是否是认领的
+message IsClaimedReq{
+  int64  UserId = 1 ;// 用户id
+  int64  Id = 2; // 认领记录id
+  string AppId = 3 ;//appid
+}
+// 我认领的
+message ClaimedReq{
+  int64  UserId = 1 ;// 用户id
+  string AppId = 2 ;//appid
+  int64  Page = 3; // 认领记录id
+  int64 PageSize = 4 ;//appid
+}
+// 响应
+message CommonResp{
+  int64           ErrorCode = 1;  // 响应代码
+  string          ErrorMsg = 2;   // 响应信息
+  google.protobuf.Any Data = 3;   // 响应数据
+}
+
+
+//
+message ClaimList{
+  int64 Total = 1;
+  repeated ClaimedReq  List = 2;
+}
+//
 service Medical {
   //搜索医疗机构
   rpc Institution(SearchInstitutionReq) returns(CompanyResp);
@@ -86,5 +126,15 @@ service Medical {
   rpc GetFilterItem (Zero) returns(FilterItemResp);
   //搜索经销商
   rpc Distributor(SearchDistributorReq) returns(CompanyResp);
+  // 认领(经销商/医疗机构)
+  rpc Claim(ClaimReq) returns(CommonResp);
+  // 取消认领(经销商/医疗机构)
+  rpc UnClaimed(UnclaimedReq) returns(CommonResp);
+  // 是否认领(经销商/医疗机构)
+  rpc IsClaimed(IsClaimedReq) returns(CommonResp);
+  // 我认领的经销商列表
+  rpc ClaimedDistributorList(ClaimedReq) returns(CommonResp);
+  // 我认领的医疗机构列表
+  rpc ClaimedInstitutionList(ClaimedReq) returns(CommonResp);
 
 }

+ 40 - 0
rpc/medical/medical/medical.go

@@ -18,6 +18,16 @@ type (
 		GetFilterItem(ctx context.Context, in *Zero, opts ...grpc.CallOption) (*FilterItemResp, error)
 		// 搜索经销商
 		Distributor(ctx context.Context, in *SearchDistributorReq, opts ...grpc.CallOption) (*CompanyResp, error)
+		//  认领(经销商/医疗机构)
+		Claim(ctx context.Context, in *ClaimReq, opts ...grpc.CallOption) (*CommonResp, error)
+		//  取消认领(经销商/医疗机构)
+		UnClaimed(ctx context.Context, in *UnclaimedReq, opts ...grpc.CallOption) (*CommonResp, error)
+		//  是否认领(经销商/医疗机构)
+		IsClaimed(ctx context.Context, in *IsClaimedReq, opts ...grpc.CallOption) (*CommonResp, error)
+		//  我认领的经销商列表
+		ClaimedDistributorList(ctx context.Context, in *ClaimedReq, opts ...grpc.CallOption) (*CommonResp, error)
+		//  我认领的医疗机构列表
+		ClaimedInstitutionList(ctx context.Context, in *ClaimedReq, opts ...grpc.CallOption) (*CommonResp, error)
 	}
 
 	defaultMedical struct {
@@ -48,3 +58,33 @@ func (m *defaultMedical) Distributor(ctx context.Context, in *SearchDistributorR
 	client := NewMedicalClient(m.cli.Conn())
 	return client.Distributor(ctx, in, opts...)
 }
+
+//  认领(经销商/医疗机构)
+func (m *defaultMedical) Claim(ctx context.Context, in *ClaimReq, opts ...grpc.CallOption) (*CommonResp, error) {
+	client := NewMedicalClient(m.cli.Conn())
+	return client.Claim(ctx, in, opts...)
+}
+
+//  取消认领(经销商/医疗机构)
+func (m *defaultMedical) UnClaimed(ctx context.Context, in *UnclaimedReq, opts ...grpc.CallOption) (*CommonResp, error) {
+	client := NewMedicalClient(m.cli.Conn())
+	return client.UnClaimed(ctx, in, opts...)
+}
+
+//  是否认领(经销商/医疗机构)
+func (m *defaultMedical) IsClaimed(ctx context.Context, in *IsClaimedReq, opts ...grpc.CallOption) (*CommonResp, error) {
+	client := NewMedicalClient(m.cli.Conn())
+	return client.IsClaimed(ctx, in, opts...)
+}
+
+//  我认领的经销商列表
+func (m *defaultMedical) ClaimedDistributorList(ctx context.Context, in *ClaimedReq, opts ...grpc.CallOption) (*CommonResp, error) {
+	client := NewMedicalClient(m.cli.Conn())
+	return client.ClaimedDistributorList(ctx, in, opts...)
+}
+
+//  我认领的医疗机构列表
+func (m *defaultMedical) ClaimedInstitutionList(ctx context.Context, in *ClaimedReq, opts ...grpc.CallOption) (*CommonResp, error) {
+	client := NewMedicalClient(m.cli.Conn())
+	return client.ClaimedInstitutionList(ctx, in, opts...)
+}

File diff suppressed because it is too large
+ 644 - 235
rpc/medical/medical/medical.pb.go


+ 191 - 1
rpc/medical/medical/medical_grpc.pb.go

@@ -1,7 +1,7 @@
 // Code generated by protoc-gen-go-grpc. DO NOT EDIT.
 // versions:
 // - protoc-gen-go-grpc v1.2.0
-// - protoc             v3.15.1
+// - protoc             v3.19.4
 // source: medical.proto
 
 package medical
@@ -28,6 +28,16 @@ type MedicalClient interface {
 	GetFilterItem(ctx context.Context, in *Zero, opts ...grpc.CallOption) (*FilterItemResp, error)
 	//搜索经销商
 	Distributor(ctx context.Context, in *SearchDistributorReq, opts ...grpc.CallOption) (*CompanyResp, error)
+	// 认领(经销商/医疗机构)
+	Claim(ctx context.Context, in *ClaimReq, opts ...grpc.CallOption) (*CommonResp, error)
+	// 取消认领(经销商/医疗机构)
+	UnClaimed(ctx context.Context, in *UnclaimedReq, opts ...grpc.CallOption) (*CommonResp, error)
+	// 是否认领(经销商/医疗机构)
+	IsClaimed(ctx context.Context, in *IsClaimedReq, opts ...grpc.CallOption) (*CommonResp, error)
+	// 我认领的经销商列表
+	ClaimedDistributorList(ctx context.Context, in *ClaimedReq, opts ...grpc.CallOption) (*CommonResp, error)
+	// 我认领的医疗机构列表
+	ClaimedInstitutionList(ctx context.Context, in *ClaimedReq, opts ...grpc.CallOption) (*CommonResp, error)
 }
 
 type medicalClient struct {
@@ -65,6 +75,51 @@ func (c *medicalClient) Distributor(ctx context.Context, in *SearchDistributorRe
 	return out, nil
 }
 
+func (c *medicalClient) Claim(ctx context.Context, in *ClaimReq, opts ...grpc.CallOption) (*CommonResp, error) {
+	out := new(CommonResp)
+	err := c.cc.Invoke(ctx, "/medical.Medical/Claim", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
+func (c *medicalClient) UnClaimed(ctx context.Context, in *UnclaimedReq, opts ...grpc.CallOption) (*CommonResp, error) {
+	out := new(CommonResp)
+	err := c.cc.Invoke(ctx, "/medical.Medical/UnClaimed", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
+func (c *medicalClient) IsClaimed(ctx context.Context, in *IsClaimedReq, opts ...grpc.CallOption) (*CommonResp, error) {
+	out := new(CommonResp)
+	err := c.cc.Invoke(ctx, "/medical.Medical/IsClaimed", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
+func (c *medicalClient) ClaimedDistributorList(ctx context.Context, in *ClaimedReq, opts ...grpc.CallOption) (*CommonResp, error) {
+	out := new(CommonResp)
+	err := c.cc.Invoke(ctx, "/medical.Medical/ClaimedDistributorList", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
+func (c *medicalClient) ClaimedInstitutionList(ctx context.Context, in *ClaimedReq, opts ...grpc.CallOption) (*CommonResp, error) {
+	out := new(CommonResp)
+	err := c.cc.Invoke(ctx, "/medical.Medical/ClaimedInstitutionList", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
 // MedicalServer is the server API for Medical service.
 // All implementations must embed UnimplementedMedicalServer
 // for forward compatibility
@@ -75,6 +130,16 @@ type MedicalServer interface {
 	GetFilterItem(context.Context, *Zero) (*FilterItemResp, error)
 	//搜索经销商
 	Distributor(context.Context, *SearchDistributorReq) (*CompanyResp, error)
+	// 认领(经销商/医疗机构)
+	Claim(context.Context, *ClaimReq) (*CommonResp, error)
+	// 取消认领(经销商/医疗机构)
+	UnClaimed(context.Context, *UnclaimedReq) (*CommonResp, error)
+	// 是否认领(经销商/医疗机构)
+	IsClaimed(context.Context, *IsClaimedReq) (*CommonResp, error)
+	// 我认领的经销商列表
+	ClaimedDistributorList(context.Context, *ClaimedReq) (*CommonResp, error)
+	// 我认领的医疗机构列表
+	ClaimedInstitutionList(context.Context, *ClaimedReq) (*CommonResp, error)
 	mustEmbedUnimplementedMedicalServer()
 }
 
@@ -91,6 +156,21 @@ func (UnimplementedMedicalServer) GetFilterItem(context.Context, *Zero) (*Filter
 func (UnimplementedMedicalServer) Distributor(context.Context, *SearchDistributorReq) (*CompanyResp, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method Distributor not implemented")
 }
+func (UnimplementedMedicalServer) Claim(context.Context, *ClaimReq) (*CommonResp, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method Claim not implemented")
+}
+func (UnimplementedMedicalServer) UnClaimed(context.Context, *UnclaimedReq) (*CommonResp, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method UnClaimed not implemented")
+}
+func (UnimplementedMedicalServer) IsClaimed(context.Context, *IsClaimedReq) (*CommonResp, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method IsClaimed not implemented")
+}
+func (UnimplementedMedicalServer) ClaimedDistributorList(context.Context, *ClaimedReq) (*CommonResp, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method ClaimedDistributorList not implemented")
+}
+func (UnimplementedMedicalServer) ClaimedInstitutionList(context.Context, *ClaimedReq) (*CommonResp, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method ClaimedInstitutionList not implemented")
+}
 func (UnimplementedMedicalServer) mustEmbedUnimplementedMedicalServer() {}
 
 // UnsafeMedicalServer may be embedded to opt out of forward compatibility for this service.
@@ -158,6 +238,96 @@ func _Medical_Distributor_Handler(srv interface{}, ctx context.Context, dec func
 	return interceptor(ctx, in, info, handler)
 }
 
+func _Medical_Claim_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(ClaimReq)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(MedicalServer).Claim(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/medical.Medical/Claim",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(MedicalServer).Claim(ctx, req.(*ClaimReq))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
+func _Medical_UnClaimed_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(UnclaimedReq)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(MedicalServer).UnClaimed(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/medical.Medical/UnClaimed",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(MedicalServer).UnClaimed(ctx, req.(*UnclaimedReq))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
+func _Medical_IsClaimed_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(IsClaimedReq)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(MedicalServer).IsClaimed(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/medical.Medical/IsClaimed",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(MedicalServer).IsClaimed(ctx, req.(*IsClaimedReq))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
+func _Medical_ClaimedDistributorList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(ClaimedReq)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(MedicalServer).ClaimedDistributorList(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/medical.Medical/ClaimedDistributorList",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(MedicalServer).ClaimedDistributorList(ctx, req.(*ClaimedReq))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
+func _Medical_ClaimedInstitutionList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(ClaimedReq)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(MedicalServer).ClaimedInstitutionList(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/medical.Medical/ClaimedInstitutionList",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(MedicalServer).ClaimedInstitutionList(ctx, req.(*ClaimedReq))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
 // Medical_ServiceDesc is the grpc.ServiceDesc for Medical service.
 // It's only intended for direct use with grpc.RegisterService,
 // and not to be introspected or modified (even as a copy)
@@ -177,6 +347,26 @@ var Medical_ServiceDesc = grpc.ServiceDesc{
 			MethodName: "Distributor",
 			Handler:    _Medical_Distributor_Handler,
 		},
+		{
+			MethodName: "Claim",
+			Handler:    _Medical_Claim_Handler,
+		},
+		{
+			MethodName: "UnClaimed",
+			Handler:    _Medical_UnClaimed_Handler,
+		},
+		{
+			MethodName: "IsClaimed",
+			Handler:    _Medical_IsClaimed_Handler,
+		},
+		{
+			MethodName: "ClaimedDistributorList",
+			Handler:    _Medical_ClaimedDistributorList_Handler,
+		},
+		{
+			MethodName: "ClaimedInstitutionList",
+			Handler:    _Medical_ClaimedInstitutionList_Handler,
+		},
 	},
 	Streams:  []grpc.StreamDesc{},
 	Metadata: "medical.proto",

+ 17 - 0
service/InstitutionService_test.go

@@ -7,6 +7,8 @@ import (
 	"testing"
 )
 
+var EntClaimSrv EntClaimService
+
 func initMysql() {
 	entity.Mysql = &mysql.Mysql{
 		Address:      "192.168.3.217:4000",
@@ -17,6 +19,21 @@ func initMysql() {
 		MaxIdleConns: 5,
 	}
 	entity.Mysql.Init()
+
+	BaseMysqlConn := &mysql.Mysql{
+		Address:      "192.168.3.217:4000",
+		UserName:     "root",
+		PassWord:     "=PDT49#80Z!RVv52_z",
+		DBName:       "base_service",
+		MaxOpenConns: 5,
+		MaxIdleConns: 5,
+	}
+	BaseMysqlConn.Init()
+	MyConn := entity.Conn{
+		Mysql:     entity.Mysql,
+		BaseMysql: BaseMysqlConn,
+	}
+	EntClaimSrv = *NewEntClaimSrv(&MyConn)
 }
 func init() {
 	initMysql()

+ 96 - 0
service/claim.go

@@ -0,0 +1,96 @@
+package service
+
+import (
+	"app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/date"
+	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/entity"
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+// EntClaimService 企业认领
+type EntClaimService struct {
+	*entity.Conn
+}
+
+// NewEntClaimSrv 创建一个EntClaimSrv实例
+func NewEntClaimSrv(conn *entity.Conn) *EntClaimService {
+	return &EntClaimService{
+		conn,
+	}
+}
+
+// Claim 认领
+func (e *EntClaimService) Claim(data *entity.EntClaim) bool {
+	return e.BaseMysql.Insert(entity.TableDomainEntClaim, common.StructToMapMore(data)) > 0
+}
+
+// Unclaimed // 取消认领
+func (e *EntClaimService) Unclaimed(id, userId int) bool {
+	query := map[string]interface{}{
+		"id": id,
+	}
+	// 1. 查询该条数据
+	rs := e.BaseMysql.FindOne(entity.TableDomainEntClaim, query, "user_id", "")
+	if rs == nil || len(*rs) == 0 {
+		logx.Errorf("取消认领:无效的id %v", id)
+		return false
+	}
+	// 2. 存在则判断是否是该用户的
+	rsUerId := common.IntAll((*rs)["user_id"])
+	if rsUerId != userId {
+		logx.Errorf("取消认领:id[%v]与用户id[%v]不匹配 ", id, userId)
+		return false
+	}
+	// 3. 取消认领
+	update := map[string]interface{}{
+		"status":      entity.StatusUnClaimed,
+		"update_time": date.NowFormat(date.Date_Full_Layout),
+	}
+	return e.BaseMysql.Update(entity.TableDomainEntClaim, query, update)
+}
+
+// IsClaimed 是否认领
+func (e *EntClaimService) IsClaimed(userId int, appId string, entId int, typeCode int) bool {
+	query := map[string]interface{}{
+		"user_id": userId,
+		"type":    typeCode,
+		"ent_id":  entId,
+		"status":  entity.StatusClaimed,
+	}
+	return e.BaseMysql.Count(entity.TableDomainEntClaim, query) > 0
+}
+
+// DistributorList 关注的经销商列表
+func (e *EntClaimService) DistributorList(userId int, appId string, page int, pageSize int) (*[]map[string]interface{}, int) {
+
+	query := map[string]interface{}{
+		"user_id": userId,
+		"appid":   appId,
+		"type":    entity.TypeDistributor,
+		"status":  entity.StatusClaimed,
+	}
+	field := "id,appid,user_id,ent_id,ent_name,address,create_time"
+	order := "create_time desc"
+	total := e.BaseMysql.Count(entity.TableDomainEntClaim, query)
+	if total == 0 {
+		return nil, 0
+	}
+	return e.BaseMysql.Find(entity.TableDomainEntClaim, query, field, order, (page-1)*pageSize, pageSize), int(total)
+}
+
+// InstitutionList  我关注的医疗机构列表
+func (e *EntClaimService) InstitutionList(userId int, appId string, page int, pageSize int) (*[]map[string]interface{}, int) {
+	query := map[string]interface{}{
+		"user_id": userId,
+		"appid":   appId,
+		"type":    entity.TypeInstitution,
+		"status":  entity.StatusClaimed,
+	}
+	field := "id,appid,user_id,ent_id,ent_name,address,create_time"
+	order := "create_time desc"
+	total := e.BaseMysql.Count(entity.TableDomainEntClaim, query)
+	if total == 0 {
+		return nil, 0
+	}
+	return e.BaseMysql.Find(entity.TableDomainEntClaim, query, field, order, (page-1)*pageSize, pageSize), int(total)
+}

+ 129 - 0
service/claim_test.go

@@ -0,0 +1,129 @@
+package service
+
+import (
+	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/entity"
+	"reflect"
+	"testing"
+)
+
+// 认领
+func TestEntClaimService_Claim(t *testing.T) {
+
+	type args struct {
+		data *entity.EntClaim
+	}
+	tests := []struct {
+		name string
+		args args
+		want bool
+	}{
+		{"认领医疗机构", args{
+			data: &entity.EntClaim{UserId: 1, AppId: "10000", EntId: "11", EntName: "877", Status: entity.StatusClaimed, Type: entity.TypeInstitution, Address: "2223", EstablishDate: "2022", RegisterCapital: "dd", Phone: "18238182402", CreateTime: "2022-08-19 15:08:00"},
+		}, true,
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+
+			if got := EntClaimSrv.Claim(tt.args.data); got != tt.want {
+				t.Errorf("Claim() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
+
+// 我认领的经销商的列表
+func TestEntClaimService_DistributorList(t *testing.T) {
+	type args struct {
+		userId   int
+		appId    string
+		page     int
+		pageSize int
+	}
+	tests := []struct {
+		name string
+		args args
+		want *[]map[string]interface{}
+	}{
+		{
+			name: "我认领的医疗机构", args: args{userId: 1, appId: "10000", page: 1, pageSize: 10}, want: nil,
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			if got, _ := EntClaimSrv.DistributorList(tt.args.userId, tt.args.appId, tt.args.page, tt.args.pageSize); !reflect.DeepEqual(got, tt.want) {
+				t.Errorf("DistributorList() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
+
+// 我认领的机构列表
+func TestEntClaimService_InstitutionList(t *testing.T) {
+	type args struct {
+		userId   int
+		appId    string
+		page     int
+		pageSize int
+	}
+	tests := []struct {
+		name string
+		args args
+		want *[]map[string]interface{}
+	}{
+		// TODO: Add test cases.
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			if got, _ := EntClaimSrv.InstitutionList(tt.args.userId, tt.args.appId, tt.args.page, tt.args.pageSize); !reflect.DeepEqual(got, tt.want) {
+				t.Errorf("InstitutionList() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
+
+// 是否认领
+func TestEntClaimService_IsClaimed(t *testing.T) {
+	type args struct {
+		userId   int
+		appId    string
+		entId    int
+		typeCode int
+	}
+	tests := []struct {
+		name string
+		args args
+		want bool
+	}{
+		// TODO: Add test cases.
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			if got := EntClaimSrv.IsClaimed(tt.args.userId, tt.args.appId, tt.args.entId, tt.args.typeCode); got != tt.want {
+				t.Errorf("IsClaimed() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
+
+// 取消认领
+func TestEntClaimService_Unclaimed(t *testing.T) {
+	type args struct {
+		id     int
+		userId int
+	}
+	tests := []struct {
+		name string
+		args args
+		want bool
+	}{
+		// TODO: Add test cases.
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			if got := EntClaimSrv.Unclaimed(tt.args.id, tt.args.userId); got != tt.want {
+				t.Errorf("Unclaimed() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}

+ 8 - 0
test/rpc_test.http

@@ -0,0 +1,8 @@
+GRPC {{host}}:8080/medical.Medical/ClaimedDistributorList
+
+{
+  "AppId": "1000",
+  "UserId": 1,
+  "Page": 0,
+  "PageSize": 10
+}

Some files were not shown because too many files changed in this diff