zhouqi_article_map.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. )
  5. type CygxZhouqiArticleMap struct {
  6. CategoryId int `description:"产业Id"`
  7. ParentId int `description:"父级ID"`
  8. MatchTypeName string `description:"行业名称"`
  9. SeriesName string `description:"系列名称"`
  10. ArticleUpdateTime string `description:"对应文章的更新时间"`
  11. }
  12. type CygxZhouqiArticleDetail struct {
  13. FiccReportId string `description:"Ficc研报单一篇报告,多个地方展示配置项"`
  14. }
  15. // 获取周期下面的一级分类
  16. func GetCygxZhouqiArticleMapFirst() (items []*CygxZhouqiArticleMap, err error) {
  17. o := orm.NewOrm()
  18. sql := `SELECT
  19. category_id,
  20. parent_id,
  21. match_type_name,
  22. series_name,
  23. article_update_time
  24. FROM
  25. cygx_zhouqi_article_map
  26. WHERE
  27. hidden = 0
  28. AND parent_id = 0
  29. ORDER BY
  30. sort DESC `
  31. _, err = o.Raw(sql).QueryRows(&items)
  32. return
  33. }
  34. // 根据父级分类ID获取下面的子分类
  35. func GetCygxZhouqiArticleMapByParentId(parentId int) (items []*CygxZhouqiArticleMap, err error) {
  36. o := orm.NewOrm()
  37. sql := `SELECT
  38. category_id,
  39. match_type_name,
  40. series_name,
  41. article_update_time
  42. FROM
  43. cygx_zhouqi_article_map
  44. WHERE
  45. parent_id = ? `
  46. _, err = o.Raw(sql, parentId).QueryRows(&items)
  47. return
  48. }
  49. // 根据名称获取详情
  50. func GetCygxZhouqiArticleMapByMatchTypeName(matchTypeName string) (item *CygxZhouqiArticleMap, err error) {
  51. o := orm.NewOrm()
  52. sql := ``
  53. sql = `SELECT a.* FROM cygx_zhouqi_article_map AS a WHERE a.match_type_name=? AND parent_id > 0 `
  54. err = o.Raw(sql, matchTypeName).QueryRow(&item)
  55. return
  56. }
  57. // 更新对应分类所关联的最新文章的时间
  58. func UpdateCygxZhouqiArticleMapTime(articleUpdateTime string, categoryId int) (err error) {
  59. o := orm.NewOrm()
  60. sql := ``
  61. sql = `UPDATE cygx_zhouqi_article_map SET hidden=0,article_update_time=? WHERE category_id = ? `
  62. _, err = o.Raw(sql, articleUpdateTime, categoryId).Exec()
  63. return
  64. }
  65. // 通过纪要ID获取详情
  66. func GetCygxZhouqiArticleMapInfoById(categoryId int) (item *CygxZhouqiArticleDetail, err error) {
  67. o := orm.NewOrm()
  68. sql := `SELECT * FROM cygx_zhouqi_article_map WHERE category_id=? `
  69. err = o.Raw(sql, categoryId).QueryRow(&item)
  70. return
  71. }