industrial_article_group_subject.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hz_crm_api/utils"
  5. "time"
  6. )
  7. type CygxIndustrialArticleGroupSubject struct {
  8. Id int `orm:"column(id);pk" description:"主键ID"`
  9. CygxArticleId int `description:"cygx_article表的主键ID"`
  10. ArticleId int `description:"cygx_article表的文章ID"`
  11. IndustrialSubjectId int `description:"cygx_industrial_subject表的文章ID"`
  12. CreateTime time.Time `description:"创建时间"`
  13. }
  14. // 新增
  15. func AddCygxIndustrialArticleGroupSubject(item *CygxIndustrialArticleGroupSubject) (newId int64, err error) {
  16. o := orm.NewOrmUsingDB("hz_cygx")
  17. _, err = o.Insert(item)
  18. if err != nil {
  19. return
  20. }
  21. return
  22. }
  23. func GetSubjectIds(articleId int) (subjects string, err error) {
  24. sql := ` SELECT
  25. GROUP_CONCAT( DISTINCT industrial_subject_id ORDER BY id ASC SEPARATOR ',' ) AS subjects
  26. FROM
  27. cygx_industrial_article_group_subject WHERE article_id = ?`
  28. o := orm.NewOrmUsingDB("hz_cygx")
  29. err = o.Raw(sql, articleId).QueryRow(&subjects)
  30. return
  31. }
  32. func GetArticleIdsBySubjectId(industrialSubjectId string) (articleId string, err error) {
  33. sql := ` SELECT
  34. GROUP_CONCAT( DISTINCT article_id ORDER BY id ASC SEPARATOR ',' ) AS articleId
  35. FROM
  36. cygx_industrial_article_group_subject WHERE industrial_subject_id IN (` + industrialSubjectId + `)`
  37. o := orm.NewOrmUsingDB("hz_cygx")
  38. err = o.Raw(sql).QueryRow(&articleId)
  39. return
  40. }
  41. // 列表
  42. func GetSubjectArticleGroupManagementList(articleId int) (items []*SubjectActivityGroupManagementRep, err error) {
  43. o := orm.NewOrmUsingDB("hz_cygx")
  44. sql := `SELECT
  45. s.subject_name,
  46. s.industrial_subject_id
  47. FROM
  48. cygx_industrial_article_group_subject AS ag
  49. INNER JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = ag.industrial_subject_id
  50. WHERE
  51. ag.article_id = ?`
  52. _, err = o.Raw(sql, articleId).QueryRows(&items)
  53. return
  54. }
  55. type SubjectArticleGroupManagementRep struct {
  56. IndustrialSubjectId int `description:"产业id"`
  57. SubjectName string `description:"标的名称"`
  58. ArticleId int `description:"cygx_article表的文章ID"`
  59. }
  60. // 列表
  61. func GetSubjectArticleGroupManagementListBysubjectId(subjectId int) (items []*SubjectArticleGroupManagementRep, err error) {
  62. o := orm.NewOrmUsingDB("hz_cygx")
  63. sql := `SELECT
  64. ag.article_id
  65. FROM
  66. cygx_industrial_article_group_subject AS ag
  67. INNER JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = ag.industrial_subject_id
  68. WHERE
  69. ag.industrial_subject_id = ?`
  70. _, err = o.Raw(sql, subjectId).QueryRows(&items)
  71. return
  72. }
  73. // 列表
  74. func GetSubjectArticleGroupManagementListBysubjectIds(subjectIds []int) (items []*SubjectArticleGroupManagementRep, err error) {
  75. lenArr := len(subjectIds)
  76. if lenArr == 0 {
  77. return
  78. }
  79. o := orm.NewOrmUsingDB("hz_cygx")
  80. sql := `SELECT
  81. ag.article_id
  82. FROM
  83. cygx_industrial_article_group_subject AS ag
  84. INNER JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = ag.industrial_subject_id
  85. WHERE
  86. ag.industrial_subject_id IN (` + utils.GetOrmInReplace(lenArr) + `)`
  87. _, err = o.Raw(sql, subjectIds).QueryRows(&items)
  88. return
  89. }
  90. type SubjectlArticleGroupResp struct {
  91. ArticleId int `description:"文章ID"`
  92. IndustrialManagementId int `description:"cygx_industrial_management表的主键ID"`
  93. IndustrialSubjectId int `description:"标的id"`
  94. SubjectName string `description:"标的名称"`
  95. }
  96. // 列表
  97. func GetSubjectArticleGroupListByarticleIds(articleIds string) (items []*SubjectlArticleGroupResp, err error) {
  98. o := orm.NewOrmUsingDB("hz_cygx")
  99. sql := `SELECT
  100. sg.*,
  101. s.subject_name,
  102. s.industrial_management_id
  103. FROM
  104. cygx_industrial_article_group_subject AS sg
  105. INNER JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = sg.industrial_subject_id
  106. WHERE
  107. 1 = 1
  108. AND sg.article_id IN (` + articleIds + `) GROUP BY sg.article_id,sg.industrial_subject_id`
  109. _, err = o.Raw(sql).QueryRows(&items)
  110. return
  111. }
  112. // 列表
  113. func GetSubjectArticleGroupListByarticleIdsArr(articleIds []int) (items []*SubjectlArticleGroupResp, err error) {
  114. lenArr := len(articleIds)
  115. if lenArr == 0 {
  116. return
  117. }
  118. o := orm.NewOrmUsingDB("hz_cygx")
  119. sql := `SELECT
  120. sg.*,
  121. s.subject_name,
  122. s.industrial_management_id
  123. FROM
  124. cygx_industrial_article_group_subject AS sg
  125. INNER JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = sg.industrial_subject_id
  126. WHERE
  127. 1 = 1
  128. AND sg.article_id IN (` + utils.GetOrmInReplace(lenArr) + `) GROUP BY sg.article_id,sg.industrial_subject_id`
  129. _, err = o.Raw(sql, articleIds).QueryRows(&items)
  130. return
  131. }