report_push_status.go 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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报告 2-pdf报告"`
  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报告 2-pdf报告"`
  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(reportType int, 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_type=? AND report_id IN (` + utils.GetOrmReplaceHolder(len(reportId)) + `) `
  100. _, err = o.Raw(sql, reportType, reportId).QueryRows(&items)
  101. return
  102. }
  103. func GetReportPushStatusListByCondition(condition, sortCondition 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. if sortCondition != "" {
  110. sql += sortCondition
  111. }
  112. sql += ` LIMIT ?,? `
  113. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  114. return
  115. }
  116. func GetReportByCondition(condition string, pars []interface{}) (items []*Report, err error) {
  117. o := orm.NewOrmUsingDB("rddp")
  118. sql := `SELECT * FROM report WHERE 1=1 AND (state=2 OR state=6) `
  119. if condition != "" {
  120. sql += condition
  121. }
  122. _, err = o.Raw(sql, pars...).QueryRows(&items)
  123. return
  124. }
  125. func GetReportIdListByCondition(condition string, pars []interface{}) (reportId []int, err error) {
  126. o := orm.NewOrm()
  127. sql := `SELECT report_id FROM report_push_status WHERE 1=1 `
  128. if condition != "" {
  129. sql += condition
  130. }
  131. _, err = o.Raw(sql, pars).QueryRows(&reportId)
  132. return
  133. }
  134. func GetReportCountById(id int) (count int, err error) {
  135. o := orm.NewOrmUsingDB("rddp")
  136. sql := `SELECT COUNT(*) AS count FROM report WHERE (state=2 OR state=6) AND id=?`
  137. err = o.Raw(sql, id).QueryRow(&count)
  138. return
  139. }
  140. func GetReportCountByCondition(condition string, pars []interface{}) (count int, err error) {
  141. o := orm.NewOrm()
  142. sql := `SELECT COUNT(*) AS count FROM report_push_status WHERE 1=1 `
  143. if condition != "" {
  144. sql += condition
  145. }
  146. err = o.Raw(sql, pars).QueryRow(&count)
  147. return
  148. }
  149. // BatchPushReport 批量推送报告
  150. func BatchPushReport(reportId []int) (err error) {
  151. if len(reportId) == 0 {
  152. return
  153. }
  154. o := orm.NewOrm()
  155. sql := `UPDATE report_push_status SET state=1, push_time=NOW() WHERE report_id IN (` + utils.GetOrmReplaceHolder(len(reportId)) + `)`
  156. _, err = o.Raw(sql, reportId).Exec()
  157. return
  158. }
  159. // BatchPushCancelReport 批量撤销推送报告
  160. func BatchPushCancelReport(reportId []int) (err error) {
  161. if len(reportId) == 0 {
  162. return
  163. }
  164. o := orm.NewOrm()
  165. sql := `UPDATE report_push_status SET state=0, modify_time=NOW() WHERE report_id IN (` + utils.GetOrmReplaceHolder(len(reportId)) + `)`
  166. _, err = o.Raw(sql, reportId).Exec()
  167. return
  168. }
  169. // BatchAddReportPushStatus 批量添加报告
  170. func BatchAddReportPushStatus(items []*ReportPushStatus) (err error) {
  171. if len(items) == 0 {
  172. return
  173. }
  174. o := orm.NewOrm()
  175. _, err = o.InsertMulti(100, items)
  176. return
  177. }
  178. func GetMaxSyncIdReportPush(report_type int) (count int, err error) {
  179. o := orm.NewOrm()
  180. sql := `SELECT MAX(report_id) AS max_id FROM report_push_status WHERE report_type=?`
  181. err = o.Raw(sql, report_type).QueryRow(&count)
  182. return
  183. }
  184. func GetBatchReport(maxId, batchSize int) (items []*Report, err error) {
  185. o := orm.NewOrmUsingDB("rddp")
  186. sql := `SELECT * FROM report WHERE id>? AND (state=2 OR state=6) LIMIT ?`
  187. o.Raw(sql, maxId, batchSize).QueryRows(&items)
  188. return
  189. }