resource_data.go 7.1 KB

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