add
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
// DeleteRequest 删除请求参数结构
|
||||
type DeleteRequest struct {
|
||||
CountryID string `json:"currency_id" binding:"required"` // 货币ID,必填
|
||||
CurrencyID string `json:"currency_id" binding:"required"` // 货币ID,必填
|
||||
}
|
||||
|
||||
// DeleteResponse 删除响应结构
|
||||
@@ -52,7 +52,7 @@ func DeleteHandler(c *gin.Context) {
|
||||
|
||||
zap.L().Debug("✅ 请求参数验证通过",
|
||||
zap.String("req_id", reqID),
|
||||
zap.String("currency_id", req.CountryID),
|
||||
zap.String("currency_id", req.CurrencyID),
|
||||
)
|
||||
|
||||
// 开启数据库事务
|
||||
@@ -90,12 +90,12 @@ func DeleteHandler(c *gin.Context) {
|
||||
}()
|
||||
|
||||
// 3.1 更新currency表
|
||||
_, err = tx.Exec("UPDATE currency SET deleted = TRUE WHERE id = $1", req.CountryID)
|
||||
_, err = tx.Exec("UPDATE currency SET deleted = TRUE WHERE id = $1", req.CurrencyID)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
zap.L().Error("❌ currency表更新失败",
|
||||
zap.String("req_id", reqID),
|
||||
zap.String("currency_id", req.CountryID),
|
||||
zap.String("currency_id", req.CurrencyID),
|
||||
zap.Error(err),
|
||||
)
|
||||
c.JSON(http.StatusInternalServerError, DeleteResponse{
|
||||
@@ -106,12 +106,12 @@ func DeleteHandler(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 3.2 更新name表
|
||||
_, err = tx.Exec("UPDATE currency_name SET deleted = TRUE WHERE currency_id = $1", req.CountryID)
|
||||
_, err = tx.Exec("UPDATE currency_name SET deleted = TRUE WHERE currency_id = $1", req.CurrencyID)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
zap.L().Error("❌ currency_name表更新失败",
|
||||
zap.String("req_id", reqID),
|
||||
zap.String("currency_id", req.CountryID),
|
||||
zap.String("currency_id", req.CurrencyID),
|
||||
zap.Error(err),
|
||||
)
|
||||
c.JSON(http.StatusInternalServerError, DeleteResponse{
|
||||
@@ -122,12 +122,12 @@ func DeleteHandler(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 3.3 更新code表
|
||||
_, err = tx.Exec("UPDATE currency_code SET deleted = TRUE WHERE currency_id = $1", req.CountryID)
|
||||
_, err = tx.Exec("UPDATE currency_code SET deleted = TRUE WHERE currency_id = $1", req.CurrencyID)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
zap.L().Error("❌ currency_code表更新失败",
|
||||
zap.String("req_id", reqID),
|
||||
zap.String("currency_id", req.CountryID),
|
||||
zap.String("currency_id", req.CurrencyID),
|
||||
zap.Error(err),
|
||||
)
|
||||
c.JSON(http.StatusInternalServerError, DeleteResponse{
|
||||
@@ -142,7 +142,7 @@ func DeleteHandler(c *gin.Context) {
|
||||
tx.Rollback()
|
||||
zap.L().Error("❌ 事务提交失败",
|
||||
zap.String("req_id", reqID),
|
||||
zap.String("currency_id", req.CountryID),
|
||||
zap.String("currency_id", req.CurrencyID),
|
||||
zap.Error(err),
|
||||
)
|
||||
c.JSON(http.StatusInternalServerError, DeleteResponse{
|
||||
@@ -156,7 +156,7 @@ func DeleteHandler(c *gin.Context) {
|
||||
duration := time.Since(startTime)
|
||||
zap.L().Info("✅ 货币删除请求处理完成",
|
||||
zap.String("req_id", reqID),
|
||||
zap.String("currency_id", req.CountryID),
|
||||
zap.String("currency_id", req.CurrencyID),
|
||||
zap.Duration("duration", duration),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user