industrial_activity_group_subject.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hz_crm_api/utils"
  5. "time"
  6. )
  7. type CygxIndustrialActivityGroupSubject struct {
  8. Id int `orm:"column(id);pk" description:"主键ID"`
  9. ActivityId int `description:"活动ID"`
  10. IndustrialSubjectId int `description:"cygx_industrial_subject表的文章ID"`
  11. Source int `description:"来源,1 活动,2专项调研"`
  12. CreateTime time.Time `description:"创建时间"`
  13. }
  14. type SubjectActivityGroupManagementRep struct {
  15. IndustrialSubjectId int `description:"产业id"`
  16. SubjectName string `description:"标的名称"`
  17. ActivityId int `description:"活动ID"`
  18. }
  19. // 列表
  20. func GetSubjectActivityGroupManagementList(activityId, source int) (items []*SubjectActivityGroupManagementRep, err error) {
  21. o := orm.NewOrmUsingDB("hz_cygx")
  22. sql := `SELECT
  23. s.subject_name,
  24. s.industrial_subject_id
  25. FROM
  26. cygx_industrial_activity_group_subject AS ag
  27. INNER JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = ag.industrial_subject_id
  28. WHERE
  29. ag.activity_id = ? AND ag.source = ?`
  30. _, err = o.Raw(sql, activityId, source).QueryRows(&items)
  31. return
  32. }
  33. // 列表
  34. func GetSubjectActivityGroupManagementListByActivityIdsArr(activityIds []int, source int) (items []*SubjectActivityGroupManagementRep, err error) {
  35. lenArr := len(activityIds)
  36. if lenArr == 0 {
  37. return
  38. }
  39. o := orm.NewOrmUsingDB("hz_cygx")
  40. sql := `SELECT
  41. ag.activity_id,
  42. s.subject_name,
  43. s.industrial_subject_id
  44. FROM
  45. cygx_industrial_activity_group_subject AS ag
  46. INNER JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = ag.industrial_subject_id
  47. WHERE
  48. ag.activity_id IN (` + utils.GetOrmInReplace(lenArr) + `) AND ag.source = ?`
  49. _, err = o.Raw(sql, activityIds, source).QueryRows(&items)
  50. return
  51. }
  52. // 列表
  53. func GetSubjectActivityGroupManagementListBySubjectId(subjectId, source int) (items []*SubjectActivityGroupManagementRep, err error) {
  54. o := orm.NewOrmUsingDB("hz_cygx")
  55. sql := `SELECT
  56. ag.activity_id,
  57. s.subject_name,
  58. s.industrial_subject_id
  59. FROM
  60. cygx_industrial_activity_group_subject AS ag
  61. INNER JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = ag.industrial_subject_id
  62. WHERE
  63. ag.industrial_subject_id = ? AND ag.source = ?`
  64. _, err = o.Raw(sql, subjectId, source).QueryRows(&items)
  65. return
  66. }
  67. // 列表
  68. func GetSubjectActivityGroupManagementListBySubjectIds(subjectIds []int, source int) (items []*SubjectActivityGroupManagementRep, err error) {
  69. lenArr := len(subjectIds)
  70. if lenArr == 0 {
  71. return
  72. }
  73. o := orm.NewOrmUsingDB("hz_cygx")
  74. sql := `SELECT
  75. ag.activity_id,
  76. s.subject_name,
  77. s.industrial_subject_id
  78. FROM
  79. cygx_industrial_activity_group_subject AS ag
  80. INNER JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = ag.industrial_subject_id
  81. WHERE
  82. ag.industrial_subject_id IN (` + utils.GetOrmInReplace(lenArr) + `) AND ag.source = ?`
  83. _, err = o.Raw(sql, subjectIds, source).QueryRows(&items)
  84. return
  85. }
  86. func GetActivityIdsByIndustrialSubjectId(industrialSubjectId string) (activityId string, err error) {
  87. sql := ` SELECT
  88. GROUP_CONCAT( DISTINCT activity_id ORDER BY id ASC SEPARATOR ',' ) AS activity_id
  89. FROM
  90. cygx_industrial_activity_group_subject WHERE industrial_subject_id IN (` + industrialSubjectId + `)`
  91. o := orm.NewOrmUsingDB("hz_cygx")
  92. err = o.Raw(sql).QueryRow(&activityId)
  93. return
  94. }
  95. type SubjectlActivityGroupResp struct {
  96. ActivityId int `description:"活动ID"`
  97. IndustrialManagementId int `description:"cygx_industrial_management表的主键ID"`
  98. IndustrialSubjectId int `description:"标的id"`
  99. SubjectName string `description:"标的名称"`
  100. }
  101. // 列表
  102. func GetSubjectActivityGroupListByactivityIds(activityIds string) (items []*SubjectlActivityGroupResp, err error) {
  103. o := orm.NewOrmUsingDB("hz_cygx")
  104. sql := `SELECT
  105. sg.*,
  106. s.subject_name,
  107. s.industrial_management_id
  108. FROM
  109. cygx_industrial_activity_group_subject AS sg
  110. INNER JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = sg.industrial_subject_id
  111. WHERE
  112. 1 = 1
  113. AND sg.activity_id IN (` + activityIds + `) GROUP BY sg.activity_id,sg.industrial_subject_id`
  114. _, err = o.Raw(sql).QueryRows(&items)
  115. return
  116. }
  117. type IndustrySubjectActCountGroupByType struct {
  118. ActivityType string `json:"activity_type" description:"活动类型名称"`
  119. ActivityCount int `json:"activity_count" description:"关联的活动数"`
  120. }
  121. // GetIndustrySubjectActCountGroupByType 获取标的关联的活动数-根据活动类型分组
  122. func GetIndustrySubjectActCountGroupByType(subjectId int) (list []*IndustrySubjectActCountGroupByType, err error) {
  123. sqlCount := `SELECT
  124. COUNT(1) AS activity_count,
  125. CASE
  126. WHEN a.chart_permission_id = 31 THEN
  127. "研选活动"
  128. ELSE
  129. "弘则活动"
  130. END AS activity_type
  131. FROM
  132. cygx_industrial_activity_group_subject AS gsub
  133. INNER JOIN cygx_activity AS a ON a.activity_id = gsub.activity_id
  134. INNER JOIN cygx_industrial_subject AS sub ON sub.industrial_subject_id = gsub.industrial_subject_id
  135. WHERE
  136. gsub.industrial_subject_id = ? AND a.publish_status = 1
  137. GROUP BY
  138. activity_type`
  139. o := orm.NewOrmUsingDB("hz_cygx")
  140. _, err = o.Raw(sqlCount, subjectId).QueryRows(&list)
  141. return
  142. }