industrial_management.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_web_mfyx/utils"
  5. "strconv"
  6. "time"
  7. )
  8. type IndustrialManagementRep struct {
  9. IndustryName string `description:"产业名称"`
  10. IndustrialManagementId int `description:"产业id"`
  11. ChartPermissionId int `description:"权限id"`
  12. RecommendedIndex int `description:"推荐指数"`
  13. LayoutTime string `description:"布局时间"`
  14. ArticleReadNum int `description:"文章阅读数量"`
  15. IsResearch bool `description:"是否属于研选"`
  16. IsJump bool `description:"是否跳转"`
  17. IndustryNewLabel bool `description:"是否产业新标签"`
  18. }
  19. type IndustrialManagementCount struct {
  20. IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
  21. }
  22. type IndustrialManagementIdInt struct {
  23. IndustrialManagementId int `description:"产业Id"`
  24. IndustryName string `description:"产业名称"`
  25. SubjectName string `description:"标的名称"`
  26. ArticleId int `description:"文章ID"`
  27. IsResearch bool `description:"是否属于研选"`
  28. ChartPermissionId int `description:"权限id"`
  29. }
  30. type IndustrialManagementIdInts struct {
  31. IndustrialManagementId int `description:"产业Id"`
  32. IndustryName string `description:"产业名称"`
  33. SubjectNames string `description:"标的名称"`
  34. ArticleId int `description:"文章ID"`
  35. IndustrialAndSubjectIds string `description:"关联标的以及产业ID"`
  36. }
  37. type IndustrialManagementIdName struct {
  38. DepartmentId int `description:"作者ID"`
  39. ArticleId int `description:"文章id"`
  40. IndustryName string `description:"产业名称"`
  41. SubjectName string `description:"标的名称"`
  42. IsReport string `description:"1观点,0纪要"`
  43. }
  44. type IndustrialSubject struct {
  45. IndustrialSubjectId int `orm:"column(industrial_subject_id);pk" description:"标的id"`
  46. IndustrialManagementId int `description:"产业id"`
  47. SubjectName string `description:"标的名称"`
  48. IndustryName string `description:"产业名称"`
  49. }
  50. type IndustrialSubjectResp struct {
  51. IndustrialSubjectId int `orm:"column(industrial_subject_id);pk" description:"标的id"`
  52. SubjectName string `description:"标的名称"`
  53. }
  54. type IndustrialManagementArticle struct {
  55. IndustrialManagementId int `description:"产业Id"`
  56. IndustryName string `description:"产业名称"`
  57. ArticleId int `description:"文章ID"`
  58. PublishDate string `description:"发布时间"`
  59. }
  60. type IndustrialManagementResp struct {
  61. IndustrialManagementId int `description:"产业Id"`
  62. IndustryName string `description:"产业名称"`
  63. ChartPermissionId int `description:"权限id"`
  64. }
  65. // IndustryArtCount 产业文章数
  66. type IndustryArtCount struct {
  67. ArtNum int `json:"art_num" description:"文章数"`
  68. IndustrialManagementId int `json:"industrial_management_id" description:"产业ID"`
  69. }
  70. type IndustryVideoDetailResp struct {
  71. IndustryVideo *MicroVideoSimpleInfo
  72. AuthInfo *UserPermissionAuthInfo
  73. }
  74. // 产业列表
  75. func GetIndustrialManagementAllCount(condition string) (count int, err error) {
  76. o := orm.NewOrm()
  77. sql := `SELECT
  78. COUNT(*) as count
  79. FROM
  80. (SELECT
  81. COUNT(*)
  82. FROM
  83. cygx_industrial_management AS man
  84. INNER JOIN cygx_report_mapping AS re ON re.chart_permission_id = man.chart_permission_id
  85. INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.industrial_management_id = man.industrial_management_id
  86. INNER JOIN cygx_article AS art ON art.article_id = man_g.article_id
  87. WHERE
  88. 1 = 1
  89. AND re.report_type = 2
  90. AND art.is_report = 1
  91. AND art.is_class = 1 ` + condition + ` GROUP BY man.industrial_management_id) AS num `
  92. err = o.Raw(sql).QueryRow(&count)
  93. return
  94. }
  95. // 获取产业下阅读数量第三的产业详情
  96. func GetIndustrialManagementHot3(chartPermissionId int) (item *IndustrialManagementRep, err error) {
  97. o := orm.NewOrm()
  98. sql := `SELECT * FROM cygx_industrial_management WHERE chart_permission_id = ? ORDER BY article_read_num DESC LIMIT 2,1`
  99. err = o.Raw(sql, chartPermissionId).QueryRow(&item)
  100. return
  101. }
  102. // 产业列表
  103. func GetIndustrialManagementAll(uid int, condition, orderSrt string, startSize, pageSize int, isBillboard bool) (items []*IndustrialManagement, err error) {
  104. o := orm.NewOrm()
  105. var conditionBillboard string
  106. if isBillboard {
  107. var startTime string
  108. startTime = time.Now().AddDate(0, 0, -30).Format(utils.FormatDate)
  109. conditionBillboard = ` ( SELECT COUNT( 1 ) FROM cygx_industry_fllow AS f WHERE f.industrial_management_id = man.industrial_management_id AND f.create_time > '` + startTime + `' ) AS follow_num, `
  110. }
  111. sql := `SELECT
  112. man.*,
  113. re.chart_permission_name,
  114. man.new_art_publish_date AS update_time ,
  115. MIN(art.publish_date) AS min_report_time,` + conditionBillboard + `
  116. (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
  117. FROM
  118. cygx_industrial_management AS man
  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 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 ` + orderSrt + ` LIMIT ?,?`
  129. _, err = o.Raw(sql, 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(startSize, pageSize int, condition string, pars []interface{}) (list []*IndustrialManagement, err error) {
  320. sql := `SELECT
  321. man.*
  322. FROM cygx_industrial_management AS man
  323. WHERE 1 = 1 `
  324. if condition != "" {
  325. sql += condition
  326. }
  327. sql += ` GROUP BY
  328. man.industrial_management_id
  329. ORDER BY
  330. man.one_month_follow_num DESC , man.industrial_management_id DESC
  331. LIMIT ?,?`
  332. _, err = orm.NewOrm().Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  333. return
  334. }
  335. // GetActiveArticleIndustryIds 获取有已归类行业报告的行业IDs
  336. func GetActiveArticleIndustryIds() (ids []int, err error) {
  337. sql := `SELECT
  338. man.industrial_management_id
  339. FROM
  340. cygx_industrial_management AS man
  341. JOIN cygx_report_mapping AS re ON re.chart_permission_id = man.chart_permission_id
  342. JOIN cygx_industrial_article_group_management AS man_g ON man_g.industrial_management_id = man.industrial_management_id
  343. JOIN cygx_article AS art ON art.article_id = man_g.article_id
  344. WHERE
  345. 1 = 1 AND re.report_type = 2 AND art.is_report = 1 AND art.is_class = 1 AND art.publish_status = 1
  346. GROUP BY
  347. man.industrial_management_id`
  348. _, err = orm.NewOrm().Raw(sql).QueryRows(&ids)
  349. return
  350. }
  351. // GetIndustryByName 通过名称获取产业
  352. func GetIndustryByName(industryName string) (item *IndustrialManagement, err error) {
  353. sql := `SELECT * FROM cygx_industrial_management WHERE industry_name = ? LIMIT 1`
  354. err = orm.NewOrm().Raw(sql, industryName).QueryRow(&item)
  355. return
  356. }
  357. // GetSourceIndustryByName 通过名称获取资源包产业
  358. func GetSourceIndustryByName(industryName string) (item *IndustrialManagement, err error) {
  359. sql := `SELECT
  360. m.industry_name,
  361. m.industrial_management_id,
  362. m.chart_permission_id
  363. FROM
  364. cygx_industrial_management AS m
  365. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  366. INNER JOIN cygx_article AS a ON a.article_id = mg.article_id AND a.article_type != 'lyjh'
  367. WHERE
  368. 1 = 1 AND m.industry_name = ? AND a.publish_status = 1 AND a.article_id < 1000000
  369. GROUP BY
  370. m.industrial_management_id`
  371. err = orm.NewOrm().Raw(sql, industryName).QueryRow(&item)
  372. return
  373. }
  374. // 近期更新主题列表
  375. func GetIndustrialManagementNewList(condition string) (items []*IndustrialManagementNewResp, err error) {
  376. o := orm.NewOrm()
  377. sql := `SELECT
  378. m.industrial_management_id,
  379. m.industry_name,
  380. m.article_read_num,
  381. MAX( a.publish_date ) AS publish_date
  382. FROM
  383. cygx_article AS a
  384. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  385. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  386. WHERE
  387. 1 = 1
  388. AND a.article_type_id > 0
  389. AND publish_status = 1 ` + condition + `
  390. GROUP BY
  391. m.industrial_management_id
  392. ORDER BY
  393. publish_date DESC LIMIT 12`
  394. _, err = o.Raw(sql).QueryRows(&items)
  395. return
  396. }
  397. // 获取该产业下最新的产品内测详情
  398. func GetNewProductInteriorByIndustrialIds(industrialIdArr []int) (items []*IndustrialManagementArticle, err error) {
  399. arrLen := len(industrialIdArr)
  400. if arrLen == 0 {
  401. return
  402. }
  403. o := orm.NewOrm()
  404. sql := `SELECT
  405. mg.industrial_management_id,
  406. MAX( a.product_interior_id ) AS article_id,
  407. a.title,
  408. MAX( a.publish_time ) AS publish_date
  409. FROM
  410. cygx_product_interior_industrial_group_management AS mg
  411. INNER JOIN cygx_product_interior AS a ON mg.product_interior_id = a.product_interior_id
  412. WHERE
  413. 1 = 1
  414. AND a.STATUS = 1
  415. AND a.visible_range = 1
  416. AND mg.industrial_management_id IN(` + utils.GetOrmInReplace(len(industrialIdArr)) + `)
  417. GROUP BY
  418. mg.industrial_management_id`
  419. _, err = o.Raw(sql, industrialIdArr).QueryRows(&items)
  420. return
  421. }