| 
									
										
										
										
											2025-07-13 16:36:20 +08:00
										 |  |  |  | package routes | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | 	"go.uber.org/zap" | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-13 16:36:20 +08:00
										 |  |  |  | 	"tyapi-server/internal/infrastructure/http/handlers" | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | 	"tyapi-server/internal/shared/http" | 
					
						
							| 
									
										
										
										
											2025-07-13 16:36:20 +08:00
										 |  |  |  | 	"tyapi-server/internal/shared/middleware" | 
					
						
							|  |  |  |  | ) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | // CertificationRoutes 认证路由 | 
					
						
							| 
									
										
										
										
											2025-07-13 16:36:20 +08:00
										 |  |  |  | type CertificationRoutes struct { | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | 	handler  *handlers.CertificationHandler | 
					
						
							|  |  |  |  | 	router   *http.GinRouter | 
					
						
							|  |  |  |  | 	logger   *zap.Logger | 
					
						
							|  |  |  |  | 	auth     *middleware.JWTAuthMiddleware | 
					
						
							|  |  |  |  | 	optional *middleware.OptionalAuthMiddleware | 
					
						
							| 
									
										
										
										
											2025-07-13 16:36:20 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | // NewCertificationRoutes 创建认证路由 | 
					
						
							| 
									
										
										
										
											2025-07-13 16:36:20 +08:00
										 |  |  |  | func NewCertificationRoutes( | 
					
						
							| 
									
										
										
										
											2025-07-20 20:53:26 +08:00
										 |  |  |  | 	handler *handlers.CertificationHandler, | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | 	router *http.GinRouter, | 
					
						
							| 
									
										
										
										
											2025-07-13 16:36:20 +08:00
										 |  |  |  | 	logger *zap.Logger, | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | 	auth *middleware.JWTAuthMiddleware, | 
					
						
							|  |  |  |  | 	optional *middleware.OptionalAuthMiddleware, | 
					
						
							| 
									
										
										
										
											2025-07-13 16:36:20 +08:00
										 |  |  |  | ) *CertificationRoutes { | 
					
						
							|  |  |  |  | 	return &CertificationRoutes{ | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | 		handler:  handler, | 
					
						
							|  |  |  |  | 		router:   router, | 
					
						
							|  |  |  |  | 		logger:   logger, | 
					
						
							|  |  |  |  | 		auth:     auth, | 
					
						
							|  |  |  |  | 		optional: optional, | 
					
						
							| 
									
										
										
										
											2025-07-13 16:36:20 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | // Register 注册认证路由 | 
					
						
							|  |  |  |  | func (r *CertificationRoutes) Register(router *http.GinRouter) { | 
					
						
							|  |  |  |  | 	// 认证管理路由组 | 
					
						
							|  |  |  |  | 	certificationGroup := router.GetEngine().Group("/api/v1/certifications") | 
					
						
							| 
									
										
										
										
											2025-07-13 16:36:20 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | 		// 需要认证的路由 | 
					
						
							|  |  |  |  | 		authGroup := certificationGroup.Group("") | 
					
						
							|  |  |  |  | 		authGroup.Use(r.auth.Handle()) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  |  | 			authGroup.GET("", r.handler.ListCertifications) // 查询认证列表(管理员) | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 			// 1. 获取认证详情 | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  |  | 			authGroup.GET("/details", r.handler.GetCertification) | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 			// 2. 提交企业信息 | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  |  | 			authGroup.POST("/enterprise-info", r.handler.SubmitEnterpriseInfo) | 
					
						
							| 
									
										
										
										
											2025-07-13 16:36:20 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  |  | 			// 3. 申请合同签署 | 
					
						
							|  |  |  |  | 			authGroup.POST("/apply-contract", r.handler.ApplyContract) | 
					
						
							| 
									
										
										
										
											2025-07-13 16:36:20 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  |  | 			// 前端确认是否完成认证 | 
					
						
							|  |  |  |  | 			authGroup.POST("/confirm-auth", r.handler.ConfirmAuth) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 			// 前端确认是否完成签署 | 
					
						
							|  |  |  |  | 			authGroup.POST("/confirm-sign", r.handler.ConfirmSign) | 
					
						
							| 
									
										
										
										
											2025-07-13 16:36:20 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | 		} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// 回调路由(不需要认证,但需要验证签名) | 
					
						
							|  |  |  |  | 		callbackGroup := certificationGroup.Group("/callbacks") | 
					
						
							|  |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  |  | 			callbackGroup.POST("/esign", r.handler.HandleEsignCallback) // e签宝回调(统一处理企业认证和合同签署回调) | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2025-07-13 16:36:20 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	r.logger.Info("认证路由注册完成") | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | // 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/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}, | 
					
						
							| 
									
										
										
										
											2025-07-28 01:46:39 +08:00
										 |  |  |  | 		{Method: "POST", Path: "/api/v1/certifications/callbacks/esign", Handler: "HandleEsignCallback", Auth: false}, | 
					
						
							| 
									
										
										
										
											2025-07-21 15:13:26 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | // RouteInfo 路由信息 | 
					
						
							|  |  |  |  | type RouteInfo struct { | 
					
						
							|  |  |  |  | 	Method  string | 
					
						
							|  |  |  |  | 	Path    string | 
					
						
							|  |  |  |  | 	Handler string | 
					
						
							|  |  |  |  | 	Auth    bool | 
					
						
							|  |  |  |  | } |