warehouse.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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/warehousesrv"
  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. // warehousePage
  12. // @Tags 后台-仓库管理
  13. // @Summary 仓库列表
  14. // @Success 200 {object} swagger.PageListResponse "成功响应的结构体"
  15. // @Param req body swagger.WarehousePageReqVO true "请求参数"
  16. // @Accept application/json
  17. // @Router /manage/warehouse/page [post]
  18. func (api Api) warehousePage(c *gin.Context) {
  19. req := warehousesrv.WarehousePageReqVO{}
  20. if err := c.BindJSON(&req); err != nil {
  21. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, ""))
  22. return
  23. }
  24. srv := warehousesrv.NewWarehouseService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  25. res, err := srv.WarehousePage(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. // addWarehouse
  33. // @Tags 后台-仓库管理
  34. // @Summary 添加仓库
  35. // @Success 200 {object} warehousesrv.WarehouseIdRespVO "成功响应的结构体"
  36. // @Param req body warehousesrv.AddWarehouseReqVO true "请求参数"
  37. // @Accept application/json
  38. // @Router /manage/warehouse/add [post]
  39. func (api Api) addWarehouse(c *gin.Context) {
  40. req := warehousesrv.AddWarehouseReqVO{}
  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 := warehousesrv.NewWarehouseService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  50. res, err := srv.AddWarehouse(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. // updateWarehouse
  58. // @Tags 后台-仓库管理
  59. // @Summary 修改仓库
  60. // @Success 200 {object} warehousesrv.WarehouseIdRespVO "成功响应的结构体"
  61. // @Param req body warehousesrv.UpdateWarehouseReqVO true "请求参数"
  62. // @Accept application/json
  63. // @Router /manage/warehouse/update [post]
  64. func (api Api) updateWarehouse(c *gin.Context) {
  65. req := warehousesrv.UpdateWarehouseReqVO{}
  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 := warehousesrv.NewWarehouseService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  75. res, err := srv.UpdateWarehouse(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. // updateWarehouse
  83. // @Tags 后台-仓库管理
  84. // @Summary 仓库订单列表
  85. // @Success 200 {object} swagger.PageListResponse "成功响应的结构体"
  86. // @Param req body swagger.WarehousePageReqVO true "请求参数"
  87. // @Accept application/json
  88. // @Router /manage/warehouse/orderPage [post]
  89. func (api Api) warehouseOrder(c *gin.Context) {
  90. req := warehousesrv.WarehouseOrderReqVO{}
  91. if err := c.ShouldBindJSON(&req); err != nil {
  92. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrBindJSON, ""))
  93. return
  94. }
  95. srv := warehousesrv.NewWarehouseService(dao.NewDataStore(global.CommonConnectRepoInst.StoreDB))
  96. res, err := srv.WarehouseOrder(c, req)
  97. if err != nil {
  98. core.WriteErrResponse(c, errors.WithCodeOnce(err, codex.ErrQueryFailed, ""))
  99. return
  100. }
  101. core.WriteResponse(c, nil, res)
  102. }