|
@@ -19,6 +19,7 @@ var Engine *xorm.Engine
|
|
type DeduplicationService struct{}
|
|
type DeduplicationService struct{}
|
|
|
|
|
|
var PREFIX = "qc"
|
|
var PREFIX = "qc"
|
|
|
|
+var SaveNumChan chan int
|
|
|
|
|
|
//数据判重
|
|
//数据判重
|
|
func (service *DeduplicationService) DataDeduplicateInsert(data *deduplication.Request) (*deduplication.Info, string) {
|
|
func (service *DeduplicationService) DataDeduplicateInsert(data *deduplication.Request) (*deduplication.Info, string) {
|
|
@@ -91,11 +92,10 @@ func (service *DeduplicationService) DataDeduplicateInsert(data *deduplication.R
|
|
tmp := []interface{}{insertSql}
|
|
tmp := []interface{}{insertSql}
|
|
tmp = append(tmp, insertList...)
|
|
tmp = append(tmp, insertList...)
|
|
_, err3 := orm.Exec(tmp...)
|
|
_, err3 := orm.Exec(tmp...)
|
|
- insertList = []interface{}{}
|
|
|
|
- parmList = []string{}
|
|
|
|
if err3 != nil {
|
|
if err3 != nil {
|
|
orm.Rollback()
|
|
orm.Rollback()
|
|
- log.Println(err3, "新增数据失败")
|
|
|
|
|
|
+ log.Printf("DataDeduplicateInsert 执行失败已回滚,err:%s", err3)
|
|
|
|
+ log.Printf("DataDeduplicateInsert 执行失败sql:%s,该批次部分数据:%v", insertSql, insertList)
|
|
return &deduplication.Info{
|
|
return &deduplication.Info{
|
|
TotalCount: int64(totalInfoCount),
|
|
TotalCount: int64(totalInfoCount),
|
|
ExistCount: int64(totalExist),
|
|
ExistCount: int64(totalExist),
|
|
@@ -103,6 +103,8 @@ func (service *DeduplicationService) DataDeduplicateInsert(data *deduplication.R
|
|
IsInsert: false,
|
|
IsInsert: false,
|
|
}, "新增数据失败"
|
|
}, "新增数据失败"
|
|
}
|
|
}
|
|
|
|
+ insertList = []interface{}{}
|
|
|
|
+ parmList = []string{}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if len(insertList) > 0 {
|
|
if len(insertList) > 0 {
|
|
@@ -112,7 +114,8 @@ func (service *DeduplicationService) DataDeduplicateInsert(data *deduplication.R
|
|
_, err3 := orm.Exec(tmp...)
|
|
_, err3 := orm.Exec(tmp...)
|
|
if err3 != nil {
|
|
if err3 != nil {
|
|
orm.Rollback()
|
|
orm.Rollback()
|
|
- log.Println(err3, "新增数据失败")
|
|
|
|
|
|
+ log.Printf("DataDeduplicateInsert 执行失败已回滚,err:%s", err3)
|
|
|
|
+ log.Printf("DataDeduplicateInsert 执行失败sql:%s,该批次部分数据:%v", insertSql, insertList)
|
|
return &deduplication.Info{
|
|
return &deduplication.Info{
|
|
TotalCount: int64(totalInfoCount),
|
|
TotalCount: int64(totalInfoCount),
|
|
ExistCount: int64(totalExist),
|
|
ExistCount: int64(totalExist),
|
|
@@ -124,6 +127,8 @@ func (service *DeduplicationService) DataDeduplicateInsert(data *deduplication.R
|
|
err := orm.Commit()
|
|
err := orm.Commit()
|
|
if err != nil {
|
|
if err != nil {
|
|
log.Println("提交失败")
|
|
log.Println("提交失败")
|
|
|
|
+ log.Printf("DataDeduplicateInsert commit err:%s 最后一个sql:%s", err, insertSql)
|
|
|
|
+ log.Printf("DataDeduplicateInsert 提交失败该批次部分数据:%v", insertList...)
|
|
return &deduplication.Info{
|
|
return &deduplication.Info{
|
|
TotalCount: int64(totalInfoCount),
|
|
TotalCount: int64(totalInfoCount),
|
|
ExistCount: int64(totalExist),
|
|
ExistCount: int64(totalExist),
|
|
@@ -270,7 +275,7 @@ func (service *DeduplicationService) DataDeduplicateAndSave(data *deduplication.
|
|
log.Println("id已存在", id)
|
|
log.Println("id已存在", id)
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
- log.Println("新增", id)
|
|
|
|
|
|
+ //log.Println("新增", id)
|
|
temData := entity.Deduplication{
|
|
temData := entity.Deduplication{
|
|
InfoId: id,
|
|
InfoId: id,
|
|
EntId: "0",
|
|
EntId: "0",
|
|
@@ -316,10 +321,13 @@ func a(data string) string {
|
|
}
|
|
}
|
|
|
|
|
|
func SaveMysql(tableName string, saveList []entity.Deduplication) {
|
|
func SaveMysql(tableName string, saveList []entity.Deduplication) {
|
|
- //
|
|
|
|
|
|
+ SaveNumChan <- 1
|
|
log.Println("保存数据开始")
|
|
log.Println("保存数据开始")
|
|
orm := Engine.NewSession()
|
|
orm := Engine.NewSession()
|
|
- defer orm.Close()
|
|
|
|
|
|
+ defer func() {
|
|
|
|
+ orm.Close()
|
|
|
|
+ <-SaveNumChan
|
|
|
|
+ }()
|
|
orm.Begin()
|
|
orm.Begin()
|
|
insertList := []interface{}{}
|
|
insertList := []interface{}{}
|
|
insertSql := fmt.Sprintf("insert IGNORE into %s (info_id,ent_id,person_id,account_id,data_desc) values ", tableName)
|
|
insertSql := fmt.Sprintf("insert IGNORE into %s (info_id,ent_id,person_id,account_id,data_desc) values ", tableName)
|
|
@@ -332,12 +340,14 @@ func SaveMysql(tableName string, saveList []entity.Deduplication) {
|
|
tmp := []interface{}{insertSql}
|
|
tmp := []interface{}{insertSql}
|
|
tmp = append(tmp, insertList...)
|
|
tmp = append(tmp, insertList...)
|
|
_, err3 := orm.Exec(tmp...)
|
|
_, err3 := orm.Exec(tmp...)
|
|
- insertList = []interface{}{}
|
|
|
|
- parmList = []string{}
|
|
|
|
if err3 != nil {
|
|
if err3 != nil {
|
|
orm.Rollback()
|
|
orm.Rollback()
|
|
- log.Println(err3, "新增数据失败")
|
|
|
|
|
|
+ log.Printf("DataDeduplicateAndSave执行失败err:%s", err3)
|
|
|
|
+ log.Printf("DataDeduplicateAndSave执行失败sql:%s,该批次部分数据:%v", insertSql, insertList)
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
+ insertList = []interface{}{}
|
|
|
|
+ parmList = []string{}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if len(insertList) > 0 {
|
|
if len(insertList) > 0 {
|
|
@@ -347,12 +357,23 @@ func SaveMysql(tableName string, saveList []entity.Deduplication) {
|
|
_, err3 := orm.Exec(tmp...)
|
|
_, err3 := orm.Exec(tmp...)
|
|
if err3 != nil {
|
|
if err3 != nil {
|
|
orm.Rollback()
|
|
orm.Rollback()
|
|
- log.Println(err3, "新增数据失败")
|
|
|
|
|
|
+ log.Printf("DataDeduplicateAndSave执行失败err:%s", err3)
|
|
|
|
+ log.Printf("DataDeduplicateAndSave执行失败sql:%s,该批次部分数据:%v", insertSql, insertList)
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
err2 := orm.Commit()
|
|
err2 := orm.Commit()
|
|
- log.Println("err2", err2)
|
|
|
|
|
|
+ if err2 != nil {
|
|
|
|
+ log.Printf("DataDeduplicateAndSave commit失败:%s 最后一次sql:%s", err2, insertSql)
|
|
|
|
+ log.Printf("DataDeduplicateAndSave commit 该批次部分数据:%v", insertList)
|
|
|
|
+ }
|
|
log.Println("保存数据结束")
|
|
log.Println("保存数据结束")
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+//type saveChanStruct struct {
|
|
|
|
+// TableName string
|
|
|
|
+// Data []entity.Deduplication
|
|
|
|
+//}
|
|
|
|
+//
|
|
|
|
+//var SaveChan = make(chan saveChanStruct, 10000)
|