sys_team.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/models"
  5. "eta_gn/eta_api/models/system"
  6. "eta_gn/eta_api/utils"
  7. "strings"
  8. "time"
  9. )
  10. // 部门组
  11. type SysTeamController struct {
  12. BaseAuthController
  13. }
  14. // @Title 新增分组
  15. // @Description 新增分组接口
  16. // @Param request body system.SysTeamAddReq true "type json string"
  17. // @Success 200 新增成功
  18. // @router /team/add [post]
  19. func (this *SysTeamController) Add() {
  20. br := new(models.BaseResponse).Init()
  21. defer func() {
  22. this.Data["json"] = br
  23. this.ServeJSON()
  24. }()
  25. var req system.SysTeamAddReq
  26. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  27. if err != nil {
  28. br.Msg = "参数解析异常!"
  29. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  30. return
  31. }
  32. if req.GroupId <= 0 {
  33. br.Msg = "请选择部门"
  34. br.ErrMsg = "大组ID不可为空"
  35. return
  36. }
  37. if req.TeamName == "" {
  38. br.Msg = "分组名称不能为空"
  39. return
  40. }
  41. teamNameArr := strings.Split(req.TeamName, ",")
  42. for _, v := range teamNameArr {
  43. count, err := system.GetSysTeamCount(req.GroupId, v)
  44. if err != nil {
  45. br.Msg = "获取数据失败"
  46. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  47. return
  48. }
  49. if count <= 0 {
  50. item := new(system.SysGroup)
  51. item.GroupName = v
  52. item.DepartmentId = req.DepartmentId
  53. item.ParentId = req.GroupId
  54. item.CreateTime = time.Now()
  55. _, e := system.AddSysGroup(item)
  56. if e != nil {
  57. br.Msg = "新增失败"
  58. br.ErrMsg = "新增失败,Err:" + e.Error()
  59. return
  60. }
  61. }
  62. }
  63. br.Ret = 200
  64. br.Success = true
  65. br.Msg = "新增成功"
  66. }
  67. // @Title 修改分组
  68. // @Description 修改分组接口
  69. // @Param request body system.SysTeamEditReq true "type json string"
  70. // @Success 200 修改成功
  71. // @router /team/edit [post]
  72. func (this *SysTeamController) Edit() {
  73. br := new(models.BaseResponse).Init()
  74. defer func() {
  75. this.Data["json"] = br
  76. this.ServeJSON()
  77. }()
  78. var req system.SysTeamEditReq
  79. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  80. if err != nil {
  81. br.Msg = "参数解析异常!"
  82. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  83. return
  84. }
  85. if req.TeamId <= 0 {
  86. br.Msg = "参数错误"
  87. br.ErrMsg = "参数错误,GroupId 小于等于0 "
  88. return
  89. }
  90. if req.TeamName == "" {
  91. br.Msg = "分组名称不能为空"
  92. return
  93. }
  94. item, err := system.GetSysTeamByName(req.TeamName)
  95. if err != nil && !utils.IsErrNoRow(err) {
  96. br.Msg = "获取数据失败"
  97. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  98. return
  99. }
  100. if item != nil && item.GroupId > 0 {
  101. if item.GroupId != req.TeamId {
  102. br.Msg = "名称已存在,请重新输入"
  103. return
  104. }
  105. }
  106. err = system.ModifySysTeam(req.TeamName, req.TeamId)
  107. if err != nil {
  108. br.Msg = "修改失败"
  109. br.ErrMsg = "修改失败,Err:" + err.Error()
  110. return
  111. }
  112. br.Ret = 200
  113. br.Success = true
  114. br.Msg = "修改成功"
  115. }
  116. // @Title 删除分组
  117. // @Description 删除分组接口
  118. // @Param request body system.SysTeamDeleteReq true "type json string"
  119. // @Success 200 删除成功
  120. // @router /team/delete [post]
  121. func (this *SysTeamController) Delete() {
  122. br := new(models.BaseResponse).Init()
  123. defer func() {
  124. this.Data["json"] = br
  125. this.ServeJSON()
  126. }()
  127. var req system.SysTeamDeleteReq
  128. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  129. if err != nil {
  130. br.Msg = "参数解析异常!"
  131. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  132. return
  133. }
  134. if req.TeamId <= 0 {
  135. br.Msg = "参数错误"
  136. br.ErrMsg = "参数错误,GroupId 小于等于0 "
  137. return
  138. }
  139. err = system.DeleteSysGroup(req.TeamId)
  140. if err != nil {
  141. br.Msg = "删除失败"
  142. br.ErrMsg = "删除失败,Err:" + err.Error()
  143. return
  144. }
  145. err = system.ClearSysUserTeam(req.TeamId)
  146. if err != nil {
  147. br.Msg = "删除失败"
  148. br.ErrMsg = "删除失败,情况分组失败,Err:" + err.Error()
  149. return
  150. }
  151. br.Ret = 200
  152. br.Success = true
  153. br.Msg = "删除成功"
  154. }