Преглед на файлове

【修复查询采购单位bug】

wcc преди 2 години
родител
ревизия
be62235180
променени са 1 файла, в които са добавени 14 реда и са изтрити 14 реда
  1. 14 14
      createEsIndex/buyertask.go

+ 14 - 14
createEsIndex/buyertask.go

@@ -18,14 +18,12 @@ func buyerOnce() {
 
 	rowsPerPage := 1000
 	now := time.Now()
-	//tarTime := time.Date(now.Year(), now.Month(), now.Day()-7, 00, 00, 00, 00, time.Local)
+	tarTime := time.Date(now.Year(), now.Month(), now.Day()-1, 00, 00, 00, 00, time.Local)
+	curTime := tarTime.Format("2006-01-02")
 
-	curTime := now.Format("2006-01-02")
-
-	finalId := 0
-	lastSql := fmt.Sprintf(`
+	countSql := fmt.Sprintf(`
 	 SELECT
-              t.id
+              count(t.id)
 
           FROM
               dws_f_ent_tags AS t
@@ -36,12 +34,14 @@ func buyerOnce() {
           ORDER BY t.id DESC  LIMIT 1
 `, curTime, curTime)
 
-	lastInfo := Mysql.SelectBySql(lastSql)
-	if len(*lastInfo) > 0 {
-		finalId = util.IntAll((*lastInfo)[0]["id"])
+	dataCounts := Mysql.CountBySql(countSql)
+	if dataCounts > 0 {
+		log.Info("buyerOnce", zap.Any(fmt.Sprintf("总数:%s", curTime), dataCounts))
+	} else {
+		log.Info("buyerOnce", zap.String(curTime, "没有更新数据"))
+		return
 	}
 
-	log.Info("buyerOnce", zap.Int("finalId", finalId))
 	lastid, total := 0, 0
 	realCount := 0
 
@@ -64,10 +64,10 @@ func buyerOnce() {
                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'
+			WHERE  (t.createtime >= '%v' OR t.updatetime >= '%v') and ( t.id > %d ) 
            ORDER BY t.id ASC
           LIMIT %d;
-      `, curTime, curTime, rowsPerPage)
+      `, curTime, curTime, lastid, rowsPerPage)
 
 		ctx := context.Background()
 		rows, err := Mysql.DB.QueryContext(ctx, query)
@@ -75,7 +75,7 @@ func buyerOnce() {
 			log.Info("dealData", zap.Any("QueryContext err", err))
 		}
 
-		if finalId == lastid {
+		if total >= int(dataCounts) {
 			log.Info("buyerOnce over", zap.Any("total", total), zap.Any("lastid", lastid))
 			break
 		}
@@ -114,6 +114,7 @@ func buyerOnce() {
 			if total%100 == 0 {
 				log.Info("buyerOnce", zap.Int("current total", total))
 			}
+
 			lastid = util.IntAll(ret["id"])
 
 			name := util.ObjToString(ret["name"])
@@ -165,7 +166,6 @@ func buyerOnce() {
 				if err != nil {
 					log.Info("buyerOnce", zap.Any("InsertOrUpdate err", err))
 				}
-				log.Info("buyerOnce", zap.Any("ret ", ret))
 			}
 
 		}