From 2d6875c93b25d0b7336c7fa11e066d213259fe2e Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期四, 25 四月 2024 10:02:01 +0800
Subject: [PATCH] 更改定时任务时区设置

---
 serf/sqlite.go |   69 +++-------------------------------
 1 files changed, 6 insertions(+), 63 deletions(-)

diff --git a/serf/sqlite.go b/serf/sqlite.go
index 79021d9..a617e1d 100644
--- a/serf/sqlite.go
+++ b/serf/sqlite.go
@@ -3,7 +3,6 @@
 import (
 	"errors"
 	"fmt"
-	"regexp"
 	"strings"
 
 	"github.com/jinzhu/gorm"
@@ -40,25 +39,25 @@
 
 			tSql := fmt.Sprintf(`PRAGMA table_info("%s")`, table)
 			err := db.Raw(tSql).Scan(&tDescArr).Error
-
-			fmt.Println("tDescArr err:", err, "len(tDescArr)=", len(tDescArr))
 			if err != nil {
 				return nil, errors.New("tableDesc err")
 			}
 
-			fmt.Println(table, "'Columns is:", tDescArr)
 			if tDescArr == nil || len(tDescArr) == 0 {
-				return nil, errors.New(table + " has no column")
+				continue
 			}
 
 			var columnNames []string
+			var columnValues []string
 			for _, col := range tDescArr {
-				columnNames = append(columnNames, fmt.Sprintf(`'||quote("%s")||'`, col.Name))
+				columnNames = append(columnNames, col.Name)
+				columnValues = append(columnValues, fmt.Sprintf(`'||quote("%s")||'`, col.Name))
 			}
 
-			tSql = fmt.Sprintf(`SELECT 'INSERT INTO "%s" VALUES(%s)' as sql FROM "%s";`,
+			tSql = fmt.Sprintf(`SELECT 'INSERT INTO "%s" (%s) VALUES(%s)' as sql FROM "%s";`,
 				table,
 				strings.Join(columnNames, ","),
+				strings.Join(columnValues, ","),
 				table)
 			//fmt.Println("tSql:", tSql)
 
@@ -78,60 +77,4 @@
 	}
 
 	return nil, errors.New("tableNames is nil")
-}
-
-type DbLogger struct {
-}
-
-func (dbLogger *DbLogger) Print(values ...interface{}) {
-	var (
-		level = values[0]
-	)
-
-	fmt.Println("dblogger", values)
-
-	if level == "sql" {
-		msgArr := gorm.LogFormatter(values...)
-		sql := msgArr[3].(string)
-		sql = strings.TrimPrefix(sql, " ")
-		if !strings.HasPrefix(sql, "SELECT") && !strings.HasPrefix(sql, "select") && !strings.Contains(sql, "PRAGMA") && !strings.Contains(sql, "pragma") {
-			affected := values[5].(int64)
-			if affected > 0 { //鎵ц鎴愬姛
-				//鍒ゆ柇鎿嶄綔鐨勬槸鍝紶琛�
-				whereIdx := strings.Index(sql, "WHERE")
-				sqlWithTable := sql
-				if whereIdx > -1 {
-					sqlWithTable = sql[:whereIdx]
-				}
-
-				fmt.Println("鍒ゆ柇鏄摢寮犺〃 sqlWithTable:", sqlWithTable)
-
-				insertReg := regexp.MustCompile(`^\s*(?i:insert)\s`) //insert
-				updateReg := regexp.MustCompile(`^\s*(?i:update)\s`) //update
-				delReg := regexp.MustCompile(`^\s*(?i:delete)\s`)    //delete
-
-				if insertReg.MatchString(sqlWithTable) {
-					fmt.Println("鎻掑叆鎿嶄綔")
-					for _, t := range agent.syncTables {
-						reg := regexp.MustCompile(`\s+\"?(?i:` + t + `)\"?\s+`)
-						if reg.MatchString(sqlWithTable) {
-							fmt.Println("灞炰簬鍚屾琛�:", t)
-							syncSqlChan <- sql
-						}
-					}
-				} else if updateReg.MatchString(sqlWithTable) || delReg.MatchString(sqlWithTable) {
-					fmt.Println("鍒犻櫎鎴栬�呮洿鏂�")
-					for _, t := range agent.syncTables {
-						reg := regexp.MustCompile(`\s+\"?(?i:` + t + `)\"?\s+`)
-						if reg.MatchString(sqlWithTable) {
-							fmt.Println("灞炰簬鍚屾琛�:", t)
-							syncSqlChan <- sql
-						}
-					}
-				}
-			}
-		}
-	} else {
-		fmt.Println("dbLogger level!=sql")
-	}
 }

--
Gitblit v1.8.0