industrial_article_group_management.go 8.3 KB

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