diff --git a/services/cn_futures_trading_records/src/crud/create.go b/services/cn_futures_trading_records/src/crud/create.go index 7a5127b..6a0d5f7 100644 --- a/services/cn_futures_trading_records/src/crud/create.go +++ b/services/cn_futures_trading_records/src/crud/create.go @@ -38,8 +38,7 @@ type Payload struct { /* ---------- 单条创建 ---------- */ type TradingRecordsCreateRequest struct { - EventType string `json:"event_type"` - Payload Payload `json:"payload" binding:"required"` + Payload Payload `json:"payload" binding:"required"` } type TradingRecordsCreateResponse struct { @@ -73,7 +72,7 @@ func CreateHandler(c *gin.Context) { 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() if err != nil { @@ -98,7 +97,7 @@ func CreateHandler(c *gin.Context) { } 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 { tx.Rollback() 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 { tx.Rollback() 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.Symbol = row[3] p.Contract = row[4] - p.Direction = row[5] + p.Direction, _ = strconv.Atoi(row[5]) p.OpenPrice, _ = strconv.ParseFloat(row[6], 64) p.OpenFee, _ = strconv.ParseFloat(row[7], 64) p.CloseYear, _ = strconv.Atoi(row[8]) @@ -226,4 +225,4 @@ func CreateBatchHandler(c *gin.Context) { duration := time.Since(startTime) 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}) -} +} \ No newline at end of file