package controllers import ( "eta/eta_forum_admin/models" "eta/eta_forum_admin/models/system" "eta/eta_forum_admin/utils" "strconv" ) type AdminController struct { BaseAuthController } // GetBusinessAdmin // @Title 获取机构用户 // @Description 获取机构用户 // @Success 200 {object} models.ChartInfoDetailResp // @router /business/admin [get] func (this *AdminController) GetBusinessAdmin() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } // 查询所有机构 /*ob := new(system.EtaBusiness) companyList, err := ob.GetItemsByCondition("", make([]interface{}, 0), []string{}, "") if err != nil { br.Msg = "获取机构信息失败" br.ErrMsg = err.Error() return }*/ list := make([]*system.BusinessAdmin, 0) // todo 查询上传图表的所有用户ID creators, err := models.GetChartCreators() if err != nil { br.Msg = "获取上传图表的所有用户信息失败" br.ErrMsg = err.Error() return } if len(creators) == 0 { var resp system.BusinessAdminResp resp.List = list br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp return } //查询机构下的用户 admin := new(system.Admin) cond := ` AND admin_id in (` + utils.GetOrmInReplace(len(creators)) + `)` pars := make([]interface{}, 0) pars = append(pars, creators) adminList, err := admin.GetItemsByCondition(cond, pars, []string{}, "") if err != nil { br.Msg = "获取机构用户失败" br.ErrMsg = err.Error() return } companyMap := make(map[string][]*system.BusinessAdmin) if len(adminList) > 0 { for _, v := range adminList { tmp := &system.BusinessAdmin{ AdminId: strconv.Itoa(v.AdminId), RealName: v.RealName, } companyMap[v.BusinessCode] = append(companyMap[v.BusinessCode], tmp) } } companyList := make([]*system.HzEtaBusiness, 0) hzCompany := new(system.HzEtaBusiness) hzCompany.BusinessName = utils.HzCompanyName hzCompany.BusinessCode = utils.HzBusinessCodeRelease companyList = append(companyList, hzCompany) if len(companyList) > 0 { for _, v := range companyList { tmp := &system.BusinessAdmin{ AdminId: v.BusinessCode, RealName: v.BusinessName, } l, ok := companyMap[v.BusinessCode] if ok { tmp.ChildrenList = l list = append(list, tmp) } } } var resp system.BusinessAdminResp resp.List = list br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp }