Browse Source

Merge branch 'feature/eta_2.4.8' into debug

hsun 3 weeks ago
parent
commit
d97cd38556

+ 70 - 7
controllers/data_manage/base_from_radish_research.go

@@ -55,6 +55,7 @@ func (this *BaseFromRadishResearchController) IndexPageList() {
 	}
 	resp := new(data_manage.RadishResearchIndexPageListResp)
 	resp.List = make([]*data_manage.BaseFromRadishResearchIndexItem, 0)
+	classifyId, _ := this.GetInt("ClassifyId", -1)
 
 	// 分页查询
 	var startSize int
@@ -73,9 +74,33 @@ func (this *BaseFromRadishResearchController) IndexPageList() {
 		pars        []interface{}
 		classifyIds []int
 	)
+	// 未分类
+	if classifyId == 0 {
+		cond += fmt.Sprintf(` AND %s = ?`, indexOb.Cols().ClassifyId)
+		pars = append(pars, classifyId)
+	}
+	// 包含所有子分类的指标
+	if classifyId > 0 {
+		classifyOb := new(data_manage.BaseFromRadishResearchClassify)
+		classifies, e := classifyOb.GetItemsByCondition(fmt.Sprintf(" AND FIND_IN_SET(%d, %s)", classifyId, classifyOb.Cols().LevelPath), make([]interface{}, 0), []string{classifyOb.Cols().PrimaryId}, fmt.Sprintf("%s ASC, %s ASC", classifyOb.Cols().ParentId, classifyOb.Cols().Sort))
+		if e != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = fmt.Sprintf("获取子分类IDs失败, %v", e)
+			return
+		}
+		for _, v := range classifies {
+			if v.BaseFromRadishResearchClassifyId <= 0 {
+				continue
+			}
+			classifyIds = append(classifyIds, v.BaseFromRadishResearchClassifyId)
+		}
+		if len(classifyIds) > 0 {
+			cond += fmt.Sprintf(` AND %s IN ?`, indexOb.Cols().ClassifyId)
+			pars = append(pars, classifyIds)
+		}
+	}
+	// 分类多选
 	params.ClassifyIds = strings.TrimSpace(params.ClassifyIds)
-	params.Frequencies = strings.TrimSpace(params.Frequencies)
-	params.Keyword = strings.TrimSpace(params.Keyword)
 	if params.ClassifyIds != "" {
 		idsArr := strings.Split(params.ClassifyIds, ",")
 		for _, v := range idsArr {
@@ -89,6 +114,8 @@ func (this *BaseFromRadishResearchController) IndexPageList() {
 			pars = append(pars, classifyIds)
 		}
 	}
+	// 频度多选
+	params.Frequencies = strings.TrimSpace(params.Frequencies)
 	if params.Frequencies != "" {
 		freArr := strings.Split(params.Frequencies, ",")
 		if len(freArr) > 0 {
@@ -96,11 +123,14 @@ func (this *BaseFromRadishResearchController) IndexPageList() {
 			pars = append(pars, freArr)
 		}
 	}
+	// 关键词
+	params.Keyword = strings.TrimSpace(params.Keyword)
 	if params.Keyword != "" {
 		kw := fmt.Sprint("%", params.Keyword, "%")
 		cond += fmt.Sprintf(` AND (%s LIKE ? OR %s LIKE ?)`, indexOb.Cols().IndexName, indexOb.Cols().IndexCode)
 		pars = append(pars, kw, kw)
 	}
+	// 是否忽略已加入指标库的
 	if params.IgnoreEdbExist {
 		cond += fmt.Sprintf(` AND %s = 0`, indexOb.Cols().EdbExist)
 	}
@@ -408,7 +438,39 @@ func (this *BaseFromRadishResearchController) IndexExport() {
 		br.Ret = 408
 		return
 	}
-	classifyId, _ := this.GetInt("ClassifyId")
+	classifyId, _ := this.GetInt("ClassifyId", -1)
+
+	var (
+		cond        string
+		pars        []interface{}
+		classifyIds []int
+	)
+	// 未分类
+	indexOb := new(data_manage.BaseFromRadishResearchIndex)
+	if classifyId == 0 {
+		cond += fmt.Sprintf(` AND %s = ?`, indexOb.Cols().ClassifyId)
+		pars = append(pars, classifyId)
+	}
+	// 包含所有子分类的指标
+	if classifyId > 0 {
+		classifyOb := new(data_manage.BaseFromRadishResearchClassify)
+		classifies, e := classifyOb.GetItemsByCondition(fmt.Sprintf(" AND FIND_IN_SET(%d, %s)", classifyId, classifyOb.Cols().LevelPath), make([]interface{}, 0), []string{classifyOb.Cols().PrimaryId}, fmt.Sprintf("%s ASC, %s ASC", classifyOb.Cols().ParentId, classifyOb.Cols().Sort))
+		if e != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = fmt.Sprintf("获取子分类IDs失败, %v", e)
+			return
+		}
+		for _, v := range classifies {
+			if v.BaseFromRadishResearchClassifyId <= 0 {
+				continue
+			}
+			classifyIds = append(classifyIds, v.BaseFromRadishResearchClassifyId)
+		}
+		if len(classifyIds) > 0 {
+			cond += fmt.Sprintf(` AND %s IN ?`, indexOb.Cols().ClassifyId)
+			pars = append(pars, classifyIds)
+		}
+	}
 
 	dir, _ := os.Executable()
 	exPath := filepath.Dir(dir)
@@ -416,10 +478,6 @@ func (this *BaseFromRadishResearchController) IndexExport() {
 	xlsxFile := xlsx.NewFile()
 
 	// 获取指标数据
-	indexOb := new(data_manage.BaseFromRadishResearchIndex)
-	cond := fmt.Sprintf(` AND %s = ?`, indexOb.Cols().ClassifyId)
-	pars := make([]interface{}, 0)
-	pars = append(pars, classifyId)
 	indexes, e := indexOb.GetItemsByCondition(cond, pars, []string{}, fmt.Sprintf("%s ASC, %s ASC", indexOb.Cols().Sort, indexOb.Cols().PrimaryId))
 	if e != nil {
 		br.Msg = "获取失败"
@@ -444,6 +502,11 @@ func (this *BaseFromRadishResearchController) IndexExport() {
 				return
 			}
 		}
+		fileName := fmt.Sprintf("%s%s%s", utils.DATA_SOURCE_NAME_RADISH_RESEARCH, time.Now().Format("06.01.02"), ".xlsx")
+		this.Ctx.Output.Download(downFile, fileName)
+		defer func() {
+			_ = os.Remove(downFile)
+		}()
 		return
 	}
 

+ 1 - 0
models/data_manage/base_from_radish_research_index.go

@@ -369,6 +369,7 @@ type RadishResearchIndexMultiOptReq struct {
 type RadishResearchIndexListForm struct {
 	PageSize       int    `form:"PageSize" description:"每页数据量"`
 	CurrentIndex   int    `form:"CurrentIndex" description:"页码"`
+	ClassifyId     int    `form:"ClassifyId" description:"分类ID(查询结果包含所有子分类指标)"`
 	ClassifyIds    string `form:"ClassifyIds" description:"分类IDs"`
 	IgnoreEdbExist bool   `form:"IgnoreEdbExist" description:"忽略已加入指标库的"`
 	Frequencies    string `form:"Frequencies" description:"频度(多选)"`