|
@@ -892,11 +892,10 @@ func (this *EdbInfoController) YongyiEdbInfoAdd() {
|
|
|
}
|
|
|
|
|
|
// ExportYongyiList
|
|
|
-// @Title 导出Yongyi数据
|
|
|
-// @Description 导出Yongyi数据
|
|
|
-// @Param IndexName query string false "名称关键词"
|
|
|
-// @Param IndexCode query string false "指标唯一编码"
|
|
|
-// @Param ClassifyId query string true "分类"
|
|
|
+// @Title 导出涌益数据
|
|
|
+// @Description 导出涌益数据
|
|
|
+// @Param ClassifyId query int true "关键字搜索"
|
|
|
+// @Param IndexCode query string true "指标编码"
|
|
|
// @Success 200 导出成功
|
|
|
// @router /yongyi/export [get]
|
|
|
func (this *EdbInfoController) ExportYongyiList() {
|
|
@@ -912,141 +911,164 @@ func (this *EdbInfoController) ExportYongyiList() {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- indexCode := this.GetString("IndexCode") //指标唯一编码
|
|
|
classifyId, _ := this.GetInt("ClassifyId")
|
|
|
- //secNameList := make([]*models.EdbdataExportList, 0)
|
|
|
-
|
|
|
+ indexCode := this.GetString("IndexCode")
|
|
|
+ if classifyId < 0 {
|
|
|
+ br.Msg = "请选择分类"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ secNameList := make([]*data_manage.BaseFromYongyiIndex, 0)
|
|
|
dir, _ := os.Executable()
|
|
|
exPath := filepath.Dir(dir)
|
|
|
-
|
|
|
downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
|
|
|
xlsxFile := xlsx.NewFile()
|
|
|
|
|
|
+ var condition string
|
|
|
var pars []interface{}
|
|
|
- condition := ""
|
|
|
+ var classifyName string
|
|
|
if classifyId > 0 {
|
|
|
- //获取指标
|
|
|
- condition += " AND classify_id=?"
|
|
|
+ classifyInfo, err := data_manage.GetBaseFromYongyiClassifyById(classifyId)
|
|
|
+ if err != nil {
|
|
|
+ if err.Error() == utils.ErrNoRow() {
|
|
|
+ br.Msg = "分类不存在"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ br.Msg = "下载失败"
|
|
|
+ br.ErrMsg = "获取分类失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ classifyName = classifyInfo.ClassifyName
|
|
|
+ childClassify, err := data_manage.GetBaseFromYongyiClassifyByParentId(classifyId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "下载失败"
|
|
|
+ br.ErrMsg = "获取分类失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(childClassify) > 0 {
|
|
|
+ condition += `AND classify_id IN (` + utils.GetOrmInReplace(len(childClassify)) + `)`
|
|
|
+ for _, child := range childClassify {
|
|
|
+ pars = append(pars, child.ClassifyId)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ condition += ` AND classify_id=?`
|
|
|
+ pars = append(pars, classifyId)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ condition += ` AND classify_id=?`
|
|
|
pars = append(pars, classifyId)
|
|
|
}
|
|
|
if indexCode != "" {
|
|
|
- //获取指标
|
|
|
- condition += " AND index_code=?"
|
|
|
+ condition += ` AND index_code=? `
|
|
|
pars = append(pars, indexCode)
|
|
|
}
|
|
|
- indexList, err := data_manage.GetYongyiIndex(condition, pars)
|
|
|
+ frequencies, err := data_manage.GetYongyiFrequencyByCondition(condition, pars)
|
|
|
if err != nil {
|
|
|
- fmt.Println("获取数据失败,Err:" + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- if len(indexList) <= 0 {
|
|
|
- fmt.Println("indexList 为空")
|
|
|
- br.Ret = 200
|
|
|
- br.Success = true
|
|
|
- br.Msg = "success"
|
|
|
+ fmt.Println("GetSciFrequency err:", err.Error())
|
|
|
+ utils.FileLog.Info("GetSciFrequency err:" + err.Error())
|
|
|
return
|
|
|
}
|
|
|
- sheetNew := new(xlsx.Sheet)
|
|
|
- // todo 分类名称
|
|
|
- sheetNew, err = xlsxFile.AddSheet("涌益咨询")
|
|
|
- //sheetNew.SetColWidth()
|
|
|
- //获取指标数据
|
|
|
- windRow := sheetNew.AddRow()
|
|
|
- secNameRow := sheetNew.AddRow()
|
|
|
- indexCodeRow := sheetNew.AddRow()
|
|
|
- frequencyRow := sheetNew.AddRow()
|
|
|
- unitRow := sheetNew.AddRow()
|
|
|
- lastModifyDateRow := sheetNew.AddRow()
|
|
|
- //获取分类下指标最大数据量
|
|
|
- var dataMax int
|
|
|
- setRowIndex := 6
|
|
|
- indexCodeList := make([]string, 0)
|
|
|
- for _, v := range indexList {
|
|
|
- indexCodeList = append(indexCodeList, v.IndexCode)
|
|
|
- }
|
|
|
- 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()
|
|
|
+ for _, frequency := range frequencies {
|
|
|
+ //获取指标
|
|
|
+
|
|
|
+ secNameList, err = data_manage.GetYongyiByConditionAndFrequency(condition, frequency, pars)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("获取数据失败,Err:" + err.Error())
|
|
|
return
|
|
|
}
|
|
|
- for _, v := range allDataList {
|
|
|
- dataListMap[v.IndexCode] = append(dataListMap[v.IndexCode], v)
|
|
|
+ if len(secNameList) <= 0 {
|
|
|
+ fmt.Println("secNameList长度为0")
|
|
|
+ return
|
|
|
}
|
|
|
- for _, v := range dataListMap {
|
|
|
- if len(v) > dataMax {
|
|
|
- dataMax = len(v)
|
|
|
- }
|
|
|
+ var sheetName string
|
|
|
+ switch frequency {
|
|
|
+ case "日度":
|
|
|
+ sheetName = "日度(Daily)"
|
|
|
+ case "周度":
|
|
|
+ sheetName = "周度(Weekly)"
|
|
|
+ case "旬度":
|
|
|
+ sheetName = "旬度(ten-day)"
|
|
|
+ case "月度":
|
|
|
+ sheetName = "月度(Monthly)"
|
|
|
+ case "季度":
|
|
|
+ sheetName = "季度(Quarterly)"
|
|
|
+ case "半年度":
|
|
|
+ sheetName = "半年度(Semi-annual)"
|
|
|
+ case "年度":
|
|
|
+ sheetName = "年度(Annual)"
|
|
|
+ default:
|
|
|
+ sheetName = "其他数据"
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- for k, sv := range indexList {
|
|
|
- //获取数据
|
|
|
- dataList, ok := dataListMap[sv.IndexCode]
|
|
|
- if !ok {
|
|
|
- continue
|
|
|
+ sheetNew, err := xlsxFile.AddSheet(sheetName)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("新增Sheet失败", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ secNameRow := sheetNew.AddRow()
|
|
|
+ frequencyRow := sheetNew.AddRow()
|
|
|
+ unitRow := sheetNew.AddRow()
|
|
|
+ lastModifyDateRow := sheetNew.AddRow()
|
|
|
+
|
|
|
+ var indexIdList []int
|
|
|
+ for _, sv := range secNameList {
|
|
|
+ indexIdList = append(indexIdList, sv.YongyiIndexId)
|
|
|
+ }
|
|
|
+ dataTimeList, err := data_manage.GetYongyiDataDataTimeByIndexId(indexIdList)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("获取数据时间失败", err.Error())
|
|
|
+ return
|
|
|
}
|
|
|
- if len(dataList) > 0 {
|
|
|
- windRow.AddCell().SetValue("涌益咨询")
|
|
|
- secNameRow.AddCell().SetValue("指标名称")
|
|
|
- indexCodeRow.AddCell().SetValue("指标ID")
|
|
|
- frequencyRow.AddCell().SetValue("频率")
|
|
|
- unitRow.AddCell().SetValue("单位")
|
|
|
- lastModifyDateRow.AddCell().SetValue("更新时间")
|
|
|
|
|
|
+ // 添加excel左侧指标日期
|
|
|
+ setRowIndex := 4
|
|
|
+ for rk, dv := range dataTimeList {
|
|
|
+ rowIndex := setRowIndex + rk
|
|
|
+ row := sheetNew.Row(rowIndex)
|
|
|
+ displayDate, _ := time.Parse(utils.FormatDate, dv)
|
|
|
+ displayDateCell := row.AddCell()
|
|
|
+ style := new(xlsx.Style)
|
|
|
+ style.ApplyAlignment = true
|
|
|
+ style.Alignment.WrapText = true
|
|
|
+ displayDateCell.SetStyle(style)
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ if k == 0 {
|
|
|
+ secNameRow.AddCell().SetValue("指标名称/Metric Name")
|
|
|
+ frequencyRow.AddCell().SetValue("频度/Frequency")
|
|
|
+ unitRow.AddCell().SetValue("单位/Unit")
|
|
|
+ lastModifyDateRow.AddCell().SetValue("更新时间/Update Time")
|
|
|
+ min := k * 3
|
|
|
+ sheetNew.SetColWidth(min, min, 15)
|
|
|
+ }
|
|
|
+ if len(dataList) == 0 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
secNameRow.AddCell().SetValue(sv.IndexName)
|
|
|
- indexCodeRow.AddCell().SetValue(sv.IndexCode)
|
|
|
frequencyRow.AddCell().SetValue(sv.Frequency)
|
|
|
-
|
|
|
unitRow.AddCell().SetValue(sv.Unit)
|
|
|
- lastModifyDateRow.AddCell().SetValue(sv.ModifyTime)
|
|
|
-
|
|
|
- windRow.AddCell()
|
|
|
- windRow.AddCell()
|
|
|
- secNameRow.AddCell()
|
|
|
- indexCodeRow.AddCell()
|
|
|
- frequencyRow.AddCell()
|
|
|
- unitRow.AddCell()
|
|
|
- lastModifyDateRow.AddCell()
|
|
|
- min := k * 3
|
|
|
- sheetNew.SetColWidth(min, min, 15)
|
|
|
-
|
|
|
- if len(dataList) <= 0 {
|
|
|
- for n := 0; n < dataMax; n++ {
|
|
|
- rowIndex := setRowIndex + n
|
|
|
- row := sheetNew.Row(rowIndex)
|
|
|
- row.AddCell()
|
|
|
- row.AddCell()
|
|
|
- row.AddCell()
|
|
|
- }
|
|
|
- } else {
|
|
|
- endRowIndex := 0
|
|
|
- for rk, dv := range dataList {
|
|
|
- rowIndex := setRowIndex + rk
|
|
|
- row := sheetNew.Row(rowIndex)
|
|
|
- displayDate, _ := time.Parse(utils.FormatDate, dv.DataTime)
|
|
|
- displayDateCell := row.AddCell()
|
|
|
- style := new(xlsx.Style)
|
|
|
- style.ApplyAlignment = true
|
|
|
- style.Alignment.WrapText = true
|
|
|
- displayDateCell.SetStyle(style)
|
|
|
- displayDateCell.SetDate(displayDate)
|
|
|
-
|
|
|
- row.AddCell().SetValue(dv.Value)
|
|
|
- row.AddCell()
|
|
|
- endRowIndex = rowIndex
|
|
|
- }
|
|
|
- if len(dataList) < dataMax {
|
|
|
- dataLen := dataMax - len(dataList)
|
|
|
- for n := 0; n < dataLen; n++ {
|
|
|
- rowIndex := (endRowIndex + 1) + n
|
|
|
- row := sheetNew.Row(rowIndex)
|
|
|
- row.AddCell()
|
|
|
- row.AddCell()
|
|
|
- row.AddCell()
|
|
|
- }
|
|
|
+
|
|
|
+ lastModifyDateRow.AddCell().SetValue(sv.ModifyTime.Format(utils.FormatDate))
|
|
|
+ dataInfoMap := make(map[string]*data_manage.BaseFromYongyiData)
|
|
|
+ for _, v := range dataList {
|
|
|
+ dataInfoMap[v.DataTime] = v
|
|
|
+ }
|
|
|
+
|
|
|
+ for rk, dtv := range dataTimeList {
|
|
|
+ rowIndex := setRowIndex + rk
|
|
|
+ row := sheetNew.Row(rowIndex)
|
|
|
+ displayDateCell := row.AddCell()
|
|
|
+ tmpData, ok := dataInfoMap[dtv]
|
|
|
+ if ok {
|
|
|
+ displayDateCell.SetValue(tmpData.Value)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1071,9 +1093,10 @@ func (this *EdbInfoController) ExportYongyiList() {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
- fileName := `涌益咨询数据`
|
|
|
- if len(indexList) > 0 {
|
|
|
- fileName = indexList[0].IndexName
|
|
|
+
|
|
|
+ fileName := classifyName
|
|
|
+ if indexCode != "" && len(secNameList) == 1 {
|
|
|
+ fileName = secNameList[0].IndexName
|
|
|
}
|
|
|
fileName += time.Now().Format("06.01.02") + `.xlsx` //文件名称
|
|
|
this.Ctx.Output.Download(downLoadnFilePath, fileName)
|