Browse Source

搜索精选目录下的图表

xyxie 3 weeks ago
parent
commit
426506b42a

+ 32 - 3
controllers/data_manage/chart_info.go

@@ -1601,6 +1601,7 @@ func (this *ChartInfoController) ChartInfoDetailV2() {
 	}
 
 	resp := new(data_manage.ChartInfoDetailResp)
+	isSelected := 0
 	// 图表数据权限
 	{
 		// 图表分类
@@ -1610,7 +1611,7 @@ func (this *ChartInfoController) ChartInfoDetailV2() {
 			br.ErrMsg = "获取图表分类信息失败,Err:" + err.Error()
 			return
 		}
-
+		isSelected = chartClassify.IsSelected
 		// 已授权分类id
 		permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, chartInfo.ChartInfoId, chartInfo.ChartClassifyId)
 		if err != nil {
@@ -1818,6 +1819,7 @@ func (this *ChartInfoController) ChartInfoDetailV2() {
 	}
 
 	// 图表当前分类的分类树
+	
 	classifyLevels := make([]string, 0)
 	{
 		list, e := data_manage.GetChartClassifyAllBySource(utils.CHART_SOURCE_DEFAULT)
@@ -1836,6 +1838,7 @@ func (this *ChartInfoController) ChartInfoDetailV2() {
 	}
 
 	resp.ClassifyLevels = classifyLevels
+	resp.IsSelected = isSelected
 
 	//图表操作权限
 	chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, chartInfo.HaveOperaAuth)
@@ -2287,6 +2290,32 @@ func (this *ChartInfoController) ChartInfoSearchByEs() {
 	startSize = paging.StartIndex(currentIndex, pageSize)
 
 	keyword := this.GetString("Keyword")
+	isSelected, _ := this.GetInt("IsSelected", -1)
+	chartClassifyIds := make([]int, 0)
+	if isSelected >= 0 {
+		// 查询所有分类
+		chartClassifyList, e := data_manage.GetChartClassifyAllBySourceIsSelected(utils.CHART_SOURCE_DEFAULT, isSelected)
+		if e != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取图表分类失败,Err:" + e.Error()
+			return
+		}
+		if len(chartClassifyList) == 0 {
+			page := paging.GetPaging(currentIndex, pageSize, 0)
+			resp := data_manage.ChartInfoListByEsResp{
+				Paging: page,
+				List:   make([]*data_manage.ChartInfoMore, 0),
+			}
+			br.Ret = 200
+			br.Success = true
+			br.Msg = "获取成功"
+			br.Data = resp
+			return
+		}
+		for _, v := range chartClassifyList {
+			chartClassifyIds = append(chartClassifyIds, v.ChartClassifyId)
+		}
+	}
 
 	//只看我的
 	isShowMe, _ := this.GetBool("IsShowMe")
@@ -2317,10 +2346,10 @@ func (this *ChartInfoController) ChartInfoSearchByEs() {
 	// 是否走ES
 	isEs := false
 	if keyword != "" {
-		searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, []int{utils.CHART_SOURCE_DEFAULT}, noPermissionChartIdList, startSize, pageSize)
+		searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, []int{utils.CHART_SOURCE_DEFAULT}, noPermissionChartIdList, startSize, pageSize, chartClassifyIds)
 		isEs = true
 	} else {
-		total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, []int{utils.CHART_SOURCE_DEFAULT}, noPermissionChartIdList, startSize, pageSize)
+		total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, []int{utils.CHART_SOURCE_DEFAULT}, noPermissionChartIdList, startSize, pageSize, chartClassifyIds)
 		if err != nil && !utils.IsErrNoRow(err) {
 			br.Msg = "获取失败"
 			br.ErrMsg = "获取图表信息失败,Err:" + err.Error()

+ 2 - 2
controllers/data_manage/correlation/correlation_chart_info.go

@@ -1964,9 +1964,9 @@ func (this *CorrelationChartInfoController) SearchByEs() {
 	}
 
 	if keyword != "" {
-		searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
+		searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize, []int{})
 	} else {
-		total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
+		total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, sourceList, noPermissionChartIdList, startSize, pageSize, []int{})
 		if err != nil && !utils.IsErrNoRow(err) {
 			br.Msg = "获取失败"
 			br.ErrMsg = "获取图表信息失败,Err:" + err.Error()

+ 2 - 2
controllers/data_manage/cross_variety/chart_info.go

@@ -1471,9 +1471,9 @@ func (c *ChartInfoController) SearchByEs() {
 	}
 
 	if keyword != "" {
-		searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
+		searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize, []int{})
 	} else {
-		total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
+		total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, sourceList, noPermissionChartIdList, startSize, pageSize, []int{})
 		if err != nil && !utils.IsErrNoRow(err) {
 			br.Msg = "获取失败"
 			br.ErrMsg = "获取图表信息失败,Err:" + err.Error()

+ 2 - 2
controllers/data_manage/future_good/future_good_chart_info.go

@@ -2411,9 +2411,9 @@ func (this *FutureGoodChartInfoController) ChartInfoSearchByEs() {
 	}
 
 	if keyword != "" {
-		searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, []int{utils.CHART_SOURCE_FUTURE_GOOD, utils.CHART_SOURCE_FUTURE_GOOD_PROFIT}, noPermissionChartIdList, startSize, pageSize)
+		searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, []int{utils.CHART_SOURCE_FUTURE_GOOD, utils.CHART_SOURCE_FUTURE_GOOD_PROFIT}, noPermissionChartIdList, startSize, pageSize, []int{})
 	} else {
-		total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, []int{utils.CHART_SOURCE_FUTURE_GOOD, utils.CHART_SOURCE_FUTURE_GOOD_PROFIT}, noPermissionChartIdList, startSize, pageSize)
+		total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, []int{utils.CHART_SOURCE_FUTURE_GOOD, utils.CHART_SOURCE_FUTURE_GOOD_PROFIT}, noPermissionChartIdList, startSize, pageSize, []int{})
 		if err != nil && !utils.IsErrNoRow(err) {
 			br.Msg = "获取失败"
 			br.ErrMsg = "获取图表信息失败,Err:" + err.Error()

+ 2 - 2
controllers/data_manage/line_equation/line_chart_info.go

@@ -1634,9 +1634,9 @@ func (this *LineEquationChartInfoController) SearchByEs() {
 	}
 
 	if keyword != "" {
-		searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
+		searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize, []int{})
 	} else {
-		total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
+		total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, sourceList, noPermissionChartIdList, startSize, pageSize, []int{})
 		if err != nil && !utils.IsErrNoRow(err) {
 			br.Msg = "获取失败"
 			br.ErrMsg = "获取图表信息失败,Err:" + err.Error()

+ 2 - 2
controllers/data_manage/line_feature/chart_info.go

@@ -2781,9 +2781,9 @@ func (this *LineFeaturesChartInfoController) SearchByEs() {
 	}
 
 	if keyword != "" {
-		searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
+		searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize, []int{})
 	} else {
-		total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
+		total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, sourceList, noPermissionChartIdList, startSize, pageSize, []int{})
 		if err != nil && !utils.IsErrNoRow(err) {
 			br.Msg = "获取失败"
 			br.ErrMsg = "获取图表信息失败,Err:" + err.Error()

+ 26 - 14
controllers/data_manage/my_chart.go

@@ -70,30 +70,42 @@ func (this *MyChartController) ChartList() {
 	condition += ` AND source = ? `
 	pars = append(pars, utils.CHART_SOURCE_DEFAULT)
 
-	chartClassifyIds := make([]int, 0)
-	if chartClassifyId > 0 {
+	// 是否显示精选资源
+	isSelected, _ := this.GetInt("IsSelected", -1)
 
-		list, e := data_manage.GetChartClassifyAllBySource(utils.CHART_SOURCE_DEFAULT)
-		if e != nil {
+	chartClassifyIds := make([]int, 0)
+	var classifyList []*data_manage.ChartClassifyItems
+	var err error
+	if isSelected >= 0 {
+		classifyList, err = data_manage.GetChartClassifyAllBySourceIsSelected(utils.CHART_SOURCE_DEFAULT, isSelected)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = fmt.Sprintf("获取图表分类失败, Err: %v", err)
+			return
+		}
+	} else {
+		classifyList, err = data_manage.GetChartClassifyAllBySource(utils.CHART_SOURCE_DEFAULT)
+		if err != nil {
 			br.Msg = "获取失败"
-			br.ErrMsg = fmt.Sprintf("获取图表分类失败, Err: %v", e)
+			br.ErrMsg = fmt.Sprintf("获取图表分类失败, Err: %v", err)
 			return
 		}
-		parents := data.GetChartClassifyChildrenRecursive(list, chartClassifyId)
+	}
+	if chartClassifyId > 0 {
+		parents := data.GetChartClassifyChildrenRecursive(classifyList, chartClassifyId)
 		sort.Slice(parents, func(i, j int) bool {
 			return parents[i].Level < parents[i].Level
 		})
 		for _, v := range parents {
 			chartClassifyIds = append(chartClassifyIds, v.ChartClassifyId)
 		}
-
-		//chartClassifyId, err := data_manage.GetChartClassify(chartClassifyId)
-		//if err != nil && err.Error() != utils.ErrNoRow() {
-		//	br.Msg = "获取图表信息失败"
-		//	br.ErrMsg = "获取信息失败,GetChartClassify,Err:" + err.Error()
-		//	return
-		//}
-		condition += " AND chart_classify_id IN(" + utils.GetOrmInReplace(len(chartClassifyIds)) + ") "
+		condition += " AND chart_classify_id IN (" + utils.GetOrmInReplace(len(chartClassifyIds)) + ") "
+		pars = append(pars, chartClassifyIds)
+	} else if isSelected >= 0 {
+		for _, v := range classifyList {
+			chartClassifyIds = append(chartClassifyIds, v.ChartClassifyId)
+		}
+		condition += " AND chart_classify_id IN (" + utils.GetOrmInReplace(len(chartClassifyIds)) + ") "
 		pars = append(pars, chartClassifyIds)
 	}
 

+ 2 - 2
controllers/data_manage/range_analysis/chart_info.go

@@ -1838,9 +1838,9 @@ func (this *RangeChartChartInfoController) SearchByEs() {
 	}
 
 	if keyword != "" {
-		searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
+		searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize, []int{})
 	} else {
-		total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
+		total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, sourceList, noPermissionChartIdList, startSize, pageSize, []int{})
 		if err != nil && !utils.IsErrNoRow(err) {
 			br.Msg = "获取失败"
 			br.ErrMsg = "获取图表信息失败,Err:" + err.Error()

+ 2 - 2
controllers/trade_analysis/warehouse.go

@@ -1305,9 +1305,9 @@ func (this *WarehouseController) SearchByEs() {
 	}
 
 	if keyword != "" {
-		searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
+		searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize, []int{})
 	} else {
-		total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
+		total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, sourceList, noPermissionChartIdList, startSize, pageSize, []int{})
 		if err != nil && !utils.IsErrNoRow(err) {
 			br.Msg = "获取失败"
 			br.ErrMsg = "获取图表信息失败,Err:" + err.Error()

+ 9 - 2
models/data_manage/chart_classify.go

@@ -577,6 +577,13 @@ func GetChartClassifyAllBySource(source int) (items []*ChartClassifyItems, err e
 	return
 }
 
+// GetChartClassifyAllBySourceIsSelected 根据来源获取所有精选分类
+func GetChartClassifyAllBySourceIsSelected(source int, isSelected int) (items []*ChartClassifyItems, err error) {
+	sql := ` SELECT * FROM chart_classify WHERE source = ? AND is_selected = ? ORDER BY parent_id ASC, sort ASC, chart_classify_id ASC`
+	err = global.DbMap[utils.DbNameIndex].Raw(sql, source, isSelected).Find(&items).Error
+	return
+}
+
 // GetChartClassifyInfoSelectedBySource 获取所有的精选目录
 func GetChartClassifyInfoSelectedBySource(source int) (items []*ChartClassify, err error) {
 	sql := ` SELECT * FROM chart_classify WHERE source = ? AND is_selected = ? ORDER BY parent_id ASC, sort ASC, chart_classify_id ASC`
@@ -661,7 +668,7 @@ WHERE
 ORDER BY
 	sort ASC,
 	chart_classify_id ASC`
-	err = global.DbMap[utils.DbNameIndex].Raw(sql, parentId, isSelected, parentId).Find(&items).Error
+	err = global.DbMap[utils.DbNameIndex].Raw(sql, parentId, parentId, isSelected).Find(&items).Error
 	return
 }
 
@@ -708,7 +715,7 @@ WHERE
 ORDER BY
 	sort ASC,
 	chart_classify_id ASC`
-	err = global.DbMap[utils.DbNameIndex].Raw(sql, parentId, isSelected,parentId, adminId).Find(&items).Error
+	err = global.DbMap[utils.DbNameIndex].Raw(sql, parentId, parentId, adminId, isSelected).Find(&items).Error
 	return
 }
 

+ 7 - 1
models/data_manage/chart_info.go

@@ -817,6 +817,7 @@ type ChartInfoDetailResp struct {
 	CorrelationChartInfo *CorrelationInfo `description:"相关性图表信息"`
 	DataResp             interface{}      `description:"图表数据,根据图的类型而定的,没有确定的数据格式"`
 	ClassifyLevels       []string         `description:"图表分类的UniqueCode-从最顶级到当前分类(给前端回显定位用的=_=!)"`
+	IsSelected        int             `description:"是否为精选目录下的图表,0:否;1:是;默认:0"`
 }
 
 type FutureGoodChartInfoDetailResp struct {
@@ -1763,7 +1764,7 @@ func ChartInfoSearchByKeyWord(keyword string, showSysId int) (searchList []*Char
 }
 
 // ChartInfoSearchByEmptyKeyWord 没有关键字的时候获取默认100条数据
-func ChartInfoSearchByEmptyKeyWord(showSysId int, sourceList []int, noPermissionChartIdList []int, startSize, pageSize int) (total int64, searchList []*ChartInfoMore, err error) {
+func ChartInfoSearchByEmptyKeyWord(showSysId int, sourceList []int, noPermissionChartIdList []int, startSize, pageSize int, chartClassifyIds []int) (total int64, searchList []*ChartInfoMore, err error) {
 	num := len(sourceList)
 	o := global.DbMap[utils.DbNameIndex]
 
@@ -1783,6 +1784,11 @@ func ChartInfoSearchByEmptyKeyWord(showSysId int, sourceList []int, noPermission
 		basePars = append(basePars, noPermissionChartIdList)
 	}
 
+	if len(chartClassifyIds) > 0 {
+		baseSql += ` AND chart_classify_id in (` + utils.GetOrmInReplace(len(chartClassifyIds)) + `) `
+		basePars = append(basePars, chartClassifyIds)
+	}
+
 	// 查找数量
 	totalSql := " SELECT count(1) as total " + baseSql
 	err = o.Raw(totalSql, basePars...).Scan(&total).Error

+ 2 - 2
services/data/chart_info_elastic.go

@@ -125,8 +125,8 @@ func EsDeleteChartInfo(chartInfoId int) {
 }
 
 // EsSearchChartInfo 搜索图表信息
-func EsSearchChartInfo(keyword string, showSysId int, sourceList []int, noPermissionChartIdList []int, startSize, pageSize int) (list []*data_manage.ChartInfoMore, total int64, err error) {
-	list, total, err = elastic.SearchChartInfoData(utils.CHART_INDEX_NAME, keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize)
+func EsSearchChartInfo(keyword string, showSysId int, sourceList []int, noPermissionChartIdList []int, startSize, pageSize int, chartClassifyIds []int) (list []*data_manage.ChartInfoMore, total int64, err error) {
+	list, total, err = elastic.SearchChartInfoData(utils.CHART_INDEX_NAME, keyword, showSysId, sourceList, noPermissionChartIdList, startSize, pageSize, chartClassifyIds)
 	return
 }
 

+ 8 - 1
services/elastic/elastic.go

@@ -1101,7 +1101,7 @@ func EsDeleteDataV2(indexName, docId string) (err error) {
 }
 
 // SearchChartInfoData 查询es中的图表数据
-func SearchChartInfoData(indexName, keywordStr string, showSysId int, sourceList []int, noPermissionChartIdList []int, from, size int) (list []*data_manage.ChartInfoMore, total int64, err error) {
+func SearchChartInfoData(indexName, keywordStr string, showSysId int, sourceList []int, noPermissionChartIdList []int, from, size int, chartClassifyIds []int) (list []*data_manage.ChartInfoMore, total int64, err error) {
 	list = make([]*data_manage.ChartInfoMore, 0)
 	defer func() {
 		if err != nil {
@@ -1218,6 +1218,13 @@ func SearchChartInfoData(indexName, keywordStr string, showSysId int, sourceList
 			},
 		})
 	}
+	if len(chartClassifyIds) > 0 {
+		mustMap = append(mustMap, map[string]interface{}{
+			"terms": map[string]interface{}{
+				"ChartClassifyId": chartClassifyIds,
+			},
+		})
+	}
 
 	queryMap := map[string]interface{}{
 		"query": map[string]interface{}{