industrial_article_group_management.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "strconv"
  5. "time"
  6. )
  7. type CygxIndustrialArticleGroupManagement struct {
  8. Id int `orm:"column(id);pk" description:"主键ID"`
  9. CygxArticleId int `description:"cygx_article表的主键ID"`
  10. ArticleId int `description:"cygx_article表的文章ID"`
  11. IndustrialManagementId int `description:"cygx_industrial_management表的主键ID"`
  12. CreateTime time.Time `description:"创建时间"`
  13. }
  14. // 新增
  15. func AddCygxIndustrialArticleGroupManagement(item *CygxIndustrialArticleGroupManagement) (newId int64, err error) {
  16. o := orm.NewOrm()
  17. _, err = o.Insert(item)
  18. if err != nil {
  19. return
  20. }
  21. return
  22. }
  23. // 列表
  24. func GetIndustrialArticleGroupManagementList(articleId int) (items []*IndustrialActivityGroupManagementRep, err error) {
  25. o := orm.NewOrm()
  26. sql := `SELECT
  27. p.permission_name,
  28. p.chart_permission_id,
  29. m.industrial_management_id,
  30. m.industry_name
  31. FROM
  32. cygx_industrial_article_group_management AS am
  33. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = am.industrial_management_id
  34. INNER JOIN chart_permission AS p ON p.chart_permission_id = m.chart_permission_id
  35. WHERE
  36. am.article_id = ?`
  37. _, err = o.Raw(sql, articleId).QueryRows(&items)
  38. return
  39. }
  40. // 通过名称获取详情
  41. func GetIndustrialManagemenDetailByAaticle(articleId int) (item *CygxIndustrialArticleGroupManagement, err error) {
  42. o := orm.NewOrm()
  43. sql := `SELECT * FROM cygx_industrial_article_group_management WHERE article_id = ? `
  44. err = o.Raw(sql, articleId).QueryRow(&item)
  45. return
  46. }
  47. func GetArticleIdsByIndustrialManagementId(industrialManagementId string) (articleId string, err error) {
  48. sql := ` SELECT
  49. GROUP_CONCAT( DISTINCT article_id ORDER BY id ASC SEPARATOR ',' ) AS articleId
  50. FROM
  51. cygx_industrial_article_group_management WHERE industrial_management_id IN (` + industrialManagementId + `)`
  52. o := orm.NewOrm()
  53. err = o.Raw(sql).QueryRow(&articleId)
  54. return
  55. }
  56. type ArticleIndustrialSubjectNameResp struct {
  57. ArticleId int `description:"文章id"`
  58. IndustryName string `description:"产业名称"`
  59. SubjectNameStr string `description:"关联标的"`
  60. IndustrialManagementId int `description:"产业id"`
  61. }
  62. // 通过文章ID获取所关联的产业与标的
  63. func GetCygxArticleIndustrialSubjectName(articleIds string) (items []*ArticleIndustrialSubjectNameResp, err error) {
  64. o := orm.NewOrm()
  65. sql := ` SELECT
  66. art.article_id,
  67. (
  68. SELECT
  69. GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' )
  70. FROM
  71. cygx_industrial_subject AS s
  72. WHERE
  73. s.industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.article_id = art.article_id )
  74. ) AS subject_name_str,
  75. (
  76. SELECT
  77. GROUP_CONCAT( DISTINCT man.industry_name SEPARATOR '/' )
  78. FROM
  79. cygx_industrial_management AS man
  80. WHERE
  81. man.industrial_management_id IN ( SELECT industrial_management_id FROM cygx_industrial_article_group_management AS man_g WHERE man_g.article_id = art.article_id )
  82. ) AS industry_name
  83. FROM
  84. cygx_article AS art
  85. WHERE art.article_id IN(` + articleIds + `)`
  86. _, err = o.Raw(sql).QueryRows(&items)
  87. return
  88. }
  89. type IndustrialArticleGroupResp struct {
  90. ArticleId int `description:"活动ID"`
  91. IndustrialManagementId int `description:"cygx_industrial_management表的主键ID"`
  92. IndustryName string `description:"产业名称"`
  93. }
  94. // 通过id 获取详情
  95. func GetIndustrialManagemenDetailByAaticleID(articleId int) (items []*ArticleIndustrialSubjectNameResp, err error) {
  96. o := orm.NewOrm()
  97. sql := `SELECT
  98. article_id,
  99. m.industrial_management_id,
  100. industry_name
  101. FROM
  102. cygx_industrial_article_group_management AS mg
  103. INNER JOIN cygx_industrial_management AS m ON mg.industrial_management_id = m.industrial_management_id
  104. WHERE
  105. mg.article_id = ? `
  106. _, err = o.Raw(sql, articleId).QueryRows(&items)
  107. return
  108. }
  109. // 列表
  110. func GetIndustrialArticleGroupListByarticleIds(articleIds string) (items []*IndustrialArticleGroupResp, err error) {
  111. o := orm.NewOrm()
  112. sql := `SELECT mg.*,m.industry_name FROM
  113. cygx_industrial_article_group_management AS mg
  114. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  115. WHERE 1 = 1
  116. AND mg.article_id IN (` + articleIds + `) GROUP BY mg.article_id,mg.industrial_management_id`
  117. _, err = o.Raw(sql).QueryRows(&items)
  118. return
  119. }
  120. // 用户收藏榜start
  121. type IndustrialManagementHotResp struct {
  122. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  123. IndustryName string `description:"产业名称"`
  124. IsFollw bool `description:"是否关注"`
  125. FllowNum int `description:"关注数量"`
  126. IsNew bool `description:"是否新标签"`
  127. IsHot bool `description:"是否新标签"`
  128. IsRed bool `description:"是否标记红点"`
  129. Readnum int `description:"阅读数量"`
  130. PublishDate string `description:"发布时间"`
  131. MinReportTime string `description:"报告最早发布时间"`
  132. ArticleReadNum int `description:"文章阅读数量"`
  133. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  134. IndustrialSubjectList []*CygxIndustrialSubject `description:"标的列表"`
  135. }
  136. // 产业与文章关联列表
  137. func GetSearchResourceList(userId int, condition string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
  138. o := orm.NewOrm()
  139. sql := `SELECT
  140. m.industry_name,
  141. m.industrial_management_id,
  142. MAX( a.publish_date ) as publish_date_order,
  143. MIN(a.publish_date) AS min_report_time,
  144. date_format( MAX( a.publish_date ), '%Y-%m-%d' ) AS publish_date,
  145. (SELECT COUNT(1) FROM cygx_article_history_record AS rec WHERE rec.user_id = ` + strconv.Itoa(userId) + ` AND rec.article_id=a.article_id) AS readnum
  146. FROM
  147. cygx_industrial_management AS m
  148. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  149. INNER JOIN cygx_article AS a ON a.article_id = mg.article_id AND a.article_type != 'lyjh'
  150. WHERE
  151. 1 = 1
  152. AND publish_status = 1 ` + condition + ` GROUP BY m.industrial_management_id ORDER BY publish_date_order DESC `
  153. if startSize > 0 || pageSize > 0 {
  154. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  155. }
  156. _, err = o.Raw(sql).QueryRows(&items)
  157. return
  158. }