resource_data.go 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "time"
  6. )
  7. type CygxResourceData struct {
  8. Id int `orm:"column(id);pk"`
  9. SourceId int `description:"资源ID"`
  10. Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  11. Title string `description:"标题"`
  12. Annotation string `description:"核心观点"`
  13. CreateTime time.Time `description:"创建时间"`
  14. PublishDate string `description:"发布时间"`
  15. Abstract string `description:"摘要"`
  16. }
  17. type CygxResourceDataResp struct {
  18. Id int `orm:"column(id);pk"`
  19. SourceId int `description:"资源ID"`
  20. Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  21. PublishDate string `description:"发布时间"`
  22. Article *HomeArticle `description:"文章"`
  23. Newchart *HomeChartListResp `description:"图表"`
  24. Roadshow *MicroRoadShowPageList `description:"微路演"`
  25. Activity *ActivityDetail `description:"活动"`
  26. Activityvideo *MicroRoadShowPageList `description:"活动视频"`
  27. Activityvoice *MicroRoadShowPageList `description:"活动音频"`
  28. Activityspecial *CygxActivitySpecialDetail `description:"专项调研活动"`
  29. Researchsummary *CygxReportSelectionRep `description:"本周研究汇总"`
  30. Minutessummary *CygxReportSelectionRep `description:"上周纪要汇总"`
  31. }
  32. // Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  33. type HomeResourceDataListResp struct {
  34. Paging *paging.PagingItem
  35. List []*CygxResourceDataResp `description:"列表"`
  36. }
  37. // 列表
  38. func GetResourceDataList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxResourceData, err error) {
  39. o := orm.NewOrm()
  40. sql := `SELECT * FROM cygx_resource_data WHERE 1= 1 `
  41. if condition != "" {
  42. sql += condition
  43. }
  44. sql += ` ORDER BY publish_date DESC , id DESC LIMIT ?,? `
  45. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  46. return
  47. }
  48. // 获取用户报名成功数量
  49. func GetResourceDataCount(condition string, pars []interface{}) (count int, err error) {
  50. sqlCount := `SELECT COUNT(1) AS count FROM cygx_resource_data WHERE 1= 1 ` + condition
  51. o := orm.NewOrm()
  52. err = o.Raw(sqlCount, pars).QueryRow(&count)
  53. return
  54. }
  55. // 添加
  56. func AddCygxResourceData(item *CygxResourceData) (lastId int64, err error) {
  57. o := orm.NewOrm()
  58. lastId, err = o.Insert(item)
  59. return
  60. }
  61. // 删除数据
  62. func DeleteResourceData(sourceId int, source string) (err error) {
  63. o := orm.NewOrm()
  64. sql := ` DELETE FROM cygx_resource_data WHERE source_id = ? AND source =? `
  65. _, err = o.Raw(sql, sourceId, source).Exec()
  66. return
  67. }
  68. // 修改数据
  69. func UpdateResourceData(sourceId int, source, publishDate string) (err error) {
  70. o := orm.NewOrm()
  71. sql := `UPDATE cygx_resource_data SET publish_date=? WHERE source_id=? AND source =? `
  72. _, err = o.Raw(sql, publishDate, sourceId, source).Exec()
  73. return
  74. }
  75. // 批量删除
  76. func DeleteResourceDataList(condition string, pars []interface{}) (err error) {
  77. if condition == "" {
  78. return
  79. }
  80. o := orm.NewOrm()
  81. sql := `DELETE FROM cygx_resource_data WHERE 1=1 ` + condition
  82. _, err = o.Raw(sql, pars).Exec()
  83. return
  84. }