|
@@ -229,22 +229,23 @@ func GetReportIdListByOrgIds(orgIds map[string][]int) (ids []int, err error) {
|
|
|
func GetMaxIdByPermissionIds(orgIds map[string][]int, disCardIds []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
|
|
|
- //if err != nil {
|
|
|
- // logger.Error("获取报告最大ID失败:%v", err)
|
|
|
- // return 0
|
|
|
- //}
|
|
|
maxId = 0
|
|
|
total = 0
|
|
|
return
|
|
|
}
|
|
|
+ countQuery := db.Model(&Report{}).Select("count(*)").Where("status = ? ", StatusPublish, disCardIds)
|
|
|
+ maxQuery := db.Model(&Report{}).Select("MAX(id) id").Where("status = ? ", StatusPublish)
|
|
|
+ if len(disCardIds) > 0 {
|
|
|
+ countQuery.Where("id not in ?", disCardIds)
|
|
|
+ maxQuery.Where("id not in ?", disCardIds)
|
|
|
+ }
|
|
|
if len(orgIds["ETA"]) == 0 {
|
|
|
- err = db.Model(&Report{}).Select("count(*)").Where("status = ?", StatusPublish).Where(" source='HT' and org_id in ? and id not in ?", orgIds["HT"], disCardIds).Scan(&total).Error
|
|
|
+ err = countQuery.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 ? and id not in ?", orgIds["HT"], disCardIds).Scan(&maxId).Error
|
|
|
+ err = maxQuery.Where(" source='HT' and org_id in ? ", orgIds["HT"]).Scan(&maxId).Error
|
|
|
if err != nil {
|
|
|
logger.Error("获取报告最大ID失败:%v", err)
|
|
|
return
|
|
@@ -252,24 +253,24 @@ func GetMaxIdByPermissionIds(orgIds map[string][]int, disCardIds []int) (total i
|
|
|
return
|
|
|
}
|
|
|
if len(orgIds["HT"]) == 0 {
|
|
|
- err = db.Model(&Report{}).Select("count(*)").Where("status = ?", StatusPublish).Where(" source='ETA' and org_id in ? and id not in ?", orgIds["ETA"], disCardIds).Scan(&total).Error
|
|
|
+ err = countQuery.Where(" source='ETA' and org_id in ? ", orgIds["ETA"]).Scan(&total).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 ? and id not in ?", orgIds["ETA"], disCardIds).Scan(&maxId).Error
|
|
|
+ err = maxQuery.Where(" source='ETA' and org_id in ? ", orgIds["ETA"]).Scan(&maxId).Error
|
|
|
if err != nil {
|
|
|
logger.Error("获取报告最大ID失败:%v", err)
|
|
|
return
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
- err = db.Model(&Report{}).Select("count(*)").Where("status = ?", StatusPublish).Where(" source='ETA' and org_id in ? and id not in ?", orgIds["ETA"]).Or("source='HT' and org_id in ?", orgIds["HT"], disCardIds).Scan(&total).Error
|
|
|
+ err = countQuery.Where(" source='ETA' and org_id in ? ", orgIds["ETA"]).Or("source='HT' and org_id in ?", orgIds["HT"]).Scan(&total).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 ? and id not in ?", orgIds["ETA"]).Or("source='HT' and org_id in ?", orgIds["HT"], disCardIds).Scan(&maxId).Error
|
|
|
+ err = maxQuery.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
|