article.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. )
  5. type ArticleDetail struct {
  6. ArticleId int `description:"报告id"`
  7. ArticleIdMd5 string `description:"报告MD5id"`
  8. IsReport int `description:"是否属于报告,1是,0否"`
  9. Title string `description:"标题"`
  10. CategoryName string `description:"一级分类"`
  11. CategoryId int `description:"分类ID"`
  12. CreateDate string `description:"创建时间"`
  13. PublishDate string `description:"发布时间"`
  14. Body string `description:"内容"`
  15. Abstract string `description:"摘要"`
  16. Annotation string `description:"核心观点"`
  17. IsInterviewApply bool `description:"是否申请访谈:true,已申请,false:未申请"`
  18. InterviewApplyStatus string `description:"当前访谈申请状态:'待邀请','待访谈','已完成','已取消'"`
  19. IsFollow bool `description:"是否关注,1是,0否"`
  20. FollowNum int `description:"关注数量"`
  21. IsCollect bool `description:"是否收藏:true,已收藏,false:未收藏"`
  22. CollectionNum int `description:"收藏数量"`
  23. DepartmentId int `description:"作者ID"`
  24. DepartmentImgUrl string `description:"作者头像"`
  25. NickName string `description:"作者昵称"`
  26. HttpUrl string `description:"文章链接跳转地址"`
  27. IsNeedJump bool `description:"是否需要跳转链接地址"`
  28. Seller SellerResp `description:"作者昵称"`
  29. DepartmentDetail *DepartmentResp `description:"作者昵称"`
  30. Disclaimers string `description:"免责声明"`
  31. IsSpecialArticle bool `description:"是否属于专项调研报告"`
  32. SubCategoryName string `description:"二级分类"`
  33. ArticleTypeId int `description:"文章类型ID"`
  34. }
  35. type SellerResp struct {
  36. SellerMobile string `description:"销售手机号"`
  37. SellerName string `description:"销售名称"`
  38. }
  39. type ArticleDetailResp struct {
  40. Mobile string `description:"用户手机号"`
  41. PopupMsg string `description:"权限弹窗信息"`
  42. SellerMobile string `description:"销售电话"`
  43. SellerName string `description:"销售姓名"`
  44. Detail *ArticleDetail
  45. IsSpecialArticle bool `description:"是否属于专项调研报告"`
  46. HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  47. }
  48. func GetArticleDetailById(articleId int) (item *ArticleDetail, err error) {
  49. o := orm.NewOrm()
  50. sql := `SELECT * FROM cygx_article WHERE article_id = ? AND publish_status = 1 `
  51. err = o.Raw(sql, articleId).QueryRow(&item)
  52. return
  53. }
  54. func GetArticlePermission(companyId int) (item *ChartPermission, err error) {
  55. o := orm.NewOrm()
  56. sql := `SELECT
  57. a.chart_permission_name as permission_name
  58. FROM
  59. cygx_report_mapping AS a
  60. WHERE
  61. a.category_id = ?`
  62. err = o.Raw(sql, companyId).QueryRow(&item)
  63. return
  64. }
  65. type ArticleFollowDetail struct {
  66. DNum int `description:"作者被关注的数量"`
  67. MdNum int `description:"本人是否关注这个作者"`
  68. AcNum int `description:"文章被收藏的数量"`
  69. MacNum int `description:"本人是否收藏这个文章"`
  70. }
  71. // 获取文章被关注被收藏的详情
  72. func GetArticleFollowDetail(articleId, uid int) (item *ArticleFollowDetail, err error) {
  73. //d_num 作者被关注的数量 、 md_num 本人是否关注这个作者 、ac_num 文章被收藏的数量 、 mac_num 本人是否收藏这个文章
  74. o := orm.NewOrm()
  75. sql := ` SELECT
  76. ( SELECT count( 1 ) FROM cygx_article_department_follow AS af INNER JOIN wx_user as u ON u.user_id = af.user_id WHERE af.department_id = art.department_id AND af.type = 1 ) AS d_num,
  77. ( SELECT count( 1 ) FROM cygx_article_department_follow AS af WHERE af.department_id = art.department_id AND af.type = 1 AND af.user_id = ? ) AS md_num,
  78. ( SELECT count( 1 ) FROM cygx_article_collect AS ac INNER JOIN wx_user as u ON u.user_id = ac.user_id WHERE ac.article_id = art.article_id ) AS ac_num,
  79. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = art.article_id AND ac.user_id = ? ) AS mac_num
  80. FROM
  81. cygx_article AS art
  82. LEFT JOIN cygx_article_department_follow AS af ON af.department_id = art.department_id
  83. LEFT JOIN cygx_article_collect AS ac ON ac.article_id = art.article_id
  84. WHERE
  85. art.article_id = ?
  86. GROUP BY art.article_id `
  87. err = o.Raw(sql, uid, uid, articleId).QueryRow(&item)
  88. return
  89. }
  90. func GetArticleCountById(articleId int) (count int, err error) {
  91. o := orm.NewOrm()
  92. sql := `SELECT COUNT(1) AS count FROM cygx_article WHERE article_id = ? `
  93. err = o.Raw(sql, articleId).QueryRow(&count)
  94. return
  95. }
  96. // 用户收藏榜start
  97. type ArticleCollectionResp struct {
  98. ArticleId int `description:"文章id"`
  99. Title string `description:"标题"`
  100. PublishDate string `description:"发布时间"`
  101. DepartmentId int `description:"作者Id"`
  102. NickName string `description:"作者昵称"`
  103. IsCollect bool `description:"本人是否收藏"`
  104. Pv int `description:"PV"`
  105. CollectNum int `description:"收藏人数"`
  106. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  107. List []*IndustrialManagementResp `description:"产业列表"`
  108. Body string `description:"内容"`
  109. Abstract string `description:"摘要"`
  110. Annotation string `description:"核心观点"`
  111. CategoryName string `description:"一级分类"`
  112. SubCategoryName string `description:"二级分类"`
  113. IsResearch bool `description:"是否属于研选"`
  114. ImgUrlPc string `description:"图片链接"`
  115. CategoryId string `description:"文章分类"`
  116. HttpUrl string `description:"文章链接跳转地址"`
  117. IsNeedJump bool `description:"是否需要跳转链接地址"`
  118. MyCollectNum int `description:"本人是否收藏数量"`
  119. ArticleTypeId int `description:"文章类型ID"`
  120. }
  121. // 列表
  122. func GetArticleCollectionList(condition string, userId int) (items []*ArticleCollectionResp, err error) {
  123. o := orm.NewOrm()
  124. sql := `SELECT
  125. a.article_id,
  126. a.title,
  127. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  128. m.industry_name,
  129. m.industrial_management_id,
  130. d.nick_name,
  131. d.department_id,
  132. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  133. ( SELECT count( 1 ) FROM cygx_article_collect AS ac INNER JOIN wx_user as u ON u.user_id = ac.user_id WHERE ac.article_id = a.article_id ) AS collect_num,
  134. ( SELECT count( 1 ) FROM cygx_article_collect AS ac INNER JOIN wx_user as u ON u.user_id = ac.user_id WHERE ac.article_id = a.article_id AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time ) ) AS collect_num_order,
  135. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ? ) AS my_collect_num
  136. FROM
  137. cygx_article AS a
  138. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  139. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  140. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  141. WHERE
  142. 1 = 1 AND a.publish_status = 1 `
  143. if condition != "" {
  144. sql += condition
  145. }
  146. _, err = o.Raw(sql, userId).QueryRows(&items)
  147. return
  148. } //end
  149. type ArticleCollectionLIstResp struct {
  150. List []*ArticleCollectionResp
  151. }
  152. type CygxArticleEs struct {
  153. Id int `orm:"column(id);pk"`
  154. ArticleId int `description:"文章id"`
  155. Title string `description:"标题"`
  156. TitleEn string `description:"英文标题 "`
  157. UpdateFrequency string `description:"更新周期"`
  158. CreateDate string `description:"创建时间"`
  159. PublishDate string `description:"发布时间"`
  160. Body string `description:"内容"`
  161. BodyText string `description:"内容"`
  162. Abstract string `description:"摘要"`
  163. CategoryName string `description:"一级分类"`
  164. SubCategoryName string `description:"二级分类"`
  165. PublishStatus int `description:"发布状态"`
  166. CategoryId string `description:"分类id"`
  167. ExpertBackground string `description:"专家背景"`
  168. ExpertNumber string `description:"专家编号"`
  169. InterviewDate string `description:"访谈日期"`
  170. Department string `description:"作者"`
  171. ArticleIdMd5 string `description:"ID,md5值"`
  172. IsClass int `description:"是否归类,1是,0否"`
  173. IsSummary bool `description:"是否是纪要库,1是,0否"`
  174. IsReport bool `description:"是否属于报告,1是,0否"`
  175. ReportType int `description:"报告类型,1行业报告,2产业报告,0无"`
  176. FileLink string `description:"下载预览链接"`
  177. MatchTypeName string `description:"匹配类型"`
  178. }
  179. // 获取文章列表
  180. func GetArticleList(condition string, pars []interface{}) (items []*ArticleDetail, err error) {
  181. o := orm.NewOrm()
  182. sql := `SELECT article_id FROM cygx_article WHERE 1= 1 ` + condition
  183. _, err = o.Raw(sql, pars).QueryRows(&items)
  184. return
  185. }
  186. func GetArticleDetailByIdStr(articleIdStr string) (items []*ArticleDetail, err error) {
  187. o := orm.NewOrm()
  188. sql := `SELECT art.*,d.nick_name FROM
  189. cygx_article AS art
  190. LEFT JOIN cygx_article_department AS d ON d.department_id = art.department_id WHERE article_id IN(` + articleIdStr + `) `
  191. _, err = o.Raw(sql).QueryRows(&items)
  192. return
  193. }
  194. // 检查用户是否阅读某一分类最新文章
  195. func GetUserIsReadThisNewCategoryArticleCount(categoryId, uid int) (count int, err error) {
  196. sqlCount := `SELECT COUNT(1) as count FROM
  197. cygx_article_history_record
  198. WHERE
  199. article_id = ( SELECT article_id FROM cygx_article WHERE category_id = ? ORDER BY publish_date DESC LIMIT 0, 1 )
  200. AND user_id = ?`
  201. o := orm.NewOrm()
  202. err = o.Raw(sqlCount, categoryId, uid).QueryRow(&count)
  203. return
  204. }
  205. // 获取最新文章
  206. func GetNewArticleByCategoryId(categoryId int) (item *ArticleDetail, err error) {
  207. o := orm.NewOrm()
  208. sql := ` SELECT * FROM cygx_article WHERE category_id = ? ORDER BY publish_date DESC LIMIT 0, 1`
  209. err = o.Raw(sql, categoryId).QueryRow(&item)
  210. return
  211. }
  212. func GetArticleDetailByIdMd5(articleIdMd5 string) (item *ArticleDetail, err error) {
  213. o := orm.NewOrm()
  214. sql := `SELECT * FROM cygx_article WHERE article_id_md5 = ? `
  215. err = o.Raw(sql, articleIdMd5).QueryRow(&item)
  216. return
  217. }
  218. type SummaryArticleStock struct {
  219. Id int `description:"新ID"`
  220. ArticleId int `description:"文章id"`
  221. Stock string `description:"个股标签"`
  222. }
  223. type SummaryArticleStockResp struct {
  224. List []*SummaryArticleStock
  225. }
  226. // 综述报告
  227. func GetArticleStock() (items []*SummaryArticleStock, err error) {
  228. o := orm.NewOrm()
  229. sql := `SELECT
  230. stock,article_id
  231. FROM
  232. cygx_article AS art
  233. WHERE
  234. 1 = 1
  235. AND type_name = '综述报告' `
  236. _, err = o.Raw(sql).QueryRows(&items)
  237. return
  238. }