Browse Source

战研报告 多品种 选取交集

gmy 3 months ago
parent
commit
a1a230c3b0

+ 9 - 4
models/document_manage_model/outside_report.go

@@ -52,8 +52,14 @@ func init() {
 // GetOutsideReportListByConditionCount 根据条件查询列表条数
 func GetOutsideReportListByConditionCount(condition string, pars []interface{}) (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 `
+	sql := `select count(1) from ( 
+			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
+	sql += ` ) t`
+
 	err = o.Raw(sql, pars).QueryRow(&count)
 	if err != nil {
 		return 0, err
@@ -63,15 +69,14 @@ func GetOutsideReportListByConditionCount(condition string, pars []interface{})
 }
 
 // GetOutsideReportListByCondition 根据条件查询列表
-func GetOutsideReportListByCondition(condition string, pars []interface{}, currentIndex int, pageSize int) (list []OutsideReport, err error) {
+func GetOutsideReportListByCondition(condition string, pars []interface{}) (list []OutsideReport, err error) {
 	o := orm.NewOrmUsingDB("rddp")
 	sql := `select DISTINCT t1.outside_report_id, t1.source, t1.title, t1.abstract, t1.classify_id, 
 t1.classify_name, t1.sys_user_id, t1.sys_user_name, t1.email_message_uid, t1.report_update_time, 
 t1.modify_time, t1.create_time, t1.report_code 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
-	sql += ` limit ?, ?`
-	_, err = o.Raw(sql, pars, (currentIndex-1)*pageSize, pageSize).QueryRows(&list)
+	_, err = o.Raw(sql, pars).QueryRows(&list)
 	if err != nil {
 		return nil, err
 	}

+ 6 - 1
services/document_manage_service/document_manage_service.go

@@ -161,6 +161,8 @@ func DocumentReportList(documentType int, chartPermissionIdList []string, classi
 		pars = append(pars, "%"+keyword+"%", "%"+keyword+"%")
 	}
 
+	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)
 	if err != nil {
 		return nil, err
@@ -179,7 +181,10 @@ func DocumentReportList(documentType int, chartPermissionIdList []string, classi
 		condition += ` order by t1.report_update_time desc`
 	}
 
-	outsideReportList, err := document_manage_model.GetOutsideReportListByCondition(condition, pars, startSize, pageSize)
+	condition += ` LIMIT ?,?`
+	pars = append(pars, (startSize-1)*pageSize, pageSize)
+
+	outsideReportList, err := document_manage_model.GetOutsideReportListByCondition(condition, pars)
 	if err != nil {
 		return nil, err
 	}