industrial_activity_group_management.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hz_crm_api/utils"
  5. "time"
  6. )
  7. type CygxIndustrialActivityGroupManagement struct {
  8. Id int `orm:"column(id);pk" description:"主键ID"`
  9. ActivityId int `description:"活动ID"`
  10. IndustrialManagementId int `description:"cygx_industrial_management表的主键ID"`
  11. Source int `description:"来源,1 活动,2专项调研"`
  12. CreateTime time.Time `description:"创建时间"`
  13. }
  14. type IndustrialActivityGroupManagementRep struct {
  15. IndustrialManagementId int `description:"cygx_industrial_management表的主键ID"`
  16. IndustryName string `description:"产业名称"`
  17. ChartPermissionId int `description:"权限id"`
  18. PermissionName string `description:"行业名称"`
  19. ActivityId int `description:"活动ID"`
  20. }
  21. type IndustryAndSubjectName struct {
  22. IndustryNames string `description:"产业名称"`
  23. SubjectNames string `description:"标的名称"`
  24. TemporaryLabel string `description:"临时标签"`
  25. }
  26. // 列表
  27. func GetIndustrialActivityGroupManagementList(activityId, source int) (items []*IndustrialActivityGroupManagementRep, err error) {
  28. o := orm.NewOrmUsingDB("hz_cygx")
  29. sql := `SELECT
  30. m.chart_permission_id,
  31. m.industrial_management_id,
  32. m.industry_name
  33. FROM
  34. cygx_industrial_activity_group_management AS am
  35. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = am.industrial_management_id
  36. WHERE
  37. am.activity_id = ? AND am.source = ?`
  38. _, err = o.Raw(sql, activityId, source).QueryRows(&items)
  39. return
  40. }
  41. // 根据产业ID获取关联的对应活动
  42. func GetIndustrialActivityGroupManagementListByIndustriaId(industrialId, source int) (items []*IndustrialActivityGroupManagementRep, err error) {
  43. o := orm.NewOrmUsingDB("hz_cygx")
  44. sql := `SELECT
  45. am.activity_id
  46. FROM
  47. cygx_industrial_activity_group_management AS am
  48. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = am.industrial_management_id
  49. WHERE
  50. am.industrial_management_id = ? AND am.source = ?`
  51. _, err = o.Raw(sql, industrialId, source).QueryRows(&items)
  52. return
  53. }
  54. // 获取产业关联的活动数量
  55. func GetIndustrialManagementGroupActCount(industrialManagementId int) (count int, err error) {
  56. sqlCount := `SELECT
  57. COUNT( 1 ) AS count
  58. FROM
  59. cygx_industrial_activity_group_management AS am
  60. INNER JOIN cygx_activity AS a ON a.activity_id = am.activity_id
  61. INNER JOIN cygx_industrial_management as m ON m.industrial_management_id = am.industrial_management_id
  62. WHERE
  63. am.industrial_management_id =?
  64. AND a.publish_status = 1 `
  65. o := orm.NewOrmUsingDB("hz_cygx")
  66. err = o.Raw(sqlCount, industrialManagementId).QueryRow(&count)
  67. return
  68. }
  69. func GetActivityIdsByIndustrialManagementId(industrialManagementId string) (activityId string, err error) {
  70. sql := ` SELECT
  71. GROUP_CONCAT( DISTINCT activity_id ORDER BY id ASC SEPARATOR ',' ) AS activityId
  72. FROM
  73. cygx_industrial_activity_group_management WHERE industrial_management_id IN (` + industrialManagementId + `)`
  74. o := orm.NewOrmUsingDB("hz_cygx")
  75. err = o.Raw(sql).QueryRow(&activityId)
  76. return
  77. }
  78. type IndustrialActivityGroupResp struct {
  79. ActivityId int `description:"活动ID"`
  80. IndustrialManagementId int `description:"cygx_industrial_management表的主键ID"`
  81. IndustryName string `description:"产业名称"`
  82. }
  83. // 列表
  84. func GetIndustrialActivityGroupListByactivityIds(activityIds string) (items []*IndustrialActivityGroupResp, err error) {
  85. o := orm.NewOrmUsingDB("hz_cygx")
  86. sql := `SELECT mg.*,m.industry_name FROM
  87. cygx_industrial_activity_group_management AS mg
  88. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  89. WHERE 1 = 1
  90. AND mg.activity_id IN (` + activityIds + `) AND mg.source = 1 GROUP BY mg.activity_id,mg.industrial_management_id`
  91. _, err = o.Raw(sql).QueryRows(&items)
  92. return
  93. }
  94. // 列表
  95. func GetIndustrialActivityGroupListByactivityIdsArr(activityIds []int, source int) (items []*IndustrialActivityGroupResp, err error) {
  96. lenArr := len(activityIds)
  97. if lenArr == 0 {
  98. return
  99. }
  100. o := orm.NewOrmUsingDB("hz_cygx")
  101. sql := `SELECT mg.*,m.industry_name FROM
  102. cygx_industrial_activity_group_management AS mg
  103. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  104. WHERE 1 = 1
  105. AND mg.activity_id IN (` + utils.GetOrmInReplace(lenArr) + `) AND mg.source = ? GROUP BY mg.activity_id,mg.industrial_management_id`
  106. _, err = o.Raw(sql, activityIds, source).QueryRows(&items)
  107. return
  108. }
  109. type IndustryActCountGroupByType struct {
  110. ActivityType string `json:"activity_type" description:"活动类型名称"`
  111. ActivityCount int `json:"activity_count" description:"关联的活动数"`
  112. }
  113. // GetIndustryActCountGroupByType 获取产业关联的活动数-根据活动类型分组
  114. func GetIndustryActCountGroupByType(industryId int) (list []*IndustryActCountGroupByType, err error) {
  115. sqlCount := `SELECT
  116. COUNT(1) AS activity_count,
  117. CASE
  118. WHEN a.chart_permission_name LIKE "%研选%" THEN
  119. "研选活动"
  120. ELSE
  121. "弘则活动"
  122. END AS activity_type
  123. FROM
  124. cygx_industrial_activity_group_management AS am
  125. INNER JOIN cygx_activity AS a ON a.activity_id = am.activity_id
  126. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = am.industrial_management_id
  127. WHERE
  128. am.industrial_management_id = ? AND a.publish_status = 1
  129. GROUP BY
  130. activity_type `
  131. o := orm.NewOrmUsingDB("hz_cygx")
  132. _, err = o.Raw(sqlCount, industryId).QueryRows(&list)
  133. return
  134. }
  135. // 获取数量
  136. func GetCygxIndustrialActivityGroupManagementCount(condition string, pars []interface{}) (count int, err error) {
  137. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_industrial_activity_group_management as art WHERE 1= 1 `
  138. if condition != "" {
  139. sqlCount += condition
  140. }
  141. o := orm.NewOrmUsingDB("hz_cygx")
  142. err = o.Raw(sqlCount, pars).QueryRow(&count)
  143. return
  144. }
  145. // CygxIndustrialActivityGroupManagement 获取活动与产业关联列表
  146. func GetCygxIndustrialActivityGroupManagementList(condition string, pars []interface{}) (list []*CygxIndustrialActivityGroupManagement, err error) {
  147. o := orm.NewOrmUsingDB("hz_cygx")
  148. sql := `SELECT
  149. *
  150. FROM
  151. cygx_industrial_activity_group_management
  152. WHERE
  153. 1 = 1 `
  154. if condition != `` {
  155. sql += condition
  156. }
  157. _, err = o.Raw(sql, pars).QueryRows(&list)
  158. return
  159. }