adapter.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package adapter
  2. import (
  3. "Cold_Logistic/internal/server/adapter/http/v1/common"
  4. "Cold_Logistic/internal/server/adapter/http/v1/insider"
  5. "Cold_Logistic/internal/server/adapter/http/v1/manage"
  6. "Cold_Logistic/internal/server/adapter/http/v1/myself"
  7. "Cold_Logistic/internal/server/adapter/http/v1/public"
  8. "Cold_Logistic/internal/server/adapter/http/v1/swagger"
  9. "Cold_Logistic/internal/server/adapter/job/ordercron"
  10. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/watcher"
  11. "github.com/gin-gonic/gin"
  12. _ "Cold_Logistic/docs"
  13. "Cold_Logistic/internal/server/adapter/http/v1/auth"
  14. )
  15. func HttpRoutes() func(r *gin.Engine) {
  16. return func(r *gin.Engine) {
  17. //Swagger文档
  18. swagger.RegisterSwagger(r)
  19. // 用户端
  20. app := r.Group("/clodLogistic/api/v1/app")
  21. auth.Register(app)
  22. // 我的
  23. myself.Register(app)
  24. // 开放接口
  25. public.Register(app)
  26. // 司机、仓管
  27. insider.Register(app)
  28. // 地区下拉列表
  29. common.Register(app)
  30. // 管理后台
  31. admin := r.Group("/clodLogistic/api/v1/manage")
  32. manage.Register(admin)
  33. }
  34. }
  35. // RegisterCron 注册周期任务
  36. func RegisterCron() func(c *watcher.MyCronJob) {
  37. return func(c *watcher.MyCronJob) {
  38. var err error
  39. orderNoJob := ordercron.NewOrderNoJob()
  40. _, err = c.RegisterJob("0 0 */2 * * ?", // 每隔两小时触发
  41. watcher.NewJob(orderNoJob, watcher.WithSkipRunningJobV2()), // 若上次任务未结束就跳过,遇panic可以下一轮调度
  42. watcher.WithRegisterStop(orderNoJob))
  43. if err != nil {
  44. panic(err)
  45. }
  46. }
  47. }