This commit is contained in:
2026-04-21 22:36:48 +08:00
commit 488c695fdf
748 changed files with 266838 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
package routes
import (
"hyapi-server/internal/infrastructure/http/handlers"
sharedhttp "hyapi-server/internal/shared/http"
"hyapi-server/internal/shared/middleware"
"go.uber.org/zap"
)
// AdminSecurityRoutes 管理端安全路由
type AdminSecurityRoutes struct {
handler *handlers.AdminSecurityHandler
admin *middleware.AdminAuthMiddleware
logger *zap.Logger
}
func NewAdminSecurityRoutes(
handler *handlers.AdminSecurityHandler,
admin *middleware.AdminAuthMiddleware,
logger *zap.Logger,
) *AdminSecurityRoutes {
return &AdminSecurityRoutes{
handler: handler,
admin: admin,
logger: logger,
}
}
func (r *AdminSecurityRoutes) Register(router *sharedhttp.GinRouter) {
engine := router.GetEngine()
group := engine.Group("/api/v1/admin/security")
group.Use(r.admin.Handle())
{
group.GET("/suspicious-ip/list", r.handler.ListSuspiciousIPs)
group.GET("/suspicious-ip/geo-stream", r.handler.GetSuspiciousIPGeoStream)
}
r.logger.Info("管理员安全路由注册完成")
}

View File

@@ -0,0 +1,73 @@
package routes
import (
"hyapi-server/internal/infrastructure/http/handlers"
sharedhttp "hyapi-server/internal/shared/http"
"hyapi-server/internal/shared/middleware"
"go.uber.org/zap"
)
// AnnouncementRoutes 公告路由
type AnnouncementRoutes struct {
handler *handlers.AnnouncementHandler
auth *middleware.JWTAuthMiddleware
admin *middleware.AdminAuthMiddleware
logger *zap.Logger
}
// NewAnnouncementRoutes 创建公告路由
func NewAnnouncementRoutes(
handler *handlers.AnnouncementHandler,
auth *middleware.JWTAuthMiddleware,
admin *middleware.AdminAuthMiddleware,
logger *zap.Logger,
) *AnnouncementRoutes {
return &AnnouncementRoutes{
handler: handler,
auth: auth,
admin: admin,
logger: logger,
}
}
// Register 注册路由
func (r *AnnouncementRoutes) Register(router *sharedhttp.GinRouter) {
engine := router.GetEngine()
// ==================== 用户端路由 ====================
// 公告相关路由 - 用户端(只显示已发布的公告)
announcementGroup := engine.Group("/api/v1/announcements")
{
// 公开路由 - 不需要认证
announcementGroup.GET("/:id", r.handler.GetAnnouncementByID) // 获取公告详情
announcementGroup.GET("", r.handler.ListAnnouncements) // 获取公告列表
}
// ==================== 管理员端路由 ====================
// 管理员公告管理路由
adminAnnouncementGroup := engine.Group("/api/v1/admin/announcements")
adminAnnouncementGroup.Use(r.admin.Handle())
{
// 统计信息
adminAnnouncementGroup.GET("/stats", r.handler.GetAnnouncementStats) // 获取公告统计
// 公告列表查询
adminAnnouncementGroup.GET("", r.handler.ListAnnouncements) // 获取公告列表(管理员端,包含所有状态)
// 公告管理
adminAnnouncementGroup.POST("", r.handler.CreateAnnouncement) // 创建公告
adminAnnouncementGroup.PUT("/:id", r.handler.UpdateAnnouncement) // 更新公告
adminAnnouncementGroup.DELETE("/:id", r.handler.DeleteAnnouncement) // 删除公告
// 公告状态管理
adminAnnouncementGroup.POST("/:id/publish", r.handler.PublishAnnouncement) // 发布公告
adminAnnouncementGroup.POST("/:id/withdraw", r.handler.WithdrawAnnouncement) // 撤回公告
adminAnnouncementGroup.POST("/:id/archive", r.handler.ArchiveAnnouncement) // 归档公告
adminAnnouncementGroup.POST("/:id/schedule-publish", r.handler.SchedulePublishAnnouncement) // 定时发布公告
adminAnnouncementGroup.POST("/:id/update-schedule-publish", r.handler.UpdateSchedulePublishAnnouncement) // 修改定时发布时间
adminAnnouncementGroup.POST("/:id/cancel-schedule", r.handler.CancelSchedulePublishAnnouncement) // 取消定时发布
}
r.logger.Info("公告路由注册完成")
}

View File

@@ -0,0 +1,74 @@
package routes
import (
"hyapi-server/internal/infrastructure/http/handlers"
sharedhttp "hyapi-server/internal/shared/http"
"hyapi-server/internal/shared/middleware"
"go.uber.org/zap"
)
// ApiRoutes API路由注册器
type ApiRoutes struct {
apiHandler *handlers.ApiHandler
authMiddleware *middleware.JWTAuthMiddleware
domainAuthMiddleware *middleware.DomainAuthMiddleware
logger *zap.Logger
}
// NewApiRoutes 创建API路由注册器
func NewApiRoutes(
apiHandler *handlers.ApiHandler,
authMiddleware *middleware.JWTAuthMiddleware,
domainAuthMiddleware *middleware.DomainAuthMiddleware,
logger *zap.Logger,
) *ApiRoutes {
return &ApiRoutes{
apiHandler: apiHandler,
authMiddleware: authMiddleware,
domainAuthMiddleware: domainAuthMiddleware,
logger: logger,
}
}
// Register 注册相关路由
func (r *ApiRoutes) Register(router *sharedhttp.GinRouter) {
// API路由组需要用户认证
engine := router.GetEngine()
apiGroup := engine.Group("/api/v1")
{
// API调用接口 - 不受频率限制(业务核心接口)
apiGroup.POST("/:api_name", r.domainAuthMiddleware.Handle(""), r.apiHandler.HandleApiCall)
// Console专用接口 - 使用JWT认证不需要域名认证
apiGroup.POST("/console/:api_name", r.authMiddleware.Handle(), r.apiHandler.HandleApiCall)
// 表单配置接口(用于前端动态生成表单)
apiGroup.GET("/form-config/:api_code", r.authMiddleware.Handle(), r.apiHandler.GetFormConfig)
// 加密接口(用于前端调试)
apiGroup.POST("/encrypt", r.authMiddleware.Handle(), r.apiHandler.EncryptParams)
// 解密接口(用于前端调试)
apiGroup.POST("/decrypt", r.authMiddleware.Handle(), r.apiHandler.DecryptParams)
// API密钥管理接口
apiGroup.GET("/api-keys", r.authMiddleware.Handle(), r.apiHandler.GetUserApiKeys)
// 白名单管理接口
apiGroup.GET("/white-list", r.authMiddleware.Handle(), r.apiHandler.GetUserWhiteList)
apiGroup.POST("/white-list", r.authMiddleware.Handle(), r.apiHandler.AddWhiteListIP)
apiGroup.DELETE("/white-list/:ip", r.authMiddleware.Handle(), r.apiHandler.DeleteWhiteListIP)
// API调用记录接口
apiGroup.GET("/my/api-calls", r.authMiddleware.Handle(), r.apiHandler.GetUserApiCalls)
// 余额预警设置接口
apiGroup.GET("/user/balance-alert/settings", r.authMiddleware.Handle(), r.apiHandler.GetUserBalanceAlertSettings)
apiGroup.PUT("/user/balance-alert/settings", r.authMiddleware.Handle(), r.apiHandler.UpdateUserBalanceAlertSettings)
apiGroup.POST("/user/balance-alert/test-sms", r.authMiddleware.Handle(), r.apiHandler.TestBalanceAlertSms)
}
r.logger.Info("API路由注册完成")
}

View File

@@ -0,0 +1,109 @@
package routes
import (
"hyapi-server/internal/infrastructure/http/handlers"
sharedhttp "hyapi-server/internal/shared/http"
"hyapi-server/internal/shared/middleware"
"go.uber.org/zap"
)
// ArticleRoutes 文章路由
type ArticleRoutes struct {
handler *handlers.ArticleHandler
auth *middleware.JWTAuthMiddleware
admin *middleware.AdminAuthMiddleware
logger *zap.Logger
}
// NewArticleRoutes 创建文章路由
func NewArticleRoutes(
handler *handlers.ArticleHandler,
auth *middleware.JWTAuthMiddleware,
admin *middleware.AdminAuthMiddleware,
logger *zap.Logger,
) *ArticleRoutes {
return &ArticleRoutes{
handler: handler,
auth: auth,
admin: admin,
logger: logger,
}
}
// Register 注册路由
func (r *ArticleRoutes) Register(router *sharedhttp.GinRouter) {
engine := router.GetEngine()
// ==================== 用户端路由 ====================
// 文章相关路由 - 用户端
articleGroup := engine.Group("/api/v1/articles")
{
// 公开路由 - 不需要认证
articleGroup.GET("/:id", r.handler.GetArticleByID) // 获取文章详情
articleGroup.GET("", r.handler.ListArticles) // 获取文章列表(支持筛选:标题、分类、摘要、标签、推荐状态)
}
// 分类相关路由 - 用户端
categoryGroup := engine.Group("/api/v1/article-categories")
{
// 公开路由 - 不需要认证
categoryGroup.GET("", r.handler.ListCategories) // 获取分类列表
categoryGroup.GET("/:id", r.handler.GetCategoryByID) // 获取分类详情
}
// 标签相关路由 - 用户端
tagGroup := engine.Group("/api/v1/article-tags")
{
// 公开路由 - 不需要认证
tagGroup.GET("", r.handler.ListTags) // 获取标签列表
tagGroup.GET("/:id", r.handler.GetTagByID) // 获取标签详情
}
// ==================== 管理员端路由 ====================
// 管理员文章管理路由
adminArticleGroup := engine.Group("/api/v1/admin/articles")
adminArticleGroup.Use(r.admin.Handle())
{
// 统计信息
adminArticleGroup.GET("/stats", r.handler.GetArticleStats) // 获取文章统计
// 文章列表查询
adminArticleGroup.GET("", r.handler.ListArticlesForAdmin) // 获取文章列表(管理员端,包含所有状态)
// 文章管理
adminArticleGroup.POST("", r.handler.CreateArticle) // 创建文章
adminArticleGroup.PUT("/:id", r.handler.UpdateArticle) // 更新文章
adminArticleGroup.DELETE("/:id", r.handler.DeleteArticle) // 删除文章
// 文章状态管理
adminArticleGroup.POST("/:id/publish", r.handler.PublishArticle) // 发布文章
adminArticleGroup.POST("/:id/schedule-publish", r.handler.SchedulePublishArticle) // 定时发布文章
adminArticleGroup.POST("/:id/update-schedule-publish", r.handler.UpdateSchedulePublishArticle) // 修改定时发布时间
adminArticleGroup.POST("/:id/cancel-schedule", r.handler.CancelSchedulePublishArticle) // 取消定时发布
adminArticleGroup.POST("/:id/archive", r.handler.ArchiveArticle) // 归档文章
adminArticleGroup.PUT("/:id/featured", r.handler.SetFeatured) // 设置推荐状态
}
// 管理员分类管理路由
adminCategoryGroup := engine.Group("/api/v1/admin/article-categories")
adminCategoryGroup.Use(r.admin.Handle())
{
// 分类管理
adminCategoryGroup.POST("", r.handler.CreateCategory) // 创建分类
adminCategoryGroup.PUT("/:id", r.handler.UpdateCategory) // 更新分类
adminCategoryGroup.DELETE("/:id", r.handler.DeleteCategory) // 删除分类
}
// 管理员标签管理路由
adminTagGroup := engine.Group("/api/v1/admin/article-tags")
adminTagGroup.Use(r.admin.Handle())
{
// 标签管理
adminTagGroup.POST("", r.handler.CreateTag) // 创建标签
adminTagGroup.PUT("/:id", r.handler.UpdateTag) // 更新标签
adminTagGroup.DELETE("/:id", r.handler.DeleteTag) // 删除标签
}
r.logger.Info("文章路由注册完成")
}

View File

@@ -0,0 +1,33 @@
package routes
import (
"hyapi-server/internal/infrastructure/http/handlers"
sharedhttp "hyapi-server/internal/shared/http"
"go.uber.org/zap"
)
// CaptchaRoutes 验证码路由
type CaptchaRoutes struct {
handler *handlers.CaptchaHandler
logger *zap.Logger
}
// NewCaptchaRoutes 创建验证码路由
func NewCaptchaRoutes(handler *handlers.CaptchaHandler, logger *zap.Logger) *CaptchaRoutes {
return &CaptchaRoutes{
handler: handler,
logger: logger,
}
}
// Register 注册验证码相关路由
func (r *CaptchaRoutes) Register(router *sharedhttp.GinRouter) {
engine := router.GetEngine()
captchaGroup := engine.Group("/api/v1/captcha")
{
captchaGroup.POST("/encryptedSceneId", r.handler.GetEncryptedSceneId)
captchaGroup.GET("/config", r.handler.GetConfig)
}
r.logger.Info("验证码路由注册完成")
}

View File

@@ -0,0 +1,129 @@
package routes
import (
"go.uber.org/zap"
"hyapi-server/internal/infrastructure/http/handlers"
"hyapi-server/internal/shared/http"
"hyapi-server/internal/shared/middleware"
)
// CertificationRoutes 认证路由
type CertificationRoutes struct {
handler *handlers.CertificationHandler
router *http.GinRouter
logger *zap.Logger
auth *middleware.JWTAuthMiddleware
admin *middleware.AdminAuthMiddleware
optional *middleware.OptionalAuthMiddleware
dailyRateLimit *middleware.DailyRateLimitMiddleware
}
// NewCertificationRoutes 创建认证路由
func NewCertificationRoutes(
handler *handlers.CertificationHandler,
router *http.GinRouter,
logger *zap.Logger,
auth *middleware.JWTAuthMiddleware,
admin *middleware.AdminAuthMiddleware,
optional *middleware.OptionalAuthMiddleware,
dailyRateLimit *middleware.DailyRateLimitMiddleware,
) *CertificationRoutes {
return &CertificationRoutes{
handler: handler,
router: router,
logger: logger,
auth: auth,
admin: admin,
optional: optional,
dailyRateLimit: dailyRateLimit,
}
}
// Register 注册认证路由
func (r *CertificationRoutes) Register(router *http.GinRouter) {
// 认证管理路由组
certificationGroup := router.GetEngine().Group("/api/v1/certifications")
{
// 需要认证的路由
authGroup := certificationGroup.Group("")
authGroup.Use(r.auth.Handle())
{
authGroup.GET("", r.handler.ListCertifications) // 查询认证列表(管理员)
// 1. 获取认证详情
authGroup.GET("/details", r.handler.GetCertification)
// 2. 提交企业信息(应用每日限流)
authGroup.POST("/enterprise-info", r.dailyRateLimit.Handle(), r.handler.SubmitEnterpriseInfo)
// OCR营业执照识别接口
authGroup.POST("/ocr/business-license", r.handler.RecognizeBusinessLicense)
// 认证图片上传(七牛云,用于企业信息中的各类图片)
authGroup.POST("/upload", r.handler.UploadCertificationFile)
// 3. 申请合同签署
authGroup.POST("/apply-contract", r.handler.ApplyContract)
// 前端确认是否完成认证
authGroup.POST("/confirm-auth", r.handler.ConfirmAuth)
// 前端确认是否完成签署
authGroup.POST("/confirm-sign", r.handler.ConfirmSign)
// 管理员代用户完成认证(暂不关联合同)
authGroup.POST("/admin/complete-without-contract", r.handler.AdminCompleteCertificationWithoutContract)
}
// 管理端企业审核(需管理员权限,以状态机状态为准)
adminGroup := certificationGroup.Group("/admin")
adminGroup.Use(r.auth.Handle())
adminGroup.Use(r.admin.Handle())
{
adminGroup.POST("/transition-status", r.handler.AdminTransitionCertificationStatus)
}
adminCertGroup := adminGroup.Group("/submit-records")
{
adminCertGroup.GET("", r.handler.AdminListSubmitRecords)
adminCertGroup.GET("/:id", r.handler.AdminGetSubmitRecordByID)
adminCertGroup.POST("/:id/approve", r.handler.AdminApproveSubmitRecord)
adminCertGroup.POST("/:id/reject", r.handler.AdminRejectSubmitRecord)
}
// 回调路由(不需要认证,但需要验证签名)
callbackGroup := certificationGroup.Group("/callbacks")
{
callbackGroup.POST("/esign", r.handler.HandleEsignCallback) // e签宝回调统一处理企业认证和合同签署回调
}
}
r.logger.Info("认证路由注册完成")
}
// GetRoutes 获取路由信息(用于调试)
func (r *CertificationRoutes) GetRoutes() []RouteInfo {
return []RouteInfo{
{Method: "POST", Path: "/api/v1/certifications", Handler: "CreateCertification", Auth: true},
{Method: "GET", Path: "/api/v1/certifications/:id", Handler: "GetCertification", Auth: true},
{Method: "GET", Path: "/api/v1/certifications/user", Handler: "GetUserCertifications", Auth: true},
{Method: "GET", Path: "/api/v1/certifications", Handler: "ListCertifications", Auth: true},
{Method: "GET", Path: "/api/v1/certifications/statistics", Handler: "GetCertificationStatistics", Auth: true},
{Method: "POST", Path: "/api/v1/certifications/:id/enterprise-info", Handler: "SubmitEnterpriseInfo", Auth: true},
{Method: "POST", Path: "/api/v1/certifications/ocr/business-license", Handler: "RecognizeBusinessLicense", Auth: true},
{Method: "POST", Path: "/api/v1/certifications/apply-contract", Handler: "ApplyContract", Auth: true},
{Method: "POST", Path: "/api/v1/certifications/retry", Handler: "RetryOperation", Auth: true},
{Method: "POST", Path: "/api/v1/certifications/force-transition", Handler: "ForceTransitionStatus", Auth: true},
{Method: "GET", Path: "/api/v1/certifications/monitoring", Handler: "GetSystemMonitoring", Auth: true},
{Method: "POST", Path: "/api/v1/certifications/callbacks/esign", Handler: "HandleEsignCallback", Auth: false},
}
}
// RouteInfo 路由信息
type RouteInfo struct {
Method string
Path string
Handler string
Auth bool
}

View File

@@ -0,0 +1,58 @@
package routes
import (
"hyapi-server/internal/infrastructure/http/handlers"
sharedhttp "hyapi-server/internal/shared/http"
"hyapi-server/internal/shared/middleware"
"go.uber.org/zap"
)
// ComponentReportOrderRoutes 组件报告订单路由
type ComponentReportOrderRoutes struct {
componentReportOrderHandler *handlers.ComponentReportOrderHandler
auth *middleware.JWTAuthMiddleware
logger *zap.Logger
}
// NewComponentReportOrderRoutes 创建组件报告订单路由
func NewComponentReportOrderRoutes(
componentReportOrderHandler *handlers.ComponentReportOrderHandler,
auth *middleware.JWTAuthMiddleware,
logger *zap.Logger,
) *ComponentReportOrderRoutes {
return &ComponentReportOrderRoutes{
componentReportOrderHandler: componentReportOrderHandler,
auth: auth,
logger: logger,
}
}
// Register 注册组件报告订单相关路由
func (r *ComponentReportOrderRoutes) Register(router *sharedhttp.GinRouter) {
engine := router.GetEngine()
// 产品组件报告相关接口 - 需要认证
componentReportGroup := engine.Group("/api/v1/products/:id/component-report", r.auth.Handle())
{
// 检查下载可用性
componentReportGroup.GET("/check", r.componentReportOrderHandler.CheckDownloadAvailability)
// 获取下载信息
componentReportGroup.GET("/info", r.componentReportOrderHandler.GetDownloadInfo)
// 创建支付订单
componentReportGroup.POST("/create-order", r.componentReportOrderHandler.CreatePaymentOrder)
}
// 组件报告订单相关接口 - 需要认证
componentReportOrder := engine.Group("/api/v1/component-report", r.auth.Handle())
{
// 检查支付状态
componentReportOrder.GET("/check-payment/:orderId", r.componentReportOrderHandler.CheckPaymentStatus)
// 下载文件
componentReportOrder.GET("/download/:orderId", r.componentReportOrderHandler.DownloadFile)
// 获取用户订单列表
componentReportOrder.GET("/orders", r.componentReportOrderHandler.GetUserOrders)
}
r.logger.Info("组件报告订单路由注册完成")
}

View File

@@ -0,0 +1,109 @@
package routes
import (
"hyapi-server/internal/infrastructure/http/handlers"
sharedhttp "hyapi-server/internal/shared/http"
"hyapi-server/internal/shared/middleware"
"go.uber.org/zap"
)
// FinanceRoutes 财务路由注册器
type FinanceRoutes struct {
financeHandler *handlers.FinanceHandler
authMiddleware *middleware.JWTAuthMiddleware
adminAuthMiddleware *middleware.AdminAuthMiddleware
logger *zap.Logger
}
// NewFinanceRoutes 创建财务路由注册器
func NewFinanceRoutes(
financeHandler *handlers.FinanceHandler,
authMiddleware *middleware.JWTAuthMiddleware,
adminAuthMiddleware *middleware.AdminAuthMiddleware,
logger *zap.Logger,
) *FinanceRoutes {
return &FinanceRoutes{
financeHandler: financeHandler,
authMiddleware: authMiddleware,
adminAuthMiddleware: adminAuthMiddleware,
logger: logger,
}
}
// Register 注册财务相关路由
func (r *FinanceRoutes) Register(router *sharedhttp.GinRouter) {
engine := router.GetEngine()
// 支付宝回调路由(不需要认证)
alipayGroup := engine.Group("/api/v1/finance/alipay")
{
alipayGroup.POST("/callback", r.financeHandler.HandleAlipayCallback) // 支付宝异步回调
alipayGroup.GET("/return", r.financeHandler.HandleAlipayReturn) // 支付宝同步回调
}
// 微信支付回调路由(不需要认证)
wechatPayGroup := engine.Group("/api/v1/pay/wechat")
{
wechatPayGroup.POST("/callback", r.financeHandler.HandleWechatPayCallback) // 微信支付异步回调
}
// 微信退款回调路由(不需要认证)
wechatRefundGroup := engine.Group("/api/v1/wechat")
{
wechatRefundGroup.POST("/refund_callback", r.financeHandler.HandleWechatRefundCallback) // 微信退款异步回调
}
// 财务路由组,需要用户认证
financeGroup := engine.Group("/api/v1/finance")
financeGroup.Use(r.authMiddleware.Handle())
{
// 钱包相关路由
walletGroup := financeGroup.Group("/wallet")
{
walletGroup.GET("", r.financeHandler.GetWallet) // 获取钱包信息
walletGroup.GET("/transactions", r.financeHandler.GetUserWalletTransactions) // 获取钱包交易记录
walletGroup.GET("/recharge-config", r.financeHandler.GetRechargeConfig) // 获取充值配置
walletGroup.POST("/alipay-recharge", r.financeHandler.CreateAlipayRecharge) // 创建支付宝充值订单
walletGroup.POST("/wechat-recharge", r.financeHandler.CreateWechatRecharge) // 创建微信充值订单
walletGroup.GET("/recharge-records", r.financeHandler.GetUserRechargeRecords) // 用户充值记录分页
walletGroup.GET("/alipay-order-status", r.financeHandler.GetAlipayOrderStatus) // 获取支付宝订单状态
walletGroup.GET("/wechat-order-status", r.financeHandler.GetWechatOrderStatus) // 获取微信订单状态
financeGroup.GET("/purchase-records", r.financeHandler.GetUserPurchaseRecords) // 用户购买记录分页
}
}
// 发票相关路由,需要用户认证
invoiceGroup := engine.Group("/api/v1/invoices")
invoiceGroup.Use(r.authMiddleware.Handle())
{
invoiceGroup.POST("/apply", r.financeHandler.ApplyInvoice) // 申请开票
invoiceGroup.GET("/info", r.financeHandler.GetUserInvoiceInfo) // 获取用户发票信息
invoiceGroup.PUT("/info", r.financeHandler.UpdateUserInvoiceInfo) // 更新用户发票信息
invoiceGroup.GET("/records", r.financeHandler.GetUserInvoiceRecords) // 获取用户开票记录
invoiceGroup.GET("/available-amount", r.financeHandler.GetAvailableAmount) // 获取可开票金额
invoiceGroup.GET("/:application_id/download", r.financeHandler.DownloadInvoiceFile) // 下载发票文件
}
// 管理员财务路由组
adminFinanceGroup := engine.Group("/api/v1/admin/finance")
adminFinanceGroup.Use(r.adminAuthMiddleware.Handle())
{
adminFinanceGroup.POST("/transfer-recharge", r.financeHandler.TransferRecharge) // 对公转账充值
adminFinanceGroup.POST("/gift-recharge", r.financeHandler.GiftRecharge) // 赠送充值
adminFinanceGroup.GET("/recharge-records", r.financeHandler.GetAdminRechargeRecords) // 管理员充值记录分页
adminFinanceGroup.GET("/purchase-records", r.financeHandler.GetAdminPurchaseRecords) // 管理员购买记录分页
}
// 管理员发票相关路由组
adminInvoiceGroup := engine.Group("/api/v1/admin/invoices")
adminInvoiceGroup.Use(r.adminAuthMiddleware.Handle())
{
adminInvoiceGroup.GET("/pending", r.financeHandler.GetPendingApplications) // 获取待处理申请列表
adminInvoiceGroup.POST("/:application_id/approve", r.financeHandler.ApproveInvoiceApplication) // 通过发票申请
adminInvoiceGroup.POST("/:application_id/reject", r.financeHandler.RejectInvoiceApplication) // 拒绝发票申请
adminInvoiceGroup.GET("/:application_id/download", r.financeHandler.AdminDownloadInvoiceFile) // 下载发票文件
}
r.logger.Info("财务路由注册完成")
}

View File

@@ -0,0 +1,38 @@
package routes
import (
"go.uber.org/zap"
sharedhttp "hyapi-server/internal/shared/http"
"hyapi-server/internal/infrastructure/http/handlers"
)
// PDFGRoutes PDFG路由
type PDFGRoutes struct {
pdfgHandler *handlers.PDFGHandler
logger *zap.Logger
}
// NewPDFGRoutes 创建PDFG路由
func NewPDFGRoutes(
pdfgHandler *handlers.PDFGHandler,
logger *zap.Logger,
) *PDFGRoutes {
return &PDFGRoutes{
pdfgHandler: pdfgHandler,
logger: logger,
}
}
// Register 注册相关路由
func (r *PDFGRoutes) Register(router *sharedhttp.GinRouter) {
engine := router.GetEngine()
apiGroup := engine.Group("/api/v1")
{
// PDF下载接口 - 不需要认证(因为下载链接已经包含了验证信息)
apiGroup.GET("/pdfg/download", r.pdfgHandler.DownloadPDF)
}
r.logger.Info("PDFG路由注册完成")
}

View File

@@ -0,0 +1,105 @@
package routes
import (
"hyapi-server/internal/infrastructure/http/handlers"
sharedhttp "hyapi-server/internal/shared/http"
"hyapi-server/internal/shared/middleware"
)
// ProductAdminRoutes 产品管理员路由
type ProductAdminRoutes struct {
handler *handlers.ProductAdminHandler
auth *middleware.JWTAuthMiddleware
admin *middleware.AdminAuthMiddleware
}
// NewProductAdminRoutes 创建产品管理员路由
func NewProductAdminRoutes(
handler *handlers.ProductAdminHandler,
auth *middleware.JWTAuthMiddleware,
admin *middleware.AdminAuthMiddleware,
) *ProductAdminRoutes {
return &ProductAdminRoutes{
handler: handler,
auth: auth,
admin: admin,
}
}
// Register 注册路由
func (r *ProductAdminRoutes) Register(router *sharedhttp.GinRouter) {
// 管理员路由组
engine := router.GetEngine()
adminGroup := engine.Group("/api/v1/admin")
adminGroup.Use(r.admin.Handle()) // 管理员权限验证
{
// 产品管理
products := adminGroup.Group("/products")
{
products.GET("", r.handler.ListProducts)
products.GET("/available", r.handler.GetAvailableProducts)
products.GET("/:id", r.handler.GetProductDetail)
products.POST("", r.handler.CreateProduct)
products.PUT("/:id", r.handler.UpdateProduct)
products.DELETE("/:id", r.handler.DeleteProduct)
// 组合包管理
products.POST("/:id/package-items", r.handler.AddPackageItem)
products.PUT("/:id/package-items/:item_id", r.handler.UpdatePackageItem)
products.DELETE("/:id/package-items/:item_id", r.handler.RemovePackageItem)
products.PUT("/:id/package-items/reorder", r.handler.ReorderPackageItems)
products.PUT("/:id/package-items/batch", r.handler.UpdatePackageItems)
// API配置管理
products.GET("/:id/api-config", r.handler.GetProductApiConfig)
products.POST("/:id/api-config", r.handler.CreateProductApiConfig)
products.PUT("/:id/api-config", r.handler.UpdateProductApiConfig)
products.DELETE("/:id/api-config", r.handler.DeleteProductApiConfig)
// 文档管理
products.GET("/:id/documentation", r.handler.GetProductDocumentation)
products.POST("/:id/documentation", r.handler.CreateOrUpdateProductDocumentation)
products.DELETE("/:id/documentation", r.handler.DeleteProductDocumentation)
}
// 分类管理
categories := adminGroup.Group("/product-categories")
{
categories.GET("", r.handler.ListCategories)
categories.GET("/:id", r.handler.GetCategoryDetail)
categories.POST("", r.handler.CreateCategory)
categories.PUT("/:id", r.handler.UpdateCategory)
categories.DELETE("/:id", r.handler.DeleteCategory)
}
// 订阅管理
subscriptions := adminGroup.Group("/subscriptions")
{
subscriptions.GET("", r.handler.ListSubscriptions)
subscriptions.GET("/stats", r.handler.GetSubscriptionStats)
subscriptions.PUT("/:id/price", r.handler.UpdateSubscriptionPrice)
subscriptions.POST("/batch-update-prices", r.handler.BatchUpdateSubscriptionPrices)
}
// 消费记录管理
walletTransactions := adminGroup.Group("/wallet-transactions")
{
walletTransactions.GET("", r.handler.GetAdminWalletTransactions)
walletTransactions.GET("/export", r.handler.ExportAdminWalletTransactions)
}
// API调用记录管理
apiCalls := adminGroup.Group("/api-calls")
{
apiCalls.GET("", r.handler.GetAdminApiCalls)
apiCalls.GET("/export", r.handler.ExportAdminApiCalls)
}
// 充值记录管理
rechargeRecords := adminGroup.Group("/recharge-records")
{
rechargeRecords.GET("", r.handler.GetAdminRechargeRecords)
rechargeRecords.GET("/export", r.handler.ExportAdminRechargeRecords)
}
}
}

View File

@@ -0,0 +1,108 @@
package routes
import (
"hyapi-server/internal/infrastructure/http/handlers"
component_report "hyapi-server/internal/shared/component_report"
sharedhttp "hyapi-server/internal/shared/http"
"hyapi-server/internal/shared/middleware"
"go.uber.org/zap"
)
// ProductRoutes 产品路由
type ProductRoutes struct {
productHandler *handlers.ProductHandler
componentReportHandler *component_report.ComponentReportHandler
auth *middleware.JWTAuthMiddleware
optionalAuth *middleware.OptionalAuthMiddleware
logger *zap.Logger
}
// NewProductRoutes 创建产品路由
func NewProductRoutes(
productHandler *handlers.ProductHandler,
componentReportHandler *component_report.ComponentReportHandler,
auth *middleware.JWTAuthMiddleware,
optionalAuth *middleware.OptionalAuthMiddleware,
logger *zap.Logger,
) *ProductRoutes {
return &ProductRoutes{
productHandler: productHandler,
componentReportHandler: componentReportHandler,
auth: auth,
optionalAuth: optionalAuth,
logger: logger,
}
}
// Register 注册产品相关路由
func (r *ProductRoutes) Register(router *sharedhttp.GinRouter) {
engine := router.GetEngine()
// 数据大厅 - 公开接口
products := engine.Group("/api/v1/products")
{
// 获取产品列表(分页+筛选)
products.GET("", r.optionalAuth.Handle(), r.productHandler.ListProducts)
// 获取产品统计
products.GET("/stats", r.productHandler.GetProductStats)
// 根据产品代码获取API配置
products.GET("/code/:product_code/api-config", r.productHandler.GetProductApiConfigByCode)
// 产品详情和API配置 - 使用具体路径避免冲突
products.GET("/:id", r.productHandler.GetProductDetail)
products.GET("/:id/api-config", r.productHandler.GetProductApiConfig)
products.GET("/:id/documentation", r.productHandler.GetProductDocumentation)
products.GET("/:id/documentation/download", r.productHandler.DownloadProductDocumentation)
// 订阅产品(需要认证)
products.POST("/:id/subscribe", r.auth.Handle(), r.productHandler.SubscribeProduct)
}
// 组件报告 - 需要认证
componentReport := engine.Group("/api/v1/component-report", r.auth.Handle())
{
// 生成并下载 example.json 文件
componentReport.POST("/download-example-json", r.componentReportHandler.DownloadExampleJSON)
// 生成并下载示例报告ZIP文件
componentReport.POST("/generate-and-download", r.componentReportHandler.GenerateAndDownloadZip)
}
// 产品组件报告相关接口 - 已迁移到 ComponentReportOrderRoutes
// 分类 - 公开接口
categories := engine.Group("/api/v1/categories")
{
// 获取分类列表
categories.GET("", r.productHandler.ListCategories)
// 获取分类详情
categories.GET("/:id", r.productHandler.GetCategoryDetail)
}
// 我的订阅 - 需要认证
my := engine.Group("/api/v1/my", r.auth.Handle())
{
subscriptions := my.Group("/subscriptions")
{
// 获取我的订阅列表
subscriptions.GET("", r.productHandler.ListMySubscriptions)
// 获取我的订阅统计
subscriptions.GET("/stats", r.productHandler.GetMySubscriptionStats)
// 获取订阅详情
subscriptions.GET("/:id", r.productHandler.GetMySubscriptionDetail)
// 获取订阅使用情况
subscriptions.GET("/:id/usage", r.productHandler.GetMySubscriptionUsage)
// 取消订阅
subscriptions.POST("/:id/cancel", r.productHandler.CancelMySubscription)
}
}
r.logger.Info("产品路由注册完成")
}

View File

@@ -0,0 +1,37 @@
package routes
import (
"hyapi-server/internal/infrastructure/http/handlers"
sharedhttp "hyapi-server/internal/shared/http"
)
// QYGLReportRoutes 企业报告页面路由注册器
type QYGLReportRoutes struct {
handler *handlers.QYGLReportHandler
}
// NewQYGLReportRoutes 创建企业报告页面路由注册器
func NewQYGLReportRoutes(
handler *handlers.QYGLReportHandler,
) *QYGLReportRoutes {
return &QYGLReportRoutes{
handler: handler,
}
}
// Register 注册企业报告页面路由
func (r *QYGLReportRoutes) Register(router *sharedhttp.GinRouter) {
engine := router.GetEngine()
// 企业全景报告页面(实时生成)
engine.GET("/reports/qygl", r.handler.GetQYGLReportPage)
// 企业全景报告页面(通过编号查看)
engine.GET("/reports/qygl/:id", r.handler.GetQYGLReportPageByID)
// 企业全景报告 PDF 预生成状态(通过编号,供前端轮询)
engine.GET("/reports/qygl/:id/pdf/status", r.handler.GetQYGLReportPDFStatusByID)
// 企业全景报告 PDF 导出(通过编号)
engine.GET("/reports/qygl/:id/pdf", r.handler.GetQYGLReportPDFByID)
}

View File

@@ -0,0 +1,168 @@
package routes
import (
"hyapi-server/internal/infrastructure/http/handlers"
sharedhttp "hyapi-server/internal/shared/http"
"hyapi-server/internal/shared/middleware"
"go.uber.org/zap"
)
// StatisticsRoutes 统计路由
type StatisticsRoutes struct {
statisticsHandler *handlers.StatisticsHandler
auth *middleware.JWTAuthMiddleware
optionalAuth *middleware.OptionalAuthMiddleware
admin *middleware.AdminAuthMiddleware
logger *zap.Logger
}
// NewStatisticsRoutes 创建统计路由
func NewStatisticsRoutes(
statisticsHandler *handlers.StatisticsHandler,
auth *middleware.JWTAuthMiddleware,
optionalAuth *middleware.OptionalAuthMiddleware,
admin *middleware.AdminAuthMiddleware,
logger *zap.Logger,
) *StatisticsRoutes {
return &StatisticsRoutes{
statisticsHandler: statisticsHandler,
auth: auth,
optionalAuth: optionalAuth,
admin: admin,
logger: logger,
}
}
// Register 注册统计相关路由
func (r *StatisticsRoutes) Register(router *sharedhttp.GinRouter) {
engine := router.GetEngine()
// ================ 用户端统计路由 ================
// 统计公开接口
statistics := engine.Group("/api/v1/statistics")
{
// 获取公开统计信息
statistics.GET("/public", r.statisticsHandler.GetPublicStatistics)
// 获取API受欢迎榜单公开接口
statistics.GET("/api-popularity-ranking", r.statisticsHandler.GetPublicApiPopularityRanking)
// 获取最新产品推荐(公开接口)
statistics.GET("/latest-products", r.statisticsHandler.GetLatestProducts)
}
// 用户统计接口 - 需要认证
userStats := engine.Group("/api/v1/statistics", r.auth.Handle())
{
// 获取用户统计信息
userStats.GET("/user", r.statisticsHandler.GetUserStatistics)
// 独立统计接口(用户只能查询自己的数据)
userStats.GET("/api-calls", r.statisticsHandler.GetApiCallsStatistics)
userStats.GET("/consumption", r.statisticsHandler.GetConsumptionStatistics)
userStats.GET("/recharge", r.statisticsHandler.GetRechargeStatistics)
// 获取指标列表
userStats.GET("/metrics", r.statisticsHandler.GetMetrics)
// 获取指标详情
userStats.GET("/metrics/:id", r.statisticsHandler.GetMetricDetail)
// 获取仪表板列表
userStats.GET("/dashboards", r.statisticsHandler.GetDashboards)
// 获取仪表板详情
userStats.GET("/dashboards/:id", r.statisticsHandler.GetDashboardDetail)
// 获取仪表板数据
userStats.GET("/dashboards/:id/data", r.statisticsHandler.GetDashboardData)
// 获取报告列表
userStats.GET("/reports", r.statisticsHandler.GetReports)
// 获取报告详情
userStats.GET("/reports/:id", r.statisticsHandler.GetReportDetail)
// 创建报告
userStats.POST("/reports", r.statisticsHandler.CreateReport)
}
// ================ 管理员统计路由 ================
// 管理员路由组
adminGroup := engine.Group("/api/v1/admin")
adminGroup.Use(r.admin.Handle()) // 管理员权限验证
{
// 统计指标管理
metrics := adminGroup.Group("/statistics/metrics")
{
metrics.GET("", r.statisticsHandler.AdminGetMetrics)
metrics.POST("", r.statisticsHandler.AdminCreateMetric)
metrics.PUT("/:id", r.statisticsHandler.AdminUpdateMetric)
metrics.DELETE("/:id", r.statisticsHandler.AdminDeleteMetric)
}
// 仪表板管理
dashboards := adminGroup.Group("/statistics/dashboards")
{
dashboards.GET("", r.statisticsHandler.AdminGetDashboards)
dashboards.POST("", r.statisticsHandler.AdminCreateDashboard)
dashboards.PUT("/:id", r.statisticsHandler.AdminUpdateDashboard)
dashboards.DELETE("/:id", r.statisticsHandler.AdminDeleteDashboard)
}
// 报告管理
reports := adminGroup.Group("/statistics/reports")
{
reports.GET("", r.statisticsHandler.AdminGetReports)
}
// 系统统计
system := adminGroup.Group("/statistics/system")
{
system.GET("", r.statisticsHandler.AdminGetSystemStatistics)
}
// 独立域统计接口
domainStats := adminGroup.Group("/statistics")
{
domainStats.GET("/user-domain", r.statisticsHandler.AdminGetUserDomainStatistics)
domainStats.GET("/api-domain", r.statisticsHandler.AdminGetApiDomainStatistics)
domainStats.GET("/consumption-domain", r.statisticsHandler.AdminGetConsumptionDomainStatistics)
domainStats.GET("/recharge-domain", r.statisticsHandler.AdminGetRechargeDomainStatistics)
}
// 排行榜接口
rankings := adminGroup.Group("/statistics")
{
rankings.GET("/user-call-ranking", r.statisticsHandler.AdminGetUserCallRanking)
rankings.GET("/recharge-ranking", r.statisticsHandler.AdminGetRechargeRanking)
rankings.GET("/api-popularity-ranking", r.statisticsHandler.AdminGetApiPopularityRanking)
rankings.GET("/today-certified-enterprises", r.statisticsHandler.AdminGetTodayCertifiedEnterprises)
}
// 用户统计
userStats := adminGroup.Group("/statistics/users")
{
userStats.GET("/:user_id", r.statisticsHandler.AdminGetUserStatistics)
}
// 独立统计接口(管理员可查询任意用户)
independentStats := adminGroup.Group("/statistics")
{
independentStats.GET("/api-calls", r.statisticsHandler.GetApiCallsStatistics)
independentStats.GET("/consumption", r.statisticsHandler.GetConsumptionStatistics)
independentStats.GET("/recharge", r.statisticsHandler.GetRechargeStatistics)
}
// 数据聚合
aggregation := adminGroup.Group("/statistics/aggregation")
{
aggregation.POST("/trigger", r.statisticsHandler.AdminTriggerAggregation)
}
}
r.logger.Info("统计路由注册完成")
}

View File

@@ -0,0 +1,52 @@
package routes
import (
"hyapi-server/internal/infrastructure/http/handlers"
sharedhttp "hyapi-server/internal/shared/http"
"hyapi-server/internal/shared/middleware"
)
// SubCategoryRoutes 二级分类路由
type SubCategoryRoutes struct {
handler *handlers.SubCategoryHandler
auth *middleware.JWTAuthMiddleware
admin *middleware.AdminAuthMiddleware
}
// NewSubCategoryRoutes 创建二级分类路由
func NewSubCategoryRoutes(
handler *handlers.SubCategoryHandler,
auth *middleware.JWTAuthMiddleware,
admin *middleware.AdminAuthMiddleware,
) *SubCategoryRoutes {
return &SubCategoryRoutes{
handler: handler,
auth: auth,
admin: admin,
}
}
// Register 注册路由
func (r *SubCategoryRoutes) Register(router *sharedhttp.GinRouter) {
engine := router.GetEngine()
adminGroup := engine.Group("/api/v1/admin")
adminGroup.Use(r.auth.Handle())
adminGroup.Use(r.admin.Handle())
{
// 二级分类管理
subCategories := adminGroup.Group("/sub-categories")
{
subCategories.POST("", r.handler.CreateSubCategory) // 创建二级分类
subCategories.PUT("/:id", r.handler.UpdateSubCategory) // 更新二级分类
subCategories.DELETE("/:id", r.handler.DeleteSubCategory) // 删除二级分类
subCategories.GET("/:id", r.handler.GetSubCategory) // 获取二级分类详情
subCategories.GET("", r.handler.ListSubCategories) // 获取二级分类列表
}
// 一级分类下的二级分类路由(级联选择)
categoryAdmin := adminGroup.Group("/product-categories")
{
categoryAdmin.GET("/:id/sub-categories", r.handler.ListSubCategoriesByCategory) // 根据一级分类获取二级分类列表
}
}
}

View File

@@ -0,0 +1,56 @@
package routes
import (
"go.uber.org/zap"
"hyapi-server/internal/infrastructure/http/handlers"
sharedhttp "hyapi-server/internal/shared/http"
"hyapi-server/internal/shared/middleware"
)
// UIComponentRoutes UI组件路由
type UIComponentRoutes struct {
uiComponentHandler *handlers.UIComponentHandler
logger *zap.Logger
auth *middleware.JWTAuthMiddleware
admin *middleware.AdminAuthMiddleware
}
// NewUIComponentRoutes 创建UI组件路由
func NewUIComponentRoutes(
uiComponentHandler *handlers.UIComponentHandler,
logger *zap.Logger,
auth *middleware.JWTAuthMiddleware,
admin *middleware.AdminAuthMiddleware,
) *UIComponentRoutes {
return &UIComponentRoutes{
uiComponentHandler: uiComponentHandler,
logger: logger,
auth: auth,
admin: admin,
}
}
// RegisterRoutes 注册UI组件路由
func (r *UIComponentRoutes) Register(router *sharedhttp.GinRouter) {
// 管理员路由组
engine := router.GetEngine()
uiComponentGroup := engine.Group("/api/v1/admin/ui-components")
uiComponentGroup.Use(r.admin.Handle()) // 管理员权限验证
{
// UI组件管理
uiComponentGroup.POST("", r.uiComponentHandler.CreateUIComponent) // 创建UI组件
uiComponentGroup.POST("/create-with-file", r.uiComponentHandler.CreateUIComponentWithFile) // 创建UI组件并上传文件
uiComponentGroup.GET("", r.uiComponentHandler.ListUIComponents) // 获取UI组件列表
uiComponentGroup.GET("/:id", r.uiComponentHandler.GetUIComponent) // 获取UI组件详情
uiComponentGroup.PUT("/:id", r.uiComponentHandler.UpdateUIComponent) // 更新UI组件
uiComponentGroup.DELETE("/:id", r.uiComponentHandler.DeleteUIComponent) // 删除UI组件
// 文件操作
uiComponentGroup.POST("/:id/upload", r.uiComponentHandler.UploadUIComponentFile) // 上传UI组件文件
uiComponentGroup.POST("/:id/upload-extract", r.uiComponentHandler.UploadAndExtractUIComponentFile) // 上传并解压UI组件文件
uiComponentGroup.GET("/:id/folder-content", r.uiComponentHandler.GetUIComponentFolderContent) // 获取UI组件文件夹内容
uiComponentGroup.DELETE("/:id/folder", r.uiComponentHandler.DeleteUIComponentFolder) // 删除UI组件文件夹
uiComponentGroup.GET("/:id/download", r.uiComponentHandler.DownloadUIComponentFile) // 下载UI组件文件
}
}

View File

@@ -0,0 +1,67 @@
package routes
import (
"hyapi-server/internal/infrastructure/http/handlers"
sharedhttp "hyapi-server/internal/shared/http"
"hyapi-server/internal/shared/middleware"
"go.uber.org/zap"
)
// UserRoutes 用户路由注册器
type UserRoutes struct {
handler *handlers.UserHandler
authMiddleware *middleware.JWTAuthMiddleware
adminAuthMiddleware *middleware.AdminAuthMiddleware
logger *zap.Logger
}
// NewUserRoutes 创建用户路由注册器
func NewUserRoutes(
handler *handlers.UserHandler,
authMiddleware *middleware.JWTAuthMiddleware,
adminAuthMiddleware *middleware.AdminAuthMiddleware,
logger *zap.Logger,
) *UserRoutes {
return &UserRoutes{
handler: handler,
authMiddleware: authMiddleware,
adminAuthMiddleware: adminAuthMiddleware,
logger: logger,
}
}
// Register 注册用户相关路由
func (r *UserRoutes) Register(router *sharedhttp.GinRouter) {
// 用户域路由组
engine := router.GetEngine()
usersGroup := engine.Group("/api/v1/users")
{
// 公开路由(不需要认证)
usersGroup.POST("/send-code", r.handler.SendCode) // 发送验证码
usersGroup.POST("/register", r.handler.Register) // 用户注册
usersGroup.POST("/login-password", r.handler.LoginWithPassword) // 密码登录
usersGroup.POST("/login-sms", r.handler.LoginWithSMS) // 短信验证码登录
usersGroup.POST("/reset-password", r.handler.ResetPassword) // 重置密码
// 需要认证的路由
authenticated := usersGroup.Group("")
authenticated.Use(r.authMiddleware.Handle())
{
authenticated.GET("/me", r.handler.GetProfile) // 获取当前用户信息
authenticated.PUT("/me/password", r.handler.ChangePassword) // 修改密码
}
// 管理员路由
adminGroup := usersGroup.Group("/admin")
adminGroup.Use(r.adminAuthMiddleware.Handle())
{
adminGroup.GET("/list", r.handler.ListUsers) // 管理员查看用户列表
adminGroup.GET("/:user_id", r.handler.GetUserDetail) // 管理员获取用户详情
adminGroup.GET("/stats", r.handler.GetUserStats) // 管理员获取用户统计信息
}
}
r.logger.Info("用户路由注册完成")
}