ice_locker.go 6.0 KB

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