app_api.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package route
  2. import (
  3. "kpt-tmr-group/http/handler"
  4. "kpt-tmr-group/http/handler/dashboard"
  5. "kpt-tmr-group/http/handler/feed"
  6. "kpt-tmr-group/http/handler/mobile"
  7. "kpt-tmr-group/http/handler/pasture"
  8. "kpt-tmr-group/http/handler/statistic"
  9. "kpt-tmr-group/http/handler/system"
  10. "kpt-tmr-group/http/middleware"
  11. "github.com/gin-gonic/gin"
  12. )
  13. func AppAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
  14. return func(s *gin.Engine) {
  15. for _, opt := range opts {
  16. opt(s)
  17. }
  18. // Not Found
  19. s.NoRoute(handler.Handle404)
  20. // Health Check
  21. s.GET("/check", handler.Health)
  22. s.POST("/auth", system.Auth)
  23. s.GET("/wx_applet/openid/:js_code", system.GetWxAppletOpenId)
  24. // system API 组
  25. // 系统用户
  26. systemRoute := authRouteGroup(s, "/api/v1/system/")
  27. systemRoute.POST("/user_info", system.GetUserInfo)
  28. systemRoute.POST("/user/add", system.AddSystemUser)
  29. systemRoute.GET("/user/details/:user_id", system.DetailsSystemUser)
  30. systemRoute.POST("/user/list", system.SearchSystemUserList)
  31. systemRoute.POST("/user/edit", system.EditSystemUser)
  32. systemRoute.POST("/user/is_show", system.IsShowSystemUser)
  33. systemRoute.DELETE("/user/:user_id", system.DeleteUser)
  34. systemRoute.POST("/user/permissions", system.GetSystemUserPermissions)
  35. systemRoute.POST("/user/rest_password/:user_id", system.ResetPasswordSystemUser)
  36. systemRoute.POST("/user/logout", system.LogoutSystemUser)
  37. // 系统角色
  38. systemRoute.POST("/role/add", system.AddSystemRole)
  39. systemRoute.GET("/role/permissions/:role_id", system.GetRolePermissions)
  40. systemRoute.POST("/role/edit", system.EditSystemRole)
  41. systemRoute.DELETE("/role/:role_id", system.DeleteSystemRole)
  42. systemRoute.POST("/role/list", system.SearchSystemRoleList)
  43. // 系统菜单权限
  44. systemRoute.POST("/menu/add", system.AddSystemMenu)
  45. systemRoute.POST("/menu/edit", system.EditSystemMenu)
  46. systemRoute.POST("/menu/is_show", system.IsShowSystemMenu)
  47. systemRoute.POST("/menu/list", system.SearchSystemMenuList)
  48. systemRoute.DELETE("/menu/:menu_id", system.DeleteSystemMenu)
  49. // 移动端
  50. systemRoute.POST("/mobile/list", mobile.SearchMobileList)
  51. // 牧场管理
  52. opsRoute := authRouteGroup(s, "/api/v1/ops/")
  53. opsRoute.POST("/pasture/add", pasture.AddGroupPasture)
  54. opsRoute.POST("/pasture/edit", pasture.EditGroupPasture)
  55. opsRoute.POST("/pasture/list", pasture.SearchGroupPastureList)
  56. opsRoute.DELETE("/pasture/:pasture_id", pasture.DeleteGroupPasture)
  57. opsRoute.POST("/pasture/rest_password/:pasture_id", pasture.ResetPasswordGroupPasture)
  58. opsRoute.POST("/pasture/is_show", pasture.IsShowGroupPasture)
  59. // 牲牧类型
  60. // opsRoute.GET("/cattle/category/parent_list", pasture.ParentCattleCategoryList)
  61. opsRoute.POST("/cattle/category/add", pasture.AddCattleCategory)
  62. opsRoute.POST("/cattle/category/edit", pasture.EditCattleCategory)
  63. opsRoute.POST("/cattle/category/is_show", pasture.IsShowCattleCategory)
  64. opsRoute.DELETE("/cattle/category/:cattle_category_id", pasture.DeleteCattleCategory)
  65. opsRoute.POST("/cattle/category/list", pasture.SearchCattleCategory)
  66. // 饲料类别
  67. // opsRoute.GET("/forage/category/parent_list", pasture.ParentForageCategoryList)
  68. opsRoute.POST("/forage/category/add", pasture.AddForageCategory)
  69. opsRoute.POST("/forage/category/edit", pasture.EditForageCategory)
  70. opsRoute.POST("/forage/category/is_show", pasture.IsShowForageCategory)
  71. opsRoute.DELETE("/forage/category/:forage_category_id", pasture.DeleteForageCategory)
  72. opsRoute.POST("/forage/category/list", pasture.SearchForageCategory)
  73. // 饲料列表
  74. opsRoute.POST("/forage/add", pasture.AddForage)
  75. opsRoute.POST("/forage/edit", pasture.EditForage)
  76. opsRoute.POST("/forage/list", pasture.SearchForageList)
  77. opsRoute.POST("forage/delete", pasture.DeleteForageList)
  78. opsRoute.POST("forage/is_show", pasture.IsShowForage)
  79. opsRoute.POST("forage/excel_import", pasture.ExcelImportForage)
  80. opsRoute.POST("forage/excel_export", pasture.ExcelExportForage)
  81. opsRoute.POST("forage/excel_template", pasture.ExcelTemplateForage)
  82. opsRoute.GET("/forage/enum/list", pasture.SearchForageEnumList)
  83. // 饲料配方
  84. opsRoute.POST("/feed_formula/add", feed.AddFeedFormula)
  85. opsRoute.POST("/feed_formula/edit", feed.EditFeedFormula)
  86. opsRoute.POST("/feed_formula/list", feed.SearchFeedFormulaList)
  87. opsRoute.DELETE("/feed_formula/delete/:feed_formula_id", feed.DeleteFeedFormula)
  88. opsRoute.POST("/feed_formula/is_modify_show", feed.IsShowModifyFeedFormula)
  89. opsRoute.POST("/feed_formula/excel_export", feed.ExcelExportFeedFormula)
  90. opsRoute.POST("/feed_formula/excel_import", feed.ExcelImportFeedFormula)
  91. opsRoute.POST("/feed_formula/excel_template", feed.ExcelTemplateFeedFormula)
  92. opsRoute.GET("/feed_formula/encode_number", feed.EncodeNumber)
  93. opsRoute.POST("/feed_formula/distribute", feed.DistributeFeedFormula)
  94. //统计分析 statistic analysis
  95. opsRoute.POST("/feed_estimate/list", statistic.SearchFormulaEstimateList)
  96. opsRoute.POST("/inventory/statistics", statistic.SearchInventoryStatistics)
  97. opsRoute.POST("/inventory/statistics/excel_export", statistic.SearchInventoryStatisticsExcelExport)
  98. opsRoute.POST("/inventory/user_materials_statistics", statistic.SearchUserMaterialsStatistics)
  99. opsRoute.POST("/inventory/user_materials_statistics/excel_export", statistic.SearchUserMaterialsStatisticsExcelExport)
  100. opsRoute.POST("/inventory/price_statistics", statistic.SearchPriceStatistics)
  101. opsRoute.POST("/feed_efficiency/statistics", statistic.SearchFeedStatistics)
  102. opsRoute.POST("/feed_efficiency/chart_statistics", statistic.SearchFeedChartStatistics)
  103. opsRoute.POST("/feed_efficiency/cows_analysis", statistic.SearchCowsAnalysis)
  104. opsRoute.POST("/accuracy/agg_statistics", statistic.SearchAccuracyAggStatistics)
  105. opsRoute.POST("/accuracy/mixed_statistics", statistic.SearchMixFeedStatistics)
  106. opsRoute.POST("/accuracy/sprinkle_statistics", statistic.SearchSprinkleStatistics)
  107. opsRoute.POST("/accuracy/data_by_name", statistic.GetDataByName)
  108. opsRoute.POST("/process/analysis", statistic.SearchProcessAnalysis)
  109. opsRoute.POST("/statistics/train_number", statistic.TrainNumber)
  110. // 首页仪表盘
  111. opsRoute.POST("/dashboard/accuracy", dashboard.AnalysisAccuracy)
  112. opsRoute.POST("/dashboard/top_pasture", dashboard.TopPasture)
  113. opsRoute.POST("/dashboard/exec_time", dashboard.ExecutionTime)
  114. opsRoute.POST("/dashboard/sprinkle_time", dashboard.SprinkleFeedTime)
  115. }
  116. }
  117. func authRouteGroup(s *gin.Engine, relativePath string) *gin.RouterGroup {
  118. group := s.Group(relativePath)
  119. // 中间件鉴权
  120. group.Use(middleware.RequireAdmin(), middleware.CORS())
  121. return group
  122. }