report_push_status.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package models
  2. import (
  3. "eta/eta_mini_crm/utils"
  4. "time"
  5. "github.com/beego/beego/v2/client/orm"
  6. )
  7. type ReportPushStatus struct {
  8. ReportPushStatusId int `orm:"pk"`
  9. ReportId int `description:"报告id"`
  10. State int `description:"报告状态:0-未推送,1-已推送"`
  11. Title string `description:"报告标题"`
  12. Abstract string `description:"报告摘要"`
  13. Stage int `description:"期数"`
  14. ClassifyIdFirst int `description:"一级分类id"`
  15. ClassifyNameFirst string `description:"一级分类名称"`
  16. ClassifyIdSecond int `description:"二级分类id"`
  17. ClassifyNameSecond string `description:"二级分类名称"`
  18. ClassifyIdThird int `description:"三级分类id"`
  19. ClassifyNameThird string `description:"三级分类名称"`
  20. Author string `description:"报告作者"`
  21. ReportType int `description:"报告类型:1-eta报告"`
  22. PublishTime time.Time `description:"报告发布时间"`
  23. CreateTime time.Time `description:"创建时间"`
  24. ModifyTime time.Time `description:"修改时间"`
  25. PushTime time.Time `description:"推送时间"`
  26. }
  27. type Report struct {
  28. Id int `description:"报告id"` // id
  29. ClassifyIdFirst int `description:"一级分类id"` // 一级分类id
  30. ClassifyNameFirst string `description:"一级分类名称"` // 一级分类名称
  31. ClassifyIdSecond int `description:"二级分类id"` // 二级分类id
  32. ClassifyNameSecond string `description:"二级分类名称"` // 二级分类名称
  33. ClassifyIdThird int `description:"三级分类id"` // 三级分类id
  34. ClassifyNameThird string `description:"三级分类名称"` // 三级分类名称
  35. Title string `description:"报告标题"` // 标题
  36. Abstract string `description:"摘要"` // 摘要
  37. Author string `description:"作者"` // 作者
  38. CreateTime time.Time `description:"创建时间"` // 创建时间
  39. ModifyTime time.Time `description:"修改时间"` // 修改时间
  40. PublishTime time.Time `description:"发布时间"` // 发布时间
  41. Stage int `description:"期数"` // 期数
  42. ContentModifyTime time.Time `description:"内容更新时间"` // 内容更新时间
  43. ReportCreateTime time.Time `description:"创建时间"` // 报告时间创建时间
  44. }
  45. type ReportPushView struct {
  46. ReportPushStatusId int `orm:"pk"`
  47. ReportId int `description:"报告id"`
  48. Title string `description:"报告标题"`
  49. Abstract string `description:"报告摘要"`
  50. ClassifyIdFirst int `description:"一级分类id"`
  51. ClassifyNameFirst string `description:"一级分类名称"`
  52. ClassifyIdSecond int `description:"二级分类id"`
  53. ClassifyNameSecond string `description:"二级分类名称"`
  54. ClassifyIdThird int `description:"二级分类id"`
  55. ClassifyNameThird string `description:"二级分类名称"`
  56. Author string `description:"报告作者"`
  57. State int `description:"报告状态:0-未推送,1-已推送"`
  58. PushTime string `description:"推送时间"`
  59. PublishTime string `description:"报告发布时间"`
  60. ReportType int `description:"报告类型:1-eta报告"`
  61. CreateTime string `description:"创建时间"`
  62. ModifyTime string `description:"修改时间"`
  63. }
  64. func (r *ReportPushStatus) Insert() (insertId int64, err error) {
  65. o := orm.NewOrm()
  66. insertId, err = o.Insert(r)
  67. return
  68. }
  69. func (r *ReportPushStatus) MultiInsert(items []*ReportPushStatus) (err error) {
  70. o := orm.NewOrm()
  71. _, err = o.InsertMulti(500, items)
  72. return
  73. }
  74. func (r *ReportPushStatus) Update(cols []string) (err error) {
  75. o := orm.NewOrm()
  76. _, err = o.Update(r, cols...)
  77. return
  78. }
  79. func GetReportPushStatusByReportId(reportId, state int) (item *ReportPushStatus, err error) {
  80. o := orm.NewOrm()
  81. sql := `SELECT * FROM report_push_status WHERE report_id=? AND state=?`
  82. err = o.Raw(sql, reportId, state).QueryRow(&item)
  83. return
  84. }
  85. func GetReportPushStatusByReportIdAndState(reportId []int, state int) (items []*ReportPushStatus, err error) {
  86. if len(reportId) == 0 {
  87. return
  88. }
  89. o := orm.NewOrm()
  90. sql := `SELECT * FROM report_push_status WHERE report_id IN (` + utils.GetOrmReplaceHolder(len(reportId)) + `) AND state=?`
  91. _, err = o.Raw(sql, reportId, state).QueryRows(&items)
  92. return
  93. }
  94. func GetReportPushStatusByReportIds(reportId []int) (items []*ReportPushStatus, err error) {
  95. if len(reportId) == 0 {
  96. return
  97. }
  98. o := orm.NewOrm()
  99. sql := `SELECT * FROM report_push_status WHERE report_id IN (` + utils.GetOrmReplaceHolder(len(reportId)) + `) `
  100. _, err = o.Raw(sql, reportId).QueryRows(&items)
  101. return
  102. }
  103. func GetReportPushStatusListByCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportPushView, err error) {
  104. o := orm.NewOrm()
  105. sql := `SELECT * FROM report_push_status WHERE 1=1 `
  106. if condition != "" {
  107. sql += condition
  108. }
  109. sql += ` LIMIT ?,? `
  110. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  111. return
  112. }
  113. func GetReportByCondition(condition string) (items []*Report, err error) {
  114. o := orm.NewOrmUsingDB("rddp")
  115. sql := `SELECT * FROM report WHERE 1=1 AND (state=2 OR state=6) `
  116. if condition != "" {
  117. sql += condition
  118. }
  119. _, err = o.Raw(sql).QueryRows(&items)
  120. return
  121. }
  122. func GetReportIdListByCondition(condition string, pars []interface{}) (reportId []int, err error) {
  123. o := orm.NewOrm()
  124. sql := `SELECT report_id FROM report_push_status WHERE 1=1 `
  125. if condition != "" {
  126. sql += condition
  127. }
  128. _, err = o.Raw(sql, pars).QueryRows(&reportId)
  129. return
  130. }
  131. func GetReportCountById(id int) (count int, err error) {
  132. o := orm.NewOrmUsingDB("rddp")
  133. sql := `SELECT COUNT(*) AS count FROM report WHERE (state=2 OR state=6) AND id=?`
  134. err = o.Raw(sql, id).QueryRow(&count)
  135. return
  136. }
  137. func GetReportCountByCondition(condition string, pars []interface{}) (count int, err error) {
  138. o := orm.NewOrm()
  139. sql := `SELECT COUNT(*) AS count FROM report_push_status WHERE 1=1 `
  140. if condition != "" {
  141. sql += condition
  142. }
  143. err = o.Raw(sql, pars).QueryRow(&count)
  144. return
  145. }
  146. // BatchPushReport 批量推送报告
  147. func BatchPushReport(reportId []int) (err error) {
  148. o := orm.NewOrm()
  149. sql := `UPDATE report_push_status SET state=1, push_time=NOW() WHERE report_id IN (` + utils.GetOrmReplaceHolder(len(reportId)) + `)`
  150. _, err = o.Raw(sql, reportId).Exec()
  151. return
  152. }
  153. // BatchPushCancelReport 批量撤销推送报告
  154. func BatchPushCancelReport(reportId []int) (err error) {
  155. o := orm.NewOrm()
  156. sql := `UPDATE report_push_status SET state=0, modify_time=NOW() WHERE report_id IN (` + utils.GetOrmReplaceHolder(len(reportId)) + `)`
  157. _, err = o.Raw(sql, reportId).Exec()
  158. return
  159. }
  160. // BatchAddReportPushStatus 批量添加报告
  161. func BatchAddReportPushStatus(items []*ReportPushStatus) (err error) {
  162. if len(items) == 0 {
  163. return
  164. }
  165. o := orm.NewOrm()
  166. _, err = o.InsertMulti(100, items)
  167. return
  168. }
  169. func GetMaxSyncIdReportPush(report_type int) (count int, err error) {
  170. o := orm.NewOrm()
  171. sql := `SELECT MAX(report_id) AS max_id FROM report_push_status WHERE report_type=?`
  172. err = o.Raw(sql, report_type).QueryRow(&count)
  173. return
  174. }
  175. func GetBatchReport(maxId, batchSize int) (items []*Report, err error) {
  176. o := orm.NewOrmUsingDB("rddp")
  177. sql := `SELECT * FROM report WHERE id>? AND (state=2 OR state=6) LIMIT ?`
  178. o.Raw(sql, maxId, batchSize).QueryRows(&items)
  179. return
  180. }