industrial_article_group_management.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxIndustrialArticleGroupManagement struct {
  7. Id int `orm:"column(id);pk" description:"主键ID"`
  8. CygxArticleId int `description:"cygx_article表id"`
  9. ArticleId int `description:"文章ID"`
  10. IndustrialManagementId int `description:"cygx_industrial_management表的主键ID"`
  11. Source int `description:"来源,1 活动,2专项调研"`
  12. CreateTime time.Time `description:"创建时间"`
  13. }
  14. // IndustryArtCount 产业文章数
  15. type IndustryArtCount struct {
  16. ArtNum int `json:"art_num" description:"文章数"`
  17. IndustrialManagementId int `json:"industrial_management_id" description:"产业ID"`
  18. }
  19. // GetIndustryArtCountByCondition 获取产业文章关联的文章数
  20. func GetIndustryArtCountByCondition(condition string, pars []interface{}) (list []*IndustryArtCount, err error) {
  21. sql := `SELECT
  22. COUNT(1) AS art_num,
  23. agm.industrial_management_id
  24. FROM
  25. cygx_industrial_article_group_management AS agm
  26. JOIN cygx_industrial_management AS man ON man.industrial_management_id = agm.industrial_management_id
  27. WHERE
  28. 1 = 1 `
  29. if condition != "" {
  30. sql += condition
  31. }
  32. sql += ` GROUP BY agm.industrial_management_id`
  33. _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
  34. return
  35. }
  36. // IndustryArticleMinMaxPublishTime 产业文章最大最小发布时间
  37. type IndustryArticleMinMaxPublishTime struct {
  38. IndustrialManagementId int `description:"产业ID"`
  39. MinPublishTime time.Time `description:"文章最小发布时间"`
  40. MaxPublishTime time.Time `description:"文章最大发布时间"`
  41. }
  42. // GetIndustryArticleMinMaxPublishTime 获取产业文章最大最小发布时间
  43. func GetIndustryArticleMinMaxPublishTime(condition string, pars []interface{}) (list []*IndustryArticleMinMaxPublishTime, err error) {
  44. sql := `SELECT
  45. a.industrial_management_id,
  46. MIN(b.publish_date) AS min_publish_time,
  47. MAX(b.publish_date) AS max_publish_time
  48. FROM
  49. cygx_industrial_article_group_management AS a
  50. JOIN cygx_article AS b ON a.article_id = b.article_id
  51. WHERE
  52. 1 = 1`
  53. if condition != `` {
  54. sql += condition
  55. }
  56. sql += `GROUP BY a.industrial_management_id`
  57. _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
  58. return
  59. }
  60. // GetIndustrialArticleGroupManagementList 查询产业
  61. func GetIndustrialArticleGroupManagementList(condition string, pars []interface{}) (list []*CygxIndustrialArticleGroupManagement, err error) {
  62. sql := `SELECT
  63. *
  64. FROM
  65. cygx_industrial_article_group_management AS a
  66. WHERE
  67. 1 = 1 `
  68. if condition != `` {
  69. sql += condition
  70. }
  71. _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
  72. return
  73. }
  74. // 列表
  75. func GetIndustrialArticleGroupManagementListByArticleId(articleId int) (items []*CygxIndustrialArticleGroupManagement, err error) {
  76. o := orm.NewOrm()
  77. sql := `SELECT
  78. m.chart_permission_id,
  79. m.industrial_management_id,
  80. m.industry_name
  81. FROM
  82. cygx_industrial_article_group_management AS am
  83. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = am.industrial_management_id
  84. WHERE
  85. am.article_id = ?`
  86. _, err = o.Raw(sql, articleId).QueryRows(&items)
  87. return
  88. }