qdy 3 ay önce
ebeveyn
işleme
3af07894dc

+ 7
- 0
factory/database/db_factory.go Dosyayı Görüntüle

@@ -112,6 +112,13 @@ func (f *DBFactory) Close() error {
112 112
 	return nil
113 113
 }
114 114
 
115
+// GetDBType 得到当前使用数据库类型
116
+func (f *DBFactory) GetDBType() string {
117
+	cfg := config.GetConfig()
118
+	dbConfig := cfg.GetDatabase()
119
+	return dbConfig.Type
120
+}
121
+
115 122
 // QueryToJSON 快捷查询,直接返回 JSON 字节流
116 123
 func (f *DBFactory) QueryToJSON(sql string) *types.QueryResult {
117 124
 	return functions.QueryToJSON(f.db, sql)

+ 16
- 16
gct.sh Dosyayı Görüntüle

@@ -52,18 +52,18 @@ else
52 52
 fi
53 53
 
54 54
 # 检查标签是否已存在
55
-if git rev-parse "$VERSION_TAG" >/dev/null 2>&1; then
56
-    echo "错误: 标签 '$VERSION_TAG' 已经存在。"
57
-    exit 1
58
-fi
55
+#if git rev-parse "$VERSION_TAG" >/dev/null 2>&1; then
56
+ #   echo "错误: 标签 '$VERSION_TAG' 已经存在。"
57
+  #  exit 1
58
+#fi
59 59
 
60 60
 # 创建标签
61
-git tag "$VERSION_TAG"
62
-if [ $? -ne 0 ]; then
63
-    echo "错误: 创建标签失败。"
64
-    exit 1
65
-fi
66
-echo "✅ 标签 '$VERSION_TAG' 已创建"
61
+#git tag "$VERSION_TAG"
62
+#if [ $? -ne 0 ]; then
63
+#    echo "错误: 创建标签失败。"
64
+#    exit 1
65
+#fi
66
+#echo "✅ 标签 '$VERSION_TAG' 已创建"
67 67
 
68 68
 # 推送到远程仓库并推送标签
69 69
 echo "正在推送到远程仓库..."
@@ -73,10 +73,10 @@ if [ $? -ne 0 ]; then
73 73
     exit 1
74 74
 fi
75 75
 
76
-git push origin "$VERSION_TAG"
77
-if [ $? -ne 0 ]; then
78
-    echo "错误: 推送标签失败。"
79
-    exit 1
80
-fi
76
+#git push origin "$VERSION_TAG"
77
+#if [ $? -ne 0 ]; then
78
+#    echo "错误: 推送标签失败。"
79
+#    exit 1
80
+#fi
81 81
 
82
-echo "✅ 完成!提交已推送,版本标签 $VERSION_TAG 已创建并推送。"
82
+#echo "✅ 完成!提交已推送,版本标签 $VERSION_TAG 已创建并推送。"

+ 36
- 0
myhandle/queryHandlerBytes.go Dosyayı Görüntüle

@@ -0,0 +1,36 @@
1
+package myhandle
2
+
3
+import (
4
+	"encoding/json"
5
+	"net/http"
6
+
7
+	"git.x2erp.com/qdy/go-base/types"
8
+	"git.x2erp.com/qdy/go-db/factory/database"
9
+)
10
+
11
+// 最简单的 queryHandler,只处理 []byte 返回
12
+func QueryHandlerBytes(
13
+	w http.ResponseWriter,
14
+	r *http.Request,
15
+	dbFactory *database.DBFactory,
16
+	handlerFunc func(*database.DBFactory, types.QueryRequest) []byte,
17
+) {
18
+	// 解析请求参数
19
+	var req types.QueryRequest
20
+	if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
21
+		// 返回 CSV 格式的错误信息
22
+		errorCSV := "error,Invalid request body\n"
23
+		w.Header().Set("Content-Type", "text/csv")
24
+		w.WriteHeader(http.StatusBadRequest)
25
+		w.Write([]byte(errorCSV))
26
+		return
27
+	}
28
+
29
+	// 调用业务逻辑函数
30
+	csvData := handlerFunc(dbFactory, req)
31
+
32
+	// 直接返回 CSV 数据(包含错误信息时也会被正确处理)
33
+	w.Header().Set("Content-Type", "text/csv")
34
+	w.Header().Set("Content-Disposition", "attachment; filename=query_result.csv")
35
+	w.Write(csvData)
36
+}

+ 38
- 0
myhandle/queryHandlerJson.go Dosyayı Görüntüle

@@ -0,0 +1,38 @@
1
+package myhandle
2
+
3
+import (
4
+	"encoding/json"
5
+	"net/http"
6
+	"time"
7
+
8
+	"git.x2erp.com/qdy/go-base/types"
9
+	"git.x2erp.com/qdy/go-db/factory/database"
10
+)
11
+
12
+// queryHandler - 最简单的版本
13
+func QueryHandlerJson(
14
+	w http.ResponseWriter,
15
+	r *http.Request,
16
+	dbFactory *database.DBFactory,
17
+	handlerFunc func(*database.DBFactory, types.QueryRequest) *types.QueryResult,
18
+) {
19
+	// 解析请求参数
20
+	var req types.QueryRequest
21
+	if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
22
+		// 如果解析失败,也返回 QueryResult 格式
23
+		w.Header().Set("Content-Type", "application/json")
24
+		json.NewEncoder(w).Encode(&types.QueryResult{
25
+			Success: false,
26
+			Error:   "Invalid request body: " + err.Error(),
27
+			Time:    time.Now().Format(time.RFC3339),
28
+		})
29
+		return
30
+	}
31
+
32
+	// 执行业务逻辑
33
+	result := handlerFunc(dbFactory, req)
34
+
35
+	// 设置头,写入结果
36
+	w.Header().Set("Content-Type", "application/json")
37
+	json.NewEncoder(w).Encode(result)
38
+}

Loading…
İptal
Kaydet