report.go 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "strconv"
  6. "time"
  7. //"github.com/rdlucklib/rdluck_tools/paging"
  8. )
  9. type IndustrialManagementList struct {
  10. Paging *paging.PagingItem
  11. List []*IndustrialManagement
  12. }
  13. type IndustrialManagement struct {
  14. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  15. IndustryName string `description:"产业名称"`
  16. RecommendedIndex int `description:"推荐指数"`
  17. CategoryId int `description:"文章分类ID"`
  18. LayoutTime string `description:"布局时间"`
  19. UpdateTime string `description:"更新时间"`
  20. MinReportTime string `description:"报告最早发布时间"`
  21. IsRed bool `description:"是否标记红点"`
  22. IsTop bool `description:"是否置顶"`
  23. IsHot bool `description:"是否是热门-近一个月内,产业下关联的报告阅读次数最多的"`
  24. IsFollow int `description:"是否关注"`
  25. IsNew bool `description:"是否为新-关联报告的发布时间,均在3个月以内的"`
  26. Analyst string `description:"分析师"`
  27. ArticleReadNum int `description:"文章阅读数量"`
  28. OneMonFollowNum int `description:"近一个月关注增量"`
  29. AnalystList []*IndustrialAnalyst `description:"分析师列表"`
  30. IndustrialSubjectList []*IndustrialSubject `description:"标的列表"`
  31. ChartPermissionId int `description:"行业ID"`
  32. PermissionName string `description:"行业名称"`
  33. IndustryVideo *MicroVideoSimpleInfo
  34. AuthInfo *UserPermissionAuthInfo
  35. ArticleId int `description:"文章id"`
  36. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  37. }
  38. type MicroVideoSimpleInfo struct {
  39. Id int `description:"视频ID"`
  40. Title string `description:"标题"`
  41. ResourceUrl string `description:"链接"`
  42. BackgroundImg string `description:"背景图"`
  43. PlaySeconds int `description:"音视频时长"`
  44. DetailImgUrl string `description:"产业详情页背景图"`
  45. ChartPermissionId int `description:"行业ID"`
  46. ChartPermissionName string `description:"行业名称"`
  47. }
  48. type IndustrialAnalyst struct {
  49. AnalystName string `description:"分析师名称"`
  50. IndustrialManagementId int `description:"产业id"`
  51. }
  52. type IndustrialSubject struct {
  53. IndustrialSubjectId int `orm:"column(industrial_subject_id);pk" description:"标的id"`
  54. IndustrialManagementId int `description:"产业id"`
  55. SubjectName string `description:"标的名称"`
  56. IndustryName string `description:"产业名称"`
  57. LayoutTime string `description:"产业布局时间"`
  58. }
  59. // 获取产业报告数量
  60. func GetReportIndustrialCount(categoryId, industrialManagementId int) (count int, err error) {
  61. o := orm.NewOrm()
  62. sql := `SELECT COUNT(1) count
  63. FROM
  64. cygx_article AS a
  65. INNER JOIN cygx_industrial_article_group_management as man_g ON man_g.article_id = a.article_id
  66. WHERE
  67. a.publish_status = 1
  68. AND category_id IN (SELECT
  69. category_id
  70. FROM
  71. cygx_report_mapping
  72. WHERE
  73. chart_permission_id = any( SELECT chart_permission_id FROM cygx_report_mapping WHERE category_id = ` + strconv.Itoa(categoryId) + ` )
  74. AND match_type_name = any( SELECT match_type_name FROM cygx_report_mapping WHERE category_id = ` + strconv.Itoa(categoryId) + ` ) )
  75. AND a.is_class = 1
  76. AND man_g.industrial_management_id = ? `
  77. err = o.Raw(sql, industrialManagementId).QueryRow(&count)
  78. return
  79. }
  80. // 获取产业报告列表
  81. func GetReportIndustrialList(pars []interface{}, categoryId, industrialManagementId, userId, startSize, pageSize int) (items []*ReportArticle, err error) {
  82. o := orm.NewOrm()
  83. sql := `SELECT *,( 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
  84. FROM
  85. cygx_article AS a
  86. INNER JOIN cygx_industrial_article_group_management as man_g ON man_g.article_id = a.article_id
  87. WHERE
  88. a.publish_status = 1
  89. AND category_id IN (SELECT
  90. category_id
  91. FROM
  92. cygx_report_mapping
  93. WHERE
  94. chart_permission_id = any( SELECT chart_permission_id FROM cygx_report_mapping WHERE category_id = ` + strconv.Itoa(categoryId) + ` )
  95. AND match_type_name = any( SELECT match_type_name FROM cygx_report_mapping WHERE category_id = ` + strconv.Itoa(categoryId) + ` ) )
  96. AND a.is_class = 1
  97. AND man_g.industrial_management_id = ?`
  98. sql += ` GROUP BY a.article_id ORDER BY publish_date DESC LIMIT ?,? `
  99. _, err = o.Raw(sql, pars, industrialManagementId, startSize, pageSize).QueryRows(&items)
  100. return
  101. }
  102. // 获取产业报告列表
  103. func GetReportAndproductInteriorIndustrialList(pars []interface{}, categoryId, industrialManagementId, userId, startSize, pageSize int) (items []*ReportArticle, total int, err error) {
  104. o := orm.NewOrm()
  105. sql := `SELECT
  106. art.article_id,
  107. art.title,
  108. art.publish_date,
  109. ( SELECT COUNT( 1 ) FROM cygx_article_history_record AS rec WHERE rec.user_id = ` + strconv.Itoa(userId) + ` AND rec.article_id = art.article_id ) AS readnum ,
  110. 1 AS resource
  111. FROM
  112. cygx_article AS art
  113. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = art.article_id
  114. WHERE
  115. art.publish_status = 1
  116. AND art.article_id IN ( SELECT article_id FROM cygx_report_mapping_category_group WHERE id_cygx = ` + strconv.Itoa(categoryId) + ` )
  117. AND art.is_class = 1
  118. AND man_g.industrial_management_id =` + strconv.Itoa(industrialManagementId) + `
  119. GROUP BY
  120. art.article_id UNION ALL
  121. SELECT
  122. art.product_interior_id AS article_id,
  123. art.title,
  124. art.publish_time AS publish_date,
  125. ( SELECT COUNT( 1 ) FROM cygx_product_interior_history AS rec WHERE rec.user_id = ` + strconv.Itoa(userId) + ` AND rec.product_interior_id = art.product_interior_id ) AS readnum ,
  126. 2 AS resource
  127. FROM
  128. cygx_product_interior AS art
  129. INNER JOIN cygx_product_interior_industrial_group_management AS man_g ON man_g.product_interior_id = art.product_interior_id
  130. WHERE
  131. art.STATUS = 1
  132. AND art.visible_range = 1
  133. AND art.match_type_id = ` + strconv.Itoa(categoryId) + `
  134. AND man_g.industrial_management_id = ` + strconv.Itoa(industrialManagementId) + `
  135. GROUP BY
  136. art.product_interior_id `
  137. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  138. err = o.Raw(totalSql, pars).QueryRow(&total)
  139. sql += ` ORDER BY publish_date DESC LIMIT ?,? `
  140. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  141. return
  142. }
  143. // 获取行业报告列表
  144. func GetReportAndproductIndustrylList(categoryId, startSize, pageSize int) (items []*ReportArticle, total int, err error) {
  145. o := orm.NewOrm()
  146. sql := `SELECT
  147. art.article_id,
  148. art.report_id,
  149. art.title,
  150. art.abstract,
  151. art.publish_date,
  152. 1 AS resource
  153. FROM
  154. cygx_article AS art
  155. WHERE
  156. art.publish_status = 1
  157. AND art.article_id IN ( SELECT article_id FROM cygx_report_mapping_category_group WHERE id_cygx = ` + strconv.Itoa(categoryId) + ` ) UNION ALL
  158. SELECT
  159. art.product_interior_id AS article_id,
  160. 0 AS report_id,
  161. art.title,
  162. "" as abstract,
  163. art.publish_time AS publish_date,
  164. 2 AS resource
  165. FROM
  166. cygx_product_interior AS art
  167. WHERE
  168. art.STATUS = 1
  169. AND art.visible_range = 1
  170. AND art.match_type_id = ` + strconv.Itoa(categoryId)
  171. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  172. err = o.Raw(totalSql).QueryRow(&total)
  173. sql += ` ORDER BY publish_date DESC LIMIT ?,? `
  174. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  175. return
  176. }
  177. // 产业下所关联的文章分类列表
  178. func IndustrialToArticleCategory(industrialManagementId, chartPermissionId int) (items []*IndustrialToArticleCategoryRep, err error) {
  179. o := orm.NewOrm()
  180. sql := `SELECT map.match_type_name,map.category_id
  181. FROM cygx_report_mapping AS map
  182. INNER JOIN cygx_article AS art ON art.category_id = map.category_id
  183. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = art.article_id
  184. WHERE map.report_type = 2
  185. AND map.is_report = 1
  186. AND art.is_report = 1
  187. AND art.publish_status = 1
  188. AND man_g.industrial_management_id =?
  189. AND map.chart_permission_id = ?
  190. GROUP BY map.match_type_name`
  191. _, err = o.Raw(sql, industrialManagementId, chartPermissionId).QueryRows(&items)
  192. return
  193. }
  194. // 产业下所关联的文章分类列表 2022-10-13
  195. func IndustrialToArticleCategoryNew(industrialManagementId int) (items []*IndustrialToArticleCategoryRep, err error) {
  196. o := orm.NewOrm()
  197. sql := `SELECT map.match_type_name,map.category_id
  198. FROM cygx_report_mapping AS map
  199. INNER JOIN cygx_article AS art ON art.category_id = map.category_id
  200. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = art.article_id
  201. WHERE map.report_type = 2
  202. AND map.is_report = 1
  203. AND art.is_report = 1
  204. AND art.publish_status = 1
  205. AND man_g.industrial_management_id =?
  206. GROUP BY map.match_type_name`
  207. _, err = o.Raw(sql, industrialManagementId).QueryRows(&items)
  208. return
  209. }
  210. // 产业下所关联的文章、产品内测分类列表 2023-04-14
  211. func IndustrialToArticleAndProductInteriorCategoryNew(industrialManagementId int) (items []*IndustrialToArticleCategoryRep, err error) {
  212. o := orm.NewOrm()
  213. sql := `SELECT
  214. map.match_type_name,
  215. map.sort,
  216. map.id,
  217. map.id AS category_id
  218. FROM
  219. cygx_report_mapping_cygx AS map
  220. INNER JOIN cygx_report_mapping_group AS g ON g.id_cygx = map.id
  221. INNER JOIN cygx_report_mapping_celue AS cl ON cl.category_id = g.category_id_celue
  222. INNER JOIN cygx_article AS art ON art.category_id = cl.category_id
  223. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = art.article_id
  224. WHERE
  225. 1 = 1
  226. AND map.report_type = 2
  227. AND map.is_report = 1
  228. AND art.is_report = 1
  229. AND art.publish_status = 1
  230. AND man_g.industrial_management_id = ?
  231. GROUP BY
  232. map.match_type_name UNION ALL
  233. SELECT
  234. map.match_type_name,
  235. map.sort,
  236. map.id,
  237. map.id AS category_id
  238. FROM
  239. cygx_report_mapping_cygx AS map
  240. INNER JOIN cygx_industrial_management AS im ON im.chart_permission_id = map.chart_permission_id
  241. INNER JOIN cygx_product_interior AS art ON art.match_type_id = map.id
  242. INNER JOIN cygx_product_interior_industrial_group_management AS man_g ON man_g.product_interior_id = art.product_interior_id
  243. WHERE
  244. 1 = 1
  245. AND art.STATUS = 1
  246. AND art.visible_range = 1
  247. AND man_g.industrial_management_id = ?
  248. GROUP BY
  249. map.match_type_name ORDER BY id ASC , sort DESC `
  250. _, err = o.Raw(sql, industrialManagementId, industrialManagementId).QueryRows(&items)
  251. return
  252. }
  253. // 判断用户是否阅读该产业下,某一分类的文章
  254. func IndustrialUserRecordArticleCount(userId, industrialManagementId, categoryId int) (count int, err error) {
  255. o := orm.NewOrm()
  256. sql := `SELECT
  257. COUNT(1) count
  258. FROM
  259. cygx_article_history_record
  260. WHERE
  261. 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 IN (SELECT
  262. category_id
  263. FROM
  264. cygx_report_mapping
  265. WHERE
  266. chart_permission_id = any( SELECT chart_permission_id FROM cygx_report_mapping WHERE category_id = ? )
  267. AND match_type_name = any( SELECT match_type_name FROM cygx_report_mapping WHERE category_id = ? ) ) ORDER BY publish_date DESC LIMIT 0, 1 )
  268. AND user_id = ? `
  269. err = o.Raw(sql, industrialManagementId, categoryId, categoryId, userId).QueryRow(&count)
  270. return
  271. }
  272. // 获取最新文章
  273. func GetNewIndustrialUserRecordArticle(industrialManagementId, categoryId int) (item *ArticleDetail, err error) {
  274. o := orm.NewOrm()
  275. //sql := ` SELECT * FROM cygx_article WHERE article_id IN (SELECT article_id FROM cygx_industrial_article_group_management WHERE industrial_management_id = ? ) AND match_type_name = any( SELECT match_type_name FROM cygx_report_mapping WHERE category_id = ? ) ORDER BY publish_date DESC LIMIT 0, 1`
  276. 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 IN (SELECT
  277. category_id
  278. FROM
  279. cygx_report_mapping
  280. WHERE
  281. chart_permission_id = any( SELECT chart_permission_id FROM cygx_report_mapping WHERE category_id = ? )
  282. AND match_type_name = any( SELECT match_type_name FROM cygx_report_mapping WHERE category_id = ? ) ) ORDER BY publish_date DESC LIMIT 0, 1`
  283. err = o.Raw(sql, industrialManagementId, categoryId, categoryId).QueryRow(&item)
  284. return
  285. }
  286. // 获取最新文章
  287. func GetNewArticleByCategoryId(categoryId int) (item *ArticleDetail, err error) {
  288. o := orm.NewOrm()
  289. sql := ` SELECT * 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 `
  290. err = o.Raw(sql, categoryId).QueryRow(&item)
  291. return
  292. }
  293. func GetIndustrialManagementIdsBykeyWord(condition string) (industrialManagementIds string, err error) {
  294. sql := `SELECT GROUP_CONCAT(DISTINCT industrial_management_id SEPARATOR ',') AS industrial_management_ids FROM cygx_industrial_management WHERE` + condition
  295. o := orm.NewOrm()
  296. err = o.Raw(sql).QueryRow(&industrialManagementIds)
  297. return
  298. }
  299. type ReportArticleWhichIndustrial struct {
  300. ArticleId int `description:"文章id"`
  301. Title string `description:"标题"`
  302. PublishDate string `description:"发布时间"`
  303. IndustryName string `description:"产业名称"`
  304. SubjectName string `description:"标的名称"`
  305. NickName string `description:"作者昵称"`
  306. IsRed bool `description:"是否标记红点"`
  307. Readnum int `description:"阅读数量"`
  308. IsResearch bool `description:"是否属于研选"`
  309. Pv int `description:"PV"`
  310. ImgUrlPc string `description:"图片链接"`
  311. }
  312. type ReportArticleWhichIndustrialRepList struct {
  313. HaveResearch bool `description:"是否有研选权限"`
  314. Paging *paging.PagingItem `description:"分页数据"`
  315. NickName string `description:"作者昵称"`
  316. IndustryName string `description:"产业名称"`
  317. List []*ReportArticleWhichIndustrial
  318. }
  319. // 列表
  320. func IndustrialToArticleWhichDepartment(condition string, pars []interface{}, uid, startSize, pageSize int) (items []*ReportArticleWhichIndustrial, err error) {
  321. o := orm.NewOrm()
  322. sql := `SELECT
  323. art.* ,m.industry_name,d.nick_name,
  324. (SELECT count(1) FROM cygx_article_history_record_newpv as h WHERE h.article_id = art.article_id ) as pv,
  325. ( SELECT COUNT( 1 ) FROM cygx_article_history_record_newpv AS rec WHERE rec.user_id = ` + strconv.Itoa(uid) + ` AND rec.article_id = art.article_id ) AS readnum
  326. FROM
  327. cygx_article AS art
  328. INNER JOIN cygx_industrial_article_group_management as mg ON mg.article_id = art.article_id
  329. INNER JOIN cygx_industrial_management as m ON m.industrial_management_id = mg.industrial_management_id
  330. INNER JOIN cygx_article_department as d ON d.department_id = art.department_id
  331. WHERE 1 = 1
  332. AND art.publish_status = 1`
  333. if condition != "" {
  334. sql += condition
  335. }
  336. sql += ` LIMIT ?,?`
  337. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  338. return
  339. }
  340. func GetWhichDepartmentCount(condition string) (count int, err error) {
  341. o := orm.NewOrm()
  342. sql := `SELECT COUNT(1) count
  343. FROM
  344. cygx_article AS art
  345. INNER JOIN cygx_industrial_article_group_management as mg ON mg.article_id = art.article_id
  346. INNER JOIN cygx_industrial_management as m ON m.industrial_management_id = mg.industrial_management_id
  347. INNER JOIN cygx_article_department as d ON d.department_id = art.department_id
  348. WHERE 1 = 1
  349. AND art.publish_status = 1`
  350. if condition != "" {
  351. sql += condition
  352. }
  353. err = o.Raw(sql).QueryRow(&count)
  354. return
  355. }
  356. type IsShow struct {
  357. IsShow bool `description:"绝密内参按钮是否展示"`
  358. IsShowFreeButton bool `description:"免费送月卡按钮是否展示"`
  359. IsShowResearch bool `description:"研选是否展示限免"`
  360. IsShowChart bool `description:"图表是否展示限免"`
  361. IsShowList bool `description:"榜单是否展示"`
  362. LinkWxExplain string `description:"关注微信公众号链接说明地址"`
  363. YanXuan_Explain bool `description:"研选说明"`
  364. ActivitySpecialExplain string `description:"专项调研活动"`
  365. SearchTxtList SearchTxt `description:"搜索栏回显内容说明"`
  366. IsBelongRai bool `description:"是否属于权益内部人员"`
  367. IsShowResearchPoints bool `description:"是否展示研选扣点搜索"`
  368. IsShowQuestionnaire bool `description:"是否展示研选问卷调查"`
  369. IsShowAboutVideo bool `description:"是否展示关于我们的视频"`
  370. IsShowMobileAndEmailButton bool `description:"是否展示手机号跟邮箱按钮"`
  371. }
  372. type SearchTxt struct {
  373. SummarySearch string `description:"素材库搜索说明"`
  374. ReportSearch string `description:"报告搜索说明"`
  375. YanXuanSearch string `description:"研选搜索说明"`
  376. ActivitySearch string `description:"活动搜索说明"`
  377. TabSearch string `description:"素材库搜索说明"`
  378. }
  379. // 获取用户是否有查看权限
  380. func GetUserIsAdminCount(mobile string) (count int, err error) {
  381. o := orm.NewOrm()
  382. sql := `SELECT COUNT(1) count FROM admin
  383. WHERE
  384. mobile = ?
  385. AND (group_id IN (11, 13, 14, 15, 16, 17) OR department_id = 3 ) AND enabled = 1`
  386. err = o.Raw(sql, mobile).QueryRow(&count)
  387. return
  388. }
  389. type ReportDetailRoadshow struct {
  390. ArticleId int `description:"报告Id"`
  391. Title string `description:"标题"`
  392. Department string `orm:"column(seller_and_mobile)"description:"作者"`
  393. PublishDate string `description:"发布时间"`
  394. VideoUrl string `description:"链接"`
  395. VideoPlaySeconds string `description:"时长"`
  396. VideoName string `description:"音频名称"`
  397. Abstract string `description:"摘要"`
  398. Body string `description:"内容"`
  399. CategoryName string `description:"行业名称"`
  400. ReportLink string `orm:"column(link_article_id)"description:"报告链接"`
  401. IsCollect bool `description:"是否收藏:true,已收藏,false:未收藏"`
  402. IsRoadShow bool `description:"是否是路演精华"`
  403. CategoryId int `description:"文章分类ID"`
  404. VisibleRange int `description:"设置可见范围1全部,0内部"`
  405. }
  406. type RoadshowDetailResp struct {
  407. Detail *ReportDetailRoadshow
  408. HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  409. HasFree int `description:"1:已付费(至少包含一个品类的权限),2:未付费(没有任何品类权限)"`
  410. IsShow bool `description:"是否展示"`
  411. }
  412. func GetReportRoadshowDetailById(articleId int) (item *ReportDetailRoadshow, err error) {
  413. o := orm.NewOrm()
  414. sql := `SELECT * FROM cygx_article WHERE article_id = ? AND publish_status = 1 `
  415. err = o.Raw(sql, articleId).QueryRow(&item)
  416. return
  417. }
  418. type CygxIndustryAndArticleList struct {
  419. ArticleId int `orm:"column(article_id);pk"description:"报告id"`
  420. Title string `description:"标题"`
  421. PublishDate string `description:"发布时间"`
  422. IndustryName string `description:"产业名称"`
  423. SubjectName string `description:"标的名称"`
  424. }
  425. type CygxIndustrySearchList struct {
  426. ArtList []*CygxIndustryAndArticleList `description:"文章列表"`
  427. IndList []*IndustrialManagement `description:"产业列表"`
  428. }
  429. type CygxIndustrySearchListPc struct {
  430. DepartmentList []*CygxArticleDepartmentRepPc
  431. IndList []*IndustrialManagement `description:"产业列表"`
  432. }
  433. // 列表
  434. func GetCygxIndustryAndArticleList(keyWord string) (items []*CygxIndustryAndArticleList, err error) {
  435. o := orm.NewOrm()
  436. sql := `SELECT
  437. art.title,
  438. art.article_id,
  439. art.publish_date
  440. FROM
  441. cygx_article AS art
  442. LEFT JOIN cygx_industrial_article_group_subject AS sg ON sg.article_id = art.article_id
  443. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = mg.article_id
  444. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  445. WHERE
  446. category_name LIKE '%研选%'
  447. AND art.article_id IN ( SELECT article_id FROM cygx_industrial_article_group_subject AS sg WHERE sg.industrial_subject_id IN ( SELECT industrial_subject_id FROM cygx_industrial_subject WHERE subject_name LIKE '%` + keyWord + `%' ) GROUP BY sg.article_id )
  448. OR ( art.article_id IN ( SELECT article_id FROM cygx_industrial_article_group_management AS mg WHERE mg.industrial_management_id IN ( SELECT industrial_management_id FROM cygx_industrial_management WHERE industry_name LIKE '%` + keyWord + `%' ) GROUP BY mg.article_id ) AND category_name LIKE '%研选%' )
  449. GROUP BY
  450. art.article_id`
  451. _, err = o.Raw(sql).QueryRows(&items)
  452. return
  453. }
  454. func GetArticleIdsBySubId(subjectId string) (articleIds string, err error) {
  455. o := orm.NewOrm()
  456. sql := `SELECT GROUP_CONCAT( DISTINCT a.article_id SEPARATOR ',' ) AS articleIds
  457. FROM cygx_article AS a
  458. WHERE subject_ids LIKE '%` + subjectId + `%'`
  459. err = o.Raw(sql).QueryRow(&articleIds)
  460. return
  461. } //end
  462. // 用户收藏榜start
  463. type ArticleCollectionResp struct {
  464. ArticleId int `description:"文章id"`
  465. Title string `description:"标题"`
  466. PublishDate string `description:"发布日期"`
  467. PublishTime time.Time `description:"发布时间"`
  468. IndustrialManagementId int `description:"产业Id"`
  469. IndustryName string `description:"产业名称"`
  470. DepartmentId int `description:"作者Id"`
  471. NickName string `description:"作者昵称"`
  472. MyCollectNum int `description:"本人是否收藏"`
  473. IsCollect bool `description:"本人是否收藏"`
  474. Pv int `description:"PV"`
  475. CollectNum int `description:"收藏人数"`
  476. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  477. ArticleTypeId int `description:"文章类型ID"`
  478. List []*IndustrialManagementResp `description:"产业列表"`
  479. IsSpecial int `description:"是否为研选专栏"`
  480. SpecialTags string `description:"研选专栏标签"`
  481. UserId int `description:"作者id"`
  482. SpecialType int `description:"专栏类型 1:笔记,2:观点"`
  483. IndustryTags string `description:"研选专栏行业标签"`
  484. CompanyTags string `description:"研选专栏公司标签"`
  485. ArticleTypeName string `description:"文章类型名称"`
  486. TopTime int `description:"置顶时间"`
  487. }
  488. type IndustrialManagementResp struct {
  489. IndustrialManagementId int `description:"产业Id"`
  490. IndustryName string `description:"产业名称"`
  491. ChartPermissionId int `description:"权限id"`
  492. }
  493. type ArticleCollectionLIstResp struct {
  494. List []*ArticleCollectionResp
  495. }
  496. // 研选报告收藏榜单列表
  497. func GetReportCollectionBillboardListYx(limit int, pars []interface{}, condition string) (items []*ArticleCollectionResp, err error) {
  498. o := orm.NewOrm()
  499. sql := `SELECT
  500. ac.id,
  501. a.category_id,
  502. a.article_id,
  503. a.title,
  504. a.body,
  505. a.annotation,
  506. a.abstract,
  507. a.publish_date,
  508. a.article_type_id,
  509. d.nick_name,
  510. d.department_id,
  511. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  512. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time ) ) AS collection_num
  513. FROM
  514. cygx_article AS a
  515. INNER JOIN cygx_article_collect AS ac ON ac.article_id = a.article_id
  516. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  517. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  518. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  519. WHERE
  520. 1 = 1
  521. AND a.publish_status = 1 `
  522. if condition != "" {
  523. sql += condition
  524. }
  525. sql += ` GROUP BY a.article_id ORDER BY collection_num DESC, a.publish_date DESC`
  526. sql += ` LIMIT ?`
  527. _, err = o.Raw(sql, pars, limit).QueryRows(&items)
  528. return
  529. }
  530. // 列表
  531. func GetArticleCollectionList(condition string, userId int) (items []*ArticleCollectionResp, err error) {
  532. o := orm.NewOrm()
  533. sql := `SELECT
  534. a.article_id,
  535. a.title,
  536. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  537. m.industry_name,
  538. m.industrial_management_id,
  539. d.nick_name,
  540. d.department_id,
  541. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  542. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  543. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time ) ) AS collect_num_order,
  544. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ? ) AS my_collect_num
  545. FROM
  546. cygx_article AS a
  547. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  548. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  549. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  550. WHERE
  551. 1 = 1 AND a.publish_status = 1 `
  552. if condition != "" {
  553. sql += condition
  554. }
  555. _, err = o.Raw(sql, userId).QueryRows(&items)
  556. return
  557. } //end
  558. // 资源包研选跟研选专栏的搜索
  559. //func GetArticleAndYxSpecialList(condition, conditionSpecial string, userId int) (items []*ArticleCollectionResp, err error) {
  560. // o := orm.NewOrm()
  561. // sql := `SELECT
  562. // a.article_id,
  563. // a.title,
  564. // date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  565. // d.nick_name,
  566. // d.department_id,
  567. // a.article_type_id,
  568. // 0 AS is_special,
  569. // "" AS special_tags,
  570. // "" AS company_tags,
  571. // "" AS industry_tags,
  572. // ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  573. // ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  574. // ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ? ) AS my_collect_num,
  575. // '' AS special_type,
  576. // '' AS user_id,
  577. // '' AS create_time
  578. // FROM
  579. // cygx_article AS a
  580. // INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  581. // INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  582. // INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  583. // WHERE
  584. // 1 = 1
  585. // AND a.publish_status = 1 ` + condition + ` GROUP BY article_id
  586. // UNION ALL
  587. // SELECT
  588. // a.id AS article_id,
  589. // a.title AS title,
  590. // date_format( a.publish_time, '%Y-%m-%d' ) AS publish_date,
  591. // "" AS nick_name,
  592. // 0 AS department_id,
  593. // - 1 AS article_type_id,
  594. // 1 AS is_special,
  595. // a.tags AS special_tags,
  596. // a.company_tags,
  597. // a.industry_tags,
  598. // ( SELECT count( 1 ) FROM cygx_yanxuan_special_record AS h WHERE h.yanxuan_special_id = a.id ) AS pv,
  599. // ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id ) AS collect_num,
  600. // ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id AND user_id = ? ) AS my_collect_num,
  601. // a.type AS special_type,
  602. // a.user_id AS user_id,
  603. // a.create_time AS create_time
  604. // FROM
  605. // cygx_yanxuan_special AS a
  606. // JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  607. // WHERE
  608. // 1 = 1
  609. // AND a.STATUS = 3 ` + conditionSpecial + ` ORDER BY publish_date DESC LIMIT 30`
  610. //
  611. // _, err = o.Raw(sql, userId, userId).QueryRows(&items)
  612. // return
  613. //} //end
  614. // 资源包研选跟研选专栏的搜索
  615. func GetArticleAndYxSpecialList(condition, conditionSpecial string, userId int) (items []*ArticleCollectionResp, err error) {
  616. o := orm.NewOrm()
  617. sql := `SELECT
  618. a.article_id,
  619. a.title,
  620. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  621. d.nick_name,
  622. d.department_id,
  623. a.article_type_id,
  624. 0 AS is_special,
  625. 0 AS pv,
  626. 0 AS collect_num,
  627. "" AS special_tags,
  628. "" AS company_tags,
  629. "" AS industry_tags,
  630. '' AS special_type,
  631. '' AS user_id,
  632. '' AS create_time
  633. FROM
  634. cygx_article AS a
  635. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  636. WHERE
  637. 1 = 1
  638. AND a.publish_status = 1 ` + condition + ` GROUP BY article_id
  639. UNION ALL
  640. SELECT
  641. a.id AS article_id,
  642. a.title AS title,
  643. date_format( a.publish_time, '%Y-%m-%d' ) AS publish_date,
  644. "" AS nick_name,
  645. 0 AS department_id,
  646. - 1 AS article_type_id,
  647. 1 AS is_special,
  648. a.pv,
  649. a.article_collect_num as collect_num,
  650. a.tags AS special_tags,
  651. a.company_tags,
  652. a.industry_tags,
  653. a.type AS special_type,
  654. a.user_id AS user_id,
  655. a.create_time AS create_time
  656. FROM
  657. cygx_yanxuan_special AS a
  658. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  659. WHERE
  660. 1 = 1
  661. AND a.STATUS = 3 ` + conditionSpecial + ` ORDER BY publish_date DESC LIMIT 30`
  662. _, err = o.Raw(sql).QueryRows(&items)
  663. return
  664. } //end
  665. type ArticleResearchListResp struct {
  666. Paging *paging.PagingItem
  667. List []*ArticleResearchResp
  668. }
  669. type ArticleResearchResp struct {
  670. ArticleId int `description:"文章id"`
  671. Title string `description:"标题"`
  672. PublishDate string `description:"发布时间"`
  673. DepartmentId int `description:"作者Id"`
  674. NickName string `description:"作者昵称"`
  675. IsCollect bool `description:"本人是否收藏"`
  676. Pv int `description:"PV"`
  677. CollectNum int `description:"收藏人数"`
  678. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  679. ArticleTypeId int `description:"文章类型ID"`
  680. ArticleTypeName string `description:"类型名称"`
  681. ButtonStyle string `description:"按钮展示样式"`
  682. IsSpecial int `description:"是否为研选专栏"`
  683. SpecialTags string `description:"研选专栏标签"`
  684. UserId int `description:"作者id"`
  685. List []*IndustrialManagementResp `description:"产业列表"`
  686. TopTime int `description:"置顶时间"`
  687. }
  688. // 获取我的日程数量
  689. func GetArticleResearchCount(condition string, pars []interface{}, needYanxuanSpecial bool) (count int, err error) {
  690. o := orm.NewOrm()
  691. sqlCount := `SELECT COUNT( 1 ) AS count FROM
  692. cygx_article AS a
  693. WHERE
  694. 1 = 1 AND a.publish_status = 1` + condition
  695. if needYanxuanSpecial {
  696. sqlCount = `SELECT SUM(count) AS count FROM (` + sqlCount + `
  697. UNION ALL
  698. SELECT COUNT( 1 ) AS count FROM
  699. cygx_yanxuan_special AS a WHERE
  700. 1 = 1 AND a.status = 3) AS c`
  701. }
  702. err = o.Raw(sqlCount, pars).QueryRow(&count)
  703. return
  704. }
  705. //func GetArticleResearchList(condition string, pars []interface{}, startSize, pageSize, userId int, needYanxuanSpecial bool) (items []*ArticleCollectionResp, err error) {
  706. // o := orm.NewOrm()
  707. // sql := `SELECT
  708. // a.article_id,
  709. // a.title,
  710. // a.publish_date AS publish_time,
  711. // a.article_type_id,
  712. // d.nick_name,
  713. // d.department_id,
  714. // ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  715. // ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  716. // ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time ) ) AS collect_num_order,
  717. // ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ? ) AS my_collect_num,
  718. // 0 AS is_special,
  719. // 0 AS special_type,
  720. // 0 AS user_id,
  721. // '' AS company_tags,
  722. // '' AS industry_tags
  723. // FROM
  724. // cygx_article AS a
  725. // INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  726. // INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  727. // INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  728. // WHERE
  729. // 1 = 1 AND a.publish_status = 1
  730. // `
  731. // if condition != "" {
  732. // sql += condition
  733. // }
  734. // sql += ` GROUP BY a.article_id `
  735. // if needYanxuanSpecial {
  736. // sql += `UNION ALL
  737. // SELECT
  738. // a.id AS article_id,
  739. // a.title AS title,
  740. // a.publish_time AS publish_time,
  741. // -1 AS article_type_id,
  742. // b.nick_name AS nick_name,
  743. // a.user_id AS department_id,
  744. // ( SELECT count( 1 ) FROM cygx_yanxuan_special_record AS h WHERE h.yanxuan_special_id = a.id ) AS pv,
  745. // ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id ) AS collect_num,
  746. // 0 AS collect_num_order,
  747. // ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id AND user_id = ? ) AS my_collect_num,
  748. // 1 AS is_special,
  749. // a.type AS special_type,
  750. // a.user_id AS user_id,
  751. // a.company_tags AS company_tags,
  752. // a.industry_tags AS industry_tags
  753. // FROM
  754. // cygx_yanxuan_special AS a
  755. // JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  756. // WHERE
  757. // 1 = 1 AND a.status = 3 `
  758. // sql += ` ORDER BY publish_time DESC LIMIT ?,? `
  759. // _, err = o.Raw(sql, userId, userId, pars, startSize, pageSize).QueryRows(&items)
  760. // } else {
  761. // sql += ` ORDER BY publish_time DESC LIMIT ?,? `
  762. // _, err = o.Raw(sql, userId, pars, startSize, pageSize).QueryRows(&items)
  763. // }
  764. //
  765. // return
  766. //}
  767. func GetArticleResearchList(condition string, pars []interface{}, startSize, pageSize, userId int, needYanxuanSpecial bool) (items []*ArticleCollectionResp, err error) {
  768. o := orm.NewOrm()
  769. sql := `SELECT
  770. a.article_id,
  771. a.title,
  772. a.publish_date AS publish_time,
  773. a.article_type_id,
  774. d.nick_name,
  775. d.department_id,
  776. 0 AS is_special,
  777. 0 as pv,
  778. 0 as collect_num,
  779. 0 AS special_type,
  780. 0 AS user_id,
  781. '' AS company_tags,
  782. '' AS industry_tags,
  783. a.top_time
  784. FROM
  785. cygx_article AS a
  786. INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
  787. WHERE
  788. 1 = 1 AND a.publish_status = 1
  789. `
  790. if condition != "" {
  791. sql += condition
  792. }
  793. sql += ` GROUP BY a.article_id `
  794. if needYanxuanSpecial {
  795. sql += `UNION ALL
  796. SELECT
  797. a.id AS article_id,
  798. a.title AS title,
  799. a.publish_time AS publish_time,
  800. -1 AS article_type_id,
  801. b.nick_name AS nick_name,
  802. a.user_id AS department_id,
  803. 1 AS is_special,
  804. a.pv,
  805. a.article_collect_num as collect_num,
  806. a.type AS special_type,
  807. a.user_id AS user_id,
  808. a.company_tags AS company_tags,
  809. a.industry_tags AS industry_tags,
  810. 0 as top_time
  811. FROM
  812. cygx_yanxuan_special AS a
  813. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  814. WHERE
  815. 1 = 1 AND a.status = 3 `
  816. }
  817. sql += ` ORDER BY top_time DESC, publish_time DESC LIMIT ?,? `
  818. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  819. return
  820. }
  821. // 用户收藏榜start
  822. type IndustrialManagementHotResp struct {
  823. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  824. IndustryName string `description:"产业名称"`
  825. IsFollw bool `description:"是否关注"`
  826. FllowNum int `description:"关注数量"`
  827. IsNew bool `description:"是否新标签"`
  828. IsHot bool `description:"是否新标签"`
  829. IsRed bool `description:"是否标记红点"`
  830. Readnum int `description:"阅读数量"`
  831. PublishDate string `description:"发布时间"`
  832. MinReportTime string `description:"报告最早发布时间"`
  833. ArticleReadNum int `description:"文章阅读数量"`
  834. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  835. IndustrialSubjectList []*IndustrialSubject `description:"标的列表"`
  836. IndustryVideo *MicroVideoSimpleInfo `description:"产业视频"`
  837. AuthInfo *UserPermissionAuthInfo
  838. }
  839. type IndustrialManagementHotListResp struct {
  840. Paging *paging.PagingItem `description:"分页数据"`
  841. List []*IndustrialManagementHotResp
  842. }
  843. // 产业列表
  844. func GetThemeHeatList(userId int, condition, conditionOrder string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
  845. o := orm.NewOrm()
  846. sql := `SELECT
  847. m.industry_name,
  848. m.industrial_management_id,
  849. m.article_read_num,
  850. MAX( a.publish_date ) AS publish_date,
  851. MIN(a.publish_date) AS min_report_time,
  852. ( SELECT count( 1 ) FROM cygx_industry_fllow AS f WHERE f.industrial_management_id = m.industrial_management_id AND user_id =? AND f.type = 1 ) AS fllow_num,
  853. m.yanxuan_article_read_num + m.activity_num AS sum_num
  854. FROM
  855. cygx_industrial_management AS m
  856. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  857. LEFT JOIN cygx_article AS a ON a.article_id = mg.article_id
  858. LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
  859. WHERE
  860. 1 = 1
  861. AND publish_status = 1 ` + condition + ` GROUP BY m.industrial_management_id ` + conditionOrder + ` , last_updated_time DESC LIMIT ?,?`
  862. _, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  863. return
  864. }
  865. // 获取数量
  866. func GetThemeHeatListCount(condition string) (count int, err error) {
  867. o := orm.NewOrm()
  868. sql := `SELECT COUNT( DISTINCT m.industrial_management_id ) FROM
  869. cygx_industrial_management AS m
  870. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  871. LEFT JOIN cygx_article AS a ON a.article_id = mg.article_id
  872. LEFT JOIN cygx_industrial_activity_group_management as ag ON ag.industrial_management_id = mg.industrial_management_id
  873. WHERE
  874. 1 = 1
  875. AND a.publish_status = 1 ` + condition
  876. err = o.Raw(sql).QueryRow(&count)
  877. return
  878. }
  879. // 标的列表
  880. func GetThemeHeatSubjectList(condition string) (items []*IndustrialSubject, err error) {
  881. o := orm.NewOrm()
  882. sql := `SELECT
  883. m.subject_name,
  884. m.industrial_management_id,
  885. m.industrial_subject_id
  886. FROM
  887. cygx_article AS a
  888. INNER JOIN cygx_industrial_article_group_subject AS mg ON mg.article_id = a.article_id
  889. INNER JOIN cygx_industrial_subject AS m ON m.industrial_subject_id = mg.industrial_subject_id
  890. WHERE
  891. 1 = 1`
  892. if condition != "" {
  893. sql += condition
  894. }
  895. sql += ` AND publish_status = 1
  896. GROUP BY
  897. m.industrial_subject_id
  898. ORDER BY
  899. publish_date DESC`
  900. _, err = o.Raw(sql).QueryRows(&items)
  901. return
  902. } //end
  903. // Kol sratr
  904. type DepartmentResp struct {
  905. DepartmentId int `description:"作者Id"`
  906. NickName string `description:"作者昵称"`
  907. ImgUrl string `description:"图片链接"`
  908. IsFollw bool `description:"是否关注"`
  909. IsHot bool `description:"是否关注"`
  910. FllowNum int `description:"关注数量"`
  911. List []*IndustrialDepartmentListResp
  912. }
  913. type DepartmentListResp struct {
  914. Paging *paging.PagingItem `description:"分页数据"`
  915. List []*DepartmentResp
  916. }
  917. type IndustrialDepartmentListResp struct {
  918. IndustrialManagementId int `description:"产业Id"`
  919. IndustryName string `description:"产业名称"`
  920. DepartmentId int `description:"作者Id"`
  921. }
  922. // 作者列表
  923. func GetDepartmentList(condition, conditionOrder string, userId, startSize, pageSize int) (items []*DepartmentResp, err error) {
  924. o := orm.NewOrm()
  925. sql := `SELECT
  926. d.nick_name,
  927. d.department_id,
  928. d.img_url,
  929. MAX( a.publish_date ) AS publish_date,
  930. ( SELECT count( 1 ) FROM cygx_article_department_follow AS f WHERE f.department_id = d.department_id AND user_id =? AND f.type= 1 ) AS fllow_num,
  931. ( SELECT count( 1 ) FROM cygx_article_department_follow AS f WHERE f.department_id = d.department_id AND f.type= 1 ) AS sum_num
  932. FROM
  933. cygx_article_department AS d
  934. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  935. WHERE
  936. 1 = 1
  937. AND publish_status = 1 ` + condition + `
  938. GROUP BY
  939. d.department_id ` + conditionOrder + ` , last_updated_time DESC LIMIT ?,?`
  940. _, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  941. return
  942. }
  943. // 获取数量
  944. func GetDepartmentlistCount(condition string) (count int, err error) {
  945. o := orm.NewOrm()
  946. sql := `SELECT
  947. count(*) AS count
  948. FROM
  949. (
  950. SELECT
  951. COUNT( 1 ) AS count
  952. FROM
  953. cygx_article_department AS d
  954. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  955. WHERE
  956. 1 = 1
  957. AND a.article_type_id > 0
  958. AND publish_status = 1
  959. GROUP BY
  960. d.department_id
  961. ) c `
  962. err = o.Raw(sql).QueryRow(&count)
  963. return
  964. }
  965. // 作者文章所关联的产业列表
  966. func GetIndustrialDepartmentList() (items []*IndustrialDepartmentListResp, err error) {
  967. o := orm.NewOrm()
  968. sql := `SELECT
  969. m.industrial_management_id,
  970. m.industry_name,
  971. d.department_id
  972. FROM
  973. cygx_article_department AS d
  974. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  975. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  976. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  977. WHERE
  978. 1 = 1
  979. AND a.article_type_id > 0
  980. AND publish_status = 1
  981. ORDER BY
  982. a.publish_date DESC`
  983. _, err = o.Raw(sql).QueryRows(&items)
  984. return
  985. }
  986. // 主题详情start
  987. type GetThemeDetailListResp struct {
  988. ArticleId int `description:"文章id"`
  989. Title string `description:"标题"`
  990. PublishDate string `description:"发布时间"`
  991. SubjectName string `description:"标的名称"`
  992. IndustrialSubjectId int `description:"标的id"`
  993. DepartmentId int `description:"作者Id"`
  994. NickName string `description:"作者昵称"`
  995. Pv int `description:"PV"`
  996. CollectNum int `description:"收藏人数"`
  997. IndustrialManagementId int `description:"产业Id"`
  998. IndustryName string `description:"产业名称"`
  999. FllowNum int `description:"关注数量"`
  1000. MyCollectNum int `description:"本人是否收藏"`
  1001. IsCollect bool `description:"本人是否收藏"`
  1002. }
  1003. type GetThemeAericleListResp struct {
  1004. ArticleId int `description:"文章id"`
  1005. Title string `description:"标题"`
  1006. PublishDate string `description:"发布时间"`
  1007. SubjectName string `description:"标的名称"`
  1008. IndustrialSubjectId int `description:"标的ID"`
  1009. DepartmentId int `description:"作者Id"`
  1010. NickName string `description:"作者昵称"`
  1011. Pv int `description:"PV"`
  1012. CollectNum int `description:"收藏人数"`
  1013. FllowNum int `description:"关注数量"`
  1014. MyCollectNum int `description:"本人是否收藏"`
  1015. IsCollect bool `description:"本人是否收藏"`
  1016. }
  1017. type GetThemeAericleListBuSubjectResp struct {
  1018. SubjectName string `description:"标的名称"`
  1019. List []*GetThemeAericleListResp
  1020. }
  1021. // 主题详情start
  1022. type GetThemeDetailResp struct {
  1023. IndustrialManagementId int `description:"产业Id"`
  1024. IndustryName string `description:"产业名称"`
  1025. IsFollw bool `description:"是否关注"`
  1026. ListSubject []*IndustrialSubject `description:"标的列表"`
  1027. List []*GetThemeAericleListResp
  1028. }
  1029. // 列表
  1030. func GetThemeDetail(userId, industrialManagementId int, condition string) (items []*GetThemeDetailListResp, err error) {
  1031. o := orm.NewOrm()
  1032. sql := `SELECT
  1033. a.article_id,
  1034. a.title,
  1035. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  1036. m.industry_name,
  1037. m.industrial_management_id,
  1038. d.nick_name,
  1039. d.department_id,
  1040. s.industrial_subject_id,
  1041. s.subject_name,
  1042. ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  1043. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  1044. ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id and user_id = ? ) AS my_collect_num,
  1045. ( SELECT count( 1 ) FROM cygx_industry_fllow AS ac WHERE user_id = ? AND ac.industrial_management_id = m.industrial_management_id AND ac.type= 1) AS fllow_num
  1046. FROM
  1047. cygx_article AS a
  1048. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  1049. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  1050. LEFT JOIN cygx_article_department AS d ON d.department_id = a.department_id
  1051. LEFT JOIN cygx_industrial_article_group_subject AS sg ON sg.article_id = a.article_id
  1052. LEFT JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = sg.industrial_subject_id
  1053. WHERE
  1054. 1 = 1
  1055. AND m.industrial_management_id = ?
  1056. AND publish_status = 1 ` + condition + ` GROUP BY article_id
  1057. ORDER BY
  1058. publish_date DESC`
  1059. _, err = o.Raw(sql, userId, userId, industrialManagementId).QueryRows(&items)
  1060. return
  1061. } //end
  1062. // 用户收藏榜start
  1063. type DepartmentDetailResp struct {
  1064. DepartmentId int `description:"作者Id"`
  1065. NickName string `description:"作者昵称"`
  1066. ImgUrl string `description:"图片链接"`
  1067. FllowNum int `description:"多少人关注"`
  1068. ArticleNum int `description:"文章数量"`
  1069. CollectNum int `description:"收藏人数"`
  1070. IsFllow bool `description:"是否关注"`
  1071. List []*ArticleCollectionResp
  1072. ListIndustrial []*IndustrialManagementNewResp
  1073. }
  1074. type DepartmentDetail struct {
  1075. DepartmentId int `description:"作者Id"`
  1076. NickName string `description:"作者昵称"`
  1077. ImgUrl string `description:"图片链接"`
  1078. FllowNum int `description:"多少人关注"`
  1079. ArticleNum int `description:"文章数量"`
  1080. CollectNum int `description:"收藏人数"`
  1081. IsFllow bool `description:"是否关注"`
  1082. MyFllowNum int `description:"本人是否关注"`
  1083. }
  1084. // 列表
  1085. func GetDepartmentDetail(userId, departmentId int, condition string) (item DepartmentDetail, err error) {
  1086. o := orm.NewOrm()
  1087. sql := `SELECT
  1088. d.department_id,
  1089. d.nick_name,
  1090. d.img_url,
  1091. ( SELECT count( 1 ) FROM cygx_article_department_follow AS af WHERE af.user_id = ? AND af.department_id = d.department_id AND af.type= 1 ) AS my_fllow_num,
  1092. ( SELECT count( 1 ) FROM cygx_article_department_follow AS f WHERE f.department_id = d.department_id AND f.type= 1 ) AS fllow_num,
  1093. ( SELECT count( 1 ) FROM cygx_article AS a WHERE a.department_id = d.department_id ` + condition + ` ) AS article_num,
  1094. ( SELECT count( 1 ) FROM cygx_article_collect AS c WHERE c.article_id IN (SELECT article_id FROM cygx_article AS a WHERE a.department_id = d.department_id ` + condition + ` )) AS collect_num
  1095. FROM
  1096. cygx_article_department AS d
  1097. WHERE
  1098. d.department_id = ?`
  1099. err = o.Raw(sql, userId, departmentId).QueryRow(&item)
  1100. return
  1101. } //end
  1102. // 报告搜索start
  1103. type ReoprtSearchResp struct {
  1104. ListYx []*ArticleCollectionResp `description:"研选报告"`
  1105. ListHz []*ArticleCollectionResp `description:"弘则报告"`
  1106. }
  1107. //// 列表
  1108. //func GetReoprtSearchList(condition string, userId int) (items []*ArticleCollectionResp, err error) {
  1109. // o := orm.NewOrm()
  1110. // sql := `SELECT
  1111. // a.article_id,
  1112. // a.title,
  1113. // date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  1114. // m.industry_name,
  1115. // m.industrial_management_id,
  1116. // ( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
  1117. // ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
  1118. // ( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ?) AS my_collect_num
  1119. // FROM
  1120. // cygx_article AS a
  1121. // LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  1122. // LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  1123. // WHERE
  1124. // 1 = 1 `
  1125. // if condition != "" {
  1126. // sql += condition
  1127. // }
  1128. // _, err = o.Raw(sql, userId).QueryRows(&items)
  1129. // return
  1130. //} //end
  1131. // 列表
  1132. func GetReoprtSearchList(condition string, userId int) (items []*ArticleCollectionResp, err error) {
  1133. o := orm.NewOrm()
  1134. sql := `SELECT
  1135. a.article_id,
  1136. a.title,
  1137. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
  1138. m.industry_name,
  1139. m.industrial_management_id
  1140. FROM
  1141. cygx_article AS a
  1142. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  1143. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  1144. WHERE
  1145. 1 = 1 `
  1146. if condition != "" {
  1147. sql += condition
  1148. }
  1149. _, err = o.Raw(sql).QueryRows(&items)
  1150. return
  1151. } //end
  1152. // 搜索资源包 start
  1153. type SearchResourceResp struct {
  1154. ListHz []*IndustrialManagementHotResp `description:"弘则"`
  1155. ListYx []*IndustrialManagementHotResp `description:"研选"`
  1156. }
  1157. // 搜索资源包 start
  1158. type SearchReportAndResourceResp struct {
  1159. ListHzResource []*IndustrialManagementHotResp `description:"弘则资源包"`
  1160. ListYxResource []*IndustrialManagementHotResp `description:"研选资源包"`
  1161. ListYxReport []*ArticleCollectionResp `description:"研选报告"`
  1162. ListHzReport []*ArticleCollectionResp `description:"弘则报告"`
  1163. }
  1164. // 产业列表
  1165. func GetSearchResourceList(userId int, condition string, startSize, pageSize int) (items []*IndustrialManagementHotResp, err error) {
  1166. o := orm.NewOrm()
  1167. sql := `SELECT
  1168. m.industry_name,
  1169. m.industrial_management_id,
  1170. MAX( a.publish_date ) as publish_date_order,
  1171. MIN(a.publish_date) AS min_report_time,
  1172. date_format( MAX( a.publish_date ), '%Y-%m-%d' ) AS publish_date,
  1173. (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
  1174. FROM
  1175. cygx_industrial_management AS m
  1176. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  1177. INNER JOIN cygx_article AS a ON a.article_id = mg.article_id AND a.article_type != 'lyjh'
  1178. WHERE
  1179. 1 = 1
  1180. AND publish_status = 1 ` + condition + ` GROUP BY m.industrial_management_id ORDER BY publish_date_order DESC `
  1181. if startSize > 0 || pageSize > 0 {
  1182. sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
  1183. }
  1184. _, err = o.Raw(sql).QueryRows(&items)
  1185. return
  1186. }
  1187. // 切换列表
  1188. type ReportBillboardTableResp struct {
  1189. Name string `description:"名称"`
  1190. Source int `description:"类型"`
  1191. List []*ChartPermission
  1192. }
  1193. // 切换列表
  1194. type ReportBillboardTableListResp struct {
  1195. List []*ReportBillboardTableResp
  1196. }
  1197. // 报告榜单start
  1198. type ArticleReportBillboardResp struct {
  1199. ArticleId int `description:"文章id"`
  1200. Title string `description:"标题"`
  1201. PublishDate string `description:"发布时间"`
  1202. PermissionName string `description:"行业名称"`
  1203. DepartmentId int `description:"作者Id"`
  1204. NickName string `description:"作者昵称"`
  1205. IsCollect bool `description:"本人是否收藏"`
  1206. Pv int `description:"PV"`
  1207. CollectNum int `description:"收藏人数"`
  1208. Source int `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
  1209. IsRoadShow bool `description:"是否是路演精华"`
  1210. CategoryId int `description:"分类ID"`
  1211. IsResearch bool `description:"是否属于研选"`
  1212. ArticleTypeId int `description:"文章类型ID"`
  1213. ArticleTypeName string `description:"文章类型名称"`
  1214. IsSpecial int `description:"是否为研选专栏"`
  1215. SpecialTags string `description:"研选专栏标签"`
  1216. MyCollectNum int `description:"本人是否收藏"`
  1217. SpecialType int `description:"专栏类型 1:笔记,2:观点"`
  1218. UserId int `description:"作者id"`
  1219. List []*IndustrialManagementIdInt
  1220. }
  1221. type ArticleReportBillboardLIstResp struct {
  1222. List []*ArticleReportBillboardResp
  1223. }
  1224. type ArticleReportBillboardLIstPageResp struct {
  1225. List []*ArticleReportBillboardResp
  1226. Paging *paging.PagingItem
  1227. }
  1228. // 报告收藏榜单列表
  1229. func GetReportCollectionBillboardList(limit int, pars []interface{}, condition string) (items []*ArticleReportBillboardResp, err error) {
  1230. o := orm.NewOrm()
  1231. sql := `SELECT
  1232. ac.id,
  1233. a.article_id,
  1234. a.title,
  1235. date_format(a.publish_date, '%Y-%m-%d') AS publish_date,
  1236. m.chart_permission_name AS permission_name,
  1237. COUNT(ac.id) AS collection_num
  1238. FROM
  1239. cygx_article AS a
  1240. INNER JOIN cygx_report_mapping AS m ON m.category_id = a.category_id
  1241. INNER JOIN cygx_article_collect AS ac ON ac.article_id = a.article_id
  1242. WHERE
  1243. 1 = 1
  1244. AND a.publish_status = 1 `
  1245. if condition != "" {
  1246. sql += condition
  1247. }
  1248. sql += ` GROUP BY a.article_id ORDER BY collection_num DESC, ac.id DESC, a.publish_date DESC`
  1249. sql += ` LIMIT ?`
  1250. _, err = o.Raw(sql, pars, limit).QueryRows(&items)
  1251. return
  1252. }
  1253. // 报告阅读榜单列表
  1254. func GetReportPvBillboardList(pars []interface{}, condition string) (items []*ArticleReportBillboardResp, err error) {
  1255. o := orm.NewOrm()
  1256. sql := `SELECT
  1257. a.article_id,
  1258. a.title,
  1259. date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date
  1260. FROM
  1261. cygx_article AS a
  1262. INNER JOIN cygx_report_mapping AS m ON m.category_id = a.category_id
  1263. WHERE
  1264. 1 = 1
  1265. AND a.publish_status = 1 `
  1266. if condition != "" {
  1267. sql += condition
  1268. }
  1269. _, err = o.Raw(sql, pars).QueryRows(&items)
  1270. return
  1271. }
  1272. // 获取产业报告+晨会点评数量
  1273. func GetTimeLineReportIndustrialCount(industrialManagementId int) (count int, err error) {
  1274. o := orm.NewOrm()
  1275. sql := `SELECT SUM(count) AS count FROM (
  1276. SELECT
  1277. COUNT( 1 ) count
  1278. FROM
  1279. cygx_article AS a
  1280. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = a.article_id
  1281. WHERE
  1282. a.publish_status = 1
  1283. AND a.is_class = 1
  1284. AND man_g.industrial_management_id = ?
  1285. UNION ALL
  1286. SELECT
  1287. COUNT( 1 ) count
  1288. FROM
  1289. cygx_morning_meeting_review_chapter AS mmc
  1290. INNER JOIN cygx_morning_meeting_reviews AS mm
  1291. WHERE
  1292. mm.id = mmc.meeting_id
  1293. AND mm.status = 1
  1294. AND mmc.industry_id = ? UNION ALL
  1295. SELECT
  1296. COUNT( 1 ) count
  1297. FROM
  1298. cygx_product_interior AS p
  1299. INNER JOIN cygx_product_interior_industrial_group_management AS pm
  1300. WHERE
  1301. p.product_interior_id = pm.product_interior_id
  1302. AND p.visible_range = 1
  1303. AND pm.industrial_management_id = ? ) AS t `
  1304. err = o.Raw(sql, industrialManagementId, industrialManagementId, industrialManagementId).QueryRow(&count)
  1305. return
  1306. }
  1307. type TimeLineReportItem struct {
  1308. Id int `description:"文章或晨报点评id"`
  1309. Title string `description:"标题"`
  1310. PublishTime string `description:"发布时间"`
  1311. Content string `description:"内容"`
  1312. VideoUrl string `description:"视频链接"`
  1313. VoiceUrl string `description:"音频链接"`
  1314. VoicePlaySeconds string `description:"音频时长"`
  1315. IsHaveVideo bool `description:"是否包含视频"`
  1316. ImgUrlPc string `description:"pc图片"`
  1317. SubCategoryName string `description:"二级分类"`
  1318. IsRed bool `description:"是否标红"`
  1319. Readnum int `description:"阅读数量"`
  1320. Resource int `description:"来源类型,1:文章、2:产品内测、3:晨报点评 4:活动回放视频 5:活动回放音频 "`
  1321. LinkArticleId int `description:"晨会精华报告ID链接"`
  1322. ListSubject []*CygxIndustrialSubject `description:"标的列表"`
  1323. }
  1324. // 获取产业报告+晨会点评列表
  1325. func GetTimeLineReportIndustrialList(userId, industrialManagementId, startSize, pageSize int) (items []*TimeLineReportItem, err error) {
  1326. o := orm.NewOrm()
  1327. sql := `SELECT
  1328. *
  1329. FROM
  1330. (
  1331. SELECT
  1332. a.article_id AS id,
  1333. a.title,
  1334. a.publish_date AS publish_time,
  1335. a.video_url,
  1336. '' AS voice_url,
  1337. a.sub_category_name,
  1338. '' AS content,
  1339. 1 AS resource,
  1340. '' AS voice_play_seconds,
  1341. ( 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
  1342. FROM
  1343. cygx_article AS a
  1344. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.article_id = a.article_id
  1345. WHERE
  1346. a.publish_status = 1
  1347. AND a.is_class = 1
  1348. AND man_g.industrial_management_id = ? GROUP BY id UNION ALL
  1349. SELECT
  1350. mmc.id,
  1351. mmc.title,
  1352. mm.publish_time AS publish_time,
  1353. '' AS video_url,
  1354. '' AS voice_url,
  1355. '时间线' AS sub_category_name,
  1356. mmc.content,
  1357. 3 AS resource,
  1358. '' AS voice_play_seconds,
  1359. 0 AS readnum
  1360. FROM
  1361. cygx_morning_meeting_review_chapter AS mmc
  1362. INNER JOIN cygx_morning_meeting_reviews AS mm
  1363. WHERE
  1364. mm.id = mmc.meeting_id
  1365. AND mm.STATUS = 1
  1366. AND mmc.industry_id = ? UNION ALL
  1367. SELECT
  1368. p.product_interior_id AS id,
  1369. p.title,
  1370. p.publish_time,
  1371. '' AS video_url,
  1372. '' AS voice_url,
  1373. '' AS sub_category_name,
  1374. '' AS content,
  1375. 2 AS resource,
  1376. '' AS voice_play_seconds,
  1377. 0 AS readnum
  1378. FROM
  1379. cygx_product_interior AS p
  1380. INNER JOIN cygx_product_interior_industrial_group_management AS pm
  1381. WHERE
  1382. p.product_interior_id = pm.product_interior_id
  1383. AND p.visible_range = 1
  1384. AND pm.industrial_management_id = ? UNION ALL
  1385. SELECT
  1386. ca.activity_id AS id,
  1387. cav.video_name AS title,
  1388. ca.activity_time AS publish_time,
  1389. cav.video_url AS video_url,
  1390. '' AS voice_url,
  1391. '' AS sub_category_name,
  1392. '' AS content,
  1393. 4 AS resource,
  1394. '' AS voice_play_seconds,
  1395. ( SELECT COUNT( 1 ) FROM cygx_activity_video_history AS rec WHERE rec.user_id = ` + strconv.Itoa(userId) + ` AND rec.activity_id = ca.activity_id ) AS readnum
  1396. FROM
  1397. cygx_activity AS ca
  1398. INNER JOIN cygx_activity_video AS cav ON ca.activity_id = cav.activity_id
  1399. INNER JOIN cygx_industrial_activity_group_management AS cam ON ca.activity_id=cam.activity_id
  1400. WHERE
  1401. cam.industrial_management_id = ? AND cam.source = 1 UNION ALL
  1402. SELECT
  1403. ca.activity_id AS id,
  1404. cavo.voice_name AS title,
  1405. ca.activity_time AS publish_time,
  1406. '' AS video_url,
  1407. cavo.voice_url AS voice_url,
  1408. '' AS sub_category_name,
  1409. '' AS content,
  1410. 5 AS resource,
  1411. cavo.voice_play_seconds AS voice_play_seconds,
  1412. ( SELECT COUNT( 1 ) FROM cygx_activity_voice_history AS rec WHERE rec.user_id = ` + strconv.Itoa(userId) + ` AND rec.activity_id = ca.activity_id ) AS readnum
  1413. FROM
  1414. cygx_activity AS ca
  1415. INNER JOIN cygx_activity_voice AS cavo ON ca.activity_id = cavo.activity_id
  1416. INNER JOIN cygx_industrial_activity_group_management AS cam ON ca.activity_id=cam.activity_id
  1417. WHERE
  1418. cam.industrial_management_id = ? AND cam.source = 1
  1419. ) AS t
  1420. `
  1421. sql += ` ORDER BY
  1422. t.publish_time DESC LIMIT ?,? `
  1423. _, err = o.Raw(sql, industrialManagementId, industrialManagementId, industrialManagementId, industrialManagementId, industrialManagementId, startSize, pageSize).QueryRows(&items)
  1424. return
  1425. }
  1426. type ArticleIdReq struct {
  1427. ArticleId int `description:"文章id"`
  1428. PlaySeconds int `description:"播放时长"`
  1429. PageRouter string `description:"页面路径"`
  1430. }
  1431. type IndustrialReadNum struct {
  1432. IndustrialManagementId int `description:"产业id"`
  1433. Readnum int `description:"阅读次数"`
  1434. }
  1435. // 获取该产业下文章的用户阅读次数-小红点用
  1436. func GetReportIndustrialReadNumList(userId int, industrialIds string, createtime time.Time) (items []*IndustrialReadNum, err error) {
  1437. o := orm.NewOrm()
  1438. sql := `SELECT a.industrial_management_id, MIN(a.readnum) AS readnum FROM (
  1439. SELECT man_g.industrial_management_id,( 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
  1440. FROM
  1441. cygx_article AS a
  1442. INNER JOIN cygx_industrial_article_group_management as man_g ON man_g.article_id = a.article_id
  1443. WHERE
  1444. a.publish_status = 1
  1445. AND a.is_class = 1
  1446. AND man_g.industrial_management_id IN (` + industrialIds + `)
  1447. AND a.publish_date > ?
  1448. GROUP BY a.article_id ORDER BY publish_date DESC
  1449. ) AS a GROUP BY industrial_management_id`
  1450. _, err = o.Raw(sql, createtime).QueryRows(&items)
  1451. return
  1452. }