report_send_ths_detail.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. //报告推送给同花顺的表结构体
  7. type ReportSendThsDetail struct {
  8. SendId int `orm:"column(send_id);pk" description:"发送给同花顺的Id"`
  9. ReportId int `description:"报告id"`
  10. ReportType string `description:"报告类型"`
  11. Status int8 `description:"发送结果,0:待发送,-1发送失败,1发送成功"`
  12. Remark string `description:"失败原因"`
  13. PushTime time.Time `description:"实际开始推送时间/预推送时间"`
  14. CreateTime time.Time `description:"发送时间"`
  15. }
  16. //新增报告发送给同花顺的记录
  17. func AddReportSendThsDetail(item *ReportSendThsDetail) (lastId int64, err error) {
  18. o := orm.NewOrm()
  19. //o.Using("rddp")
  20. lastId, err = o.Insert(item)
  21. return
  22. }
  23. //修改报告发送给同花顺的记录状态
  24. func ModifyReportSendThsDetailStatus(sendId int, status int8, remark string) (err error) {
  25. o := orm.NewOrm()
  26. //o.Using("rddp")
  27. sql := `UPDATE report_send_ths_detail SET status = ?,remark=? WHERE send_id = ? `
  28. _, err = o.Raw(sql, status, remark, sendId).Exec()
  29. return
  30. }
  31. //根据报告id获取发送记录
  32. func GetReportSendThsDetailByReportId(reportId int, reportType string) (item *ReportSendThsDetail, err error) {
  33. o := orm.NewOrm()
  34. sql := ` SELECT * FROM report_send_ths_detail WHERE report_id=? and report_type=? order by send_id desc`
  35. //o.Using("rddp")
  36. err = o.Raw(sql, reportId, reportType).QueryRow(&item)
  37. return
  38. }
  39. // GetLatelyReportSendThsDetail 获取发送中/发送成功的 距离现在最近的一条记录
  40. func GetLatelyReportSendThsDetail() (item *ReportSendThsDetail, err error) {
  41. o := orm.NewOrm()
  42. sql := ` SELECT * FROM report_send_ths_detail WHERE status >=0 order by push_time,send_id desc`
  43. //o.Using("rddp")
  44. err = o.Raw(sql).QueryRow(&item)
  45. return
  46. }
  47. // GetWaitReportSendThsDetailList 获取当前需要推送的报告记录
  48. func GetWaitReportSendThsDetailList() (list []*ReportSendThsDetail, err error) {
  49. o := orm.NewOrm()
  50. sql := ` SELECT * FROM report_send_ths_detail WHERE status = 2 and push_time <=now() order by send_id asc`
  51. //o.Using("rddp")
  52. _, err = o.Raw(sql).QueryRows(&list)
  53. return
  54. }