smart_report_approval.go 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_hub/models"
  5. "eta/eta_hub/services"
  6. "eta/eta_hub/utils"
  7. "github.com/rdlucklib/rdluck_tools/paging"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. // SmartReportController 智能研报
  13. type SmartReportController struct {
  14. BaseAuthController
  15. }
  16. // List
  17. // @Title 报告列表
  18. // @Description 报告列表
  19. // @Param PageSize query int true "每页数据条数"
  20. // @Param CurrentIndex query int true "当前页页码"
  21. // @Param TimeType query string false "筛选的时间类别: publish_time-发布时间, modify_time-更新时间"
  22. // @Param StartDate query string false "开始时间"
  23. // @Param EndDate query string false "结束时间"
  24. // @Param Frequency query string false "频度"
  25. // @Param ClassifyIdFirst query int false "一级分类ID"
  26. // @Param ClassifyIdSecond query int false "二级分类ID"
  27. // @Param State query int false "发布状态: 1-待发布; 2-已发布"
  28. // @Param Keyword query string false "搜索关键词"
  29. // @Success 200 {object} models.SmartReportListResp
  30. // @router /list [get]
  31. func (this *SmartReportController) List() {
  32. br := new(models.BaseResponse).Init()
  33. defer func() {
  34. this.Data["json"] = br
  35. this.ServeJSON()
  36. }()
  37. type SmartReportListReq struct {
  38. PageSize int `form:"PageSize"`
  39. CurrentIndex int `form:"CurrentIndex"`
  40. TimeType string `form:"TimeType"`
  41. StartDate string `form:"StartDate"`
  42. EndDate string `form:"EndDate"`
  43. Frequency string `form:"Frequency"`
  44. ClassifyIdFirst int `form:"ClassifyIdFirst"`
  45. ClassifyIdSecond int `form:"ClassifyIdSecond"`
  46. State int `form:"State"`
  47. Keyword string `form:"Keyword"`
  48. }
  49. params := new(SmartReportListReq)
  50. if e := this.ParseForm(params); e != nil {
  51. br.Msg = "获取失败"
  52. br.ErrMsg = "入参解析失败, Err: " + e.Error()
  53. return
  54. }
  55. if params.TimeType == "" {
  56. params.TimeType = "publish_time"
  57. }
  58. if params.TimeType != "publish_time" && params.TimeType != "modify_time" {
  59. br.Msg = "请选择正确的时间类型"
  60. return
  61. }
  62. // 更新时间指的是内容更新时间
  63. if params.TimeType == "modify_time" {
  64. params.TimeType = "content_modify_time"
  65. }
  66. var condition string
  67. var pars []interface{}
  68. // 筛选项
  69. {
  70. //keyword := strings.TrimSpace(params.Keyword)
  71. //if keyword != "" {
  72. // kw := fmt.Sprint("%", keyword, "%")
  73. // condition += fmt.Sprintf(` AND (title LIKE ? OR admin_real_name LIKE ? OR last_modify_admin_name LIKE ?)`)
  74. // pars = append(pars, kw, kw, kw)
  75. //}
  76. //if params.StartDate != "" && params.EndDate != "" {
  77. // st := fmt.Sprintf("%s 00:00:00", params.StartDate)
  78. // ed := fmt.Sprintf("%s 23:59:59", params.EndDate)
  79. // condition += fmt.Sprintf(` AND %s >= ? AND %s <= ?`, params.TimeType, params.TimeType)
  80. // pars = append(pars, st, ed)
  81. //}
  82. //if params.Frequency != "" {
  83. // condition += ` AND frequency = ?`
  84. // pars = append(pars, params.Frequency)
  85. //}
  86. //if params.ClassifyIdFirst > 0 {
  87. // condition += ` AND classify_id_first = ?`
  88. // pars = append(pars, params.ClassifyIdFirst)
  89. //}
  90. //if params.ClassifyIdSecond > 0 {
  91. // condition += ` AND classify_id_second = ?`
  92. // pars = append(pars, params.ClassifyIdSecond)
  93. //}
  94. //if params.State > 0 {
  95. // condition += ` AND state = ?`
  96. // pars = append(pars, params.State)
  97. //}
  98. }
  99. condition += ` AND state <> 1 `
  100. resp := new(models.SmartReportListResp)
  101. reportOB := new(models.SmartReport)
  102. total, e := reportOB.GetCountByCondition(condition, pars)
  103. if e != nil {
  104. br.Msg = "获取失败"
  105. br.ErrMsg = "获取报告总数失败, Err:" + e.Error()
  106. return
  107. }
  108. if total <= 0 {
  109. page := paging.GetPaging(params.CurrentIndex, params.PageSize, total)
  110. resp.Paging = page
  111. br.Ret = 200
  112. br.Msg = "获取成功"
  113. br.Data = resp
  114. return
  115. }
  116. // 分页列表
  117. var startSize int
  118. if params.PageSize <= 0 {
  119. params.PageSize = utils.PageSize20
  120. }
  121. if params.CurrentIndex <= 0 {
  122. params.CurrentIndex = 1
  123. }
  124. startSize = utils.StartIndex(params.CurrentIndex, params.PageSize)
  125. // 列表查询过滤掉富文本内容
  126. fields := []string{
  127. "smart_report_id", "report_code", "classify_id_first", "classify_name_first", "classify_id_second", "classify_name_second", "add_type",
  128. "title", "abstract", "author", "frequency", "stage", "video_url", "video_name", "video_play_seconds", "video_size", "detail_img_url", "detail_pdf_url",
  129. "admin_id", "admin_real_name", "state", "publish_time", "pre_publish_time", "pre_msg_send", "msg_is_send", "msg_send_time", "create_time", "modify_time",
  130. "last_modify_admin_id", "last_modify_admin_name", "content_modify_time", "pv", "uv",
  131. }
  132. list, e := reportOB.GetPageItemsByCondition(condition, pars, fields, "", startSize, params.PageSize)
  133. if e != nil {
  134. br.Msg = "获取失败"
  135. br.ErrMsg = "获取报告分页列表失败, Err:" + e.Error()
  136. return
  137. }
  138. resp.List = list
  139. page := paging.GetPaging(params.CurrentIndex, params.PageSize, total)
  140. resp.Paging = page
  141. br.Ret = 200
  142. br.Msg = "获取成功"
  143. br.Data = resp
  144. }
  145. // Detail
  146. // @Title 详情
  147. // @Description 详情
  148. // @Param SmartReportId query int true "智能研报ID"
  149. // @Success 200 {object} models.SmartReportItem
  150. // @router /detail [get]
  151. func (this *SmartReportController) Detail() {
  152. br := new(models.BaseResponse).Init()
  153. defer func() {
  154. this.Data["json"] = br
  155. this.ServeJSON()
  156. }()
  157. reportId, _ := this.GetInt("SmartReportId")
  158. if reportId <= 0 {
  159. br.Msg = "参数有误"
  160. br.ErrMsg = "报告ID有误"
  161. return
  162. }
  163. ob := new(models.SmartReport)
  164. item, e := ob.GetItemById(reportId)
  165. if e != nil {
  166. if e.Error() == utils.ErrNoRow() {
  167. br.Msg = "报告不存在, 请刷新页面"
  168. return
  169. }
  170. br.Msg = "操作失败"
  171. br.ErrMsg = "获取研报失败, Err: " + e.Error()
  172. return
  173. }
  174. // 报告状态 2待审核 3已驳回 4已审批
  175. if !utils.InArrayByInt([]int{models.SmartReportStatePublished, models.SmartReportStateRejected, models.SmartReportStateApprovaled}, item.State) {
  176. br.Msg = "报告状态错误"
  177. br.ErrMsg = "报告状态错误"
  178. return
  179. }
  180. resp := models.FormatSmartReport2Item(item)
  181. br.Ret = 200
  182. br.Msg = "获取成功"
  183. br.Data = resp
  184. }
  185. // Publish
  186. // @Title 发布/取消发布
  187. // @Description 发布/取消发布
  188. // @Param request body models.SmartReportPublishReq true "type json string"
  189. // @Success 200 string "操作成功"
  190. // @router /publish [post]
  191. func (this *SmartReportController) Publish() {
  192. br := new(models.BaseResponse).Init()
  193. defer func() {
  194. this.Data["json"] = br
  195. this.ServeJSON()
  196. }()
  197. var req models.SmartReportPublishReq
  198. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  199. if err != nil {
  200. br.Msg = "参数解析异常!"
  201. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  202. return
  203. }
  204. if req.SmartReportIds == "" {
  205. br.Msg = "参数有误"
  206. br.ErrMsg = "报告ID为空"
  207. return
  208. }
  209. if req.PublishState != models.SmartReportStateRejected && req.PublishState != models.SmartReportStateApprovaled {
  210. br.Msg = "参数有误"
  211. return
  212. }
  213. reportArr := strings.Split(req.SmartReportIds, ",")
  214. for _, v := range reportArr {
  215. vint, err := strconv.Atoi(v)
  216. if err != nil {
  217. br.Msg = "参数错误"
  218. br.ErrMsg = "参数错误,Err:" + err.Error()
  219. return
  220. }
  221. ob := new(models.SmartReport)
  222. item, e := ob.GetItemById(vint)
  223. if e != nil {
  224. if e.Error() == utils.ErrNoRow() {
  225. br.Msg = "报告不存在, 请刷新页面"
  226. return
  227. }
  228. br.Msg = "操作失败"
  229. br.ErrMsg = "获取研报失败, Err: " + e.Error()
  230. return
  231. }
  232. cols := []string{"State", "ModifyTime"}
  233. item.State = req.PublishState
  234. item.ModifyTime = time.Now().Local()
  235. if e = item.Update(cols); e != nil {
  236. br.Msg = "操作失败"
  237. br.ErrMsg = "更新研报失败, Err: " + e.Error()
  238. return
  239. }
  240. recordItem := &models.ReportStateRecord{
  241. ReportId: vint,
  242. ReportType: 2,
  243. State: req.PublishState,
  244. CreateTime: time.Now(),
  245. }
  246. go func() {
  247. _, _ = models.AddReportStateRecord(recordItem)
  248. }()
  249. // ES更新报告
  250. go func() {
  251. _ = services.SmartReportElasticUpsert(item.SmartReportId, req.PublishState)
  252. }()
  253. }
  254. if req.PublishState == models.SmartReportStateRejected {
  255. br.Msg = "驳回成功"
  256. } else {
  257. br.Msg = "审批通过"
  258. }
  259. br.Ret = 200
  260. }