package models import ( "github.com/beego/beego/v2/client/orm" "time" ) //报告推送给同花顺的表结构体 type ReportSendThsDetail struct { SendId int `orm:"column(send_id);pk" description:"发送给同花顺的Id"` ReportId int `description:"报告id"` ReportType string `description:"报告类型"` Status int8 `description:"发送结果,0:待发送,-1发送失败,1发送成功"` Remark string `description:"失败原因"` PushTime time.Time `description:"实际开始推送时间/预推送时间"` CreateTime time.Time `description:"发送时间"` } //新增报告发送给同花顺的记录 func AddReportSendThsDetail(item *ReportSendThsDetail) (lastId int64, err error) { o := orm.NewOrm() //o.Using("rddp") lastId, err = o.Insert(item) return } //修改报告发送给同花顺的记录状态 func ModifyReportSendThsDetailStatus(sendId int, status int8, remark string) (err error) { o := orm.NewOrm() //o.Using("rddp") sql := `UPDATE report_send_ths_detail SET status = ?,remark=? WHERE send_id = ? ` _, err = o.Raw(sql, status, remark, sendId).Exec() return } //根据报告id获取发送记录 func GetReportSendThsDetailByReportId(reportId int, reportType string) (item *ReportSendThsDetail, err error) { o := orm.NewOrm() sql := ` SELECT * FROM report_send_ths_detail WHERE report_id=? and report_type=? order by send_id desc` //o.Using("rddp") err = o.Raw(sql, reportId, reportType).QueryRow(&item) return } // GetLatelyReportSendThsDetail 获取发送中/发送成功的 距离现在最近的一条记录 func GetLatelyReportSendThsDetail() (item *ReportSendThsDetail, err error) { o := orm.NewOrm() sql := ` SELECT * FROM report_send_ths_detail WHERE status >=0 order by push_time,send_id desc` //o.Using("rddp") err = o.Raw(sql).QueryRow(&item) return } // GetWaitReportSendThsDetailList 获取当前需要推送的报告记录 func GetWaitReportSendThsDetailList() (list []*ReportSendThsDetail, err error) { o := orm.NewOrm() sql := ` SELECT * FROM report_send_ths_detail WHERE status = 2 and push_time <=now() order by send_id asc` //o.Using("rddp") _, err = o.Raw(sql).QueryRows(&list) return }