report.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. package models
  2. import (
  3. "eta/eta_mini_bridge/utils"
  4. "fmt"
  5. "time"
  6. "github.com/beego/beego/v2/client/orm"
  7. )
  8. type ReportList struct {
  9. Id int `description:"报告Id"`
  10. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  11. ClassifyIdFirst int `description:"一级分类id"`
  12. ClassifyNameFirst string `description:"一级分类名称"`
  13. ClassifyIdSecond int `description:"二级分类id"`
  14. ClassifyNameSecond string `description:"二级分类名称"`
  15. ClassifyIdThird int `description:"三级分类id"`
  16. ClassifyNameThird string `description:"三级分类名称"`
  17. PermissionNames []string `description:"二级分类名称"`
  18. Title string `description:"标题"`
  19. Abstract string `description:"摘要"`
  20. Author string `description:"作者"`
  21. Frequency string `description:"频度"`
  22. CreateTime string `description:"创建时间"`
  23. ModifyTime time.Time `description:"修改时间"`
  24. State int `description:"1:未发布,2:已发布"`
  25. PublishTime string `description:"发布时间"`
  26. Stage int `description:"期数"`
  27. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  28. Content string `description:"内容"`
  29. VideoUrl string `description:"音频文件URL"`
  30. VideoName string `description:"音频文件名称"`
  31. VideoPlaySeconds string `description:"音频播放时长"`
  32. VideoSize string `description:"音频文件大小,单位M"`
  33. HasPermission int `description:"是否拥有报告权限,1:拥有,0:没有"`
  34. TitleType string `description:"标题类型,FICC或者权益"`
  35. IsCurrentDate int `description:"是否当前日期:1是,0不是"`
  36. ClassifyDetail
  37. }
  38. type ReportPushStatus struct {
  39. ReportPushStatusId int `orm:"pk"`
  40. ReportId int `description:"报告id"`
  41. State int `description:"报告状态:0-未推送,1-已推送"`
  42. Title string `description:"报告标题"`
  43. Abstract string `description:"报告摘要"`
  44. Stage int `description:"期数"`
  45. ClassifyIdFirst int `description:"一级分类id"`
  46. ClassifyNameFirst string `description:"一级分类名称"`
  47. ClassifyIdSecond int `description:"二级分类id"`
  48. ClassifyNameSecond string `description:"二级分类名称"`
  49. ClassifyIdThird int `description:"三级分类id"`
  50. ClassifyNameThird string `description:"三级分类名称"`
  51. Author string `description:"报告作者"`
  52. ReportType int `description:"报告类型:1-eta报告"`
  53. PublishTime time.Time `description:"报告发布时间"`
  54. CreateTime time.Time `description:"创建时间"`
  55. ModifyTime time.Time `description:"修改时间"`
  56. PushTime time.Time `description:"推送时间"`
  57. }
  58. type ReportPushView struct {
  59. ReportPushStatusId int `orm:"pk"`
  60. ReportId int `description:"报告id"`
  61. Title string `description:"报告标题"`
  62. Abstract string `description:"报告摘要"`
  63. ClassifyIdFirst int `description:"一级分类id"`
  64. ClassifyNameFirst string `description:"一级分类名称"`
  65. ClassifyIdSecond int `description:"二级分类id"`
  66. ClassifyNameSecond string `description:"二级分类名称"`
  67. ClassifyIdThird int `description:"二级分类id"`
  68. ClassifyNameThird string `description:"二级分类名称"`
  69. Author string `description:"报告作者"`
  70. Stage int `description:"期数"`
  71. State int `description:"报告状态:0-未推送,1-已推送"`
  72. PushTime string `description:"推送时间"`
  73. PublishTime string `description:"报告发布时间"`
  74. ReportType int `description:"报告类型:1-eta报告"`
  75. CreateTime string `description:"创建时间"`
  76. ModifyTime string `description:"修改时间"`
  77. }
  78. // GetReportDailyListCount 获得今日报告数量
  79. func GetReportDailyListCount() (count int, err error) {
  80. o := orm.NewOrmUsingDB("rddp")
  81. sql := ` SELECT COUNT(*) AS count FROM report WHERE 1=1 AND (state=2 OR state=6) AND DATE(publish_time)=DATE(NOW()) `
  82. err = o.Raw(sql).QueryRow(&count)
  83. return
  84. }
  85. // func GetReportDailyList(startSize, pageSize int) (items []*ReportList, err error) {
  86. // o := orm.NewOrmUsingDB("rddp")
  87. // sql := ` SELECT a.id,a.add_type,a.classify_id_first,a.classify_name_first,a.classify_id_second,a.classify_name_second,a.title,a.abstract,a.author,a.frequency,
  88. // a.create_time,a.modify_time,a.state,a.publish_time,a.stage,a.msg_is_send,b.id AS classify_id,b.classify_name,b.descript,b.report_author,b.author_descript,
  89. // b.report_img_url,b.head_img_url,b.avatar_img_url,b.column_img_url,a.video_url,a.video_name,a.video_play_seconds,a.video_size,
  90. // CASE WHEN DATE(a.publish_time)=DATE(NOW()) THEN 1 ELSE 0 END AS is_current_date
  91. // FROM report AS a
  92. // INNER JOIN classify AS b ON a.classify_id_second=b.id
  93. // WHERE (a.state=2 OR a.state=6) AND DATE(a.publish_time)=DATE(NOW())
  94. // ORDER BY a.publish_time DESC LIMIT ?,? `
  95. // _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  96. // return
  97. // }
  98. func GetReportDailyList(startSize, pageSize int) (items []*ReportList, err error) {
  99. o := orm.NewOrmUsingDB("rddp")
  100. sql := ` SELECT * FROM report WHERE (state=2 OR state=6) AND DATE(publish_time)=DATE(NOW()) ORDER BY publish_time DESC LIMIT ?,? `
  101. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  102. return
  103. }
  104. // GetReportRecentListCount 获得报告数量
  105. func GetReportRecentListCount() (count int, err error) {
  106. o := orm.NewOrmUsingDB("rddp")
  107. sql := ` SELECT COUNT(*) AS count FROM report
  108. WHERE 1=1 AND (state=2 OR state=6) AND classify_id_second IN (
  109. SELECT DISTINCT classify_id
  110. FROM chart_permission_search_key_word_mapping
  111. )`
  112. err = o.Raw(sql).QueryRow(&count)
  113. return
  114. }
  115. func GetReportRecentList(startSize, pageSize int) (items []*ReportList, err error) {
  116. o := orm.NewOrmUsingDB("rddp")
  117. sql := ` SELECT * FROM report WHERE (state=2 OR state=6) ORDER BY publish_time DESC LIMIT ?,? `
  118. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  119. return
  120. }
  121. func GetReportCountByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds []int, condition string) (count int, err error) {
  122. if len(classifyFirstIds) == 0 && len(classifySecondIds) == 0 && len(classifyThirdIds) == 0 {
  123. return
  124. }
  125. o := orm.NewOrmUsingDB("rddp")
  126. sql := `SELECT COUNT(*) AS count FROM report AS a WHERE (a.state=2 OR a.state=6) AND (1=2 `
  127. if len(classifyFirstIds) > 0 {
  128. sql += fmt.Sprintf(" OR a.classify_id_first IN (%s) ", utils.GetOrmReplaceHolder(len(classifyFirstIds)))
  129. }
  130. if len(classifySecondIds) > 0 {
  131. sql += fmt.Sprintf(" OR a.classify_id_second IN (%s) ", utils.GetOrmReplaceHolder(len(classifySecondIds)))
  132. }
  133. if len(classifyThirdIds) > 0 {
  134. sql += fmt.Sprintf(" OR a.classify_id_third IN (%s) ", utils.GetOrmReplaceHolder(len(classifyThirdIds)))
  135. }
  136. sql += ` ) `
  137. if condition != "" {
  138. sql += condition
  139. }
  140. err = o.Raw(sql, classifyFirstIds, classifySecondIds, classifyThirdIds).QueryRow(&count)
  141. return
  142. }
  143. func GetPushReportCountByClassifyIds(reportType int, classifyFirstIds, classifySecondIds, classifyThirdIds []int, condition string) (count int, err error) {
  144. if len(classifyFirstIds) == 0 && len(classifySecondIds) == 0 && len(classifyThirdIds) == 0 {
  145. return
  146. }
  147. o := orm.NewOrm()
  148. sql := `SELECT COUNT(*) AS count FROM report_push_status WHERE state=1 AND report_type=? AND (1=2 `
  149. if len(classifyFirstIds) > 0 {
  150. sql += fmt.Sprintf(" OR classify_id_first IN (%s) ", utils.GetOrmReplaceHolder(len(classifyFirstIds)))
  151. }
  152. if len(classifySecondIds) > 0 {
  153. sql += fmt.Sprintf(" OR classify_id_second IN (%s) ", utils.GetOrmReplaceHolder(len(classifySecondIds)))
  154. }
  155. if len(classifyThirdIds) > 0 {
  156. sql += fmt.Sprintf(" OR classify_id_third IN (%s) ", utils.GetOrmReplaceHolder(len(classifyThirdIds)))
  157. }
  158. sql += ` ) `
  159. if condition != "" {
  160. sql += condition
  161. }
  162. err = o.Raw(sql, reportType, classifyFirstIds, classifySecondIds, classifyThirdIds).QueryRow(&count)
  163. return
  164. }
  165. func GetPushReportListByClassifyIds(reportType int, classifyFirstIds, classifySecondIds, classifyThirdIds []int, condition string, startSize, pageSize int) (items []*ReportPushView, err error) {
  166. if len(classifyFirstIds) == 0 && len(classifySecondIds) == 0 && len(classifyThirdIds) == 0 {
  167. return
  168. }
  169. o := orm.NewOrm()
  170. sql := `SELECT * FROM report_push_status WHERE state=1 AND report_type=? AND (1=2 `
  171. // AND (a.classify_id_first IN (%s) OR a.classify_id_second IN (%s) OR a.classify_id_third IN (%s)) `
  172. if len(classifyFirstIds) > 0 {
  173. sql += fmt.Sprintf(" OR classify_id_first IN (%s) ", utils.GetOrmReplaceHolder(len(classifyFirstIds)))
  174. }
  175. if len(classifySecondIds) > 0 {
  176. sql += fmt.Sprintf(" OR classify_id_second IN (%s) ", utils.GetOrmReplaceHolder(len(classifySecondIds)))
  177. }
  178. if len(classifyThirdIds) > 0 {
  179. sql += fmt.Sprintf(" OR classify_id_third IN (%s) ", utils.GetOrmReplaceHolder(len(classifyThirdIds)))
  180. }
  181. sql += `) `
  182. if condition != "" {
  183. sql += condition
  184. }
  185. sql += ` ORDER BY publish_time DESC LIMIT ?,? `
  186. _, err = o.Raw(sql, reportType, classifyFirstIds, classifySecondIds, classifyThirdIds, startSize, pageSize).QueryRows(&items)
  187. return
  188. }
  189. func GetPushReportCount(reportType int, classifyIds []int, dateCondition string) (count int, err error) {
  190. o := orm.NewOrm()
  191. sql := ` SELECT COUNT(*) AS count FROM report_push_status WHERE state=1 AND report_type=? `
  192. var pars []interface{}
  193. if len(classifyIds) > 0 {
  194. sql += ` AND (classify_id_first IN (%s) OR classify_id_second IN (%s) OR classify_id_third IN (%s)) `
  195. sql = fmt.Sprintf(sql, utils.GetOrmReplaceHolder(len(classifyIds)), utils.GetOrmReplaceHolder(len(classifyIds)), utils.GetOrmReplaceHolder(len(classifyIds)))
  196. pars = append(pars, classifyIds, classifyIds, classifyIds)
  197. }
  198. if dateCondition != "" {
  199. sql += dateCondition
  200. }
  201. tmpPars := []interface{}{reportType}
  202. tmpPars = append(tmpPars, pars...)
  203. err = o.Raw(sql, tmpPars).QueryRow(&count)
  204. return
  205. }
  206. func GetPushReportListByPage(reportType int, classifyIds []int, dateCondition string, startSize, pageSize int) (items []*ReportPushView, err error) {
  207. o := orm.NewOrm()
  208. sql := ` SELECT * FROM report_push_status WHERE state=1 AND report_type=? `
  209. var pars []interface{}
  210. if len(classifyIds) > 0 {
  211. sql += ` AND (classify_id_first IN (%s) OR classify_id_second IN (%s) OR classify_id_third IN (%s)) `
  212. sql = fmt.Sprintf(sql, utils.GetOrmReplaceHolder(len(classifyIds)), utils.GetOrmReplaceHolder(len(classifyIds)), utils.GetOrmReplaceHolder(len(classifyIds)))
  213. pars = append(pars, classifyIds, classifyIds, classifyIds)
  214. }
  215. if dateCondition != "" {
  216. sql += dateCondition
  217. }
  218. sql += ` ORDER BY publish_time DESC LIMIT ?,? `
  219. _, err = o.Raw(sql, reportType, pars, startSize, pageSize).QueryRows(&items)
  220. return
  221. }
  222. func GetReportByClassifyIds(classifyIds []int, condition string) (count int, err error) {
  223. if len(classifyIds) == 0 {
  224. return
  225. }
  226. o := orm.NewOrmUsingDB("rddp")
  227. sql := `SELECT COUNT(*) AS count FROM report AS a
  228. WHERE (a.state=2 OR a.state=6) AND a.classify_id_second IN (%s) `
  229. sql = fmt.Sprintf(sql, utils.GetOrmReplaceHolder(len(classifyIds)))
  230. if condition != "" {
  231. sql += condition
  232. }
  233. err = o.Raw(sql, classifyIds).QueryRow(&count)
  234. return
  235. }
  236. func GetReportListByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds []int, condition string, startSize, pageSize int) (items []*ReportList, err error) {
  237. if len(classifyFirstIds) == 0 && len(classifySecondIds) == 0 && len(classifyThirdIds) == 0 {
  238. return
  239. }
  240. o := orm.NewOrmUsingDB("rddp")
  241. sql := `SELECT a.id,a.add_type,a.classify_id_first,a.classify_name_first,a.classify_id_second,a.classify_name_second,a.title,a.abstract,a.author,a.frequency,
  242. a.create_time,a.modify_time,a.state,a.publish_time,a.stage,a.msg_is_send,b.id AS classify_id,b.classify_name,b.descript,b.report_author,b.author_descript,
  243. b.report_img_url,b.head_img_url,b.avatar_img_url,b.column_img_url,a.video_url,a.video_name,a.video_play_seconds,a.video_size,
  244. CASE WHEN DATE(a.modify_time)=DATE(NOW()) THEN 1 ELSE 0 END AS is_current_date
  245. FROM report AS a
  246. INNER JOIN classify AS b ON a.classify_id_second=b.id
  247. WHERE (a.state=2 OR a.state=6) AND (1=2 `
  248. // AND (a.classify_id_first IN (%s) OR a.classify_id_second IN (%s) OR a.classify_id_third IN (%s)) `
  249. if len(classifyFirstIds) > 0 {
  250. sql += fmt.Sprintf(" OR a.classify_id_first IN (%s) ", utils.GetOrmReplaceHolder(len(classifyFirstIds)))
  251. }
  252. if len(classifySecondIds) > 0 {
  253. sql += fmt.Sprintf(" OR a.classify_id_second IN (%s) ", utils.GetOrmReplaceHolder(len(classifySecondIds)))
  254. }
  255. if len(classifyThirdIds) > 0 {
  256. sql += fmt.Sprintf(" OR a.classify_id_third IN (%s) ", utils.GetOrmReplaceHolder(len(classifyThirdIds)))
  257. }
  258. sql += `) `
  259. if condition != "" {
  260. sql += condition
  261. }
  262. sql += ` ORDER BY a.publish_time DESC LIMIT ?,? `
  263. _, err = o.Raw(sql, classifyFirstIds, classifySecondIds, classifyThirdIds, startSize, pageSize).QueryRows(&items)
  264. return
  265. }
  266. type ReportDetail struct {
  267. Id int `description:"报告Id"`
  268. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  269. ClassifyIdFirst int `description:"一级分类id"`
  270. ClassifyNameFirst string `description:"一级分类名称"`
  271. ClassifyIdSecond int `description:"二级分类id"`
  272. ClassifyNameSecond string `description:"二级分类名称"`
  273. ClassifyIdThird int `description:"三级分类id"`
  274. ClassifyNameThird string `description:"三级分类名称"`
  275. Title string `description:"标题"`
  276. Abstract string `description:"摘要"`
  277. Author string `description:"作者"`
  278. Frequency string `description:"频度"`
  279. CreateTime string `description:"创建时间"`
  280. ModifyTime string `description:"修改时间"`
  281. State int `description:"1:未发布,2:已发布"`
  282. PublishTime string `description:"发布时间"`
  283. Stage int `description:"期数"`
  284. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  285. Content string `description:"内容"`
  286. ChapterContent []*ReportChapter `description:"章节内容"`
  287. VideoUrl string `description:"音频文件URL"`
  288. VideoName string `description:"音频文件名称"`
  289. VideoPlaySeconds string `description:"音频播放时长"`
  290. VideoSize string `description:"音频文件大小,单位M"`
  291. ContentSub string `description:"内容前两个章节"`
  292. IsShowNewLabel int `description:"是否显示新标签"`
  293. IsCurrentDate int `description:"是否当前日期"`
  294. ClassifyName string `description:"分类名称"`
  295. TitleType string `description:"标题类型,FICC或者权益"`
  296. IsPublic bool `description:"是否是公共报告 "`
  297. HeadResourceId int `description:"版头资源库id"`
  298. EndResourceId int `description:"版尾资源库id"`
  299. HeadResource *SmartReportResource `description:"版头资源库"`
  300. EndResource *SmartReportResource `description:"版尾资源库"`
  301. CollaborateType int `description:"合作类型, 1:个人,2:多人协作"`
  302. ReportLayout int `description:"报告布局, 1:常规布局,2:智能布局"`
  303. HasChapter int `description:"是否有章节: 0-否 1-是"`
  304. }
  305. type ReportChapter struct {
  306. Title string `description:"章节标题"`
  307. Content string `description:"章节内容"`
  308. }
  309. func GetReportChapterList(reportId int) (items []*ReportChapter, err error) {
  310. o := orm.NewOrmUsingDB("rddp")
  311. sql := `SELECT * FROM report_chapter WHERE report_id=? ORDER BY sort ASC`
  312. _, err = o.Raw(sql, reportId).QueryRows(&items)
  313. return
  314. }
  315. func GetReportById(reportId int) (item *ReportDetail, err error) {
  316. o := orm.NewOrmUsingDB("rddp")
  317. sql := `SELECT * FROM report WHERE (state=2 OR state=6) AND id=?`
  318. err = o.Raw(sql, reportId).QueryRow(&item)
  319. return
  320. }
  321. type ReportCollectListItem struct {
  322. ReportId int `description:"报告Id"`
  323. ReportChapterId int `description:"报告章节Id"`
  324. ClassifyIdFirst int `description:"一级分类id"`
  325. ClassifyNameFirst string `description:"一级分类名称" `
  326. ClassifyIdSecond int `description:"二级分类id"`
  327. ClassifyNameSecond string `description:"二级分类名称"`
  328. ReportChapterTypeId int `description:"报告章节类型id"`
  329. PublishTime time.Time `description:"发布时间"`
  330. Title string `description:"标题"`
  331. ContentSub string `description:"内容前两个章节"`
  332. Abstract string `description:"摘要"`
  333. Stage string `description:"期数"`
  334. Author string `description:"作者"`
  335. PdfUrl string `description:"pdf文件url"`
  336. ReportType int `description:"报告类型:1:eta报告,2:小程序pdf报告"`
  337. }
  338. type SmartReportResource struct {
  339. ResourceId int `description:"资源库id"`
  340. ImgUrl string `description:"图片url"`
  341. Type int `description:"资源类型:1-版头 2-版尾"`
  342. Style string `description:"版图样式"`
  343. }
  344. func GetSmartReportResourceById(resourceId int) (item *SmartReportResource, err error) {
  345. o := orm.NewOrmUsingDB("rddp")
  346. sql := `SELECT * FROM smart_report_resource WHERE resource_id=?`
  347. err = o.Raw(sql, resourceId).QueryRow(&item)
  348. return
  349. }