|
@@ -6,13 +6,13 @@ import (
|
|
|
"eta/eta_api/models/data_manage/excel/request"
|
|
|
"eta/eta_api/utils"
|
|
|
"fmt"
|
|
|
- "math"
|
|
|
"os"
|
|
|
"reflect"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
|
|
|
+ "github.com/shopspring/decimal"
|
|
|
"github.com/tealeg/xlsx"
|
|
|
"github.com/xuri/excelize/v2"
|
|
|
)
|
|
@@ -1757,40 +1757,78 @@ func GetTableDataByMixedTableData(config [][]request.MixedTableCellDataReq, hide
|
|
|
tmp.FontColor = styleConfig.Color
|
|
|
}
|
|
|
tmp.Monitor = showFormatValue
|
|
|
- tmpShowValue, err := strconv.ParseFloat(cell.Value, 64)
|
|
|
+ // 如果没有showValue, 则使用value
|
|
|
+ if cell.ShowValue == "" {
|
|
|
+ _, err := strconv.ParseFloat(cell.Value, 64)
|
|
|
+ if err == nil {
|
|
|
+ cell.ShowValue = cell.Value
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _, err := strconv.ParseFloat(cell.Value, 64)
|
|
|
if err == nil {
|
|
|
- switch styleConfig.Last {
|
|
|
- case "nt":
|
|
|
- // 先进行数字的百分比计算,然后保留小数点位数
|
|
|
- percent := tmpShowValue * 100
|
|
|
+ hasPercent := false
|
|
|
+ if styleConfig.Nt == "percent" {
|
|
|
+ hasPercent = true
|
|
|
+ }
|
|
|
+ // 修复历史数据
|
|
|
+ if styleConfig.Pn != 0 {
|
|
|
if styleConfig.Decimal == nil {
|
|
|
- continue
|
|
|
+ styleConfig.Decimal = new(int)
|
|
|
}
|
|
|
- factor := math.Pow(10, float64(*styleConfig.Decimal))
|
|
|
- rounded := math.Round(percent*factor) / factor
|
|
|
- tmp.Monitor = fmt.Sprintf("%g%%", rounded)
|
|
|
- case "decimal":
|
|
|
- // 先保留小数点位数,再进行百分比计算
|
|
|
- if styleConfig.Decimal == nil {
|
|
|
- continue
|
|
|
+ *styleConfig.Decimal += styleConfig.Pn
|
|
|
+ if *styleConfig.Decimal < 0 {
|
|
|
+ *styleConfig.Decimal = 0
|
|
|
}
|
|
|
- factor := math.Pow(10, float64(*styleConfig.Decimal))
|
|
|
- rounded := math.Round(tmpShowValue*factor) / factor
|
|
|
- if styleConfig.Nt == "percent" {
|
|
|
- percent := rounded * 100
|
|
|
- var precisionStr string
|
|
|
- if *styleConfig.Decimal > 2 {
|
|
|
- precision := *styleConfig.Decimal - 2
|
|
|
- precisionStr = strconv.FormatFloat(rounded, 'f', precision, 64)
|
|
|
- } else {
|
|
|
- precisionStr = strconv.FormatFloat(math.Round(percent), 'f', -1, 64)
|
|
|
- }
|
|
|
- tmp.Monitor = fmt.Sprintf("%s%%", precisionStr)
|
|
|
+ }
|
|
|
+
|
|
|
+ if styleConfig.Decimal != nil {
|
|
|
+ tmp.Monitor = utils.RoundNumber(cell.ShowValue, *styleConfig.Decimal, hasPercent)
|
|
|
+ } else {
|
|
|
+ if hasPercent {
|
|
|
+ numDecimal, _ := decimal.NewFromString(cell.ShowValue)
|
|
|
+ tmpStr := numDecimal.Mul(decimal.NewFromInt(100)).String()
|
|
|
+ tmp.Monitor = tmpStr + "%"
|
|
|
} else {
|
|
|
- tmp.Monitor = fmt.Sprintf("%g", rounded)
|
|
|
+ tmp.Monitor = cell.ShowValue
|
|
|
}
|
|
|
}
|
|
|
+ } else {
|
|
|
+ if cell.DataType == request.CustomTextDT {
|
|
|
+ tmp.Monitor = cell.Value
|
|
|
+ }
|
|
|
}
|
|
|
+ // switch styleConfig.Last {
|
|
|
+ // case "nt":
|
|
|
+ // // 先进行数字的百分比计算,然后保留小数点位数
|
|
|
+ // percent := tmpShowValue * 100
|
|
|
+ // if styleConfig.Decimal == nil {
|
|
|
+ // continue
|
|
|
+ // }
|
|
|
+ // factor := math.Pow(10, float64(*styleConfig.Decimal))
|
|
|
+ // rounded := math.Round(percent*factor) / factor
|
|
|
+ // tmp.Monitor = fmt.Sprintf("%g%%", rounded)
|
|
|
+ // case "decimal":
|
|
|
+ // // 先保留小数点位数,再进行百分比计算
|
|
|
+ // if styleConfig.Decimal == nil {
|
|
|
+ // continue
|
|
|
+ // }
|
|
|
+ // factor := math.Pow(10, float64(*styleConfig.Decimal))
|
|
|
+ // rounded := math.Round(tmpShowValue*factor) / factor
|
|
|
+ // if styleConfig.Nt == "percent" {
|
|
|
+ // percent := rounded * 100
|
|
|
+ // var precisionStr string
|
|
|
+ // if *styleConfig.Decimal > 2 {
|
|
|
+ // precision := *styleConfig.Decimal - 2
|
|
|
+ // precisionStr = strconv.FormatFloat(rounded, 'f', precision, 64)
|
|
|
+ // } else {
|
|
|
+ // precisionStr = strconv.FormatFloat(math.Round(percent), 'f', -1, 64)
|
|
|
+ // }
|
|
|
+ // tmp.Monitor = fmt.Sprintf("%s%%", precisionStr)
|
|
|
+ // } else {
|
|
|
+ // tmp.Monitor = fmt.Sprintf("%g", rounded)
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
|
|
|
}
|
|
|
dataCol = append(dataCol, tmp)
|