From 14ba2fcfb9424266dbdb3082d3d18a964f863582 Mon Sep 17 00:00:00 2001 From: huanghai <10402852@qq.com> Date: Sat, 5 Sep 2020 09:03:25 +0800 Subject: [PATCH] 'commit' --- .../ElasticsearchToGreenPlum.go | 18 +++++++++++------ dsSupport/Utils/CommonUtil/CommonUtil.go | 20 +++++++++++++++++-- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/dsSupport/Test/ElasticsearchToGreenPlum/ElasticsearchToGreenPlum.go b/dsSupport/Test/ElasticsearchToGreenPlum/ElasticsearchToGreenPlum.go index 30c70941..8a82c369 100644 --- a/dsSupport/Test/ElasticsearchToGreenPlum/ElasticsearchToGreenPlum.go +++ b/dsSupport/Test/ElasticsearchToGreenPlum/ElasticsearchToGreenPlum.go @@ -55,7 +55,7 @@ func main() { pk := list[0]["field_name"].(string) //取所有 CTX := context.Background() - result, err := esClient.Scroll().Index(indexName).Size(1000).Do(CTX) + result, err := esClient.Scroll().Index(indexName).Size(200).Do(CTX) if err != nil { panic(err) } @@ -142,7 +142,7 @@ func addRecord(pk string, jsonStr string) []string { break } } - lineSql+="'"+CommonUtil.GetUUID()+"'" + lineSql += "'" + CommonUtil.GetUUID() + "'" insertStrArray = append(insertStrArray, lineSql) } else { fmt.Println(err.Error()) @@ -153,11 +153,13 @@ func addRecord(pk string, jsonStr string) []string { //提交 func batchSave(tableName string, pkName string, keys []string) { var pkStr = "" + //数组去重 + pkStrArray = CommonUtil.RemoveRepeatedElement(pkStrArray) for i := range pkStrArray { pkStr += "'" + pkStrArray[i] + "'," } pkStr = pkStr[0 : len(pkStr)-1] - sql := `update ` + tableName + " set enable_flag=0 where " + pkName + " in (" + pkStr + ")" + sql := `update ` + tableName + " set enable_flag=0 where " + pkName + " in (" + pkStr + ") and enable_flag=1" pgDb.SQL(sql).Execute() //插入 @@ -166,7 +168,7 @@ func batchSave(tableName string, pkName string, keys []string) { for _, k := range keys { sql += k + "," } - sql+="uuid" + sql += "uuid" var lineSql = "" for i := range insertStrArray { @@ -174,6 +176,10 @@ func batchSave(tableName string, pkName string, keys []string) { } lineSql = lineSql[0 : len(lineSql)-1] sql += ") values " + lineSql + ";" - pgDb.SQL(sql).Execute() - fmt.Println("批量执行"+ CommonUtil.ConvertIntToString(len(insertStrArray))+"条.") + _,err:=pgDb.SQL(sql).Execute() + if err!=nil{ + fmt.Println(sql) + //panic(err) + } + fmt.Println("批量执行" + CommonUtil.ConvertIntToString(len(insertStrArray)) + "条.") } diff --git a/dsSupport/Utils/CommonUtil/CommonUtil.go b/dsSupport/Utils/CommonUtil/CommonUtil.go index 9858b572..fa7669c7 100644 --- a/dsSupport/Utils/CommonUtil/CommonUtil.go +++ b/dsSupport/Utils/CommonUtil/CommonUtil.go @@ -363,8 +363,24 @@ func ConvertIntegerArrayToStringArray(nums []int) []string { func ConvertInt64ToString(int64 int64) string { return strconv.FormatInt(int64, 10) } -func ConvertFloatt64ToString(float64 float64) string { - return strconv.FormatFloat(float64, 'E', -1, 64) +/** +功能:数组去重 + */ +func RemoveRepeatedElement(arr []string) (newArr []string) { + newArr = make([]string, 0) + for i := 0; i < len(arr); i++ { + repeat := false + for j := i + 1; j < len(arr); j++ { + if arr[i] == arr[j] { + repeat = true + break + } + } + if !repeat { + newArr = append(newArr, arr[i]) + } + } + return } /**