router.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package api
  2. import (
  3. "box-cost/db/repo"
  4. "fmt"
  5. "github.com/gin-gonic/gin"
  6. )
  7. // RegRouters 注册路由
  8. func RegRouters(svc *Service) {
  9. boxcost := svc.NewGinRouter("/" + svc.Conf.Name)
  10. boxcost.group.Use(Logger())
  11. //数据存储
  12. boxcost.POST("/save/policy", ServiceObsUploadPolicy)
  13. boxcost.GET("/printr", Printr)
  14. boxcost.GET("/removeSyncBill", RemovePlanSyncBill)
  15. boxcost.GET("/callback", callback)
  16. boxcost.POSTJWT("/diffUpdatePlanTest", DiffUpdatePlanTest)
  17. boxcost.POSTJWT("/diffUpdateProduceTest", DiffUpdateProduceTest)
  18. // boxcost.GET("/printDiff", PrintDiff)
  19. boxcost.GETJWT("/bill/history/list", BillHistoryList)
  20. boxcost.GETJWT("/plan/history/list", PlanHistoryList)
  21. boxcost.GETJWT("/bill/history/detail/:id", GetBillHistory)
  22. boxcost.GETJWT("/plan/history/detail/:id", GetPlanHistory)
  23. boxcost.POSTJWT("/download/plan/track", DownloadPlanTrack)
  24. PlanTrack(boxcost)
  25. // 材料管理
  26. Material(boxcost)
  27. // 工艺管理
  28. Craft(boxcost)
  29. // 供应商管理
  30. Supplier(boxcost)
  31. // 供应商价格管理
  32. SupplierPrice(boxcost)
  33. // 包装管理
  34. Pack(boxcost)
  35. // 生产计划管理
  36. ProductPlan(boxcost)
  37. //材料采购单据管理
  38. Bill(boxcost)
  39. //加工单据
  40. BillProduce(boxcost)
  41. //成品采购
  42. BillProduct(boxcost)
  43. //设置
  44. Setting(boxcost)
  45. // 签名管理
  46. Signature(boxcost)
  47. // 统计报表
  48. Report(boxcost)
  49. // 成品采购管理
  50. Product(boxcost)
  51. // 计划汇总
  52. Summary(boxcost)
  53. boxcost.GET("/apk/version", func(c *gin.Context, apictx *ApiSession) (interface{}, error) {
  54. out, err := repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
  55. CollectName: "versions",
  56. Page: 1,
  57. Size: 10,
  58. Sort: repo.Map{"releaseDate": -1},
  59. })
  60. c.JSON(200, out.List)
  61. return nil, err
  62. })
  63. }
  64. func Logger() gin.HandlerFunc {
  65. return func(c *gin.Context) {
  66. // 开始时间
  67. // start := time.Now()
  68. // 处理请求
  69. c.Next()
  70. // 结束时间
  71. // end := time.Now()
  72. //执行时间
  73. // latency := end.Sub(start)
  74. path := c.Request.URL.Path
  75. clientIP := c.ClientIP()
  76. // method := c.Request.Method
  77. // statusCode := c.Writer.Status()
  78. out := fmt.Sprintf("%15s=> %s", clientIP, path)
  79. fmt.Println(out)
  80. }
  81. }