浏览代码

fix:报告删除时,章节也要一起删除

Roc 8 月之前
父节点
当前提交
0665611f70
共有 4 个文件被更改,包括 33 次插入34 次删除
  1. 0 1
      controllers/report_v2.go
  2. 2 2
      models/report.go
  3. 0 31
      services/report.go
  4. 31 0
      services/report_v2.go

+ 0 - 1
controllers/report_v2.go

@@ -131,7 +131,6 @@ func (this *ReportController) ListReport() {
 		condition += ` AND a.is_public_publish = ? `
 		pars = append(pars, 1)
 		condition += `  AND a.state in (2,6) `
-
 	case 3:
 		condition += ` AND a.admin_id = ? `
 		pars = append(pars, this.SysUser.AdminId)

+ 2 - 2
models/report.go

@@ -250,12 +250,12 @@ func GetReportListCountByGrant(condition string, pars []interface{}) (count int,
 func GetReportListByGrant(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
 	o := orm.NewOrmUsingDB("rddp")
 
-	sql := `SELECT * FROM report as a JOIN report_grant b on a.id = b.report_id  WHERE 1=1  `
+	sql := `SELECT a.* FROM report as a JOIN report_grant b on a.id = b.report_id  WHERE 1=1  `
 	if condition != "" {
 		sql += condition
 	}
 	// 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
-	sql += ` GROUP BY a.id ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
+	sql += ` GROUP BY a.id ORDER BY FIELD(state,3,1,4,5,6,2), a.modify_time DESC LIMIT ?,?`
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
 	return
 }

+ 0 - 31
services/report.go

@@ -307,37 +307,6 @@ func updateReportChapterEsByChapter(chapterInfo *models.ReportChapter) (err erro
 	return
 }
 
-// DeleteReportAndChapter 删除报告及章节
-func DeleteReportAndChapter(reportId int) (err error) {
-	reportInfo, err := models.GetReportByReportId(reportId)
-	if err != nil {
-		err = errors.New("报告信息有误, Err: " + err.Error())
-		return
-	}
-	if reportInfo.State == 2 {
-		err = errors.New("报告已发布,不可删除")
-		return
-	}
-	// 更新ES
-	_ = UpdateReportEs(reportId, 1)
-	// 删除
-	if reportInfo.HasChapter == 1 && (reportInfo.ChapterType == utils.REPORT_TYPE_DAY || reportInfo.ChapterType == utils.REPORT_TYPE_WEEK) {
-		err = models.DeleteDayWeekReportAndChapter(reportId)
-	} else {
-		err = models.DeleteReport(reportId)
-	}
-	if err != nil {
-		err = errors.New("删除失败, Err: " + err.Error())
-		return
-	}
-	// 重置PPT关联报告
-	go func() {
-		_ = ResetPPTReport(reportId, false)
-	}()
-
-	return
-}
-
 // 替换报告内容中的base64图片
 func replaceReportBase64ToImg(content string) (newContent string, err error) {
 	if content == "" {

+ 31 - 0
services/report_v2.go

@@ -1257,6 +1257,37 @@ func PublishChapterReport(reportInfo *models.Report, reportUrl string, sysUser *
 	return
 }
 
+// DeleteReportAndChapter 删除报告及章节
+func DeleteReportAndChapter(reportId int) (err error) {
+	reportInfo, err := models.GetReportByReportId(reportId)
+	if err != nil {
+		err = errors.New("报告信息有误, Err: " + err.Error())
+		return
+	}
+	if reportInfo.State == 2 {
+		err = errors.New("报告已发布,不可删除")
+		return
+	}
+	// 更新ES
+	_ = UpdateReportEs(reportId, 1)
+	// 删除
+	if reportInfo.HasChapter == 1 {
+		err = models.DeleteDayWeekReportAndChapter(reportId)
+	} else {
+		err = models.DeleteReport(reportId)
+	}
+	if err != nil {
+		err = errors.New("删除失败, Err: " + err.Error())
+		return
+	}
+	// 重置PPT关联报告
+	go func() {
+		_ = ResetPPTReport(reportId, false)
+	}()
+
+	return
+}
+
 // getMinClassify
 // @Description: 获取最小分类ID
 // @author: Roc