report.go 9.6 KB

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