system.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package controllers
  2. import (
  3. "hongze/hongze_mobile_admin/models/tables/system"
  4. "strconv"
  5. )
  6. // SystemCommon 系统模块
  7. type SystemCommon struct {
  8. BaseAuth
  9. }
  10. // SellerList
  11. // @Title 获取未配置权限的管理员(根据部门、分组)
  12. // @Description 获取未配置权限的管理员(根据部门、分组)接口
  13. // @Success 200 {object} response.DepartmentGroupSellersResp
  14. // @router /role/seller/list [get]
  15. func (this *SystemCommon) SellerList() {
  16. departmentList, err := system.GetDepartmentList()
  17. if err != nil {
  18. this.FailWithMessage("获取失败!", "获取部门失败,Err:"+err.Error())
  19. return
  20. }
  21. departmentMap := make(map[int]*system.SysDepartmentList)
  22. for _, v := range departmentList {
  23. departmentMap[v.DepartmentId] = v
  24. }
  25. fullGroups, err := system.GetFullGroup()
  26. if err != nil {
  27. this.FailWithMessage("获取分组失败!", "获取分组失败,Err:"+err.Error())
  28. return
  29. }
  30. fullGroupMap := make(map[int]*system.SysFullGroup)
  31. for _, v := range fullGroups {
  32. fullGroupMap[v.GroupId] = v
  33. }
  34. var list []system.DepartmentGroupSellers
  35. departmentListMap := make(map[int][]system.DepartmentGroupSellers)
  36. groupListMap := make(map[int][]system.DepartmentGroupSellers)
  37. teamListMap := make(map[int][]system.DepartmentGroupSellers)
  38. departmentHasMap := make(map[int]bool)
  39. groupHasMap := make(map[int]bool)
  40. teamHasMap := make(map[int]bool)
  41. condition := " and enabled = 1 "
  42. sellerList, err := system.GetSysUserItems(condition, []interface{}{})
  43. if err != nil {
  44. this.FailWithMessage("获取管理账号失败!", "获取管理账号失败,Err:"+err.Error())
  45. return
  46. }
  47. for _, v := range sellerList {
  48. tmp := system.DepartmentGroupSellers{
  49. AdminId: strconv.Itoa(v.AdminId),
  50. RealName: v.RealName,
  51. }
  52. if v.GroupId > 0 {
  53. if groupInfo, ok := fullGroupMap[v.GroupId]; ok {
  54. if groupInfo.ParentId > 0 {
  55. teamListMap[v.GroupId] = append(teamListMap[v.GroupId], tmp)
  56. } else {
  57. groupListMap[groupInfo.GroupId] = append(groupListMap[groupInfo.GroupId], tmp)
  58. }
  59. }
  60. } else {
  61. departmentListMap[v.DepartmentId] = append(departmentListMap[v.DepartmentId], tmp)
  62. }
  63. }
  64. for _, groupInfo := range fullGroups {
  65. var team1 system.DepartmentGroupSellers
  66. //处理小组
  67. if groupInfo.ParentId > 0 {
  68. if _, ok2 := teamHasMap[groupInfo.GroupId]; !ok2 {
  69. if len(teamListMap[groupInfo.GroupId]) > 0 {
  70. team1 = system.DepartmentGroupSellers{
  71. AdminId: "team_" + strconv.Itoa(groupInfo.GroupId),
  72. RealName: groupInfo.GroupName,
  73. ChildrenList: teamListMap[groupInfo.GroupId],
  74. }
  75. teamHasMap[groupInfo.GroupId] = true
  76. groupListMap[groupInfo.ParentId] = append(groupListMap[groupInfo.ParentId], team1)
  77. }
  78. }
  79. }
  80. }
  81. for _, groupInfo := range fullGroups {
  82. var group1 system.DepartmentGroupSellers
  83. //处理大组
  84. if groupInfo.ParentId == 0 {
  85. if _, ok2 := groupHasMap[groupInfo.GroupId]; !ok2 {
  86. if len(groupListMap[groupInfo.GroupId]) > 0 {
  87. group1 = system.DepartmentGroupSellers{
  88. AdminId: "group_" + strconv.Itoa(groupInfo.GroupId),
  89. RealName: groupInfo.GroupName,
  90. ChildrenList: groupListMap[groupInfo.GroupId],
  91. }
  92. groupHasMap[groupInfo.GroupId] = true
  93. departmentListMap[groupInfo.DepartmentId] = append(departmentListMap[groupInfo.DepartmentId], group1)
  94. }
  95. }
  96. }
  97. }
  98. for _, groupInfo := range departmentList {
  99. var department1 system.DepartmentGroupSellers
  100. //处理部门
  101. if _, ok1 := departmentHasMap[groupInfo.DepartmentId]; !ok1 {
  102. if len(departmentListMap[groupInfo.DepartmentId]) > 0 {
  103. department1 = system.DepartmentGroupSellers{
  104. AdminId: "department_" + strconv.Itoa(groupInfo.DepartmentId),
  105. RealName: groupInfo.DepartmentName,
  106. ChildrenList: departmentListMap[groupInfo.DepartmentId],
  107. }
  108. departmentHasMap[groupInfo.DepartmentId] = true
  109. list = append(list, department1)
  110. }
  111. }
  112. }
  113. resp := new(system.DepartmentGroupSellersResp)
  114. resp.List = list
  115. this.OkDetailed(resp, "获取成功")
  116. return
  117. }