industrial_article_group_management.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. // IndustryArticleMinMaxPublishTime 产业文章最大最小发布时间
  15. type IndustryArticleMinMaxPublishTime struct {
  16. IndustrialManagementId int `description:"产业ID"`
  17. MinPublishTime time.Time `description:"文章最小发布时间"`
  18. MaxPublishTime time.Time `description:"文章最大发布时间"`
  19. }
  20. // GetIndustryArticleMinMaxPublishTime 获取产业文章最大最小发布时间
  21. func GetIndustryArticleMinMaxPublishTime(condition string, pars []interface{}) (list []*IndustryArticleMinMaxPublishTime, err error) {
  22. sql := `SELECT
  23. a.industrial_management_id,
  24. MIN(b.publish_date) AS min_publish_time,
  25. MAX(b.publish_date) AS max_publish_time
  26. FROM
  27. cygx_industrial_article_group_management AS a
  28. JOIN cygx_article AS b ON a.article_id = b.article_id
  29. WHERE
  30. 1 = 1`
  31. if condition != `` {
  32. sql += condition
  33. }
  34. sql += `GROUP BY a.industrial_management_id`
  35. _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
  36. return
  37. }
  38. // GetIndustrialArticleGroupManagementList 查询产业
  39. func GetIndustrialArticleGroupManagementList(condition string, pars []interface{}) (list []*CygxIndustrialArticleGroupManagement, err error) {
  40. sql := `SELECT
  41. *
  42. FROM
  43. cygx_industrial_article_group_management AS a
  44. WHERE
  45. 1 = 1 `
  46. if condition != `` {
  47. sql += condition
  48. }
  49. _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
  50. return
  51. }
  52. type IndustrialDepartmentListResp struct {
  53. IndustrialManagementId int `description:"产业Id"`
  54. IndustryName string `description:"产业名称"`
  55. DepartmentId int `description:"作者Id"`
  56. List []*IndustrialDepartmentListResp
  57. }
  58. // 作者文章所关联的产业列表
  59. func GetIndustrialDepartmentList() (items []*IndustrialDepartmentListResp, err error) {
  60. o := orm.NewOrm()
  61. sql := `SELECT
  62. m.industrial_management_id,
  63. m.industry_name,
  64. d.department_id
  65. FROM
  66. cygx_article_department AS d
  67. INNER JOIN cygx_article AS a ON d.department_id = a.department_id
  68. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
  69. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
  70. WHERE
  71. 1 = 1
  72. AND a.article_type_id > 0
  73. AND publish_status = 1
  74. GROUP BY
  75. a.article_id
  76. ORDER BY
  77. a.publish_date DESC`
  78. _, err = o.Raw(sql).QueryRows(&items)
  79. return
  80. }
  81. type CygxIndustrialArticleGroupManagementResp struct {
  82. ArticleId int `description:"文章ID"`
  83. IndustrialManagementId int `description:"cygx_industrial_management表的主键ID"`
  84. PublishDate time.Time `description:"发布时间"`
  85. }
  86. // GetCygxIndustrialArticleGroupManagement 获取产业关联的所有文章
  87. func GetCygxIndustrialArticleGroupManagement(condition string, pars []interface{}) (list []*CygxIndustrialArticleGroupManagementResp, err error) {
  88. sql := `SELECT
  89. mg.industrial_management_id,
  90. a.article_id,
  91. a.publish_date
  92. FROM
  93. cygx_industrial_article_group_management AS mg
  94. INNER JOIN cygx_article AS a ON a.article_id = mg.article_id
  95. WHERE
  96. 1 = 1
  97. AND a.publish_status = 1 `
  98. if condition != `` {
  99. sql += condition
  100. }
  101. _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
  102. return
  103. }