|
@@ -6,8 +6,142 @@ import (
|
|
|
"eta/eta_api/models/data_manage"
|
|
|
"eta/eta_api/utils"
|
|
|
"fmt"
|
|
|
+ "github.com/rdlucklib/rdluck_tools/paging"
|
|
|
)
|
|
|
|
|
|
+// RzdIndexData 获取睿姿得指标数据
|
|
|
+func RzdIndexData(classifyId int, frequency string, currentIndex, startSize, pageSize int) (dataList []*data_manage.BaseFromRzdIndexList, err error) {
|
|
|
+
|
|
|
+ // 获取指标
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+ if classifyId >= 0 {
|
|
|
+ // 递归查询子集分类
|
|
|
+ classifyIdList, err := recursiveQuery(classifyId)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ classifyIdList = append(classifyIdList, classifyId)
|
|
|
+
|
|
|
+ interfaceClassifyIdList := make([]interface{}, len(classifyIdList))
|
|
|
+ for i, id := range classifyIdList {
|
|
|
+ interfaceClassifyIdList[i] = id
|
|
|
+ }
|
|
|
+
|
|
|
+ condition += ` AND base_from_rzd_classify_id in (` + utils.GetOrmInReplace(len(classifyIdList)) + `)`
|
|
|
+ pars = append(pars, interfaceClassifyIdList...)
|
|
|
+ }
|
|
|
+
|
|
|
+ if frequency != "" {
|
|
|
+ condition += ` AND frequency=? `
|
|
|
+ pars = append(pars, frequency)
|
|
|
+ }
|
|
|
+
|
|
|
+ indexes, err := data_manage.GetRzdIndex(condition, pars)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ indexCodes := make([]string, 0)
|
|
|
+ for _, v := range indexes {
|
|
|
+ indexCodes = append(indexCodes, v.IndexCode)
|
|
|
+ }
|
|
|
+ indexCounts, e := data_manage.GetRzdIndexDataCountGroup(indexCodes)
|
|
|
+ if e != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ countMap := make(map[string]int)
|
|
|
+ for _, v := range indexCounts {
|
|
|
+ countMap[v.IndexCode] = v.Count
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断是否存在于指标库
|
|
|
+ edbCodeList, err := data_manage.GetEdbInfoByEdbCodeList(utils.DATA_SOURCE_RZD, indexCodes)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ edbCodeMap := make(map[string]*data_manage.EdbInfo)
|
|
|
+ for _, v := range edbCodeList {
|
|
|
+ edbCodeMap[v.EdbCode] = v
|
|
|
+ }
|
|
|
+
|
|
|
+ resultList := make([]*data_manage.BaseFromRzdIndexList, 0)
|
|
|
+ for _, v := range indexes {
|
|
|
+ product := new(data_manage.BaseFromRzdIndexList)
|
|
|
+ product.BaseFromRzdIndexId = v.BaseFromRzdIndexId
|
|
|
+ product.BaseFromRzdClassifyId = v.BaseFromRzdClassifyId
|
|
|
+ product.Unit = v.Unit
|
|
|
+ product.IndexCode = v.IndexCode
|
|
|
+ product.IndexName = v.IndexName
|
|
|
+ product.Frequency = v.Frequency
|
|
|
+ product.CreateTime = v.CreateTime
|
|
|
+ product.ModifyTime = v.ModifyTime
|
|
|
+
|
|
|
+ edbInfo := edbCodeMap[v.IndexCode]
|
|
|
+ if edbInfo != nil {
|
|
|
+ product.EdbInfoId = edbInfo.EdbInfoId
|
|
|
+ }
|
|
|
+
|
|
|
+ total := countMap[v.IndexCode]
|
|
|
+ page := paging.GetPaging(currentIndex, pageSize, total)
|
|
|
+ indexDataList, e := data_manage.GetRzdIndexData(v.IndexCode, startSize, pageSize)
|
|
|
+ if e != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ if indexDataList == nil {
|
|
|
+ indexDataList = make([]*data_manage.BaseFromRzdData, 0)
|
|
|
+ }
|
|
|
+ product.DataList = indexDataList
|
|
|
+ product.Paging = page
|
|
|
+ resultList = append(resultList, product)
|
|
|
+ }
|
|
|
+
|
|
|
+ return resultList, nil
|
|
|
+}
|
|
|
+
|
|
|
+// 递归查询分类
|
|
|
+func recursiveQuery(classifyId int) ([]int, error) {
|
|
|
+ var classifyIdList []int
|
|
|
+
|
|
|
+ // 查询当前分类 ID 的子分类
|
|
|
+ rzdClassifyList, err := GetRzdClassifyItemByParentId(classifyId)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ // 遍历子分类
|
|
|
+ for _, classify := range rzdClassifyList {
|
|
|
+ // 将当前子分类的 ID 添加到列表中
|
|
|
+ classifyIdList = append(classifyIdList, classify.BaseFromRzdClassifyId)
|
|
|
+
|
|
|
+ // 递归查询当前子分类的子分类
|
|
|
+ childIds, err := recursiveQuery(classify.BaseFromRzdClassifyId)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ // 合并子分类的 ID
|
|
|
+ classifyIdList = append(classifyIdList, childIds...)
|
|
|
+ }
|
|
|
+
|
|
|
+ return classifyIdList, nil
|
|
|
+}
|
|
|
+
|
|
|
+func GetRzdIndexFrequency(classify int) ([]*string, error) {
|
|
|
+
|
|
|
+ classifyIdList, err := recursiveQuery(classify)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ classifyIdList = append(classifyIdList, classify)
|
|
|
+
|
|
|
+ frequencyNameList, err := data_manage.GetRzdIndexFrequency(classifyIdList)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ return frequencyNameList, nil
|
|
|
+}
|
|
|
+
|
|
|
// RzdIndexAddValidate 指标添加校验
|
|
|
func RzdIndexAddValidate(indexCodes []string) (*[]data_manage.RzdIndexCheckData, error) {
|
|
|
// 根据指标编码获取指标库 指标信息
|
|
@@ -128,16 +262,17 @@ func RzdIndexAdd(req data_manage.RzdIndexAddReq, lang string) (edb *data_manage.
|
|
|
}
|
|
|
|
|
|
// GetRzdIndexInfo 获取指标信息-分页
|
|
|
-func GetRzdIndexInfo(keyWord string, classifyIdList []string, frequencyList []string) (rzdIndexInfoList []*data_manage.BaseFromRzdIndex, err error) {
|
|
|
+func GetRzdIndexInfo(keyWord string, classifyIdList []string, frequencyList []string, currentIndex, startSize, pageSize int) (rzdIndexInfoList *data_manage.BaseFromRzdIndexPage, err error) {
|
|
|
|
|
|
// 获取指标
|
|
|
var condition string
|
|
|
var pars []interface{}
|
|
|
if keyWord != "" {
|
|
|
condition += ` AND CONCAT(index_name,index_code) LIKE '%` + keyWord + `%'`
|
|
|
+ pars = append(pars, keyWord)
|
|
|
}
|
|
|
if len(classifyIdList) > 0 {
|
|
|
- condition += ` AND classify_id IN (`
|
|
|
+ condition += ` AND base_from_rzd_classify_id IN (`
|
|
|
for _, v := range classifyIdList {
|
|
|
condition += `?,`
|
|
|
pars = append(pars, v)
|
|
@@ -153,12 +288,50 @@ func GetRzdIndexInfo(keyWord string, classifyIdList []string, frequencyList []st
|
|
|
condition = condition[:len(condition)-1] + `)`
|
|
|
}
|
|
|
|
|
|
- rzdIndexInfoList, err = data_manage.GetRzdIndexInfoPage(condition, pars)
|
|
|
+ condition += ` ORDER BY base_from_rzd_index_id asc`
|
|
|
+
|
|
|
+ // 分页
|
|
|
+ condition += ` LIMIT ?, ?`
|
|
|
+ pars = append(pars, startSize, pageSize)
|
|
|
+
|
|
|
+ count, err := data_manage.GetRzdIndexInfoCount(condition, pars)
|
|
|
if err != nil {
|
|
|
- return
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ indexPage := data_manage.BaseFromRzdIndexPage{}
|
|
|
+ page := paging.GetPaging(currentIndex, pageSize, count)
|
|
|
+ if count <= 0 {
|
|
|
+ indexPage.Paging = page
|
|
|
+ return &indexPage, nil
|
|
|
}
|
|
|
|
|
|
- return
|
|
|
+ indexInfoPage, err := data_manage.GetRzdIndexInfoPage(condition, pars)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ var indexCodes []string
|
|
|
+ for _, indexInfo := range indexInfoPage {
|
|
|
+ indexCodes = append(indexCodes, indexInfo.IndexCode)
|
|
|
+ }
|
|
|
+ IndexDataList, err := data_manage.GetRzdLastUpdateTimeLastByIndexCode(indexCodes)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ var indexDataMap = make(map[string]*data_manage.BaseFromRzdData, 0)
|
|
|
+ for _, data := range IndexDataList {
|
|
|
+ indexDataMap[data.IndexCode] = data
|
|
|
+ }
|
|
|
+ for _, indexInfo := range indexInfoPage {
|
|
|
+ if indexDataMap[indexInfo.IndexCode] == nil {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ indexInfo.ModifyTimeMax = indexDataMap[indexInfo.IndexCode].ModifyTime
|
|
|
+ indexInfo.Value = indexDataMap[indexInfo.IndexCode].Value
|
|
|
+ }
|
|
|
+
|
|
|
+ indexPage.List = indexInfoPage
|
|
|
+ indexPage.Paging = page
|
|
|
+ return &indexPage, nil
|
|
|
}
|
|
|
|
|
|
// GetRzdIndexDetail 获取指标详情
|