admin.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package controllers
  2. import (
  3. "eta/eta_forum_admin/models"
  4. "eta/eta_forum_admin/models/system"
  5. "eta/eta_forum_admin/utils"
  6. "strconv"
  7. )
  8. type AdminController struct {
  9. BaseAuthController
  10. }
  11. // GetBusinessAdmin
  12. // @Title 获取机构用户
  13. // @Description 获取机构用户
  14. // @Success 200 {object} models.ChartInfoDetailResp
  15. // @router /business/admin [get]
  16. func (this *AdminController) GetBusinessAdmin() {
  17. br := new(models.BaseResponse).Init()
  18. defer func() {
  19. this.Data["json"] = br
  20. this.ServeJSON()
  21. }()
  22. sysUser := this.SysUser
  23. if sysUser == nil {
  24. br.Msg = "请登录"
  25. br.ErrMsg = "请登录,SysUser Is Empty"
  26. br.Ret = 408
  27. return
  28. }
  29. // 查询所有机构
  30. /*ob := new(system.EtaBusiness)
  31. companyList, err := ob.GetItemsByCondition("", make([]interface{}, 0), []string{}, "")
  32. if err != nil {
  33. br.Msg = "获取机构信息失败"
  34. br.ErrMsg = err.Error()
  35. return
  36. }*/
  37. list := make([]*system.BusinessAdmin, 0)
  38. // todo 查询上传图表的所有用户ID
  39. creators, err := models.GetChartCreators()
  40. if err != nil {
  41. br.Msg = "获取上传图表的所有用户信息失败"
  42. br.ErrMsg = err.Error()
  43. return
  44. }
  45. if len(creators) == 0 {
  46. var resp system.BusinessAdminResp
  47. resp.List = list
  48. br.Ret = 200
  49. br.Success = true
  50. br.Msg = "获取成功"
  51. br.Data = resp
  52. return
  53. }
  54. //查询机构下的用户
  55. admin := new(system.Admin)
  56. cond := ` AND admin_id in (` + utils.GetOrmInReplace(len(creators)) + `)`
  57. pars := make([]interface{}, 0)
  58. pars = append(pars, creators)
  59. adminList, err := admin.GetItemsByCondition(cond, pars, []string{}, "")
  60. if err != nil {
  61. br.Msg = "获取机构用户失败"
  62. br.ErrMsg = err.Error()
  63. return
  64. }
  65. companyMap := make(map[string][]*system.BusinessAdmin)
  66. if len(adminList) > 0 {
  67. for _, v := range adminList {
  68. tmp := &system.BusinessAdmin{
  69. AdminId: strconv.Itoa(v.AdminId),
  70. RealName: v.RealName,
  71. }
  72. companyMap[v.BusinessCode] = append(companyMap[v.BusinessCode], tmp)
  73. }
  74. }
  75. companyList := make([]*system.HzEtaBusiness, 0)
  76. hzCompany := new(system.HzEtaBusiness)
  77. hzCompany.BusinessName = utils.HzCompanyName
  78. hzCompany.BusinessCode = utils.HzBusinessCodeRelease
  79. companyList = append(companyList, hzCompany)
  80. if len(companyList) > 0 {
  81. for _, v := range companyList {
  82. tmp := &system.BusinessAdmin{
  83. AdminId: v.BusinessCode,
  84. RealName: v.BusinessName,
  85. }
  86. l, ok := companyMap[v.BusinessCode]
  87. if ok {
  88. tmp.ChildrenList = l
  89. list = append(list, tmp)
  90. }
  91. }
  92. }
  93. var resp system.BusinessAdminResp
  94. resp.List = list
  95. br.Ret = 200
  96. br.Success = true
  97. br.Msg = "获取成功"
  98. br.Data = resp
  99. }