Browse Source

fix:pdf列表

zqbao 8 months ago
parent
commit
6251fff31f
2 changed files with 35 additions and 34 deletions
  1. 24 24
      controllers/report.go
  2. 11 10
      models/report_pdf.go

+ 24 - 24
controllers/report.go

@@ -177,31 +177,31 @@ func (this *ReportController) PdfList() {
 	var leafClassifyIds []int
 	var leafClassifyIdMap map[int]struct{}
 	var classifyMap map[int]*models.ClassifyView
-	if classifyId != 0 {
-		classifyResp, err := services.GetAllClassify()
-		if err != nil {
-			br.Msg = "获取数据失败"
-			br.ErrMsg = "获取数据失败,Err:" + err.Error()
-			return
-		}
-		if classifyResp.Ret != 200 {
-			br.Msg = classifyResp.Msg
-			br.ErrMsg = classifyResp.ErrMsg
-			return
-		}
-		classifyList := classifyResp.Data
-		classifyMap = make(map[int]*models.ClassifyView)
-		isHas := false
-		for _, v := range classifyList {
-			if v.Id == classifyId && classifyId != 0 {
-				isHas = true
-			}
-			classifyMap[v.Id] = v
-		}
-		if !isHas && classifyId != 0 {
-			br.Msg = "分类不存在"
-			return
+	classifyResp, err := services.GetAllClassify()
+	if err != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	if classifyResp.Ret != 200 {
+		br.Msg = classifyResp.Msg
+		br.ErrMsg = classifyResp.ErrMsg
+		return
+	}
+	classifyList := classifyResp.Data
+	classifyMap = make(map[int]*models.ClassifyView)
+	isHas := false
+	for _, v := range classifyList {
+		if v.Id == classifyId && classifyId != 0 {
+			isHas = true
 		}
+		classifyMap[v.Id] = v
+	}
+	if !isHas && classifyId != 0 {
+		br.Msg = "分类不存在"
+		return
+	}
+	if classifyId != 0 {
 		leafClassifyIds = getLeafClassifyIds(classifyMap, classifyId)
 		leafClassifyIdMap = make(map[int]struct{})
 		for _, v := range leafClassifyIds {

+ 11 - 10
models/report_pdf.go

@@ -66,22 +66,22 @@ func GetReportPdfListByCondition(firstClassifyIds, secondClassifyIds, thirdClass
 		return
 	}
 	o := orm.NewOrm()
-	sql := `SELECT * FROM report_pdf WHERE 1=1 `
+	sql := `SELECT * FROM report_pdf WHERE 1=1 AND (1=2`
 	if len(firstClassifyIds) > 0 {
-		sql += fmt.Sprintf(" OR a.classify_id_first IN (%s) ", utils.GetOrmReplaceHolder(len(firstClassifyIds)))
+		sql += fmt.Sprintf(" OR classify_id_first IN (%s) ", utils.GetOrmReplaceHolder(len(firstClassifyIds)))
 	}
 	if len(secondClassifyIds) > 0 {
-		sql += fmt.Sprintf(" OR a.classify_id_second IN (%s) ", utils.GetOrmReplaceHolder(len(secondClassifyIds)))
+		sql += fmt.Sprintf(" OR classify_id_second IN (%s) ", utils.GetOrmReplaceHolder(len(secondClassifyIds)))
 	}
 	if len(thirdClassifyIds) > 0 {
-		sql += fmt.Sprintf(" OR a.classify_id_third IN (%s) ", utils.GetOrmReplaceHolder(len(thirdClassifyIds)))
+		sql += fmt.Sprintf(" OR classify_id_third IN (%s) ", utils.GetOrmReplaceHolder(len(thirdClassifyIds)))
 	}
-
+	sql += ")"
 	if condition != "" {
 		sql += condition
 	}
 	sql += ` ORDER BY publish_time DESC LIMIT ?,?`
-	_, err = o.Raw(sql, startSize, pageSize).QueryRows(&reportPdfs)
+	_, err = o.Raw(sql, firstClassifyIds, secondClassifyIds, thirdClassifyIds, startSize, pageSize).QueryRows(&reportPdfs)
 	return
 }
 
@@ -97,17 +97,18 @@ func GetReportPdfCountByCondition(firstClassifyIds, secondClassifyIds, thirdClas
 		return
 	}
 	o := orm.NewOrm()
-	sql := `SELECT COUNT(*) AS count FROM report_pdf WHERE 1=1 `
+	sql := `SELECT COUNT(*) AS count FROM report_pdf WHERE 1=1 AND (1=2 `
 
 	if len(firstClassifyIds) > 0 {
-		sql += fmt.Sprintf(" OR a.classify_id_first IN (%s) ", utils.GetOrmReplaceHolder(len(firstClassifyIds)))
+		sql += fmt.Sprintf(" OR classify_id_first IN (%s) ", utils.GetOrmReplaceHolder(len(firstClassifyIds)))
 	}
 	if len(secondClassifyIds) > 0 {
-		sql += fmt.Sprintf(" OR a.classify_id_second IN (%s) ", utils.GetOrmReplaceHolder(len(secondClassifyIds)))
+		sql += fmt.Sprintf(" OR classify_id_second IN (%s) ", utils.GetOrmReplaceHolder(len(secondClassifyIds)))
 	}
 	if len(thirdClassifyIds) > 0 {
-		sql += fmt.Sprintf(" OR a.classify_id_third IN (%s) ", utils.GetOrmReplaceHolder(len(thirdClassifyIds)))
+		sql += fmt.Sprintf(" OR classify_id_third IN (%s) ", utils.GetOrmReplaceHolder(len(thirdClassifyIds)))
 	}
+	sql += ` )`
 	if condition != "" {
 		sql += condition
 	}