router.go 1.8 KB

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