industrial_management.go 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "hongze/hongze_cygx/utils"
  6. "strconv"
  7. "strings"
  8. "time"
  9. )
  10. type IndustrialManagementRep struct {
  11. IndustryName string `description:"产业名称"`
  12. IndustrialManagementId int `description:"产业id"`
  13. ChartPermissionId int `description:"权限id"`
  14. RecommendedIndex int `description:"推荐指数"`
  15. LayoutTime string `description:"布局时间"`
  16. ArticleReadNum int `description:"文章阅读数量"`
  17. IsResearch bool `description:"是否属于研选"`
  18. IsJump bool `description:"是否跳转"`
  19. IndustryNewLabel bool `description:"是否产业新标签"`
  20. }
  21. // 列表
  22. func GetIndustrialManagementRepList(condition string, pars []interface{}, startSize, pageSize int) (items []*IndustrialManagementRep, err error) {
  23. o := orm.NewOrm()
  24. sql := `SELECT * FROM cygx_industrial_management as art WHERE 1= 1 `
  25. if condition != "" {
  26. sql += condition
  27. }
  28. sql += ` LIMIT ?,? `
  29. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  30. return
  31. }
  32. type IndustrialManagementCount struct {
  33. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  34. }
  35. // 获取产业置顶数量分类列表
  36. func GetIndustrialManagemenCountTop(sqlChartPermissionId string, uid int, condition string) (items []*IndustrialManagementCount, err error) {
  37. o := orm.NewOrm()
  38. sql := `SELECT
  39. man_g.industrial_management_id
  40. FROM
  41. cygx_industrial_article_group_management AS man_g
  42. INNER JOIN cygx_industrial_management as man ON man.industrial_management_id = man_g.industrial_management_id
  43. WHERE 1=1 ` + sqlChartPermissionId + `
  44. AND man_g.industrial_management_id IN ( SELECT industrial_management_id FROM cygx_industry_top WHERE user_id = ? ) ` + condition + `
  45. GROUP BY
  46. man_g.industrial_management_id`
  47. _, err = o.Raw(sql, uid).QueryRows(&items)
  48. return
  49. }
  50. // 获取产业不置顶数量
  51. func GetIndustrialManagemenCountNoTop(sqlChartPermissionId string, uid int, condition string) (items []*IndustrialManagementCount, err error) {
  52. o := orm.NewOrm()
  53. sql := `SELECT
  54. man_g.industrial_management_id
  55. FROM
  56. cygx_industrial_article_group_management AS man_g
  57. INNER JOIN cygx_industrial_management as man ON man.industrial_management_id = man_g.industrial_management_id
  58. WHERE 1=1 ` + sqlChartPermissionId + `
  59. AND man_g.industrial_management_id NOT IN ( SELECT industrial_management_id FROM cygx_industry_top WHERE user_id = ? ) ` + condition + `
  60. GROUP BY
  61. man_g.industrial_management_id`
  62. _, err = o.Raw(sql, uid).QueryRows(&items)
  63. return
  64. }
  65. // 产业列表
  66. func GetIndustrialManagementAll(uid int, condition, orderSrt string, startSize, pageSize int) (items []*IndustrialManagement, err error) {
  67. o := orm.NewOrm()
  68. sql := `SELECT
  69. man.*,re.chart_permission_name as permission_name,
  70. MAX(art.article_id ) AS article_id,
  71. man.new_art_publish_date AS update_time , MIN(art.publish_date) AS min_report_time,(
  72. SELECT COUNT( 1 ) FROM cygx_article_history_record AS rec WHERE rec.user_id = ` + strconv.Itoa(uid) + ` AND rec.article_id = art.article_id ) AS readnum ,
  73. (SELECT COUNT( 1 ) FROM cygx_industry_fllow AS f WHERE f.user_id = ` + strconv.Itoa(uid) + ` AND f.industrial_management_id = man.industrial_management_id AND f.type = 1) AS is_follow
  74. FROM
  75. cygx_industrial_management AS man
  76. INNER JOIN cygx_report_mapping AS re ON re.chart_permission_id = man.chart_permission_id
  77. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.industrial_management_id = man.industrial_management_id
  78. INNER JOIN cygx_article AS art ON art.article_id = man_g.article_id
  79. WHERE 1= 1
  80. AND re.report_type = 2
  81. AND art.is_report = 1
  82. AND art.is_class = 1 ` + condition + `
  83. GROUP BY
  84. man.industry_name
  85. ORDER BY ` + orderSrt + ` LIMIT ?,?`
  86. //AND man.industrial_management_id NOT IN ( SELECT industrial_management_id FROM cygx_industry_top WHERE user_id = ` + strconv.Itoa(uid) + ` )
  87. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  88. return
  89. }
  90. // 产业列表
  91. func GetIndustrialManagementAllCount(condition string) (count int, err error) {
  92. o := orm.NewOrm()
  93. sql := `SELECT
  94. COUNT(*) as count
  95. FROM
  96. (SELECT
  97. COUNT(*)
  98. FROM
  99. cygx_industrial_management AS man
  100. INNER JOIN cygx_report_mapping AS re ON re.chart_permission_id = man.chart_permission_id
  101. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.industrial_management_id = man.industrial_management_id
  102. INNER JOIN cygx_article AS art ON art.article_id = man_g.article_id
  103. WHERE
  104. 1 = 1
  105. AND re.report_type = 2
  106. AND art.is_report = 1
  107. AND art.is_class = 1 ` + condition + ` GROUP BY man.industrial_management_id) AS num `
  108. err = o.Raw(sql).QueryRow(&count)
  109. return
  110. }
  111. // 产业列表 -置顶
  112. func GetIndustrialManagementTopAll(uid int, condition string, startSize, pageSize int) (items []*IndustrialManagement, err error) {
  113. o := orm.NewOrm()
  114. sql := `SELECT
  115. man.*
  116. FROM
  117. cygx_industrial_management AS man
  118. INNER JOIN cygx_industry_top as top ON man.industrial_management_id = top.industrial_management_id
  119. INNER JOIN cygx_report_mapping AS re ON re.chart_permission_id = man.chart_permission_id
  120. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.industrial_management_id = man.industrial_management_id
  121. INNER JOIN cygx_article AS art ON art.article_id = man_g.article_id
  122. WHERE 1=1
  123. AND top.user_id = ` + strconv.Itoa(uid) + `
  124. AND re.report_type = 2
  125. AND art.is_report = 1
  126. AND art.is_class = 1 ` + condition + `
  127. GROUP BY
  128. man.industry_name
  129. ORDER BY
  130. top.create_time DESC LIMIT ?,?`
  131. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  132. return
  133. }
  134. // 标的列表
  135. func GetIndustrialSubjectAll(IndustrialManagementId int) (items []*IndustrialSubject, err error) {
  136. o := orm.NewOrm()
  137. sql := `SELECT * FROM cygx_industrial_subject WHERE industrial_management_id = ? `
  138. _, err = o.Raw(sql, IndustrialManagementId).QueryRows(&items)
  139. return
  140. }
  141. // 标的列表
  142. func GetIndustrialSubjectAllByIndustrialId(industrialIdArr []int) (items []*IndustrialSubject, err error) {
  143. o := orm.NewOrm()
  144. sql := `SELECT * FROM cygx_industrial_subject WHERE industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialIdArr)) + `) `
  145. _, err = o.Raw(sql, industrialIdArr).QueryRows(&items)
  146. return
  147. }
  148. // GetTopOneMonthArtReadNumIndustry 获取近一个月报告阅读数量最多的产业信息 根据行业分组
  149. func GetTopOneMonthArtReadNumIndustryAll(condition string, pars []interface{}) (items []*IndustrialManagement, err error) {
  150. sql := `SELECT * FROM cygx_industrial_management WHERE 1 = 1 `
  151. if condition != `` {
  152. sql += condition
  153. }
  154. sql += ` ORDER BY article_read_num DESC `
  155. _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&items)
  156. return
  157. }
  158. // 分析师列表
  159. func GetIndustrialAnalystAll(IndustrialManagementId int) (items []*IndustrialAnalyst, err error) {
  160. o := orm.NewOrm()
  161. sql := `SELECT * FROM cygx_industrial_analyst where industrial_management_id = ? `
  162. _, err = o.Raw(sql, IndustrialManagementId).QueryRows(&items)
  163. return
  164. }
  165. // 获取产业数量
  166. func GetIndustrialManagementCount(IndustrialManagementId int) (count int, err error) {
  167. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_industrial_management WHERE industrial_management_id=? `
  168. o := orm.NewOrm()
  169. err = o.Raw(sqlCount, IndustrialManagementId).QueryRow(&count)
  170. return
  171. }
  172. func GetIndustrialManagementDetail(industrialManagementId int) (items *IndustrialManagementRep, err error) {
  173. o := orm.NewOrm()
  174. sql := `SELECT * FROM cygx_industrial_management WHERE industrial_management_id = ?`
  175. err = o.Raw(sql, industrialManagementId).QueryRow(&items)
  176. return
  177. }
  178. // 获取该产业下最新的文章详情
  179. func GetIndustrialNewArticleDetail(industrialManagementId int) (item *ArticleDetail, err error) {
  180. o := orm.NewOrm()
  181. sql := `SELECT
  182. *
  183. FROM
  184. cygx_article
  185. WHERE
  186. article_id IN (
  187. SELECT
  188. article_id
  189. FROM
  190. cygx_industrial_article_group_management
  191. WHERE
  192. industrial_management_id = ?
  193. )
  194. AND is_class = 1 AND is_report = 1
  195. ORDER BY
  196. is_report DESC,
  197. publish_date DESC
  198. LIMIT 0,1`
  199. err = o.Raw(sql, industrialManagementId).QueryRow(&item)
  200. return
  201. }
  202. // 修改产业是否属于新标签
  203. func UpdateIndustrialIsNewLabel() (err error) {
  204. o := orm.NewOrm()
  205. resultTime := time.Now().AddDate(0, -2, 0).Format(utils.FormatDateTime)
  206. var condition string
  207. condition += ` AND is_hand_new_label = 0 AND create_time < ` + "'" + resultTime + "'"
  208. msql := " UPDATE cygx_industrial_management SET is_new_label = 0 WHERE 1 = 1 " + condition
  209. _, err = o.Raw(msql).Exec()
  210. return
  211. }
  212. type IndustrialManagementId struct {
  213. IndustrialManagementId string `description:"产业Id"`
  214. }
  215. type IndustrialManagementName struct {
  216. IndustryName string `description:"产业名称"`
  217. }
  218. // 获取归类产业报告数量大于10的
  219. func GetIndustrialMorethan10() (items []*IndustrialManagementId, err error) {
  220. o := orm.NewOrm()
  221. sql := `SELECT * FROM
  222. ( SELECT industrial_management_id, COUNT( 1 ) AS ca FROM cygx_industrial_article_group_management GROUP BY industrial_management_id ) AS na
  223. WHERE ca > 10 `
  224. _, err = o.Raw(sql).QueryRows(&items)
  225. return
  226. }
  227. // 修改产业是否属于深度标签
  228. func UpdateIndustrialIsDeepLabel(idStr string) (err error) {
  229. o := orm.NewOrm()
  230. msql := `UPDATE cygx_industrial_management
  231. SET is_deep_label = 1
  232. WHERE
  233. industrial_management_id IN (
  234. SELECT
  235. a.industrial_management_id
  236. FROM
  237. cygx_industrial_article_group_management AS a
  238. INNER JOIN cygx_article AS b ON b.id = a.cygx_article_id
  239. WHERE
  240. 1 = 1
  241. AND b.match_type_name = '行业深度'
  242. AND a.industrial_management_id IN ( ` + idStr + `)
  243. GROUP BY
  244. a.industrial_management_id)`
  245. _, err = o.Raw(msql).Exec()
  246. return
  247. }
  248. type IndustrialManagementIdInt struct {
  249. IndustrialManagementId int `description:"产业Id"`
  250. IndustryName string `description:"产业名称"`
  251. SubjectName string `description:"标的名称"`
  252. ArticleId int `description:"文章ID"`
  253. IsResearch bool `description:"是否属于研选"`
  254. ChartPermissionId int `description:"权限id"`
  255. }
  256. type IndustrialManagementIdInts struct {
  257. IndustrialManagementId int `description:"产业Id"`
  258. IndustryName string `description:"产业名称"`
  259. SubjectNames string `description:"标的名称"`
  260. ArticleId int `description:"文章ID"`
  261. IndustrialAndSubjectIds string `description:"关联标的以及产业ID"`
  262. }
  263. type IndustrialManagementIdName struct {
  264. DepartmentId int `description:"作者ID"`
  265. ArticleId int `description:"文章id"`
  266. IndustryName string `description:"产业名称"`
  267. SubjectName string `description:"标的名称"`
  268. IsReport string `description:"1观点,0纪要"`
  269. }
  270. // 获取归类产业报告数量大于10的
  271. func GetIndustrialManagementIds() (items []*IndustrialManagementIdInt, err error) {
  272. o := orm.NewOrm()
  273. //sql := `SELECT a.industrial_management_id FROM
  274. // cygx_industrial_management AS a
  275. // INNER JOIN cygx_industrial_subject as b ON b.industrial_management_id=a.industrial_management_id
  276. // WHERE b.industrial_subject_id > 0
  277. // GROUP BY a.industrial_management_id `
  278. sql := `SELECT industrial_management_id,industry_name FROM cygx_industrial_management `
  279. _, err = o.Raw(sql).QueryRows(&items)
  280. return
  281. }
  282. func GetcygxIndustrialSubject(industrialManagementId int) (items []*IndustrialSubject, err error) {
  283. o := orm.NewOrm()
  284. sql := `SELECT subject_name,industrial_subject_id FROM cygx_industrial_subject WHERE industrial_management_id = ?`
  285. _, err = o.Raw(sql, industrialManagementId).QueryRows(&items)
  286. return
  287. }
  288. // 通过名称获取
  289. func GetcygxIndustrialSubjectByName(name string) (industrial_management_id string, err error) {
  290. o := orm.NewOrm()
  291. sql := ` SELECT industrial_subject_id FROM cygx_industrial_subject WHERE subject_name = ?`
  292. err = o.Raw(sql, name).QueryRow(&industrial_management_id)
  293. return
  294. }
  295. func UpdateIndustrialManagementSubjectNames(nameStr string, industrialManagementId int) (err error) {
  296. o := orm.NewOrm()
  297. sql := `UPDATE cygx_industrial_management SET subject_names = ? WHERE industrial_management_id = ?`
  298. _, err = o.Raw(sql, nameStr, industrialManagementId).Exec()
  299. return
  300. }
  301. // 处理每个产业下所关联的文章的阅读量 start
  302. func IndustrialManagementAll() (items []*IndustrialManagement, err error) {
  303. o := orm.NewOrm()
  304. sql := `SELECT * FROM cygx_industrial_management `
  305. _, err = o.Raw(sql).QueryRows(&items)
  306. return
  307. }
  308. func GetIndustrialManagementArtCount(industrialManagementId int) (count int, err error) {
  309. sqlCount := ` SELECT COUNT(1) AS count
  310. FROM cygx_article_history_record_newpv AS h
  311. INNER JOIN cygx_industrial_article_group_management as mg ON mg.article_id = h.article_id
  312. WHERE mg.industrial_management_id = ? AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( h.create_time ) `
  313. o := orm.NewOrm()
  314. err = o.Raw(sqlCount, industrialManagementId).QueryRow(&count)
  315. return
  316. }
  317. type IndustrialManagementArtHistoryCount struct {
  318. IndustrialManagementId int `description:"产业id"`
  319. Count int `description:"数量"`
  320. }
  321. func GetIndustrialManagementArtHistoryCount(condition string) (items []*IndustrialManagementArtHistoryCount, err error) {
  322. sql := `SELECT
  323. COUNT( 1 ) AS count,
  324. mg.industrial_management_id
  325. FROM
  326. cygx_article_history_record_newpv AS h
  327. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = h.article_id
  328. INNER JOIN cygx_article AS a ON a.article_id = h.article_id
  329. WHERE
  330. 1 = 1
  331. AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( h.create_time ) ` + condition + `
  332. GROUP BY
  333. mg.industrial_management_id `
  334. o := orm.NewOrm()
  335. _, err = o.Raw(sql).QueryRows(&items)
  336. return
  337. }
  338. func GetIndustrialManagementActivityHistoryCount() (items []*IndustrialManagementArtHistoryCount, err error) {
  339. sql := `SELECT
  340. COUNT( 1 ) AS count,
  341. mg.industrial_management_id
  342. FROM
  343. cygx_activity_meet_detail_log AS h
  344. INNER JOIN cygx_industrial_activity_group_management AS mg ON mg.activity_id = h.activity_id
  345. INNER JOIN cygx_activity AS a ON a.activity_id = h.activity_id
  346. WHERE
  347. 1 = 1
  348. AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( a.activity_time )
  349. GROUP BY
  350. mg.industrial_management_id `
  351. o := orm.NewOrm()
  352. _, err = o.Raw(sql).QueryRows(&items)
  353. return
  354. }
  355. func UpdateIndustrialManagementArtticleReadNum() (err error) {
  356. o := orm.NewOrm()
  357. sql := `UPDATE cygx_industrial_management SET article_read_num = 0 ,yanxuan_article_read_num = 0 ,activity_num = 0 `
  358. _, err = o.Raw(sql).Exec()
  359. return
  360. }
  361. func UpdateIndustrialManagementArtReadNum(num, industrialManagementId int) (err error) {
  362. o := orm.NewOrm()
  363. sql := `UPDATE cygx_industrial_management SET article_read_num = ? WHERE industrial_management_id = ?`
  364. _, err = o.Raw(sql, num, industrialManagementId).Exec()
  365. return
  366. }
  367. func UpdateIndustrialManagementArtYanXuanReadNum(num, industrialManagementId int) (err error) {
  368. o := orm.NewOrm()
  369. sql := `UPDATE cygx_industrial_management SET yanxuan_article_read_num = ? WHERE industrial_management_id = ?`
  370. _, err = o.Raw(sql, num, industrialManagementId).Exec()
  371. return
  372. }
  373. func UpdateIndustrialManagementActivityNum(num, industrialManagementId int) (err error) {
  374. o := orm.NewOrm()
  375. sql := `UPDATE cygx_industrial_management SET activity_num = ? WHERE industrial_management_id = ?`
  376. _, err = o.Raw(sql, num, industrialManagementId).Exec()
  377. return
  378. }
  379. // 更新产业布局时间
  380. func UpdateIndustrialManagementLayoutTime(layoutTime string, industrialManagementId int) (err error) {
  381. o := orm.NewOrm()
  382. sql := `UPDATE cygx_industrial_management SET layout_time = ? WHERE industrial_management_id = ?`
  383. _, err = o.Raw(sql, layoutTime, industrialManagementId).Exec()
  384. return
  385. }
  386. // 获取产业下阅读数量第三的产业详情
  387. func GetIndustrialManagementHot3(chartPermissionId int) (item *IndustrialManagementRep, err error) {
  388. o := orm.NewOrm()
  389. sql := `SELECT * FROM cygx_industrial_management WHERE chart_permission_id = ? ORDER BY article_read_num DESC LIMIT 2,1`
  390. err = o.Raw(sql, chartPermissionId).QueryRow(&item)
  391. return
  392. }
  393. // 获取产业关联标的的数量
  394. func GetIndustrialManagementSubjectCount(industrialManagementId int) (count int, err error) {
  395. sqlCount := ` SELECT COUNT(1) AS count FROM
  396. cygx_industrial_subject AS s
  397. INNER JOIN cygx_industrial_article_group_subject as sg ON sg.industrial_subject_id = s.industrial_subject_id
  398. INNER JOIN cygx_article as a ON a.article_id = sg.article_id
  399. WHERE a.industrial_management_id = ?
  400. AND a.publish_status = 1`
  401. o := orm.NewOrm()
  402. err = o.Raw(sqlCount, industrialManagementId).QueryRow(&count)
  403. return
  404. }
  405. // 获取产业关联标的列表
  406. func GetIndustrialManagementSubjectList(articleId int) (items []*IndustrialSubject, err error) {
  407. o := orm.NewOrm()
  408. sql := `SELECT
  409. s.subject_name
  410. FROM
  411. cygx_industrial_subject AS s
  412. INNER JOIN cygx_industrial_article_group_subject AS sg ON sg.industrial_subject_id = s.industrial_subject_id
  413. INNER JOIN cygx_article AS a
  414. WHERE
  415. sg.article_id = ?
  416. AND a.publish_status = 1
  417. GROUP BY
  418. s.industrial_subject_id
  419. ORDER BY
  420. sg.id ASC
  421. LIMIT 4`
  422. _, err = o.Raw(sql, articleId).QueryRows(&items)
  423. return
  424. }
  425. type IndustrialManagementNewResp struct {
  426. IndustrialManagementId int `description:"产业Id"`
  427. IndustryName string `description:"产业名称"`
  428. IsHot bool `description:"是否是热门"`
  429. ArticleReadNum int `description:"文章阅读数量"`
  430. }
  431. type IndustrialManagementNewList struct {
  432. List []*IndustrialManagementNewResp
  433. }
  434. // 近期更新主题列表
  435. func GetIndustrialManagementNewList(condition string) (items []*IndustrialManagementNewResp, err error) {
  436. o := orm.NewOrm()
  437. sql := `SELECT
  438. m.industrial_management_id,
  439. m.industry_name,
  440. m.article_read_num,
  441. MAX( a.publish_date ) AS publish_date
  442. FROM
  443. cygx_article AS a
  444. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  445. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  446. WHERE
  447. 1 = 1
  448. AND a.article_type_id > 0
  449. AND publish_status = 1 ` + condition + `
  450. GROUP BY
  451. m.industrial_management_id
  452. ORDER BY
  453. publish_date DESC LIMIT 12`
  454. _, err = o.Raw(sql).QueryRows(&items)
  455. return
  456. }
  457. // 获取产业关联标的列表
  458. func GetIndustrialManagementForSubjecName(subjectName string, chartPermissionId int) (items []*IndustrialSubject, err error) {
  459. o := orm.NewOrm()
  460. sql := `SELECT s.subject_name,s.industrial_subject_id,m.industrial_management_id,m.industry_name,layout_time
  461. FROM cygx_industrial_subject as s
  462. INNER JOIN cygx_industrial_management as m ON m.industrial_management_id = s.industrial_management_id
  463. WHERE subject_name IN (` + subjectName + `) AND m.chart_permission_id = ? `
  464. _, err = o.Raw(sql, chartPermissionId).QueryRows(&items)
  465. return
  466. }
  467. // 报告分类的新增与修改
  468. func ReportArticleClassificationEditNew(reportId int, industrialManagementIdStr string, articleId int, ndustrialSubjectIdStr string) (err error) {
  469. to, err := orm.NewOrm().Begin()
  470. if err != nil {
  471. return
  472. }
  473. defer func() {
  474. fmt.Println(err)
  475. if err == nil {
  476. to.Commit()
  477. } else {
  478. to.Rollback()
  479. }
  480. }()
  481. //修改文章是否过滤字段
  482. sql := `UPDATE cygx_article SET is_filter=0, is_class=1 WHERE article_id=? `
  483. _, err = to.Raw(sql, articleId).Exec()
  484. if err != nil {
  485. return
  486. }
  487. //删除文章关联标的
  488. sql = ` DELETE FROM cygx_industrial_article_group_subject WHERE article_id = ?`
  489. fmt.Println(articleId)
  490. _, err = to.Raw(sql, articleId).Exec()
  491. if err != nil {
  492. return
  493. }
  494. //添加文章关联标的
  495. if ndustrialSubjectIdStr != "0" && ndustrialSubjectIdStr != "" {
  496. strList := strings.Split(ndustrialSubjectIdStr, ",")
  497. for _, v := range strList {
  498. sql := `INSERT INTO cygx_industrial_article_group_subject ( cygx_article_id, article_id, industrial_subject_id, create_time ) VALUES ( ?, ?, ?, ? )`
  499. _, err = to.Raw(sql, reportId, articleId, v, time.Now()).Exec()
  500. if err != nil {
  501. return
  502. }
  503. }
  504. }
  505. //删除文章关联行业 (避免截断表时产生的脏数据,故不用update而是先删除再增加)
  506. sql = ` DELETE FROM cygx_industrial_article_group_management WHERE article_id = ?`
  507. _, err = to.Raw(sql, articleId).Exec()
  508. if err != nil {
  509. return
  510. }
  511. //添加文章关联行业
  512. industrialStrList := strings.Split(industrialManagementIdStr, ",")
  513. for _, v := range industrialStrList {
  514. sql = ` INSERT INTO cygx_industrial_article_group_management ( cygx_article_id, article_id, industrial_management_id, create_time ) VALUES ( ?, ?, ?, ? )`
  515. _, err = to.Raw(sql, reportId, articleId, v, time.Now()).Exec()
  516. if err != nil {
  517. return
  518. }
  519. }
  520. return
  521. }
  522. // 通过标的名称获取相关联的活动ID
  523. func GetActivityIdListBySubjecName(subjectName string) (items []*ActivityIdRep, err error) {
  524. o := orm.NewOrm()
  525. sql := `SELECT * FROM cygx_industrial_activity_group_subject WHERE industrial_subject_id IN (SELECT industrial_subject_id FROM cygx_industrial_subject WHERE subject_name IN(` + subjectName + `) ) GROUP BY activity_id`
  526. _, err = o.Raw(sql).QueryRows(&items)
  527. return
  528. }
  529. // 产业关注榜
  530. func GetIndustrialManagementFllowBillboard(pars []interface{}, condition, orderSrt string, startSize, pageSize int) (items []*IndustrialManagement, err error) {
  531. o := orm.NewOrm()
  532. sql := `SELECT
  533. man.*
  534. FROM
  535. cygx_industrial_management AS man
  536. INNER JOIN cygx_report_mapping AS re ON re.chart_permission_id = man.chart_permission_id
  537. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.industrial_management_id = man.industrial_management_id
  538. INNER JOIN cygx_article AS art ON art.article_id = man_g.article_id
  539. WHERE
  540. 1 = 1
  541. AND re.report_type = 2
  542. AND art.is_report = 1
  543. AND art.is_class = 1
  544. AND art.publish_status = 1 ` + condition + ` GROUP BY man.industrial_management_id ORDER BY ` + orderSrt + ` LIMIT ?,?`
  545. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  546. return
  547. }
  548. // 获取标的列表
  549. func GetSubjectList(pars []interface{}, condition string) (items []*IndustrialManagementIdInt, err error) {
  550. o := orm.NewOrm()
  551. sql := `SELECT
  552. subject_name,
  553. s.industrial_management_id
  554. FROM
  555. cygx_industrial_subject AS s
  556. INNER JOIN cygx_industrial_article_group_subject AS sg ON sg.industrial_subject_id = s.industrial_subject_id
  557. WHERE
  558. 1 = 1 ` + condition + `
  559. GROUP BY
  560. s.industrial_subject_id`
  561. _, err = o.Raw(sql, pars).QueryRows(&items)
  562. return
  563. }
  564. // 获取标的列表
  565. func GetIndustrialListByarticleId(pars []interface{}, condition string) (items []*IndustrialManagementIdInt, err error) {
  566. o := orm.NewOrm()
  567. sql := `SELECT
  568. mg.article_id,
  569. m.industry_name,
  570. mg.industrial_management_id
  571. FROM
  572. cygx_industrial_management AS m
  573. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  574. WHERE
  575. 1 = 1 ` + condition + ` GROUP BY mg.article_id, mg.industrial_management_id `
  576. _, err = o.Raw(sql, pars).QueryRows(&items)
  577. return
  578. }
  579. // 修改产业关注数量
  580. func UpdateIndustrialManagementFllowNum(num, industrialManagementId int) (err error) {
  581. o := orm.NewOrm()
  582. sql := `UPDATE cygx_industrial_management SET user_fllow_num = ? WHERE industrial_management_id = ?`
  583. _, err = o.Raw(sql, num, industrialManagementId).Exec()
  584. return
  585. }
  586. // 通过id 获取详情
  587. func GetIndustrialManagemenDetailByAaticleID(articleId int) (items []*IndustrialManagementRep, err error) {
  588. o := orm.NewOrm()
  589. sql := `SELECT
  590. article_id,
  591. m.industrial_management_id,
  592. industry_name
  593. FROM
  594. cygx_industrial_article_group_management AS mg
  595. INNER JOIN cygx_industrial_management AS m ON mg.industrial_management_id = m.industrial_management_id
  596. WHERE
  597. mg.article_id = ? GROUP BY mg.industrial_management_id `
  598. _, err = o.Raw(sql, articleId).QueryRows(&items)
  599. return
  600. }
  601. // 获取所有的产业
  602. func GetindustrialManagement() (items []*IndustrialManagementRep, err error) {
  603. o := orm.NewOrm()
  604. sql := `SELECT
  605. i.*
  606. FROM
  607. cygx_industrial_management AS i
  608. INNER JOIN cygx_industrial_article_group_management AS m ON m.industrial_management_id = i.industrial_management_id
  609. GROUP BY
  610. i.industrial_management_id `
  611. _, err = o.Raw(sql).QueryRows(&items)
  612. return
  613. }
  614. // GetActiveArticleIndustryIds 获取有已归类行业报告的行业IDs
  615. func GetActiveArticleIndustryIds() (ids []int, err error) {
  616. sql := `SELECT
  617. man.industrial_management_id
  618. FROM
  619. cygx_industrial_management AS man
  620. JOIN cygx_report_mapping AS re ON re.chart_permission_id = man.chart_permission_id
  621. JOIN cygx_industrial_article_group_management AS man_g ON man_g.industrial_management_id = man.industrial_management_id
  622. JOIN cygx_article AS art ON art.article_id = man_g.article_id
  623. WHERE
  624. 1 = 1 AND re.report_type = 2 AND art.is_report = 1 AND art.is_class = 1 AND art.publish_status = 1
  625. GROUP BY
  626. man.industrial_management_id`
  627. _, err = orm.NewOrm().Raw(sql).QueryRows(&ids)
  628. return
  629. }
  630. // GetTopOneMonthArtReadNumIndustry 获取近一个月报告阅读数量最多的产业信息
  631. func GetTopOneMonthArtReadNumIndustry(condition string, pars []interface{}) (item *IndustrialManagement, err error) {
  632. sql := `SELECT * FROM cygx_industrial_management WHERE 1 = 1 `
  633. if condition != `` {
  634. sql += condition
  635. }
  636. sql += ` ORDER BY article_read_num DESC LIMIT 1`
  637. err = orm.NewOrm().Raw(sql, pars).QueryRow(&item)
  638. return
  639. }
  640. // GetSourceIndustryByName 通过名称获取资源包产业
  641. func GetSourceIndustryByName(industryName string) (item *IndustrialManagement, err error) {
  642. sql := `SELECT
  643. m.industry_name,
  644. m.industrial_management_id,
  645. m.chart_permission_id
  646. FROM
  647. cygx_industrial_management AS m
  648. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  649. INNER JOIN cygx_article AS a ON a.article_id = mg.article_id AND a.article_type != 'lyjh'
  650. WHERE
  651. 1 = 1 AND m.industry_name = ? AND a.publish_status = 1 AND a.article_id < 1000000
  652. GROUP BY
  653. m.industrial_management_id`
  654. err = orm.NewOrm().Raw(sql, industryName).QueryRow(&item)
  655. return
  656. }
  657. // GetIndustryByName 通过名称获取产业
  658. func GetIndustryByName(industryName string) (item *IndustrialManagement, err error) {
  659. sql := `SELECT * FROM cygx_industrial_management WHERE industry_name = ? LIMIT 1`
  660. err = orm.NewOrm().Raw(sql, industryName).QueryRow(&item)
  661. return
  662. }
  663. type IndustrialManagementArticle struct {
  664. IndustrialManagementId int `description:"产业Id"`
  665. IndustryName string `description:"产业名称"`
  666. ArticleId int `description:"文章ID"`
  667. PublishDate string `description:"发布时间"`
  668. }
  669. // 时间线的更新时间
  670. func GetTimeLineReportIndustrialPublishdateList(industrialIdArr []int) (items []*IndustrialManagementArticle, err error) {
  671. if len(industrialIdArr) == 0 {
  672. return
  673. }
  674. o := orm.NewOrm()
  675. sql := `SELECT
  676. mmc.id,
  677. 0,
  678. mmc.industry_id AS industrial_management_id,
  679. mmc.content AS title,
  680. MAX( mm.meeting_time ) AS publish_date
  681. FROM
  682. cygx_morning_meeting_review_chapter AS mmc
  683. INNER JOIN cygx_morning_meeting_reviews AS mm
  684. WHERE
  685. mm.id = mmc.meeting_id
  686. AND mm.STATUS = 1
  687. AND mmc.industry_id IN (` + utils.GetOrmInReplace(len(industrialIdArr)) + `)
  688. GROUP BY industrial_management_id ORDER BY publish_date DESC `
  689. _, err = o.Raw(sql, industrialIdArr).QueryRows(&items)
  690. return
  691. }
  692. // 获取该产业下最新的文章详情
  693. func GetNewArticleDetailByIndustrialIds(industrialIdArr []int) (items []*IndustrialManagementArticle, err error) {
  694. arrLen := len(industrialIdArr)
  695. if arrLen == 0 {
  696. return
  697. }
  698. o := orm.NewOrm()
  699. sql := `SELECT
  700. mg.industrial_management_id,
  701. MAX( a.article_id ) AS article_id,
  702. a.title,
  703. MAX( a.publish_date ) AS publish_date
  704. FROM
  705. cygx_industrial_article_group_management AS mg
  706. INNER JOIN cygx_article AS a ON mg.article_id = a.article_id
  707. WHERE
  708. 1 = 1
  709. AND a.is_report = 1
  710. AND a.is_class = 1
  711. AND mg.industrial_management_id IN(` + utils.GetOrmInReplace(len(industrialIdArr)) + `)
  712. GROUP BY
  713. mg.industrial_management_id `
  714. _, err = o.Raw(sql, industrialIdArr).QueryRows(&items)
  715. return
  716. }
  717. // 获取该产业下最新的产品内测详情
  718. func GetNewProductInteriorByIndustrialIds(industrialIdArr []int) (items []*IndustrialManagementArticle, err error) {
  719. arrLen := len(industrialIdArr)
  720. if arrLen == 0 {
  721. return
  722. }
  723. o := orm.NewOrm()
  724. sql := `SELECT
  725. mg.industrial_management_id,
  726. MAX( a.product_interior_id ) AS article_id,
  727. a.title,
  728. MAX( a.publish_time ) AS publish_date
  729. FROM
  730. cygx_product_interior_industrial_group_management AS mg
  731. INNER JOIN cygx_product_interior AS a ON mg.product_interior_id = a.product_interior_id
  732. WHERE
  733. 1 = 1
  734. AND a.STATUS = 1
  735. AND a.visible_range = 1
  736. AND mg.industrial_management_id IN(` + utils.GetOrmInReplace(len(industrialIdArr)) + `)
  737. GROUP BY
  738. mg.industrial_management_id`
  739. _, err = o.Raw(sql, industrialIdArr).QueryRows(&items)
  740. return
  741. }
  742. // GetIndustrialManagementArticleNewPublishData 获取产业关联文章的最新发布时间
  743. func GetIndustrialManagementArticleNewPublishData() (items []*IndustrialManagement, err error) {
  744. o := orm.NewOrm()
  745. sql := `SELECT
  746. man.industrial_management_id,
  747. MAX( art.publish_date ) AS update_time
  748. FROM
  749. cygx_industrial_management AS man
  750. INNER JOIN cygx_report_mapping AS re ON re.chart_permission_id = man.chart_permission_id
  751. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.industrial_management_id = man.industrial_management_id
  752. INNER JOIN cygx_article AS art ON art.article_id = man_g.article_id
  753. WHERE
  754. 1 = 1
  755. AND re.report_type = 2
  756. AND art.is_report = 1
  757. AND art.is_class = 1
  758. GROUP BY
  759. man.industry_name
  760. ORDER BY
  761. update_time DESC`
  762. _, err = o.Raw(sql).QueryRows(&items)
  763. return
  764. }
  765. // UpdateIndustrialManagementArticleNewPublishData 批量修改获取产业关联文章的最新发布时间
  766. func UpdateIndustrialManagementArticleNewPublishData(items map[int]string) (err error) {
  767. o := orm.NewOrm()
  768. p, err := o.Raw("UPDATE cygx_industrial_management SET new_art_publish_date = ? WHERE industrial_management_id = ?").Prepare()
  769. if err != nil {
  770. return
  771. }
  772. defer func() {
  773. _ = p.Close() // 别忘记关闭 statement
  774. }()
  775. for k, v := range items {
  776. _, err = p.Exec(v, k)
  777. if err != nil {
  778. return
  779. }
  780. }
  781. return
  782. }
  783. // UpdateIndustrialManagementInit 初始化每月产业用户关注数量
  784. func UpdateIndustrialManagementInit() (err error) {
  785. o := orm.NewOrm()
  786. sql := `UPDATE cygx_industrial_management SET one_month_follow_num = 0 `
  787. _, err = o.Raw(sql).Exec()
  788. return
  789. }
  790. // UpdateIndustrialManagementOneMonthFollowNumMulti 批量修改每月产业用户关注数量
  791. func UpdateIndustrialManagementOneMonthFollowNumMulti(items []*CygxIndustryFllowNumResp) (err error) {
  792. o := orm.NewOrm()
  793. p, err := o.Raw(` UPDATE cygx_industrial_management SET one_month_follow_num = ? WHERE industrial_management_id = ? `).Prepare()
  794. if err != nil {
  795. return
  796. }
  797. defer func() {
  798. _ = p.Close() // 别忘记关闭 statement
  799. }()
  800. for _, v := range items {
  801. _, err = p.Exec(
  802. v.Total,
  803. v.IndustrialManagementId)
  804. if err != nil {
  805. return
  806. }
  807. }
  808. return
  809. }