sys_post.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. package apis
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. "github.com/gin-gonic/gin/binding"
  6. "github.com/go-admin-team/go-admin-core/sdk/api"
  7. "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
  8. _ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
  9. "go-admin/app/admin/models"
  10. "go-admin/app/admin/service"
  11. "go-admin/app/admin/service/dto"
  12. )
  13. type SysPost struct {
  14. api.Api
  15. }
  16. // GetPage
  17. // @Summary 岗位列表数据
  18. // @Description 获取JSON
  19. // @Tags 岗位
  20. // @Param postName query string false "postName"
  21. // @Param postCode query string false "postCode"
  22. // @Param postId query string false "postId"
  23. // @Param status query string false "status"
  24. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  25. // @Router /api/v1/post [get]
  26. // @Security Bearer
  27. func (e SysPost) GetPage(c *gin.Context) {
  28. s := service.SysPost{}
  29. req :=dto.SysPostPageReq{}
  30. err := e.MakeContext(c).
  31. MakeOrm().
  32. Bind(&req, binding.Form).
  33. MakeService(&s.Service).
  34. Errors
  35. if err != nil {
  36. e.Logger.Error(err)
  37. e.Error(500, err, err.Error())
  38. return
  39. }
  40. list := make([]models.SysPost, 0)
  41. var count int64
  42. err = s.GetPage(&req, &list, &count)
  43. if err != nil {
  44. e.Error(500, err, "查询失败")
  45. return
  46. }
  47. e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  48. }
  49. // Get
  50. // @Summary 获取岗位信息
  51. // @Description 获取JSON
  52. // @Tags 岗位
  53. // @Param id path int true "编码"
  54. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  55. // @Router /api/v1/post/{postId} [get]
  56. // @Security Bearer
  57. func (e SysPost) Get(c *gin.Context) {
  58. s := service.SysPost{}
  59. req :=dto.SysPostGetReq{}
  60. err := e.MakeContext(c).
  61. MakeOrm().
  62. Bind(&req, nil).
  63. MakeService(&s.Service).
  64. Errors
  65. if err != nil {
  66. e.Logger.Error(err)
  67. e.Error(500, err, err.Error())
  68. return
  69. }
  70. var object models.SysPost
  71. err = s.Get(&req, &object)
  72. if err != nil {
  73. e.Error(500, err, fmt.Sprintf("岗位信息获取失败!错误详情:%s", err.Error()))
  74. return
  75. }
  76. e.OK(object, "查询成功")
  77. }
  78. // Insert
  79. // @Summary 添加岗位
  80. // @Description 获取JSON
  81. // @Tags 岗位
  82. // @Accept application/json
  83. // @Product application/json
  84. // @Param data body dto.SysPostInsertReq true "data"
  85. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  86. // @Router /api/v1/post [post]
  87. // @Security Bearer
  88. func (e SysPost) Insert(c *gin.Context) {
  89. s := service.SysPost{}
  90. req :=dto.SysPostInsertReq{}
  91. err := e.MakeContext(c).
  92. MakeOrm().
  93. Bind(&req, binding.JSON).
  94. MakeService(&s.Service).
  95. Errors
  96. if err != nil {
  97. e.Logger.Error(err)
  98. e.Error(500, err, err.Error())
  99. return
  100. }
  101. req.SetCreateBy(user.GetUserId(c))
  102. err = s.Insert(&req)
  103. if err != nil {
  104. e.Error(500, err, fmt.Sprintf("新建岗位失败!错误详情:%s", err.Error()))
  105. return
  106. }
  107. e.OK(req.GetId(), "创建成功")
  108. }
  109. // Update
  110. // @Summary 修改岗位
  111. // @Description 获取JSON
  112. // @Tags 岗位
  113. // @Accept application/json
  114. // @Product application/json
  115. // @Param data body dto.SysPostUpdateReq true "body"
  116. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  117. // @Router /api/v1/post/{id} [put]
  118. // @Security Bearer
  119. func (e SysPost) Update(c *gin.Context) {
  120. s := service.SysPost{}
  121. req :=dto.SysPostUpdateReq{}
  122. err := e.MakeContext(c).
  123. MakeOrm().
  124. Bind(&req, binding.JSON, nil).
  125. MakeService(&s.Service).
  126. Errors
  127. if err != nil {
  128. e.Logger.Error(err)
  129. e.Error(500, err, err.Error())
  130. return
  131. }
  132. req.SetUpdateBy(user.GetUserId(c))
  133. err = s.Update(&req)
  134. if err != nil {
  135. e.Error(500, err, fmt.Sprintf("岗位更新失败!错误详情:%s", err.Error()))
  136. return
  137. }
  138. e.OK(req.GetId(), "更新成功")
  139. }
  140. // Delete
  141. // @Summary 删除岗位
  142. // @Description 删除数据
  143. // @Tags 岗位
  144. // @Param id body dto.SysPostDeleteReq true "请求参数"
  145. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  146. // @Router /api/v1/post [delete]
  147. // @Security Bearer
  148. func (e SysPost) Delete(c *gin.Context) {
  149. s := service.SysPost{}
  150. req :=dto.SysPostDeleteReq{}
  151. err := e.MakeContext(c).
  152. MakeOrm().
  153. Bind(&req, binding.JSON).
  154. MakeService(&s.Service).
  155. Errors
  156. if err != nil {
  157. e.Logger.Error(err)
  158. e.Error(500, err, err.Error())
  159. return
  160. }
  161. req.SetUpdateBy(user.GetUserId(c))
  162. err = s.Remove(&req)
  163. if err != nil {
  164. e.Error(500, err, fmt.Sprintf("岗位删除失败!错误详情:%s", err.Error()))
  165. return
  166. }
  167. e.OK(req.GetId(), "删除成功")
  168. }