fill_gun.go 5.1 KB

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