dept.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package system
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/gin-gonic/gin/binding"
  5. "device-manage/app/admin/models"
  6. "device-manage/tools"
  7. "device-manage/tools/app"
  8. "device-manage/tools/app/msg"
  9. )
  10. // @Summary 分页部门列表数据
  11. // @Description 分页列表
  12. // @Tags 部门
  13. // @Param name query string false "name"
  14. // @Param id query string false "id"
  15. // @Param position query string false "position"
  16. // @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
  17. // @Router /api/v1/deptList [get]
  18. // @Security Bearer
  19. func GetDeptList(c *gin.Context) {
  20. var Dept models.SysDept
  21. Dept.DeptName = c.Request.FormValue("deptName")
  22. Dept.Status = c.Request.FormValue("status")
  23. Dept.DeptId, _ = tools.StringToInt(c.Request.FormValue("deptId"))
  24. Dept.DataScope = tools.GetUserIdStr(c)
  25. result, err := Dept.SetDept(true)
  26. tools.HasError(err, "抱歉未找到相关信息", -1)
  27. app.OK(c, result, "")
  28. }
  29. func GetDeptTree(c *gin.Context) {
  30. var Dept models.SysDept
  31. Dept.DeptName = c.Request.FormValue("deptName")
  32. Dept.Status = c.Request.FormValue("status")
  33. Dept.DeptId, _ = tools.StringToInt(c.Request.FormValue("deptId"))
  34. result, err := Dept.SetDept(false)
  35. tools.HasError(err, "抱歉未找到相关信息", -1)
  36. app.OK(c, result, "")
  37. }
  38. // @Summary 部门列表数据
  39. // @Description 获取JSON
  40. // @Tags 部门
  41. // @Param deptId path string false "deptId"
  42. // @Param position query string false "position"
  43. // @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
  44. // @Router /api/v1/dept/{deptId} [get]
  45. // @Security Bearer
  46. func GetDept(c *gin.Context) {
  47. var Dept models.SysDept
  48. Dept.DeptId, _ = tools.StringToInt(c.Param("deptId"))
  49. Dept.DataScope = tools.GetUserIdStr(c)
  50. result, err := Dept.Get()
  51. tools.HasError(err, msg.NotFound, 404)
  52. app.OK(c, result, msg.GetSuccess)
  53. }
  54. // @Summary 添加部门
  55. // @Description 获取JSON
  56. // @Tags 部门
  57. // @Accept application/json
  58. // @Product application/json
  59. // @Param data body models.SysDept true "data"
  60. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  61. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  62. // @Router /api/v1/dept [post]
  63. // @Security Bearer
  64. func InsertDept(c *gin.Context) {
  65. var data models.SysDept
  66. err := c.BindWith(&data, binding.JSON)
  67. tools.HasError(err, "", 500)
  68. data.CreateBy = tools.GetUserIdStr(c)
  69. result, err := data.Create()
  70. tools.HasError(err, "", -1)
  71. app.OK(c, result, msg.CreatedSuccess)
  72. }
  73. // @Summary 修改部门
  74. // @Description 获取JSON
  75. // @Tags 部门
  76. // @Accept application/json
  77. // @Product application/json
  78. // @Param id path int true "id"
  79. // @Param data body models.SysDept true "body"
  80. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  81. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  82. // @Router /api/v1/dept [put]
  83. // @Security Bearer
  84. func UpdateDept(c *gin.Context) {
  85. var data models.SysDept
  86. err := c.BindJSON(&data)
  87. tools.HasError(err, "", -1)
  88. data.UpdateBy = tools.GetUserIdStr(c)
  89. result, err := data.Update(data.DeptId)
  90. tools.HasError(err, "", -1)
  91. app.OK(c, result, msg.UpdatedSuccess)
  92. }
  93. // @Summary 删除部门
  94. // @Description 删除数据
  95. // @Tags 部门
  96. // @Param id path int true "id"
  97. // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
  98. // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
  99. // @Router /api/v1/dept/{id} [delete]
  100. func DeleteDept(c *gin.Context) {
  101. var data models.SysDept
  102. id, err := tools.StringToInt(c.Param("id"))
  103. _, err = data.Delete(id)
  104. tools.HasError(err, "删除失败", 500)
  105. app.OK(c, "", msg.DeletedSuccess)
  106. }
  107. func GetDeptTreeRoleselect(c *gin.Context) {
  108. var Dept models.SysDept
  109. var SysRole models.SysRole
  110. id, err := tools.StringToInt(c.Param("roleId"))
  111. SysRole.RoleId = id
  112. result, err := Dept.SetDeptLable()
  113. tools.HasError(err, msg.NotFound, -1)
  114. menuIds := make([]int, 0)
  115. if id != 0 {
  116. menuIds, err = SysRole.GetRoleDeptId()
  117. tools.HasError(err, "抱歉未找到相关信息", -1)
  118. }
  119. app.Custum(c, gin.H{
  120. "code": 200,
  121. "depts": result,
  122. "checkedKeys": menuIds,
  123. })
  124. }