resource_data_industrial_group_management.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // 首页资源表与产业的关系
  7. type CygxResourceDataIndustrialGroupManagement struct {
  8. Id int `orm:"column(id);pk" description:"主键ID"`
  9. ResourceDataId int `description:"cygx_resource_data 主键ID"`
  10. SourceId int `description:"资源ID"`
  11. Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  12. IndustrialManagementId int `description:"cygx_industrial_management表的主键ID"`
  13. CreateTime time.Time `description:"创建时间"`
  14. }
  15. // 首页资源表与产业的关系
  16. type CygxResourceDataIndustrialGroupSubject struct {
  17. Id int `orm:"column(id);pk" description:"主键ID"`
  18. ResourceDataId int `description:"cygx_resource_data 主键ID"`
  19. SourceId int `description:"资源ID"`
  20. Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  21. IndustrialSubjectId int `description:"cygx_industrial_subject表的主键ID"`
  22. CreateTime time.Time `description:"创建时间"`
  23. }
  24. // 关联产业列表
  25. func GetCygxResourceDataIndustrialGroupManagementList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxResourceDataIndustrialGroupManagement, err error) {
  26. o := orm.NewOrm()
  27. sql := `SELECT * FROM cygx_resource_data_industrial_group_management as a WHERE 1= 1 `
  28. if condition != "" {
  29. sql += condition
  30. }
  31. if startSize+pageSize > 0 {
  32. sql += ` LIMIT ?,? `
  33. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  34. } else {
  35. _, err = o.Raw(sql, pars).QueryRows(&items)
  36. }
  37. return
  38. }
  39. // 关联标的列表
  40. func GetCygxResourceDataIndustrialGroupSubjectList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxResourceDataIndustrialGroupSubject, err error) {
  41. o := orm.NewOrm()
  42. sql := `SELECT * FROM cygx_resource_data_industrial_group_subject as a WHERE 1= 1 `
  43. if condition != "" {
  44. sql += condition
  45. }
  46. if startSize+pageSize > 0 {
  47. sql += ` LIMIT ?,? `
  48. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  49. } else {
  50. _, err = o.Raw(sql, pars).QueryRows(&items)
  51. }
  52. return
  53. }
  54. // 添加
  55. func AddCygxResourceDataGroup(sourceId int, source string, industrialItems []*CygxResourceDataIndustrialGroupManagement, subjectItems []*CygxResourceDataIndustrialGroupSubject) (err error) {
  56. o := orm.NewOrm()
  57. to, err := o.Begin()
  58. if err != nil {
  59. return
  60. }
  61. defer func() {
  62. if err != nil {
  63. _ = to.Rollback()
  64. } else {
  65. _ = to.Commit()
  66. }
  67. }()
  68. //删除关联产业
  69. sql := ` DELETE FROM cygx_resource_data_industrial_group_management WHERE source_id = ? AND source =? `
  70. _, err = to.Raw(sql, sourceId, source).Exec()
  71. if err != nil {
  72. return
  73. }
  74. //删除关联标的
  75. sql = ` DELETE FROM cygx_resource_data_industrial_group_subject WHERE source_id = ? AND source =? `
  76. _, err = to.Raw(sql, sourceId, source).Exec()
  77. if err != nil {
  78. return
  79. }
  80. //批量插入关联产业
  81. if len(industrialItems) > 0 {
  82. _, err = to.InsertMulti(len(industrialItems), industrialItems)
  83. if err != nil {
  84. return
  85. }
  86. }
  87. //批量插入关联标的
  88. if len(subjectItems) > 0 {
  89. _, err = to.InsertMulti(len(subjectItems), subjectItems)
  90. if err != nil {
  91. return
  92. }
  93. }
  94. return
  95. }
  96. // 删除
  97. func DeleteCygxResourceDataGroup(sourceId int, source string) (err error) {
  98. o := orm.NewOrm()
  99. to, err := o.Begin()
  100. if err != nil {
  101. return
  102. }
  103. defer func() {
  104. if err != nil {
  105. _ = to.Rollback()
  106. } else {
  107. _ = to.Commit()
  108. }
  109. }()
  110. //删除关联产业
  111. sql := ` DELETE FROM cygx_resource_data_industrial_group_management WHERE source_id = ? AND source =? `
  112. _, err = to.Raw(sql, sourceId, source).Exec()
  113. if err != nil {
  114. return
  115. }
  116. //删除关联标的
  117. sql = ` DELETE FROM cygx_resource_data_industrial_group_subject WHERE source_id = ? AND source =? `
  118. _, err = to.Raw(sql, sourceId, source).Exec()
  119. if err != nil {
  120. return
  121. }
  122. return
  123. }