config.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. var (
  7. HomeHeaderTabConfigCode = "home_header_tab"
  8. )
  9. type CygxConfig struct {
  10. ConfigId int `json:"-" orm:"column(config_id);pk"`
  11. ConfigCode string `json:"-"`
  12. ConfigValue string
  13. Remark string `json:"-"`
  14. CreateTime time.Time `json:"-"`
  15. }
  16. type KeyWord struct {
  17. KeyWord string `description:"关键词"`
  18. }
  19. func GetConfigByCode(configCode string) (item *CygxConfig, err error) {
  20. sql := `SELECT * FROM cygx_config WHERE config_code=? `
  21. err = orm.NewOrm().Raw(sql, configCode).QueryRow(&item)
  22. return
  23. }
  24. //更改配置信息
  25. func UpdateConfigByCode(configValue, countryCode string) (err error) {
  26. o := orm.NewOrm()
  27. sql := `UPDATE cygx_config SET config_value= ? WHERE config_code=? `
  28. _, err = o.Raw(sql, configValue, countryCode).Exec()
  29. return
  30. }
  31. type ConfigResp struct {
  32. Item *CygxConfig
  33. List []*KeyWord `description:"图表搜索推荐"`
  34. ListHot []*KeyWord `description:"热搜关键词"`
  35. }
  36. //获取是否展示限免标签
  37. func GetShowSustainable() (count int, err error) {
  38. o := orm.NewOrm()
  39. sqlCount := ` SELECT COUNT(1) FROM cygx_config WHERE config_code= 'is_show_sustainable' AND config_value = 1 `
  40. err = o.Raw(sqlCount).QueryRow(&count)
  41. return
  42. }
  43. // 通过报告精选来获取最新的推荐搜索词
  44. func GetHotSearch() (permission string, err error) {
  45. sql := `SELECT
  46. GROUP_CONCAT( DISTINCT rl.subject_name ORDER BY rl.article_sun_id ASC SEPARATOR ',' ) AS subject_name
  47. FROM
  48. cygx_report_selection_log AS rl
  49. WHERE
  50. rl.article_id = (
  51. SELECT
  52. MAX( article_id )
  53. FROM
  54. cygx_report_selection
  55. WHERE
  56. publish_status = 1)`
  57. o := orm.NewOrm()
  58. err = o.Raw(sql).QueryRow(&permission)
  59. return
  60. }
  61. type HomeHeaderTab struct {
  62. Id int `description:"导航ID"`
  63. Name string `description:"导航名称"`
  64. }