package route import ( "kpt-tmr-group/http/handler" "kpt-tmr-group/http/handler/dashboard" "kpt-tmr-group/http/handler/feed" "kpt-tmr-group/http/handler/mobile" "kpt-tmr-group/http/handler/pasture" "kpt-tmr-group/http/handler/statistic" "kpt-tmr-group/http/handler/system" "kpt-tmr-group/http/middleware" "github.com/gin-gonic/gin" ) func AppAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) { return func(s *gin.Engine) { for _, opt := range opts { opt(s) } // Not Found s.NoRoute(handler.Handle404) // Health Check s.GET("/check", handler.Health) s.POST("/auth", system.Auth) s.GET("/wx_applet/openid/:js_code", system.GetWxAppletOpenId) // system API 组 // 系统用户 systemRoute := authRouteGroup(s, "/api/v1/system/") systemRoute.POST("/user_info", system.GetUserInfo) systemRoute.POST("/user/add", system.AddSystemUser) systemRoute.GET("/user/details/:user_id", system.DetailsSystemUser) systemRoute.POST("/user/list", system.SearchSystemUserList) systemRoute.POST("/user/edit", system.EditSystemUser) systemRoute.POST("/user/is_show", system.IsShowSystemUser) systemRoute.DELETE("/user/:user_id", system.DeleteUser) systemRoute.POST("/user/permissions", system.GetSystemUserPermissions) systemRoute.POST("/user/rest_password/:user_id", system.ResetPasswordSystemUser) systemRoute.POST("/user/logout", system.LogoutSystemUser) // 系统角色 systemRoute.POST("/role/add", system.AddSystemRole) systemRoute.GET("/role/permissions/:role_id", system.GetRolePermissions) systemRoute.POST("/role/edit", system.EditSystemRole) systemRoute.DELETE("/role/:role_id", system.DeleteSystemRole) systemRoute.POST("/role/list", system.SearchSystemRoleList) // 系统菜单权限 systemRoute.POST("/menu/add", system.AddSystemMenu) systemRoute.POST("/menu/edit", system.EditSystemMenu) systemRoute.POST("/menu/is_show", system.IsShowSystemMenu) systemRoute.POST("/menu/list", system.SearchSystemMenuList) systemRoute.DELETE("/menu/:menu_id", system.DeleteSystemMenu) // 移动端 systemRoute.POST("/mobile/list", mobile.SearchMobileList) // 牧场管理 opsRoute := authRouteGroup(s, "/api/v1/ops/") opsRoute.POST("/pasture/add", pasture.AddGroupPasture) opsRoute.POST("/pasture/edit", pasture.EditGroupPasture) opsRoute.POST("/pasture/list", pasture.SearchGroupPastureList) opsRoute.DELETE("/pasture/:pasture_id", pasture.DeleteGroupPasture) opsRoute.POST("/pasture/rest_password/:pasture_id", pasture.ResetPasswordGroupPasture) opsRoute.POST("/pasture/is_show", pasture.IsShowGroupPasture) // 牲牧类型 // opsRoute.GET("/cattle/category/parent_list", pasture.ParentCattleCategoryList) opsRoute.POST("/cattle/category/add", pasture.AddCattleCategory) opsRoute.POST("/cattle/category/edit", pasture.EditCattleCategory) opsRoute.POST("/cattle/category/is_show", pasture.IsShowCattleCategory) opsRoute.DELETE("/cattle/category/:cattle_category_id", pasture.DeleteCattleCategory) opsRoute.POST("/cattle/category/list", pasture.SearchCattleCategory) // 饲料类别 // opsRoute.GET("/forage/category/parent_list", pasture.ParentForageCategoryList) opsRoute.POST("/forage/category/add", pasture.AddForageCategory) opsRoute.POST("/forage/category/edit", pasture.EditForageCategory) opsRoute.POST("/forage/category/is_show", pasture.IsShowForageCategory) opsRoute.DELETE("/forage/category/:forage_category_id", pasture.DeleteForageCategory) opsRoute.POST("/forage/category/list", pasture.SearchForageCategory) // 饲料列表 opsRoute.POST("/forage/add", pasture.AddForage) opsRoute.POST("/forage/edit", pasture.EditForage) opsRoute.POST("/forage/list", pasture.SearchForageList) opsRoute.POST("forage/delete", pasture.DeleteForageList) opsRoute.POST("forage/is_show", pasture.IsShowForage) opsRoute.POST("forage/excel_import", pasture.ExcelImportForage) opsRoute.POST("forage/excel_export", pasture.ExcelExportForage) opsRoute.POST("forage/excel_template", pasture.ExcelTemplateForage) opsRoute.GET("/forage/enum/list", pasture.SearchForageEnumList) // 饲料配方 opsRoute.POST("/feed_formula/add", feed.AddFeedFormula) opsRoute.POST("/feed_formula/edit", feed.EditFeedFormula) opsRoute.POST("/feed_formula/list", feed.SearchFeedFormulaList) opsRoute.DELETE("/feed_formula/delete/:feed_formula_id", feed.DeleteFeedFormula) opsRoute.POST("/feed_formula/is_modify_show", feed.IsShowModifyFeedFormula) opsRoute.POST("/feed_formula/excel_export", feed.ExcelExportFeedFormula) opsRoute.POST("/feed_formula/excel_import", feed.ExcelImportFeedFormula) opsRoute.POST("/feed_formula/excel_template", feed.ExcelTemplateFeedFormula) opsRoute.GET("/feed_formula/encode_number", feed.EncodeNumber) opsRoute.POST("/feed_formula/distribute", feed.DistributeFeedFormula) //统计分析 statistic analysis opsRoute.POST("/feed_estimate/list", statistic.SearchFormulaEstimateList) opsRoute.POST("/inventory/statistics", statistic.SearchInventoryStatistics) opsRoute.POST("/inventory/statistics/excel_export", statistic.SearchInventoryStatisticsExcelExport) opsRoute.POST("/inventory/user_materials_statistics", statistic.SearchUserMaterialsStatistics) opsRoute.POST("/inventory/user_materials_statistics/excel_export", statistic.SearchUserMaterialsStatisticsExcelExport) opsRoute.POST("/inventory/price_statistics", statistic.SearchPriceStatistics) opsRoute.POST("/feed_efficiency/statistics", statistic.SearchFeedStatistics) opsRoute.POST("/feed_efficiency/chart_statistics", statistic.SearchFeedChartStatistics) opsRoute.POST("/feed_efficiency/cows_analysis", statistic.SearchCowsAnalysis) opsRoute.POST("/accuracy/agg_statistics", statistic.SearchAccuracyAggStatistics) opsRoute.POST("/accuracy/mixed_statistics", statistic.SearchMixFeedStatistics) opsRoute.POST("/accuracy/sprinkle_statistics", statistic.SearchSprinkleStatistics) opsRoute.POST("/accuracy/data_by_name", statistic.GetDataByName) opsRoute.POST("/process/analysis", statistic.SearchProcessAnalysis) opsRoute.POST("/statistics/train_number", statistic.TrainNumber) // 首页仪表盘 opsRoute.POST("/dashboard/accuracy", dashboard.AnalysisAccuracy) opsRoute.POST("/dashboard/top_pasture", dashboard.TopPasture) opsRoute.POST("/dashboard/exec_time", dashboard.ExecutionTime) opsRoute.POST("/dashboard/sprinkle_time", dashboard.SprinkleFeedTime) } } func authRouteGroup(s *gin.Engine, relativePath string) *gin.RouterGroup { group := s.Group(relativePath) // 中间件鉴权 group.Use(middleware.RequireAdmin(), middleware.CORS()) return group }