common.go 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package manage
  2. import (
  3. "Cold_Logistic/internal/pkg/common/codex"
  4. "Cold_Logistic/internal/pkg/common/global"
  5. "Cold_Logistic/internal/server/application/commonsrv"
  6. "Cold_Logistic/internal/server/application/devicesrv"
  7. "Cold_Logistic/internal/server/infra/dao"
  8. "github.com/gin-gonic/gin"
  9. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/core"
  10. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/errors"
  11. )
  12. // userList
  13. // @Tags 后台-公共接口
  14. // @Summary 用户列表
  15. // @Success 200 {object} swagger.PageListResponse "成功响应的结构体"
  16. // @Param req body swagger.UserListReqVO true "请求参数"
  17. // @Accept application/json
  18. // @Router /manage/common/userList [post]
  19. func (api Api) userList(c *gin.Context) {
  20. req := commonsrv.UserListReqVO{}
  21. if err := c.BindJSON(&req); err != nil {
  22. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, ""))
  23. return
  24. }
  25. srv := commonsrv.NewCommonService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  26. res, err := srv.UserList(c, req)
  27. if err != nil {
  28. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrQueryFailed, ""))
  29. return
  30. }
  31. core.WriteResponse(c, nil, res)
  32. }
  33. // deviceSensorList
  34. // @Tags 后台-公共接口
  35. // @Summary 设备探头列表
  36. // @Success 200 {object} devicesrv.DeviceSensorListRespVO "成功响应的结构体"
  37. // @Param req body devicesrv.DeviceSensorListReqVO true "请求参数"
  38. // @Accept application/json
  39. // @Router /manage/common/deviceSensorList [post]
  40. func (api Api) deviceSensorList(c *gin.Context) {
  41. req := devicesrv.DeviceSensorListReqVO{}
  42. if err := c.BindJSON(&req); err != nil {
  43. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, ""))
  44. return
  45. }
  46. if err := req.Validate(); err != nil {
  47. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrParamValidate, "参数验证失败:"))
  48. return
  49. }
  50. srv := devicesrv.NewDeviceService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  51. res, err := srv.DeviceSensorList(c, req)
  52. if err != nil {
  53. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrQueryFailed, ""))
  54. return
  55. }
  56. core.WriteResponse(c, nil, res)
  57. }
  58. // snDataList
  59. // @Tags 后台-公共接口
  60. // @Summary 设备数据列表
  61. // @Success 200 {object} swagger.PageListResponse "成功响应的结构体"
  62. // @Param req body swagger.SnDataListReqVO true "请求参数"
  63. // @Accept application/json
  64. // @Router /manage/common/sensorDataList [post]
  65. func (api Api) snDataList(c *gin.Context) {
  66. req := devicesrv.SnDataListReqVO{}
  67. if err := c.BindJSON(&req); err != nil {
  68. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, ""))
  69. return
  70. }
  71. if err := req.Validate(); err != nil {
  72. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrParamValidate, "参数验证失败:"))
  73. return
  74. }
  75. srv := devicesrv.NewDeviceService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  76. res, err := srv.SnDataList(c, req)
  77. if err != nil {
  78. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrQueryFailed, ""))
  79. return
  80. }
  81. core.WriteResponse(c, nil, res)
  82. }