|
@@ -19,6 +19,7 @@ type DeduplicationService struct{}
|
|
|
|
|
|
var PREFIX = "qc"
|
|
|
|
|
|
+
|
|
|
//数据判重
|
|
|
func (service *DeduplicationService) DataDeduplicateInsert(data *deduplication.Request) (*deduplication.Info, string) {
|
|
|
log.Println("开始=====")
|
|
@@ -269,8 +270,6 @@ func (service *DeduplicationService) DataDeduplicateAndSave(data *deduplication.
|
|
|
for _, v := range rs {
|
|
|
existIdMap[v.InfoId] = true
|
|
|
}
|
|
|
- // 开启事务
|
|
|
- orm.Begin()
|
|
|
// 新增
|
|
|
var insertList []entity.Deduplication
|
|
|
for _, id := range infoIdList {
|
|
@@ -287,50 +286,14 @@ func (service *DeduplicationService) DataDeduplicateAndSave(data *deduplication.
|
|
|
DataDesc: data.DataDesc,
|
|
|
}
|
|
|
insertList = append(insertList, temData)
|
|
|
- if len(insertList) > 500 {
|
|
|
- _, err3 := orm.Table(tableName).Insert(insertList)
|
|
|
- insertList = []entity.Deduplication{}
|
|
|
- if err3 != nil {
|
|
|
- orm.Rollback()
|
|
|
- log.Println(err3, "新增数据失败")
|
|
|
- return &deduplication.Info{
|
|
|
- TotalCount: int64(totalInfoCount),
|
|
|
- ExistCount: int64(count),
|
|
|
- NewCount: int64(totalInfoCount - count),
|
|
|
- }, "新增数据失败"
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if len(insertList) > 0 {
|
|
|
- _, err3 := orm.Table(tableName).Insert(insertList)
|
|
|
- if err3 != nil {
|
|
|
- orm.Rollback()
|
|
|
- log.Println(err3, "新增数据失败")
|
|
|
- return &deduplication.Info{
|
|
|
- TotalCount: int64(totalInfoCount),
|
|
|
- ExistCount: int64(count),
|
|
|
- NewCount: int64(totalInfoCount - count),
|
|
|
- }, "新增数据失败"
|
|
|
- }
|
|
|
- }
|
|
|
- err2 := orm.Commit()
|
|
|
- if err2 != nil {
|
|
|
- log.Println("提交失败")
|
|
|
- return &deduplication.Info{
|
|
|
- TotalCount: int64(totalInfoCount),
|
|
|
- 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(count),
|
|
|
- NewCount: int64(totalInfoCount - count),
|
|
|
- }, ""
|
|
|
|
|
|
}
|
|
|
+ go SaveMysql(tableName,insertList)
|
|
|
+ return &deduplication.Info{
|
|
|
+ TotalCount: int64(totalInfoCount),
|
|
|
+ ExistCount: int64(count),
|
|
|
+ NewCount: int64(totalInfoCount - count),
|
|
|
+ }, ""
|
|
|
|
|
|
|
|
|
|
|
@@ -356,4 +319,38 @@ func a(data string) string {
|
|
|
t := md5.New()
|
|
|
io.WriteString(t, data)
|
|
|
return fmt.Sprintf("%x", t.Sum(nil))
|
|
|
+}
|
|
|
+
|
|
|
+func SaveMysql(tableName string,saveList []entity.Deduplication) {
|
|
|
+ //
|
|
|
+ log.Println("保存数据开始")
|
|
|
+ orm := Engine.NewSession()
|
|
|
+ defer orm.Close()
|
|
|
+ orm.Begin()
|
|
|
+ insertList := []entity.Deduplication{}
|
|
|
+ for _, saveData := range saveList {
|
|
|
+ insertList = append(insertList, saveData)
|
|
|
+ if len(insertList) > 500 {
|
|
|
+ _, err3 := orm.Table(tableName).Insert(insertList)
|
|
|
+ insertList = []entity.Deduplication{}
|
|
|
+ if err3 != nil {
|
|
|
+ orm.Rollback()
|
|
|
+ log.Println(err3, "新增数据失败")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(insertList) > 0 {
|
|
|
+ _, err3 := orm.Table(tableName).Insert(insertList)
|
|
|
+ if err3 != nil {
|
|
|
+ orm.Rollback()
|
|
|
+ log.Println(err3, "新增数据失败")
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ err2 := orm.Commit()
|
|
|
+ log.Println("err2", err2)
|
|
|
+ log.Println("保存数据结束")
|
|
|
+
|
|
|
}
|