浏览代码

报告筛选

kobe6258 8 月之前
父节点
当前提交
d873e48a57
共有 2 个文件被更改,包括 30 次插入10 次删除
  1. 7 3
      domian/report/report_service.go
  2. 23 7
      models/report/report.go

+ 7 - 3
domian/report/report_service.go

@@ -643,8 +643,8 @@ func GetTotalPageCountByPermissionIds(permissionIds []int) (total int64, latestI
 		logger.Error("品种筛选eta报告id失败:%v", err)
 		etaOrgIds = []int{}
 	}
-	total = int64(len(etaOrgIds) + len(htOrgIds))
-	if total == 0 {
+	totalCol := int64(len(etaOrgIds) + len(htOrgIds))
+	if totalCol == 0 {
 		latestId = 0
 		return
 	}
@@ -660,7 +660,11 @@ func GetTotalPageCountByPermissionIds(permissionIds []int) (total int64, latestI
 		ids["HT"] = htOrgIds
 	}
 	//ids = append(etaIds, htIds...)
-	latestId = reportDao.GetMaxIdByPermissionIds(ids)
+	total, latestId, err = reportDao.GetMaxIdByPermissionIds(ids)
+	if err != nil {
+		logger.Error("获取筛选报告的最大记录和记录数失败:%v", err)
+		return
+	}
 	return
 }
 func convertEtaReport(etaRp eta.ETAReport, status reportDao.ReportStatus) reportDao.Report {

+ 23 - 7
models/report/report.go

@@ -193,7 +193,7 @@ func GetListByCondition[T any](column string, values []T) (reports []Report, err
 	}
 	return
 }
-func GetMaxIdByPermissionIds(orgIds map[string][]int) (maxId int64) {
+func GetMaxIdByPermissionIds(orgIds map[string][]int) (total int64, maxId int64, err error) {
 	db := models.Main()
 	if len(orgIds["ETA"]) == 0 && len(orgIds["HT"]) == 0 {
 		//err := db.Model(&Report{}).Select("MAX(id) id").Where("status = ?", StatusPublish).Scan(&maxId).Error
@@ -202,28 +202,44 @@ func GetMaxIdByPermissionIds(orgIds map[string][]int) (maxId int64) {
 		//	return 0
 		//}
 		maxId = 0
+		total = 0
 		return
 	}
 	if len(orgIds["ETA"]) == 0 {
-		err := db.Model(&Report{}).Select("MAX(id) id").Where("status = ?", StatusPublish).Where(" source='HT' and org_id in ?", orgIds["HT"]).Scan(&maxId).Error
+		err = db.Model(&Report{}).Select("count(*)").Where("status = ?", StatusPublish).Where(" source='HT' and org_id in ?", orgIds["HT"]).Scan(&total).Error
+		if err != nil {
+			logger.Error("获取记录条数失败:%v", err)
+			return
+		}
+		err = db.Model(&Report{}).Select("MAX(id) id").Where("status = ?", StatusPublish).Where(" source='HT' and org_id in ?", orgIds["HT"]).Scan(&maxId).Error
 		if err != nil {
 			logger.Error("获取报告最大ID失败:%v", err)
-			return 0
+			return
 		}
 		return
 	}
 	if len(orgIds["HT"]) == 0 {
-		err := db.Model(&Report{}).Select("MAX(id) id").Where("status = ?", StatusPublish).Where(" source='ETA' and org_id in ?", orgIds["ETA"]).Scan(&maxId).Error
+		err = db.Model(&Report{}).Select("count(*)").Where("status = ?", StatusPublish).Where(" source='ETA' and org_id in ?", orgIds["ETA"]).Scan(&maxId).Error
+		if err != nil {
+			logger.Error("获取报告最大ID失败:%v", err)
+			return
+		}
+		err = db.Model(&Report{}).Select("MAX(id) id").Where("status = ?", StatusPublish).Where(" source='ETA' and org_id in ?", orgIds["ETA"]).Scan(&maxId).Error
 		if err != nil {
 			logger.Error("获取报告最大ID失败:%v", err)
-			return 0
+			return
 		}
 		return
 	}
-	err := db.Model(&Report{}).Select("MAX(id) id").Where("status = ?", StatusPublish).Where(" source='ETA' and org_id in ?", orgIds["ETA"]).Or("source='HT' and org_id in ?", orgIds["HT"]).Scan(&maxId).Error
+	err = db.Model(&Report{}).Select("count(*)").Where("status = ?", StatusPublish).Where(" source='ETA' and org_id in ?", orgIds["ETA"]).Or("source='HT' and org_id in ?", orgIds["HT"]).Scan(&maxId).Error
 	if err != nil {
 		logger.Error("获取报告最大ID失败:%v", err)
-		return 0
+		return
+	}
+	err = db.Model(&Report{}).Select("MAX(id) id").Where("status = ?", StatusPublish).Where(" source='ETA' and org_id in ?", orgIds["ETA"]).Or("source='HT' and org_id in ?", orgIds["HT"]).Scan(&maxId).Error
+	if err != nil {
+		logger.Error("获取报告最大ID失败:%v", err)
+		return
 	}
 	return
 }