industrial_management.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_clpt/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. }
  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.create_time > '` + startTime + `' ) AS follow_num, `
  109. }
  110. sql := `SELECT
  111. man.*,
  112. re.chart_permission_name,
  113. MAX( art.publish_date ) AS update_time ,
  114. MIN(art.publish_date) AS min_report_time,` + conditionBillboard + `
  115. (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
  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. WHERE 1= 1
  122. AND re.report_type = 2
  123. AND art.is_report = 1
  124. AND art.is_class = 1 ` + condition + `
  125. GROUP BY
  126. man.industry_name
  127. ORDER BY ` + orderSrt + ` LIMIT ?,?`
  128. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  129. return
  130. }
  131. //标的列表
  132. func GetIndustrialSubjectAll(IndustrialManagementId int) (items []*IndustrialSubject, err error) {
  133. o := orm.NewOrm()
  134. sql := `SELECT * FROM cygx_industrial_subject WHERE industrial_management_id = ? `
  135. _, err = o.Raw(sql, IndustrialManagementId).QueryRows(&items)
  136. return
  137. }
  138. //获取该产业下最新的文章详情
  139. func GetIndustrialNewArticleDetail(industrialManagementId int) (item *ArticleDetail, err error) {
  140. o := orm.NewOrm()
  141. sql := `SELECT
  142. *
  143. FROM
  144. cygx_article
  145. WHERE
  146. article_id IN ( SELECT article_id FROM cygx_industrial_article_group_management WHERE industrial_management_id = ? )
  147. ORDER BY
  148. is_report DESC,
  149. publish_date DESC
  150. LIMIT 0,1`
  151. err = o.Raw(sql, industrialManagementId).QueryRow(&item)
  152. return
  153. }
  154. //获取该产业下最新的文章详情
  155. func GetNewArticleDetailByIndustrialIds(industrialIdArr []int) (items []*IndustrialManagementArticle, err error) {
  156. arrLen := len(industrialIdArr)
  157. if arrLen == 0 {
  158. return
  159. }
  160. o := orm.NewOrm()
  161. sql := `SELECT
  162. mg.industrial_management_id,
  163. MAX( a.article_id ) AS article_id,
  164. a.title,
  165. MAX( a.publish_date ) AS publish_date
  166. FROM
  167. cygx_industrial_article_group_management AS mg
  168. INNER JOIN cygx_article AS a ON mg.article_id = a.article_id
  169. WHERE
  170. 1 = 1
  171. AND a.article_id < ?
  172. AND a.is_report = 1
  173. AND a.is_class = 1
  174. AND mg.industrial_management_id IN(` + utils.GetOrmInReplace(len(industrialIdArr)) + `)
  175. GROUP BY
  176. mg.industrial_management_id `
  177. _, err = o.Raw(sql, utils.SummaryArticleId, industrialIdArr).QueryRows(&items)
  178. return
  179. }
  180. //获取产业数量
  181. func GetIndustrialManagementCount(IndustrialManagementId int) (count int, err error) {
  182. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_industrial_management WHERE industrial_management_id=? `
  183. o := orm.NewOrm()
  184. err = o.Raw(sqlCount, IndustrialManagementId).QueryRow(&count)
  185. return
  186. }
  187. //获取关注数量
  188. func GetCountCygxIndustryFllow(industrialManagementId int, mobile, condition string) (count int, err error) {
  189. sql := `SELECT COUNT(1) AS count FROM cygx_industry_fllow WHERE mobile=? AND industrial_management_id=? ` + condition
  190. err = orm.NewOrm().Raw(sql, mobile, industrialManagementId).QueryRow(&count)
  191. return
  192. }
  193. func GetIndustrialManagementDetail(industrialManagementId int) (items *IndustrialManagementRep, err error) {
  194. o := orm.NewOrm()
  195. sql := `SELECT * FROM cygx_industrial_management WHERE industrial_management_id = ?`
  196. err = o.Raw(sql, industrialManagementId).QueryRow(&items)
  197. return
  198. }
  199. //获取所有的产业
  200. func GetindustrialManagement() (items []*IndustrialManagementRep, err error) {
  201. o := orm.NewOrm()
  202. sql := `SELECT
  203. i.*
  204. FROM
  205. cygx_industrial_management AS i
  206. INNER JOIN cygx_industrial_article_group_management AS m ON m.industrial_management_id = i.industrial_management_id
  207. GROUP BY
  208. i.industrial_management_id `
  209. _, err = o.Raw(sql).QueryRows(&items)
  210. return
  211. }
  212. //标的列表
  213. func GetIndustrialSubjectAllByIndustrialId(industrialIdArr []int) (items []*IndustrialSubject, err error) {
  214. o := orm.NewOrm()
  215. sql := `SELECT * FROM cygx_industrial_subject WHERE industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialIdArr)) + `) `
  216. _, err = o.Raw(sql, industrialIdArr).QueryRows(&items)
  217. return
  218. }
  219. //获取标的列表
  220. func GetIndustrialListByarticleId(pars []interface{}, condition string) (items []*IndustrialManagementIdInt, err error) {
  221. o := orm.NewOrm()
  222. sql := `SELECT
  223. mg.article_id,
  224. m.industry_name,
  225. m.chart_permission_id,
  226. mg.industrial_management_id
  227. FROM
  228. cygx_industrial_management AS m
  229. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = m.industrial_management_id
  230. WHERE
  231. 1 = 1 ` + condition + ` GROUP BY mg.article_id, mg.industrial_management_id `
  232. _, err = o.Raw(sql, pars).QueryRows(&items)
  233. return
  234. }
  235. // GetIndustryArtCountByCondition 获取产业文章关联的文章数
  236. func GetIndustryArtCountByCondition(condition string, pars []interface{}) (list []*IndustryArtCount, err error) {
  237. sql := `SELECT
  238. COUNT(1) AS art_num,
  239. agm.industrial_management_id
  240. FROM
  241. cygx_industrial_article_group_management AS agm
  242. JOIN cygx_industrial_management AS man ON man.industrial_management_id = agm.industrial_management_id
  243. WHERE
  244. 1 = 1 `
  245. if condition != "" {
  246. sql += condition
  247. }
  248. sql += ` GROUP BY agm.industrial_management_id`
  249. _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
  250. return
  251. }
  252. type IndustrialArticleGroupManagementResp struct {
  253. IndustrialManagementId int `description:"产业Id"`
  254. ArticleId int `description:"文章ID"`
  255. }
  256. // GetIndustrialArticleGroupManagementByIndustrialManagementId 获取产业文章关联的文章ID
  257. func GetIndustrialArticleGroupManagementByIndustrialManagementId(industrialManagementId int) (list []*IndustrialArticleGroupManagementResp, err error) {
  258. sql := `SELECT
  259. *
  260. FROM
  261. cygx_industrial_article_group_management
  262. WHERE
  263. industrial_management_id = ? `
  264. _, err = orm.NewOrm().Raw(sql, industrialManagementId).QueryRows(&list)
  265. return
  266. }
  267. // GetTopOneMonthArtReadNumIndustry 获取近一个月报告阅读数量最多的产业信息
  268. func GetTopOneMonthArtReadNumIndustry(condition string, pars []interface{}) (item *IndustrialManagement, err error) {
  269. sql := `SELECT * FROM cygx_industrial_management WHERE 1 = 1 `
  270. if condition != `` {
  271. sql += condition
  272. }
  273. sql += ` ORDER BY article_read_num DESC LIMIT 1`
  274. err = orm.NewOrm().Raw(sql, pars).QueryRow(&item)
  275. return
  276. }