Jelajahi Sumber

fix: PDF报告查询逻辑

hsun 2 hari lalu
induk
melakukan
a33df3a12f
2 mengubah file dengan 46 tambahan dan 6 penghapusan
  1. 40 0
      controllers/report.go
  2. 6 6
      models/report.go

+ 40 - 0
controllers/report.go

@@ -66,8 +66,18 @@ func (this *ReportController) List() {
 		return
 	}
 	classifyMapping := make(map[int]*models.MiniClassify)
+	var classifyIds, firstIds, secondIds, thirdIds []int
 	for _, v := range classifies {
 		classifyMapping[v.Id] = v
+		classifyIds = append(classifyIds, v.Id)
+		switch v.Level {
+		case 1:
+			firstIds = append(firstIds, v.Id)
+		case 2:
+			secondIds = append(secondIds, v.Id)
+		case 3:
+			thirdIds = append(thirdIds, v.Id)
+		}
 	}
 	if params.ClassifyId > 0 {
 		classify := classifyMapping[params.ClassifyId]
@@ -102,6 +112,36 @@ func (this *ReportController) List() {
 			outsideCond += ` AND o.classify_id = ?`
 			outsidePars = append(outsidePars, params.ClassifyId)
 		}
+	} else {
+		// 默认只查询mini_classify分类中的
+		if len(classifyIds) > 0 {
+			var cond string
+			if len(firstIds) > 0 {
+				cond += fmt.Sprintf(`r.classify_id_first IN (%s)`, utils.GetOrmInReplace(len(firstIds)))
+				reportPars = append(reportPars, firstIds)
+			}
+			if len(secondIds) > 0 {
+				if cond != "" {
+					cond += fmt.Sprintf(` OR r.classify_id_second IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
+				} else {
+					cond += fmt.Sprintf(`r.classify_id_second IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
+				}
+				reportPars = append(reportPars, secondIds)
+			}
+			if len(thirdIds) > 0 {
+				if cond != "" {
+					cond += fmt.Sprintf(` OR r.classify_id_third IN (%s)`, utils.GetOrmInReplace(len(thirdIds)))
+				} else {
+					cond += fmt.Sprintf(`r.classify_id_third IN (%s)`, utils.GetOrmInReplace(len(thirdIds)))
+				}
+				reportPars = append(reportPars, thirdIds)
+			}
+			if cond != "" {
+				reportCond += fmt.Sprintf(` AND (%s)`, cond)
+			}
+			outsideCond += fmt.Sprintf(` AND o.classify_id IN (%s)`, utils.GetOrmInReplace(len(classifyIds)))
+			outsidePars = append(outsidePars, classifyIds)
+		}
 	}
 	resp := new(response.ReportList)
 

+ 6 - 6
models/report.go

@@ -54,11 +54,11 @@ func GetReportAndOutsideReportCount(reportCond, outsideCond string, reportPars,
 				ON 
 					o.outside_report_id = oa.outside_report_id
 				WHERE 
-					oa.title LIKE '%.pdf%' AND oa.create_time = (
-						SELECT MAX(oa2.create_time)
+					oa.title LIKE '%.pdf%' AND oa.outside_report_attachment_id = (
+						SELECT MAX(oa2.outside_report_attachment_id)
 						FROM outside_report_attachment oa2
 						WHERE oa2.outside_report_id = o.outside_report_id AND oa2.title LIKE '%.pdf%'
-					) ` + outsideCond + `
+					) ` + outsideCond + ` GROUP BY o.outside_report_id
 			)
 		) AS t`
 	//sql = fmt.Sprintf(sql, reportCond, outsideCond)
@@ -106,11 +106,11 @@ func GetReportAndOutsideReportByCondition(reportCond, outsideCond string, report
 			ON 
 				o.outside_report_id = oa.outside_report_id
 			WHERE 
-				oa.title LIKE '%.pdf%' AND oa.create_time = (
-					SELECT MAX(oa2.create_time)
+				oa.title LIKE '%.pdf%' AND oa.outside_report_attachment_id = (
+					SELECT MAX(oa2.outside_report_attachment_id)
 					FROM outside_report_attachment oa2
 					WHERE oa2.outside_report_id = o.outside_report_id AND oa2.title LIKE '%.pdf%'
-				) ` + outsideCond + `
+				) ` + outsideCond + ` GROUP BY o.outside_report_id
 		)
 		ORDER BY publish_time DESC LIMIT ?,?`
 	//sql = fmt.Sprintf(sql, reportCond, outsideCond)