router.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. // plan相关操作
  54. boxcost.POSTJWT("/plan/add/component/:id", AddCompnonet)
  55. boxcost.POSTJWT("/plan/delete/component/:id/:componentId", DeleteCompnonet)
  56. boxcost.POSTJWT("/plan/update/component/:id/:componentId", UpdateCompnonet)
  57. boxcost.POSTJWT("/plan/add/stages", AddStage)
  58. boxcost.POSTJWT("/plan/update/stages", UpdateStages)
  59. boxcost.POSTJWT("/plan/delete/stage", DeleteStage)
  60. boxcost.POSTJWT("/plan/update/fileds", UpdatePlanfileds)
  61. boxcost.GET("/apk/version", func(c *gin.Context, apictx *ApiSession) (interface{}, error) {
  62. out, err := repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
  63. CollectName: "versions",
  64. Page: 1,
  65. Size: 10,
  66. Sort: repo.Map{"releaseDate": -1},
  67. })
  68. c.JSON(200, out.List)
  69. return nil, err
  70. })
  71. }
  72. func Logger() gin.HandlerFunc {
  73. return func(c *gin.Context) {
  74. // 开始时间
  75. // start := time.Now()
  76. // 处理请求
  77. c.Next()
  78. // 结束时间
  79. // end := time.Now()
  80. //执行时间
  81. // latency := end.Sub(start)
  82. path := c.Request.URL.Path
  83. clientIP := c.ClientIP()
  84. // method := c.Request.Method
  85. // statusCode := c.Writer.Status()
  86. out := fmt.Sprintf("%15s=> %s", clientIP, path)
  87. fmt.Println(out)
  88. }
  89. }