package controllers import ( "hongze/hongze_mobile_admin/models/tables/system" "strconv" ) // SystemCommon 系统模块 type SystemCommon struct { BaseAuth } // SellerList // @Title 获取未配置权限的管理员(根据部门、分组) // @Description 获取未配置权限的管理员(根据部门、分组)接口 // @Success 200 {object} response.DepartmentGroupSellersResp // @router /role/seller/list [get] func (this *SystemCommon) SellerList() { departmentList, err := system.GetDepartmentList() if err != nil { this.FailWithMessage("获取失败!", "获取部门失败,Err:"+err.Error()) return } departmentMap := make(map[int]*system.SysDepartmentList) for _, v := range departmentList { departmentMap[v.DepartmentId] = v } fullGroups, err := system.GetFullGroup() if err != nil { this.FailWithMessage("获取分组失败!", "获取分组失败,Err:"+err.Error()) return } fullGroupMap := make(map[int]*system.SysFullGroup) for _, v := range fullGroups { fullGroupMap[v.GroupId] = v } var list []system.DepartmentGroupSellers departmentListMap := make(map[int][]system.DepartmentGroupSellers) groupListMap := make(map[int][]system.DepartmentGroupSellers) teamListMap := make(map[int][]system.DepartmentGroupSellers) departmentHasMap := make(map[int]bool) groupHasMap := make(map[int]bool) teamHasMap := make(map[int]bool) condition := " and enabled = 1 " sellerList, err := system.GetSysUserItems(condition, []interface{}{}) if err != nil { this.FailWithMessage("获取管理账号失败!", "获取管理账号失败,Err:"+err.Error()) return } for _, v := range sellerList { tmp := system.DepartmentGroupSellers{ AdminId: strconv.Itoa(v.AdminId), RealName: v.RealName, } if v.GroupId > 0 { if groupInfo, ok := fullGroupMap[v.GroupId]; ok { if groupInfo.ParentId > 0 { teamListMap[v.GroupId] = append(teamListMap[v.GroupId], tmp) } else { groupListMap[groupInfo.GroupId] = append(groupListMap[groupInfo.GroupId], tmp) } } } else { departmentListMap[v.DepartmentId] = append(departmentListMap[v.DepartmentId], tmp) } } for _, groupInfo := range fullGroups { var team1 system.DepartmentGroupSellers //处理小组 if groupInfo.ParentId > 0 { if _, ok2 := teamHasMap[groupInfo.GroupId]; !ok2 { if len(teamListMap[groupInfo.GroupId]) > 0 { team1 = system.DepartmentGroupSellers{ AdminId: "team_" + strconv.Itoa(groupInfo.GroupId), RealName: groupInfo.GroupName, ChildrenList: teamListMap[groupInfo.GroupId], } teamHasMap[groupInfo.GroupId] = true groupListMap[groupInfo.ParentId] = append(groupListMap[groupInfo.ParentId], team1) } } } } for _, groupInfo := range fullGroups { var group1 system.DepartmentGroupSellers //处理大组 if groupInfo.ParentId == 0 { if _, ok2 := groupHasMap[groupInfo.GroupId]; !ok2 { if len(groupListMap[groupInfo.GroupId]) > 0 { group1 = system.DepartmentGroupSellers{ AdminId: "group_" + strconv.Itoa(groupInfo.GroupId), RealName: groupInfo.GroupName, ChildrenList: groupListMap[groupInfo.GroupId], } groupHasMap[groupInfo.GroupId] = true departmentListMap[groupInfo.DepartmentId] = append(departmentListMap[groupInfo.DepartmentId], group1) } } } } for _, groupInfo := range departmentList { var department1 system.DepartmentGroupSellers //处理部门 if _, ok1 := departmentHasMap[groupInfo.DepartmentId]; !ok1 { if len(departmentListMap[groupInfo.DepartmentId]) > 0 { department1 = system.DepartmentGroupSellers{ AdminId: "department_" + strconv.Itoa(groupInfo.DepartmentId), RealName: groupInfo.DepartmentName, ChildrenList: departmentListMap[groupInfo.DepartmentId], } departmentHasMap[groupInfo.DepartmentId] = true list = append(list, department1) } } } resp := new(system.DepartmentGroupSellersResp) resp.List = list this.OkDetailed(resp, "获取成功") return }