|
@@ -4,7 +4,12 @@ import (
|
|
|
"eta/eta_api/models"
|
|
|
"eta/eta_api/models/data_manage"
|
|
|
"eta/eta_api/utils"
|
|
|
+ "fmt"
|
|
|
"github.com/rdlucklib/rdluck_tools/paging"
|
|
|
+ "github.com/tealeg/xlsx"
|
|
|
+ "os"
|
|
|
+ "path/filepath"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
// YongyiClassify
|
|
@@ -41,16 +46,15 @@ func (this *EdbInfoController) YongyiClassify() {
|
|
|
br.Data = ret
|
|
|
}
|
|
|
|
|
|
-// YongyiData
|
|
|
+// YongyiIndexData
|
|
|
// @Title 获取钢联数据
|
|
|
// @Description 获取钢联数据接口
|
|
|
// @Param PageSize query int true "每页数据条数"
|
|
|
// @Param CurrentIndex query int true "当前页页码,从1开始"
|
|
|
// @Param ClassifyId query string true "分类id"
|
|
|
-// @Param Frequency query string true "频度名称"
|
|
|
// @Success 200 {object} data_manage.LzFrequency
|
|
|
-// @router /yongyi/index [get]
|
|
|
-func (this *EdbInfoController) YongyiData() {
|
|
|
+// @router /yongyi/index/data [get]
|
|
|
+func (this *EdbInfoController) YongyiIndexData() {
|
|
|
br := new(models.BaseResponse).Init()
|
|
|
defer func() {
|
|
|
this.Data["json"] = br
|
|
@@ -221,13 +225,10 @@ func (this *EdbInfoController) YongyiSingleData() {
|
|
|
// @Param IndexName query string false "名称关键词"
|
|
|
// @Param IndexCode query string false "指标唯一编码"
|
|
|
// @Param ClassifyId query string true "分类"
|
|
|
-// @Param Frequency query string true "频度"
|
|
|
-// @Param UnitName query string false "单位"
|
|
|
-// @Param ModifyTime query string false "更新时间"
|
|
|
// @Success 200 导出成功
|
|
|
-// @router /export/yongyiList [get]
|
|
|
+// @router /yongyi/export [get]
|
|
|
func (this *EdbInfoController) ExportYongyiList() {
|
|
|
- /*br := new(models.BaseResponse).Init()
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
defer func() {
|
|
|
this.Data["json"] = br
|
|
|
this.ServeJSON()
|
|
@@ -239,12 +240,9 @@ func (this *EdbInfoController) ExportYongyiList() {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- //typeName := this.GetString("TypeName") //分类
|
|
|
- //frequency := this.GetString("Frequency")
|
|
|
-
|
|
|
indexCode := this.GetString("IndexCode") //指标唯一编码
|
|
|
classifyId, _ := this.GetInt("ClassifyId")
|
|
|
- secNameList := make([]*models.EdbdataExportList, 0)
|
|
|
+ //secNameList := make([]*models.EdbdataExportList, 0)
|
|
|
|
|
|
dir, _ := os.Executable()
|
|
|
exPath := filepath.Dir(dir)
|
|
@@ -252,240 +250,137 @@ func (this *EdbInfoController) ExportYongyiList() {
|
|
|
downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
|
|
|
xlsxFile := xlsx.NewFile()
|
|
|
|
|
|
- if classifyId >= 0 && indexCode == "" {
|
|
|
-
|
|
|
- frequencies, err := data_manage.GetYongyiFrequency(classifyId)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("GetYongyiFrequency err:", err.Error())
|
|
|
- utils.FileLog.Info("GetYongyiFrequency err:" + err.Error())
|
|
|
+ var pars []interface{}
|
|
|
+ condition := ""
|
|
|
+ if classifyId > 0 {
|
|
|
+ //获取指标
|
|
|
+ condition += " AND classify_id=?"
|
|
|
+ pars = append(pars, classifyId)
|
|
|
+ }
|
|
|
+ if indexCode != "" {
|
|
|
+ //获取指标
|
|
|
+ condition += " AND index_code=?"
|
|
|
+ pars = append(pars, indexCode)
|
|
|
+ }
|
|
|
+ indexList, err := data_manage.GetYongyiIndex(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"
|
|
|
+ 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()
|
|
|
return
|
|
|
}
|
|
|
- for _, frequency := range frequencies {
|
|
|
-
|
|
|
- //获取指标
|
|
|
- var pars []interface{}
|
|
|
- pars = append(pars, classifyId)
|
|
|
- pars = append(pars, frequency)
|
|
|
- condition := " AND classify_id=? AND frequency=? "
|
|
|
- secNameList, err := data_manage.GetYongyiIndex(condition, pars)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("获取数据失败,Err:" + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- if len(secNameList) <= 0 {
|
|
|
- fmt.Println("secNameList长度为0")
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- var sheetNew *xlsx.Sheet
|
|
|
- if *frequency == "" {
|
|
|
- newFrequency := "无频度"
|
|
|
- sheetNew, err = xlsxFile.AddSheet(newFrequency)
|
|
|
- } else {
|
|
|
- sheetNew, err = xlsxFile.AddSheet(*frequency)
|
|
|
- }
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- fmt.Println("新增Sheet失败", err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- //sheetNew.SetColWidth()
|
|
|
- //获取指标数据
|
|
|
- windRow := sheetNew.AddRow()
|
|
|
- secNameRow := sheetNew.AddRow()
|
|
|
- indexCodeRow := sheetNew.AddRow()
|
|
|
- frequencyRow := sheetNew.AddRow()
|
|
|
- unitRow := sheetNew.AddRow()
|
|
|
- lastModifyDateRow := sheetNew.AddRow()
|
|
|
- //获取分类下指标最大数据量
|
|
|
- dataMax, err := data_manage.GetYongyiDataMaxCount(classifyId)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("获取指标最大数据量失败", err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- fmt.Println("dataMax:", dataMax)
|
|
|
- setRowIndex := 6
|
|
|
- for k, sv := range secNameList {
|
|
|
- //获取数据
|
|
|
- dataList, err := data_manage.GetYongyiIndexDataByCode(sv.IndexCode)
|
|
|
- if err != nil {
|
|
|
- br.Msg = "获取数据失败"
|
|
|
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
|
|
|
- return
|
|
|
- }
|
|
|
- if len(dataList) > 0 {
|
|
|
- windRow.AddCell().SetValue("Yongyi")
|
|
|
- secNameRow.AddCell().SetValue("指标名称")
|
|
|
- indexCodeRow.AddCell().SetValue("指标ID")
|
|
|
- frequencyRow.AddCell().SetValue("频率")
|
|
|
- unitRow.AddCell().SetValue("单位")
|
|
|
- lastModifyDateRow.AddCell().SetValue("更新时间")
|
|
|
-
|
|
|
- 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()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- frequencies, err := data_manage.GetYongyiFrequencyByCode(indexCode)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("GetYongyiFrequencyByCode err:", err.Error())
|
|
|
- utils.FileLog.Info("GetYongyiFrequencyByCode err:" + err.Error())
|
|
|
- return
|
|
|
+ for _, v := range allDataList {
|
|
|
+ dataListMap[v.IndexCode] = append(dataListMap[v.IndexCode], v)
|
|
|
}
|
|
|
- for _, frequency := range frequencies {
|
|
|
- //获取数据
|
|
|
- dataList, err := data_manage.GetYongyiIndexDataByCode(indexCode)
|
|
|
- if err != nil {
|
|
|
- br.Msg = "获取数据失败"
|
|
|
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
|
|
|
- return
|
|
|
+ for _, v := range dataListMap {
|
|
|
+ if len(v) > dataMax {
|
|
|
+ dataMax = len(v)
|
|
|
}
|
|
|
- if len(dataList) > 0 {
|
|
|
- name := this.GetString("IndexName")
|
|
|
- unit := this.GetString("UnitName")
|
|
|
- modifyTime := this.GetString("ModifyTime")
|
|
|
-
|
|
|
- var sheet *xlsx.Sheet
|
|
|
- if *frequency == "" {
|
|
|
- newFrequency := "无频度"
|
|
|
- sheet, err = xlsxFile.AddSheet(newFrequency)
|
|
|
- } else {
|
|
|
- sheet, err = xlsxFile.AddSheet(*frequency)
|
|
|
- }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if err != nil {
|
|
|
- br.Msg = "新增Sheet失败"
|
|
|
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
|
|
|
- return
|
|
|
+ for k, sv := range indexList {
|
|
|
+ //获取数据
|
|
|
+ dataList, ok := dataListMap[sv.IndexCode]
|
|
|
+ if !ok {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if len(dataList) > 0 {
|
|
|
+ windRow.AddCell().SetValue("涌益咨询")
|
|
|
+ secNameRow.AddCell().SetValue("指标名称")
|
|
|
+ indexCodeRow.AddCell().SetValue("指标ID")
|
|
|
+ frequencyRow.AddCell().SetValue("频率")
|
|
|
+ unitRow.AddCell().SetValue("单位")
|
|
|
+ lastModifyDateRow.AddCell().SetValue("更新时间")
|
|
|
+
|
|
|
+ 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()
|
|
|
}
|
|
|
- //获取指标数据
|
|
|
- windRow := sheet.AddRow()
|
|
|
- windRow.AddCell().SetValue("Yongyi")
|
|
|
- rowSecName := sheet.AddRow()
|
|
|
- celSecName := rowSecName.AddCell()
|
|
|
- celSecName.SetValue("指标名称")
|
|
|
- cellSenName := rowSecName.AddCell()
|
|
|
- cellSenName.SetValue(name)
|
|
|
- indexCodeRow := sheet.AddRow()
|
|
|
- indexCodeRow.AddCell().SetValue("指标ID")
|
|
|
- indexCodeRow.AddCell().SetValue(indexCode)
|
|
|
-
|
|
|
- rowFrequency := sheet.AddRow()
|
|
|
- celFrequency := rowFrequency.AddCell()
|
|
|
- celFrequency.SetValue("频率")
|
|
|
- cellFrequency := rowFrequency.AddCell()
|
|
|
- cellFrequency.SetValue(*frequency)
|
|
|
-
|
|
|
- rowUnit := sheet.AddRow()
|
|
|
- celUnit := rowUnit.AddCell()
|
|
|
- celUnit.SetValue("单位")
|
|
|
- cellUnit := rowUnit.AddCell()
|
|
|
- cellUnit.SetValue(unit)
|
|
|
-
|
|
|
- rowModifyDate := sheet.AddRow()
|
|
|
- rowModifyCell := rowModifyDate.AddCell()
|
|
|
- rowModifyCell.SetValue("更新时间")
|
|
|
- rowModifyCell = rowModifyDate.AddCell()
|
|
|
- rowModifyCell.SetValue(modifyTime)
|
|
|
- dataMax, err := data_manage.GetYongyiIndexDataCount(indexCode)
|
|
|
- if err != nil {
|
|
|
- br.Msg = "查询数量失败"
|
|
|
- br.ErrMsg = "GetYongyiIndexDataCount,Err:" + err.Error()
|
|
|
- return
|
|
|
+ } 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) <= 0 {
|
|
|
- for n := 0; n < dataMax; n++ {
|
|
|
- rowIndex := 6 + n
|
|
|
- row := sheet.Row(rowIndex)
|
|
|
- row.AddCell()
|
|
|
+ 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()
|
|
|
- }
|
|
|
- } else {
|
|
|
- endRowIndex := 0
|
|
|
- for rk, dv := range dataList {
|
|
|
- rowIndex := 6 + rk
|
|
|
- row := sheet.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 := sheet.Row(rowIndex)
|
|
|
- row.AddCell()
|
|
|
- row.AddCell()
|
|
|
- row.AddCell()
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- err := xlsxFile.Save(downLoadnFilePath)
|
|
|
+ err = xlsxFile.Save(downLoadnFilePath)
|
|
|
if err != nil {
|
|
|
//有指标无数据时先导出一遍空表
|
|
|
sheet, err := xlsxFile.AddSheet("无数据")
|
|
@@ -504,9 +399,9 @@ func (this *EdbInfoController) ExportYongyiList() {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
- fileName := `Yongyi数据`
|
|
|
- if len(secNameList) > 0 {
|
|
|
- fileName = secNameList[0].ClassifyName
|
|
|
+ fileName := `涌益咨询数据`
|
|
|
+ if len(indexList) > 0 {
|
|
|
+ fileName = indexList[0].IndexName
|
|
|
}
|
|
|
fileName += time.Now().Format("06.01.02") + `.xlsx` //文件名称
|
|
|
this.Ctx.Output.Download(downLoadnFilePath, fileName)
|
|
@@ -516,5 +411,5 @@ func (this *EdbInfoController) ExportYongyiList() {
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|
|
|
br.Msg = "success"
|
|
|
- */
|
|
|
+
|
|
|
}
|