fuwencai 4 лет назад
Родитель
Сommit
c73a13cbc1

+ 3 - 1
api/internal/logic/dedupandsavelogic.go

@@ -3,6 +3,7 @@ package logic
 import (
 	"app.yhyue.com/moapp/dataDeduplication/rpc/deduplication"
 	"context"
+	"log"
 
 	"app.yhyue.com/moapp/dataDeduplication/api/internal/svc"
 	"app.yhyue.com/moapp/dataDeduplication/api/internal/types"
@@ -25,12 +26,13 @@ func NewDedupAndSaveLogic(ctx context.Context, svcCtx *svc.ServiceContext) Dedup
 }
 
 func (l *DedupAndSaveLogic) DedupAndSave(req types.DedupByAccountReq) (*types.DedupResp, error) {
-	res,_:=l.svcCtx.Dedup.DataDeduplicateAndSave(l.ctx,&deduplication.ByAccountRequest{
+	res,err:=l.svcCtx.Dedup.DataDeduplicateAndSave(l.ctx,&deduplication.ByAccountRequest{
 		InfoId: req.InfoId,
 		PersonId: req.PersonId,
 		AccountId: req.AccountId,
 		DataDesc: req.DataDesc,
 	})
+	log.Println(res,err,"api")
 	return &types.DedupResp{
 		Code: res.Code,
 		Msg: "请求成功",

+ 2 - 0
rpc/internal/logic/datadeduplicateandsavelogic.go

@@ -2,6 +2,7 @@ package logic
 
 import (
 	"context"
+	"log"
 
 	"app.yhyue.com/moapp/dataDeduplication/rpc/deduplication"
 	"app.yhyue.com/moapp/dataDeduplication/rpc/internal/svc"
@@ -30,6 +31,7 @@ func (l *DataDeduplicateAndSaveLogic) DataDeduplicateAndSave(in *deduplication.B
 	if err!= ""{
 		code = -1
 	}
+	log.Println(err,"===rpc")
 	return &deduplication.Response{
 		Data: info,
 		Message: err,

+ 34 - 15
service/deduplication.go

@@ -162,7 +162,7 @@ func (service *DeduplicationService) DataDeduplicateByAccountId(data *deduplicat
 	tableName := PREFIX + fmt.Sprintf("%03d", number%100)
 
 	// 查询
-	var rs entity.Deduplication
+	//var rs entity.Deduplication
 	var tmpList []string
 	var valueList []interface{}
 	var selectSql string
@@ -175,12 +175,12 @@ func (service *DeduplicationService) DataDeduplicateByAccountId(data *deduplicat
 		}
 
 	}
-
+	var rs []*entity.Deduplication
 	selectSql = fmt.Sprintf("account_id=? and data_desc=? and info_id in (%s)", strings.Join(tmpList, ","))
 	infoIdList := strings.Split(data.InfoId, ",")
 	totalInfoCount := len(infoIdList)
-	count, err := orm.Table(tableName).Where(selectSql, valueList...).Count(rs)
-	log.Println(count, "已存在数据量")
+	err := orm.Table(tableName).Cols("info_id").Where(selectSql, valueList...).Find(&rs)
+
 	if err != nil {
 		log.Println(err, "判重查询失败")
 		return &deduplication.Info{
@@ -190,7 +190,16 @@ func (service *DeduplicationService) DataDeduplicateByAccountId(data *deduplicat
 			IsInsert:   false,
 		}, "判重查询失败"
 	}
-
+	existInfoIdMap := map[string]bool{}
+	existIdList := []string{}
+	for _, v := range rs {
+		if existInfoIdMap[v.InfoId] {
+			continue
+		}else {
+			existIdList = append(existIdList,v.InfoId)
+		}
+	}
+	count := int64(len(existIdList))
 	return &deduplication.Info{
 		TotalCount: int64(totalInfoCount),
 		ExistCount: count,
@@ -235,8 +244,17 @@ func (service *DeduplicationService) DataDeduplicateAndSave(data *deduplication.
 	infoIdList := strings.Split(data.InfoId, ",")
 	totalInfoCount := len(infoIdList)
 	err := orm.Table(tableName).Cols("info_id").Where(selectSql, valueList...).Find(&rs)
-	totalExist := len(rs)
-	log.Println(totalExist, "已存在数据量")
+	existInfoIdMap := map[string]bool{}
+	existIdList := []string{}
+	for _, v := range rs {
+		if existInfoIdMap[v.InfoId] {
+			continue
+		}else {
+			existIdList = append(existIdList,v.InfoId)
+		}
+	}
+	count := len(existIdList)
+	log.Println(count, "已存在数据量")
 	if err != nil {
 		log.Println(err, "判重查询失败")
 		return &deduplication.Info{
@@ -277,8 +295,8 @@ func (service *DeduplicationService) DataDeduplicateAndSave(data *deduplication.
 				log.Println(err3, "新增数据失败")
 				return &deduplication.Info{
 					TotalCount: int64(totalInfoCount),
-					ExistCount: int64(totalExist),
-					NewCount:   int64(totalInfoCount - totalExist),
+					ExistCount: int64(count),
+					NewCount:   int64(totalInfoCount - count),
 				}, "新增数据失败"
 			}
 		}
@@ -290,8 +308,8 @@ func (service *DeduplicationService) DataDeduplicateAndSave(data *deduplication.
 			log.Println(err3, "新增数据失败")
 			return &deduplication.Info{
 				TotalCount: int64(totalInfoCount),
-				ExistCount: int64(totalExist),
-				NewCount:   int64(totalInfoCount - totalExist),
+				ExistCount: int64(count),
+				NewCount:   int64(totalInfoCount - count),
 			}, "新增数据失败"
 		}
 	}
@@ -300,15 +318,16 @@ func (service *DeduplicationService) DataDeduplicateAndSave(data *deduplication.
 		log.Println("提交失败")
 		return &deduplication.Info{
 			TotalCount: int64(totalInfoCount),
-			ExistCount: int64(totalExist),
-			NewCount:   int64(totalInfoCount - totalExist),
+			ExistCount: int64(count),
+			NewCount:   int64(totalInfoCount - count),
 		}, "提交失败"
 	} else {
 		log.Println("提交成功")
+		log.Println(count,"2222",int64(count),int64(totalInfoCount - count))
 		return &deduplication.Info{
 			TotalCount: int64(totalInfoCount),
-			ExistCount: int64(totalExist),
-			NewCount:   int64(totalInfoCount - totalExist),
+			ExistCount: int64(count),
+			NewCount:   int64(totalInfoCount - count),
 		}, ""
 
 	}