resource_data.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. 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. YanxuanSpecial *CygxYanxuanSpecialCenterResp `description:"研选专栏"`
  39. AskserieVideo *MicroRoadShowPageList `description:"活动音频"`
  40. }
  41. // Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  42. type HomeResourceDataListResp struct {
  43. Paging *paging.PagingItem
  44. List []*CygxResourceDataResp `description:"列表"`
  45. }
  46. // 列表
  47. func GetResourceDataList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxResourceData, err error) {
  48. o := orm.NewOrm()
  49. sql := `SELECT * FROM cygx_resource_data WHERE 1= 1 `
  50. if condition != "" {
  51. sql += condition
  52. }
  53. sql += ` ORDER BY publish_date DESC , id DESC LIMIT ?,? `
  54. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  55. return
  56. }
  57. // 获取用户报名成功数量
  58. func GetResourceDataCount(condition string, pars []interface{}) (count int, err error) {
  59. sqlCount := `SELECT COUNT(1) AS count FROM cygx_resource_data WHERE 1= 1 ` + condition
  60. o := orm.NewOrm()
  61. err = o.Raw(sqlCount, pars).QueryRow(&count)
  62. return
  63. }
  64. // 添加
  65. func AddCygxResourceData(item *CygxResourceData) (lastId int64, err error) {
  66. o := orm.NewOrm()
  67. lastId, err = o.Insert(item)
  68. return
  69. }
  70. // 删除数据
  71. func DeleteResourceData(sourceId int, source string) (err error) {
  72. o := orm.NewOrm()
  73. sql := ` DELETE FROM cygx_resource_data WHERE source_id = ? AND source =? `
  74. _, err = o.Raw(sql, sourceId, source).Exec()
  75. return
  76. }
  77. // 修改数据
  78. func UpdateResourceData(sourceId int, source, publishDate string) (err error) {
  79. o := orm.NewOrm()
  80. sql := `UPDATE cygx_resource_data SET publish_date=? WHERE source_id=? AND source =? `
  81. _, err = o.Raw(sql, publishDate, sourceId, source).Exec()
  82. return
  83. }
  84. // 修改
  85. func UpdateResourceDataByItem(item *CygxResourceData) (err error) {
  86. o := orm.NewOrm()
  87. updateParams := make(map[string]interface{})
  88. updateParams["PublishDate"] = item.PublishDate
  89. updateParams["SearchTag"] = item.SearchTag
  90. ptrStructOrTableName := "cygx_resource_data"
  91. whereParam := map[string]interface{}{"source_id": item.SourceId, "source": item.Source}
  92. qs := o.QueryTable(ptrStructOrTableName)
  93. for expr, exprV := range whereParam {
  94. qs = qs.Filter(expr, exprV)
  95. }
  96. _, err = qs.Update(updateParams)
  97. if err != nil {
  98. return
  99. }
  100. return
  101. }
  102. // 批量删除
  103. func DeleteResourceDataList(condition string, pars []interface{}) (err error) {
  104. if condition == "" {
  105. return
  106. }
  107. o := orm.NewOrm()
  108. sql := `DELETE FROM cygx_resource_data WHERE 1=1 ` + condition
  109. _, err = o.Raw(sql, pars).Exec()
  110. return
  111. }
  112. // 获取数量
  113. func GetCygxReportSelectionBySourceAndId(sourceId int, source string) (count int, err error) {
  114. o := orm.NewOrm()
  115. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_resource_data WHERE source_id = ? AND source =? `
  116. err = o.Raw(sqlCount, sourceId, source).QueryRow(&count)
  117. return
  118. }
  119. // 通过ID跟资源获取详情
  120. func GetCygxResourceDataByIdAndSource(sourceId int, source string) (item *CygxResourceData, err error) {
  121. o := orm.NewOrm()
  122. sql := `SELECT * FROM cygx_resource_data WHERE source_id = ? AND source =? `
  123. err = o.Raw(sql, sourceId, source).QueryRow(&item)
  124. return
  125. }
  126. // 获取数量
  127. func GetCygxResourceDataBySourceAndIdCount(sourceId int, source string) (count int, err error) {
  128. o := orm.NewOrm()
  129. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_resource_data WHERE source_id = ? AND source =? `
  130. err = o.Raw(sqlCount, sourceId, source).QueryRow(&count)
  131. return
  132. }
  133. // 列表
  134. func GetResourceDataListCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxResourceData, err error) {
  135. o := orm.NewOrm()
  136. sql := `SELECT * FROM cygx_resource_data WHERE 1= 1 `
  137. if condition != "" {
  138. sql += condition
  139. }
  140. sql += ` ORDER BY search_order_time DESC LIMIT ?,? `
  141. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  142. return
  143. }