add
This commit is contained in:
@@ -1,12 +1,13 @@
|
|||||||
package logic4company
|
package logic4country
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"asset_assistant/db" // 数据库操作相关包
|
||||||
"net/http"
|
"net/http"
|
||||||
"country/db" // 数据库操作相关包
|
"time" // 时间处理包
|
||||||
"time" // 时间处理包
|
|
||||||
"github.com/google/uuid" // UUID生成工具
|
|
||||||
"github.com/gin-gonic/gin" // Gin框架,用于处理HTTP请求
|
"github.com/gin-gonic/gin" // Gin框架,用于处理HTTP请求
|
||||||
"go.uber.org/zap" // 日志库
|
"github.com/google/uuid" // UUID生成工具
|
||||||
|
"go.uber.org/zap" // 日志库
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreateRequest 注册请求参数结构
|
// CreateRequest 注册请求参数结构
|
||||||
@@ -19,9 +20,9 @@ type CreateRequest struct {
|
|||||||
// CreateResponse 注册响应结构
|
// CreateResponse 注册响应结构
|
||||||
// 统一的API响应格式,包含成功状态、提示信息和数据
|
// 统一的API响应格式,包含成功状态、提示信息和数据
|
||||||
type CreateResponse struct {
|
type CreateResponse struct {
|
||||||
Success bool `json:"success"` // 操作是否成功
|
Success bool `json:"success"` // 操作是否成功
|
||||||
Message string `json:"message"` // 提示信息
|
Message string `json:"message"` // 提示信息
|
||||||
Data CreateData `json:"data"` // 响应数据
|
Data CreateData `json:"data"` // 响应数据
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateData 响应数据结构
|
// CreateData 响应数据结构
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
package logic4company
|
package logic4country
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"asset_assistant/db"
|
||||||
"net/http"
|
"net/http"
|
||||||
"country/db"
|
|
||||||
"time"
|
"time"
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/google/uuid"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
package logic4company
|
package logic4country
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"country/db"
|
"asset_assistant/db"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
@@ -15,33 +16,33 @@ import (
|
|||||||
|
|
||||||
// ReadRequest 读取请求参数结构
|
// ReadRequest 读取请求参数结构
|
||||||
type ReadRequest struct {
|
type ReadRequest struct {
|
||||||
CountryID string `form:"country_id"` // 国家ID,可选
|
CountryID string `form:"country_id"` // 国家ID,可选
|
||||||
Name string `form:"name"` // 国家名称,可选
|
Name string `form:"name"` // 国家名称,可选
|
||||||
Code string `form:"code"` // 国家代码,可选
|
Code string `form:"code"` // 国家代码,可选
|
||||||
Page string `form:"page"` // 页码,可选
|
Page string `form:"page"` // 页码,可选
|
||||||
PageSize string `form:"page_size"` // 每页条数,可选
|
PageSize string `form:"page_size"` // 每页条数,可选
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadData 读取响应数据结构
|
// ReadData 读取响应数据结构
|
||||||
type ReadData struct {
|
type ReadData struct {
|
||||||
Total int64 `json:"total"` // 总条数
|
Total int64 `json:"total"` // 总条数
|
||||||
Page int `json:"page"` // 当前页码
|
Page int `json:"page"` // 当前页码
|
||||||
PageSize int `json:"page_size"`// 每页条数
|
PageSize int `json:"page_size"` // 每页条数
|
||||||
Items []CountryInfoViewItem `json:"items"` // 数据列表
|
Items []CountryInfoViewItem `json:"items"` // 数据列表
|
||||||
}
|
}
|
||||||
|
|
||||||
// CountryInfoViewItem 视图数据项结构
|
// CountryInfoViewItem 视图数据项结构
|
||||||
type CountryInfoViewItem struct {
|
type CountryInfoViewItem struct {
|
||||||
CountryID string `json:"country_id"` // 国家ID
|
CountryID string `json:"country_id"` // 国家ID
|
||||||
Name string `json:"name"` // 国家名称
|
Name string `json:"name"` // 国家名称
|
||||||
Code string `json:"code"` // 国家代码
|
Code string `json:"code"` // 国家代码
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadResponse 读取响应结构
|
// ReadResponse 读取响应结构
|
||||||
type ReadResponse struct {
|
type ReadResponse struct {
|
||||||
Success bool `json:"success"` // 操作是否成功
|
Success bool `json:"success"` // 操作是否成功
|
||||||
Message string `json:"message"` // 提示信息
|
Message string `json:"message"` // 提示信息
|
||||||
Data ReadData `json:"data"` // 响应数据
|
Data ReadData `json:"data"` // 响应数据
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadHandler 处理国家信息查询逻辑
|
// ReadHandler 处理国家信息查询逻辑
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package logic4company
|
package logic4country
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"country/db"
|
"asset_assistant/db"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"asset_assistant/db" // 数据库相关操作包
|
"asset_assistant/db" // 数据库相关操作包
|
||||||
"asset_assistant/logger" // 日志工具包
|
"asset_assistant/logger" // 日志工具包
|
||||||
|
"asset_assistant/logic4country"
|
||||||
"asset_assistant/logic4user"
|
"asset_assistant/logic4user"
|
||||||
|
|
||||||
// 业务逻辑处理包
|
// 业务逻辑处理包
|
||||||
@@ -60,6 +61,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
zap.L().Info("✅ 用户接口注册完成")
|
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端口
|
// 记录服务启动日志,监听80端口
|
||||||
zap.L().Info("✅ 服务启动在80端口")
|
zap.L().Info("✅ 服务启动在80端口")
|
||||||
r.Run(":80")
|
r.Run(":80")
|
||||||
|
|||||||
Reference in New Issue
Block a user