resource_data.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxResourceData struct {
  7. Id int `orm:"column(id);pk"`
  8. SourceId int `description:"资源ID"`
  9. Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  10. Title string `description:"标题"`
  11. Annotation string `description:"核心观点"`
  12. CreateTime time.Time `description:"创建时间"`
  13. PublishDate string `description:"发布时间"`
  14. Abstract string `description:"摘要"`
  15. SearchTag string `description:"搜索标签"`
  16. ChartPermissionId int `description:"行业id"`
  17. SearchTitle string `description:"搜索匹配用的标题"`
  18. SearchContent string `description:"搜索匹配用的内容"`
  19. SearchOrderTime string `description:"搜索排序时间"`
  20. }
  21. // 根据资源类型获取列表
  22. func GetCygxResourceDataListBysource(source string) (items []*CygxResourceData, err error) {
  23. o := orm.NewOrmUsingDB("hz_cygx")
  24. sql := `SELECT * FROM cygx_resource_data as art WHERE 1= 1 AND source = ? AND search_title = '' `
  25. _, err = o.Raw(sql, source).QueryRows(&items)
  26. return
  27. }
  28. // 添加
  29. func AddCygxResourceData(item *CygxResourceData) (lastId int64, err error) {
  30. o := orm.NewOrmUsingDB("hz_cygx")
  31. lastId, err = o.Insert(item)
  32. return
  33. }
  34. // 删除数据
  35. func DeleteResourceData(sourceId int, source string) (err error) {
  36. o := orm.NewOrmUsingDB("hz_cygx")
  37. sql := ` DELETE FROM cygx_resource_data WHERE source_id = ? AND source =? `
  38. _, err = o.Raw(sql, sourceId, source).Exec()
  39. return
  40. }
  41. // 修改数据
  42. func UpdateResourceData(sourceId int, source, publishDate string) (err error) {
  43. o := orm.NewOrmUsingDB("hz_cygx")
  44. sql := `UPDATE cygx_resource_data SET publish_date=? WHERE source_id=? AND source =? `
  45. _, err = o.Raw(sql, publishDate, sourceId, source).Exec()
  46. return
  47. }
  48. // 修改
  49. func UpdateResourceDataByItem(item *CygxResourceData) (err error) {
  50. o := orm.NewOrmUsingDB("hz_cygx")
  51. updateParams := make(map[string]interface{})
  52. updateParams["PublishDate"] = item.PublishDate
  53. updateParams["SearchTag"] = item.SearchTag
  54. updateParams["ChartPermissionId"] = item.ChartPermissionId
  55. updateParams["SearchTitle"] = item.SearchTitle
  56. updateParams["SearchContent"] = item.SearchContent
  57. updateParams["SearchOrderTime"] = item.SearchOrderTime
  58. ptrStructOrTableName := "cygx_resource_data"
  59. whereParam := map[string]interface{}{"source_id": item.SourceId, "source": item.Source}
  60. qs := o.QueryTable(ptrStructOrTableName)
  61. for expr, exprV := range whereParam {
  62. qs = qs.Filter(expr, exprV)
  63. }
  64. _, err = qs.Update(updateParams)
  65. if err != nil {
  66. return
  67. }
  68. return
  69. }
  70. // 修改
  71. func UpdateChartPermissionIdResourceDataByItem(item *CygxResourceData) (err error) {
  72. o := orm.NewOrmUsingDB("hz_cygx")
  73. updateParams := make(map[string]interface{})
  74. updateParams["ChartPermissionId"] = item.ChartPermissionId
  75. ptrStructOrTableName := "cygx_resource_data"
  76. whereParam := map[string]interface{}{"source_id": item.SourceId, "source": item.Source}
  77. qs := o.QueryTable(ptrStructOrTableName)
  78. for expr, exprV := range whereParam {
  79. qs = qs.Filter(expr, exprV)
  80. }
  81. _, err = qs.Update(updateParams)
  82. if err != nil {
  83. return
  84. }
  85. return
  86. }
  87. // 获取数量
  88. func GetCygxReportSelectionBySourceAndId(sourceId int, source string) (count int, err error) {
  89. o := orm.NewOrmUsingDB("hz_cygx")
  90. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_resource_data WHERE source_id = ? AND source =? `
  91. err = o.Raw(sqlCount, sourceId, source).QueryRow(&count)
  92. return
  93. }
  94. // 通过ID跟资源获取详情
  95. func GetCygxResourceDataByIdAndSource(sourceId int, source string) (item *CygxResourceData, err error) {
  96. o := orm.NewOrmUsingDB("hz_cygx")
  97. sql := `SELECT * FROM cygx_resource_data WHERE source_id = ? AND source =? `
  98. err = o.Raw(sql, sourceId, source).QueryRow(&item)
  99. return
  100. }
  101. // 获取数量
  102. func GetCygxResourceDataBySourceAndIdCount(sourceId int, source string) (count int, err error) {
  103. o := orm.NewOrmUsingDB("hz_cygx")
  104. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_resource_data WHERE source_id = ? AND source =? `
  105. err = o.Raw(sqlCount, sourceId, source).QueryRow(&count)
  106. return
  107. }