api.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package common
  2. import (
  3. "Cold_Logistic/internal/pkg/common/codex"
  4. "Cold_Logistic/internal/pkg/common/global"
  5. "Cold_Logistic/internal/server/adapter/http/middleware"
  6. "Cold_Logistic/internal/server/application/commonsrv"
  7. "Cold_Logistic/internal/server/application/devicesrv"
  8. "Cold_Logistic/internal/server/infra/dao"
  9. "github.com/gin-gonic/gin"
  10. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/core"
  11. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/errors"
  12. )
  13. func Register(r *gin.RouterGroup) {
  14. api := NewApi()
  15. common := r.Group("/common")
  16. common.Use(middleware.Auth())
  17. common.GET("/provinceList", api.provinceList) // 省市区列表
  18. common.GET("/sensorDataList", api.sensorDataList) // 设备数据列表
  19. common.GET("/logisticList", api.logisticList) // 物流公司列表
  20. return
  21. }
  22. type Api struct{}
  23. func NewApi() Api {
  24. return Api{}
  25. }
  26. // provinceList
  27. // @Tags 公共接口
  28. // @Summary 省市区列表
  29. // @Success 200 {object} commonsrv.ProvinceListRespVO "成功响应的结构体"
  30. // @Accept application/json
  31. // @Router /app/common/provinceList [get]
  32. func (api Api) provinceList(c *gin.Context) {
  33. srv := commonsrv.NewCommonService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  34. data, err := srv.ProvinceList(c)
  35. if err != nil {
  36. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrQueryFailed, ""))
  37. return
  38. }
  39. core.WriteResponse(c, nil, data)
  40. }
  41. // sensorDataList
  42. // @Tags 公共接口
  43. // @Summary 设备数据列表
  44. // @Success 200 {object} swagger.PageListResponse "成功响应的结构体"
  45. // @Param req body swagger.SnDataListReqVO true "请求参数"
  46. // @Accept application/json
  47. // @Router /app/common/sensorDataList [get]
  48. func (api Api) sensorDataList(c *gin.Context) {
  49. req := devicesrv.SnDataListReqVO{}
  50. if err := c.BindJSON(&req); err != nil {
  51. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, ""))
  52. return
  53. }
  54. if err := req.Validate(); err != nil {
  55. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrParamValidate, "参数验证失败:"))
  56. return
  57. }
  58. srv := devicesrv.NewDeviceService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  59. res, err := srv.SnDataList(c, req)
  60. if err != nil {
  61. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrQueryFailed, ""))
  62. return
  63. }
  64. core.WriteResponse(c, nil, res)
  65. }
  66. // logisticList
  67. // @Tags 公共接口
  68. // @Summary 物流公司列表
  69. // @Success 200 {object} swagger.PageListResponse "成功响应的结构体"
  70. // @Param req body swagger.LogisticListReqVO true "请求参数"
  71. // @Accept application/json
  72. // @Router /app/common/logisticList [get]
  73. func (api Api) logisticList(c *gin.Context) {
  74. req := commonsrv.LogisticListReqVO{}
  75. if err := c.BindJSON(&req); err != nil {
  76. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, ""))
  77. return
  78. }
  79. srv := commonsrv.NewCommonService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  80. res, err := srv.LogisticList(c, req)
  81. if err != nil {
  82. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrQueryFailed, ""))
  83. return
  84. }
  85. core.WriteResponse(c, nil, res)
  86. }