|
@@ -2399,65 +2399,69 @@ func formatCalculateFormula(calculateFormula string) (ruleTitle string) {
|
|
|
var tmpCalculateFormula []map[string]string
|
|
|
if e := json.Unmarshal([]byte(calculateFormula), &tmpCalculateFormula); e != nil {
|
|
|
ruleTitle = "=" + calculateFormula
|
|
|
- } else {
|
|
|
- newCalculateFormula := make([]map[string]string, 0)
|
|
|
- sort.Slice(tmpCalculateFormula, func(i, j int) bool {
|
|
|
- if tmpCalculateFormula[i]["d"] == "" {
|
|
|
- return true
|
|
|
- }
|
|
|
- if tmpCalculateFormula[j]["d"] == "" {
|
|
|
- return false
|
|
|
- }
|
|
|
- it, e := time.Parse(utils.FormatDate, tmpCalculateFormula[i]["d"])
|
|
|
- if e != nil {
|
|
|
- return false
|
|
|
- }
|
|
|
- jt, e := time.Parse(utils.FormatDate, tmpCalculateFormula[j]["d"])
|
|
|
- if e != nil {
|
|
|
- return false
|
|
|
- }
|
|
|
- return it.Before(jt)
|
|
|
- })
|
|
|
- fLen := len(tmpCalculateFormula)
|
|
|
- for i := 0; i < fLen; i++ {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ newCalculateFormula := make([]map[string]string, 0)
|
|
|
+ sort.Slice(tmpCalculateFormula, func(i, j int) bool {
|
|
|
+ return compareDates(tmpCalculateFormula[i]["d"], tmpCalculateFormula[j]["d"])
|
|
|
+ })
|
|
|
+
|
|
|
+ for i, entry := range tmpCalculateFormula {
|
|
|
+ if formula, ok := entry["f"]; ok {
|
|
|
singleFormula := make(map[string]string)
|
|
|
- val, ok := tmpCalculateFormula[i]["f"]
|
|
|
- if !ok {
|
|
|
- continue
|
|
|
- } else {
|
|
|
- singleFormula["公式"] = val
|
|
|
- }
|
|
|
- if fLen == 1 {
|
|
|
- singleFormula["日期"] = "全部"
|
|
|
- newCalculateFormula = append(newCalculateFormula, singleFormula)
|
|
|
- break
|
|
|
- }
|
|
|
- date, ok := tmpCalculateFormula[i]["d"]
|
|
|
- if ok {
|
|
|
- var tmpDate string
|
|
|
- if len(tmpCalculateFormula) > 1 && i == 0 {
|
|
|
- tmpDate = tmpCalculateFormula[fLen-1]["d"] + "(含)之后"
|
|
|
- }
|
|
|
- if i == fLen-1 {
|
|
|
- tmpDate = tmpCalculateFormula[1]["d"] + "之前"
|
|
|
- }
|
|
|
- if fLen > 2 && i >= 1 && i < fLen-1 {
|
|
|
- tmpDate = fmt.Sprintf("%s(含)——%s", date, tmpCalculateFormula[i+1]["d"])
|
|
|
- }
|
|
|
- singleFormula["日期"] = tmpDate
|
|
|
- }
|
|
|
+ singleFormula["公式"] = formula
|
|
|
+ singleFormula["日期"] = determineDateRange(i, len(tmpCalculateFormula), tmpCalculateFormula)
|
|
|
newCalculateFormula = append(newCalculateFormula, singleFormula)
|
|
|
}
|
|
|
- b, e := json.Marshal(newCalculateFormula)
|
|
|
- if e != nil {
|
|
|
- ruleTitle = "=" + calculateFormula
|
|
|
- return
|
|
|
- }
|
|
|
+
|
|
|
+ }
|
|
|
+ if b, e := json.Marshal(newCalculateFormula); e != nil {
|
|
|
+ ruleTitle = "=" + calculateFormula
|
|
|
+ } else {
|
|
|
ruleTitle = "=" + string(b)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// compareDates 日期比较 date1 < date2 --> true
|
|
|
+func compareDates(date1, date2 string) bool {
|
|
|
+ if date1 == "" {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ if date2 == "" {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ date1Parsed, err := time.Parse(utils.FormatDate, date1)
|
|
|
+ if err != nil {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ date2Parsed, err := time.Parse(utils.FormatDate, date2)
|
|
|
+ if err != nil {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ return date1Parsed.Before(date2Parsed)
|
|
|
+}
|
|
|
+
|
|
|
+func determineDateRange(index, totalLength int, formulas []map[string]string) string {
|
|
|
+ if totalLength == 1 {
|
|
|
+ return "全部"
|
|
|
+ }
|
|
|
+
|
|
|
+ currentDate := formulas[index]["d"]
|
|
|
+ if index == 0 {
|
|
|
+ return formulas[totalLength-1]["d"] + "(含)之后"
|
|
|
+ }
|
|
|
+ if index == totalLength-1 {
|
|
|
+ return formulas[1]["d"] + "之前"
|
|
|
+ }
|
|
|
+ if index >= 1 && index < totalLength-1 {
|
|
|
+ return fmt.Sprintf("%s(含)——%s", currentDate, formulas[index+1]["d"])
|
|
|
+ }
|
|
|
+ return ""
|
|
|
+}
|
|
|
+
|
|
|
// GetEdbChartAdminList
|
|
|
// @param source 来源 :1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库 6:ETA表格
|
|
|
func GetEdbChartAdminList(source int) (list []int, err error) {
|