classify.go 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type Classify struct {
  7. Id int `orm:"column(id);pk"`
  8. ClassifyName string `description:"分类名称"`
  9. Sort int `json:"-"`
  10. ParentId int `description:"父级分类id"`
  11. CreateTime time.Time `description:"创建时间"`
  12. ModifyTime time.Time `description:"修改时间"`
  13. Abstract string `description:"栏目简介"`
  14. Descript string `description:"分享描述"`
  15. ReportAuthor string `description:"栏目作者"`
  16. AuthorDescript string `description:"作者简介"`
  17. ColumnImgUrl string `description:"栏目配图"`
  18. HeadImgUrl string `description:"头部banner"`
  19. AvatarImgUrl string `description:"头像"`
  20. ReportImgUrl string `description:"报告配图"`
  21. HomeImgUrl string `description:"首页配图"`
  22. }
  23. func GetClassifyById(classifyId int) (item *Classify, err error) {
  24. sql := ` SELECT * FROM classify WHERE id = ? `
  25. o := orm.NewOrmUsingDB("rddp")
  26. err = o.Raw(sql, classifyId).QueryRow(&item)
  27. return
  28. }
  29. func GetClassifyList() (item []*Classify, err error) {
  30. sql := ` SELECT * FROM classify WHERE parent_id = 0 AND classify_name not in("权益研报","双周报","月报","晨报","周报","草根调研","需求报告","会议纪要","大事点评","年报合集","宏观点评") `
  31. o := orm.NewOrmUsingDB("rddp")
  32. _, err = o.Raw(sql).QueryRows(&item)
  33. return
  34. }
  35. func GetClassifySecondList(classifyId int) (item []*ClassifyDetail, err error) {
  36. sql := ` SELECT a.id AS classify_id,a.classify_name,a.sort,a.parent_id,a.create_time,a.modify_time,a.abstract,a.descript,a.report_author,a.author_descript,a.report_img_url,a.head_img_url,a.avatar_img_url,a.column_img_url,a.home_img_url,a.is_home_column,MAX(b.stage) AS stage
  37. FROM classify AS a
  38. LEFT JOIN report AS b ON a.id=b.classify_id_second
  39. WHERE a.parent_id = ?
  40. GROUP BY a.id
  41. ORDER BY sort ASC `
  42. o := orm.NewOrmUsingDB("rddp")
  43. _, err = o.Raw(sql, classifyId).QueryRows(&item)
  44. return
  45. }
  46. type ClassifyDetail struct {
  47. ClassifyId int `description:"分类id"`
  48. ClassifyName string `description:"分类名称"`
  49. Sort int `json:"-"`
  50. ParentId int `description:"父级分类id"`
  51. CreateTime time.Time `description:"创建时间"`
  52. ModifyTime time.Time `description:"修改时间"`
  53. Abstract string `description:"栏目简介"`
  54. Descript string `description:"分享描述"`
  55. ReportAuthor string `description:"栏目作者"`
  56. AuthorDescript string `description:"作者简介"`
  57. ColumnImgUrl string `description:"栏目配图"`
  58. HeadImgUrl string `description:"头部banner"`
  59. AvatarImgUrl string `description:"头像"`
  60. ReportImgUrl string `description:"报告配图"`
  61. HomeImgUrl string `description:"首页配图"`
  62. Stage int `description:"最新期数"`
  63. CommentList []*CustomerComment
  64. }
  65. func GetClassifyDetailById(classifyId int) (item *ClassifyDetail, err error) {
  66. sql := ` SELECT id AS classify_id,classify_name,sort,parent_id,create_time,modify_time,abstract,descript,report_author,author_descript,report_img_url,head_img_url,avatar_img_url,column_img_url FROM classify WHERE id = ? `
  67. o := orm.NewOrmUsingDB("rddp")
  68. err = o.Raw(sql, classifyId).QueryRow(&item)
  69. return
  70. }