add
This commit is contained in:
@@ -14,17 +14,17 @@ import (
|
|||||||
var shanghaiLoc *time.Location
|
var shanghaiLoc *time.Location
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
var err error
|
var err error
|
||||||
shanghaiLoc, err = time.LoadLocation("Asia/Shanghai")
|
shanghaiLoc, err = time.LoadLocation("Asia/Shanghai")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// 尝试备选时区名称
|
// 尝试备选时区名称
|
||||||
shanghaiLoc, err = time.LoadLocation("PRC")
|
shanghaiLoc, err = time.LoadLocation("PRC")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// 若仍失败,手动设置东八区偏移
|
// 若仍失败,手动设置东八区偏移
|
||||||
shanghaiLoc = time.FixedZone("CST", 8*3600)
|
shanghaiLoc = time.FixedZone("CST", 8*3600)
|
||||||
log.Printf("警告:加载时区失败,使用手动东八区偏移: %v", err)
|
log.Printf("警告:加载时区失败,使用手动东八区偏移: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init 初始化日志(依赖配置文件已加载)
|
// Init 初始化日志(依赖配置文件已加载)
|
||||||
@@ -43,10 +43,10 @@ func Init() {
|
|||||||
// 日志轮转配置(lumberjack)
|
// 日志轮转配置(lumberjack)
|
||||||
hook := lumberjack.Logger{
|
hook := lumberjack.Logger{
|
||||||
Filename: viper.GetString("logger.path") + "logs/app.log", // 日志文件路径
|
Filename: viper.GetString("logger.path") + "logs/app.log", // 日志文件路径
|
||||||
MaxSize: viper.GetInt("logger.max_size"), // 单个文件最大大小(MB)
|
MaxSize: viper.GetInt("logger.max_size"), // 单个文件最大大小(MB)
|
||||||
MaxBackups: viper.GetInt("logger.max_backup"), // 最大备份数
|
MaxBackups: viper.GetInt("logger.max_backup"), // 最大备份数
|
||||||
MaxAge: viper.GetInt("logger.max_age"), // 最大保留天数
|
MaxAge: viper.GetInt("logger.max_age"), // 最大保留天数
|
||||||
Compress: true, // 是否压缩
|
Compress: true, // 是否压缩
|
||||||
}
|
}
|
||||||
|
|
||||||
// 编码器配置
|
// 编码器配置
|
||||||
@@ -83,4 +83,4 @@ func customTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
|
|||||||
beijingTime := t.In(shanghaiLoc)
|
beijingTime := t.In(shanghaiLoc)
|
||||||
// 格式化输出
|
// 格式化输出
|
||||||
enc.AppendString(beijingTime.Format("2006-01-02 15:04:05.000"))
|
enc.AppendString(beijingTime.Format("2006-01-02 15:04:05.000"))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -229,4 +229,4 @@ func UpdateHandler(c *gin.Context) {
|
|||||||
Success: true,
|
Success: true,
|
||||||
Message: "更新成功",
|
Message: "更新成功",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ import (
|
|||||||
|
|
||||||
// CreateRequest 创建品种请求参数结构
|
// CreateRequest 创建品种请求参数结构
|
||||||
type CreateRequest struct {
|
type CreateRequest struct {
|
||||||
Name string `json:"name" binding:"required"` // 品种名称,必填
|
Name string `json:"name" binding:"required"` // 品种名称,必填
|
||||||
Code string `json:"code" binding:"required"` // 品种代码,必填
|
Code string `json:"code" binding:"required"` // 品种代码,必填
|
||||||
Tick float64 `json:"tick" binding:"required"` // 品种tick,必填
|
Tick float64 `json:"tick" binding:"required"` // 品种tick,必填
|
||||||
TickPrice float64 `json:"tick_price" binding:"required"` // 品种tick价格,必填
|
TickPrice float64 `json:"tick_price" binding:"required"` // 品种tick价格,必填
|
||||||
ExchangeID string `json:"exchange_id" binding:"required"` // 交易所ID,必填
|
ExchangeID string `json:"exchange_id" binding:"required"` // 交易所ID,必填
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateResponse 创建品种响应结构
|
// CreateResponse 创建品种响应结构
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
package logic4variety
|
package logic4variety
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ import (
|
|||||||
|
|
||||||
// ReadRequest 读取请求参数结构
|
// ReadRequest 读取请求参数结构
|
||||||
type ReadRequest struct {
|
type ReadRequest struct {
|
||||||
VarietyID string `form:"variety_id"` // 品种ID,可选
|
VarietyID string `form:"variety_id"` // 品种ID,可选
|
||||||
Name string `form:"name"` // 品种名称,可选
|
Name string `form:"name"` // 品种名称,可选
|
||||||
Code string `form:"code"` // 品种代码,可选
|
Code string `form:"code"` // 品种代码,可选
|
||||||
ExchangeName string `form:"exchange_name"` // 交易所名称,可选
|
ExchangeName string `form:"exchange_name"` // 交易所名称,可选
|
||||||
Page string `form:"page"` // 页码,可选
|
Page string `form:"page"` // 页码,可选
|
||||||
PageSize string `form:"page_size"` // 每页条数,可选
|
PageSize string `form:"page_size"` // 每页条数,可选
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadData 读取响应数据结构
|
// ReadData 读取响应数据结构
|
||||||
@@ -34,13 +34,13 @@ type ReadData struct {
|
|||||||
|
|
||||||
// VarietyInfoViewItem 视图数据项结构
|
// VarietyInfoViewItem 视图数据项结构
|
||||||
type VarietyInfoViewItem struct {
|
type VarietyInfoViewItem struct {
|
||||||
VarietyID string `json:"variety_id"` // 品种ID
|
VarietyID string `json:"variety_id"` // 品种ID
|
||||||
Name string `json:"name"` // 品种名称
|
Name string `json:"name"` // 品种名称
|
||||||
Code string `json:"code"` // 品种代码
|
Code string `json:"code"` // 品种代码
|
||||||
ExchangeName string `json:"exchange_name"` // 交易所名称
|
ExchangeName string `json:"exchange_name"` // 交易所名称
|
||||||
Tick string `json:"tick"` // 最小变动价位
|
Tick string `json:"tick"` // 最小变动价位
|
||||||
TickPrice string `json:"tick_price"` // 最小变动价位对应的价值
|
TickPrice string `json:"tick_price"` // 最小变动价位对应的价值
|
||||||
TickOriginal float64 `json:"tick_original"` // 最小变动价位(原始值)
|
TickOriginal float64 `json:"tick_original"` // 最小变动价位(原始值)
|
||||||
TickPriceOriginal float64 `json:"tick_price_original"` // 最小变动价位对应的价值(原始值)
|
TickPriceOriginal float64 `json:"tick_price_original"` // 最小变动价位对应的价值(原始值)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ import (
|
|||||||
|
|
||||||
// UpdateRequest 更新请求参数结构
|
// UpdateRequest 更新请求参数结构
|
||||||
type UpdateRequest struct {
|
type UpdateRequest struct {
|
||||||
VarietyID string `json:"variety_id" binding:"required"` // 品种ID,必填
|
VarietyID string `json:"variety_id" binding:"required"` // 品种ID,必填
|
||||||
ExchangeID string `json:"exchange_id"` // 交易所ID,可选
|
ExchangeID string `json:"exchange_id"` // 交易所ID,可选
|
||||||
ExchangeName string `json:"exchange_name"` // 交易所名称,可选
|
ExchangeName string `json:"exchange_name"` // 交易所名称,可选
|
||||||
Name string `json:"name"` // 品种名称,可选
|
Name string `json:"name"` // 品种名称,可选
|
||||||
Code string `json:"code"` // 品种代码,可选
|
Code string `json:"code"` // 品种代码,可选
|
||||||
Tick float64 `json:"tick"` // 最小变动价位,可选
|
Tick float64 `json:"tick"` // 最小变动价位,可选
|
||||||
TickPrice float64 `json:"tick_price"` // 最小变动价值,可选
|
TickPrice float64 `json:"tick_price"` // 最小变动价值,可选
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateResponse 更新响应结构
|
// UpdateResponse 更新响应结构
|
||||||
@@ -143,7 +143,7 @@ func UpdateHandler(c *gin.Context) {
|
|||||||
// 插入新记录
|
// 插入新记录
|
||||||
_, err = tx.Exec("INSERT INTO variety_exchange (variety_id, exchange_id, exchange_name) VALUES ($1, $2, $3)", req.VarietyID, req.ExchangeID, req.ExchangeName)
|
_, err = tx.Exec("INSERT INTO variety_exchange (variety_id, exchange_id, exchange_name) VALUES ($1, $2, $3)", req.VarietyID, req.ExchangeID, req.ExchangeName)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
zap.L().Error("❌ variety_exchange表更新失败",
|
zap.L().Error("❌ variety_exchange表更新失败",
|
||||||
@@ -187,7 +187,7 @@ func UpdateHandler(c *gin.Context) {
|
|||||||
} else {
|
} else {
|
||||||
_, err = tx.Exec("INSERT INTO variety_name (variety_id, name) VALUES ($1, $2)", req.VarietyID, req.Name)
|
_, err = tx.Exec("INSERT INTO variety_name (variety_id, name) VALUES ($1, $2)", req.VarietyID, req.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
zap.L().Error("❌ variety_name表更新失败",
|
zap.L().Error("❌ variety_name表更新失败",
|
||||||
@@ -231,7 +231,7 @@ func UpdateHandler(c *gin.Context) {
|
|||||||
} else {
|
} else {
|
||||||
_, err = tx.Exec("INSERT INTO variety_code (variety_id, code) VALUES ($1, $2)", req.VarietyID, req.Code)
|
_, err = tx.Exec("INSERT INTO variety_code (variety_id, code) VALUES ($1, $2)", req.VarietyID, req.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
zap.L().Error("❌ variety_code表更新失败",
|
zap.L().Error("❌ variety_code表更新失败",
|
||||||
@@ -275,7 +275,7 @@ func UpdateHandler(c *gin.Context) {
|
|||||||
} else {
|
} else {
|
||||||
_, err = tx.Exec("INSERT INTO variety_tick (variety_id, tick) VALUES ($1, $2)", req.VarietyID, req.Tick)
|
_, err = tx.Exec("INSERT INTO variety_tick (variety_id, tick) VALUES ($1, $2)", req.VarietyID, req.Tick)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
zap.L().Error("❌ variety_tick表更新失败",
|
zap.L().Error("❌ variety_tick表更新失败",
|
||||||
@@ -319,7 +319,7 @@ func UpdateHandler(c *gin.Context) {
|
|||||||
} else {
|
} else {
|
||||||
_, err = tx.Exec("INSERT INTO variety_tick_price (variety_id, price) VALUES ($1, $2)", req.VarietyID, req.TickPrice)
|
_, err = tx.Exec("INSERT INTO variety_tick_price (variety_id, price) VALUES ($1, $2)", req.VarietyID, req.TickPrice)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
zap.L().Error("❌ variety_tick_price表更新失败",
|
zap.L().Error("❌ variety_tick_price表更新失败",
|
||||||
|
|||||||
Reference in New Issue
Block a user