浏览代码

Merge branch 'bzq/dev' of eta_mini/eta_mini_bridge into debug

鲍自强 7 月之前
父节点
当前提交
51f403a437
共有 2 个文件被更改,包括 24 次插入7 次删除
  1. 6 2
      controllers/report.go
  2. 18 5
      models/report.go

+ 6 - 2
controllers/report.go

@@ -935,14 +935,18 @@ func (this *ReportNoAuthController) List() {
 		}
 		reportList = tmpReportList
 	case 0:
-		tmptotal, err := models.GetPushReportCount()
+		var selectedClassifyIds []int
+		for k := range classifyIdMap {
+			selectedClassifyIds = append(selectedClassifyIds, k)
+		}
+		tmptotal, err := models.GetPushReportCount(selectedClassifyIds)
 		if err != nil {
 			br.Msg = "获取数据失败"
 			br.ErrMsg = "获取数据失败,Err:" + err.Error()
 			return
 		}
 		total = tmptotal
-		tmpReportList, err := models.GetPushReportListByPage(startSize, pageSize)
+		tmpReportList, err := models.GetPushReportListByPage(selectedClassifyIds, startSize, pageSize)
 		if err != nil {
 			br.Msg = "获取报告列表失败"
 			br.ErrMsg = "获取报告列表失败,Err:" + err.Error()

+ 18 - 5
models/report.go

@@ -200,17 +200,30 @@ func GetPushReportListByClassifyIds(classifyFirstIds, classifySecondIds, classif
 	return
 }
 
-func GetPushReportCount() (count int, err error) {
+func GetPushReportCount(classifyIds []int) (count int, err error) {
 	o := orm.NewOrm()
 	sql := ` SELECT COUNT(*) AS count FROM report_push_status WHERE state=1 AND report_type=1 `
-	err = o.Raw(sql).QueryRow(&count)
+	var pars []interface{}
+	if len(classifyIds) > 0 {
+		sql += " AND (classify_id_first IN (%s) OR classify_id_second IN (%s) OR classify_id_third IN (%s))"
+		sql = fmt.Sprintf(sql, utils.GetOrmReplaceHolder(len(classifyIds)), utils.GetOrmReplaceHolder(len(classifyIds)), utils.GetOrmReplaceHolder(len(classifyIds)))
+		pars = append(pars, classifyIds, classifyIds, classifyIds)
+	}
+	err = o.Raw(sql, pars...).QueryRow(&count)
 	return
 }
 
-func GetPushReportListByPage(startSize, pageSize int) (items []*ReportPushView, err error) {
+func GetPushReportListByPage(classifyIds []int, startSize, pageSize int) (items []*ReportPushView, err error) {
 	o := orm.NewOrm()
-	sql := ` SELECT * FROM report_push_status WHERE state=1 AND report_type=1 ORDER BY publish_time DESC LIMIT ?,? `
-	_, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
+	sql := ` SELECT * FROM report_push_status WHERE state=1 AND report_type=1 `
+	var pars []interface{}
+	if len(classifyIds) > 0 {
+		sql += ` AND (classify_id_first IN (%s) OR classify_id_second IN (%s) OR classify_id_third IN (%s)) `
+		sql = fmt.Sprintf(sql, utils.GetOrmReplaceHolder(len(classifyIds)), utils.GetOrmReplaceHolder(len(classifyIds)), utils.GetOrmReplaceHolder(len(classifyIds)))
+		pars = append(pars, classifyIds, classifyIds, classifyIds)
+	}
+	sql += ` ORDER BY publish_time DESC LIMIT ?,? `
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
 	return
 }