浏览代码

Merge branch 'custom'

xyxie 5 月之前
父节点
当前提交
2632ed73bf

+ 7 - 2
controllers/document_manage/document_manage_controller.go

@@ -202,7 +202,7 @@ func (this *DocumentManageController) DocumentReportList() {
 	if currentIndex <= 0 {
 		currentIndex = 1
 	}
-	documentReportPage, err := document_manage_service.DocumentReportList(documentType, chartPermissionIdList, classifyIdList, keyword, orderField, orderType, currentIndex, pageSize)
+	documentReportPage, err := document_manage_service.DocumentReportList(this.SysUser.AdminId, documentType, chartPermissionIdList, classifyIdList, keyword, orderField, orderType, currentIndex, pageSize)
 	if err != nil {
 		br.Msg = "获取报告列表失败"
 		br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
@@ -241,6 +241,11 @@ func (this *DocumentManageController) RuiSiReportList() {
 	if strings.TrimSpace(classifyIdListStr) != "" {
 		classifyIdList = strings.Split(classifyIdListStr, ",")
 	}
+	chartPermissionIdString := this.GetString("ChartPermissionIdList")
+	var chartPermissionIdList []string
+	if strings.TrimSpace(chartPermissionIdString) != "" {
+		chartPermissionIdList = strings.Split(chartPermissionIdString, ",")
+	}
 
 	keyword := this.GetString("Keyword")
 	orderField := this.GetString("OrderField")
@@ -254,7 +259,7 @@ func (this *DocumentManageController) RuiSiReportList() {
 	if currentIndex <= 0 {
 		currentIndex = 1
 	}
-	RuiSiReportPage, err := document_manage_service.RuiSiReportListV2(classifyIdList, keyword, orderField, orderType, currentIndex, pageSize)
+	RuiSiReportPage, err := document_manage_service.RuiSiReportListV2(classifyIdList, chartPermissionIdList, keyword, orderField, orderType, this.SysUser.AdminId, currentIndex, pageSize)
 	if err != nil {
 		br.Msg = "获取报告列表失败"
 		br.ErrMsg = "获取报告列表失败,Err:" + err.Error()

+ 8 - 3
models/document_manage_model/outside_report.go

@@ -23,8 +23,13 @@ type OutsideReport struct {
 	ReportCode       string `orm:"column(report_code)" description:"报告唯一编码"`
 }
 
+type OutsideReportResp struct {
+	OutsideReport
+	IsCollect  int `description:"是否收藏"`
+}
+
 type OutsideReportPage struct {
-	List   []OutsideReport    `description:"报告列表"`
+	List   []OutsideReportResp    `description:"报告列表"`
 	Paging *paging.PagingItem `description:"分页数据"`
 }
 
@@ -63,9 +68,9 @@ 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{}, currentIndex int, pageSize int) (list []OutsideReportResp, err error) {
 	o := orm.NewOrmUsingDB("rddp")
-	sql := `select distinct t1.* 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 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)

+ 20 - 4
models/report.go

@@ -149,6 +149,7 @@ type ReportList struct {
 	ClassifyIdThird     int       `description:"三级分类id"`
 	ClassifyNameThird   string    `description:"三级分类名称"`
 	InheritReportId     int       `description:"待继承的报告ID"`
+	IsCollect           int       `description:"是否收藏"`
 }
 
 type ReportListResp struct {
@@ -1685,7 +1686,7 @@ func GetReportListByCollectList(classifyIdFirst, classifyIdSecond, classifyIdThi
 	return items, err
 }
 
-func GetReportListByCollectCountV2(classifyIdFirst, classifyIdSecond, classifyIdThird []string, keyword, author string, state int) (count int, err error) {
+func GetReportListByCollectCountV2(classifyIdFirst, classifyIdSecond, classifyIdThird, chartPermissionIdList []string, keyword, author string, state int) (count int, err error) {
 	o := orm.NewOrmUsingDB("rddp")
 	var params []interface{}
 
@@ -1694,9 +1695,16 @@ func GetReportListByCollectCountV2(classifyIdFirst, classifyIdSecond, classifyId
 		SELECT COUNT(DISTINCT t.id) AS totalCount
 		FROM (
 			SELECT b.id
-			FROM report AS b
+			FROM report AS b left join chart_permission_search_key_word_mapping c on
+b.classify_id_first = c.classify_id
 			WHERE 1 = 1
 	`
+	if len(chartPermissionIdList) > 0 {
+		sql += ` and c.chart_permission_id in (` + utils.GetOrmInReplace(len(chartPermissionIdList)) + `)`
+		for _, chartPermissionId := range chartPermissionIdList {
+			params = append(params, chartPermissionId)
+		}
+	}
 
 	// 处理关键词
 	if keyword != "" {
@@ -1750,7 +1758,7 @@ func GetReportListByCollectCountV2(classifyIdFirst, classifyIdSecond, classifyId
 	return count, err
 }
 
-func GetReportListByCollectListV2(classifyIdFirst, classifyIdSecond, classifyIdThird []string, keyword, orderField, orderType string, startSize, pageSize int, author string, state int) (items []*ReportList, err error) {
+func GetReportListByCollectListV2(classifyIdFirst, classifyIdSecond, classifyIdThird, chartPermissionIdList []string, keyword, orderField, orderType string, startSize, pageSize int, author string, state int) (items []*ReportList, err error) {
 	o := orm.NewOrmUsingDB("rddp")
 	var params []interface{}
 
@@ -1759,7 +1767,8 @@ func GetReportListByCollectListV2(classifyIdFirst, classifyIdSecond, classifyIdT
 		SELECT DISTINCT t.id, t.title, t.author, t.modify_time, t.publish_time,t.classify_id_first,t.classify_name_first,t.classify_id_second,t.classify_name_second,t.classify_id_third,t.classify_name_third
 		FROM (
 			SELECT b.id, b.title, b.author, b.modify_time, b.publish_time,b.classify_id_first,b.classify_name_first,b.classify_id_second,b.classify_name_second,b.classify_id_third,b.classify_name_third
-			FROM report AS b
+			FROM report AS b  left join chart_permission_search_key_word_mapping c on
+b.classify_id_first = c.classify_id 
 			WHERE 1 = 1
 	`
 
@@ -1808,6 +1817,13 @@ func GetReportListByCollectListV2(classifyIdFirst, classifyIdSecond, classifyIdT
 		sql += ` AND (` + strings.Join(classifyIdSqlList, " OR ") + `) `
 	}
 
+	if len(chartPermissionIdList) > 0 {
+		sql += ` and c.chart_permission_id in (` + utils.GetOrmInReplace(len(chartPermissionIdList)) + `)`
+		for _, chartPermissionId := range chartPermissionIdList {
+			params = append(params, chartPermissionId)
+		}
+	}
+
 	sql += ") AS t "
 
 	// 排序处理

+ 42 - 5
services/document_manage_service/document_manage_service.go

@@ -168,7 +168,7 @@ func getChildVariety(permissionList []*models.ChartPermission, permissionId int)
 
 }
 
-func DocumentReportList(documentType int, chartPermissionIdList []string, classifyIdList []string, keyword string, orderField, orderType string, startSize, pageSize int) (*document_manage_model.OutsideReportPage, error) {
+func DocumentReportList(userId, documentType int, chartPermissionIdList []string, classifyIdList []string, keyword string, orderField, orderType string, startSize, pageSize int) (*document_manage_model.OutsideReportPage, error) {
 	logs.Info("DocumentVarietyList")
 
 	var condition string
@@ -217,6 +217,23 @@ func DocumentReportList(documentType int, chartPermissionIdList []string, classi
 		return nil, err
 	}
 
+	// 查询用户已收藏的分类
+	collectClassifyList, err := models.GetUserCollectClassifyList(userId, 0)
+	if err != nil {
+		return nil, err
+	}
+	// 转换成map
+	collectClassifyMap := make(map[int]bool)
+	for _, collectClassify := range collectClassifyList {
+		collectClassifyMap[collectClassify.ClassifyId] = true
+	}
+
+	for i, _ := range outsideReportList {
+		if _, ok := collectClassifyMap[outsideReportList[i].ClassifyId]; ok {
+			outsideReportList[i].IsCollect = 1
+		}
+	}
+
 	reportPage.Paging = page
 	reportPage.List = outsideReportList
 
@@ -418,7 +435,7 @@ func DocumentDelete(outsideReportId int) error {
 	return nil
 }
 
-func RuiSiReportListV2(classifyIdList []string, keyword, orderField, orderType string, startSize, pageSize int) (*models.ReportListResp, error) {
+func RuiSiReportListV2(classifyIdList, chartPermissionIdList []string, keyword, orderField, orderType string, userId, startSize, pageSize int) (*models.ReportListResp, error) {
 	logs.Info("RuiSiReportList")
 
 	allClassifyList, err := models.GetClassifyListByIdStrList(classifyIdList)
@@ -443,7 +460,7 @@ func RuiSiReportListV2(classifyIdList []string, keyword, orderField, orderType s
 	// 已发布的报告
 	state := 2
 
-	count, err := models.GetReportListByCollectCountV2(classifyIdFirst, classifyIdSecond, classifyIdThird, keyword, author, state)
+	count, err := models.GetReportListByCollectCountV2(classifyIdFirst, classifyIdSecond, classifyIdThird, chartPermissionIdList, keyword, author, state)
 	if err != nil {
 		return nil, err
 	}
@@ -455,13 +472,33 @@ func RuiSiReportListV2(classifyIdList []string, keyword, orderField, orderType s
 		return &reportPage, nil
 	}
 
-	reportList, err := models.GetReportListByCollectListV2(classifyIdFirst, classifyIdSecond, classifyIdThird, keyword, orderField, orderType, startSize, pageSize, author, state)
+	reportList, err := models.GetReportListByCollectListV2(classifyIdFirst, classifyIdSecond, classifyIdThird, chartPermissionIdList, keyword, orderField, orderType, startSize, pageSize, author, state)
 	if err != nil {
 		return nil, err
 	}
 
-	for _, report := range reportList {
+	// 查询用户已收藏的分类
+	collectClassifyList, err := models.GetUserCollectClassifyList(userId, 0)
+	if err != nil {
+		return nil, err
+	}
+	// 转换成map
+	collectClassifyMap := make(map[int]bool)
+	for _, collectClassify := range collectClassifyList {
+		collectClassifyMap[collectClassify.ClassifyId] = true
+	}
+
+	for i, report := range reportList {
 		report.ModifyTime = report.ModifyTime.UTC()
+		if _, ok := collectClassifyMap[reportList[i].ClassifyIdFirst]; ok {
+			reportList[i].IsCollect = 1
+		}
+		if _, ok := collectClassifyMap[reportList[i].ClassifyIdSecond]; ok {
+			reportList[i].IsCollect = 1
+		}
+		if _, ok := collectClassifyMap[reportList[i].ClassifyIdThird]; ok {
+			reportList[i].IsCollect = 1
+		}
 	}
 
 	reportPage.Paging = page