home.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hongze_api/utils"
  7. )
  8. type HomeList struct {
  9. ClassifyId int `orm:"column(id)"`
  10. ClassifyName string `description:"分类名称"`
  11. Child []*HomeClassifyItem
  12. }
  13. type HomeClassifyItem struct {
  14. ClassifyId int `orm:"column(id)"`
  15. ClassifyName string `description:"分类名称"`
  16. TitleType string `description:"标题类型,FICC或者权益"`
  17. Child *Report
  18. }
  19. func ListHome(userId, maxPermission, userPermission int, permissionStr string) (homeList []*HomeList, err error) {
  20. o := orm.NewOrmUsingDB("rddp")
  21. //sql := `SELECT id,classify_name FROM classify WHERE parent_id=0 ORDER BY create_time ASC `
  22. //暂时将双周报、月报隐藏
  23. items := make([]*HomeList, 0)
  24. sql := `SELECT id,classify_name FROM classify WHERE parent_id=0 and classify_name not IN("双周报","月报","晨报","周报","草根调研","需求报告","会议纪要","大事点评","年报合集") ORDER BY create_time ASC `
  25. _, err = o.Raw(sql).QueryRows(&items)
  26. if err != nil {
  27. fmt.Println("Get classify Err:" + err.Error())
  28. return
  29. }
  30. lenItem := len(items)
  31. fmt.Println("lenItem:", lenItem)
  32. for i := 0; i < lenItem; i++ {
  33. item := items[i]
  34. subItems := make([]*HomeClassifyItem, 0)
  35. subWhere := ``
  36. if maxPermission < 15 && userPermission == 0 {
  37. if permissionStr != "" {
  38. subWhere = ` WHERE parent_id=? AND classify_name IN(` + permissionStr + `) `
  39. } else {
  40. subWhere = ` WHERE parent_id=? `
  41. }
  42. } else {
  43. subWhere = ` WHERE parent_id=? `
  44. }
  45. subSql := `SELECT id ,classify_name FROM classify `
  46. subSql += subWhere
  47. subSql += ` and classify_name not IN("宏观点评")`
  48. subSql += ` ORDER BY sort ASC `
  49. _, err = o.Raw(subSql, item.ClassifyId).QueryRows(&subItems)
  50. if err != nil {
  51. fmt.Println("Sub Err:" + err.Error())
  52. return
  53. }
  54. lenSub := len(subItems)
  55. for k := 0; k < lenSub; k++ {
  56. subItem := subItems[k]
  57. reportSql := ` SELECT a.id,a.classify_name,b.*,
  58. (SELECT COUNT(1) FROM report_view_log AS c WHERE c.user_id=? AND c.report_id=b.id ) AS is_show_new_label,
  59. CASE WHEN DATE(b.modify_time)=DATE(NOW()) THEN 1 ELSE 0 END AS is_current_date
  60. FROM classify AS a
  61. INNER JOIN report AS b ON a.id=b.classify_id_second
  62. WHERE b.state=2 AND a.id=?
  63. ORDER BY b.publish_time DESC LIMIT 1 `
  64. report := new(Report)
  65. err = o.Raw(reportSql, userId, subItem.ClassifyId).QueryRow(&report)
  66. if err != nil {
  67. if err.Error() != utils.ErrNoRow() {
  68. return
  69. } else {
  70. err = nil
  71. }
  72. }
  73. subItems[k].Child = report
  74. }
  75. items[i].Child = subItems
  76. if lenSub > 0 {
  77. homeList = append(homeList, items[i])
  78. }
  79. }
  80. return
  81. }
  82. type PcHomeClassifyItem struct {
  83. ClassifyId int
  84. ClassifyName string `description:"分类名称"`
  85. Abstract string `description:"栏目简介"`
  86. Descript string `description:"分享描述"`
  87. ReportAuthor string `description:"栏目作者"`
  88. AuthorDescript string `description:"作者简介"`
  89. ColumnImgUrl string `description:"栏目配图"`
  90. HeadImgUrl string `description:"头部banner"`
  91. AvatarImgUrl string `description:"头像"`
  92. ReportImgUrl string `description:"报告配图"`
  93. HomeImgUrl string `description:"首页配图"`
  94. PcReport
  95. }
  96. func PcListHomeCount(classifyId int, endDate string) (count int, err error) {
  97. o := orm.NewOrmUsingDB("rddp")
  98. sql := `SELECT COUNT(1) AS count
  99. FROM classify AS a
  100. INNER JOIN report AS b ON a.id=b.classify_id_second
  101. WHERE b.state=2 AND b.classify_id_first=? AND b.publish_time>=?`
  102. err = o.Raw(sql, classifyId, endDate).QueryRow(&count)
  103. return
  104. }
  105. func PcListHome(classifyId, uid, startSize, pageSize int, endDate string) (items []*PcHomeClassifyItem, err error) {
  106. o := orm.NewOrmUsingDB("rddp")
  107. if uid > 0 {
  108. reportSql := ` SELECT a.id AS classify_id,a.head_img_url,a.avatar_img_url,a.column_img_url,a.report_img_url,a.home_img_url,b.*,
  109. (SELECT COUNT(1) FROM report_view_log AS c WHERE c.user_id=? AND c.report_id=b.id ) AS is_show_new_label,
  110. CASE WHEN DATE(b.modify_time)=DATE(NOW()) THEN 1 ELSE 0 END AS is_current_date
  111. FROM classify AS a
  112. INNER JOIN report AS b ON a.id=b.classify_id_second
  113. WHERE b.state=2 AND b.classify_id_first=? AND b.publish_time>=?
  114. ORDER BY b.publish_time DESC LIMIT ?,? `
  115. _, err = o.Raw(reportSql, uid, classifyId, endDate, startSize, pageSize).QueryRows(&items)
  116. } else {
  117. reportSql := ` SELECT a.id AS classify_id,a.head_img_url,a.avatar_img_url,a.column_img_url,a.report_img_url,a.home_img_url,b.*,
  118. CASE WHEN DATE(b.modify_time)=DATE(NOW()) THEN 1 ELSE 0 END AS is_current_date
  119. FROM classify AS a
  120. INNER JOIN report AS b ON a.id=b.classify_id_second
  121. WHERE b.state=2 AND b.classify_id_first=? AND b.publish_time>=?
  122. ORDER BY b.publish_time DESC LIMIT ?,? `
  123. _, err = o.Raw(reportSql, classifyId, endDate, startSize, pageSize).QueryRows(&items)
  124. }
  125. return
  126. }
  127. type PcListHomeResp struct {
  128. Paging *paging.PagingItem
  129. List []*PcHomeClassifyItem
  130. }