fuwencai 4 سال پیش
والد
کامیت
0076de2be4

+ 13 - 1
api/deduplication.api

@@ -11,7 +11,7 @@ type (
 	Info {
 		TotalCount int64 `json:"totalCount"` // 本次查询info_id总量
 		ExistCount int64 `json:"existCount"` // 已存在的info_id的数量
-		NewCount   int64 `json:"NewCount"`   // 不存在的info_id的数量
+		NewCount   int64 `json:"newCount"`   // 不存在的info_id的数量
 	}
 
 	DedupReq {
@@ -28,7 +28,19 @@ type (
 	}
 )
 
+type (
+	EntCountReq {
+		EntId string `form:"entId"` // 企业id
+	}
+	EntCountResp {
+		Code int64  `json:"code"`
+		Msg  string `json:"msg"`
+		Data int64  `json:"data"`
+	}
+)
 service deduplication-api {
 	@handler Datadeduplication // 调用数据去重
 	post /data/deduplication (DedupReq) returns (DedupResp)
+	@handler GetEntCount // 调用数据去重
+	post /data/getEntCount (EntCountReq) returns (EntCountResp)
 }

+ 29 - 0
api/internal/handler/getentcounthandler.go

@@ -0,0 +1,29 @@
+package handler
+
+import (
+	"net/http"
+
+	"app.yhyue.com/moapp/dataDeduplication/api/internal/logic"
+	"app.yhyue.com/moapp/dataDeduplication/api/internal/svc"
+	"app.yhyue.com/moapp/dataDeduplication/api/internal/types"
+
+	"github.com/tal-tech/go-zero/rest/httpx"
+)
+
+func GetEntCountHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.EntCountReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewGetEntCountLogic(r.Context(), ctx)
+		resp, err := l.GetEntCount(req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 5 - 0
api/internal/handler/routes.go

@@ -17,6 +17,11 @@ func RegisterHandlers(engine *rest.Server, serverCtx *svc.ServiceContext) {
 				Path:    "/data/deduplication",
 				Handler: DatadeduplicationHandler(serverCtx),
 			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/data/getEntCount",
+				Handler: GetEntCountHandler(serverCtx),
+			},
 		},
 	)
 }

+ 40 - 0
api/internal/logic/getentcountlogic.go

@@ -0,0 +1,40 @@
+package logic
+
+import (
+	"app.yhyue.com/moapp/dataDeduplication/rpc/deduplication"
+	"context"
+
+	"app.yhyue.com/moapp/dataDeduplication/api/internal/svc"
+	"app.yhyue.com/moapp/dataDeduplication/api/internal/types"
+
+	"github.com/tal-tech/go-zero/core/logx"
+)
+
+type GetEntCountLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewGetEntCountLogic(ctx context.Context, svcCtx *svc.ServiceContext) GetEntCountLogic {
+	return GetEntCountLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *GetEntCountLogic) GetEntCount(req types.EntCountReq) (*types.EntCountResp, error) {
+	// todo: add your logic here and delete this line
+	res,err:=l.svcCtx.Dedup.GetEntCount(l.ctx,&deduplication.GetEntCountRequest{
+		EntId: req.EntId,
+	})
+	if err != nil {
+		return nil, err
+	}
+	return &types.EntCountResp{
+		Code: 0,
+		Msg:  "请求成功",
+		Data: res.Data,
+	}, nil
+}

+ 11 - 1
api/internal/types/types.go

@@ -4,7 +4,7 @@ package types
 type Info struct {
 	TotalCount int64 `json:"totalCount"` // 本次查询info_id总量
 	ExistCount int64 `json:"existCount"` // 已存在的info_id的数量
-	NewCount   int64 `json:"NewCount"`   // 不存在的info_id的数量
+	NewCount   int64 `json:"newCount"`   // 不存在的info_id的数量
 }
 
 type DedupReq struct {
@@ -20,3 +20,13 @@ type DedupResp struct {
 	Msg  string `json:"msg"`
 	Data Info   `json:"data"`
 }
+
+type EntCountReq struct {
+	EntId string `form:"entId"` // 企业id
+}
+
+type EntCountResp struct {
+	Code int64  `json:"code"`
+	Msg  string `json:"msg"`
+	Data int64  `json:"data"`
+}

+ 11 - 1
rpc/deduplication.proto

@@ -16,6 +16,10 @@ message Info {
   int64  NewCount = 3;   // 不存在的info_id的数量
   bool  isInsert = 4 ;   // 是否插入新数据
 
+}
+message GetEntCountRequest {
+  string entId = 1;        // 企业id
+
 }
 
 message Response {
@@ -23,8 +27,14 @@ message Response {
   string message = 2;  //响应消息
   Info data = 3;     //响应内容
 }
-
+message GetEntCountResponse {
+  int64  code = 1;    //响应代码
+  string message = 2;  //响应消息
+  int64 data = 3;     //响应内容
+}
 service Deduplication {
   // 数据判重
   rpc dataDeduplication(Request) returns(Response);
+  // 获取企业数据总量
+  rpc GetEntCount(GetEntCountRequest) returns(GetEntCountResponse);
 }

+ 214 - 24
rpc/deduplication/deduplication.pb.go

@@ -179,6 +179,53 @@ func (x *Info) GetIsInsert() bool {
 	return false
 }
 
+type GetEntCountRequest struct {
+	state         protoimpl.MessageState
+	sizeCache     protoimpl.SizeCache
+	unknownFields protoimpl.UnknownFields
+
+	EntId string `protobuf:"bytes,1,opt,name=entId,proto3" json:"entId,omitempty"` // 企业id
+}
+
+func (x *GetEntCountRequest) Reset() {
+	*x = GetEntCountRequest{}
+	if protoimpl.UnsafeEnabled {
+		mi := &file_deduplication_proto_msgTypes[2]
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		ms.StoreMessageInfo(mi)
+	}
+}
+
+func (x *GetEntCountRequest) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*GetEntCountRequest) ProtoMessage() {}
+
+func (x *GetEntCountRequest) ProtoReflect() protoreflect.Message {
+	mi := &file_deduplication_proto_msgTypes[2]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use GetEntCountRequest.ProtoReflect.Descriptor instead.
+func (*GetEntCountRequest) Descriptor() ([]byte, []int) {
+	return file_deduplication_proto_rawDescGZIP(), []int{2}
+}
+
+func (x *GetEntCountRequest) GetEntId() string {
+	if x != nil {
+		return x.EntId
+	}
+	return ""
+}
+
 type Response struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
@@ -192,7 +239,7 @@ type Response struct {
 func (x *Response) Reset() {
 	*x = Response{}
 	if protoimpl.UnsafeEnabled {
-		mi := &file_deduplication_proto_msgTypes[2]
+		mi := &file_deduplication_proto_msgTypes[3]
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		ms.StoreMessageInfo(mi)
 	}
@@ -205,7 +252,7 @@ func (x *Response) String() string {
 func (*Response) ProtoMessage() {}
 
 func (x *Response) ProtoReflect() protoreflect.Message {
-	mi := &file_deduplication_proto_msgTypes[2]
+	mi := &file_deduplication_proto_msgTypes[3]
 	if protoimpl.UnsafeEnabled && x != nil {
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		if ms.LoadMessageInfo() == nil {
@@ -218,7 +265,7 @@ func (x *Response) ProtoReflect() protoreflect.Message {
 
 // Deprecated: Use Response.ProtoReflect.Descriptor instead.
 func (*Response) Descriptor() ([]byte, []int) {
-	return file_deduplication_proto_rawDescGZIP(), []int{2}
+	return file_deduplication_proto_rawDescGZIP(), []int{3}
 }
 
 func (x *Response) GetCode() int64 {
@@ -242,6 +289,69 @@ func (x *Response) GetData() *Info {
 	return nil
 }
 
+type GetEntCountResponse struct {
+	state         protoimpl.MessageState
+	sizeCache     protoimpl.SizeCache
+	unknownFields protoimpl.UnknownFields
+
+	Code    int64  `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`      //响应代码
+	Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"` //响应消息
+	Data    int64  `protobuf:"varint,3,opt,name=data,proto3" json:"data,omitempty"`      //响应内容
+}
+
+func (x *GetEntCountResponse) Reset() {
+	*x = GetEntCountResponse{}
+	if protoimpl.UnsafeEnabled {
+		mi := &file_deduplication_proto_msgTypes[4]
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		ms.StoreMessageInfo(mi)
+	}
+}
+
+func (x *GetEntCountResponse) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*GetEntCountResponse) ProtoMessage() {}
+
+func (x *GetEntCountResponse) ProtoReflect() protoreflect.Message {
+	mi := &file_deduplication_proto_msgTypes[4]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use GetEntCountResponse.ProtoReflect.Descriptor instead.
+func (*GetEntCountResponse) Descriptor() ([]byte, []int) {
+	return file_deduplication_proto_rawDescGZIP(), []int{4}
+}
+
+func (x *GetEntCountResponse) GetCode() int64 {
+	if x != nil {
+		return x.Code
+	}
+	return 0
+}
+
+func (x *GetEntCountResponse) GetMessage() string {
+	if x != nil {
+		return x.Message
+	}
+	return ""
+}
+
+func (x *GetEntCountResponse) GetData() int64 {
+	if x != nil {
+		return x.Data
+	}
+	return 0
+}
+
 var File_deduplication_proto protoreflect.FileDescriptor
 
 var file_deduplication_proto_rawDesc = []byte{
@@ -263,19 +373,33 @@ var file_deduplication_proto_rawDesc = []byte{
 	0x6f, 0x75, 0x6e, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x4e, 0x65, 0x77, 0x43, 0x6f, 0x75, 0x6e, 0x74,
 	0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x4e, 0x65, 0x77, 0x43, 0x6f, 0x75, 0x6e, 0x74,
 	0x12, 0x1a, 0x0a, 0x08, 0x69, 0x73, 0x49, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x18, 0x04, 0x20, 0x01,
-	0x28, 0x08, 0x52, 0x08, 0x69, 0x73, 0x49, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x22, 0x61, 0x0a, 0x08,
-	0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65,
-	0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07,
-	0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d,
-	0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x27, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03,
-	0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x64, 0x65, 0x64, 0x75, 0x70, 0x6c, 0x69, 0x63, 0x61,
-	0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x32,
-	0x55, 0x0a, 0x0d, 0x44, 0x65, 0x64, 0x75, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e,
-	0x12, 0x44, 0x0a, 0x11, 0x64, 0x61, 0x74, 0x61, 0x44, 0x65, 0x64, 0x75, 0x70, 0x6c, 0x69, 0x63,
-	0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x2e, 0x64, 0x65, 0x64, 0x75, 0x70, 0x6c, 0x69, 0x63,
-	0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e,
-	0x64, 0x65, 0x64, 0x75, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x52, 0x65,
-	0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+	0x28, 0x08, 0x52, 0x08, 0x69, 0x73, 0x49, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x22, 0x2a, 0x0a, 0x12,
+	0x47, 0x65, 0x74, 0x45, 0x6e, 0x74, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65,
+	0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
+	0x09, 0x52, 0x05, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x22, 0x61, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x70,
+	0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01,
+	0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73,
+	0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61,
+	0x67, 0x65, 0x12, 0x27, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b,
+	0x32, 0x13, 0x2e, 0x64, 0x65, 0x64, 0x75, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e,
+	0x2e, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x57, 0x0a, 0x13, 0x47,
+	0x65, 0x74, 0x45, 0x6e, 0x74, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
+	0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03,
+	0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67,
+	0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
+	0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04,
+	0x64, 0x61, 0x74, 0x61, 0x32, 0xab, 0x01, 0x0a, 0x0d, 0x44, 0x65, 0x64, 0x75, 0x70, 0x6c, 0x69,
+	0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x44, 0x0a, 0x11, 0x64, 0x61, 0x74, 0x61, 0x44, 0x65,
+	0x64, 0x75, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x2e, 0x64, 0x65,
+	0x64, 0x75, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x52, 0x65, 0x71, 0x75,
+	0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x64, 0x65, 0x64, 0x75, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74,
+	0x69, 0x6f, 0x6e, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x54, 0x0a, 0x0b,
+	0x47, 0x65, 0x74, 0x45, 0x6e, 0x74, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x21, 0x2e, 0x64, 0x65,
+	0x64, 0x75, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x47, 0x65, 0x74, 0x45,
+	0x6e, 0x74, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22,
+	0x2e, 0x64, 0x65, 0x64, 0x75, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x47,
+	0x65, 0x74, 0x45, 0x6e, 0x74, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
+	0x73, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (
@@ -290,18 +414,22 @@ func file_deduplication_proto_rawDescGZIP() []byte {
 	return file_deduplication_proto_rawDescData
 }
 
-var file_deduplication_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
+var file_deduplication_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
 var file_deduplication_proto_goTypes = []interface{}{
-	(*Request)(nil),  // 0: deduplication.Request
-	(*Info)(nil),     // 1: deduplication.Info
-	(*Response)(nil), // 2: deduplication.Response
+	(*Request)(nil),             // 0: deduplication.Request
+	(*Info)(nil),                // 1: deduplication.Info
+	(*GetEntCountRequest)(nil),  // 2: deduplication.GetEntCountRequest
+	(*Response)(nil),            // 3: deduplication.Response
+	(*GetEntCountResponse)(nil), // 4: deduplication.GetEntCountResponse
 }
 var file_deduplication_proto_depIdxs = []int32{
 	1, // 0: deduplication.Response.data:type_name -> deduplication.Info
 	0, // 1: deduplication.Deduplication.dataDeduplication:input_type -> deduplication.Request
-	2, // 2: deduplication.Deduplication.dataDeduplication:output_type -> deduplication.Response
-	2, // [2:3] is the sub-list for method output_type
-	1, // [1:2] is the sub-list for method input_type
+	2, // 2: deduplication.Deduplication.GetEntCount:input_type -> deduplication.GetEntCountRequest
+	3, // 3: deduplication.Deduplication.dataDeduplication:output_type -> deduplication.Response
+	4, // 4: deduplication.Deduplication.GetEntCount:output_type -> deduplication.GetEntCountResponse
+	3, // [3:5] is the sub-list for method output_type
+	1, // [1:3] is the sub-list for method input_type
 	1, // [1:1] is the sub-list for extension type_name
 	1, // [1:1] is the sub-list for extension extendee
 	0, // [0:1] is the sub-list for field type_name
@@ -338,6 +466,18 @@ func file_deduplication_proto_init() {
 			}
 		}
 		file_deduplication_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
+			switch v := v.(*GetEntCountRequest); i {
+			case 0:
+				return &v.state
+			case 1:
+				return &v.sizeCache
+			case 2:
+				return &v.unknownFields
+			default:
+				return nil
+			}
+		}
+		file_deduplication_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Response); i {
 			case 0:
 				return &v.state
@@ -349,6 +489,18 @@ func file_deduplication_proto_init() {
 				return nil
 			}
 		}
+		file_deduplication_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
+			switch v := v.(*GetEntCountResponse); i {
+			case 0:
+				return &v.state
+			case 1:
+				return &v.sizeCache
+			case 2:
+				return &v.unknownFields
+			default:
+				return nil
+			}
+		}
 	}
 	type x struct{}
 	out := protoimpl.TypeBuilder{
@@ -356,7 +508,7 @@ func file_deduplication_proto_init() {
 			GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
 			RawDescriptor: file_deduplication_proto_rawDesc,
 			NumEnums:      0,
-			NumMessages:   3,
+			NumMessages:   5,
 			NumExtensions: 0,
 			NumServices:   1,
 		},
@@ -384,6 +536,8 @@ const _ = grpc.SupportPackageIsVersion6
 type DeduplicationClient interface {
 	// 数据判重
 	DataDeduplication(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
+	// 获取企业数据总量
+	GetEntCount(ctx context.Context, in *GetEntCountRequest, opts ...grpc.CallOption) (*GetEntCountResponse, error)
 }
 
 type deduplicationClient struct {
@@ -403,10 +557,21 @@ func (c *deduplicationClient) DataDeduplication(ctx context.Context, in *Request
 	return out, nil
 }
 
+func (c *deduplicationClient) GetEntCount(ctx context.Context, in *GetEntCountRequest, opts ...grpc.CallOption) (*GetEntCountResponse, error) {
+	out := new(GetEntCountResponse)
+	err := c.cc.Invoke(ctx, "/deduplication.Deduplication/GetEntCount", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
 // DeduplicationServer is the server API for Deduplication service.
 type DeduplicationServer interface {
 	// 数据判重
 	DataDeduplication(context.Context, *Request) (*Response, error)
+	// 获取企业数据总量
+	GetEntCount(context.Context, *GetEntCountRequest) (*GetEntCountResponse, error)
 }
 
 // UnimplementedDeduplicationServer can be embedded to have forward compatible implementations.
@@ -416,6 +581,9 @@ type UnimplementedDeduplicationServer struct {
 func (*UnimplementedDeduplicationServer) DataDeduplication(context.Context, *Request) (*Response, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method DataDeduplication not implemented")
 }
+func (*UnimplementedDeduplicationServer) GetEntCount(context.Context, *GetEntCountRequest) (*GetEntCountResponse, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method GetEntCount not implemented")
+}
 
 func RegisterDeduplicationServer(s *grpc.Server, srv DeduplicationServer) {
 	s.RegisterService(&_Deduplication_serviceDesc, srv)
@@ -439,6 +607,24 @@ func _Deduplication_DataDeduplication_Handler(srv interface{}, ctx context.Conte
 	return interceptor(ctx, in, info, handler)
 }
 
+func _Deduplication_GetEntCount_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(GetEntCountRequest)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(DeduplicationServer).GetEntCount(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/deduplication.Deduplication/GetEntCount",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(DeduplicationServer).GetEntCount(ctx, req.(*GetEntCountRequest))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
 var _Deduplication_serviceDesc = grpc.ServiceDesc{
 	ServiceName: "deduplication.Deduplication",
 	HandlerType: (*DeduplicationServer)(nil),
@@ -447,6 +633,10 @@ var _Deduplication_serviceDesc = grpc.ServiceDesc{
 			MethodName: "dataDeduplication",
 			Handler:    _Deduplication_DataDeduplication_Handler,
 		},
+		{
+			MethodName: "GetEntCount",
+			Handler:    _Deduplication_GetEntCount_Handler,
+		},
 	},
 	Streams:  []grpc.StreamDesc{},
 	Metadata: "deduplication.proto",

+ 13 - 3
rpc/deduplicationclient/deduplication.go

@@ -14,13 +14,17 @@ import (
 )
 
 type (
-	Response = deduplication.Response
-	Request  = deduplication.Request
-	Info     = deduplication.Info
+	GetEntCountRequest  = deduplication.GetEntCountRequest
+	Response            = deduplication.Response
+	GetEntCountResponse = deduplication.GetEntCountResponse
+	Request             = deduplication.Request
+	Info                = deduplication.Info
 
 	Deduplication interface {
 		//  数据判重
 		DataDeduplication(ctx context.Context, in *Request) (*Response, error)
+		//  获取企业数据总量
+		GetEntCount(ctx context.Context, in *GetEntCountRequest) (*GetEntCountResponse, error)
 	}
 
 	defaultDeduplication struct {
@@ -39,3 +43,9 @@ func (m *defaultDeduplication) DataDeduplication(ctx context.Context, in *Reques
 	client := deduplication.NewDeduplicationClient(m.cli.Conn())
 	return client.DataDeduplication(ctx, in)
 }
+
+//  获取企业数据总量
+func (m *defaultDeduplication) GetEntCount(ctx context.Context, in *GetEntCountRequest) (*GetEntCountResponse, error) {
+	client := deduplication.NewDeduplicationClient(m.cli.Conn())
+	return client.GetEntCount(ctx, in)
+}

+ 38 - 0
rpc/internal/logic/getentcountlogic.go

@@ -0,0 +1,38 @@
+package logic
+
+import (
+	"context"
+
+	"app.yhyue.com/moapp/dataDeduplication/rpc/deduplication"
+	"app.yhyue.com/moapp/dataDeduplication/rpc/internal/svc"
+
+	"github.com/tal-tech/go-zero/core/logx"
+)
+
+type GetEntCountLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewGetEntCountLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetEntCountLogic {
+	return &GetEntCountLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+//  获取企业数据总量
+func (l *GetEntCountLogic) GetEntCount(in *deduplication.GetEntCountRequest) (*deduplication.GetEntCountResponse, error) {
+	count, err := deduplicationService.EntCount(in)
+	code := 0
+	if err != "" {
+		code = -1
+	}
+	return &deduplication.GetEntCountResponse{
+		Data:    count,
+		Message: err,
+		Code:    int64(code),
+	}, nil
+}

+ 6 - 0
rpc/internal/server/deduplicationserver.go

@@ -26,3 +26,9 @@ func (s *DeduplicationServer) DataDeduplication(ctx context.Context, in *dedupli
 	l := logic.NewDataDeduplicationLogic(ctx, s.svcCtx)
 	return l.DataDeduplication(in)
 }
+
+//  获取企业数据总量
+func (s *DeduplicationServer) GetEntCount(ctx context.Context, in *deduplication.GetEntCountRequest) (*deduplication.GetEntCountResponse, error) {
+	l := logic.NewGetEntCountLogic(ctx, s.svcCtx)
+	return l.GetEntCount(in)
+}

+ 32 - 15
service/deduplication.go

@@ -29,10 +29,10 @@ func (service *DeduplicationService) DataDeduplicateInsert(data *deduplication.R
 	var rs []*entity.Deduplication
 	var tmpList []string
 	var valueList []interface{}
-	var  selectSql string
-	if data.IsEnt{
+	var selectSql string
+	if data.IsEnt {
 		valueList = append(valueList, data.EntId)
-	}else {
+	} else {
 		valueList = append(valueList, data.PersonId, data.EntId)
 	}
 
@@ -40,9 +40,9 @@ func (service *DeduplicationService) DataDeduplicateInsert(data *deduplication.R
 		tmpList = append(tmpList, "?")
 		valueList = append(valueList, v)
 	}
-	if data.IsEnt{
+	if data.IsEnt {
 		selectSql = fmt.Sprintf("ent_id=? and info_id in (%s)", strings.Join(tmpList, ","))
-	}else {
+	} else {
 		selectSql = fmt.Sprintf("person_id = ? and ent_id=? and info_id in (%s)", strings.Join(tmpList, ","))
 	}
 	log.Println(selectSql)
@@ -50,9 +50,9 @@ func (service *DeduplicationService) DataDeduplicateInsert(data *deduplication.R
 	totalInfoCount := len(infoIdList)
 	err := orm.Table(tableName).Cols("info_id").Where(selectSql, valueList...).Find(&rs)
 	totalExist := len(rs)
-	log.Println(totalExist,"已存在")
+	log.Println(totalExist, "已存在")
 	if err != nil {
-		log.Println(err,"判重查询失败")
+		log.Println(err, "判重查询失败")
 		return &deduplication.Info{
 			TotalCount: 0,
 			ExistCount: 0,
@@ -63,20 +63,20 @@ func (service *DeduplicationService) DataDeduplicateInsert(data *deduplication.R
 
 	if data.IsInsert {
 
-		existIdMap :=map[string]bool{}
-		for _,v := range rs{
-			existIdMap[v.InfoId]=true
+		existIdMap := map[string]bool{}
+		for _, v := range rs {
+			existIdMap[v.InfoId] = true
 		}
 		// 开启事务
 		orm.Begin()
 		// 新增
 		var insertList []entity.Deduplication
 		for _, id := range infoIdList {
-			if existIdMap[id]{
-				log.Println("id已存在",id,)
+			if existIdMap[id] {
+				log.Println("id已存在", id)
 				continue
 			}
-			log.Println("新增",id,)
+			log.Println("新增", id)
 			temData := entity.Deduplication{
 				InfoId:   id,
 				EntId:    data.EntId,
@@ -88,7 +88,7 @@ func (service *DeduplicationService) DataDeduplicateInsert(data *deduplication.R
 				insertList = []entity.Deduplication{}
 				if err3 != nil {
 					orm.Rollback()
-					log.Println(err3,"新增数据失败")
+					log.Println(err3, "新增数据失败")
 					return &deduplication.Info{
 						TotalCount: int64(totalInfoCount),
 						ExistCount: int64(totalExist),
@@ -102,7 +102,7 @@ func (service *DeduplicationService) DataDeduplicateInsert(data *deduplication.R
 			_, err3 := orm.Table(tableName).Insert(insertList)
 			if err3 != nil {
 				orm.Rollback()
-				log.Println(err3,"新增数据失败")
+				log.Println(err3, "新增数据失败")
 				return &deduplication.Info{
 					TotalCount: int64(totalInfoCount),
 					ExistCount: int64(totalExist),
@@ -139,3 +139,20 @@ func (service *DeduplicationService) DataDeduplicateInsert(data *deduplication.R
 		IsInsert:   false,
 	}, ""
 }
+func (service *DeduplicationService) EntCount(data *deduplication.GetEntCountRequest) (int64, string) {
+	log.Println("开始=====")
+	orm := Engine.NewSession()
+	defer orm.Close()
+	// 模运算取企业id
+	number, _ := strconv.Atoi(data.EntId)
+	tableName := PREFIX + fmt.Sprintf("%03d", number%100)
+	// 查询
+	var rs entity.Deduplication
+	count, err := orm.Table(tableName).Where("ent_id=?", data.EntId).Count(rs)
+	if err != nil {
+		return 0, "查询失败"
+	}
+	log.Println("count=====",count)
+	return count, ""
+
+}