|
@@ -5,6 +5,7 @@ import (
|
|
|
"fmt"
|
|
|
"sort"
|
|
|
"strings"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
// CheckFormula 检测计算公式是否异常
|
|
@@ -37,7 +38,7 @@ type FormulaListItem struct {
|
|
|
}
|
|
|
|
|
|
// HandleFormulaJson 处理计算公式json串是否异常
|
|
|
-func HandleFormulaJson(formula string, startDate string) (dateSlice []string, formulaMap map[string]string, err error) {
|
|
|
+func HandleFormulaJson(formula string, endDate time.Time) (dateSlice []string, formulaMap map[string]string, err error) {
|
|
|
list := make([]FormulaListItem, 0)
|
|
|
err = json.Unmarshal([]byte(formula), &list)
|
|
|
if err != nil {
|
|
@@ -46,16 +47,18 @@ func HandleFormulaJson(formula string, startDate string) (dateSlice []string, fo
|
|
|
}
|
|
|
formulaMap = make(map[string]string)
|
|
|
dateSlice = make([]string, 0)
|
|
|
+ // 查找最后的一天作为首个公式的起始日期
|
|
|
+ maxDate := endDate.AddDate(0, 0, 1).Format(FormatDate)
|
|
|
// 日期排序
|
|
|
for k, v := range list {
|
|
|
if k == 0 { // 首个日期均为起始日
|
|
|
- v.Date = startDate
|
|
|
+ v.Date = maxDate
|
|
|
}
|
|
|
formulaMap[v.Date] = v.Formula
|
|
|
dateSlice = append(dateSlice, v.Date)
|
|
|
}
|
|
|
sort.Slice(dateSlice, func(i, j int) bool {
|
|
|
- return dateSlice[i] > dateSlice[j]
|
|
|
+ return dateSlice[i] < dateSlice[j]
|
|
|
})
|
|
|
|
|
|
return
|