resource_data_industrial_group_management.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package cygx
  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 AddCygxResourceDataGroup(sourceId int, source string, industrialItems []*CygxResourceDataIndustrialGroupManagement, subjectItems []*CygxResourceDataIndustrialGroupSubject) (err error) {
  26. o := orm.NewOrmUsingDB("hz_cygx")
  27. to, err := o.Begin()
  28. if err != nil {
  29. return
  30. }
  31. defer func() {
  32. if err != nil {
  33. _ = to.Rollback()
  34. } else {
  35. _ = to.Commit()
  36. }
  37. }()
  38. //删除关联产业
  39. sql := ` DELETE FROM cygx_resource_data_industrial_group_management WHERE source_id = ? AND source =? `
  40. _, err = to.Raw(sql, sourceId, source).Exec()
  41. if err != nil {
  42. return
  43. }
  44. //删除关联标的
  45. sql = ` DELETE FROM cygx_resource_data_industrial_group_subject WHERE source_id = ? AND source =? `
  46. _, err = to.Raw(sql, sourceId, source).Exec()
  47. if err != nil {
  48. return
  49. }
  50. //批量插入关联产业
  51. if len(industrialItems) > 0 {
  52. _, err = to.InsertMulti(len(industrialItems), industrialItems)
  53. if err != nil {
  54. return
  55. }
  56. }
  57. //批量插入关联标的
  58. if len(subjectItems) > 0 {
  59. _, err = to.InsertMulti(len(subjectItems), subjectItems)
  60. if err != nil {
  61. return
  62. }
  63. }
  64. return
  65. }
  66. // 删除
  67. func DeleteCygxResourceDataGroup(sourceId int, source string) (err error) {
  68. o := orm.NewOrmUsingDB("hz_cygx")
  69. to, err := o.Begin()
  70. if err != nil {
  71. return
  72. }
  73. defer func() {
  74. if err != nil {
  75. _ = to.Rollback()
  76. } else {
  77. _ = to.Commit()
  78. }
  79. }()
  80. //删除关联产业
  81. sql := ` DELETE FROM cygx_resource_data_industrial_group_management WHERE source_id = ? AND source =? `
  82. _, err = to.Raw(sql, sourceId, source).Exec()
  83. if err != nil {
  84. return
  85. }
  86. //删除关联标的
  87. sql = ` DELETE FROM cygx_resource_data_industrial_group_subject WHERE source_id = ? AND source =? `
  88. _, err = to.Raw(sql, sourceId, source).Exec()
  89. if err != nil {
  90. return
  91. }
  92. return
  93. }