industrial_management.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_clpt/utils"
  5. "time"
  6. )
  7. type IndustrialManagementRep struct {
  8. IndustryName string `description:"产业名称"`
  9. IndustrialManagementId int `description:"产业id"`
  10. ChartPermissionId int `description:"权限id"`
  11. RecommendedIndex int `description:"推荐指数"`
  12. LayoutTime string `description:"布局时间"`
  13. ArticleReadNum int `description:"文章阅读数量"`
  14. IsResearch bool `description:"是否属于研选"`
  15. IsJump bool `description:"是否跳转"`
  16. IndustryNewLabel bool `description:"是否产业新标签"`
  17. }
  18. type IndustrialManagementCount struct {
  19. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  20. }
  21. type IndustrialManagementIdInt struct {
  22. IndustrialManagementId int `description:"产业Id"`
  23. IndustryName string `description:"产业名称"`
  24. SubjectName string `description:"标的名称"`
  25. ArticleId int `description:"文章ID"`
  26. IsResearch bool `description:"是否属于研选"`
  27. ChartPermissionId int `description:"权限id"`
  28. }
  29. type IndustrialManagementIdInts struct {
  30. IndustrialManagementId int `description:"产业Id"`
  31. IndustryName string `description:"产业名称"`
  32. SubjectNames string `description:"标的名称"`
  33. ArticleId int `description:"文章ID"`
  34. IndustrialAndSubjectIds string `description:"关联标的以及产业ID"`
  35. }
  36. type IndustrialManagementIdName struct {
  37. DepartmentId int `description:"作者ID"`
  38. ArticleId int `description:"文章id"`
  39. IndustryName string `description:"产业名称"`
  40. SubjectName string `description:"标的名称"`
  41. IsReport string `description:"1观点,0纪要"`
  42. }
  43. type IndustrialSubject struct {
  44. IndustrialSubjectId int `orm:"column(industrial_subject_id);pk" description:"标的id"`
  45. IndustrialManagementId int `description:"产业id"`
  46. SubjectName string `description:"标的名称"`
  47. IndustryName string `description:"产业名称"`
  48. }
  49. type IndustrialSubjectResp struct {
  50. IndustrialSubjectId int `orm:"column(industrial_subject_id);pk" description:"标的id"`
  51. SubjectName string `description:"标的名称"`
  52. }
  53. type IndustrialManagementArticle struct {
  54. IndustrialManagementId int `description:"产业Id"`
  55. IndustryName string `description:"产业名称"`
  56. ArticleId int `description:"文章ID"`
  57. PublishDate string `description:"发布时间"`
  58. }
  59. type IndustrialManagementResp struct {
  60. IndustrialManagementId int `description:"产业Id"`
  61. IndustryName string `description:"产业名称"`
  62. ChartPermissionId int `description:"权限id"`
  63. }
  64. // IndustryArtCount 产业文章数
  65. type IndustryArtCount struct {
  66. ArtNum int `json:"art_num" description:"文章数"`
  67. IndustrialManagementId int `json:"industrial_management_id" description:"产业ID"`
  68. }
  69. type IndustryVideoDetailResp struct {
  70. IndustryVideo *MicroVideoSimpleInfo
  71. AuthInfo *UserPermissionAuthInfo
  72. }
  73. // 产业列表
  74. func GetIndustrialManagementAllCount(condition string) (count int, err error) {
  75. o := orm.NewOrm()
  76. sql := `SELECT
  77. COUNT(*) as count
  78. FROM
  79. (SELECT
  80. COUNT(*)
  81. FROM
  82. cygx_industrial_management AS man
  83. INNER JOIN cygx_report_mapping AS re ON re.chart_permission_id = man.chart_permission_id
  84. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.industrial_management_id = man.industrial_management_id
  85. INNER JOIN cygx_article AS art ON art.article_id = man_g.article_id
  86. WHERE
  87. 1 = 1
  88. AND re.report_type = 2
  89. AND art.is_report = 1
  90. AND art.is_class = 1 ` + condition + ` GROUP BY man.industrial_management_id) AS num `
  91. err = o.Raw(sql).QueryRow(&count)
  92. return
  93. }
  94. // 获取产业下阅读数量第三的产业详情
  95. func GetIndustrialManagementHot3(chartPermissionId int) (item *IndustrialManagementRep, err error) {
  96. o := orm.NewOrm()
  97. sql := `SELECT * FROM cygx_industrial_management WHERE chart_permission_id = ? ORDER BY article_read_num DESC LIMIT 2,1`
  98. err = o.Raw(sql, chartPermissionId).QueryRow(&item)
  99. return
  100. }
  101. // 产业列表
  102. func GetIndustrialManagementAll(uid int, condition, orderSrt string, startSize, pageSize int, isBillboard bool) (items []*IndustrialManagement, err error) {
  103. o := orm.NewOrm()
  104. var conditionBillboard string
  105. if isBillboard {
  106. var startTime string
  107. startTime = time.Now().AddDate(0, 0, -30).Format(utils.FormatDate)
  108. conditionBillboard = ` ( SELECT COUNT( 1 ) FROM cygx_industry_fllow AS f WHERE f.industrial_management_id = man.industrial_management_id AND f.follow_type = 1 AND f.create_time > '` + startTime + `' ) AS follow_num, `
  109. }
  110. sql := `SELECT
  111. man.*,
  112. re.chart_permission_name,
  113. man.new_art_publish_date AS update_time ,
  114. MIN(art.publish_date) AS min_report_time,` + conditionBillboard + `
  115. IFNULL( f.follow_type_order, 0 ) AS follow_type_order
  116. FROM
  117. cygx_industrial_management AS man
  118. INNER JOIN cygx_report_mapping AS re ON re.chart_permission_id = man.chart_permission_id
  119. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.industrial_management_id = man.industrial_management_id
  120. INNER JOIN cygx_article AS art ON art.article_id = man_g.article_id
  121. LEFT JOIN cygx_industry_fllow AS f ON f.industrial_management_id = man.industrial_management_id AND f.user_id = ?
  122. WHERE 1= 1
  123. AND re.report_type = 2
  124. AND art.is_report = 1
  125. AND art.is_class = 1 ` + condition + `
  126. GROUP BY
  127. man.industry_name
  128. ORDER BY follow_type_order DESC , ` + orderSrt + ` LIMIT ?,?`
  129. _, err = o.Raw(sql, uid, startSize, pageSize).QueryRows(&items)
  130. return
  131. }
  132. // 标的列表
  133. func GetIndustrialSubjectAll(IndustrialManagementId int) (items []*IndustrialSubject, err error) {
  134. o := orm.NewOrm()
  135. sql := `SELECT * FROM cygx_industrial_subject WHERE industrial_management_id = ? `
  136. _, err = o.Raw(sql, IndustrialManagementId).QueryRows(&items)
  137. return
  138. }
  139. // 获取该产业下最新的文章详情
  140. func GetIndustrialNewArticleDetail(industrialManagementId int) (item *ArticleDetail, err error) {
  141. o := orm.NewOrm()
  142. sql := `SELECT
  143. *
  144. FROM
  145. cygx_article
  146. WHERE
  147. article_id IN ( SELECT article_id FROM cygx_industrial_article_group_management WHERE industrial_management_id = ? )
  148. ORDER BY
  149. is_report DESC,
  150. publish_date DESC
  151. LIMIT 0,1`
  152. err = o.Raw(sql, industrialManagementId).QueryRow(&item)
  153. return
  154. }
  155. // 获取该产业下最新的文章详情
  156. func GetNewArticleDetailByIndustrialIds(pars []interface{}, condition string) (items []*IndustrialManagementArticle, err error) {
  157. //arrLen := len(industrialIdArr)
  158. //if arrLen == 0 {
  159. // return
  160. //}
  161. o := orm.NewOrm()
  162. sql := `SELECT
  163. mg.industrial_management_id,
  164. MAX( a.article_id ) AS article_id,
  165. a.title,
  166. MAX( a.publish_date ) AS publish_date
  167. FROM
  168. cygx_industrial_article_group_management AS mg
  169. INNER JOIN cygx_article AS a ON mg.article_id = a.article_id
  170. WHERE
  171. 1 = 1 ` + condition + `
  172. GROUP BY
  173. mg.industrial_management_id `
  174. _, err = o.Raw(sql, pars).QueryRows(&items)
  175. return
  176. }
  177. // 获取产业数量
  178. func GetIndustrialManagementCount(IndustrialManagementId int) (count int, err error) {
  179. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_industrial_management WHERE industrial_management_id=? `
  180. o := orm.NewOrm()
  181. err = o.Raw(sqlCount, IndustrialManagementId).QueryRow(&count)
  182. return
  183. }
  184. // 获取关注数量
  185. func GetCountCygxIndustryFllow(industrialManagementId, userId int, condition string) (count int, err error) {
  186. sql := `SELECT COUNT(1) AS count FROM cygx_industry_fllow WHERE user_id=? AND industrial_management_id=? ` + condition
  187. err = orm.NewOrm().Raw(sql, userId, industrialManagementId).QueryRow(&count)
  188. return
  189. }
  190. func GetIndustrialManagementDetail(industrialManagementId int) (items *IndustrialManagementRep, err error) {
  191. o := orm.NewOrm()
  192. sql := `SELECT * FROM cygx_industrial_management WHERE industrial_management_id = ?`
  193. err = o.Raw(sql, industrialManagementId).QueryRow(&items)
  194. return
  195. }
  196. // 获取所有的产业
  197. func GetindustrialManagement() (items []*IndustrialManagementRep, err error) {
  198. o := orm.NewOrm()
  199. sql := `SELECT
  200. i.*
  201. FROM
  202. cygx_industrial_management AS i
  203. INNER JOIN cygx_industrial_article_group_management AS m ON m.industrial_management_id = i.industrial_management_id
  204. GROUP BY
  205. i.industrial_management_id `
  206. _, err = o.Raw(sql).QueryRows(&items)
  207. return
  208. }
  209. // 标的列表
  210. func GetIndustrialSubjectAllByIndustrialId(pars []interface{}, condition string) (items []*IndustrialSubject, err error) {
  211. o := orm.NewOrm()
  212. sql := `SELECT
  213. m.subject_name,
  214. m.industrial_management_id,
  215. m.industrial_subject_id
  216. FROM
  217. cygx_article AS a
  218. INNER JOIN cygx_industrial_article_group_subject AS mg ON mg.article_id = a.article_id
  219. INNER JOIN cygx_industrial_subject AS m ON m.industrial_subject_id = mg.industrial_subject_id
  220. WHERE
  221. 1 = 1
  222. AND a.publish_status = 1 ` + condition + `
  223. GROUP BY
  224. m.industrial_subject_id
  225. ORDER BY
  226. a.publish_date DESC `
  227. _, err = o.Raw(sql, pars).QueryRows(&items)
  228. return
  229. }
  230. // 获取标的列表
  231. func GetIndustrialListByarticleId(pars []interface{}, condition string) (items []*IndustrialManagementIdInt, err error) {
  232. o := orm.NewOrm()
  233. sql := `SELECT
  234. mg.article_id,
  235. m.industry_name,
  236. m.chart_permission_id,
  237. mg.industrial_management_id
  238. FROM
  239. cygx_industrial_management AS m
  240. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  241. WHERE
  242. 1 = 1 ` + condition + ` GROUP BY mg.article_id, mg.industrial_management_id `
  243. _, err = o.Raw(sql, pars).QueryRows(&items)
  244. return
  245. }
  246. // GetIndustryArtCountByCondition 获取产业文章关联的文章数
  247. func GetIndustryArtCountByCondition(condition string, pars []interface{}) (list []*IndustryArtCount, err error) {
  248. sql := `SELECT
  249. COUNT(1) AS art_num,
  250. agm.industrial_management_id
  251. FROM
  252. cygx_industrial_article_group_management AS agm
  253. JOIN cygx_industrial_management AS man ON man.industrial_management_id = agm.industrial_management_id
  254. WHERE
  255. 1 = 1 `
  256. if condition != "" {
  257. sql += condition
  258. }
  259. sql += ` GROUP BY agm.industrial_management_id`
  260. _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
  261. return
  262. }
  263. type IndustrialArticleGroupManagementResp struct {
  264. IndustrialManagementId int `description:"产业Id"`
  265. ArticleId int `description:"文章ID"`
  266. }
  267. // GetIndustrialArticleGroupManagementByIndustrialManagementId 获取产业文章关联的文章ID
  268. func GetIndustrialArticleGroupManagementByIndustrialManagementId(industrialManagementId int) (list []*IndustrialArticleGroupManagementResp, err error) {
  269. sql := `SELECT
  270. *
  271. FROM
  272. cygx_industrial_article_group_management
  273. WHERE
  274. industrial_management_id = ? `
  275. _, err = orm.NewOrm().Raw(sql, industrialManagementId).QueryRows(&list)
  276. return
  277. }
  278. // GetTopOneMonthArtReadNumIndustry 获取近一个月报告阅读数量最多的产业信息
  279. func GetTopOneMonthArtReadNumIndustry(condition string, pars []interface{}) (item *IndustrialManagement, err error) {
  280. sql := `SELECT * FROM cygx_industrial_management WHERE 1 = 1 `
  281. if condition != `` {
  282. sql += condition
  283. }
  284. sql += ` ORDER BY article_read_num DESC LIMIT 1`
  285. err = orm.NewOrm().Raw(sql, pars).QueryRow(&item)
  286. return
  287. }
  288. // GetTopOneMonthArtReadNumIndustry 获取近一个月报告阅读数量最多的产业信息 根据行业分组
  289. func GetTopOneMonthArtReadNumIndustryAll(condition string, pars []interface{}) (items []*IndustrialManagement, err error) {
  290. sql := `SELECT * FROM cygx_industrial_management WHERE 1 = 1 `
  291. if condition != `` {
  292. sql += condition
  293. }
  294. sql += ` ORDER BY article_read_num DESC `
  295. _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&items)
  296. return
  297. }
  298. //// GetTopIndustryFollowData 获取关注度最高的产业关注数据
  299. //func GetTopIndustryFollowData(startSize, pageSize int, condition string, pars []interface{}) (list []*IndustrialManagement, err error) {
  300. // sql := `SELECT
  301. // COUNT(1) AS one_month_follow_num,
  302. // man.*
  303. // FROM
  304. // cygx_industry_fllow AS idf
  305. // JOIN cygx_industrial_management AS man ON idf.industrial_management_id = man.industrial_management_id
  306. // WHERE 1 = 1 `
  307. // if condition != "" {
  308. // sql += condition
  309. // }
  310. // sql += ` GROUP BY
  311. // idf.industrial_management_id
  312. // ORDER BY
  313. // one_month_follow_num DESC
  314. // LIMIT ?,?`
  315. // _, err = orm.NewOrm().Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  316. // return
  317. //}
  318. // GetTopIndustryFollowData 获取关注度最高的产业关注数据
  319. func GetTopIndustryFollowData(uid, startSize, pageSize int, condition string, pars []interface{}) (list []*IndustrialManagement, err error) {
  320. sql := `SELECT
  321. man.*,
  322. IFNULL( f.follow_type_order, 0 ) AS follow_type_order
  323. FROM cygx_industrial_management AS man
  324. LEFT JOIN cygx_industry_fllow AS f ON f.industrial_management_id = man.industrial_management_id AND f.user_id = ?
  325. WHERE 1 = 1 `
  326. if condition != "" {
  327. sql += condition
  328. }
  329. sql += ` GROUP BY
  330. man.industrial_management_id
  331. ORDER BY follow_type_order DESC ,
  332. man.one_month_follow_num DESC , man.industrial_management_id DESC
  333. LIMIT ?,?`
  334. _, err = orm.NewOrm().Raw(sql, uid, pars, startSize, pageSize).QueryRows(&list)
  335. return
  336. }
  337. // GetActiveArticleIndustryIds 获取有已归类行业报告的行业IDs
  338. func GetActiveArticleIndustryIds() (ids []int, err error) {
  339. sql := `SELECT
  340. man.industrial_management_id
  341. FROM
  342. cygx_industrial_management AS man
  343. JOIN cygx_report_mapping AS re ON re.chart_permission_id = man.chart_permission_id
  344. JOIN cygx_industrial_article_group_management AS man_g ON man_g.industrial_management_id = man.industrial_management_id
  345. JOIN cygx_article AS art ON art.article_id = man_g.article_id
  346. WHERE
  347. 1 = 1 AND re.report_type = 2 AND art.is_report = 1 AND art.is_class = 1 AND art.publish_status = 1
  348. GROUP BY
  349. man.industrial_management_id`
  350. _, err = orm.NewOrm().Raw(sql).QueryRows(&ids)
  351. return
  352. }
  353. // GetIndustryByName 通过名称获取产业
  354. func GetIndustryByName(industryName string) (item *IndustrialManagement, err error) {
  355. sql := `SELECT * FROM cygx_industrial_management WHERE industry_name = ? LIMIT 1`
  356. err = orm.NewOrm().Raw(sql, industryName).QueryRow(&item)
  357. return
  358. }
  359. // GetSourceIndustryByName 通过名称获取资源包产业
  360. func GetSourceIndustryByName(industryName string) (item *IndustrialManagement, err error) {
  361. sql := `SELECT
  362. m.industry_name,
  363. m.industrial_management_id,
  364. m.chart_permission_id
  365. FROM
  366. cygx_industrial_management AS m
  367. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  368. INNER JOIN cygx_article AS a ON a.article_id = mg.article_id AND a.article_type != 'lyjh'
  369. WHERE
  370. 1 = 1 AND m.industry_name = ? AND a.publish_status = 1 AND a.article_id < 1000000
  371. GROUP BY
  372. m.industrial_management_id`
  373. err = orm.NewOrm().Raw(sql, industryName).QueryRow(&item)
  374. return
  375. }
  376. // 近期更新主题列表
  377. func GetIndustrialManagementNewList(condition string) (items []*IndustrialManagementNewResp, err error) {
  378. o := orm.NewOrm()
  379. sql := `SELECT
  380. m.industrial_management_id,
  381. m.industry_name,
  382. m.article_read_num,
  383. MAX( a.publish_date ) AS publish_date
  384. FROM
  385. cygx_article AS a
  386. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  387. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  388. WHERE
  389. 1 = 1
  390. AND a.article_type_id > 0
  391. AND publish_status = 1 ` + condition + `
  392. GROUP BY
  393. m.industrial_management_id
  394. ORDER BY
  395. publish_date DESC LIMIT 12`
  396. _, err = o.Raw(sql).QueryRows(&items)
  397. return
  398. }
  399. // 获取该产业下最新的产品内测详情
  400. func GetNewProductInteriorByIndustrialIds(industrialIdArr []int) (items []*IndustrialManagementArticle, err error) {
  401. arrLen := len(industrialIdArr)
  402. if arrLen == 0 {
  403. return
  404. }
  405. o := orm.NewOrm()
  406. sql := `SELECT
  407. mg.industrial_management_id,
  408. MAX( a.product_interior_id ) AS article_id,
  409. a.title,
  410. MAX( a.publish_time ) AS publish_date
  411. FROM
  412. cygx_product_interior_industrial_group_management AS mg
  413. INNER JOIN cygx_product_interior AS a ON mg.product_interior_id = a.product_interior_id
  414. WHERE
  415. 1 = 1
  416. AND a.STATUS = 1
  417. AND a.visible_range = 1
  418. AND mg.industrial_management_id IN(` + utils.GetOrmInReplace(len(industrialIdArr)) + `)
  419. GROUP BY
  420. mg.industrial_management_id`
  421. _, err = o.Raw(sql, industrialIdArr).QueryRows(&items)
  422. return
  423. }