resource_data.go 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. Roadshow *MicroRoadShowPageList `description:"微路演"`
  31. Activity *ActivityDetail `description:"活动"`
  32. Activityvideo *MicroRoadShowPageList `description:"活动视频"`
  33. Activityvoice *MicroRoadShowPageList `description:"活动音频"`
  34. Activityspecial *CygxActivitySpecialDetail `description:"专项调研活动"`
  35. Researchsummary *CygxReportSelectionRep `description:"本周研究汇总"`
  36. Minutessummary *CygxReportSelectionRep `description:"上周纪要汇总"`
  37. Meetingreviewchapt *CygxMorningMeetingGatherDetailListResp `description:"晨会精华"`
  38. ProductInterior *CygxProductInteriorResp `description:"产品内测"`
  39. IndustrialResource *IndustrialManagementHotResp `description:"产业资源包"`
  40. ReportSelection *CygxReportSelectionRep `description:"重点公司(原报告精选)"`
  41. YanxuanSpecial *CygxYanxuanSpecialCenterResp `description:"研选专栏"`
  42. AskserieVideo *MicroRoadShowPageList `description:"活动音频"`
  43. YanxuanSpecialAuthor *CygxYanxuanSpecialAuthorItem `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 GetResourceDataCount(condition string, pars []interface{}) (count int, err error) {
  63. sqlCount := `SELECT COUNT(1) AS count FROM cygx_resource_data WHERE 1= 1 ` + condition
  64. o := orm.NewOrm()
  65. err = o.Raw(sqlCount, pars).QueryRow(&count)
  66. return
  67. }
  68. // 获取首页最新表,与研选专栏作者表的数量
  69. func GetResourceDataAndYanxuanSpecialAuthorCount(condition string, pars []interface{}, conditionContentYxAuthor string, parsContentYxAuthor []interface{}) (count int, err error) {
  70. sqlCount := `SELECT
  71. COUNT( 1 ) total FROM
  72. ( SELECT id FROM cygx_resource_data WHERE 1 = 1 ` + condition + `
  73. UNION ALL
  74. SELECT id FROM cygx_yanxuan_special_author WHERE 1 = 1 ` + conditionContentYxAuthor + `
  75. ) z`
  76. o := orm.NewOrm()
  77. err = o.Raw(sqlCount, pars, parsContentYxAuthor).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. ptrStructOrTableName := "cygx_resource_data"
  107. whereParam := map[string]interface{}{"source_id": item.SourceId, "source": item.Source}
  108. qs := o.QueryTable(ptrStructOrTableName)
  109. for expr, exprV := range whereParam {
  110. qs = qs.Filter(expr, exprV)
  111. }
  112. _, err = qs.Update(updateParams)
  113. if err != nil {
  114. return
  115. }
  116. return
  117. }
  118. // 批量删除
  119. func DeleteResourceDataList(condition string, pars []interface{}) (err error) {
  120. if condition == "" {
  121. return
  122. }
  123. o := orm.NewOrm()
  124. sql := `DELETE FROM cygx_resource_data WHERE 1=1 ` + condition
  125. _, err = o.Raw(sql, pars).Exec()
  126. return
  127. }
  128. // 获取数量
  129. func GetCygxReportSelectionBySourceAndId(sourceId int, source string) (count int, err error) {
  130. o := orm.NewOrm()
  131. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_resource_data WHERE source_id = ? AND source =? `
  132. err = o.Raw(sqlCount, sourceId, source).QueryRow(&count)
  133. return
  134. }
  135. // 通过ID跟资源获取详情
  136. func GetCygxResourceDataByIdAndSource(sourceId int, source string) (item *CygxResourceData, err error) {
  137. o := orm.NewOrm()
  138. sql := `SELECT * FROM cygx_resource_data WHERE source_id = ? AND source =? `
  139. err = o.Raw(sql, sourceId, source).QueryRow(&item)
  140. return
  141. }
  142. // 获取数量
  143. func GetCygxResourceDataBySourceAndIdCount(sourceId int, source string) (count int, err error) {
  144. o := orm.NewOrm()
  145. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_resource_data WHERE source_id = ? AND source =? `
  146. err = o.Raw(sqlCount, sourceId, source).QueryRow(&count)
  147. return
  148. }
  149. // 列表
  150. func GetResourceDataListCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxResourceData, err error) {
  151. o := orm.NewOrm()
  152. sql := `SELECT * FROM cygx_resource_data WHERE 1= 1 `
  153. if condition != "" {
  154. sql += condition
  155. }
  156. sql += ` ORDER BY search_order_time DESC LIMIT ?,? `
  157. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  158. return
  159. }
  160. // 获取首页最新表,与研选专栏作者表的列表
  161. func GetResourceDataAndYanxuanSpecialAuthorListCondition(condition string, pars []interface{}, conditionContentYxAuthor string, parsContentYxAuthor []interface{}, startSize, pageSize int) (items []*CygxResourceData, err error) {
  162. o := orm.NewOrm()
  163. sql := `SELECT
  164. title,
  165. publish_date,
  166. abstract,
  167. annotation,
  168. source_id,
  169. source,
  170. create_time,
  171. search_tag,
  172. search_order_time
  173. FROM
  174. cygx_resource_data
  175. WHERE
  176. 1 = 1 ` + condition + `
  177. UNION ALL
  178. SELECT
  179. '' AS title,
  180. '' AS publish_date,
  181. '' AS abstract,
  182. '' AS annotation,
  183. id AS source_id,
  184. 'yanxuanspecialauthor',
  185. '' AS create_time,
  186. '' AS search_tag,
  187. modify_time AS search_order_time
  188. FROM
  189. cygx_yanxuan_special_author
  190. WHERE
  191. 1 = 1 ` + conditionContentYxAuthor
  192. sql += ` ORDER BY search_order_time DESC LIMIT ?,? `
  193. _, err = o.Raw(sql, pars, parsContentYxAuthor, startSize, pageSize).QueryRows(&items)
  194. return
  195. }