|
@@ -54,17 +54,51 @@ type ReportPdfView struct {
|
|
|
}
|
|
|
|
|
|
func (r *ReportPdf) Insert() (insertId int64, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ tx, err := orm.NewOrm().Begin()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ tx.Rollback()
|
|
|
+ } else {
|
|
|
+ tx.Commit()
|
|
|
+ }
|
|
|
+ }()
|
|
|
// 计算研报期数
|
|
|
sql := `SELECT MAX(stage) + 1 AS count FROM report_pdf WHERE classify_id_second=?`
|
|
|
- err = o.Raw(sql, r.ClassifyIdSecond).QueryRow(&r.Stage)
|
|
|
+ err = tx.Raw(sql, r.ClassifyIdSecond).QueryRow(&r.Stage)
|
|
|
if r.Stage == 0 {
|
|
|
r.Stage = 1
|
|
|
}
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
- insertId, err = o.Insert(r)
|
|
|
+ insertId, err = tx.Insert(r)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if r.State == utils.ReportStatusUp {
|
|
|
+ insertPushStatus := &ReportPushStatus{
|
|
|
+ ReportId: r.ReportPdfId,
|
|
|
+ State: 0,
|
|
|
+ Title: r.Title,
|
|
|
+ Abstract: r.Abstract,
|
|
|
+ Stage: r.Stage,
|
|
|
+ ClassifyIdFirst: r.ClassifyIdFirst,
|
|
|
+ ClassifyNameFirst: r.ClassifyNameFirst,
|
|
|
+ ClassifyIdSecond: r.ClassifyIdSecond,
|
|
|
+ ClassifyNameSecond: r.ClassifyNameSecond,
|
|
|
+ ClassifyIdThird: r.ClassifyIdThird,
|
|
|
+ ClassifyNameThird: r.ClassifyNameThird,
|
|
|
+ Author: r.Author,
|
|
|
+ ReportType: utils.ReportTypePdf,
|
|
|
+ PublishTime: r.PublishTime,
|
|
|
+ CreateTime: time.Now(),
|
|
|
+ ModifyTime: time.Now(),
|
|
|
+ }
|
|
|
+ _, err = tx.Insert(insertPushStatus)
|
|
|
+ }
|
|
|
return
|
|
|
}
|
|
|
|