resource_data.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxResourceData struct {
  7. Id int `orm:"column(id);pk"`
  8. SourceId int `description:"资源ID"`
  9. Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  10. Title string `description:"标题"`
  11. Annotation string `description:"核心观点"`
  12. CreateTime time.Time `description:"创建时间"`
  13. PublishDate string `description:"发布时间"`
  14. Abstract string `description:"摘要"`
  15. SearchTag string `description:"搜索标签"`
  16. }
  17. // 添加
  18. func AddCygxResourceData(item *CygxResourceData) (lastId int64, err error) {
  19. o := orm.NewOrm()
  20. lastId, err = o.Insert(item)
  21. return
  22. }
  23. // 删除数据
  24. func DeleteResourceData(sourceId int, source string) (err error) {
  25. o := orm.NewOrm()
  26. sql := ` DELETE FROM cygx_resource_data WHERE source_id = ? AND source =? `
  27. _, err = o.Raw(sql, sourceId, source).Exec()
  28. return
  29. }
  30. // 修改数据
  31. func UpdateResourceData(sourceId int, source, publishDate string) (err error) {
  32. o := orm.NewOrm()
  33. sql := `UPDATE cygx_resource_data SET publish_date=? WHERE source_id=? AND source =? `
  34. _, err = o.Raw(sql, publishDate, sourceId, source).Exec()
  35. return
  36. }
  37. // 获取数量
  38. func GetCygxReportSelectionBySourceAndId(sourceId int, source string) (count int, err error) {
  39. o := orm.NewOrm()
  40. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_resource_data WHERE source_id = ? AND source =? `
  41. err = o.Raw(sqlCount, sourceId, source).QueryRow(&count)
  42. return
  43. }
  44. // 通过ID跟资源获取详情
  45. func GetCygxResourceDataByIdAndSource(sourceId int, source string) (item *CygxResourceData, err error) {
  46. o := orm.NewOrm()
  47. sql := `SELECT * FROM cygx_resource_data WHERE source_id = ? AND source =? `
  48. err = o.Raw(sql, sourceId, source).QueryRow(&item)
  49. return
  50. }