report.go 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. package controllers
  2. import (
  3. "eta/eta_mini_bridge/models"
  4. "eta/eta_mini_bridge/models/response"
  5. "eta/eta_mini_bridge/utils"
  6. "html"
  7. "strconv"
  8. "time"
  9. "github.com/rdlucklib/rdluck_tools/paging"
  10. )
  11. type ReportController struct {
  12. BaseAuthController
  13. }
  14. // @Title List
  15. // @Description create users
  16. // @Param ChartPermissionId query int true "品种ID"
  17. // @Param Level query int true "品种层级"
  18. // @Param PageSize query int true "每页数据条数"
  19. // @Param CurrentIndex query int true "当前页页码,从1开始"
  20. // @Param RangeType query string true "范围类型,1-一天内,2-一周内,3-半年内"
  21. // @Success 200 {int} models.User.Id
  22. // @Failure 403 body is empty
  23. // @router /list [get]
  24. func (this *ReportController) List() {
  25. br := new(models.BaseResponse).Init()
  26. defer func() {
  27. this.Data["json"] = br
  28. this.ServeJSON()
  29. }()
  30. pageSize, _ := this.GetInt("PageSize")
  31. currentIndex, _ := this.GetInt("CurrentIndex")
  32. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  33. level, _ := this.GetInt("Level")
  34. rangeType, _ := this.GetInt("RangeType")
  35. if chartPermissionId <= 0 {
  36. br.Msg = "品种参数错误"
  37. return
  38. }
  39. var condition string
  40. switch rangeType {
  41. case 1:
  42. condition += ` AND DATE(a.modify_time)=DATE(NOW()) `
  43. case 2:
  44. condition += ` AND DATE(a.modify_time) BETWEEN DATE_SUB(NOW(),INTERVAL 1 WEEK) AND NOW() `
  45. case 3:
  46. condition += ` AND DATE(a.modify_time) BETWEEN DATE_SUB(NOW(),INTERVAL 6 MONTH) AND NOW() `
  47. }
  48. var startSize int
  49. if pageSize <= 0 {
  50. pageSize = utils.PageSize20
  51. }
  52. if currentIndex <= 0 {
  53. currentIndex = 1
  54. }
  55. startSize = utils.StartIndex(currentIndex, pageSize)
  56. var total int
  57. var reportList []*models.ReportList
  58. switch level {
  59. case 2:
  60. classifyIds, err := models.GetClassifyIdsListById(chartPermissionId)
  61. if err != nil {
  62. br.Msg = "获取报告列表失败"
  63. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  64. return
  65. }
  66. tmptotal, err := models.GetReportCountByClassifyIds(classifyIds, condition)
  67. if err != nil {
  68. br.Msg = "获取数据失败"
  69. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  70. return
  71. }
  72. total = tmptotal
  73. tmpReportList, err := models.GetReportListByClassifyIds(classifyIds, condition, startSize, pageSize)
  74. if err != nil {
  75. br.Msg = "获取报告列表失败"
  76. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  77. return
  78. }
  79. reportList = tmpReportList
  80. case 1:
  81. chartPermissionIds, err := models.GetChildChartPermissionIdsById(chartPermissionId)
  82. if err != nil {
  83. br.Msg = "获取报告列表失败"
  84. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  85. return
  86. }
  87. classifyIds, err := models.GetClassifyIdsListByIds(chartPermissionIds)
  88. if err != nil {
  89. br.Msg = "获取报告列表失败"
  90. br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
  91. return
  92. }
  93. tmptotal, err := models.GetReportCountByClassifyIds(classifyIds, condition)
  94. if err != nil {
  95. br.Msg = "获取数据失败"
  96. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  97. return
  98. }
  99. total = tmptotal
  100. tmpReportList, err := models.GetReportListByClassifyIds(classifyIds, condition, startSize, pageSize)
  101. if err != nil {
  102. br.Msg = "获取报告列表失败"
  103. br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
  104. return
  105. }
  106. reportList = tmpReportList
  107. default:
  108. br.Msg = "层级参数错误"
  109. return
  110. }
  111. page := paging.GetPaging(currentIndex, pageSize, total)
  112. resp := new(response.ReportListResp)
  113. resp.Paging = page
  114. resp.List = reportList
  115. br.Ret = 200
  116. br.Success = true
  117. br.Msg = "获取成功"
  118. br.Data = resp
  119. }
  120. // @Title 日评详情
  121. // @Description 日评详情接口
  122. // @Param ReportId query int true "报告id"
  123. // @Param UserId query int true "用户id"
  124. // @Success 200 {object} models.ReportDetailResp
  125. // @router /detail [get]
  126. func (this *ReportController) Detail() {
  127. br := new(models.BaseResponse).Init()
  128. defer func() {
  129. this.Data["json"] = br
  130. this.ServeJSON()
  131. }()
  132. reportId, err := this.GetInt("ReportId")
  133. userId, err := this.GetInt("UserId")
  134. if err != nil {
  135. br.Msg = "参数获取失败"
  136. br.ErrMsg = "参数获取失败,Err:" + err.Error()
  137. return
  138. }
  139. if reportId <= 0 {
  140. br.Msg = "参数错误"
  141. br.ErrMsg = "参数错误,报告id小于等于0"
  142. return
  143. }
  144. if userId <= 0 {
  145. br.Msg = "参数错误"
  146. br.ErrMsg = "参数错误,用户id小于等于0"
  147. return
  148. }
  149. user, err := models.GetUserById(userId)
  150. if err != nil {
  151. br.Msg = "用户不存在"
  152. br.ErrMsg = "用户不存在,系统异常,Err:" + err.Error()
  153. return
  154. }
  155. // 有效期是否到期
  156. IsVail := user.ValidEndTime.After(time.Now())
  157. report, err := models.GetReportById(reportId)
  158. if err != nil {
  159. br.Msg = "该报告已删除"
  160. br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
  161. return
  162. }
  163. report.ContentSub = html.UnescapeString(report.ContentSub)
  164. report.Content = html.UnescapeString(report.Content)
  165. if report == nil {
  166. br.Msg = "报告不存在"
  167. return
  168. }
  169. reportChartPermissionIds, err := models.GetChartPermissionIdsListByClassifyId(report.ClassifyIdSecond)
  170. if err != nil {
  171. br.Msg = "获取研报权限失败"
  172. br.ErrMsg = "获取研报权限失败,Err:" + err.Error()
  173. return
  174. }
  175. chartPermissionList, err := models.GetChartPermissionIdsByIds(reportChartPermissionIds)
  176. if err != nil {
  177. br.Msg = "获取研报权限失败"
  178. br.ErrMsg = "获取研报权限失败,Err:" + err.Error()
  179. return
  180. }
  181. var IsHas bool
  182. var IsPublic bool
  183. for _, v := range chartPermissionList {
  184. if v.IsPublic == 1 {
  185. IsPublic = true
  186. break
  187. }
  188. }
  189. resp := new(response.ReportDetailResp)
  190. if !IsPublic {
  191. // 如果被禁用或是潜在用户,直接返回无阅读报告权限
  192. if user.Status == 0 || user.Status == 1 {
  193. resp.Report = report
  194. resp.Status = utils.ReportPermissionStatusNo
  195. report.Content = ""
  196. br.Ret = 408
  197. br.Data = resp
  198. br.Msg = "用户权限不足"
  199. return
  200. }
  201. // 如果是私有报告,用户权限过期直接返回有效期已过
  202. if !IsVail {
  203. resp.Report = report
  204. resp.Status = utils.ReportPermissionStatusExpired
  205. report.Content = ""
  206. br.Ret = 408
  207. br.Data = resp
  208. br.Msg = "用户权限不足"
  209. return
  210. }
  211. chartPermissionIds, err := models.GetChartPermissionIdByUserId(userId)
  212. if err != nil {
  213. br.Msg = "获取用户权限失败"
  214. br.ErrMsg = "获取用户权限失败,Err:" + err.Error()
  215. return
  216. }
  217. if len(chartPermissionIds) <= 0 {
  218. resp.Report = report
  219. resp.Status = utils.ReportPermissionStatusNo
  220. report.Content = ""
  221. br.Ret = 408
  222. br.Data = resp
  223. br.Msg = "用户权限不足"
  224. return
  225. }
  226. classifyIds, err := models.GetClassifyIdsListByIds(chartPermissionIds)
  227. if err != nil {
  228. br.Msg = "获取用户权限失败"
  229. br.ErrMsg = "获取用户分类权限失败,Err:" + err.Error()
  230. return
  231. }
  232. if len(classifyIds) <= 0 {
  233. resp.Report = report
  234. resp.Status = utils.ReportPermissionStatusNoPermission
  235. report.Content = ""
  236. br.Ret = 408
  237. br.Data = resp
  238. br.Msg = "用户权限不足"
  239. return
  240. }
  241. reportClassifyIdStr := strconv.Itoa(report.ClassifyIdSecond)
  242. for _, v := range classifyIds {
  243. if v == reportClassifyIdStr {
  244. IsHas = true
  245. }
  246. }
  247. if !IsHas {
  248. resp.Report = report
  249. resp.Status = utils.ReportPermissionStatusNoPermission
  250. report.Content = ""
  251. br.Ret = 408
  252. br.Data = resp
  253. br.Msg = "用户权限不足"
  254. return
  255. }
  256. }
  257. resp.Report = report
  258. resp.Status = utils.ReportPermissionStatusHas
  259. br.Data = resp
  260. br.Ret = 200
  261. br.Success = true
  262. br.Msg = "获取成功"
  263. }
  264. // @Title List
  265. // @Description create users
  266. // @Param body body models.User true "body for user content"
  267. // @Success 200 {int} models.User.Id
  268. // @Failure 403 body is empty
  269. // @router /daily/list [get]
  270. func (this *ReportController) Today() {
  271. br := new(models.BaseResponse).Init()
  272. defer func() {
  273. this.Data["json"] = br
  274. this.ServeJSON()
  275. }()
  276. pageSize, _ := this.GetInt("PageSize")
  277. currentIndex, _ := this.GetInt("CurrentIndex")
  278. var startSize int
  279. if pageSize <= 0 {
  280. pageSize = utils.PageSize30
  281. }
  282. if currentIndex <= 0 {
  283. currentIndex = 1
  284. }
  285. startSize = utils.StartIndex(currentIndex, pageSize)
  286. total, err := models.GetReportDailyListCount()
  287. if err != nil {
  288. br.Msg = "获取数据失败"
  289. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  290. return
  291. }
  292. list, err := models.GetReportDailyList(startSize, pageSize)
  293. if err != nil {
  294. br.Msg = "获取失败"
  295. br.ErrMsg = "获取失败,Err:" + err.Error()
  296. return
  297. }
  298. page := paging.GetPaging(currentIndex, pageSize, total)
  299. resp := new(response.ReportListResp)
  300. resp.Paging = page
  301. resp.List = list
  302. br.Ret = 200
  303. br.Success = true
  304. br.Msg = "获取成功"
  305. br.Data = resp
  306. }