config.go 1.6 KB

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