summary_fastsearch_keywords.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package cygx
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type SummaryFastsearchKeywords struct {
  8. Id int `description:"活动类型id"`
  9. KeyWord string `description:"关键词"`
  10. }
  11. type CygxSummaryFastsearchKeywords struct {
  12. Id int `description:"活动类型id"`
  13. KeyWord string `description:"关键词"`
  14. CreateTime time.Time `description:"创建时间"`
  15. }
  16. type SummaryFastsearchKeywordsResp struct {
  17. KeyWord string `description:"关键词,多个用 , 隔开"`
  18. }
  19. type SummaryFastsearchKeyType struct {
  20. KeyType string `description:"关键词类型 ‘活动:Activity’,’纪要:Summary'"`
  21. }
  22. type SummaryFastsearchKeywordsListResp struct {
  23. List []*SummaryFastsearchKeywords
  24. }
  25. // 列表
  26. func GetSummaryFastsearchKeywordsList() (items []*SummaryFastsearchKeywords, err error) {
  27. o := orm.NewOrmUsingDB("hz_cygx")
  28. sql := `SELECT * FROM cygx_summary_fastsearch_keywords ORDER BY sort DESC`
  29. _, err = o.Raw(sql).QueryRows(&items)
  30. return
  31. }
  32. // 添加快捷搜索词
  33. func AddSummaryFastsearchKeywords(items []*CygxSummaryFastsearchKeywords) (newId int64, err error) {
  34. o := orm.NewOrmUsingDB("hz_cygx")
  35. to, err := o.Begin()
  36. if err != nil {
  37. return
  38. }
  39. defer func() {
  40. if err != nil {
  41. fmt.Println(err)
  42. _ = to.Rollback()
  43. } else {
  44. _ = to.Commit()
  45. }
  46. }()
  47. //删除原有的词库信息
  48. sql := ` DELETE FROM cygx_summary_fastsearch_keywords`
  49. _, err = to.Raw(sql).Exec()
  50. if err != nil {
  51. return
  52. }
  53. for _, v := range items {
  54. newId, err = to.Insert(v)
  55. if err != nil {
  56. return
  57. }
  58. }
  59. return
  60. }