|
@@ -9,12 +9,13 @@ import (
|
|
|
"eta/eta_chart_lib/services/data"
|
|
|
"eta/eta_chart_lib/utils"
|
|
|
"fmt"
|
|
|
- "github.com/shopspring/decimal"
|
|
|
- "github.com/yidane/formula"
|
|
|
"sort"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
+
|
|
|
+ "github.com/shopspring/decimal"
|
|
|
+ "github.com/yidane/formula"
|
|
|
)
|
|
|
|
|
|
// BaseCalculate
|
|
@@ -1185,10 +1186,19 @@ func handleMixCellShowStyle(showStyleList []string, calculateCellMap map[string]
|
|
|
|
|
|
cell := config[cellPosition.Column][cellPosition.Row]
|
|
|
val := cell.ShowValue
|
|
|
- isPercent := false
|
|
|
- if strings.Contains(val, "%") {
|
|
|
- isPercent = true
|
|
|
- val = strings.Trim(val, "%")
|
|
|
+ // 不支持手动输入的%数
|
|
|
+ // isPercent := false
|
|
|
+ // if strings.Contains(val, "%") {
|
|
|
+ // isPercent = true
|
|
|
+ // val = strings.Trim(val, "%")
|
|
|
+ // }
|
|
|
+ // 如果没有showValue, 则使用value
|
|
|
+ if cell.ShowValue == "" {
|
|
|
+ _, err := strconv.ParseFloat(cell.Value, 64)
|
|
|
+ if err == nil {
|
|
|
+ val = cell.Value
|
|
|
+ cell.ShowValue = cell.Value
|
|
|
+ }
|
|
|
}
|
|
|
_, e := strconv.ParseFloat(val, 64) // 将字符串转换成float类型
|
|
|
if e != nil { // 如果没有错误发生则返回true,说明该字符串是一个合法的数字
|
|
@@ -1200,13 +1210,47 @@ func handleMixCellShowStyle(showStyleList []string, calculateCellMap map[string]
|
|
|
err = fmt.Errorf("日期计算配置json解析失败失败: %s, Err:%s", config, err.Error())
|
|
|
return
|
|
|
}
|
|
|
+ hasPercent := false
|
|
|
+ if styleConf.Nt == "percent" {
|
|
|
+ hasPercent = true
|
|
|
+ }
|
|
|
|
|
|
if styleConf.Pn != 0 || styleConf.Nt != "" {
|
|
|
- val = changePointDecimalPlaces(val, styleConf.Pn, styleConf.Nt, isPercent)
|
|
|
- cell.ShowFormatValue = val
|
|
|
+ // val = changePointDecimalPlaces(val, styleConf.Pn, styleConf.Nt, isPercent)
|
|
|
+ // cell.ShowFormatValue = val
|
|
|
+ // 修复历史数据,没有保存小数位数,重置小数位数
|
|
|
+ if styleConf.Pn != 0 {
|
|
|
+ if styleConf.Decimal == nil {
|
|
|
+ styleConf.Decimal = new(int)
|
|
|
+ }
|
|
|
+ *styleConf.Decimal += styleConf.Pn
|
|
|
+ if *styleConf.Decimal < 0 {
|
|
|
+ *styleConf.Decimal = 0
|
|
|
+ }
|
|
|
+ cell.ShowFormatValue = utils.RoundNumber(cell.ShowValue, *styleConf.Decimal, hasPercent)
|
|
|
+ styleConf.Pn = 0
|
|
|
+ } else if styleConf.Decimal != nil {
|
|
|
+ cell.ShowFormatValue = utils.RoundNumber(cell.ShowValue, *styleConf.Decimal, hasPercent)
|
|
|
+ } else {
|
|
|
+ if hasPercent {
|
|
|
+ numDecimal, _ := decimal.NewFromString(cell.ShowValue)
|
|
|
+ tmpStr := numDecimal.Mul(decimal.NewFromInt(100)).String()
|
|
|
+ cell.ShowFormatValue = tmpStr + "%"
|
|
|
+ } else {
|
|
|
+ cell.ShowFormatValue = cell.ShowValue
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if styleConf.Decimal != nil {
|
|
|
+ cell.ShowFormatValue = utils.RoundNumber(cell.ShowValue, *styleConf.Decimal, hasPercent)
|
|
|
} else {
|
|
|
cell.ShowFormatValue = cell.ShowValue
|
|
|
}
|
|
|
+ // 前端传过来的json中有可能有glObj,需要去掉
|
|
|
+ styleConf.GlObj = nil
|
|
|
+ tmpStyleConf, err := json.Marshal(styleConf)
|
|
|
+ if err == nil {
|
|
|
+ cell.ShowStyle = string(tmpStyleConf)
|
|
|
+ }
|
|
|
config[cellPosition.Column][cellPosition.Row] = cell
|
|
|
}
|
|
|
}
|