|
@@ -7,7 +7,6 @@ import (
|
|
"github.com/beego/beego/v2/client/orm"
|
|
"github.com/beego/beego/v2/client/orm"
|
|
"github.com/shopspring/decimal"
|
|
"github.com/shopspring/decimal"
|
|
"github.com/yidane/formula"
|
|
"github.com/yidane/formula"
|
|
- "regexp"
|
|
|
|
"strconv"
|
|
"strconv"
|
|
"strings"
|
|
"strings"
|
|
"time"
|
|
"time"
|
|
@@ -515,13 +514,13 @@ func refreshAllCalculate(to orm.TxOrmer, edbInfoIdArr []*EdbInfo, edbInfoId, sou
|
|
func ReplaceFormula(edbInfoIdArr []*EdbInfo, valArr, valArrMax map[int]float64, formulaMap map[string]string, formulaStr string, edbInfoIdBytes []string, maxDealFlag bool) string {
|
|
func ReplaceFormula(edbInfoIdArr []*EdbInfo, valArr, valArrMax map[int]float64, formulaMap map[string]string, formulaStr string, edbInfoIdBytes []string, maxDealFlag bool) string {
|
|
// todo 先处理max和min函数的特殊情况
|
|
// todo 先处理max和min函数的特殊情况
|
|
//if strings.Contains(formulaStr, "MAX") || strings.Contains(formulaStr, "MIN") {
|
|
//if strings.Contains(formulaStr, "MAX") || strings.Contains(formulaStr, "MIN") {
|
|
- if maxDealFlag {
|
|
|
|
- formulaStr = GetMaxMinEdbInfo(formulaStr)
|
|
|
|
- }
|
|
|
|
funMap := GetFormulaMap()
|
|
funMap := GetFormulaMap()
|
|
for k, v := range funMap {
|
|
for k, v := range funMap {
|
|
formulaStr = strings.Replace(formulaStr, k, v, -1)
|
|
formulaStr = strings.Replace(formulaStr, k, v, -1)
|
|
}
|
|
}
|
|
|
|
+ if maxDealFlag {
|
|
|
|
+ formulaStr = GetMaxMinEdbInfo(formulaStr)
|
|
|
|
+ }
|
|
replaceCount := 0
|
|
replaceCount := 0
|
|
for dk, dv := range edbInfoIdArr {
|
|
for dk, dv := range edbInfoIdArr {
|
|
var isReplace bool
|
|
var isReplace bool
|
|
@@ -576,7 +575,7 @@ func GetFormulaMap() map[string]string {
|
|
funMap["FLOOR"] = "[@^]"
|
|
funMap["FLOOR"] = "[@^]"
|
|
funMap["MOD"] = "[@&]"
|
|
funMap["MOD"] = "[@&]"
|
|
funMap["POW"] = "[@*]"
|
|
funMap["POW"] = "[@*]"
|
|
- funMap["ROUND"] = "[@(]"
|
|
|
|
|
|
+ funMap["ROUND"] = "[@`]"
|
|
funMap["LN"] = "[@-]"
|
|
funMap["LN"] = "[@-]"
|
|
funMap["EXP"] = "[@+]"
|
|
funMap["EXP"] = "[@+]"
|
|
return funMap
|
|
return funMap
|
|
@@ -676,7 +675,7 @@ func HandleDateSaveDataMap(dateList []string, maxStartDate, minLatestDate time.T
|
|
if dateTime.Before(maxStartDate) {
|
|
if dateTime.Before(maxStartDate) {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
- // 如果当前日期晚于数据的最小结束日期,那么不处理,直接返回了
|
|
|
|
|
|
+ // todo 规则是否生效如果当前日期晚于数据的最小结束日期,那么不处理,直接返回了
|
|
if dateTime.After(minLatestDate) {
|
|
if dateTime.After(minLatestDate) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -851,21 +850,25 @@ func handleDateDataMapZero(saveDataMap map[string]map[int]float64, date string,
|
|
}
|
|
}
|
|
|
|
|
|
func GetMaxMinEdbInfo(formula string) string {
|
|
func GetMaxMinEdbInfo(formula string) string {
|
|
- //formula := "A+min(A,B,max(A,C))"
|
|
|
|
- // todo 无法处理max里嵌套max或者min的情况
|
|
|
|
- // 使用正则表达式匹配MAX和MIN函数及其参数
|
|
|
|
- regex := regexp.MustCompile(`(?i)(MAX|MIN)\((.*?)\)`)
|
|
|
|
- matches := regex.FindAllStringSubmatch(formula, -1)
|
|
|
|
- // 遍历匹配结果,输出MAX和MIN函数及其参数
|
|
|
|
- for _, match := range matches {
|
|
|
|
- if len(match) == 3 {
|
|
|
|
- parameter := strings.ToLower(match[0]) // 参数
|
|
|
|
- formula = strings.ReplaceAll(formula, match[0], parameter)
|
|
|
|
- fmt.Printf("formula: %s\n", formula)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- formula = strings.ReplaceAll(formula, "max", "MAX")
|
|
|
|
- formula = strings.ReplaceAll(formula, "min", "MIN")
|
|
|
|
|
|
+ flag := 0
|
|
|
|
+ for k, v := range formula {
|
|
|
|
+ if v >= 65 && v <= 122 {
|
|
|
|
+ // 从左边找到第一个左括号的位置,往前截取三个字符,判断是不是max或者min,如果是的话,把该入参改成小写
|
|
|
|
+ for i := k; i >= 4; i-- {
|
|
|
|
+ if formula[i:i+1] == "(" && flag >= 1 {
|
|
|
|
+ t := formula[i-4 : i]
|
|
|
|
+ if t == "[@@]" || t == "[@!]" {
|
|
|
|
+ formula = formula[:k] + strings.ToLower(formula[k:k+1]) + formula[k+1:]
|
|
|
|
+ }
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else if formula[k:k+1] == "(" {
|
|
|
|
+ flag += 1
|
|
|
|
+ } else if formula[k:k+1] == ")" {
|
|
|
|
+ flag -= 1
|
|
|
|
+ }
|
|
|
|
+ }
|
|
return formula
|
|
return formula
|
|
}
|
|
}
|
|
|
|
|