123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- package common
- import (
- "Cold_Logistic/internal/pkg/common/codex"
- "Cold_Logistic/internal/pkg/common/global"
- "Cold_Logistic/internal/server/adapter/http/middleware"
- "Cold_Logistic/internal/server/application/commonsrv"
- "Cold_Logistic/internal/server/application/devicesrv"
- "Cold_Logistic/internal/server/infra/dao"
- "github.com/gin-gonic/gin"
- "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/core"
- "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/errors"
- )
- func Register(r *gin.RouterGroup) {
- api := NewApi()
- common := r.Group("/common")
- common.Use(middleware.Auth())
- common.GET("/provinceList", api.provinceList) // 省市区列表
- common.GET("/sensorDataList", api.sensorDataList) // 设备数据列表
- common.GET("/logisticList", api.logisticList) // 物流公司列表
- return
- }
- type Api struct{}
- func NewApi() Api {
- return Api{}
- }
- // provinceList
- // @Tags 公共接口
- // @Summary 省市区列表
- // @Success 200 {object} commonsrv.ProvinceListRespVO "成功响应的结构体"
- // @Accept application/json
- // @Router /app/common/provinceList [get]
- func (api Api) provinceList(c *gin.Context) {
- srv := commonsrv.NewCommonService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
- data, err := srv.ProvinceList(c)
- if err != nil {
- core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrQueryFailed, ""))
- return
- }
- core.WriteResponse(c, nil, data)
- }
- // sensorDataList
- // @Tags 公共接口
- // @Summary 设备数据列表
- // @Success 200 {object} swagger.PageListResponse "成功响应的结构体"
- // @Param req body swagger.SnDataListReqVO true "请求参数"
- // @Accept application/json
- // @Router /app/common/sensorDataList [get]
- func (api Api) sensorDataList(c *gin.Context) {
- req := devicesrv.SnDataListReqVO{}
- if err := c.BindJSON(&req); err != nil {
- core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, ""))
- return
- }
- if err := req.Validate(); err != nil {
- core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrParamValidate, "参数验证失败:"))
- return
- }
- srv := devicesrv.NewDeviceService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
- res, err := srv.SnDataList(c, req)
- if err != nil {
- core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrQueryFailed, ""))
- return
- }
- core.WriteResponse(c, nil, res)
- }
- // logisticList
- // @Tags 公共接口
- // @Summary 物流公司列表
- // @Success 200 {object} swagger.PageListResponse "成功响应的结构体"
- // @Param req body swagger.LogisticListReqVO true "请求参数"
- // @Accept application/json
- // @Router /app/common/logisticList [get]
- func (api Api) logisticList(c *gin.Context) {
- req := commonsrv.LogisticListReqVO{}
- if err := c.BindJSON(&req); err != nil {
- core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, ""))
- return
- }
- srv := commonsrv.NewCommonService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
- res, err := srv.LogisticList(c, req)
- if err != nil {
- core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrQueryFailed, ""))
- return
- }
- core.WriteResponse(c, nil, res)
- }
|