car.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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/carsrv"
  6. "Cold_Logistic/internal/server/infra/dao"
  7. "github.com/gin-gonic/gin"
  8. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/core"
  9. "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/errors"
  10. )
  11. // carPage
  12. // @Tags 后台-车辆管理
  13. // @Summary 车辆列表
  14. // @Success 200 {object} swagger.PageListResponse "成功响应的结构体"
  15. // @Param req body swagger.CarPageReqVO true "请求参数"
  16. // @Accept application/json
  17. // @Router /manage/car/page [post]
  18. func (api Api) carPage(c *gin.Context) {
  19. req := carsrv.CarPageReqVO{}
  20. if err := c.BindJSON(&req); err != nil {
  21. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, ""))
  22. return
  23. }
  24. srv := carsrv.NewCarService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  25. res, err := srv.CarPage(c, req)
  26. if err != nil {
  27. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrQueryFailed, ""))
  28. return
  29. }
  30. core.WriteResponse(c, nil, res)
  31. }
  32. // addCar
  33. // @Tags 后台-车辆管理
  34. // @Summary 添加车辆
  35. // @Success 200 {object} carsrv.CarIdRespVO "成功响应的结构体"
  36. // @Param req body carsrv.AddCarReqVO true "请求参数"
  37. // @Accept application/json
  38. // @Router /manage/car/add [post]
  39. func (api Api) addCar(c *gin.Context) {
  40. req := carsrv.AddCarReqVO{}
  41. if err := c.BindJSON(&req); err != nil {
  42. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, ""))
  43. return
  44. }
  45. if err := req.Validate(); err != nil {
  46. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrParamValidate, "参数验证失败:"))
  47. return
  48. }
  49. srv := carsrv.NewCarService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  50. res, err := srv.AddCar(c, req)
  51. if err != nil {
  52. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrSaveFailed, ""))
  53. return
  54. }
  55. core.WriteResponse(c, nil, res)
  56. }
  57. // updateCar
  58. // @Tags 后台-车辆管理
  59. // @Summary 修改车辆
  60. // @Success 200 {object} carsrv.CarIdRespVO "成功响应的结构体"
  61. // @Param req body carsrv.UpdateCarReqVO true "请求参数"
  62. // @Accept application/json
  63. // @Router /manage/car/update [post]
  64. func (api Api) updateCar(c *gin.Context) {
  65. req := carsrv.UpdateCarReqVO{}
  66. if err := c.BindJSON(&req); err != nil {
  67. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, ""))
  68. return
  69. }
  70. if err := req.Validate(); err != nil {
  71. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrParamValidate, "参数验证失败:"))
  72. return
  73. }
  74. srv := carsrv.NewCarService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  75. res, err := srv.UpdateCar(c, req)
  76. if err != nil {
  77. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrSaveFailed, ""))
  78. return
  79. }
  80. core.WriteResponse(c, nil, res)
  81. }
  82. // updateCar
  83. // @Tags 后台-车辆管理
  84. // @Summary 车辆既往司机
  85. // @Success 200 {object} swagger.ListResponse "成功响应的结构体"
  86. // @Param req body carsrv.DriverLogReqVO true "请求参数"
  87. // @Accept application/json
  88. // @Router /manage/car/driverLog [post]
  89. func (api Api) driverLog(c *gin.Context) {
  90. req := carsrv.DriverLogReqVO{}
  91. if err := c.BindJSON(&req); err != nil {
  92. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, ""))
  93. return
  94. }
  95. if err := req.Validate(); err != nil {
  96. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrParamValidate, "参数验证失败:"))
  97. return
  98. }
  99. srv := carsrv.NewCarService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  100. res, err := srv.DriverLog(c, req)
  101. if err != nil {
  102. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrQueryFailed, ""))
  103. return
  104. }
  105. core.WriteResponse(c, nil, res)
  106. }