|
@@ -8,12 +8,13 @@ import (
|
|
"eta/eta_chart_lib/services/data"
|
|
"eta/eta_chart_lib/services/data"
|
|
"eta/eta_chart_lib/utils"
|
|
"eta/eta_chart_lib/utils"
|
|
"fmt"
|
|
"fmt"
|
|
- "github.com/shopspring/decimal"
|
|
|
|
- "github.com/yidane/formula"
|
|
|
|
"sort"
|
|
"sort"
|
|
"strconv"
|
|
"strconv"
|
|
"strings"
|
|
"strings"
|
|
"time"
|
|
"time"
|
|
|
|
+
|
|
|
|
+ "github.com/shopspring/decimal"
|
|
|
|
+ "github.com/yidane/formula"
|
|
)
|
|
)
|
|
|
|
|
|
// TableDataConfig
|
|
// TableDataConfig
|
|
@@ -27,6 +28,13 @@ type TableDataConfig struct {
|
|
ManualDate []string `description:"手动配置的日期(未来的日期)"`
|
|
ManualDate []string `description:"手动配置的日期(未来的日期)"`
|
|
TableEdbInfoList []TableEdbInfo `description:"表格内指标信息"`
|
|
TableEdbInfoList []TableEdbInfo `description:"表格内指标信息"`
|
|
TextRowData [][]request.ManualDataReq `description:"文本列表"`
|
|
TextRowData [][]request.ManualDataReq `description:"文本列表"`
|
|
|
|
+ DecimalConfig []DecimalConfig `description:"小数位数配置"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type DecimalConfig struct {
|
|
|
|
+ Row string `description:"行上的索引, 目前仅保存指标的日期"`
|
|
|
|
+ Col int `description:"列上的索引, 目前仅保存edbInfoId"`
|
|
|
|
+ Decimal int `description:"小数位数, 从左至右,从上到下的顺序"`
|
|
}
|
|
}
|
|
|
|
|
|
// TableEdbInfo
|
|
// TableEdbInfo
|
|
@@ -329,7 +337,7 @@ func GetDataByTableDataConfig(tableDataConfig TableDataConfig) (resultResp reque
|
|
d[k2].ShowValue = utils.FormatTableDataShowValue(vf)
|
|
d[k2].ShowValue = utils.FormatTableDataShowValue(vf)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ data = SetExcelShowValueByDecimalConfig(data, tableDataConfig.DecimalConfig)
|
|
resultResp = request.TableDataReq{
|
|
resultResp = request.TableDataReq{
|
|
EdbInfoIdList: edbInfoIdList,
|
|
EdbInfoIdList: edbInfoIdList,
|
|
Sort: tableDataConfig.Sort,
|
|
Sort: tableDataConfig.Sort,
|
|
@@ -340,6 +348,53 @@ func GetDataByTableDataConfig(tableDataConfig TableDataConfig) (resultResp reque
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func SetExcelShowValueByDecimalConfig(edbData []request.EdbInfoData, decimalConfig []DecimalConfig) []request.EdbInfoData {
|
|
|
|
+ if len(decimalConfig) <= 0 || len(edbData) <= 0 {
|
|
|
|
+ return edbData
|
|
|
|
+ }
|
|
|
|
+ edbInfoIndexMap := make(map[int]int)
|
|
|
|
+ dateIndexMap := make(map[string]int)
|
|
|
|
+ for i, edbInfo := range edbData {
|
|
|
|
+ edbInfoIndexMap[edbInfo.EdbInfoId] = i
|
|
|
|
+ }
|
|
|
|
+ for i, date := range edbData[0].Data {
|
|
|
|
+ dateIndexMap[date.DataTime] = i
|
|
|
|
+ }
|
|
|
|
+ for _, conf := range decimalConfig {
|
|
|
|
+ if conf.Col > 0 {
|
|
|
|
+ if edbIndex, ok := edbInfoIndexMap[conf.Col]; ok {
|
|
|
|
+ for i := 0; i < len(edbData[edbIndex].Data); i++ {
|
|
|
|
+ f, err := strconv.ParseFloat(edbData[edbIndex].Data[i].Value, 64)
|
|
|
|
+ if err != nil {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ if conf.Decimal == -1 {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ formatStr := fmt.Sprintf("%%.%df", conf.Decimal)
|
|
|
|
+ edbData[edbIndex].Data[i].ShowValue = fmt.Sprintf(formatStr, f)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if conf.Row != `` {
|
|
|
|
+ if dateIndex, ok := dateIndexMap[conf.Row]; ok {
|
|
|
|
+ for i := 0; i < len(edbData); i++ {
|
|
|
|
+ f, err := strconv.ParseFloat(edbData[i].Data[dateIndex].Value, 64)
|
|
|
|
+ if err != nil {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ if conf.Decimal == -1 {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ formatStr := fmt.Sprintf("%%.%df", conf.Decimal)
|
|
|
|
+ edbData[i].Data[dateIndex].ShowValue = fmt.Sprintf(formatStr, f)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return edbData
|
|
|
|
+}
|
|
|
|
+
|
|
// GetTableDataConfig 根据TableDataReq配置获取相关数据配置
|
|
// GetTableDataConfig 根据TableDataReq配置获取相关数据配置
|
|
func GetTableDataConfig(reqData request.TableDataReq) (tableDataConfig TableDataConfig, err error) {
|
|
func GetTableDataConfig(reqData request.TableDataReq) (tableDataConfig TableDataConfig, err error) {
|
|
// 指标数据
|
|
// 指标数据
|