Browse Source

fix:同一个报告内,章节名称不能重复

Roc 8 months ago
parent
commit
014c144769
1 changed files with 22 additions and 21 deletions
  1. 22 21
      controllers/report_chapter.go

+ 22 - 21
controllers/report_chapter.go

@@ -118,8 +118,8 @@ func (this *ReportController) AddChapter() {
 		var condition string
 		var pars []interface{}
 
-		condition += " AND title=? "
-		pars = append(pars, req.Title)
+		condition += " AND report_id = ? AND title=? "
+		pars = append(pars, req.ReportId, req.Title)
 		count, err := models.GetCountReportChapterByCondition(condition, pars)
 		if err != nil {
 			br.Msg = "新增失败"
@@ -216,13 +216,21 @@ func (this *ReportController) EditChapterBaseInfoAndPermission() {
 		return
 	}
 
+	// 获取章节详情
+	reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
+	if err != nil {
+		br.Msg = "报告章节信息有误"
+		br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
+		return
+	}
+
 	// 判断名称是否重复
 	{
 		var condition string
 		var pars []interface{}
 
-		condition += " AND title=? AND report_chapter_id != ? "
-		pars = append(pars, req.Title, reportChapterId)
+		condition += " AND report_id = ? AND title=? AND report_chapter_id != ? "
+		pars = append(pars, reportChapterInfo.ReportId, req.Title, reportChapterId)
 		count, err := models.GetCountReportChapterByCondition(condition, pars)
 		if err != nil {
 			br.Msg = "新增失败"
@@ -237,13 +245,6 @@ func (this *ReportController) EditChapterBaseInfoAndPermission() {
 		}
 	}
 
-	// 获取章节详情
-	reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
-	if err != nil {
-		br.Msg = "报告章节信息有误"
-		br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
-		return
-	}
 	// 获取报告详情
 	reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
 	if err != nil {
@@ -1498,13 +1499,21 @@ func (this *ReportController) EditChapterTitle() {
 		return
 	}
 
+	// 获取章节详情
+	reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
+	if err != nil {
+		br.Msg = "报告章节信息有误"
+		br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
+		return
+	}
+
 	// 判断名称是否重复
 	{
 		var condition string
 		var pars []interface{}
 
-		condition += " AND title=? AND report_chapter_id != ? "
-		pars = append(pars, req.Title, reportChapterId)
+		condition += " AND report_id = ? AND title=? AND report_chapter_id != ? "
+		pars = append(pars, reportChapterInfo.ReportId, req.Title, reportChapterId)
 		count, err := models.GetCountReportChapterByCondition(condition, pars)
 		if err != nil {
 			br.Msg = "新增失败"
@@ -1519,14 +1528,6 @@ func (this *ReportController) EditChapterTitle() {
 		}
 	}
 
-	// 获取章节详情
-	reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
-	if err != nil {
-		br.Msg = "报告章节信息有误"
-		br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
-		return
-	}
-
 	// 获取报告详情
 	reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
 	if err != nil {