industrial_activity_group_management.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxIndustrialActivityGroupManagement struct {
  7. Id int `orm:"column(id);pk" description:"主键ID"`
  8. ActivityId int `description:"活动ID"`
  9. IndustrialManagementId int `description:"cygx_industrial_management表的主键ID"`
  10. Source int `description:"来源,1 活动,2专项调研"`
  11. CreateTime time.Time `description:"创建时间"`
  12. }
  13. // 获取标的列表
  14. func GetCygxIndustrialSubjectList(subjectName string) (items []*CygxIndustrialSubject, err error) {
  15. o := orm.NewOrm()
  16. sql := `SELECT
  17. s.*
  18. FROM
  19. cygx_industrial_subject as s
  20. INNER JOIN cygx_industrial_management as m ON m.industrial_management_id = s.industrial_management_id
  21. WHERE
  22. subject_name = ? `
  23. _, err = o.Raw(sql, subjectName).QueryRows(&items)
  24. return
  25. }
  26. // AddCygxActiuvityGroupMulti 批量添加
  27. func AddCygxActiuvityGroupMulti(items []*CygxIndustrialActivityGroupManagement, itemsSubject []*CygxIndustrialActivityGroupSubject) (err error) {
  28. o, err := orm.NewOrm().Begin()
  29. if err != nil {
  30. return
  31. }
  32. defer func() {
  33. if err == nil {
  34. o.Commit()
  35. } else {
  36. o.Rollback()
  37. }
  38. }()
  39. if len(items) > 0 {
  40. //批量添加关联的产业
  41. _, err = o.InsertMulti(len(items), items)
  42. }
  43. if len(itemsSubject) > 0 {
  44. //批量添加关联的标的
  45. _, err = o.InsertMulti(len(itemsSubject), itemsSubject)
  46. }
  47. return
  48. }
  49. // GetActivityIndustryRelationList 获取活动与产业关联列表
  50. func GetActivityIndustryRelationList(condition string, pars []interface{}) (list []*CygxIndustrialActivityGroupManagement, err error) {
  51. sql := `SELECT
  52. a.activity_id,
  53. b.industrial_management_id
  54. FROM
  55. cygx_activity AS a
  56. JOIN cygx_industrial_activity_group_management AS b ON a.activity_id = b.activity_id
  57. WHERE
  58. 1 = 1 AND b.source = 1 `
  59. if condition != `` {
  60. sql += condition
  61. }
  62. _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
  63. return
  64. }
  65. // 获取数量
  66. func GetCygxIndustrialActivityGroupManagementCount(condition string, pars []interface{}) (count int, err error) {
  67. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_industrial_activity_group_management as art WHERE 1= 1 `
  68. if condition != "" {
  69. sqlCount += condition
  70. }
  71. o := orm.NewOrm()
  72. err = o.Raw(sqlCount, pars).QueryRow(&count)
  73. return
  74. }
  75. // CygxIndustrialActivityGroupManagement 获取活动与产业关联列表
  76. func GetCygxIndustrialActivityGroupManagementList(condition string, pars []interface{}) (list []*CygxIndustrialActivityGroupManagement, err error) {
  77. sql := `SELECT
  78. *
  79. FROM
  80. cygx_industrial_activity_group_management
  81. WHERE
  82. 1 = 1 `
  83. if condition != `` {
  84. sql += condition
  85. }
  86. _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
  87. return
  88. }
  89. // 列表
  90. func GetIndustrialActivityGroupManagementListByArticleId(activityId int) (items []*IndustrialActivityGroupManagementRep, err error) {
  91. o := orm.NewOrm()
  92. sql := `SELECT
  93. m.industry_name
  94. FROM
  95. cygx_industrial_management AS m
  96. INNER JOIN cygx_industrial_activity_group_management AS am ON m.industrial_management_id = am.industrial_management_id
  97. WHERE
  98. am.activity_id = ? AND m.source = 1 `
  99. _, err = o.Raw(sql, activityId).QueryRows(&items)
  100. return
  101. }