|
@@ -21,27 +21,32 @@ func buyerOnce() {
|
|
|
//now := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
|
|
|
now := time.Now()
|
|
|
curTime := now.Format("2006-01-02")
|
|
|
- insertquery := fmt.Sprintf(`
|
|
|
- SELECT
|
|
|
- b.name,
|
|
|
- t.id,
|
|
|
- t.name_id,
|
|
|
- c.area,
|
|
|
- c.city,
|
|
|
- class.name AS buyerclass
|
|
|
-
|
|
|
- FROM
|
|
|
- dws_f_ent_tags AS t
|
|
|
- LEFT JOIN code_buyerclass AS class ON class.code = t.labelvalues
|
|
|
- LEFT JOIN dws_f_ent_baseinfo AS b ON b.name_id = t.name_id
|
|
|
- LEFT JOIN code_area AS c ON b.city_code = c.code
|
|
|
+ query := fmt.Sprintf(`
|
|
|
+ SELECT
|
|
|
+ b.name,
|
|
|
+ t.id,
|
|
|
+ t.name_id,
|
|
|
+ t.createtime,
|
|
|
+ t.updatetime,
|
|
|
+ c.area,
|
|
|
+ c.city,
|
|
|
+ class.name AS buyerclass
|
|
|
+
|
|
|
+ FROM
|
|
|
+ dws_f_ent_tags AS t
|
|
|
+ LEFT JOIN code_buyerclass AS class ON class.code = t.labelvalues
|
|
|
+ LEFT JOIN dws_f_ent_baseinfo AS b ON b.name_id = t.name_id
|
|
|
+ LEFT JOIN code_area AS c ON b.city_code = c.code
|
|
|
|
|
|
WHERE t.createtime > '%v' OR t.updatetime > '%v'
|
|
|
- ORDER BY t.id ASC
|
|
|
- LIMIT %d, %d;
|
|
|
- `, curTime, curTime, offset, rowsPerPage)
|
|
|
+ ORDER BY t.createtime ASC
|
|
|
+ LIMIT %d, %d;
|
|
|
+ `, curTime, curTime, offset, rowsPerPage)
|
|
|
|
|
|
- result := MysqlB.SelectBySql(insertquery)
|
|
|
+ result := MysqlB.SelectBySql(query)
|
|
|
+ if result == nil {
|
|
|
+ break
|
|
|
+ }
|
|
|
|
|
|
if len(*result) > 0 {
|
|
|
for _, re := range *result {
|
|
@@ -52,6 +57,20 @@ func buyerOnce() {
|
|
|
tmp["province"] = re["area"]
|
|
|
tmp["city"] = re["city"]
|
|
|
tmp["buyerclass"] = re["buyerclass"]
|
|
|
+
|
|
|
+ if re["createtime"] != nil {
|
|
|
+ if createtime, ok := re["createtime"].(time.Time); ok {
|
|
|
+ tmp["createtime"] = createtime.Unix()
|
|
|
+ if re["updatetime"] != nil {
|
|
|
+ if updatetime, ok := re["updatetime"].(time.Time); ok {
|
|
|
+ tmp["updatetime"] = updatetime.Unix()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ tmp["updatetime"] = createtime.Unix()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
sql := fmt.Sprintf(`select * from dws_f_ent_contact where name_id = '%v'`, re["name_id"])
|
|
|
|
|
|
counts := MysqlB.SelectBySql(sql)
|
|
@@ -64,7 +83,10 @@ func buyerOnce() {
|
|
|
}
|
|
|
total = total + len(arrEs)
|
|
|
|
|
|
- Es.InsertOrUpdate(config.Conf.DB.Es.IndexBuyer, arrEs)
|
|
|
+ err := Es.InsertOrUpdate(config.Conf.DB.Es.IndexBuyer, arrEs)
|
|
|
+ if err != nil {
|
|
|
+ log.Info("buyerOnce", zap.Any("InsertOrUpdate err", err))
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if len(arrEs) < rowsPerPage {
|
|
@@ -79,7 +101,7 @@ func buyerOnce() {
|
|
|
|
|
|
//buyerall 全量数据
|
|
|
func buyerall() {
|
|
|
- rowsPerPage := 10000
|
|
|
+ rowsPerPage := 5000
|
|
|
currentPage := 1
|
|
|
total := 0
|
|
|
|
|
@@ -88,27 +110,33 @@ func buyerall() {
|
|
|
arrEs := make([]map[string]interface{}, 0)
|
|
|
offset := (currentPage - 1) * rowsPerPage
|
|
|
query := fmt.Sprintf(`
|
|
|
- SELECT
|
|
|
- b.name,
|
|
|
- t.id,
|
|
|
- t.name_id,
|
|
|
- c.area,
|
|
|
- c.city,
|
|
|
- class.name AS buyerclass
|
|
|
-
|
|
|
- FROM
|
|
|
- dws_f_ent_tags AS t
|
|
|
- LEFT JOIN code_buyerclass AS class ON class.code = t.labelvalues
|
|
|
- LEFT JOIN dws_f_ent_baseinfo AS b ON b.name_id = t.name_id
|
|
|
- LEFT JOIN code_area AS c ON b.city_code = c.code
|
|
|
-
|
|
|
- ORDER BY t.id ASC
|
|
|
+ SELECT
|
|
|
+ b.name,
|
|
|
+ t.id,
|
|
|
+ t.name_id,
|
|
|
+ t.createtime,
|
|
|
+ t.updatetime,
|
|
|
+ c.area,
|
|
|
+ c.city,
|
|
|
+ class.name AS buyerclass
|
|
|
+
|
|
|
+ FROM
|
|
|
+ dws_f_ent_tags AS t
|
|
|
+ LEFT JOIN code_buyerclass AS class ON class.code = t.labelvalues
|
|
|
+ LEFT JOIN dws_f_ent_baseinfo AS b ON b.name_id = t.name_id
|
|
|
+ LEFT JOIN code_area AS c ON b.city_code = c.code
|
|
|
+
|
|
|
+ ORDER BY t.createtime ASC
|
|
|
|
|
|
- LIMIT %d, %d;
|
|
|
- `, offset, rowsPerPage)
|
|
|
+ LIMIT %d, %d;
|
|
|
+ `, offset, rowsPerPage)
|
|
|
|
|
|
result := MysqlB.SelectBySql(query)
|
|
|
|
|
|
+ if result == nil {
|
|
|
+ break
|
|
|
+ }
|
|
|
+
|
|
|
if len(*result) > 0 {
|
|
|
for _, re := range *result {
|
|
|
tmp := make(map[string]interface{}, 0)
|
|
@@ -119,8 +147,20 @@ func buyerall() {
|
|
|
tmp["province"] = re["area"]
|
|
|
tmp["city"] = re["city"]
|
|
|
tmp["buyerclass"] = re["buyerclass"]
|
|
|
+ if re["createtime"] != nil {
|
|
|
+ if createtime, ok := re["createtime"].(time.Time); ok {
|
|
|
+ tmp["createtime"] = createtime.Unix()
|
|
|
+ if re["updatetime"] != nil {
|
|
|
+ if updatetime, ok := re["updatetime"].(time.Time); ok {
|
|
|
+ tmp["updatetime"] = updatetime.Unix()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ tmp["updatetime"] = createtime.Unix()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- sql := fmt.Sprintf(`select * from dws_f_ent_contact where name_id = '%v'`, re["name_id"])
|
|
|
+ sql := fmt.Sprintf(`select id from dws_f_ent_contact where name_id = '%v'`, re["name_id"])
|
|
|
|
|
|
counts := MysqlB.SelectBySql(sql)
|
|
|
if len(*counts) > 0 {
|