report_push_status.go 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 (r *ReportPushStatus) Delete() (err error) {
  80. o := orm.NewOrm()
  81. _, err = o.Delete(r)
  82. return
  83. }
  84. func GetReportPushStatusByReportId(reportPushStatusId, state int) (item *ReportPushStatus, err error) {
  85. o := orm.NewOrm()
  86. sql := `SELECT * FROM report_push_status WHERE report_push_status_id=? AND state=?`
  87. err = o.Raw(sql, reportPushStatusId, state).QueryRow(&item)
  88. return
  89. }
  90. func GetReportPushStatusByReportIdAndState(reportId []int, state int) (items []*ReportPushStatus, err error) {
  91. if len(reportId) == 0 {
  92. return
  93. }
  94. o := orm.NewOrm()
  95. sql := `SELECT * FROM report_push_status WHERE report_id IN (` + utils.GetOrmReplaceHolder(len(reportId)) + `) AND state=?`
  96. _, err = o.Raw(sql, reportId, state).QueryRows(&items)
  97. return
  98. }
  99. func GetReportPushStatusByIdAndState(Id []int, state int) (items []*ReportPushStatus, err error) {
  100. if len(Id) == 0 {
  101. return
  102. }
  103. o := orm.NewOrm()
  104. sql := `SELECT * FROM report_push_status WHERE report_push_status_id IN (` + utils.GetOrmReplaceHolder(len(Id)) + `) AND state=?`
  105. _, err = o.Raw(sql, Id, state).QueryRows(&items)
  106. return
  107. }
  108. func GetReportPushStatusByReportIds(reportType int, reportId []int) (items []*ReportPushStatus, err error) {
  109. if len(reportId) == 0 {
  110. return
  111. }
  112. o := orm.NewOrm()
  113. sql := `SELECT * FROM report_push_status WHERE report_type=? AND report_id IN (` + utils.GetOrmReplaceHolder(len(reportId)) + `) `
  114. _, err = o.Raw(sql, reportType, reportId).QueryRows(&items)
  115. return
  116. }
  117. func GetReportPushStatusListByCondition(condition, sortCondition string, pars []interface{}, startSize, pageSize int) (items []*ReportPushView, err error) {
  118. o := orm.NewOrm()
  119. sql := `SELECT * FROM report_push_status WHERE 1=1 `
  120. if condition != "" {
  121. sql += condition
  122. }
  123. if sortCondition != "" {
  124. sql += sortCondition
  125. }
  126. sql += ` LIMIT ?,? `
  127. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  128. return
  129. }
  130. func GetReportByCondition(condition string, pars []interface{}) (items []*Report, err error) {
  131. o := orm.NewOrmUsingDB("rddp")
  132. sql := `SELECT * FROM report WHERE 1=1 AND (state=2 OR state=6) `
  133. if condition != "" {
  134. sql += condition
  135. }
  136. _, err = o.Raw(sql, pars...).QueryRows(&items)
  137. return
  138. }
  139. func GetReportIdListByCondition(condition string, pars []interface{}) (reportId []int, err error) {
  140. o := orm.NewOrm()
  141. sql := `SELECT report_id FROM report_push_status WHERE 1=1 `
  142. if condition != "" {
  143. sql += condition
  144. }
  145. _, err = o.Raw(sql, pars).QueryRows(&reportId)
  146. return
  147. }
  148. func GetReportPushStatusIdListByCondition(condition string, pars []interface{}) (reportPushStatusId []int, err error) {
  149. o := orm.NewOrm()
  150. sql := `SELECT report_push_status_id FROM report_push_status WHERE 1=1 `
  151. if condition != "" {
  152. sql += condition
  153. }
  154. _, err = o.Raw(sql, pars).QueryRows(&reportPushStatusId)
  155. return
  156. }
  157. func GetReportCountById(id int) (count int, err error) {
  158. o := orm.NewOrmUsingDB("rddp")
  159. sql := `SELECT COUNT(*) AS count FROM report WHERE (state=2 OR state=6) AND id=?`
  160. err = o.Raw(sql, id).QueryRow(&count)
  161. return
  162. }
  163. func GetReportCountByCondition(condition string, pars []interface{}) (count int, err error) {
  164. o := orm.NewOrm()
  165. sql := `SELECT COUNT(*) AS count FROM report_push_status WHERE 1=1 `
  166. if condition != "" {
  167. sql += condition
  168. }
  169. err = o.Raw(sql, pars).QueryRow(&count)
  170. return
  171. }
  172. // BatchPushReport 批量推送报告
  173. func BatchPushReport(reportPushStatusId []int) (err error) {
  174. if len(reportPushStatusId) == 0 {
  175. return
  176. }
  177. o := orm.NewOrm()
  178. sql := `UPDATE report_push_status SET state=1, push_time=NOW() WHERE report_push_status_id IN (` + utils.GetOrmReplaceHolder(len(reportPushStatusId)) + `)`
  179. _, err = o.Raw(sql, reportPushStatusId).Exec()
  180. return
  181. }
  182. // BatchPushCancelReport 批量撤销推送报告
  183. func BatchPushCancelReport(reportPushStatusId []int) (err error) {
  184. if len(reportPushStatusId) == 0 {
  185. return
  186. }
  187. o := orm.NewOrm()
  188. sql := `UPDATE report_push_status SET state=0, modify_time=NOW() WHERE report_push_status_id IN (` + utils.GetOrmReplaceHolder(len(reportPushStatusId)) + `)`
  189. _, err = o.Raw(sql, reportPushStatusId).Exec()
  190. return
  191. }
  192. // BatchAddReportPushStatus 批量添加报告
  193. func BatchAddReportPushStatus(items []*ReportPushStatus) (err error) {
  194. if len(items) == 0 {
  195. return
  196. }
  197. o := orm.NewOrm()
  198. _, err = o.InsertMulti(100, items)
  199. return
  200. }
  201. func GetMaxSyncIdReportPush(report_type int) (count int, err error) {
  202. o := orm.NewOrm()
  203. sql := `SELECT MAX(report_id) AS max_id FROM report_push_status WHERE report_type=?`
  204. err = o.Raw(sql, report_type).QueryRow(&count)
  205. return
  206. }
  207. func GetBatchReport(maxId, batchSize int) (items []*Report, err error) {
  208. o := orm.NewOrmUsingDB("rddp")
  209. sql := `SELECT * FROM report WHERE id>? AND (state=2 OR state=6) LIMIT ?`
  210. o.Raw(sql, maxId, batchSize).QueryRows(&items)
  211. return
  212. }