report.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "strconv"
  6. )
  7. type IndustrialManagementList struct {
  8. Paging *paging.PagingItem
  9. List []*IndustrialManagement
  10. }
  11. type IndustrialManagement struct {
  12. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  13. IndustryName string `description:"产业名称"`
  14. ChartPermissionId int `description:"权限id"`
  15. ChartPermissionName string `description:"权限名称"`
  16. LayoutTime string `description:"布局时间"`
  17. UpdateTime string `description:"更新时间"`
  18. IsRed bool `description:"是否标记红点"`
  19. IsHot bool `description:"是否是热门"`
  20. IsFollow bool `description:"是否关注"`
  21. IsNew bool `description:"是否展示 NEW 标签"`
  22. IsShowRoadshow bool `description:"是否展示 微路演 标签"`
  23. ArticleReadNum int `description:"文章阅读数量"`
  24. ArticleId int `description:"文章id"`
  25. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  26. IndustrialSubjectList []*IndustrialSubject `description:"标的列表"`
  27. MinReportTime string `description:"报告最早发布时间"`
  28. IndustryVideo *MicroVideoSimpleInfo
  29. AuthInfo *UserPermissionAuthInfo
  30. }
  31. type MicroVideoSimpleInfo struct {
  32. Id int `description:"视频ID"`
  33. Title string `description:"标题"`
  34. ResourceUrl string `description:"链接"`
  35. BackgroundImg string `description:"背景图"`
  36. PlaySeconds int `description:"音视频时长"`
  37. DetailImgUrl string `description:"产业详情页背景图"`
  38. ChartPermissionId int `description:"行业ID"`
  39. ChartPermissionName string `description:"行业名称"`
  40. }
  41. type TacticsListResp struct {
  42. Paging *paging.PagingItem
  43. MatchTypeName string `description:"匹配类型"`
  44. CategoryImgUrlPc string `description:"图片"`
  45. List []*HomeArticle
  46. }
  47. //报告搜索start
  48. type ReoprtSearchResp struct {
  49. Paging *paging.PagingItem
  50. ListHz []*ArticleCollectionResp `description:"弘则报告"`
  51. }
  52. //搜索资源包 start
  53. type SearchResourceResp struct {
  54. ListHz []*IndustrialManagement `description:"弘则"`
  55. }
  56. //用户收藏榜start
  57. //type IndustrialManagementHotResp struct {
  58. // IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  59. // IndustryName string `description:"产业名称"`
  60. // IsFollw bool `description:"是否关注"`
  61. // FllowNum int `description:"关注数量"`
  62. // IsNew bool `description:"是否新标签"`
  63. // IsHot bool `description:"是否新标签"`
  64. // PublishDate string `description:"发布时间"`
  65. // ArticleReadNum int `description:"文章阅读数量"`
  66. // Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  67. // IndustrialSubjectList []*IndustrialSubject `description:"标的列表"`
  68. //}
  69. //获取列表数量
  70. func GetReoprtSearchCount(condition string) (count int, err error) {
  71. o := orm.NewOrm()
  72. sql := `SELECT
  73. COUNT( 1 ) AS count
  74. FROM
  75. cygx_article AS a
  76. WHERE
  77. 1 = 1
  78. AND a.article_id < 1000000 `
  79. if condition != "" {
  80. sql += condition
  81. }
  82. err = o.Raw(sql).QueryRow(&count)
  83. return
  84. }
  85. //列表
  86. func GetReoprtSearchList(condition string, userId, startSize, pageSize int) (items []*ArticleCollectionResp, err error) {
  87. o := orm.NewOrm()
  88. sql := `SELECT
  89. a.article_id,
  90. a.title,
  91. a.body,
  92. a.abstract,
  93. a.annotation,
  94. a.category_id,
  95. a.category_name,
  96. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  97. m.industry_name,
  98. m.industrial_management_id,
  99. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  100. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  101. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ?) AS my_collect_num
  102. FROM
  103. cygx_article AS a
  104. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  105. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  106. WHERE
  107. 1 = 1 `
  108. if condition != "" {
  109. sql += condition
  110. }
  111. sql += ` GROUP BY a.article_id ORDER BY a.publish_date DESC LIMIT ?,? `
  112. _, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  113. return
  114. } //end
  115. //列表
  116. func GetSearchResourceList(condition string) (items []*IndustrialManagement, err error) {
  117. o := orm.NewOrm()
  118. sql := `SELECT
  119. m.industry_name,
  120. m.chart_permission_id,
  121. m.industrial_management_id,
  122. MAX( a.publish_date ) as publish_date_order,
  123. date_format( MAX( a.publish_date ), '%Y-%m-%d' ) AS publish_date
  124. FROM
  125. cygx_industrial_management AS m
  126. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  127. INNER JOIN cygx_article AS a ON a.article_id = mg.article_id AND a.article_type != 'lyjh'
  128. WHERE
  129. 1 = 1
  130. AND publish_status = 1 ` + condition + ` GROUP BY m.industrial_management_id ORDER BY publish_date_order DESC `
  131. _, err = o.Raw(sql).QueryRows(&items)
  132. return
  133. }
  134. //标的列表
  135. func GetThemeHeatSubjectList(condition string) (items []*IndustrialSubject, err error) {
  136. o := orm.NewOrm()
  137. sql := `SELECT
  138. m.subject_name,
  139. m.industrial_management_id,
  140. m.industrial_subject_id
  141. FROM
  142. cygx_article AS a
  143. INNER JOIN cygx_industrial_article_group_subject AS mg ON mg.article_id = a.article_id
  144. INNER JOIN cygx_industrial_subject AS m ON m.industrial_subject_id = mg.industrial_subject_id
  145. WHERE
  146. 1 = 1`
  147. if condition != "" {
  148. sql += condition
  149. }
  150. sql += ` AND publish_status = 1
  151. GROUP BY
  152. m.industrial_subject_id
  153. ORDER BY
  154. publish_date DESC`
  155. _, err = o.Raw(sql).QueryRows(&items)
  156. return
  157. } //end
  158. //产业下所关联的文章分类列表
  159. func IndustrialToArticleCategory(industrialManagementId, chartPermissionId int) (items []*IndustrialToArticleCategoryRep, err error) {
  160. o := orm.NewOrm()
  161. sql := `SELECT map.match_type_name,map.category_id
  162. FROM cygx_report_mapping AS map
  163. INNER JOIN cygx_article AS art ON art.category_id = map.category_id
  164. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = art.article_id
  165. WHERE map.report_type = 2
  166. AND map.is_report = 1
  167. AND art.is_report = 1
  168. AND art.publish_status = 1
  169. AND man_g.industrial_management_id =?
  170. AND map.chart_permission_id = ?
  171. GROUP BY map.match_type_name`
  172. _, err = o.Raw(sql, industrialManagementId, chartPermissionId).QueryRows(&items)
  173. return
  174. }
  175. //判断用户是否阅读该产业下,某一分类的文章
  176. func IndustrialUserRecordArticleCount(userId, industrialManagementId, categoryId int) (count int, err error) {
  177. o := orm.NewOrm()
  178. sql := `SELECT
  179. COUNT(1) count
  180. FROM
  181. cygx_article_history_record
  182. WHERE
  183. article_id = ( SELECT article_id FROM cygx_article WHERE article_id IN (SELECT article_id FROM cygx_industrial_article_group_management WHERE industrial_management_id = ? ) AND category_id = ? ORDER BY publish_date DESC LIMIT 0, 1 )
  184. AND user_id = ? `
  185. err = o.Raw(sql, industrialManagementId, categoryId, userId).QueryRow(&count)
  186. return
  187. }
  188. //获取最新文章
  189. func GetNewIndustrialUserRecordArticle(industrialManagementId, categoryId int) (item *ArticleDetail, err error) {
  190. o := orm.NewOrm()
  191. sql := ` SELECT * FROM cygx_article WHERE article_id IN (SELECT article_id FROM cygx_industrial_article_group_management WHERE industrial_management_id = ? ) AND category_id = ? ORDER BY publish_date DESC LIMIT 0, 1`
  192. err = o.Raw(sql, industrialManagementId, categoryId).QueryRow(&item)
  193. return
  194. }
  195. //列表
  196. func GetReoprtSearchListHz(condition string, userId int) (items []*ArticleCollectionResp, err error) {
  197. o := orm.NewOrm()
  198. sql := `SELECT
  199. a.article_id,
  200. a.title,
  201. a.annotation,
  202. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  203. m.industry_name,
  204. m.industrial_management_id,
  205. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  206. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  207. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ?) AS my_collect_num
  208. FROM
  209. cygx_article AS a
  210. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  211. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  212. WHERE
  213. 1 = 1 `
  214. if condition != "" {
  215. sql += condition
  216. }
  217. _, err = o.Raw(sql, userId).QueryRows(&items)
  218. return
  219. } //end
  220. //产业列表
  221. func GetSearchResourceListHz(condition string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
  222. o := orm.NewOrm()
  223. sql := `SELECT
  224. m.industry_name,
  225. m.industrial_management_id,
  226. MAX( a.publish_date ) as publish_date_order,
  227. date_format( MAX( a.publish_date ), '%Y-%m-%d' ) AS publish_date
  228. FROM
  229. cygx_industrial_management AS m
  230. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  231. INNER JOIN cygx_article AS a ON a.article_id = mg.article_id AND a.article_type != 'lyjh'
  232. WHERE
  233. 1 = 1
  234. AND publish_status = 1 ` + condition + ` GROUP BY m.industrial_management_id ORDER BY publish_date_order DESC `
  235. if startSize > 0 || pageSize > 0 {
  236. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  237. }
  238. _, err = o.Raw(sql).QueryRows(&items)
  239. return
  240. }
  241. //用户收藏榜start
  242. type IndustrialManagementHotResp struct {
  243. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  244. IndustryName string `description:"产业名称"`
  245. IsFollw bool `description:"是否关注"`
  246. FllowNum int `description:"关注数量"`
  247. IsNew bool `description:"是否新标签"`
  248. IsHot bool `description:"是否新标签"`
  249. PublishDate string `description:"发布时间"`
  250. ArticleReadNum int `description:"文章阅读数量"`
  251. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  252. IndustrialSubjectList []*IndustrialSubject `description:"标的列表"`
  253. }
  254. //搜索资源包 start
  255. type SearchReportAndResourceResp struct {
  256. ListHzResource []*IndustrialManagement `description:"弘则资源包"`
  257. ListHzReport []*ArticleCollectionResp `description:"弘则报告"`
  258. Paging *paging.PagingItem `description:"弘则报告分页"`
  259. }
  260. //报告收藏榜单列表
  261. func GetReportCollectionBillboardList(limit int, pars []interface{}, condition string) (items []*HomeArticle, err error) {
  262. o := orm.NewOrm()
  263. sql := `SELECT
  264. ac.id,
  265. a.article_id,
  266. a.title,
  267. date_format(a.publish_date, '%Y-%m-%d') AS publish_date,
  268. m.chart_permission_name AS permission_name,
  269. COUNT(ac.id) AS collection_num
  270. FROM
  271. cygx_article AS a
  272. INNER JOIN cygx_report_mapping AS m ON m.category_id = a.category_id
  273. INNER JOIN cygx_article_collect AS ac ON ac.article_id = a.article_id
  274. WHERE
  275. 1 = 1
  276. AND a.publish_status = 1 `
  277. if condition != "" {
  278. sql += condition
  279. }
  280. sql += ` GROUP BY a.article_id ORDER BY collection_num DESC, ac.id DESC, a.publish_date DESC`
  281. sql += ` LIMIT ?`
  282. _, err = o.Raw(sql, pars, limit).QueryRows(&items)
  283. return
  284. }