add
This commit is contained in:
@@ -38,8 +38,7 @@ type Payload struct {
|
|||||||
|
|
||||||
/* ---------- 单条创建 ---------- */
|
/* ---------- 单条创建 ---------- */
|
||||||
type TradingRecordsCreateRequest struct {
|
type TradingRecordsCreateRequest struct {
|
||||||
EventType string `json:"event_type"`
|
Payload Payload `json:"payload" binding:"required"`
|
||||||
Payload Payload `json:"payload" binding:"required"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type TradingRecordsCreateResponse struct {
|
type TradingRecordsCreateResponse struct {
|
||||||
@@ -73,7 +72,7 @@ func CreateHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
zap.L().Debug("✅ 请求参数验证通过", zap.String("req_id", reqID), zap.String("event_type", req.EventType), zap.Any("payload", req.Payload))
|
zap.L().Debug("✅ 请求参数验证通过", zap.String("req_id", reqID), zap.Any("payload", req.Payload))
|
||||||
|
|
||||||
tx, err := db.DB.Begin()
|
tx, err := db.DB.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -98,7 +97,7 @@ func CreateHandler(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var recordID string
|
var recordID string
|
||||||
err = tx.QueryRow(`INSERT INTO cn_futures_trading_records (event_type, payload) VALUES ('交易中', $1) RETURNING id`, payloadBytes).Scan(&recordID)
|
err = tx.QueryRow(`INSERT INTO cn_futures_trading_records (payload) VALUES ($1) RETURNING id`, payloadBytes).Scan(&recordID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
zap.L().Error("❌ 插入失败", zap.String("req_id", reqID), zap.Error(err))
|
zap.L().Error("❌ 插入失败", zap.String("req_id", reqID), zap.Error(err))
|
||||||
@@ -166,7 +165,7 @@ func CreateBatchHandler(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
stmt, err := tx.Prepare(`INSERT INTO cn_futures_trading_records (event_type, payload) VALUES ('交易中', $1) RETURNING id`)
|
stmt, err := tx.Prepare(`INSERT INTO cn_futures_trading_records (payload) VALUES ($1) RETURNING id`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
zap.L().Error("❌ 预编译语句失败", zap.String("req_id", reqID), zap.Error(err))
|
zap.L().Error("❌ 预编译语句失败", zap.String("req_id", reqID), zap.Error(err))
|
||||||
@@ -190,7 +189,7 @@ func CreateBatchHandler(c *gin.Context) {
|
|||||||
p.OpenDay, _ = strconv.Atoi(row[2])
|
p.OpenDay, _ = strconv.Atoi(row[2])
|
||||||
p.Symbol = row[3]
|
p.Symbol = row[3]
|
||||||
p.Contract = row[4]
|
p.Contract = row[4]
|
||||||
p.Direction = row[5]
|
p.Direction, _ = strconv.Atoi(row[5])
|
||||||
p.OpenPrice, _ = strconv.ParseFloat(row[6], 64)
|
p.OpenPrice, _ = strconv.ParseFloat(row[6], 64)
|
||||||
p.OpenFee, _ = strconv.ParseFloat(row[7], 64)
|
p.OpenFee, _ = strconv.ParseFloat(row[7], 64)
|
||||||
p.CloseYear, _ = strconv.Atoi(row[8])
|
p.CloseYear, _ = strconv.Atoi(row[8])
|
||||||
@@ -226,4 +225,4 @@ func CreateBatchHandler(c *gin.Context) {
|
|||||||
duration := time.Since(startTime)
|
duration := time.Since(startTime)
|
||||||
zap.L().Info("✅ 交易记录批量创建完成", zap.String("req_id", reqID), zap.Int("inserted_count", len(recordIDs)), zap.Duration("duration", duration))
|
zap.L().Info("✅ 交易记录批量创建完成", zap.String("req_id", reqID), zap.Int("inserted_count", len(recordIDs)), zap.Duration("duration", duration))
|
||||||
c.JSON(http.StatusOK, TradingRecordsBatchCreateResponse{Success: true, Message: "批量创建成功", RecordIDs: recordIDs})
|
c.JSON(http.StatusOK, TradingRecordsBatchCreateResponse{Success: true, Message: "批量创建成功", RecordIDs: recordIDs})
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user