浏览代码

fix:pdf报告同步更改推送表

zqbao 5 月之前
父节点
当前提交
2906b13285
共有 2 个文件被更改,包括 26 次插入16 次删除
  1. 20 16
      models/report_pdf.go
  2. 6 0
      models/report_push_status.go

+ 20 - 16
models/report_pdf.go

@@ -117,7 +117,7 @@ func (r *ReportPdf) Update(cols []string) (err error) {
 	if err != nil {
 		return
 	}
-	if (reportPushStatus == nil || err.Error() == utils.ErrNoRow()) && r.State == 1 {
+	if (reportPushStatus == nil || err.Error() == utils.ErrNoRow()) && r.State == utils.ReportStatusUp {
 		insertPushStatus := &ReportPushStatus{
 			ReportId:           r.ReportPdfId,
 			State:              0,
@@ -137,22 +137,26 @@ func (r *ReportPdf) Update(cols []string) (err error) {
 			ModifyTime:         time.Now(),
 		}
 		_, err = tx.Insert(insertPushStatus)
-	} else {
-		reportPushStatus.Title = r.Title
-		reportPushStatus.Abstract = r.Abstract
-		reportPushStatus.Stage = r.Stage
-		reportPushStatus.ClassifyIdFirst = r.ClassifyIdFirst
-		reportPushStatus.ClassifyNameFirst = r.ClassifyNameFirst
-		reportPushStatus.ClassifyIdSecond = r.ClassifyIdSecond
-		reportPushStatus.ClassifyNameSecond = r.ClassifyNameSecond
-		reportPushStatus.ClassifyIdThird = r.ClassifyIdThird
-		reportPushStatus.ClassifyNameThird = r.ClassifyNameThird
-		reportPushStatus.Author = r.Author
-		reportPushStatus.PublishTime = r.PublishTime
-		reportPushStatus.ModifyTime = time.Now()
-		_, err = tx.Update(reportPushStatus)
+	} else if reportPushStatus != nil || err.Error() != utils.ErrNoRow() {
+		// pdf报告发布后编辑,则更新report_push_status表, 若取消发布,则在推送表中删除
+		if r.State == utils.ReportStatusDown {
+			err = reportPushStatus.Delete()
+		} else {
+			reportPushStatus.Title = r.Title
+			reportPushStatus.Abstract = r.Abstract
+			reportPushStatus.Stage = r.Stage
+			reportPushStatus.ClassifyIdFirst = r.ClassifyIdFirst
+			reportPushStatus.ClassifyNameFirst = r.ClassifyNameFirst
+			reportPushStatus.ClassifyIdSecond = r.ClassifyIdSecond
+			reportPushStatus.ClassifyNameSecond = r.ClassifyNameSecond
+			reportPushStatus.ClassifyIdThird = r.ClassifyIdThird
+			reportPushStatus.ClassifyNameThird = r.ClassifyNameThird
+			reportPushStatus.Author = r.Author
+			reportPushStatus.PublishTime = r.PublishTime
+			reportPushStatus.ModifyTime = time.Now()
+			_, err = tx.Update(reportPushStatus)
+		}
 	}
-
 	return
 }
 

+ 6 - 0
models/report_push_status.go

@@ -85,6 +85,12 @@ func (r *ReportPushStatus) Update(cols []string) (err error) {
 	return
 }
 
+func (r *ReportPushStatus) Delete() (err error) {
+	o := orm.NewOrm()
+	_, err = o.Delete(r)
+	return
+}
+
 func GetReportPushStatusByReportId(reportPushStatusId, state int) (item *ReportPushStatus, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT * FROM report_push_status WHERE report_push_status_id=? AND state=?`