123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- 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
- }
|