gmy 3 долоо хоног өмнө
parent
commit
f83137a3d5

+ 18 - 7
models/document_manage_model/outside_report.go

@@ -25,12 +25,12 @@ type OutsideReport struct {
 
 type OutsideReportResp struct {
 	OutsideReport
-	IsCollect  int `description:"是否收藏"`
+	IsCollect int `description:"是否收藏"`
 }
 
 type OutsideReportPage struct {
-	List   []OutsideReportResp    `description:"报告列表"`
-	Paging *paging.PagingItem `description:"分页数据"`
+	List   []OutsideReportResp `description:"报告列表"`
+	Paging *paging.PagingItem  `description:"分页数据"`
 }
 
 type OutsideReportBO struct {
@@ -55,12 +55,23 @@ func init() {
 }
 
 // GetOutsideReportListByConditionCount 根据条件查询列表条数
-func GetOutsideReportListByConditionCount(condition string, pars []interface{}) (count int, err error) {
+func GetOutsideReportListByConditionCount(condition string, pars []interface{}, chartPermissionIdList []string) (count int, err error) {
 	o := orm.NewOrmUsingDB("rddp")
-	sql := `select count(distinct t1.outside_report_id) from outside_report t1 left join chart_permission_search_key_word_mapping t2 on t1.classify_id = t2.classify_id  where 1 = 1 `
+	var sql string
+	if len(chartPermissionIdList) > 0 {
+		sql = `select count(1) from (`
+	}
+	sql += `SELECT COUNT( DISTINCT t1.outside_report_id ) 
+			FROM outside_report t1 
+			    LEFT JOIN chart_permission_search_key_word_mapping t2 ON t1.classify_id = t2.classify_id 
+			WHERE 1 = 1 `
 	sql += condition
+	if len(chartPermissionIdList) > 0 {
+		sql += ` ) t`
+	}
+
 	err = o.Raw(sql, pars).QueryRow(&count)
-	if err != nil {
+	if err != nil && err != orm.ErrNoRows {
 		return 0, err
 	}
 
@@ -74,7 +85,7 @@ func GetOutsideReportListByCondition(condition string, pars []interface{}, curre
 	sql += condition
 	sql += ` limit ?, ?`
 	_, err = o.Raw(sql, pars, (currentIndex-1)*pageSize, pageSize).QueryRows(&list)
-	if err != nil {
+	if err != nil && err != orm.ErrNoRows {
 		return nil, err
 	}
 

+ 5 - 1
services/document_manage_service/document_manage_service.go

@@ -211,7 +211,11 @@ func DocumentReportList(userId, documentType int, chartPermissionIdList []string
 		pars = append(pars, "%"+keyword+"%", "%"+keyword+"%")
 	}
 
-	count, err := document_manage_model.GetOutsideReportListByConditionCount(condition, pars)
+	if len(chartPermissionIdList) > 0 {
+		condition += ` GROUP BY t1.outside_report_id HAVING COUNT(DISTINCT t2.chart_permission_id) = ` + strconv.Itoa(len(chartPermissionIdList))
+	}
+
+	count, err := document_manage_model.GetOutsideReportListByConditionCount(condition, pars, chartPermissionIdList)
 	if err != nil {
 		return nil, err
 	}