|
@@ -12,7 +12,6 @@ import (
|
|
|
etaTrialService "eta/eta_api/services/eta_trial"
|
|
|
"eta/eta_api/utils"
|
|
|
"fmt"
|
|
|
- "github.com/beego/beego/v2/core/logs"
|
|
|
"github.com/tealeg/xlsx"
|
|
|
"os"
|
|
|
"path/filepath"
|
|
@@ -168,8 +167,8 @@ func (this *BaseFromLyIndexController) LyIndexAddValidate() {
|
|
|
|
|
|
codeLen := len(req.IndexCodes)
|
|
|
if codeLen > codeMax {
|
|
|
- br.Msg = "指标编码数量超过限制"
|
|
|
- br.ErrMsg = "指标编码数量超过限制,最大数量为" + string(codeMax)
|
|
|
+ br.Msg = "批量添加指标数量不得超过" + strconv.Itoa(codeMax) + "个"
|
|
|
+ br.ErrMsg = "批量添加指标数量不得超过" + strconv.Itoa(codeMax) + "个"
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -232,7 +231,7 @@ func (this *BaseFromLyIndexController) LyIndexAdd() {
|
|
|
return
|
|
|
}
|
|
|
if len(req) > codeMax {
|
|
|
- br.Msg = "批量添加指标数量不得超过30个"
|
|
|
+ br.Msg = "批量添加指标数量不得超过" + strconv.Itoa(codeMax) + "个"
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -365,168 +364,167 @@ func (this *BaseFromLyIndexController) LyIndexAdd() {
|
|
|
func (this *BaseFromLyIndexController) LyIndexDataExport() {
|
|
|
br := new(models.BaseResponse).Init()
|
|
|
defer func() {
|
|
|
- if br.ErrMsg == "" {
|
|
|
- br.IsSendEmail = false
|
|
|
- }
|
|
|
this.Data["json"] = br
|
|
|
this.ServeJSON()
|
|
|
}()
|
|
|
sysUser := this.SysUser
|
|
|
if sysUser == nil {
|
|
|
- br.Msg = "请登录"
|
|
|
- br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
- br.Ret = 408
|
|
|
+ br.Msg = "请重新登录"
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- //获取指标
|
|
|
- var condition string
|
|
|
- var pars []interface{}
|
|
|
+ //keyWord := this.GetString("KeyWord")
|
|
|
+ /*startDate := this.GetString("StartDate")
|
|
|
+ endDate := this.GetString("EndDate")*/
|
|
|
+ //frequency := this.GetString("Frequency")
|
|
|
+ classifyId, _ := this.GetInt("ClassifyId") //分类
|
|
|
+ //mobile := this.GetString("Mobile") //分类
|
|
|
+ indexCode := this.GetString("IndexCode") //指标唯一编码
|
|
|
|
|
|
- classifyId, _ := this.GetInt("ClassifyId")
|
|
|
- if classifyId < 0 {
|
|
|
+ if classifyId <= 0 {
|
|
|
br.Msg = "请选择分类"
|
|
|
- br.ErrMsg = "请选择分类"
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- if classifyId >= 0 {
|
|
|
- condition += ` AND base_from_ly_classify_id=? `
|
|
|
- pars = append(pars, classifyId)
|
|
|
- }
|
|
|
-
|
|
|
- isCheckAll, err := this.GetBool("IsCheckAll")
|
|
|
- if err != nil {
|
|
|
return
|
|
|
}
|
|
|
- var indexCodeString string
|
|
|
- if !isCheckAll {
|
|
|
- indexCodeString = strings.TrimSpace(this.GetString("IndexCodes"))
|
|
|
- if indexCodeString == "" {
|
|
|
- br.Msg = "请选择指标"
|
|
|
- br.ErrMsg = "请选择指标"
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- indexCodes := strings.Split(indexCodeString, ",")
|
|
|
- if len(indexCodes) > 0 && !isCheckAll {
|
|
|
- condition += ` AND index_code IN (`
|
|
|
- for _, v := range indexCodes {
|
|
|
- condition += "?,"
|
|
|
- pars = append(pars, v)
|
|
|
- }
|
|
|
- condition = condition[:len(condition)-1]
|
|
|
- condition += `) `
|
|
|
- }
|
|
|
|
|
|
- indexList, err := data_manage.GetLyIndexList(condition, pars)
|
|
|
+ //userId := sysUser.AdminId
|
|
|
+ //超管账号可以查看分类下的所有频度数据
|
|
|
+ /*if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
|
|
|
+ userId = 0
|
|
|
+ }*/
|
|
|
+ //获取账户所拥有权限的分类id集合
|
|
|
+ /*classifyIdStrList, err := data.GetEdbClassifyListByAdminId(int64(userId))
|
|
|
if err != nil {
|
|
|
- br.Msg = "获取数据失败"
|
|
|
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
|
|
|
+ br.Msg = "获取分类数据失败"
|
|
|
return
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
dir, _ := os.Executable()
|
|
|
exPath := filepath.Dir(dir)
|
|
|
|
|
|
- downLoadFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
|
|
|
+ downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
|
|
|
xlsxFile := xlsx.NewFile()
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- fmt.Println("新增Sheet失败", err.Error())
|
|
|
+ /*if err != nil {
|
|
|
+ br.Msg = "生成文件失败"
|
|
|
+ br.ErrMsg = "生成文件失败"
|
|
|
return
|
|
|
- }
|
|
|
- //获取指标数据
|
|
|
- sheetNew, _ := xlsxFile.AddSheet(dataSource)
|
|
|
- indexNameRow := sheetNew.AddRow()
|
|
|
- frequencyRow := sheetNew.AddRow()
|
|
|
- unitRow := sheetNew.AddRow()
|
|
|
- lastModifyDateRow := sheetNew.AddRow()
|
|
|
- //获取分类下指标最大数据量
|
|
|
- dataMax, err := data_manage.GetLyDataMaxCount(classifyId)
|
|
|
+ }*/
|
|
|
+ frequencies, err := data_manage.GetLyIndexFrequency(classifyId)
|
|
|
if err != nil {
|
|
|
- fmt.Println("获取指标最大数据量失败", err.Error())
|
|
|
+ br.Msg = "查询频度失败"
|
|
|
+ br.ErrMsg = "查询频度失败"
|
|
|
return
|
|
|
}
|
|
|
- logs.Info("dataMax:", dataMax)
|
|
|
|
|
|
- setRowIndex := 6
|
|
|
- for k, sv := range indexList {
|
|
|
- //获取数据
|
|
|
- dataList, err := data_manage.GetBaseFromLyDataByIndexCode(sv.IndexCode)
|
|
|
+ fileName := `粮油商务网`
|
|
|
+ if frequencies == nil {
|
|
|
+ sheet, err := xlsxFile.AddSheet("无数据")
|
|
|
if err != nil {
|
|
|
- br.Msg = "获取数据失败"
|
|
|
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
|
|
|
+ br.Msg = "新增Sheet失败"
|
|
|
+ br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
- if len(dataList) > 0 {
|
|
|
- indexNameRow.AddCell().SetValue("指标名称")
|
|
|
- frequencyRow.AddCell().SetValue("频率")
|
|
|
- unitRow.AddCell().SetValue("单位")
|
|
|
- lastModifyDateRow.AddCell().SetValue("更新时间")
|
|
|
-
|
|
|
- indexNameRow.AddCell().SetValue(sv.IndexName)
|
|
|
- frequencyRow.AddCell().SetValue(sv.Frequency)
|
|
|
- unitRow.AddCell().SetValue(sv.Unit)
|
|
|
- lastModifyDateRow.AddCell().SetValue(sv.ModifyTime)
|
|
|
-
|
|
|
- indexNameRow.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()
|
|
|
- row.AddCell()
|
|
|
- }
|
|
|
- } else {
|
|
|
- endRowIndex := 0
|
|
|
- for rk, dv := range dataList {
|
|
|
- rowIndex := setRowIndex + rk
|
|
|
- row := sheetNew.Row(rowIndex)
|
|
|
-
|
|
|
- // 在第一列显示时间
|
|
|
- if k == 0 {
|
|
|
- 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)
|
|
|
- } else {
|
|
|
- row.AddCell() // 其他列不显示时间
|
|
|
- }
|
|
|
-
|
|
|
- row.AddCell().SetValue(dv.Value)
|
|
|
- row.AddCell()
|
|
|
- endRowIndex = rowIndex
|
|
|
+ rowSecName := sheet.AddRow()
|
|
|
+ celSecName := rowSecName.AddCell()
|
|
|
+ celSecName.SetValue("")
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, frequency := range frequencies {
|
|
|
+ //secNameList := make([]*data_manage.BaseFromLyIndex, 0)
|
|
|
+ lyIndices, err := data_manage.GetLyIndexByCodeAndClassify(indexCode, classifyId)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if indexCode == "" {
|
|
|
+ fileName = lyIndices[0].IndexName
|
|
|
+ }
|
|
|
+
|
|
|
+ var sheet *xlsx.Sheet
|
|
|
+ if len(lyIndices) > 0 {
|
|
|
+ sheet, err = xlsxFile.AddSheet(*frequency)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "新增Sheet失败"
|
|
|
+ br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ //获取指标数据
|
|
|
+ rowSecName := sheet.AddRow()
|
|
|
+ celSecName := rowSecName.AddCell()
|
|
|
+ celSecName.SetValue("指标名称")
|
|
|
+ rowFrequency := sheet.AddRow()
|
|
|
+ celFrequency := rowFrequency.AddCell()
|
|
|
+ celFrequency.SetValue("频率")
|
|
|
+ rowUnit := sheet.AddRow()
|
|
|
+ celUnit := rowUnit.AddCell()
|
|
|
+ celUnit.SetValue("单位")
|
|
|
+
|
|
|
+ rowModifyDate := sheet.AddRow()
|
|
|
+ rowModifyCell := rowModifyDate.AddCell()
|
|
|
+ rowModifyCell.SetValue("更新时间")
|
|
|
+
|
|
|
+ dataMap := make(map[string]map[string]*data_manage.BaseFromLyData)
|
|
|
+ var tradeCodeList []string
|
|
|
+ for _, v := range lyIndices {
|
|
|
+ cellSenName := rowSecName.AddCell()
|
|
|
+ cellSenName.SetValue(v.IndexName)
|
|
|
+ celFrequency := rowFrequency.AddCell()
|
|
|
+ celFrequency.SetValue(v.Frequency)
|
|
|
+ celUnit := rowUnit.AddCell()
|
|
|
+ celUnit.SetValue(v.Unit)
|
|
|
+ rowModifyCell := rowModifyDate.AddCell()
|
|
|
+ rowModifyCell.SetValue(v.ModifyTime)
|
|
|
+ tradeCodeList = append(tradeCodeList, v.IndexCode)
|
|
|
+
|
|
|
+ var lyDataList []*data_manage.BaseFromLyData
|
|
|
+ lyDataList, err = data_manage.GetBaseFromLyDataByIndexCode(v.IndexCode)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取数据失败"
|
|
|
+ br.ErrMsg = "获取数据失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //items, err := models.GetEdbdataAllByTradeCode(v.IndexCode)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.ErrMsg = "GetEdbdataAllByTradeCode,Err:" + err.Error()
|
|
|
+ br.Msg = "获取数据失败"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, item := range lyDataList {
|
|
|
+ if dataMap[item.IndexCode] == nil {
|
|
|
+ dataMap[item.IndexCode] = make(map[string]*data_manage.BaseFromLyData)
|
|
|
}
|
|
|
+ dataMap[item.IndexCode][item.DataTime] = item
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- 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()
|
|
|
- row.AddCell()
|
|
|
- }
|
|
|
+ tradeCodeStr := strings.Join(tradeCodeList, "','")
|
|
|
+ tradeCodeStr = "'" + tradeCodeStr + "'"
|
|
|
+ dateList, err := models.GetEdbdataList(tradeCodeStr)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取数据失败"
|
|
|
+ br.ErrMsg = "获取数据失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, n := range dateList {
|
|
|
+ rowData := sheet.AddRow()
|
|
|
+ celDate := rowData.AddCell()
|
|
|
+ celDate.SetValue(n.Dt)
|
|
|
+
|
|
|
+ for _, m := range lyIndices {
|
|
|
+ celData := rowData.AddCell()
|
|
|
+ fmt.Println(m.IndexCode)
|
|
|
+ fmt.Println(n.Dt)
|
|
|
+ if dataMap[m.IndexCode][n.Dt] != nil {
|
|
|
+ celData.SetValue(dataMap[m.IndexCode][n.Dt].Value)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- err = xlsxFile.Save(downLoadFilePath)
|
|
|
+ err = xlsxFile.Save(downLoadnFilePath)
|
|
|
if err != nil {
|
|
|
//有指标无数据时先导出一遍空表
|
|
|
sheet, err := xlsxFile.AddSheet("无数据")
|
|
@@ -538,18 +536,18 @@ func (this *BaseFromLyIndexController) LyIndexDataExport() {
|
|
|
rowSecName := sheet.AddRow()
|
|
|
celSecName := rowSecName.AddCell()
|
|
|
celSecName.SetValue("")
|
|
|
- err = xlsxFile.Save(downLoadFilePath)
|
|
|
+ err = xlsxFile.Save(downLoadnFilePath)
|
|
|
if err != nil {
|
|
|
br.Msg = "保存文件失败"
|
|
|
br.ErrMsg = "保存文件失败"
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
- fileName := dataSource
|
|
|
- fileName += time.Now().Format(utils.FormatDateUnSpace) + `.xlsx` //文件名称
|
|
|
- this.Ctx.Output.Download(downLoadFilePath, fileName)
|
|
|
+
|
|
|
+ fileName += time.Now().Format("06.01.02") + `.xlsx` //文件名称
|
|
|
+ this.Ctx.Output.Download(downLoadnFilePath, fileName)
|
|
|
defer func() {
|
|
|
- os.Remove(downLoadFilePath)
|
|
|
+ os.Remove(downLoadnFilePath)
|
|
|
}()
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|