en_permission.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package english_report
  2. import (
  3. "eta/eta_mobile/controllers"
  4. "eta/eta_mobile/models"
  5. "eta/eta_mobile/utils"
  6. "fmt"
  7. "strings"
  8. )
  9. // EnPermissionController 英文权限
  10. type EnPermissionController struct {
  11. controllers.BaseAuthController
  12. }
  13. // List
  14. // @Title 品种列表
  15. // @Description 品种列表
  16. // @Param Keyword query string false "关键词"
  17. // @Param ReportId query int false "报告ID-用于邮件推送时过滤掉无权限的品种"
  18. // @Param VideoId query int false "路演视频ID-用于邮件推送时过滤掉无权限的品种"
  19. // @Success 200 Ret=200 操作成功
  20. // @router /list [get]
  21. func (this *EnPermissionController) List() {
  22. br := new(models.BaseResponse).Init()
  23. defer func() {
  24. if br.ErrMsg == "" {
  25. br.IsSendEmail = false
  26. }
  27. this.Data["json"] = br
  28. this.ServeJSON()
  29. }()
  30. sysUser := this.SysUser
  31. if sysUser == nil {
  32. br.Msg = "请登录"
  33. br.ErrMsg = "请登录,SysUser Is Empty"
  34. br.Ret = 408
  35. return
  36. }
  37. keyword := this.GetString("Keyword", "")
  38. keyword = strings.TrimSpace(keyword)
  39. // 禁用指定报告、指定路演无权限的品种
  40. reportId, _ := this.GetInt("ReportId", 0)
  41. videoId, _ := this.GetInt("VideoId", 0)
  42. limitIds := make([]int, 0)
  43. if reportId > 0 {
  44. ps, e := models.GetEnPermissionIdsByEnglishReportId(reportId)
  45. if e != nil {
  46. br.Msg = "获取失败"
  47. br.ErrMsg = "获取报告权限品种失败, Err: " + e.Error()
  48. return
  49. }
  50. limitIds = ps
  51. }
  52. if videoId > 0 {
  53. ps, e := models.GetEnPermissionIdsByEnglishVideoId(videoId)
  54. if e != nil {
  55. br.Msg = "获取失败"
  56. br.ErrMsg = "获取视频权限品种失败, Err: " + e.Error()
  57. return
  58. }
  59. limitIds = ps
  60. }
  61. cond := ``
  62. pars := make([]interface{}, 0)
  63. if keyword != "" {
  64. k := fmt.Sprint("%", keyword, "%")
  65. cond += fmt.Sprintf(` AND %s LIKE ?`, models.EnPermissionColumns.EnPermissionName)
  66. pars = append(pars, k)
  67. }
  68. list, e := models.GetEnPermissionUnionList(cond, pars)
  69. if e != nil {
  70. br.Msg = "获取失败"
  71. br.ErrMsg = "获取品种Union列表失败, Err: " + e.Error()
  72. return
  73. }
  74. // 品种树
  75. resp := make([]*models.EnPermissionItem, 0)
  76. childMap := make(map[int][]*models.EnPermissionItem)
  77. for _, v := range list {
  78. t := new(models.EnPermissionItem)
  79. t.EnPermissionId = v.EnPermissionId
  80. t.EnPermissionName = v.EnPermissionName
  81. t.CnPermissionName = v.CnPermissionName
  82. t.ParentId = v.ParentId
  83. t.Sort = v.Sort
  84. t.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
  85. t.Child = make([]*models.EnPermissionItem, 0)
  86. if v.ParentId == 0 {
  87. resp = append(resp, t)
  88. continue
  89. }
  90. if v.ParentId > 0 {
  91. if childMap[v.ParentId] == nil {
  92. childMap[v.ParentId] = make([]*models.EnPermissionItem, 0)
  93. }
  94. // 无权限则隐藏
  95. if (reportId > 0 || videoId > 0) && !utils.InArrayByInt(limitIds, t.EnPermissionId) {
  96. continue
  97. }
  98. childMap[v.ParentId] = append(childMap[v.ParentId], t)
  99. }
  100. }
  101. for _, r := range resp {
  102. r.Child = childMap[r.EnPermissionId]
  103. }
  104. br.Ret = 200
  105. br.Success = true
  106. br.Msg = "获取成功"
  107. br.Data = resp
  108. }