resource_data.go 6.3 KB

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