article.go 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "strings"
  5. "time"
  6. )
  7. type CygxArticle struct {
  8. Id int `orm:"column(id);pk"`
  9. ArticleId int `description:"文章id"`
  10. Title string `description:"标题"`
  11. TitleEn string `description:"英文标题 "`
  12. UpdateFrequency string `description:"更新周期"`
  13. CreateDate string `description:"创建时间"`
  14. PublishDate string `description:"发布时间"`
  15. Body string `description:"内容"`
  16. BodyText string `description:"内容"`
  17. Abstract string `description:"摘要"`
  18. CategoryName string `description:"一级分类"`
  19. SubCategoryName string `description:"二级分类"`
  20. PublishStatus int `description:"发布状态"`
  21. CategoryId int `description:"分类id"`
  22. CategoryIdTwo int `description:"分类id用作修改匹配类型使用"`
  23. ExpertBackground string `description:"专家背景"`
  24. ExpertNumber string `description:"专家编号"`
  25. InterviewDate string `description:"访谈日期"`
  26. Department string `description:"作者"`
  27. ArticleIdMd5 string `description:"ID,md5值"`
  28. IsClass int `description:"是否归类,1是,0否"`
  29. IsSummary int `description:"是否是纪要库,1是,0否"`
  30. IsReport int `description:"是否属于报告,1是,0否"`
  31. ReportType int `description:"报告类型,1行业报告,2产业报告,0无"`
  32. FileLink string `description:"下载预览链接"`
  33. MatchTypeName string `description:"匹配类型"`
  34. Periods string `description:"期数"`
  35. ReportLink string `description:"报告链接"`
  36. ArticleType string `description:"文章类型 文章类型,lyjh:路演精华 "`
  37. HavePublish int `description:"是否发布过,1是 ,0 否"`
  38. Source int `description:"来源 0策略平台同步,1小程序后台添加"`
  39. SellerAndMobile string `description:"销售和手机号"`
  40. VideoUrl string `description:"音频文件URL"`
  41. VideoName string `description:"音频文件名称"`
  42. VideoPlaySeconds string `description:"音频播放时长"`
  43. Stock string `description:"个股标签"`
  44. FieldName string `description:"产业标签"`
  45. Annotation string `description:"核心观点"`
  46. TypeName string `description:"策略平台报告类型"`
  47. ModifyTimeByCl string `description:"策略平台报告更新时间"`
  48. CeLueFieldId int `description:"策略平台领域ID"`
  49. Cover string `description:"封面图片"`
  50. }
  51. type CygxArticleEs struct {
  52. Id int `orm:"column(id);pk"`
  53. ArticleId int `description:"文章id"`
  54. Title string `description:"标题"`
  55. TitleEn string `description:"英文标题 "`
  56. UpdateFrequency string `description:"更新周期"`
  57. CreateDate string `description:"创建时间"`
  58. PublishDate string `description:"发布时间"`
  59. Body string `description:"内容"`
  60. BodyText string `description:"内容"`
  61. Abstract string `description:"摘要"`
  62. CategoryName string `description:"一级分类"`
  63. SubCategoryName string `description:"二级分类"`
  64. PublishStatus int `description:"发布状态"`
  65. CategoryId string `description:"分类id"`
  66. ExpertBackground string `description:"专家背景"`
  67. ExpertNumber string `description:"专家编号"`
  68. InterviewDate string `description:"访谈日期"`
  69. Department string `description:"作者"`
  70. ArticleIdMd5 string `description:"ID,md5值"`
  71. IsClass int `description:"是否归类,1是,0否"`
  72. IsSummary bool `description:"是否是纪要库,1是,0否"`
  73. IsReport bool `description:"是否属于报告,1是,0否"`
  74. ReportType int `description:"报告类型,1行业报告,2产业报告,0无"`
  75. FileLink string `description:"下载预览链接"`
  76. MatchTypeName string `description:"匹配类型"`
  77. }
  78. // 新增文章
  79. func AddCygxArticle(item *CygxArticle) (lastId int64, err error) {
  80. o := orm.NewOrm()
  81. lastId, err = o.Insert(item)
  82. return
  83. }
  84. type HomeArticle struct {
  85. ArticleId int `description:"文章id"`
  86. Title string `description:"标题"`
  87. TitleEn string `description:"英文标题 "`
  88. UpdateFrequency string `description:"更新周期"`
  89. CreateDate string `description:"创建时间"`
  90. PublishDate string `description:"发布时间"`
  91. Body string `description:"内容"`
  92. BodyHtml string `description:"内容带有HTML标签"`
  93. Abstract string `description:"摘要"`
  94. CategoryName string `description:"一级分类"`
  95. SubCategoryName string `description:"二级分类"`
  96. ExpertBackground string `description:"专家背景"`
  97. IsResearch bool `description:"是否属于研选"`
  98. Pv int `description:"PV"`
  99. ImgUrlPc string `description:"图片链接"`
  100. CategoryId string `description:"文章分类"`
  101. HttpUrl string `description:"文章链接跳转地址"`
  102. IsNeedJump bool `description:"是否需要跳转链接地址"`
  103. Source int `description:"来源 1:文章, 2:图表"`
  104. Annotation string `description:"核心观点"`
  105. HomeType int `description:"数据类型:0-纪要(默认); 1-微路演音频"`
  106. MicroAudio *MicroAudioUnionList `description:"微路演音频"`
  107. ChartPermissionName string `description:"权限名称"`
  108. ArticleTypeName string `description:"权限名称"`
  109. IsReport int `description:"是否属于报告,1是,0否"`
  110. ArticleResponse int `description:"报告类型 0:啥也不是,1研选报告,2:研选纪要,3:研选沙龙,4;研选观点"`
  111. Readnum int `description:"阅读数量"`
  112. Cover string `description:"封面图片"`
  113. BodyHighlight []string `description:"搜索高亮展示结果"`
  114. List []*IndustrialManagementIdInt
  115. }
  116. type ArticleDetail struct {
  117. ArticleId int `description:"报告id"`
  118. Title string `description:"标题"`
  119. TitleEn string `description:"英文标题 "`
  120. UpdateFrequency string `description:"更新周期"`
  121. CreateDate string `description:"创建时间"`
  122. PublishDate string `description:"发布时间"`
  123. Body string `description:"内容"`
  124. Abstract string `description:"摘要"`
  125. CategoryName string `description:"一级分类"`
  126. SubCategoryName string `description:"二级分类"`
  127. IsCollect bool `description:"是否收藏:true,已收藏,false:未收藏"`
  128. IsInterviewApply bool `description:"是否申请访谈:true,已申请,false:未申请"`
  129. BodyText string `description:"内容"`
  130. InterviewApplyStatus string `description:"当前访谈申请状态:'待邀请','待访谈','已完成','已取消'"`
  131. InterviewDate string `description:"访谈时间"`
  132. ExpertBackground string `description:"专家背景"`
  133. ExpertNumber string `description:"专家编号"`
  134. Department string `description:"作者"`
  135. SellerMobile string `description:"销售手机号"`
  136. SellerName string `description:"销售名称"`
  137. ArticleIdMd5 string `description:"纪要id"`
  138. IsClass int `description:"是否归类,1是,0否"`
  139. CategoryId int `description:"分类ID"`
  140. IsSummary int `description:"是否是纪要库,1是,0否"`
  141. IsReport int `description:"是否属于报告,1是,0否"`
  142. IsResearch bool `description:"是否属于研选"`
  143. FileLink string `description:"下载预览链接"`
  144. SellerAndMobile string `description:"销售和手机号"`
  145. IsFollow bool `description:"是否关注,1是,0否"`
  146. IsBelongSummary bool `description:"是否属于纪要库"`
  147. IsBelongReport bool `description:"是否属于报告"`
  148. FollowNum int `description:"关注数量"`
  149. CollectionNum int `description:"收藏数量"`
  150. DepartmentId int `description:"作者ID"`
  151. DepartmentImgUrl string `description:"作者头像"`
  152. NickName string `description:"作者昵称"`
  153. SubjectIds string `description:"文章关联标的的ID字符串"`
  154. IndustrialAndSubjectIds string `description:"文章关联产业和标的的ID字符串"`
  155. IndustrialManagementId int `description:"文章关联产业ID"`
  156. SellerList []*SellerRep
  157. HttpUrl string `description:"文章链接跳转地址"`
  158. IsNeedJump bool `description:"是否需要跳转链接地址"`
  159. ReportLink string `description:"报告链接"`
  160. IsShowLinkButton int `description:"这种报告类型是否展示查看报告链接"`
  161. ArticleTypeId int `description:"文章类型ID"`
  162. IsSpecialArticle bool `description:"是否属于专项调研报告"`
  163. Annotation string `description:"核心观点"`
  164. IsShowFollowButton bool `description:"是否展示关注取关按钮"`
  165. IsFollowButton bool `description:"是否关注"`
  166. IsRoadShow bool `description:"是否是路演精华"`
  167. ReportType int `description:"报告类型,1行业报告,2产业报告,0无"`
  168. }
  169. type ArticleDetailFileLink struct {
  170. FileLink string `description:"下载预览链接"`
  171. Scene string `description:"资源参数"`
  172. }
  173. type SellerRep struct {
  174. SellerMobile string `description:"销售手机号"`
  175. SellerName string `description:"销售名称"`
  176. }
  177. func GetArticleDetailById(articleId int) (item *ArticleDetail, err error) {
  178. o := orm.NewOrm()
  179. sql := `SELECT * FROM cygx_article WHERE article_id = ? AND publish_status = 1 `
  180. err = o.Raw(sql, articleId).QueryRow(&item)
  181. return
  182. }
  183. func GetSellerList(articleId int) (items []*SellerRep, err error) {
  184. o := orm.NewOrm()
  185. sql := `SELECT
  186. au.mobile as seller_mobile,
  187. au.name as seller_name
  188. FROM
  189. cygx_article_author AS au
  190. WHERE article_id = ?`
  191. _, err = o.Raw(sql, articleId).QueryRows(&items)
  192. return
  193. }
  194. func GetArticleDetailByIdMd5(articleIdMd5 string) (item *ArticleDetail, err error) {
  195. o := orm.NewOrm()
  196. sql := `SELECT * FROM cygx_article WHERE article_id_md5 = ? `
  197. err = o.Raw(sql, articleIdMd5).QueryRow(&item)
  198. return
  199. }
  200. func GetArticleDetailByIdStr(articleIdStr string) (items []*ArticleDetail, err error) {
  201. o := orm.NewOrm()
  202. sql := `SELECT art.*,d.nick_name FROM
  203. cygx_article AS art
  204. LEFT JOIN cygx_article_department AS d ON d.department_id = art.department_id WHERE article_id IN(` + articleIdStr + `) `
  205. _, err = o.Raw(sql).QueryRows(&items)
  206. return
  207. }
  208. func GetArticlePermission(companyId int) (item *ChartPermission, err error) {
  209. o := orm.NewOrm()
  210. sql := `SELECT
  211. a.chart_permission_name as permission_name
  212. FROM
  213. cygx_report_mapping AS a
  214. WHERE
  215. a.category_id = ? LIMIT 1 `
  216. err = o.Raw(sql, companyId).QueryRow(&item)
  217. //_, err = o.Raw(sql, companyId).QueryRows(&item)
  218. return
  219. }
  220. type ArticleDetailResp struct {
  221. Detail *ArticleDetail
  222. HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  223. HasFree int `description:"1:已付费(至少包含一个品类的权限),2:未付费(没有任何品类权限)"`
  224. HaveResearch bool `description:"是否有研选权限"`
  225. Mobile string `description:"用户手机号"`
  226. PopupMsg string `description:"权限弹窗信息"`
  227. SellerMobile string `description:"销售电话"`
  228. SellerName string `description:"销售姓名"`
  229. IsSpecialArticle bool `description:"是否属于专项调研报告"`
  230. IsResearch bool `description:"是否属于研选"`
  231. }
  232. type ArticleDetailHtgjResp struct {
  233. HasPermission int `description:"1:有该行业权限,正常展示,0:试用期已过期"`
  234. CompanyName string `description:"公司名称"`
  235. Detail *ArticleDetail
  236. }
  237. func ModifyArticleExpert(articleId int, expertNumStr, expertContentStr, interviewDateStr, bodyText string) (err error) {
  238. o := orm.NewOrm()
  239. sql := `UPDATE cygx_article SET expert_background=?,expert_number=?,interview_date=?,body_text=? WHERE article_id=? `
  240. _, err = o.Raw(sql, expertContentStr, expertNumStr, interviewDateStr, bodyText, articleId).Exec()
  241. return
  242. }
  243. // 更改文章发布状态
  244. func UpdateArticlePublish(articleId, publishStatus int) (err error) {
  245. o := orm.NewOrm()
  246. sql := `UPDATE cygx_article SET publish_status=? WHERE article_id=? `
  247. _, err = o.Raw(sql, publishStatus, articleId).Exec()
  248. return
  249. }
  250. type ArticleDetailTest struct {
  251. ArticleId int `description:"报告id"`
  252. Title string `description:"标题"`
  253. BodyText string `description:"内容"`
  254. Body string `json:"-" description:"内容"`
  255. }
  256. func GetArticleDetailTestById(articleId int) (item *ArticleDetail, err error) {
  257. o := orm.NewOrm()
  258. sql := `SELECT * FROM cygx_article WHERE article_id = ? `
  259. err = o.Raw(sql, articleId).QueryRow(&item)
  260. return
  261. }
  262. func GetArticleAll() (item []*ArticleDetail, err error) {
  263. o := orm.NewOrm()
  264. //sql := `SELECT * FROM cygx_article WHERE 1=1 is_summary=1`
  265. sql := `SELECT * FROM cygx_article WHERE 1=1 AND publish_status = 1 `
  266. _, err = o.Raw(sql).QueryRows(&item)
  267. return
  268. }
  269. func GetArticleAllDate(endDate string) (item []*ArticleDetail, err error) {
  270. o := orm.NewOrm()
  271. //sql := `SELECT * FROM cygx_article WHERE is_summary=1 AND publish_date >= ? `
  272. sql := `SELECT * FROM cygx_article WHERE 1=1 AND publish_date >= ? `
  273. _, err = o.Raw(sql, endDate).QueryRows(&item)
  274. return
  275. }
  276. func GetArticleAll2() (item []*ArticleDetail, err error) {
  277. o := orm.NewOrm()
  278. sql := `SELECT * FROM cygx_article `
  279. _, err = o.Raw(sql).QueryRows(&item)
  280. return
  281. }
  282. // 获取文章列表
  283. func GetArticleList(condition string, pars []interface{}) (items []*ArticleDetail, err error) {
  284. o := orm.NewOrm()
  285. sql := `SELECT * FROM cygx_article WHERE 1= 1 ` + condition
  286. _, err = o.Raw(sql, pars).QueryRows(&items)
  287. return
  288. }
  289. func ModifyArticleContent(articleId int, content, expertNumStr, expertContentStr, interviewDateStr string) (err error) {
  290. o := orm.NewOrm()
  291. sql := `UPDATE cygx_article SET body=?,expert_background=?,expert_number=?,interview_date=? WHERE article_id=? `
  292. _, err = o.Raw(sql, content, expertContentStr, expertNumStr, interviewDateStr, articleId).Exec()
  293. return
  294. }
  295. type ElasticArticleDetail struct {
  296. ArticleId int `description:"报告id"`
  297. Title string `description:"标题"`
  298. TitleEn string `description:"英文标题 "`
  299. UpdateFrequency string `description:"更新周期"`
  300. CreateDate string `description:"创建时间"`
  301. PublishDate string `description:"发布时间"`
  302. Abstract string `description:"摘要"`
  303. CategoryName string `description:"一级分类"`
  304. SubCategoryName string `description:"二级分类"`
  305. IsCollect bool `description:"是否收藏:true,已收藏,false:未收藏"`
  306. IsInterviewApply bool `description:"是否申请访谈:true,已申请,false:未申请"`
  307. BodyText string `description:"内容"`
  308. InterviewApplyStatus string `description:"当前访谈申请状态:'待邀请','待访谈','已完成','已取消'"`
  309. InterviewDate string `description:"访谈时间"`
  310. ExpertBackground string `description:"专家背景"`
  311. ExpertNumber string `description:"专家编号"`
  312. Department string `description:"作者"`
  313. SellerMobile string `description:"销售手机号"`
  314. SellerName string `description:"销售名称"`
  315. ArticleIdMd5 string `description:"纪要id"`
  316. }
  317. func GetArticleCountById(articleId int) (count int, err error) {
  318. o := orm.NewOrm()
  319. sql := `SELECT COUNT(1) AS count FROM cygx_article WHERE article_id = ? `
  320. err = o.Raw(sql, articleId).QueryRow(&count)
  321. return
  322. }
  323. type CygxArticles struct {
  324. Id int `orm:"column(id);pk"`
  325. ArticleId int `description:"文章id"`
  326. Title string `description:"标题"`
  327. TitleEn string `description:"英文标题 "`
  328. UpdateFrequency string `description:"更新周期"`
  329. CreateDate string `description:"创建时间"`
  330. PublishDate string `description:"发布时间"`
  331. Body string `description:"内容"`
  332. BodyText string `description:"内容"`
  333. Abstract string `description:"摘要"`
  334. CategoryName string `description:"一级分类"`
  335. SubCategoryName string `description:"二级分类"`
  336. PublishStatus int `description:"发布状态"`
  337. CategoryId int `description:"分类id"`
  338. ExpertBackground string `description:"专家背景"`
  339. ExpertNumber string `description:"专家编号"`
  340. InterviewDate string `description:"访谈日期"`
  341. Department string `description:"作者"`
  342. ArticleIdMd5 string `description:"ID,md5值"`
  343. IsClass int `description:"是否归类,1是,0否"`
  344. IsSummary int `description:"是否是纪要库,1是,0否"`
  345. IsReport int `description:"是否属于报告,1是,0否"`
  346. ReportType int `description:"报告类型,1行业报告,2产业报告,0无"`
  347. }
  348. // 新增文章
  349. func AddCygxArticles(item *CygxArticle) (lastId int64, err error) {
  350. o := orm.NewOrm()
  351. lastId, err = o.Insert(item)
  352. return
  353. }
  354. func GetPermissionMappingById(categoryId int) (count int, err error) {
  355. o := orm.NewOrm()
  356. sql := `SELECT COUNT(1) AS count FROM cygx_permission_mapping WHERE category_id = ? `
  357. err = o.Raw(sql, categoryId).QueryRow(&count)
  358. return
  359. }
  360. func GetReportMappingById(categoryId int) (count int, err error) {
  361. o := orm.NewOrm()
  362. sql := `SELECT COUNT(1) AS count FROM cygx_report_mapping WHERE category_id = ? `
  363. err = o.Raw(sql, categoryId).QueryRow(&count)
  364. return
  365. }
  366. type ReportArticle struct {
  367. ArticleId int `description:"文章id"`
  368. Title string `description:"标题"`
  369. TitleEn string `description:"英文标题 "`
  370. UpdateFrequency string `description:"更新周期"`
  371. CreateDate string `description:"创建时间"`
  372. PublishDate string `description:"发布时间"`
  373. Body string `description:"内容"`
  374. Abstract string `description:"摘要"`
  375. CategoryName string `description:"一级分类"`
  376. SubCategoryName string `description:"二级分类"`
  377. ExpertBackground string `description:"专家背景"`
  378. IsRed bool `description:"是否标记红点"`
  379. Readnum int `description:"阅读数量"`
  380. VideoUrl string `description:"链接"`
  381. IsHaveVideo bool `description:"是否含有音频文件"`
  382. ImgUrlPc string `description:"图片链接"`
  383. CategoryId string `description:"文章分类"`
  384. Annotation string `description:"核心观点"`
  385. Resource int `description:"来源类型,1:文章、2:产品内测"`
  386. }
  387. func GetReportPermission(categoryName string) (item []*ChartPermission, err error) {
  388. o := orm.NewOrm()
  389. sql := ` SELECT b.* FROM cygx_report_mapping AS a
  390. INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
  391. WHERE a.sub_category_name=? `
  392. _, err = o.Raw(sql, categoryName).QueryRows(&item)
  393. return
  394. }
  395. type ReportMappingCategoryRep struct {
  396. CategoryId int `description:"文章分类id"`
  397. }
  398. func GetReportMappingCategoryID() (item []*ReportMappingCategoryRep, err error) {
  399. o := orm.NewOrm()
  400. sql := ` SELECT category_id FROM cygx_permission_mapping GROUP BY category_id `
  401. _, err = o.Raw(sql).QueryRows(&item)
  402. return
  403. }
  404. type PermissionMappingCategoryRep struct {
  405. CategoryId int `description:"文章分类id"`
  406. }
  407. func GetPermissionMappingCategoryID() (item []*PermissionMappingCategoryRep, err error) {
  408. o := orm.NewOrm()
  409. sql := ` SELECT category_id FROM cygx_report_mapping GROUP BY category_id `
  410. _, err = o.Raw(sql).QueryRows(&item)
  411. return
  412. }
  413. // 检查用户是否阅读某一分类最新文章
  414. func GetUserIsReadThisNewCategoryArticleCount(categoryId, uid int) (count int, err error) {
  415. sqlCount := `SELECT
  416. COUNT( 1 ) AS count
  417. FROM
  418. cygx_article_history_record
  419. WHERE
  420. article_id = ( SELECT article_id FROM cygx_article WHERE category_id IN ( SELECT category_id_celue FROM cygx_report_mapping_group WHERE id_cygx = ? ) ORDER BY publish_date DESC LIMIT 0, 1 )
  421. AND user_id = ?`
  422. o := orm.NewOrm()
  423. err = o.Raw(sqlCount, categoryId, uid).QueryRow(&count)
  424. return
  425. }
  426. type ArticleId struct {
  427. ArticleId int `description:"文章id"`
  428. }
  429. type ArticleIdAndTitle struct {
  430. Title string `description:"标题"`
  431. ArticleId int `description:"文章id"`
  432. }
  433. // 获取自定义分类的文章ID
  434. func GetCustomArticleId() (item []*ArticleId, err error) {
  435. o := orm.NewOrm()
  436. sql := ` SELECT article_id FROM cygx_article WHERE is_custom = 1 `
  437. _, err = o.Raw(sql).QueryRows(&item)
  438. return
  439. }
  440. type ArticleFollowDetail struct {
  441. DNum int `description:"作者被关注的数量"`
  442. MdNum int `description:"本人是否关注这个作者"`
  443. AcNum int `description:"文章被收藏的数量"`
  444. MacNum int `description:"本人是否收藏这个文章"`
  445. }
  446. // 获取文章被关注被收藏的详情
  447. func GetArticleFollowDetail(articleId, uid int) (item *ArticleFollowDetail, err error) {
  448. //d_num 作者被关注的数量 、 md_num 本人是否关注这个作者 、ac_num 文章被收藏的数量 、 mac_num 本人是否收藏这个文章
  449. o := orm.NewOrm()
  450. sql := ` SELECT
  451. ( 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,
  452. ( 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,
  453. ( 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,
  454. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = art.article_id AND ac.user_id = ? ) AS mac_num
  455. FROM
  456. cygx_article AS art
  457. LEFT JOIN cygx_article_department_follow AS af ON af.department_id = art.department_id
  458. LEFT JOIN cygx_article_collect AS ac ON ac.article_id = art.article_id
  459. WHERE
  460. art.article_id = ?
  461. GROUP BY art.article_id `
  462. err = o.Raw(sql, uid, uid, articleId).QueryRow(&item)
  463. return
  464. }
  465. // 日度点评的数据同步
  466. type ReportDetail struct {
  467. Id int `orm:"column(id)" description:"报告Id"`
  468. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  469. ClassifyIdFirst int `description:"一级分类id"`
  470. ClassifyNameFirst string `description:"一级分类名称"`
  471. ClassifyIdSecond int `description:"二级分类id"`
  472. ClassifyNameSecond string `description:"二级分类名称"`
  473. Title string `description:"标题"`
  474. Abstract string `description:"摘要"`
  475. Author string `description:"作者"`
  476. Frequency string `description:"频度"`
  477. CreateTime string `description:"创建时间"`
  478. ModifyTime string `description:"修改时间"`
  479. State int `description:"1:未发布,2:已发布"`
  480. PublishTime string `description:"发布时间"`
  481. Stage int `description:"期数"`
  482. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  483. Content string `description:"内容"`
  484. VideoUrl string `description:"音频文件URL"`
  485. VideoName string `description:"音频文件名称"`
  486. VideoPlaySeconds string `description:"音频播放时长"`
  487. ContentSub string `description:"内容前两个章节"`
  488. }
  489. func GetReportList() (items []*ReportDetail, err error) {
  490. o := orm.NewOrmUsingDB("rddp")
  491. sql := `SELECT * FROM report WHERE classify_id_second = '57'`
  492. _, err = o.Raw(sql).QueryRows(&items)
  493. return
  494. }
  495. func GetMaxArticleIdInfo() (item *ArticleDetail, err error) {
  496. o := orm.NewOrm()
  497. sql := `SELECT * FROM cygx_article ORDER BY article_id desc LIMIT 1`
  498. err = o.Raw(sql).QueryRow(&item)
  499. return
  500. }
  501. type ArticleResultApi struct {
  502. Data []ArticleResultApidate `json:"data"`
  503. Code int `json:"code"`
  504. Msg string `json:"msg"`
  505. }
  506. type ArticleDetailResultApi struct {
  507. Data ArticleResultApidate `json:"data"`
  508. Code int `json:"code"`
  509. Msg string `json:"msg"`
  510. }
  511. type ArticleResultApidate struct {
  512. ArticleId int `json:"id"`
  513. Title string `json:"title"`
  514. File string `json:"file"`
  515. TitleEn string `json:"title_en"`
  516. Frequency string `json:"frequency"`
  517. CreateDate string `json:"create_date"`
  518. UpdateDate string `json:"update_date"`
  519. PublishDate time.Time `json:"publish_date"`
  520. PublishStatus int `json:"publish_status"`
  521. IndustrId int `json:"industry_id"`
  522. SeriesId int `json:"series_id"`
  523. Series ArticleSeries `json:"series"`
  524. Content ArticleResultApiContent `json:"content"`
  525. Author ArticleResultApiAuthor `json:"author"`
  526. Industry ArticleResultApiIndustry `json:"industry"`
  527. Type ArticleResultApiType `json:"type"`
  528. Stock []string `json:"stock"`
  529. Field ArticleField `json:"field"`
  530. Corpus Corpus `json:"corpus"`
  531. Cover string `json:"cover"`
  532. TypeId int `json:"type_id"`
  533. IsActive bool `json:"is_active"`
  534. }
  535. type ArticleField struct {
  536. Id int `json:"id"`
  537. Name string `json:"name"`
  538. Description string `json:"description"`
  539. IndustryId int `json:"industry_id"`
  540. }
  541. type Corpus struct {
  542. Id int `json:"id"`
  543. ArticleId int `json:"article_id"`
  544. Corpus string `json:"corpus"`
  545. }
  546. type ArticleSeries struct {
  547. Name string `json:"name"`
  548. }
  549. type ArticleResultApiContent struct {
  550. ArticleId int `json:"id"`
  551. Body string `json:"body"`
  552. Abstract string `json:"abstract"`
  553. Annotation string `json:"annotation"`
  554. }
  555. type ArticleResultApiAuthor struct {
  556. PhoneNumber string `json:"phone_number"`
  557. Name string `json:"name"`
  558. }
  559. type ArticleResultApiIndustry struct {
  560. Name string `json:"name"`
  561. }
  562. type ArticleResultApiType struct {
  563. Name string `json:"name"`
  564. }
  565. type ArticleIndustryApi struct {
  566. Data []ArticleResultApiIndustrdate `json:"data"`
  567. Code int `json:"code"`
  568. Msg string `json:"msg"`
  569. }
  570. type ArticleResultApiIndustrdate struct {
  571. Id int `json:"id"`
  572. Name string `json:"name"`
  573. Series []ArticleResultApiSeriesdate `json:"series"`
  574. }
  575. type ArticleResultApiSeriesdate struct {
  576. Id int `json:"id"`
  577. Name string `json:"name"`
  578. }
  579. type ArticleApiMap struct {
  580. Id int `description:"新ID"`
  581. OldId int `description:"旧Id"`
  582. IsClass int `description:"是否自动归类,1是,0否"`
  583. IsReport int `description:"是否属于报告,1是,0否"`
  584. IsSummary int `description:"是否属于纪要,1是,0否"`
  585. }
  586. func GetArticleApiMap() (item []*ArticleApiMap, err error) {
  587. o := orm.NewOrm()
  588. sql := ` SELECT * FROM cygx_article_api_map WHERE old_id > 0 AND is_update = 1 ORDER BY old_id ASC `
  589. _, err = o.Raw(sql).QueryRows(&item)
  590. return
  591. }
  592. func GetArticleIdSubjectGroup(keyWord string) (articleid string, err error) {
  593. o := orm.NewOrm()
  594. sql := ` SELECT
  595. GROUP_CONCAT(DISTINCT art.article_id SEPARATOR ',') AS articleid
  596. FROM
  597. cygx_article AS art
  598. INNER JOIN cygx_industrial_article_group_subject AS sg ON sg.article_id = art.article_id
  599. INNER JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = sg.industrial_subject_id
  600. WHERE
  601. s.subject_name LIKE '%` + keyWord + `%' `
  602. err = o.Raw(sql).QueryRow(&articleid)
  603. return
  604. }
  605. func GetArticleIndustrialIdGroup(keyWord string) (articleid string, err error) {
  606. o := orm.NewOrm()
  607. sql := ` SELECT
  608. GROUP_CONCAT(DISTINCT art.article_id SEPARATOR ',') AS article_id
  609. FROM
  610. cygx_article AS art
  611. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = art.article_id
  612. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  613. WHERE
  614. m.industry_name LIKE '%` + keyWord + `%' `
  615. err = o.Raw(sql).QueryRow(&articleid)
  616. return
  617. }
  618. // 通过文章ID获取文章所关联的标的ID
  619. func GetSubjectIds(articleId int) (subjects string, err error) {
  620. sql := ` SELECT
  621. GROUP_CONCAT( DISTINCT industrial_subject_id ORDER BY id ASC SEPARATOR ',' ) AS subjects
  622. FROM
  623. cygx_industrial_article_group_subject WHERE article_id = ?`
  624. o := orm.NewOrm()
  625. err = o.Raw(sql, articleId).QueryRow(&subjects)
  626. return
  627. }
  628. // 修改发布状态
  629. func UpdateIsClassFail(articleId int) (err error) {
  630. sql := `UPDATE cygx_article SET is_class_fail=1 WHERE article_id=? `
  631. o := orm.NewOrm()
  632. _, err = o.Raw(sql, articleId).Exec()
  633. return
  634. }
  635. type SummaryArticleStock struct {
  636. Id int `description:"新ID"`
  637. ArticleId int `description:"文章id"`
  638. Stock string `description:"个股标签"`
  639. }
  640. // 综述报告
  641. func GetSummaryArticle(chartPermissionId int) (items []*SummaryArticleStock, err error) {
  642. o := orm.NewOrm()
  643. sql := `SELECT
  644. *
  645. FROM
  646. cygx_article AS c
  647. INNER JOIN cygx_report_mapping AS m
  648. WHERE
  649. c.type_name = '综述报告'
  650. AND m.category_id = c.category_id_two
  651. AND m.chart_permission_id = ? ORDER BY modify_time_by_cl DESC `
  652. _, err = o.Raw(sql, chartPermissionId).QueryRows(&items)
  653. return
  654. }
  655. type SummaryArticleStockResp struct {
  656. List []*SummaryArticleStock
  657. }
  658. // 综述报告
  659. func GetArticleStock() (items []*SummaryArticleStock, err error) {
  660. o := orm.NewOrm()
  661. sql := `SELECT
  662. stock,article_id
  663. FROM
  664. cygx_article AS art
  665. WHERE
  666. 1 = 1
  667. AND type_name = '综述报告' `
  668. _, err = o.Raw(sql).QueryRows(&items)
  669. return
  670. }
  671. // 列表
  672. func GetCygxCygxArticleList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxArticle, err error) {
  673. o := orm.NewOrm()
  674. sql := `SELECT * FROM cygx_article as art WHERE 1= 1 `
  675. if condition != "" {
  676. sql += condition
  677. }
  678. sql += ` LIMIT ?,? `
  679. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  680. return
  681. }
  682. // 获取数量
  683. func GetCygxArticleCount(condition string, pars []interface{}) (count int, err error) {
  684. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article as art WHERE 1= 1 `
  685. if condition != "" {
  686. sqlCount += condition
  687. }
  688. o := orm.NewOrm()
  689. err = o.Raw(sqlCount, pars).QueryRow(&count)
  690. return
  691. }
  692. // 列表
  693. func GetCygxCygxArticleListByCondition(articleTypesCond, activityTypesCond, industryStr, subjectNameStr, articleTypeStr string) (artIds, actIds, mmIds string, err error) {
  694. o := orm.NewOrm()
  695. artSql := `SELECT GROUP_CONCAT(DISTINCT art.article_id SEPARATOR ',') AS art_ids FROM cygx_article as art `
  696. actSql := ` SELECT GROUP_CONCAT(DISTINCT act.activity_id SEPARATOR ',') AS act_ids FROM cygx_activity as act `
  697. mmSql := ` SELECT GROUP_CONCAT(DISTINCT mm.id SEPARATOR ',') AS mm_ids FROM cygx_morning_meeting_reviews as mm `
  698. if industryStr != "" {
  699. artSql += ` INNER JOIN cygx_industrial_article_group_management AS iam ON iam.article_id = art.article_id
  700. INNER JOIN cygx_industrial_management AS im ON im.industrial_management_id=iam.industrial_management_id `
  701. actSql += ` INNER JOIN cygx_industrial_activity_group_management AS iam ON iam.activity_id = act.activity_id
  702. INNER JOIN cygx_industrial_management AS im ON im.industrial_management_id=iam.industrial_management_id `
  703. mmSql += ` INNER JOIN cygx_morning_meeting_review_chapter AS mmc ON mmc.meeting_id = mm.id
  704. INNER JOIN cygx_industrial_management AS im ON im.industrial_management_id=mmc.industry_id `
  705. }
  706. if subjectNameStr != "" {
  707. artSql += ` INNER JOIN cygx_industrial_article_group_subject AS ias ON ias.article_id = art.article_id
  708. INNER JOIN cygx_industrial_subject AS cis ON cis.industrial_subject_id=ias.industrial_subject_id `
  709. actSql += ` INNER JOIN cygx_industrial_activity_group_subject AS ias ON ias.activity_id = act.activity_id
  710. INNER JOIN cygx_industrial_subject AS cis ON cis.industrial_subject_id=ias.industrial_subject_id `
  711. mmSql += ` INNER JOIN cygx_morning_meeting_review_chapter AS mmc ON mmc.meeting_id = mm.id
  712. INNER JOIN cygx_industrial_subject AS cis ON cis.industrial_subject_id=mmc.industrial_subject_ids `
  713. }
  714. artSql += ` WHERE 1=1 `
  715. if articleTypesCond != "" || (articleTypesCond == "" && activityTypesCond == "") {
  716. if industryStr != "" && subjectNameStr != "" {
  717. artSql += articleTypesCond + ` AND (im.industry_name In (` + industryStr + `) OR cis.subject_name In (` + subjectNameStr + `) )`
  718. } else if industryStr == "" && subjectNameStr != "" {
  719. artSql += articleTypesCond + ` AND cis.subject_name In (` + subjectNameStr + `) `
  720. } else if industryStr != "" && subjectNameStr == "" {
  721. artSql += articleTypesCond + ` AND im.industry_name In (` + industryStr + `) `
  722. } else {
  723. artSql += articleTypesCond
  724. }
  725. err = o.Raw(artSql).QueryRow(&artIds)
  726. }
  727. actSql += ` WHERE 1=1 `
  728. if activityTypesCond != "" || (articleTypesCond == "" && activityTypesCond == "") {
  729. if industryStr != "" && subjectNameStr != "" {
  730. actSql += activityTypesCond + ` AND (im.industry_name In (` + industryStr + `) OR cis.subject_name In (` + subjectNameStr + `) )`
  731. } else if industryStr == "" && subjectNameStr != "" {
  732. actSql += activityTypesCond + ` AND cis.subject_name In (` + subjectNameStr + `) `
  733. } else if industryStr != "" && subjectNameStr == "" {
  734. actSql += activityTypesCond + ` AND im.industry_name In (` + industryStr + `) `
  735. } else {
  736. actSql += activityTypesCond
  737. }
  738. err = o.Raw(actSql).QueryRow(&actIds)
  739. }
  740. if strings.Contains(articleTypeStr, "晨会精华") {
  741. mmSql += ` WHERE 1=1 `
  742. if industryStr != "" && subjectNameStr != "" {
  743. mmSql += ` AND (im.industry_name In (` + industryStr + `) OR cis.subject_name In (` + subjectNameStr + `) )`
  744. } else if industryStr == "" && subjectNameStr != "" {
  745. mmSql += ` AND cis.subject_name In (` + subjectNameStr + `) `
  746. } else if industryStr != "" && subjectNameStr == "" {
  747. mmSql += ` AND im.industry_name In (` + industryStr + `) `
  748. }
  749. err = o.Raw(mmSql).QueryRow(&mmIds)
  750. }
  751. return
  752. }