gas_cylinder_spec.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 deptName 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. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  87. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  88. // @Router /api/dispatch-cost [post]
  89. // @Security Bearer
  90. func (e GasCylinderSpecController) Insert(c *gin.Context) {
  91. s := service.GasCylinderSpec{}
  92. req := dto.GasCylinderSpecInsertReq{}
  93. err := e.MakeContext(c).
  94. MakeOrm().
  95. Bind(&req, binding.JSON).
  96. MakeService(&s.Service).
  97. Errors
  98. if err != nil {
  99. e.Logger.Error(err)
  100. e.Error(500, err, err.Error())
  101. return
  102. }
  103. p := actions.GetPermissionFromContext(c)
  104. // 设置创建人
  105. req.SetCreateBy(user.GetUserId(c))
  106. req.SetDeptId(p.DeptId)
  107. err = s.Insert(&req)
  108. if err != nil {
  109. e.Error(500, err, err.Error())
  110. return
  111. }
  112. e.OK(req.GetId(), "创建成功")
  113. }
  114. // Update 修改派费
  115. // @Summary 修改派费
  116. // @Description 修改派费
  117. // @Tags 派费
  118. // @Accept application/json
  119. // @Product application/json
  120. // @Param data body dto.GasCylinderSpecUpdateReq true "body"
  121. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  122. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  123. // @Router /api/dispatch-cost [put]
  124. // @Security Bearer
  125. func (e GasCylinderSpecController) Update(c *gin.Context) {
  126. s := service.GasCylinderSpec{}
  127. req := dto.GasCylinderSpecUpdateReq{}
  128. err := e.MakeContext(c).
  129. MakeOrm().
  130. Bind(&req).
  131. MakeService(&s.Service).
  132. Errors
  133. if err != nil {
  134. e.Logger.Error(err)
  135. e.Error(500, err, err.Error())
  136. return
  137. }
  138. p := actions.GetPermissionFromContext(c)
  139. req.SetUpdateBy(user.GetUserId(c))
  140. err = s.Update(&req, p)
  141. if err != nil {
  142. e.Error(500, err, err.Error())
  143. return
  144. }
  145. e.OK(req.GetId(), "更新成功")
  146. }
  147. // Delete 删除派费
  148. // @Summary 删除派费
  149. // @Description 删除派费
  150. // @Tags 派费
  151. // @Accept application/json
  152. // @Product application/json
  153. // @Param data body dto.GasCylinderSpecDeleteReq true "body"
  154. // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
  155. // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
  156. // @Router /api/dispatch-cost [delete]
  157. // @Security Bearer
  158. func (e GasCylinderSpecController) Delete(c *gin.Context) {
  159. s := service.GasCylinderSpec{}
  160. req := dto.GasCylinderSpecDeleteReq{}
  161. userSvc := service.SysUser{}
  162. err := e.MakeContext(c).
  163. MakeOrm().
  164. Bind(&req, binding.JSON, nil).
  165. MakeService(&s.Service).
  166. MakeService(&userSvc.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. }