Browse Source

测试通过

qdy 3 months ago
parent
commit
eeef81a3a5

+ 2
- 2
functions/heath.go View File

@@ -6,11 +6,11 @@ import (
6 6
 	"github.com/gin-gonic/gin"
7 7
 
8 8
 	"git.x2erp.com/qdy/go-base/types"
9
-	"git.x2erp.com/qdy/go-db/factory"
9
+	"git.x2erp.com/qdy/go-db/factory/database"
10 10
 )
11 11
 
12 12
 // HealthHandler 返回一个处理函数
13
-func HealthHandler(dbFactory *factory.DBFactory, dbType string) gin.HandlerFunc {
13
+func HealthHandler(dbFactory *database.DBFactory, dbType string) gin.HandlerFunc {
14 14
 	return func(c *gin.Context) {
15 15
 
16 16
 		dbFactory.TestConnection(dbType)

+ 2
- 2
functions/info.go View File

@@ -7,11 +7,11 @@ import (
7 7
 
8 8
 	"git.x2erp.com/qdy/go-base/config"
9 9
 	"git.x2erp.com/qdy/go-base/types"
10
-	"git.x2erp.com/qdy/go-db/factory"
10
+	"git.x2erp.com/qdy/go-db/factory/database"
11 11
 )
12 12
 
13 13
 // InfoHandler 数据库信息
14
-func InfoHandler(dbFactory *factory.DBFactory) gin.HandlerFunc {
14
+func InfoHandler(dbFactory *database.DBFactory) gin.HandlerFunc {
15 15
 	return func(c *gin.Context) {
16 16
 		dbConfig := config.GetConfig()
17 17
 		drivers := dbFactory.GetAvailableDrivers()

+ 4
- 4
functions/query_csv.go View File

@@ -5,7 +5,7 @@ import (
5 5
 
6 6
 	"git.x2erp.com/qdy/go-base/mycsv"
7 7
 	"git.x2erp.com/qdy/go-base/types"
8
-	"git.x2erp.com/qdy/go-db/factory"
8
+	"git.x2erp.com/qdy/go-db/factory/database"
9 9
 )
10 10
 
11 11
 // 统一的错误响应处理
@@ -23,7 +23,7 @@ func handleSuccessResponseCSV(c *gin.Context, csvData []byte) {
23 23
 }
24 24
 
25 25
 // 执行查询,返回CSV数据格式。无参数查询
26
-func QueryToCSV(dbFactory *factory.DBFactory) func(c *gin.Context, req types.QueryRequest) {
26
+func QueryToCSV(dbFactory *database.DBFactory) func(c *gin.Context, req types.QueryRequest) {
27 27
 	return func(c *gin.Context, req types.QueryRequest) {
28 28
 		csvData, err := dbFactory.QueryToCSV(req.SQL, req.WriterHeader)
29 29
 		if err != nil {
@@ -35,7 +35,7 @@ func QueryToCSV(dbFactory *factory.DBFactory) func(c *gin.Context, req types.Que
35 35
 }
36 36
 
37 37
 // 执行查询,返回CSV数据格式。带参数名称进行查询
38
-func QueryParamNameToCSV(dbFactory *factory.DBFactory) func(c *gin.Context, req types.QueryRequest) {
38
+func QueryParamNameToCSV(dbFactory *database.DBFactory) func(c *gin.Context, req types.QueryRequest) {
39 39
 	return func(c *gin.Context, req types.QueryRequest) {
40 40
 
41 41
 		csvData, err := dbFactory.QueryParamsNameToCSV(req.SQL, req.WriterHeader, req.Params)
@@ -48,7 +48,7 @@ func QueryParamNameToCSV(dbFactory *factory.DBFactory) func(c *gin.Context, req
48 48
 }
49 49
 
50 50
 // 执行查询,返回CSV数据格式。带占位参数进行查询
51
-func QueryPositionalToCSV(dbFactory *factory.DBFactory) func(c *gin.Context, req types.QueryRequest) {
51
+func QueryPositionalToCSV(dbFactory *database.DBFactory) func(c *gin.Context, req types.QueryRequest) {
52 52
 	return func(c *gin.Context, req types.QueryRequest) {
53 53
 		csvData, err := dbFactory.QueryPositionalToCSV(req.SQL, req.WriterHeader, req.PositionalParams)
54 54
 		if err != nil {

+ 4
- 4
functions/query_json.go View File

@@ -4,11 +4,11 @@ import (
4 4
 	"github.com/gin-gonic/gin"
5 5
 
6 6
 	"git.x2erp.com/qdy/go-base/types"
7
-	"git.x2erp.com/qdy/go-db/factory"
7
+	"git.x2erp.com/qdy/go-db/factory/database"
8 8
 )
9 9
 
10 10
 // 执行查询,返回CSV数据格式。无参数查询
11
-func QueryToJSON(dbFactory *factory.DBFactory) func(c *gin.Context, req types.QueryRequest) {
11
+func QueryToJSON(dbFactory *database.DBFactory) func(c *gin.Context, req types.QueryRequest) {
12 12
 	return func(c *gin.Context, req types.QueryRequest) {
13 13
 		result := dbFactory.QueryToJSON(req.SQL)
14 14
 		c.JSON(200, result)
@@ -16,7 +16,7 @@ func QueryToJSON(dbFactory *factory.DBFactory) func(c *gin.Context, req types.Qu
16 16
 }
17 17
 
18 18
 // 执行查询,返回CSV数据格式。带参数名称进行查询
19
-func QueryParamNameToJSON(dbFactory *factory.DBFactory) func(c *gin.Context, req types.QueryRequest) {
19
+func QueryParamNameToJSON(dbFactory *database.DBFactory) func(c *gin.Context, req types.QueryRequest) {
20 20
 	return func(c *gin.Context, req types.QueryRequest) {
21 21
 		result := dbFactory.QueryParamsNameToJSON(req.SQL, req.Params)
22 22
 		c.JSON(200, result)
@@ -24,7 +24,7 @@ func QueryParamNameToJSON(dbFactory *factory.DBFactory) func(c *gin.Context, req
24 24
 }
25 25
 
26 26
 // 执行查询,返回JSON数据格式。带占位参数进行查询
27
-func QueryPositionalToJSON(dbFactory *factory.DBFactory) func(c *gin.Context, req types.QueryRequest) {
27
+func QueryPositionalToJSON(dbFactory *database.DBFactory) func(c *gin.Context, req types.QueryRequest) {
28 28
 	return func(c *gin.Context, req types.QueryRequest) {
29 29
 		result := dbFactory.QueryPositionalToJSON(req.SQL, req.PositionalParams)
30 30
 

+ 3
- 3
main.go View File

@@ -12,7 +12,7 @@ import (
12 12
 
13 13
 	"git.x2erp.com/qdy/go-base/config"
14 14
 	"git.x2erp.com/qdy/go-base/types"
15
-	"git.x2erp.com/qdy/go-db/factory"
15
+	"git.x2erp.com/qdy/go-db/factory/database"
16 16
 	"git.x2erp.com/qdy/go-service-agent/auth"
17 17
 	"git.x2erp.com/qdy/go-service-agent/functions"
18 18
 	"github.com/gin-gonic/gin"
@@ -44,7 +44,7 @@ func startHTTPServer() {
44 44
 	cfg := config.GetConfig()
45 45
 	serviceConfig := cfg.GetService()
46 46
 
47
-	dbFactory, err := factory.GetDBFactory()
47
+	dbFactory, err := database.GetDBFactory()
48 48
 	if err != nil {
49 49
 		log.Fatalf("Failed to create DB factory: %v", err)
50 50
 	}
@@ -141,7 +141,7 @@ func setupTrustedProxiesRouter(router *gin.Engine, trimmedProxies []string) {
141 141
 
142 142
 }
143 143
 
144
-func setupGracefulShutdown(dbFactory *factory.DBFactory) {
144
+func setupGracefulShutdown(dbFactory *database.DBFactory) {
145 145
 	signalCh := make(chan os.Signal, 1)
146 146
 	signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)
147 147
 

+ 23
- 49
test/my0_test.go View File

@@ -3,14 +3,14 @@ package main
3 3
 import (
4 4
 	"fmt"
5 5
 	"log"
6
-	"strings"
7 6
 	"sync"
8 7
 	"testing"
9 8
 	"time"
10 9
 
11 10
 	"git.x2erp.com/qdy/go-base/config"
12 11
 	"git.x2erp.com/qdy/go-base/types"
13
-	"git.x2erp.com/qdy/go-db/factory"
12
+	"git.x2erp.com/qdy/go-db/factory/doris"
13
+	"git.x2erp.com/qdy/go-db/factory/http"
14 14
 )
15 15
 
16 16
 // // QueryRequest 查询请求结构体
@@ -30,16 +30,15 @@ type PageConfig1 struct {
30 30
 
31 31
 // 查询任务
32 32
 type QueryTask1 struct {
33
-	Page           int
34
-	StartRow       int
35
-	EndRow         int
36
-	QuerySQL       string
37
-	QueryParams    []interface{}
38
-	CSVData        string
39
-	Error          error
40
-	QueryTime      time.Duration
41
-	SaveTime       time.Duration
42
-	LastClothingID string // 上一页最后一条记录的CLOTHING_ID
33
+	Page        int
34
+	StartRow    int
35
+	EndRow      int
36
+	QuerySQL    string
37
+	QueryParams []interface{}
38
+	CSVData     string
39
+	Error       error
40
+	QueryTime   time.Duration
41
+	SaveTime    time.Duration
43 42
 }
44 43
 
45 44
 func TestQueryAndInsertToDoris1(t *testing.T) {
@@ -57,14 +56,14 @@ func TestQueryAndInsertToDoris1(t *testing.T) {
57 56
 	fmt.Printf("开始执行分页查询,总共%d行,每页%d条,%d线程工作\n", pageConfig.TotalRows, pageConfig.PageSize, pageConfig.MaxWorkers)
58 57
 
59 58
 	// 1. 获取HTTP工厂实例
60
-	httpFactory, err := factory.GetHTTPFactory()
59
+	httpFactory, err := http.GetHTTPFactory()
61 60
 	if err != nil {
62 61
 		t.Fatalf("Failed to get HTTP factory: %v", err)
63 62
 	}
64 63
 	fmt.Println("HTTP factory created successfully")
65 64
 
66 65
 	// 7. 获取Doris工厂实例
67
-	dorisFactory, err := factory.GetDorisFactory(httpFactory)
66
+	dorisFactory, err := doris.GetDorisFactory(httpFactory)
68 67
 	if err != nil {
69 68
 		t.Fatalf("Failed to get Doris factory: %v", err)
70 69
 	}
@@ -110,7 +109,7 @@ func TestQueryAndInsertToDoris1(t *testing.T) {
110 109
 
111 110
 			for task := range taskChan {
112 111
 				fmt.Printf("Worker %d 处理第 %d 页 (行 %d-%d, CLOTHING_ID > %s)...\n",
113
-					workerID, task.Page, task.StartRow, task.EndRow, task.LastClothingID)
112
+					workerID, task.Page, task.StartRow, task.EndRow)
114 113
 
115 114
 				// 记录查询开始时间
116 115
 				queryStartTime := time.Now()
@@ -196,26 +195,10 @@ func TestQueryAndInsertToDoris1(t *testing.T) {
196 195
 				completedTasks++
197 196
 
198 197
 				fmt.Printf("✅ Worker 完成第 %d 页 (行 %d-%d, CLOTHING_ID > %s)\n",
199
-					task.Page, task.StartRow, task.EndRow, task.LastClothingID)
198
+					task.Page, task.StartRow, task.EndRow)
200 199
 				fmt.Printf("   查询耗时: %v, 保存耗时: %v\n", task.QueryTime, task.SaveTime)
201 200
 				fmt.Printf("   估算数据行数: %d\n", estimatedRows)
202 201
 
203
-				// 从CSV数据中提取最后一行的CLOTHING_ID
204
-				if task.CSVData != "" {
205
-					// 简单实现:取最后一行第一列的第一个记录
206
-					// 这里假设CSV格式是逗号分隔,没有标题行
207
-					lines := strings.Split(strings.TrimSpace(task.CSVData), "\n")
208
-					if len(lines) > 0 {
209
-						// 取最后一行(如果有多行数据)
210
-						lastLine := lines[len(lines)-1]
211
-						fields := strings.Split(lastLine, ",")
212
-						if len(fields) > 0 {
213
-							// 更新任务的LastClothingID
214
-							task.LastClothingID = strings.TrimSpace(fields[0]) // CLOTHING_ID是第一列
215
-							fmt.Printf("   提取到最后一个CLOTHING_ID: %s\n", task.LastClothingID)
216
-						}
217
-					}
218
-				}
219 202
 			}
220 203
 
221 204
 			mu.Unlock()
@@ -231,9 +214,6 @@ func TestQueryAndInsertToDoris1(t *testing.T) {
231 214
 	// 生成任务并发送到任务通道
232 215
 	fmt.Println("\n📋 开始生成查询任务...")
233 216
 
234
-	// 初始CLOTHING_ID为"0"
235
-	lastClothingID := "A"
236
-
237 217
 	for page := 1; page <= totalPages; page++ {
238 218
 		startRow := pageConfig.StartRow + (page-1)*pageConfig.PageSize + 1
239 219
 		endRow := pageConfig.StartRow + page*pageConfig.PageSize
@@ -245,24 +225,19 @@ func TestQueryAndInsertToDoris1(t *testing.T) {
245 225
 		}
246 226
 
247 227
 		// 生成查询SQL(使用参数模式)
248
-		querySQL, queryParams := getSQLWithPagination(startRow, endRow, lastClothingID)
228
+		querySQL, queryParams := getSQLWithPagination(startRow, endRow)
249 229
 
250 230
 		task := QueryTask{
251
-			Page:           page,
252
-			StartRow:       startRow,
253
-			EndRow:         endRow,
254
-			QuerySQL:       querySQL,
255
-			QueryParams:    queryParams,
256
-			LastClothingID: lastClothingID,
231
+			Page:        page,
232
+			StartRow:    startRow,
233
+			EndRow:      endRow,
234
+			QuerySQL:    querySQL,
235
+			QueryParams: queryParams,
257 236
 		}
258 237
 
259
-		fmt.Printf("生成第 %d 页任务 (行 %d-%d), 使用CLOTHING_ID > '%s'\n",
260
-			page, startRow, endRow, lastClothingID)
238
+		fmt.Printf("生成第 %d 页任务 (行 %d-%d), 使用CLOTHING_ID > '%s'\n", page, startRow, endRow)
261 239
 		taskChan <- task
262 240
 
263
-		// 注意:在实际场景中,lastClothingID需要在任务完成后更新
264
-		// 这里简化处理,每个任务使用相同的lastClothingID
265
-		// 更好的做法是使用任务队列和结果回调来更新lastClothingID
266 241
 	}
267 242
 
268 243
 	// 关闭任务通道,通知worker没有更多任务
@@ -299,7 +274,7 @@ func TestQueryAndInsertToDoris1(t *testing.T) {
299 274
 
300 275
 // getSQLWithPagination 生成带分页的SQL语句(参数模式)
301 276
 // 返回SQL语句和参数映射
302
-func getSQLWithPagination1(startRow, endRow int, lastClothingID string) (string, []interface{}) {
277
+func getSQLWithPagination1(startRow, endRow int) (string, []interface{}) {
303 278
 	sql := `SELECT
304 279
     CLOTHING_ID,
305 280
     CLOTHING_YEAR,
@@ -319,7 +294,6 @@ WHERE rn > :3`
319 294
 
320 295
 	// 创建参数映射
321 296
 	params := []interface{}{
322
-		lastClothingID,
323 297
 		endRow,
324 298
 		startRow - 1, // WHERE rn > :start_row 所以是startRow-1
325 299
 	}

+ 24
- 48
test/my_ora_clothingToDoris_test.go View File

@@ -3,14 +3,14 @@ package main
3 3
 import (
4 4
 	"fmt"
5 5
 	"log"
6
-	"strings"
7 6
 	"sync"
8 7
 	"testing"
9 8
 	"time"
10 9
 
11 10
 	"git.x2erp.com/qdy/go-base/config"
12 11
 	"git.x2erp.com/qdy/go-base/types"
13
-	"git.x2erp.com/qdy/go-db/factory"
12
+	"git.x2erp.com/qdy/go-db/factory/doris"
13
+	"git.x2erp.com/qdy/go-db/factory/http"
14 14
 )
15 15
 
16 16
 // 一定要执行环境变量
@@ -33,16 +33,15 @@ type PageConfig struct {
33 33
 
34 34
 // 查询任务
35 35
 type QueryTask struct {
36
-	Page           int
37
-	StartRow       int
38
-	EndRow         int
39
-	QuerySQL       string
40
-	QueryParams    []interface{}
41
-	CSVData        string
42
-	Error          error
43
-	QueryTime      time.Duration
44
-	SaveTime       time.Duration
45
-	LastClothingID string // 上一页最后一条记录的CLOTHING_ID
36
+	Page        int
37
+	StartRow    int
38
+	EndRow      int
39
+	QuerySQL    string
40
+	QueryParams []interface{}
41
+	CSVData     string
42
+	Error       error
43
+	QueryTime   time.Duration
44
+	SaveTime    time.Duration
46 45
 }
47 46
 
48 47
 func TestQueryAndInsertToDoris(t *testing.T) {
@@ -60,14 +59,14 @@ func TestQueryAndInsertToDoris(t *testing.T) {
60 59
 	fmt.Printf("开始执行分页查询,总共%d行,每页%d条,%d线程工作\n", pageConfig.TotalRows, pageConfig.PageSize, pageConfig.MaxWorkers)
61 60
 
62 61
 	// 1. 获取HTTP工厂实例
63
-	httpFactory, err := factory.GetHTTPFactory()
62
+	httpFactory, err := http.GetHTTPFactory()
64 63
 	if err != nil {
65 64
 		t.Fatalf("Failed to get HTTP factory: %v", err)
66 65
 	}
67 66
 	fmt.Println("HTTP factory created successfully")
68 67
 
69 68
 	// 7. 获取Doris工厂实例
70
-	dorisFactory, err := factory.GetDorisFactory(httpFactory)
69
+	dorisFactory, err := doris.GetDorisFactory(httpFactory)
71 70
 	if err != nil {
72 71
 		t.Fatalf("Failed to get Doris factory: %v", err)
73 72
 	}
@@ -113,7 +112,7 @@ func TestQueryAndInsertToDoris(t *testing.T) {
113 112
 
114 113
 			for task := range taskChan {
115 114
 				fmt.Printf("Worker %d 处理第 %d 页 (行 %d-%d, CLOTHING_ID > %s)...\n",
116
-					workerID, task.Page, task.StartRow, task.EndRow, task.LastClothingID)
115
+					workerID, task.Page, task.StartRow, task.EndRow)
117 116
 
118 117
 				// 记录查询开始时间
119 118
 				queryStartTime := time.Now()
@@ -199,26 +198,10 @@ func TestQueryAndInsertToDoris(t *testing.T) {
199 198
 				completedTasks++
200 199
 
201 200
 				fmt.Printf("✅ Worker 完成第 %d 页 (行 %d-%d, CLOTHING_ID > %s)\n",
202
-					task.Page, task.StartRow, task.EndRow, task.LastClothingID)
201
+					task.Page, task.StartRow, task.EndRow)
203 202
 				fmt.Printf("   查询耗时: %v, 保存耗时: %v\n", task.QueryTime, task.SaveTime)
204 203
 				fmt.Printf("   估算数据行数: %d\n", estimatedRows)
205 204
 
206
-				// 从CSV数据中提取最后一行的CLOTHING_ID
207
-				if task.CSVData != "" {
208
-					// 简单实现:取最后一行第一列的第一个记录
209
-					// 这里假设CSV格式是逗号分隔,没有标题行
210
-					lines := strings.Split(strings.TrimSpace(task.CSVData), "\n")
211
-					if len(lines) > 0 {
212
-						// 取最后一行(如果有多行数据)
213
-						lastLine := lines[len(lines)-1]
214
-						fields := strings.Split(lastLine, ",")
215
-						if len(fields) > 0 {
216
-							// 更新任务的LastClothingID
217
-							task.LastClothingID = strings.TrimSpace(fields[0]) // CLOTHING_ID是第一列
218
-							fmt.Printf("   提取到最后一个CLOTHING_ID: %s\n", task.LastClothingID)
219
-						}
220
-					}
221
-				}
222 205
 			}
223 206
 
224 207
 			mu.Unlock()
@@ -234,9 +217,6 @@ func TestQueryAndInsertToDoris(t *testing.T) {
234 217
 	// 生成任务并发送到任务通道
235 218
 	fmt.Println("\n📋 开始生成查询任务...")
236 219
 
237
-	// 初始CLOTHING_ID为"0"
238
-	lastClothingID := "0"
239
-
240 220
 	for page := 1; page <= totalPages; page++ {
241 221
 		startRow := pageConfig.StartRow + (page-1)*pageConfig.PageSize + 1
242 222
 		endRow := pageConfig.StartRow + page*pageConfig.PageSize
@@ -248,24 +228,20 @@ func TestQueryAndInsertToDoris(t *testing.T) {
248 228
 		}
249 229
 
250 230
 		// 生成查询SQL(使用参数模式)
251
-		querySQL, queryParams := getSQLWithPagination(startRow, endRow, lastClothingID)
231
+		querySQL, queryParams := getSQLWithPagination(startRow, endRow)
252 232
 
253 233
 		task := QueryTask{
254
-			Page:           page,
255
-			StartRow:       startRow,
256
-			EndRow:         endRow,
257
-			QuerySQL:       querySQL,
258
-			QueryParams:    queryParams,
259
-			LastClothingID: lastClothingID,
234
+			Page:        page,
235
+			StartRow:    startRow,
236
+			EndRow:      endRow,
237
+			QuerySQL:    querySQL,
238
+			QueryParams: queryParams,
260 239
 		}
261 240
 
262
-		fmt.Printf("生成第 %d 页任务 (行 %d-%d), 使用CLOTHING_ID > '%s'\n",
263
-			page, startRow, endRow, lastClothingID)
241
+		fmt.Printf("生成第 %d 页任务 (行 %d-%d), 使用CLOTHING_ID > '%s'\n", page, startRow, endRow)
242
+
264 243
 		taskChan <- task
265 244
 
266
-		// 注意:在实际场景中,lastClothingID需要在任务完成后更新
267
-		// 这里简化处理,每个任务使用相同的lastClothingID
268
-		// 更好的做法是使用任务队列和结果回调来更新lastClothingID
269 245
 	}
270 246
 
271 247
 	// 关闭任务通道,通知worker没有更多任务
@@ -302,7 +278,7 @@ func TestQueryAndInsertToDoris(t *testing.T) {
302 278
 
303 279
 // getSQLWithPagination 生成带分页的SQL语句(参数模式)
304 280
 // 返回SQL语句和参数映射
305
-func getSQLWithPagination(startRow, endRow int, lastClothingID string) (string, []interface{}) {
281
+func getSQLWithPagination(startRow, endRow int) (string, []interface{}) {
306 282
 	sql := `SELECT
307 283
     CLOTHING_ID,
308 284
     CLOTHING_YEAR,

+ 2
- 2
test/mycsv_test.go View File

@@ -5,11 +5,11 @@ import (
5 5
 	"log"
6 6
 	"testing"
7 7
 
8
-	"git.x2erp.com/qdy/go-db/factory"
8
+	"git.x2erp.com/qdy/go-db/factory/database"
9 9
 )
10 10
 
11 11
 func TestNamedParamsQueryCSV(t *testing.T) {
12
-	factory, err := factory.GetDBFactory()
12
+	factory, err := database.GetDBFactory()
13 13
 	if err != nil {
14 14
 		t.Fatalf("Failed to get DB factory: %v", err)
15 15
 	}

+ 2
- 2
test/mysql_test.go View File

@@ -5,11 +5,11 @@ import (
5 5
 	"log"
6 6
 	"testing"
7 7
 
8
-	"git.x2erp.com/qdy/go-db/factory"
8
+	"git.x2erp.com/qdy/go-db/factory/database"
9 9
 )
10 10
 
11 11
 func TestNamedParamsQuery(t *testing.T) {
12
-	factory, err := factory.GetDBFactory()
12
+	factory, err := database.GetDBFactory()
13 13
 	if err != nil {
14 14
 		t.Fatalf("Failed to get DB factory: %v", err)
15 15
 	}

Loading…
Cancel
Save