gas_cylinder_spec.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 GasCylinderSpecController struct {
  14. api.Api
  15. }
  16. // GetPage 获取钢瓶规格列表
  17. // @Summary 获取钢瓶规格列表
  18. // @Description 获取钢瓶规格列表
  19. // @Tags 钢瓶规格
  20. // @Param name query string false "钢瓶规格名称"
  21. // @Success 200 {object} response.Response{data=response.Page{list=[]model.GasCylinderSpec}} "{"code": 200, "data": [...]}"
  22. // @Router /api/dispatch-cost [get]
  23. // @Security Bearer
  24. func (e GasCylinderSpecController) GetPage(c *gin.Context) {
  25. s := service.GasCylinderSpec{}
  26. req := dto.GasCylinderSpecGetPageReq{}
  27. err := e.MakeContext(c).
  28. MakeOrm().
  29. Bind(&req, binding.Query).
  30. MakeService(&s.Service).
  31. Errors
  32. if err != nil {
  33. e.Logger.Error(err)
  34. e.Error(500, err, err.Error())
  35. return
  36. }
  37. //数据权限检查
  38. p := actions.GetPermissionFromContext(c)
  39. list := make([]model.GasCylinderSpec, 0)
  40. var count int64
  41. err = s.GetPage(&req, &list, &count, p)
  42. if err != nil {
  43. e.Error(500, err, err.Error())
  44. return
  45. }
  46. e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  47. }
  48. // Get 通过id获取钢瓶规格
  49. // @Summary 通过id获取钢瓶规格
  50. // @Description 通过id获取钢瓶规格
  51. // @Tags 钢瓶规格
  52. // @Param id path string true "钢瓶规格id"
  53. // @Success 200 {object} response.Response{data=model.GasCylinderSpec} "{"code": 200, "data": [...]}"
  54. // @Router /api/dispatch-cost/{id} [get]
  55. // @Security Bearer
  56. func (e GasCylinderSpecController) Get(c *gin.Context) {
  57. s := service.GasCylinderSpec{}
  58. req := dto.GasCylinderSpecGetReq{}
  59. err := e.MakeContext(c).
  60. MakeOrm().
  61. Bind(&req, nil).
  62. MakeService(&s.Service).
  63. Errors
  64. if err != nil {
  65. e.Logger.Error(err)
  66. e.Error(500, err, err.Error())
  67. return
  68. }
  69. var object model.GasCylinderSpec
  70. p := actions.GetPermissionFromContext(c)
  71. //数据权限检查
  72. err = s.Get(&req, &object, p)
  73. if err != nil {
  74. e.Error(500, err, err.Error())
  75. return
  76. }
  77. e.OK(object, "查询成功")
  78. }
  79. // Insert 添加钢瓶规格
  80. // @Summary 添加钢瓶规格
  81. // @Description 添加钢瓶规格
  82. // @Tags 钢瓶规格
  83. // @Accept application/json
  84. // @Product application/json
  85. // @Param data body dto.GasCylinderSpecInsertReq true "data"
  86. // @Param pageSize query int false "页条数"
  87. // @Param page query int false "页码"
  88. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  89. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  90. // @Router /api/dispatch-cost [post]
  91. // @Security Bearer
  92. func (e GasCylinderSpecController) Insert(c *gin.Context) {
  93. s := service.GasCylinderSpec{}
  94. req := dto.GasCylinderSpecInsertReq{}
  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)
  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.GasCylinderSpecUpdateReq true "body"
  123. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  124. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  125. // @Router /api/dispatch-cost [put]
  126. // @Security Bearer
  127. func (e GasCylinderSpecController) Update(c *gin.Context) {
  128. s := service.GasCylinderSpec{}
  129. req := dto.GasCylinderSpecUpdateReq{}
  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.GasCylinderSpecDeleteReq true "body"
  156. // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
  157. // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
  158. // @Router /api/dispatch-cost [delete]
  159. // @Security Bearer
  160. func (e GasCylinderSpecController) Delete(c *gin.Context) {
  161. s := service.GasCylinderSpec{}
  162. req := dto.GasCylinderSpecDeleteReq{}
  163. userSvc := service.SysUser{}
  164. err := e.MakeContext(c).
  165. MakeOrm().
  166. Bind(&req, binding.JSON, nil).
  167. MakeService(&s.Service).
  168. MakeService(&userSvc.Service).
  169. Errors
  170. if err != nil {
  171. e.Logger.Error(err)
  172. e.Error(500, err, err.Error())
  173. return
  174. }
  175. //数据权限检查
  176. p := actions.GetPermissionFromContext(c)
  177. err = s.Remove(&req, p)
  178. if err != nil {
  179. e.Error(500, err, err.Error())
  180. return
  181. }
  182. e.OK(req.GetId(), "删除成功")
  183. }