router.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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("/logs/list", PrintDiff)
  20. boxcost.POSTJWT("/download/plan/track", DownloadPlanTrack)
  21. PlanTrack(boxcost)
  22. // 材料管理
  23. Material(boxcost)
  24. // 工艺管理
  25. Craft(boxcost)
  26. // 供应商管理
  27. Supplier(boxcost)
  28. // 供应商价格管理
  29. SupplierPrice(boxcost)
  30. // 包装管理
  31. Pack(boxcost)
  32. // 生产计划管理
  33. ProductPlan(boxcost)
  34. //材料采购单据管理
  35. Bill(boxcost)
  36. //加工单据
  37. BillProduce(boxcost)
  38. //成品采购
  39. BillProduct(boxcost)
  40. //设置
  41. Setting(boxcost)
  42. // 签名管理
  43. Signature(boxcost)
  44. // 统计报表
  45. Report(boxcost)
  46. // 成品采购管理
  47. Product(boxcost)
  48. // 计划汇总
  49. Summary(boxcost)
  50. boxcost.GET("/apk/version", func(c *gin.Context, apictx *ApiSession) (interface{}, error) {
  51. out, err := repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
  52. CollectName: "versions",
  53. Page: 1,
  54. Size: 10,
  55. Sort: repo.Map{"releaseDate": -1},
  56. })
  57. c.JSON(200, out.List)
  58. return nil, err
  59. })
  60. }
  61. func Logger() gin.HandlerFunc {
  62. return func(c *gin.Context) {
  63. // 开始时间
  64. // start := time.Now()
  65. // 处理请求
  66. c.Next()
  67. // 结束时间
  68. // end := time.Now()
  69. //执行时间
  70. // latency := end.Sub(start)
  71. path := c.Request.URL.Path
  72. clientIP := c.ClientIP()
  73. // method := c.Request.Method
  74. // statusCode := c.Writer.Status()
  75. out := fmt.Sprintf("%15s=> %s", clientIP, path)
  76. fmt.Println(out)
  77. }
  78. }