Browse Source

睿姿的分类 导出

gmy 4 months ago
parent
commit
9b5d6e820e

+ 20 - 2
controllers/data_manage/base_from_rzd_index_controller.go

@@ -142,7 +142,19 @@ func (this *BaseFromRzdIndexController) RzdIndexDetail() {
 
 	indexCode := this.GetString("IndexCode")
 
-	indexDetail, err := data.GetRzdIndexDetail(indexCode)
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	var startSize int
+
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = utils.StartIndex(currentIndex, pageSize)
+
+	indexDetail, err := data.GetRzdIndexDetail(indexCode, currentIndex, startSize, pageSize)
 	if err != nil {
 		return
 	}
@@ -478,8 +490,14 @@ func (this *BaseFromRzdIndexController) RzdIndexDataExport() {
 	downLoadFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
 	xlsxFile := xlsx.NewFile()
 
-	var classifyIdList []int
+	classifyIdList, err := data.RzdClassifyRecursiveQuery(classifyId)
+	if err != nil {
+		br.Msg = "查询分类失败"
+		br.ErrMsg = "查询分类失败"
+		return
+	}
 	classifyIdList = append(classifyIdList, classifyId)
+
 	frequencies, err := data_manage.GetRzdIndexFrequency(classifyIdList)
 	if err != nil {
 		br.Msg = "查询频度失败"

+ 23 - 0
models/data_manage/base_from_rzd_data.go

@@ -62,6 +62,29 @@ func GetBaseFormRzdDataByIndexCode(indexCode string) (items []*BaseFromRzdData,
 	return
 }
 
+func GetBaseFormRzdDataByConditionCount(condition string, pars interface{}) (count int, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT count(1) FROM base_from_rzd_data WHERE 1=1  `
+	if condition != "" {
+		sql += condition
+	}
+	err = o.Raw(sql, pars).QueryRow(&count)
+	if err != nil {
+		return 0, err
+	}
+	return
+}
+
+func GetBaseFormRzdDataByCondition(condition string, pars interface{}) (items []*BaseFromRzdData, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT * FROM base_from_rzd_data WHERE 1=1  `
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
 // GetRzdDataListByIndexCodes 根据指标编码查询
 func GetRzdDataListByIndexCodes(IndexCodes string) (items []string, err error) {
 	sql := ` SELECT data_time FROM base_from_rzd_data WHERE index_code IN(` + IndexCodes + `)  GROUP BY data_time DESC `

+ 30 - 9
services/data/base_from_rzd_index_service.go

@@ -17,7 +17,7 @@ func RzdIndexData(classifyId int, frequency string, currentIndex, startSize, pag
 	var pars []interface{}
 	if classifyId >= 0 {
 		// 递归查询子集分类
-		classifyIdList, err := recursiveQuery(classifyId)
+		classifyIdList, err := RzdClassifyRecursiveQuery(classifyId)
 		if err != nil {
 			return nil, err
 		}
@@ -99,8 +99,8 @@ func RzdIndexData(classifyId int, frequency string, currentIndex, startSize, pag
 	return resultList, nil
 }
 
-// 递归查询分类
-func recursiveQuery(classifyId int) ([]int, error) {
+// RzdClassifyRecursiveQuery 递归查询分类
+func RzdClassifyRecursiveQuery(classifyId int) ([]int, error) {
 	var classifyIdList []int
 
 	// 查询当前分类 ID 的子分类
@@ -115,7 +115,7 @@ func recursiveQuery(classifyId int) ([]int, error) {
 		classifyIdList = append(classifyIdList, classify.BaseFromRzdClassifyId)
 
 		// 递归查询当前子分类的子分类
-		childIds, err := recursiveQuery(classify.BaseFromRzdClassifyId)
+		childIds, err := RzdClassifyRecursiveQuery(classify.BaseFromRzdClassifyId)
 		if err != nil {
 			return nil, err
 		}
@@ -129,7 +129,7 @@ func recursiveQuery(classifyId int) ([]int, error) {
 
 func GetRzdIndexFrequency(classify int) ([]*string, error) {
 
-	classifyIdList, err := recursiveQuery(classify)
+	classifyIdList, err := RzdClassifyRecursiveQuery(classify)
 	if err != nil {
 		return nil, err
 	}
@@ -148,7 +148,7 @@ func RzdIndexAddValidate(req *data_manage.BaseFromRzdIndexBatchAddCheckReq) ([]*
 	var pars []interface{}
 
 	if req.IsCheckAll {
-		if len(req.ClassifyIdList) >= 0 {
+		if len(req.ClassifyIdList) > 0 {
 			condition += ` AND base_from_rzd_classify_id in (` + utils.GetOrmInReplace(len(req.ClassifyIdList)) + `)`
 			for _, id := range req.ClassifyIdList {
 				pars = append(pars, id)
@@ -366,7 +366,7 @@ func GetRzdIndexInfo(keyWord string, classifyIdList []string, frequencyList []st
 }
 
 // GetRzdIndexDetail 获取指标详情
-func GetRzdIndexDetail(indexCode string) (rzdIndexInfoList *data_manage.BaseFromRzdIndexList, err error) {
+func GetRzdIndexDetail(indexCode string, currentIndex, startSize, pageSize int) (rzdIndexInfoList *data_manage.BaseFromRzdIndexList, err error) {
 
 	// 获取指标
 	var condition string
@@ -384,11 +384,32 @@ func GetRzdIndexDetail(indexCode string) (rzdIndexInfoList *data_manage.BaseFrom
 	if len(rzdIndexList) > 0 {
 		rzdIndex = rzdIndexList[0]
 		// 查询指标数据
-		dataList, err := data_manage.GetBaseFormRzdDataByIndexCode(indexCode)
+		var condition string
+		var pars []interface{}
+		condition += ` and index_code = ?`
+		pars = append(pars, indexCode)
+
+		count, err := data_manage.GetBaseFormRzdDataByConditionCount(condition, pars)
 		if err != nil {
 			return nil, err
 		}
-		rzdIndex.DataList = dataList
+		pagingItem := paging.GetPaging(currentIndex, pageSize, count)
+		if count <= 0 {
+			rzdIndex.Paging = pagingItem
+		} else {
+			condition += ` ORDER BY data_time desc`
+
+			condition += ` LIMIT ?, ?`
+			pars = append(pars, startSize, pageSize)
+
+			dataList, err := data_manage.GetBaseFormRzdDataByCondition(condition, pars)
+			if err != nil {
+				return nil, err
+			}
+
+			rzdIndex.Paging = pagingItem
+			rzdIndex.DataList = dataList
+		}
 
 		// 查询是否在指标库
 		edbInfo, err := data_manage.GetEdbInfoByEdbCode(utils.DATA_SOURCE_RZD, indexCode)