policy_report.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. package english_report
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/services"
  7. "eta/eta_api/utils"
  8. "github.com/rdlucklib/rdluck_tools/paging"
  9. "html"
  10. "time"
  11. )
  12. // EnglishPolicyReportController 研报活动模块
  13. type EnglishPolicyReportController struct {
  14. controllers.BaseAuthController
  15. }
  16. // @Title 获取策略报告详情接口
  17. // @Description 获取报告详情
  18. // @Param Id query int true "报告ID"
  19. // @Success 200 {object} models.EnglishPolicyReportDetailView
  20. // @router /policy/detail [get]
  21. func (this *EnglishPolicyReportController) Detail() {
  22. br := new(models.BaseResponse).Init()
  23. defer func() {
  24. this.Data["json"] = br
  25. this.ServeJSON()
  26. }()
  27. reportId, err := this.GetInt("Id")
  28. if err != nil {
  29. br.Msg = "获取参数失败!"
  30. br.ErrMsg = "获取参数失败,Err:" + err.Error()
  31. return
  32. }
  33. if reportId <= 0 {
  34. br.Msg = "参数错误"
  35. return
  36. }
  37. item, err := models.GetEnglishPolicyReportById(reportId)
  38. if err != nil {
  39. if err.Error() == utils.ErrNoRow() {
  40. br.Msg = "报告不存在!"
  41. return
  42. }
  43. br.Msg = "获取失败"
  44. br.ErrMsg = "获取失败,Err:" + err.Error()
  45. return
  46. }
  47. item.Content = html.UnescapeString(item.Content)
  48. br.Ret = 200
  49. br.Success = true
  50. br.Msg = "获取成功"
  51. br.Data = item
  52. }
  53. // @Title 获取报告列表接口
  54. // @Description 获取报告列表
  55. // @Param PageSize query int true "每页数据条数"
  56. // @Param CurrentIndex query int true "当前页页码,从1开始"
  57. // @Param StartDate query string true "开始时间"
  58. // @Param EndDate query string true "结束时间"
  59. // @Param State query int true "状态"
  60. // @Param KeyWord query string true "搜索关键词"
  61. // @Success 200 {object} models.ReportListResp
  62. // @router /policy/list [get]
  63. func (this *EnglishPolicyReportController) ListReport() {
  64. br := new(models.BaseResponse).Init()
  65. defer func() {
  66. this.Data["json"] = br
  67. this.ServeJSON()
  68. }()
  69. sysUser := this.SysUser
  70. if sysUser == nil {
  71. br.Msg = "请登录"
  72. br.ErrMsg = "请登录,SysUser Is Empty"
  73. br.Ret = 408
  74. return
  75. }
  76. pageSize, _ := this.GetInt("PageSize")
  77. currentIndex, _ := this.GetInt("CurrentIndex")
  78. startDate := this.GetString("StartDate")
  79. endDate := this.GetString("EndDate")
  80. state, _ := this.GetInt("State")
  81. keyWord := this.GetString("KeyWord")
  82. var startSize int
  83. if pageSize <= 0 {
  84. pageSize = utils.PageSize20
  85. }
  86. if currentIndex <= 0 {
  87. currentIndex = 1
  88. }
  89. startSize = utils.StartIndex(currentIndex, pageSize)
  90. var condition string
  91. var pars []interface{}
  92. if keyWord != "" {
  93. condition += ` AND (title LIKE '%` + keyWord + `%' OR author LIKE '%` + keyWord + `%' ) `
  94. }
  95. if startDate != "" {
  96. condition += ` AND publish_time >= ? `
  97. pars = append(pars, startDate)
  98. }
  99. if endDate != "" {
  100. endTime, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
  101. endTime = endTime.AddDate(0, 0, 1)
  102. condition += ` AND publish_time <= ? `
  103. pars = append(pars, endTime)
  104. }
  105. if state > 0 {
  106. condition += ` AND state = ? `
  107. pars = append(pars, state)
  108. }
  109. total, err := models.GetEnglishPolicyReportListCount(condition, pars)
  110. if err != nil {
  111. br.Msg = "获取失败"
  112. br.ErrMsg = "获取失败,Err:" + err.Error()
  113. return
  114. }
  115. list, err := models.GetEnglishPolicyReportList(condition, pars, startSize, pageSize)
  116. if err != nil {
  117. br.Msg = "获取失败"
  118. br.ErrMsg = "获取失败,Err:" + err.Error()
  119. return
  120. }
  121. page := paging.GetPaging(currentIndex, pageSize, total)
  122. resp := new(models.EnglishPolicyReportListResp)
  123. resp.Paging = page
  124. resp.List = list
  125. br.Ret = 200
  126. br.Success = true
  127. br.Msg = "获取成功"
  128. br.Data = resp
  129. }
  130. // @Title 同步报告接口
  131. // @Description 同步报告接口
  132. // @Param request body models.SyncEnglishPolicyReq true "type json string"
  133. // @Success 200 Ret=200 发布成功
  134. // @router /policy/sync [post]
  135. func (this *EnglishPolicyReportController) SyncReport() {
  136. br := new(models.BaseResponse).Init()
  137. defer func() {
  138. this.Data["json"] = br
  139. this.ServeJSON()
  140. }()
  141. sysUser := this.SysUser
  142. if sysUser == nil {
  143. br.Msg = "请登录"
  144. br.ErrMsg = "请登录,SysUser Is Empty"
  145. br.Ret = 408
  146. return
  147. }
  148. var req models.SyncEnglishPolicyReq
  149. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  150. if err != nil {
  151. br.Msg = "参数解析异常!"
  152. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  153. return
  154. }
  155. reportId := req.Id
  156. if reportId <= 0 {
  157. br.Msg = "请选择策略报告"
  158. return
  159. }
  160. err, errMsg := services.EnglishPolicyReportSync(reportId, sysUser)
  161. if err != nil {
  162. br.Msg = err.Error()
  163. br.ErrMsg = errMsg
  164. return
  165. }
  166. br.Ret = 200
  167. br.Success = true
  168. br.Msg = "同步成功"
  169. }
  170. // @Title 获取最新的策略报告
  171. // @Description 获取最新的策略报告
  172. // @Param request body models.SyncEnglishPolicyReq true "type json string"
  173. // @Success 200 Ret=200 获取成功
  174. // @router /policy/pull [get]
  175. func (this *EnglishPolicyReportController) PullPolicyData() {
  176. br := new(models.BaseResponse).Init()
  177. defer func() {
  178. this.Data["json"] = br
  179. this.ServeJSON()
  180. }()
  181. data, err, msg := services.PullPolicyReport()
  182. if err != nil {
  183. br.Msg = msg
  184. br.ErrMsg = err.Error()
  185. return
  186. }
  187. br.Ret = 200
  188. br.Success = true
  189. br.Msg = "获取成功"
  190. br.Data = data
  191. }