warehouse.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. package controller
  2. import (
  3. "cold-logistics/app/admin/model"
  4. "cold-logistics/app/admin/service"
  5. "cold-logistics/app/admin/service/dto"
  6. "cold-logistics/common/actions"
  7. "github.com/gin-gonic/gin"
  8. "github.com/gin-gonic/gin/binding"
  9. "gogs.baozhida.cn/zoie/OAuth-core/api"
  10. "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/user"
  11. _ "gogs.baozhida.cn/zoie/OAuth-core/pkg/response"
  12. )
  13. type WarehouseController struct {
  14. api.Api
  15. }
  16. // GetPage 获取仓库列表
  17. // @Summary 获取仓库列表
  18. // @Description 获取仓库列表
  19. // @Tags 仓库
  20. // @Param name query string false "仓库名称"
  21. // @Param sn query string false "仓库关联sn"
  22. // @Param status query string false "状态:1-停用 2-启用"
  23. // @Param isBind query bool false "是否绑定仓管"
  24. // @Param pageSize query int false "页条数"
  25. // @Param page query int false "页码"
  26. // @Success 200 {object} response.Response{data=response.Page{list=[]model.Warehouse}} "{"code": 200, "data": [...]}"
  27. // @Router /api/warehouse [get]
  28. // @Security Bearer
  29. func (e WarehouseController) GetPage(c *gin.Context) {
  30. s := service.Warehouse{}
  31. req := dto.WarehouseGetPageReq{}
  32. err := e.MakeContext(c).
  33. MakeOrm().
  34. Bind(&req, binding.Query).
  35. MakeService(&s.Service).
  36. Errors
  37. if err != nil {
  38. e.Logger.Error(err)
  39. e.Error(500, err, err.Error())
  40. return
  41. }
  42. //数据权限检查
  43. p := actions.GetPermissionFromContext(c)
  44. list := make([]model.Warehouse, 0)
  45. var count int64
  46. err = s.GetPage(&req, &list, &count, p)
  47. if err != nil {
  48. e.Error(500, err, err.Error())
  49. return
  50. }
  51. e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  52. }
  53. // Get 通过id获取仓库
  54. // @Summary 通过id获取仓库
  55. // @Description 通过id获取仓库
  56. // @Tags 仓库
  57. // @Param id path string true "仓库id"
  58. // @Success 200 {object} response.Response{data=model.Warehouse} "{"code": 200, "data": [...]}"
  59. // @Router /api/warehouse/{id} [get]
  60. // @Security Bearer
  61. func (e WarehouseController) Get(c *gin.Context) {
  62. s := service.Warehouse{}
  63. req := dto.WarehouseGetReq{}
  64. err := e.MakeContext(c).
  65. MakeOrm().
  66. Bind(&req, nil).
  67. MakeService(&s.Service).
  68. Errors
  69. if err != nil {
  70. e.Logger.Error(err)
  71. e.Error(500, err, err.Error())
  72. return
  73. }
  74. var object model.Warehouse
  75. p := actions.GetPermissionFromContext(c)
  76. //数据权限检查
  77. err = s.Get(&req, &object, p)
  78. if err != nil {
  79. e.Error(500, err, err.Error())
  80. return
  81. }
  82. e.OK(object, "查询成功")
  83. }
  84. // Insert 添加仓库
  85. // @Summary 添加仓库
  86. // @Description 添加仓库
  87. // @Tags 仓库
  88. // @Accept application/json
  89. // @Product application/json
  90. // @Param data body dto.WarehouseInsertReq true "data"
  91. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  92. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  93. // @Router /api/warehouse [post]
  94. // @Security Bearer
  95. func (e WarehouseController) Insert(c *gin.Context) {
  96. s := service.Warehouse{}
  97. req := dto.WarehouseInsertReq{}
  98. err := e.MakeContext(c).
  99. MakeOrm().
  100. Bind(&req, binding.JSON).
  101. MakeService(&s.Service).
  102. Errors
  103. if err != nil {
  104. e.Logger.Error(err)
  105. e.Error(500, err, err.Error())
  106. return
  107. }
  108. p := actions.GetPermissionFromContext(c)
  109. // 设置创建人
  110. req.SetCreateBy(user.GetUserId(c))
  111. req.SetDeptId(p.DeptId)
  112. err = s.Insert(&req, p)
  113. if err != nil {
  114. e.Error(500, err, err.Error())
  115. return
  116. }
  117. e.OK(req.GetId(), "添加成功")
  118. }
  119. // Update 修改仓库
  120. // @Summary 修改仓库
  121. // @Description 修改仓库
  122. // @Tags 仓库
  123. // @Accept application/json
  124. // @Product application/json
  125. // @Param data body dto.WarehouseUpdateReq true "body"
  126. // @Success 200 {string} string "{"code": 200, "message": "修改成功"}"
  127. // @Success 200 {string} string "{"code": -1, "message": "修改失败"}"
  128. // @Router /api/warehouse [put]
  129. // @Security Bearer
  130. func (e WarehouseController) Update(c *gin.Context) {
  131. s := service.Warehouse{}
  132. req := dto.WarehouseUpdateReq{}
  133. err := e.MakeContext(c).
  134. MakeOrm().
  135. Bind(&req).
  136. MakeService(&s.Service).
  137. Errors
  138. if err != nil {
  139. e.Logger.Error(err)
  140. e.Error(500, err, err.Error())
  141. return
  142. }
  143. p := actions.GetPermissionFromContext(c)
  144. req.SetUpdateBy(user.GetUserId(c))
  145. err = s.Update(&req, p)
  146. if err != nil {
  147. e.Error(500, err, err.Error())
  148. return
  149. }
  150. e.OK(req.GetId(), "修改成功")
  151. }
  152. // Delete 删除仓库
  153. // @Summary 删除仓库
  154. // @Description 删除仓库
  155. // @Tags 仓库
  156. // @Accept application/json
  157. // @Product application/json
  158. // @Param data body dto.WarehouseDeleteReq true "body"
  159. // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
  160. // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
  161. // @Router /api/warehouse [delete]
  162. // @Security Bearer
  163. func (e WarehouseController) Delete(c *gin.Context) {
  164. s := service.Warehouse{}
  165. req := dto.WarehouseDeleteReq{}
  166. err := e.MakeContext(c).
  167. MakeOrm().
  168. Bind(&req, binding.JSON, nil).
  169. MakeService(&s.Service).
  170. Errors
  171. if err != nil {
  172. e.Logger.Error(err)
  173. e.Error(500, err, err.Error())
  174. return
  175. }
  176. //数据权限检查
  177. p := actions.GetPermissionFromContext(c)
  178. err = s.Remove(&req, p)
  179. if err != nil {
  180. e.Error(500, err, err.Error())
  181. return
  182. }
  183. e.OK(req.GetId(), "删除成功")
  184. }
  185. // BatchInsert 批量添加仓库
  186. // @Summary 批量添加仓库
  187. // @Description 批量添加仓库
  188. // @Tags 仓库
  189. // @Accept application/json
  190. // @Product application/json
  191. // @Param data body dto.WarehouseBatchInsertReq true "data"
  192. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  193. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  194. // @Router /api/warehouse/import [post]
  195. // @Security Bearer
  196. func (e WarehouseController) BatchInsert(c *gin.Context) {
  197. s := service.Warehouse{}
  198. req := dto.WarehouseBatchInsertReq{}
  199. err := e.MakeContext(c).
  200. MakeOrm().
  201. Bind(&req, binding.JSON).
  202. MakeService(&s.Service).
  203. Errors
  204. if err != nil {
  205. e.Logger.Error(err)
  206. e.Error(500, err, err.Error())
  207. return
  208. }
  209. p := actions.GetPermissionFromContext(c)
  210. // 设置创建人
  211. req.SetCreateBy(user.GetUserId(c))
  212. req.SetDeptId(p.DeptId)
  213. err = s.BatchInsert(&req)
  214. if err != nil {
  215. e.Error(500, err, err.Error())
  216. return
  217. }
  218. e.OK(nil, "添加成功")
  219. }