sys_team.go 3.3 KB

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