This commit is contained in:
vipg
2025-11-17 17:50:03 +08:00
parent 2f461a3a95
commit a47e544657
3 changed files with 12 additions and 12 deletions

View File

@@ -129,10 +129,10 @@ func CreateHandler(c *gin.Context) {
)
// 2. 插入国家名称到name表与country_id关联
_, err = tx.Exec("INSERT INTO name (country_id, name) VALUES ($1, $2)", countryID, req.Name)
_, err = tx.Exec("INSERT INTO country_name (country_id, name) VALUES ($1, $2)", countryID, req.Name)
if err != nil {
tx.Rollback() // 操作失败,回滚事务
zap.L().Error("❌ name表插入失败",
zap.L().Error("❌ country_name表插入失败",
zap.String("req_id", reqID),
zap.String("country_id", countryID),
zap.Error(err),
@@ -145,10 +145,10 @@ func CreateHandler(c *gin.Context) {
}
// 3. 插入国家代码到code表与country_id关联
_, err = tx.Exec("INSERT INTO code (country_id, code) VALUES ($1, $2)", countryID, req.Code)
_, err = tx.Exec("INSERT INTO country_code (country_id, code) VALUES ($1, $2)", countryID, req.Code)
if err != nil {
tx.Rollback() // 操作失败,回滚事务
zap.L().Error("❌ code表插入失败",
zap.L().Error("❌ country_code表插入失败",
zap.String("req_id", reqID),
zap.String("country_id", countryID),
zap.Error(err),

View File

@@ -106,10 +106,10 @@ func DeleteHandler(c *gin.Context) {
}
// 3.2 更新name表
_, err = tx.Exec("UPDATE name SET deleted = TRUE WHERE country_id = $1", req.CountryID)
_, err = tx.Exec("UPDATE country_name SET deleted = TRUE WHERE country_id = $1", req.CountryID)
if err != nil {
tx.Rollback()
zap.L().Error("❌ name表更新失败",
zap.L().Error("❌ country_name表更新失败",
zap.String("req_id", reqID),
zap.String("country_id", req.CountryID),
zap.Error(err),
@@ -122,10 +122,10 @@ func DeleteHandler(c *gin.Context) {
}
// 3.3 更新code表
_, err = tx.Exec("UPDATE code SET deleted = TRUE WHERE country_id = $1", req.CountryID)
_, err = tx.Exec("UPDATE country_code SET deleted = TRUE WHERE country_id = $1", req.CountryID)
if err != nil {
tx.Rollback()
zap.L().Error("❌ code表更新失败",
zap.L().Error("❌ country_code表更新失败",
zap.String("req_id", reqID),
zap.String("country_id", req.CountryID),
zap.Error(err),

View File

@@ -111,10 +111,10 @@ func UpdateHandler(c *gin.Context) {
// 如果name不为空更新name表
if req.Name != "" {
_, err = tx.Exec("UPDATE name SET name = $1 WHERE country_id = $2", req.Name, req.CountryID)
_, err = tx.Exec("UPDATE country_name SET name = $1 WHERE country_id = $2", req.Name, req.CountryID)
if err != nil {
tx.Rollback()
zap.L().Error("❌ name表更新失败",
zap.L().Error("❌ country_name表更新失败",
zap.String("req_id", reqID),
zap.String("country_id", req.CountryID),
zap.Error(err),
@@ -133,10 +133,10 @@ func UpdateHandler(c *gin.Context) {
// 如果code不为空更新code表
if req.Code != "" {
_, err = tx.Exec("UPDATE code SET code = $1 WHERE country_id = $2", req.Code, req.CountryID)
_, err = tx.Exec("UPDATE country_code SET code = $1 WHERE country_id = $2", req.Code, req.CountryID)
if err != nil {
tx.Rollback()
zap.L().Error("❌ code表更新失败",
zap.L().Error("❌ country_code表更新失败",
zap.String("req_id", reqID),
zap.String("country_id", req.CountryID),
zap.Error(err),