|
@@ -917,7 +917,6 @@ func (this *EdbInfoController) ExportYongyiList() {
|
|
|
br.Msg = "请选择分类"
|
|
|
return
|
|
|
}
|
|
|
- secNameList := make([]*data_manage.BaseFromYongyiIndex, 0)
|
|
|
dir, _ := os.Executable()
|
|
|
exPath := filepath.Dir(dir)
|
|
|
downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
|
|
@@ -962,22 +961,50 @@ func (this *EdbInfoController) ExportYongyiList() {
|
|
|
condition += ` AND index_code=? `
|
|
|
pars = append(pars, indexCode)
|
|
|
}
|
|
|
- frequencies, err := data_manage.GetYongyiFrequencyByCondition(condition, pars)
|
|
|
+
|
|
|
+ indexList, err := data_manage.GetYongyiIndex(condition, pars)
|
|
|
if err != nil {
|
|
|
- fmt.Println("GetSciFrequency err:", err.Error())
|
|
|
- utils.FileLog.Info("GetSciFrequency err:" + err.Error())
|
|
|
+ fmt.Println("获取数据失败,Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(indexList) <= 0 {
|
|
|
+ fmt.Println("indexList 为空")
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "success"
|
|
|
return
|
|
|
}
|
|
|
- for _, frequency := range frequencies {
|
|
|
- //获取指标
|
|
|
|
|
|
- secNameList, err = data_manage.GetYongyiByConditionAndFrequency(condition, frequency, pars)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("获取数据失败,Err:" + err.Error())
|
|
|
+ indexCodeList := make([]string, 0)
|
|
|
+ frequenciesMap := make(map[string][]*data_manage.BaseFromYongyiIndexList)
|
|
|
+ for _, v := range indexList {
|
|
|
+ indexCodeList = append(indexCodeList, v.IndexCode)
|
|
|
+ frequenciesMap[v.Frequency] = append(frequenciesMap[v.Frequency], v)
|
|
|
+ }
|
|
|
+ dataListMap := make(map[string][]*data_manage.BaseFromYongyiData)
|
|
|
+ if len(indexList) > 0 {
|
|
|
+ allDataList, e := data_manage.GetYongyiIndexDataByCodes(indexCodeList)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取数据失败"
|
|
|
+ br.ErrMsg = "获取数据失败,Err:" + e.Error()
|
|
|
return
|
|
|
}
|
|
|
- if len(secNameList) <= 0 {
|
|
|
- fmt.Println("secNameList长度为0")
|
|
|
+ for _, v := range allDataList {
|
|
|
+ dataListMap[v.IndexCode] = append(dataListMap[v.IndexCode], v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 按照频率分组排序
|
|
|
+ frequencies := []string{
|
|
|
+ "日度", "周度", "旬度", "月度", "季度", "半年度", "年度",
|
|
|
+ }
|
|
|
+ for _, frequency := range frequencies {
|
|
|
+ //获取指标
|
|
|
+ indexCodeList, ok := frequenciesMap[frequency]
|
|
|
+ if !ok {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if len(indexCodeList) <= 0 {
|
|
|
+ fmt.Printf("sheet:%s, 不存在指标", frequency)
|
|
|
return
|
|
|
}
|
|
|
var sheetName string
|
|
@@ -1010,8 +1037,8 @@ func (this *EdbInfoController) ExportYongyiList() {
|
|
|
lastModifyDateRow := sheetNew.AddRow()
|
|
|
|
|
|
var indexIdList []int
|
|
|
- for _, sv := range secNameList {
|
|
|
- indexIdList = append(indexIdList, sv.YongyiIndexId)
|
|
|
+ for _, idx := range frequenciesMap[frequency] {
|
|
|
+ indexIdList = append(indexIdList, idx.YongyiIndexId)
|
|
|
}
|
|
|
dataTimeList, err := data_manage.GetYongyiDataDataTimeByIndexId(indexIdList)
|
|
|
if err != nil {
|
|
@@ -1033,13 +1060,11 @@ func (this *EdbInfoController) ExportYongyiList() {
|
|
|
displayDateCell.SetDate(displayDate)
|
|
|
|
|
|
}
|
|
|
- for k, sv := range secNameList {
|
|
|
- //获取数据
|
|
|
- dataList, err := data_manage.GetYongyiIndexDataByCode(sv.IndexCode)
|
|
|
- if err != nil {
|
|
|
- br.Msg = "获取数据失败"
|
|
|
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
|
|
|
- return
|
|
|
+ for k, icl := range indexCodeList {
|
|
|
+ // 获取数据
|
|
|
+ dataList, ok := dataListMap[icl.IndexCode]
|
|
|
+ if !ok {
|
|
|
+ continue
|
|
|
}
|
|
|
if k == 0 {
|
|
|
secNameRow.AddCell().SetValue("指标名称/Metric Name")
|
|
@@ -1052,11 +1077,15 @@ func (this *EdbInfoController) ExportYongyiList() {
|
|
|
if len(dataList) == 0 {
|
|
|
continue
|
|
|
}
|
|
|
- secNameRow.AddCell().SetValue(sv.IndexName)
|
|
|
- frequencyRow.AddCell().SetValue(sv.Frequency)
|
|
|
- unitRow.AddCell().SetValue(sv.Unit)
|
|
|
+ secNameRow.AddCell().SetValue(icl.IndexName)
|
|
|
+ frequencyRow.AddCell().SetValue(icl.Frequency)
|
|
|
+ unitRow.AddCell().SetValue(icl.Unit)
|
|
|
|
|
|
- lastModifyDateRow.AddCell().SetValue(sv.ModifyTime.Format(utils.FormatDate))
|
|
|
+ timeDate, err := time.Parse(utils.FormatDateTime, dataList[0].ModifyTime)
|
|
|
+ if err != nil {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ lastModifyDateRow.AddCell().SetValue(timeDate.Format(utils.FormatDate))
|
|
|
dataInfoMap := make(map[string]*data_manage.BaseFromYongyiData)
|
|
|
for _, v := range dataList {
|
|
|
dataInfoMap[v.DataTime] = v
|
|
@@ -1095,8 +1124,8 @@ func (this *EdbInfoController) ExportYongyiList() {
|
|
|
}
|
|
|
|
|
|
fileName := classifyName
|
|
|
- if indexCode != "" && len(secNameList) == 1 {
|
|
|
- fileName = secNameList[0].IndexName
|
|
|
+ if indexCode != "" && len(indexList) == 1 {
|
|
|
+ fileName = indexList[0].IndexName
|
|
|
}
|
|
|
fileName += time.Now().Format("06.01.02") + `.xlsx` //文件名称
|
|
|
this.Ctx.Output.Download(downLoadnFilePath, fileName)
|