resource_data.go 7.0 KB

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