chart_permission.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. package controllers
  2. import (
  3. "eta/eta_mini_api/models"
  4. "eta/eta_mini_api/services"
  5. "eta/eta_mini_api/utils"
  6. )
  7. type ChartPermissionController struct {
  8. BaseAuthController
  9. }
  10. type ChartPermissionNoAuthController struct {
  11. BaseCommonController
  12. }
  13. // List
  14. // @Title 系统品种列表
  15. // @Description 系统品种列表
  16. // @Param chartPermissonId query int true "品种权限id"
  17. // @Success 200 {object} models.LoginResp
  18. // @router /list [get]
  19. func (this *ChartPermissionController) List() {
  20. br := new(models.BaseResponse).Init()
  21. defer func() {
  22. this.Data["json"] = br
  23. this.ServeJSON()
  24. }()
  25. id, _ := this.GetInt("chartPermissonId", 0)
  26. var resp *models.ChartPermissionResp[[]*models.ChartPermission]
  27. var err error
  28. if id == 0 {
  29. resp, err = services.GetChartPermissionList()
  30. } else if id > 0 {
  31. resp, err = services.GetChartPermissionSecondList(id)
  32. }
  33. if err != nil {
  34. br.Msg = "权限列表获取失败"
  35. br.ErrMsg = "权限列表获取失败,系统错误,Err:" + err.Error()
  36. return
  37. }
  38. if resp.Ret != 200 {
  39. br.Msg = resp.Msg
  40. br.ErrMsg = resp.ErrMsg
  41. return
  42. }
  43. chartPermissionList := make([]*models.ChartPermissionView, 0)
  44. for _, item := range resp.Data {
  45. chartPermissionList = append(chartPermissionList, &models.ChartPermissionView{
  46. ChartPermissionId: item.ChartPermissionId,
  47. PermissionName: item.PermissionName,
  48. Remark: item.Remark,
  49. ImageUrl: item.ImageUrl,
  50. ChartPermissionType: utils.PermissionTypeEta,
  51. })
  52. }
  53. // 如果id != 0, 则只返回二级品种权限,并且需要附加pdf报告品种
  54. if id != 0 {
  55. chartPermissionList = append(chartPermissionList, &models.ChartPermissionView{
  56. ChartPermissionId: -1,
  57. PermissionName: utils.MINI_CUSTOM_PERMISSION_NAME,
  58. Remark: "",
  59. ImageUrl: "",
  60. ChartPermissionType: utils.PermissionTypeMini,
  61. })
  62. }
  63. br.Ret = 200
  64. br.Data = chartPermissionList
  65. br.Msg = "列表获取成功"
  66. br.Success = true
  67. }
  68. // ClassifyTree
  69. // @Title 获取品种下的分类权限列表
  70. // @Description 获取研报的品种权限列表
  71. // @Param ChartPermissionId query int true "品种权限id"
  72. // @Success 200 {object} []models.ChartPermission
  73. // @router /classify/tree [get]
  74. func (this *ChartPermissionController) ClassifyTree() {
  75. br := new(models.BaseResponse).Init()
  76. defer func() {
  77. this.Data["json"] = br
  78. this.ServeJSON()
  79. }()
  80. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  81. if chartPermissionId <= 0 {
  82. br.Msg = "品种权限不能为空"
  83. return
  84. }
  85. resp, err := services.GetClassifyTreeByChartPermission(chartPermissionId)
  86. if err != nil {
  87. br.Msg = "获取分类失败"
  88. br.ErrMsg = "品种权限获取失败,系统错误,Err:" + err.Error()
  89. return
  90. }
  91. if resp.Ret != 200 {
  92. br.Msg = resp.Msg
  93. br.ErrMsg = resp.ErrMsg
  94. return
  95. }
  96. classifyList := resp.Data
  97. br.Data = classifyList
  98. br.Msg = "获取成功"
  99. br.Success = true
  100. br.Ret = 200
  101. }
  102. // ClassifyTree
  103. // @Title 获取品种下的分类权限列表
  104. // @Description 获取研报的品种权限列表
  105. // @Param ChartPermissionId query int true "品种权限id"
  106. // @Success 200 {object} []models.ChartPermission
  107. // @router /classify/tree [get]
  108. func (this *ChartPermissionNoAuthController) ClassifyTree() {
  109. br := new(models.BaseResponse).Init()
  110. defer func() {
  111. this.Data["json"] = br
  112. this.ServeJSON()
  113. }()
  114. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  115. if chartPermissionId < 0 {
  116. br.Msg = "品种权限异常"
  117. return
  118. }
  119. resp, err := services.GetClassifyTreeByChartPermission(chartPermissionId)
  120. if err != nil {
  121. br.Msg = "获取分类失败"
  122. br.ErrMsg = "品种权限获取失败,系统错误,Err:" + err.Error()
  123. return
  124. }
  125. if resp.Ret != 200 {
  126. br.Msg = resp.Msg
  127. br.ErrMsg = resp.ErrMsg
  128. return
  129. }
  130. classifyList := resp.Data
  131. br.Data = classifyList
  132. br.Msg = "获取成功"
  133. br.Success = true
  134. br.Ret = 200
  135. }
  136. // List
  137. // @Title 系统品种列表
  138. // @Description 系统品种列表
  139. // @Param chartPermissonId query int true "品种权限id"
  140. // @Success 200 {object} models.LoginResp
  141. // @router /list [get]
  142. func (this *ChartPermissionNoAuthController) List() {
  143. br := new(models.BaseResponse).Init()
  144. defer func() {
  145. this.Data["json"] = br
  146. this.ServeJSON()
  147. }()
  148. id, _ := this.GetInt("chartPermissonId", 0)
  149. var resp *models.ChartPermissionResp[[]*models.ChartPermission]
  150. var err error
  151. if id == 0 {
  152. resp, err = services.GetChartPermissionList()
  153. } else if id > 0 {
  154. resp, err = services.GetChartPermissionSecondList(id)
  155. }
  156. if err != nil {
  157. br.Msg = "权限列表获取失败"
  158. br.ErrMsg = "权限列表获取失败,系统错误,Err:" + err.Error()
  159. return
  160. }
  161. if resp.Ret != 200 {
  162. br.Msg = resp.Msg
  163. br.ErrMsg = resp.ErrMsg
  164. return
  165. }
  166. chartPermissionList := make([]*models.ChartPermissionView, 0)
  167. for _, item := range resp.Data {
  168. chartPermissionList = append(chartPermissionList, &models.ChartPermissionView{
  169. ChartPermissionId: item.ChartPermissionId,
  170. PermissionName: item.PermissionName,
  171. Remark: item.Remark,
  172. ImageUrl: item.ImageUrl,
  173. ChartPermissionType: utils.PermissionTypeEta,
  174. })
  175. }
  176. if id > 0 {
  177. chartPermissionList = append(chartPermissionList, &models.ChartPermissionView{
  178. ChartPermissionId: id,
  179. PermissionName: utils.ZC_CUSTOM_PERMISSION_NAME,
  180. Remark: "",
  181. ImageUrl: "",
  182. ChartPermissionType: utils.PermissionTypeMini,
  183. })
  184. }
  185. br.Ret = 200
  186. br.Data = chartPermissionList
  187. br.Msg = "列表获取成功"
  188. br.Success = true
  189. }