post.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package system
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "device-manage/app/admin/models"
  5. "device-manage/tools"
  6. "device-manage/tools/app"
  7. )
  8. // @Summary 岗位列表数据
  9. // @Description 获取JSON
  10. // @Tags 岗位
  11. // @Param postName query string false "postName"
  12. // @Param postCode query string false "postCode"
  13. // @Param postId query string false "postId"
  14. // @Param status query string false "status"
  15. // @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
  16. // @Router /api/v1/post [get]
  17. // @Security Bearer
  18. func GetPostList(c *gin.Context) {
  19. var data models.Post
  20. var err error
  21. var pageSize = 10
  22. var pageIndex = 1
  23. if size := c.Request.FormValue("pageSize"); size != "" {
  24. pageSize, err = tools.StringToInt(size)
  25. }
  26. if index := c.Request.FormValue("pageIndex"); index != "" {
  27. pageIndex, err = tools.StringToInt(index)
  28. }
  29. id := c.Request.FormValue("postId")
  30. data.PostId, _ = tools.StringToInt(id)
  31. data.PostCode = c.Request.FormValue("postCode")
  32. data.PostName = c.Request.FormValue("postName")
  33. data.Status = c.Request.FormValue("status")
  34. data.DataScope = tools.GetUserIdStr(c)
  35. result, count, err := data.GetPage(pageSize, pageIndex)
  36. tools.HasError(err, "", -1)
  37. app.PageOK(c, result, count, pageIndex, pageSize, "")
  38. }
  39. // @Summary 获取岗位信息
  40. // @Description 获取JSON
  41. // @Tags 岗位
  42. // @Param postId path int true "postId"
  43. // @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
  44. // @Router /api/v1/post/{postId} [get]
  45. // @Security Bearer
  46. func GetPost(c *gin.Context) {
  47. var Post models.Post
  48. Post.PostId, _ = tools.StringToInt(c.Param("postId"))
  49. result, err := Post.Get()
  50. tools.HasError(err, "抱歉未找到相关信息", -1)
  51. app.OK(c, result, "")
  52. }
  53. // @Summary 添加岗位
  54. // @Description 获取JSON
  55. // @Tags 岗位
  56. // @Accept application/json
  57. // @Product application/json
  58. // @Param data body models.Post true "data"
  59. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  60. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  61. // @Router /api/v1/post [post]
  62. // @Security Bearer
  63. func InsertPost(c *gin.Context) {
  64. var data models.Post
  65. err := c.Bind(&data)
  66. data.CreateBy = tools.GetUserIdStr(c)
  67. tools.HasError(err, "", 500)
  68. result, err := data.Create()
  69. tools.HasError(err, "", -1)
  70. app.OK(c, result, "")
  71. }
  72. // @Summary 修改岗位
  73. // @Description 获取JSON
  74. // @Tags 岗位
  75. // @Accept application/json
  76. // @Product application/json
  77. // @Param data body models.Post true "body"
  78. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  79. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  80. // @Router /api/v1/post/ [put]
  81. // @Security Bearer
  82. func UpdatePost(c *gin.Context) {
  83. var data models.Post
  84. err := c.Bind(&data)
  85. data.UpdateBy = tools.GetUserIdStr(c)
  86. tools.HasError(err, "", -1)
  87. result, err := data.Update(data.PostId)
  88. tools.HasError(err, "", -1)
  89. app.OK(c, result, "修改成功")
  90. }
  91. // @Summary 删除岗位
  92. // @Description 删除数据
  93. // @Tags 岗位
  94. // @Param id path int true "id"
  95. // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
  96. // @Success 500 {string} string "{"code": 500, "message": "删除失败"}"
  97. // @Router /api/v1/post/{postId} [delete]
  98. func DeletePost(c *gin.Context) {
  99. var data models.Post
  100. data.UpdateBy = tools.GetUserIdStr(c)
  101. IDS := tools.IdsStrToIdsIntGroup("postId", c)
  102. result, err := data.BatchDelete(IDS)
  103. tools.HasError(err, "删除失败", 500)
  104. app.OK(c, result, "删除成功")
  105. }