article_department.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 DepartmentResp struct {
  16. DepartmentId int `description:"作者ID"`
  17. CreateTime string `description:"创建时间"`
  18. PublishDate string `description:"更新时间"`
  19. NickName string `description:"昵称"`
  20. ImgUrl string `description:"头像链接"`
  21. IsFollow bool `description:"是否关注"`
  22. IsHot bool `description:"是否标红"`
  23. FllowNum int `description:"关注数量"`
  24. List []*IndustrialDepartmentListResp
  25. }
  26. type DepartmentListResp struct {
  27. Paging *paging.PagingItem `description:"分页数据"`
  28. List []*DepartmentResp
  29. }
  30. type CygxArticleDepartmentId struct {
  31. DepartmentId int `description:"作者ID"`
  32. }
  33. // 获取作者数量
  34. func GetDepartmentCount(departmentId int) (count int, err error) {
  35. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article_department WHERE department_id=? `
  36. o := orm.NewOrm()
  37. err = o.Raw(sqlCount, departmentId).QueryRow(&count)
  38. return
  39. }
  40. func GetArticleDepartmentDateilById(departmentId int) (item *DepartmentResp, err error) {
  41. o := orm.NewOrm()
  42. sql := `SELECT * FROM cygx_article_department WHERE department_id = ? `
  43. err = o.Raw(sql, departmentId).QueryRow(&item)
  44. return
  45. }
  46. // 数量
  47. func GetArticleDepartmentCount(condition string) (count int, err error) {
  48. o := orm.NewOrm()
  49. sql := ` SELECT COUNT(*) count
  50. FROM
  51. ( SELECT COUNT(1) FROM cygx_article_department AS d
  52. INNER JOIN cygx_article AS a ON a.department_id = d.department_id
  53. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  54. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id WHERE 1= 1 `
  55. if condition != "" {
  56. sql += condition
  57. }
  58. sql += ` GROUP BY d.department_id ) AS num `
  59. err = o.Raw(sql).QueryRow(&count)
  60. return
  61. }
  62. type IndustrialSubjectList struct {
  63. SubjectName string `description:"标的名称"`
  64. }
  65. // 作者列表
  66. func GetDepartmentList(condition, conditionOrder string, userId, startSize, pageSize int) (items []*DepartmentResp, err error) {
  67. o := orm.NewOrm()
  68. sql := `SELECT
  69. d.nick_name,
  70. d.department_id,
  71. d.img_url,
  72. MAX( a.publish_date ) AS publish_date,
  73. ( SELECT count( 1 ) FROM cygx_article_department_follow AS f WHERE f.department_id = d.department_id AND user_id =? AND f.type= 1 ) AS fllow_num,
  74. ( SELECT count( 1 ) FROM cygx_article_department_follow AS f WHERE f.department_id = d.department_id AND f.type= 1 ) +( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id IN (SELECT article_id FROM cygx_article WHERE department_id = d.department_id ) AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time ) ) AS sum_num
  75. FROM
  76. cygx_article_department AS d
  77. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  78. WHERE
  79. 1 = 1
  80. AND a.article_type_id > 0
  81. AND publish_status = 1 ` + condition + `
  82. GROUP BY
  83. d.department_id ` + conditionOrder + ` , last_updated_time DESC LIMIT ?,?`
  84. _, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  85. return
  86. }
  87. // 用户收藏榜start
  88. type DepartmentDetailResp struct {
  89. DepartmentId int `description:"作者Id"`
  90. NickName string `description:"作者昵称"`
  91. ImgUrl string `description:"图片链接"`
  92. FllowNum int `description:"多少人关注"`
  93. ArticleNum int `description:"文章数量"`
  94. CollectNum int `description:"收藏人数"`
  95. IsFollow bool `description:"是否关注"`
  96. List []*ArticleResearchResp
  97. ListIndustrial []*IndustrialManagementNewResp
  98. Paging *paging.PagingItem
  99. }
  100. type IndustrialManagementNewResp struct {
  101. IndustrialManagementId int `description:"产业Id"`
  102. IndustryName string `description:"产业名称"`
  103. IsHot bool `description:"是否是热门"`
  104. ArticleReadNum int `description:"文章阅读数量"`
  105. }
  106. type DepartmentDetail struct {
  107. DepartmentId int `description:"作者Id"`
  108. NickName string `description:"作者昵称"`
  109. ImgUrl string `description:"图片链接"`
  110. FllowNum int `description:"多少人关注"`
  111. ArticleNum int `description:"文章数量"`
  112. CollectNum int `description:"收藏人数"`
  113. IsFollow bool `description:"是否关注"`
  114. MyFllowNum int `description:"本人是否关注"`
  115. }
  116. // 作者详情
  117. func GetDepartmentDetail(userId, departmentId int, condition string) (item DepartmentDetail, err error) {
  118. o := orm.NewOrm()
  119. sql := `SELECT
  120. d.department_id,
  121. d.nick_name,
  122. d.img_url,
  123. ( SELECT count( 1 ) FROM cygx_article_department_follow AS af WHERE af.user_id = ? AND af.department_id = d.department_id AND af.type= 1 ) AS my_fllow_num,
  124. ( SELECT count( 1 ) FROM cygx_article_department_follow AS f WHERE f.department_id = d.department_id AND f.type= 1 ) AS fllow_num,
  125. ( SELECT count( 1 ) FROM cygx_article AS a WHERE a.department_id = d.department_id ` + condition + ` ) AS article_num,
  126. ( SELECT count( 1 ) FROM cygx_article_collect AS c WHERE c.article_id IN (SELECT article_id FROM cygx_article AS a WHERE a.department_id = d.department_id ` + condition + ` )) AS collect_num
  127. FROM
  128. cygx_article_department AS d
  129. WHERE
  130. d.department_id = ?`
  131. err = o.Raw(sql, userId, departmentId).QueryRow(&item)
  132. return
  133. } //end