article_department.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "time"
  6. )
  7. type CygxArticleDepartment struct {
  8. DepartmentId int `orm:"column(department_id);pk;主键ID"`
  9. CreateTime time.Time `description:"创建时间"`
  10. NickName string `description:"昵称"`
  11. Remark string `description:"备注"`
  12. Remarks string `description:"备注辅助字段"`
  13. Content string `description:"初始内容"`
  14. }
  15. type CygxArticleDepartmentRep struct {
  16. DepartmentId int `description:"作者ID"`
  17. CreateTime string `description:"创建时间"`
  18. NickName string `description:"昵称"`
  19. ImgUrl string `description:"头像链接"`
  20. FollowNum int `description:"是否关注 1是 ,0 否"`
  21. IsMyFollow bool `description:"是否关注"`
  22. List []*IndustrialManagementIdName
  23. }
  24. type CygxArticleDepartmentRepPc struct {
  25. DepartmentId int `description:"作者ID"`
  26. CreateTime string `description:"创建时间"`
  27. NickName string `description:"昵称"`
  28. ImgUrl string `description:"头像链接"`
  29. FollowNum int `description:"是否关注 1是 ,0 否"`
  30. IsMyFollow bool `description:"是否关注"`
  31. List []*IndustrialManagementIdNamePc
  32. }
  33. type CygxArticleDepartmentId struct {
  34. DepartmentId int `description:"作者ID"`
  35. }
  36. type CygxArticleDepartmentList struct {
  37. HaveResearch bool `description:"是否有研选权限"`
  38. Paging *paging.PagingItem `description:"分页数据"`
  39. ListnNew []*IndustrialManagementIdInt
  40. List []*CygxArticleDepartmentRep
  41. }
  42. type CygxArticleDepartmentListPc struct {
  43. HaveResearch bool `description:"是否有研选权限"`
  44. Paging *paging.PagingItem `description:"分页数据"`
  45. ListnNew []*IndustrialManagementIdInt
  46. List []*CygxArticleDepartmentRepPc
  47. }
  48. //详情
  49. func GetArticleDepartmentDateil(nickName, remarks string) (item *CygxArticleDepartmentRep, err error) {
  50. o := orm.NewOrm()
  51. sql := `SELECT * FROM cygx_article_department WHERE nick_name = ? AND remarks = ? LIMIT 1 `
  52. err = o.Raw(sql, nickName, remarks).QueryRow(&item)
  53. return
  54. }
  55. func GetArticleDepartmentDateilById(departmentId int) (item *CygxArticleDepartmentRep, err error) {
  56. o := orm.NewOrm()
  57. sql := `SELECT * FROM cygx_article_department WHERE department_id = ? `
  58. err = o.Raw(sql, departmentId).QueryRow(&item)
  59. return
  60. }
  61. //数量
  62. func GetArticleDepartmentCount(condition string) (count int, err error) {
  63. o := orm.NewOrm()
  64. sql := ` SELECT COUNT(*) count
  65. FROM
  66. ( SELECT COUNT(1) FROM cygx_article_department AS d
  67. INNER JOIN cygx_article AS a ON a.department_id = d.department_id
  68. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  69. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id WHERE 1= 1 `
  70. if condition != "" {
  71. sql += condition
  72. }
  73. sql += ` GROUP BY d.department_id ) AS num `
  74. err = o.Raw(sql).QueryRow(&count)
  75. return
  76. }
  77. //列表
  78. func GetCygxArticleDepartmentList(startSize, pageSize int, condition string, uid int) (items []*CygxArticleDepartmentRep, err error) {
  79. o := orm.NewOrm()
  80. sql := `SELECT d.*,
  81. ( SELECT COUNT( 1 ) FROM cygx_article AS a INNER JOIN cygx_article_history_record as h ON h.article_id = a.article_id WHERE a.department_id = d.department_id AND a.publish_status = 1 ) AS art_num,
  82. ( SELECT COUNT( 1 ) FROM cygx_article_department_follow AS f WHERE f.department_id = d.department_id AND f.user_id = ? AND f.type = 1 ) AS follow_num
  83. FROM
  84. cygx_article_department AS d
  85. INNER JOIN cygx_article AS a ON a.department_id = d.department_id
  86. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  87. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id WHERE 1= 1 `
  88. if condition != "" {
  89. sql += condition
  90. }
  91. sql += ` GROUP BY
  92. d.department_id
  93. ORDER BY art_num DESC LIMIT ?,?`
  94. _, err = o.Raw(sql, uid, startSize, pageSize).QueryRows(&items)
  95. return
  96. }
  97. //列表
  98. func GetCygxArticleDepartmentListPc(startSize, pageSize int, condition string, uid int) (items []*CygxArticleDepartmentRepPc, err error) {
  99. o := orm.NewOrm()
  100. sql := `SELECT d.*,
  101. ( SELECT COUNT( 1 ) FROM cygx_article AS a INNER JOIN cygx_article_history_record as h ON h.article_id = a.article_id WHERE a.department_id = d.department_id AND a.publish_status = 1 ) AS art_num,
  102. ( SELECT COUNT( 1 ) FROM cygx_article_department_follow AS f WHERE f.department_id = d.department_id AND f.user_id = ? AND f.type = 1 ) AS follow_num
  103. FROM
  104. cygx_article_department AS d
  105. INNER JOIN cygx_article AS a ON a.department_id = d.department_id
  106. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  107. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id WHERE 1= 1 `
  108. if condition != "" {
  109. sql += condition
  110. }
  111. sql += ` GROUP BY
  112. d.department_id
  113. ORDER BY art_num DESC LIMIT ?,?`
  114. _, err = o.Raw(sql, uid, startSize, pageSize).QueryRows(&items)
  115. return
  116. }
  117. //产业列表
  118. func GetIndustrialSubjectByDepartment(departmentId int) (items []*IndustrialManagementIdInt, err error) {
  119. o := orm.NewOrm()
  120. sql := `SELECT
  121. m.*,
  122. ( SELECT GROUP_CONCAT(DISTINCT s.subject_name ORDER BY s.create_time DESC SEPARATOR '/' ) FROM cygx_industrial_subject AS s WHERE s.industrial_management_id = m.industrial_management_id) AS subject_name,
  123. ( SELECT publish_date FROM cygx_article AS a INNER JOIN cygx_industrial_article_group_management as mg ON mg.article_id = a.article_id ORDER BY publish_date DESC LIMIT 1 ) AS art_time
  124. FROM
  125. cygx_article_department AS d
  126. INNER JOIN cygx_article AS a ON a.department_id = d.department_id
  127. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  128. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  129. WHERE 1= 1
  130. AND d.department_id = ?
  131. AND a.publish_status = 1
  132. GROUP BY a.article_id
  133. ORDER BY art_time DESC
  134. LIMIT 4 `
  135. _, err = o.Raw(sql, departmentId).QueryRows(&items)
  136. return
  137. }
  138. //最新产业列表
  139. func GetIndustrialSubjectByDepartmentNew() (items []*IndustrialManagementIdInts, err error) {
  140. o := orm.NewOrm()
  141. sql := `SELECT
  142. a.article_id,
  143. a.industrial_and_subject_ids,
  144. m.*,
  145. MAX( a.publish_date ) art_time
  146. FROM
  147. cygx_article_department AS d
  148. INNER JOIN cygx_article AS a ON a.department_id = d.department_id
  149. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  150. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  151. LEFT JOIN cygx_industrial_article_group_subject AS sg ON sg.article_id = a.article_id
  152. WHERE
  153. 1 = 1
  154. AND a.publish_status = 1
  155. AND a.industrial_and_subject_ids != ''
  156. GROUP BY
  157. a.industrial_and_subject_ids
  158. ORDER BY
  159. art_time DESC
  160. LIMIT 6 `
  161. _, err = o.Raw(sql).QueryRows(&items)
  162. return
  163. }
  164. //获取作者数量
  165. func GetDepartmentCount(departmentId int) (count int, err error) {
  166. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article_department WHERE department_id=? `
  167. o := orm.NewOrm()
  168. err = o.Raw(sqlCount, departmentId).QueryRow(&count)
  169. return
  170. }
  171. type IndustrialSubjectList struct {
  172. SubjectName string `description:"标的名称"`
  173. }
  174. //最新标的列表
  175. func GetIndustrialSubjectNewList(condition string) (items []*IndustrialSubjectList, err error) {
  176. o := orm.NewOrm()
  177. sql := `SELECT s.*
  178. FROM
  179. cygx_industrial_subject AS s
  180. INNER JOIN cygx_industrial_article_group_subject AS sg ON sg.industrial_subject_id = s.industrial_subject_id
  181. INNER JOIN cygx_article AS art ON art.article_id = sg.article_id
  182. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = art.article_id
  183. WHERE
  184. 1 = 1
  185. AND art.publish_status = 1 `
  186. if condition != "" {
  187. sql += condition
  188. }
  189. sql += ` GROUP BY s.industrial_subject_id ORDER BY s.create_time DESC LIMIT 4`
  190. _, err = o.Raw(sql).QueryRows(&items)
  191. return
  192. }
  193. //最新标的列表
  194. func GetIndustrialSubjectNewListByDepartmentId(departmentId, industrialManagementId int) (items []*IndustrialManagementIdName, err error) {
  195. o := orm.NewOrm()
  196. sql := `SELECT art.article_id,
  197. ( SELECT GROUP_CONCAT( DISTINCT s.subject_name ORDER BY s.industrial_subject_id DESC SEPARATOR '/' ) ) AS subject_name
  198. FROM
  199. cygx_article AS art
  200. INNER JOIN cygx_industrial_article_group_subject AS sg ON sg.article_id = art.article_id
  201. INNER JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = sg.industrial_subject_id
  202. WHERE
  203. department_id = ?
  204. AND s.industrial_management_id = ?
  205. GROUP BY art.article_id
  206. ORDER BY s.create_time DESC LIMIT 4`
  207. _, err = o.Raw(sql, departmentId, industrialManagementId).QueryRows(&items)
  208. return
  209. }
  210. //最新标的列表
  211. func GetArticleByDepartmentId(departmentId int) (items []*IndustrialManagementIdName, err error) {
  212. o := orm.NewOrm()
  213. sql := `SELECT article_id,is_report,MAX( publish_date ) art_time FROM cygx_article WHERE department_id = ? AND publish_status = 1 AND subject_ids != '' GROUP BY subject_ids ORDER BY art_time DESC LIMIT 4 `
  214. _, err = o.Raw(sql, departmentId).QueryRows(&items)
  215. return
  216. }
  217. func GetSubjectNames(articleId int) (subjects string, err error) {
  218. sql := ` SELECT GROUP_CONCAT( DISTINCT s.subject_name ORDER BY id ASC SEPARATOR '/' ) AS subject_name
  219. FROM
  220. cygx_industrial_article_group_subject as sg
  221. INNER JOIN cygx_industrial_subject as s ON s.industrial_subject_id = sg.industrial_subject_id
  222. WHERE article_id = ?`
  223. o := orm.NewOrm()
  224. err = o.Raw(sql, articleId).QueryRow(&subjects)
  225. return
  226. }
  227. func GetIndustrialNames(articleId int) (Industrial string, err error) {
  228. sql := ` SELECT
  229. m.industry_name
  230. FROM
  231. cygx_industrial_article_group_management as mg
  232. INNER JOIN cygx_industrial_management as m ON m.industrial_management_id = mg.industrial_management_id
  233. WHERE
  234. mg.article_id = ?
  235. ORDER BY m.industrial_management_id DESC
  236. LIMIT 1
  237. `
  238. o := orm.NewOrm()
  239. err = o.Raw(sql, articleId).QueryRow(&Industrial)
  240. return
  241. }
  242. type IndustrialManagementIdNamePc struct {
  243. Title string `description:"标题"`
  244. PublishDate string `description:"发布时间"`
  245. DepartmentId int `description:"作者ID"`
  246. ArticleId int `description:"文章id"`
  247. IndustryName string `description:"产业名称"`
  248. SubjectName string `description:"标的名称"`
  249. IsReport string `description:"1观点,0纪要"`
  250. Pv int `description:"Pv"`
  251. }
  252. //最新标的列表
  253. func GetArticleByDepartmentIdPc(departmentId int, articleIdGroup string) (items []*IndustrialManagementIdNamePc, err error) {
  254. o := orm.NewOrm()
  255. sql := `SELECT
  256. m.industry_name,
  257. (SELECT count(1) FROM cygx_article_history_record_newpv as h WHERE h.article_id = art.article_id ) as pv,
  258. GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' ) AS subject_name,
  259. art.*
  260. FROM
  261. cygx_article AS art
  262. LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = art.article_id
  263. LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  264. LEFT JOIN cygx_industrial_article_group_subject AS sg ON sg.article_id = art.article_id
  265. LEFT JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = sg.industrial_subject_id
  266. WHERE
  267. department_id = ?
  268. AND publish_status = 1`
  269. if articleIdGroup != "" {
  270. sql += ` AND art.article_id IN (` + articleIdGroup + `) `
  271. }
  272. sql += ` GROUP BY art.article_id ORDER BY publish_date DESC `
  273. _, err = o.Raw(sql, departmentId).QueryRows(&items)
  274. return
  275. }