industrial_management.go 32 KB

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