zhouqi_article_map.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. // 获取周期下面的一级分类
  13. func GetCygxZhouqiArticleMapFirst() (items []*CygxZhouqiArticleMap, err error) {
  14. o := orm.NewOrm()
  15. sql := `SELECT
  16. category_id,
  17. parent_id,
  18. match_type_name,
  19. series_name,
  20. article_update_time
  21. FROM
  22. cygx_zhouqi_article_map
  23. WHERE
  24. hidden = 0
  25. AND parent_id = 0
  26. ORDER BY
  27. sort DESC `
  28. _, err = o.Raw(sql).QueryRows(&items)
  29. return
  30. }
  31. // 根据父级分类ID获取下面的子分类
  32. func GetCygxZhouqiArticleMapByParentId(parentId int) (items []*CygxZhouqiArticleMap, err error) {
  33. o := orm.NewOrm()
  34. sql := `SELECT
  35. category_id,
  36. match_type_name,
  37. series_name,
  38. article_update_time
  39. FROM
  40. cygx_zhouqi_article_map
  41. WHERE
  42. parent_id = ? `
  43. _, err = o.Raw(sql, parentId).QueryRows(&items)
  44. return
  45. }
  46. // 根据名称获取详情
  47. func GetCygxZhouqiArticleMapByMatchTypeName(matchTypeName string) (item *CygxZhouqiArticleMap, err error) {
  48. o := orm.NewOrm()
  49. sql := ``
  50. sql = `SELECT a.* FROM cygx_zhouqi_article_map AS a WHERE a.match_type_name=? AND parent_id > 0 `
  51. err = o.Raw(sql, matchTypeName).QueryRow(&item)
  52. return
  53. }
  54. // 更新对应分类所关联的最新文章的时间
  55. func UpdateCygxZhouqiArticleMapTime(articleUpdateTime string, categoryId int) (err error) {
  56. o := orm.NewOrm()
  57. sql := ``
  58. sql = `UPDATE cygx_zhouqi_article_map SET hidden=0,article_update_time=? WHERE category_id = ? `
  59. _, err = o.Raw(sql, articleUpdateTime, categoryId).Exec()
  60. return
  61. }