fuwencai před 4 roky
rodič
revize
c2601c72ca

+ 10 - 0
api/deduplication.api

@@ -26,6 +26,12 @@ type (
 		Msg  string `json:"msg"`
 		Data Info   `json:"data"`
 	}
+	// 根据账户id判重
+	DedupByAccountReq {
+		PersonId  string `form:"personId"`  //人员id
+		InfoId    string `form:"infoId"`    //信息id  逗号分隔
+		AccountId string `form:"accountId"` // 账户id
+	}
 )
 
 type (
@@ -43,4 +49,8 @@ service deduplication-api {
 	post /data/deduplication (DedupReq) returns (DedupResp)
 	@handler GetEntCount // 调用数据去重
 	post /data/getEntCount (EntCountReq) returns (EntCountResp)
+	@handler dedupByAcount // 根据账户id判重
+	post /data/dedupByAcount (DedupByAccountReq) returns (DedupResp)
+	@handler dedupAndSave // 根据账户id判重并存入数据
+	post /data/dedupAndSave (DedupByAccountReq) returns (DedupResp)
 }

+ 29 - 0
api/internal/handler/dedupandsavehandler.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 dedupAndSaveHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.DedupByAccountReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewDedupAndSaveLogic(r.Context(), ctx)
+		resp, err := l.DedupAndSave(req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 29 - 0
api/internal/handler/dedupbyacounthandler.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 dedupByAcountHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.DedupByAccountReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewDedupByAcountLogic(r.Context(), ctx)
+		resp, err := l.DedupByAcount(req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

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

@@ -22,6 +22,16 @@ func RegisterHandlers(engine *rest.Server, serverCtx *svc.ServiceContext) {
 				Path:    "/data/getEntCount",
 				Handler: GetEntCountHandler(serverCtx),
 			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/data/dedupByAcount",
+				Handler: dedupByAcountHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/data/dedupAndSave",
+				Handler: dedupAndSaveHandler(serverCtx),
+			},
 		},
 	)
 }

+ 42 - 0
api/internal/logic/dedupandsavelogic.go

@@ -0,0 +1,42 @@
+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 DedupAndSaveLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewDedupAndSaveLogic(ctx context.Context, svcCtx *svc.ServiceContext) DedupAndSaveLogic {
+	return DedupAndSaveLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *DedupAndSaveLogic) DedupAndSave(req types.DedupByAccountReq) (*types.DedupResp, error) {
+	res,_:=l.svcCtx.Dedup.DataDeduplicateAndSave(l.ctx,&deduplication.ByAccountRequest{
+		InfoId: req.InfoId,
+		PersonId: req.PersonId,
+		AccountId: req.AccountId,
+	})
+	return &types.DedupResp{
+		Code: res.Code,
+		Msg: "请求成功",
+		Data: types.Info{
+			TotalCount: res.Data.TotalCount,
+			ExistCount :res.Data.ExistCount,
+			NewCount   :res.Data.NewCount,
+		},
+	}, nil
+}

+ 42 - 0
api/internal/logic/dedupbyacountlogic.go

@@ -0,0 +1,42 @@
+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 DedupByAcountLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewDedupByAcountLogic(ctx context.Context, svcCtx *svc.ServiceContext) DedupByAcountLogic {
+	return DedupByAcountLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *DedupByAcountLogic) DedupByAcount(req types.DedupByAccountReq) (*types.DedupResp, error) {
+	res,_:=l.svcCtx.Dedup.DataDeduplicateByAccount(l.ctx,&deduplication.ByAccountRequest{
+		InfoId: req.InfoId,
+		PersonId: req.PersonId,
+		AccountId: req.AccountId,
+	})
+	return &types.DedupResp{
+		Code: res.Code,
+		Msg: "请求成功",
+		Data: types.Info{
+			TotalCount: res.Data.TotalCount,
+			ExistCount :res.Data.ExistCount,
+			NewCount   :res.Data.NewCount,
+		},
+	}, nil
+}

+ 6 - 0
api/internal/types/types.go

@@ -21,6 +21,12 @@ type DedupResp struct {
 	Data Info   `json:"data"`
 }
 
+type DedupByAccountReq struct {
+	PersonId  string `form:"personId"`  //人员id
+	InfoId    string `form:"infoId"`    //信息id  逗号分隔
+	AccountId string `form:"accountId"` // 账户id
+}
+
 type EntCountReq struct {
 	EntId string `form:"entId"` // 企业id
 }