This commit is contained in:
vipg
2025-11-17 15:43:35 +08:00
parent 0e8afddcb7
commit 3a7d40ae7b
5 changed files with 50 additions and 36 deletions

View File

@@ -1,12 +1,13 @@
package logic4company
package logic4country
import (
"asset_assistant/db" // 数据库操作相关包
"net/http"
"country/db" // 数据库操作相关
"time" // 时间处理包
"github.com/google/uuid" // UUID生成工具
"time" // 时间处理
"github.com/gin-gonic/gin" // Gin框架用于处理HTTP请求
"go.uber.org/zap" // 日志库
"github.com/google/uuid" // UUID生成工具
"go.uber.org/zap" // 日志库
)
// CreateRequest 注册请求参数结构
@@ -19,9 +20,9 @@ type CreateRequest struct {
// CreateResponse 注册响应结构
// 统一的API响应格式包含成功状态、提示信息和数据
type CreateResponse struct {
Success bool `json:"success"` // 操作是否成功
Message string `json:"message"` // 提示信息
Data CreateData `json:"data"` // 响应数据
Success bool `json:"success"` // 操作是否成功
Message string `json:"message"` // 提示信息
Data CreateData `json:"data"` // 响应数据
}
// CreateData 响应数据结构
@@ -40,7 +41,7 @@ func CreateHandler(c *gin.Context) {
reqID = uuid.New().String()
zap.L().Debug("✨ 生成新的请求ID", zap.String("req_id", reqID))
}
// 记录请求接收日志,包含关键追踪信息
zap.L().Info("📥 收到国家创建请求",
zap.String("req_id", reqID),
@@ -190,4 +191,4 @@ func CreateHandler(c *gin.Context) {
CountryID: countryID,
},
})
}
}

View File

@@ -1,11 +1,12 @@
package logic4company
package logic4country
import (
"asset_assistant/db"
"net/http"
"country/db"
"time"
"github.com/google/uuid"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"go.uber.org/zap"
)
@@ -164,4 +165,4 @@ func DeleteHandler(c *gin.Context) {
Success: true,
Message: "删除成功",
})
}
}

View File

@@ -1,13 +1,14 @@
package logic4company
package logic4country
import (
"country/db"
"asset_assistant/db"
"net/http"
"strconv"
"time"
"strings"
"time"
"fmt"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"go.uber.org/zap"
@@ -15,33 +16,33 @@ import (
// ReadRequest 读取请求参数结构
type ReadRequest struct {
CountryID string `form:"country_id"` // 国家ID可选
Name string `form:"name"` // 国家名称,可选
Code string `form:"code"` // 国家代码,可选
Page string `form:"page"` // 页码,可选
PageSize string `form:"page_size"` // 每页条数,可选
CountryID string `form:"country_id"` // 国家ID可选
Name string `form:"name"` // 国家名称,可选
Code string `form:"code"` // 国家代码,可选
Page string `form:"page"` // 页码,可选
PageSize string `form:"page_size"` // 每页条数,可选
}
// ReadData 读取响应数据结构
type ReadData struct {
Total int64 `json:"total"` // 总条数
Page int `json:"page"` // 当前页码
PageSize int `json:"page_size"`// 每页条数
Items []CountryInfoViewItem `json:"items"` // 数据列表
Total int64 `json:"total"` // 总条数
Page int `json:"page"` // 当前页码
PageSize int `json:"page_size"` // 每页条数
Items []CountryInfoViewItem `json:"items"` // 数据列表
}
// CountryInfoViewItem 视图数据项结构
type CountryInfoViewItem struct {
CountryID string `json:"country_id"` // 国家ID
Name string `json:"name"` // 国家名称
Code string `json:"code"` // 国家代码
CountryID string `json:"country_id"` // 国家ID
Name string `json:"name"` // 国家名称
Code string `json:"code"` // 国家代码
}
// ReadResponse 读取响应结构
type ReadResponse struct {
Success bool `json:"success"` // 操作是否成功
Message string `json:"message"` // 提示信息
Data ReadData `json:"data"` // 响应数据
Success bool `json:"success"` // 操作是否成功
Message string `json:"message"` // 提示信息
Data ReadData `json:"data"` // 响应数据
}
// ReadHandler 处理国家信息查询逻辑
@@ -227,4 +228,4 @@ func ReadHandler(c *gin.Context) {
Items: items,
},
})
}
}

View File

@@ -1,7 +1,7 @@
package logic4company
package logic4country
import (
"country/db"
"asset_assistant/db"
"net/http"
"time"
@@ -181,4 +181,4 @@ func UpdateHandler(c *gin.Context) {
Success: true,
Message: "更新成功",
})
}
}

View File

@@ -3,6 +3,7 @@ package main
import (
"asset_assistant/db" // 数据库相关操作包
"asset_assistant/logger" // 日志工具包
"asset_assistant/logic4country"
"asset_assistant/logic4user"
// 业务逻辑处理包
@@ -60,6 +61,16 @@ func main() {
}
zap.L().Info("✅ 用户接口注册完成")
// 注册国家接口
country := r.Group("/country")
{
country.POST("/create", logic4country.CreateHandler)
country.POST("/read", logic4country.ReadHandler)
country.POST("/update", logic4country.UpdateHandler)
country.POST("/delete", logic4country.DeleteHandler)
}
zap.L().Info("✅ 国家接口注册完成")
// 记录服务启动日志监听80端口
zap.L().Info("✅ 服务启动在80端口")
r.Run(":80")