resource_data.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. SearchTag string `description:"搜索标签"`
  17. }
  18. type CygxResourceDataResp struct {
  19. Id int `orm:"column(id);pk"`
  20. BodyHighlight []string `description:"搜索高亮展示结果"`
  21. IsSummary int `description:"是否是纪要"`
  22. SourceId int `description:"资源ID"`
  23. Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  24. PublishDate string `description:"发布时间"`
  25. Article *HomeArticle `description:"文章"`
  26. Newchart *HomeChartListResp `description:"图表"`
  27. Roadshow *MicroRoadShowPageList `description:"微路演"`
  28. Activity *ActivityDetail `description:"活动"`
  29. Activityvideo *MicroRoadShowPageList `description:"活动视频"`
  30. Activityvoice *MicroRoadShowPageList `description:"活动音频"`
  31. Activityspecial *CygxActivitySpecialDetail `description:"专项调研活动"`
  32. Researchsummary *CygxReportSelectionRep `description:"本周研究汇总"`
  33. Minutessummary *CygxReportSelectionRep `description:"上周纪要汇总"`
  34. Meetingreviewchapt *CygxMorningMeetingGatherDetailListResp `description:"晨会精华"`
  35. ProductInterior *CygxProductInteriorResp `description:"产品内测"`
  36. IndustrialResource *IndustrialManagementHotResp `description:"产业资源包"`
  37. ReportSelection *CygxReportSelectionRep `description:"重点公司(原报告精选)"`
  38. }
  39. // Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  40. type HomeResourceDataListResp struct {
  41. Paging *paging.PagingItem
  42. List []*CygxResourceDataResp `description:"列表"`
  43. }
  44. // 列表
  45. func GetResourceDataList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxResourceData, err error) {
  46. o := orm.NewOrm()
  47. sql := `SELECT * FROM cygx_resource_data WHERE 1= 1 `
  48. if condition != "" {
  49. sql += condition
  50. }
  51. sql += ` ORDER BY publish_date DESC , id DESC LIMIT ?,? `
  52. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  53. return
  54. }
  55. // 获取用户报名成功数量
  56. func GetResourceDataCount(condition string, pars []interface{}) (count int, err error) {
  57. sqlCount := `SELECT COUNT(1) AS count FROM cygx_resource_data WHERE 1= 1 ` + condition
  58. o := orm.NewOrm()
  59. err = o.Raw(sqlCount, pars).QueryRow(&count)
  60. return
  61. }
  62. // 添加
  63. func AddCygxResourceData(item *CygxResourceData) (lastId int64, err error) {
  64. o := orm.NewOrm()
  65. lastId, err = o.Insert(item)
  66. return
  67. }
  68. // 删除数据
  69. func DeleteResourceData(sourceId int, source string) (err error) {
  70. o := orm.NewOrm()
  71. sql := ` DELETE FROM cygx_resource_data WHERE source_id = ? AND source =? `
  72. _, err = o.Raw(sql, sourceId, source).Exec()
  73. return
  74. }
  75. // 修改数据
  76. func UpdateResourceData(sourceId int, source, publishDate string) (err error) {
  77. o := orm.NewOrm()
  78. sql := `UPDATE cygx_resource_data SET publish_date=? WHERE source_id=? AND source =? `
  79. _, err = o.Raw(sql, publishDate, sourceId, source).Exec()
  80. return
  81. }
  82. // 修改
  83. func UpdateResourceDataByItem(item *CygxResourceData) (err error) {
  84. o := orm.NewOrm()
  85. updateParams := make(map[string]interface{})
  86. updateParams["PublishDate"] = item.PublishDate
  87. updateParams["SearchTag"] = item.SearchTag
  88. ptrStructOrTableName := "cygx_resource_data"
  89. whereParam := map[string]interface{}{"source_id": item.SourceId, "source": item.Source}
  90. qs := o.QueryTable(ptrStructOrTableName)
  91. for expr, exprV := range whereParam {
  92. qs = qs.Filter(expr, exprV)
  93. }
  94. _, err = qs.Update(updateParams)
  95. if err != nil {
  96. return
  97. }
  98. return
  99. }
  100. // 批量删除
  101. func DeleteResourceDataList(condition string, pars []interface{}) (err error) {
  102. if condition == "" {
  103. return
  104. }
  105. o := orm.NewOrm()
  106. sql := `DELETE FROM cygx_resource_data WHERE 1=1 ` + condition
  107. _, err = o.Raw(sql, pars).Exec()
  108. return
  109. }
  110. // 获取数量
  111. func GetCygxReportSelectionBySourceAndId(sourceId int, source string) (count int, err error) {
  112. o := orm.NewOrm()
  113. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_resource_data WHERE source_id = ? AND source =? `
  114. err = o.Raw(sqlCount, sourceId, source).QueryRow(&count)
  115. return
  116. }
  117. // 通过ID跟资源获取详情
  118. func GetCygxResourceDataByIdAndSource(sourceId int, source string) (item *CygxResourceData, err error) {
  119. o := orm.NewOrm()
  120. sql := `SELECT * FROM cygx_resource_data WHERE source_id = ? AND source =? `
  121. err = o.Raw(sql, sourceId, source).QueryRow(&item)
  122. return
  123. }