|
@@ -1,6 +1,7 @@
|
|
|
package data
|
|
|
|
|
|
import (
|
|
|
+ "encoding/json"
|
|
|
"errors"
|
|
|
"eta/eta_mobile/models/data_manage"
|
|
|
"eta/eta_mobile/utils"
|
|
@@ -8,6 +9,7 @@ import (
|
|
|
"github.com/shopspring/decimal"
|
|
|
"github.com/yidane/formula"
|
|
|
"math"
|
|
|
+ "sort"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
@@ -56,6 +58,52 @@ func CheckFormula2(edbInfoArr []*data_manage.EdbInfo, formulaMap map[string]stri
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+type FormulaListItem struct {
|
|
|
+ Formula string `json:"f"`
|
|
|
+ Date string `json:"d"`
|
|
|
+}
|
|
|
+
|
|
|
+// HandleFormulaJson 处理计算公式json串是否异常
|
|
|
+func HandleFormulaJson(formula string, startDate string) (dateSlice []string, formulaMap map[string]string, err error) {
|
|
|
+ list := make([]FormulaListItem, 0)
|
|
|
+ err = json.Unmarshal([]byte(formula), &list)
|
|
|
+ if err != nil {
|
|
|
+ err = fmt.Errorf("公式串解析失败: json.Unmarshal Err: %v", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ formulaMap = make(map[string]string)
|
|
|
+ dateSlice = make([]string, 0)
|
|
|
+ // 日期排序
|
|
|
+ for k, v := range list {
|
|
|
+ if k == 0 { // 首个日期均为起始日
|
|
|
+ v.Date = startDate
|
|
|
+ }
|
|
|
+ formulaMap[v.Date] = v.Formula
|
|
|
+ dateSlice = append(dateSlice, v.Date)
|
|
|
+ }
|
|
|
+ sort.Slice(dateSlice, func(i, j int) bool {
|
|
|
+ return dateSlice[i] > dateSlice[j]
|
|
|
+ })
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// CheckFormulaJson 检测计算公式json串是否异常
|
|
|
+func CheckFormulaJson(formula string) (formulaSlice []string, err error) {
|
|
|
+ list := make([]FormulaListItem, 0)
|
|
|
+ err = json.Unmarshal([]byte(formula), &list)
|
|
|
+ if err != nil {
|
|
|
+ err = fmt.Errorf("公式串解析失败: json.Unmarshal Err: %v", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ formulaSlice = make([]string, 0)
|
|
|
+ // 日期排序
|
|
|
+ for _, v := range list {
|
|
|
+ formulaSlice = append(formulaSlice, v.Formula)
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
type CalculateItems struct {
|
|
|
EdbInfoId int
|
|
|
DataMap map[string]float64
|