|
@@ -2216,7 +2216,7 @@ func getEdbRuleTitle(edbInfo, parentEdbInfo *data_manage.EdbInfo, childList []da
|
|
|
// 规则
|
|
|
switch edbInfo.Source {
|
|
|
case utils.DATA_SOURCE_CALCULATE, utils.DATA_SOURCE_PREDICT_CALCULATE:
|
|
|
- ruleTitle = "=" + edbInfo.CalculateFormula
|
|
|
+ ruleTitle = formatCalculateFormula(edbInfo.CalculateFormula)
|
|
|
case utils.DATA_SOURCE_CALCULATE_LJZZY, utils.DATA_SOURCE_PREDICT_CALCULATE_LJZZY:
|
|
|
ruleTitle = `累计转月值计算`
|
|
|
ruleTitleEn = `Cumulative to Monthly Calculation`
|
|
@@ -2388,6 +2388,76 @@ func getEdbRuleTitle(edbInfo, parentEdbInfo *data_manage.EdbInfo, childList []da
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+func formatCalculateFormula(calculateFormula string) (ruleTitle string) {
|
|
|
+ var tmpCalculateFormula []map[string]string
|
|
|
+ if e := json.Unmarshal([]byte(calculateFormula), &tmpCalculateFormula); e != nil {
|
|
|
+ ruleTitle = "=" + calculateFormula
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //newCalculateFormula := make([]map[string]string, 0)
|
|
|
+ sort.Slice(tmpCalculateFormula, func(i, j int) bool {
|
|
|
+ return compareDates(tmpCalculateFormula[i]["d"], tmpCalculateFormula[j]["d"])
|
|
|
+ })
|
|
|
+ newCalculateFormulaStr := "<div><div>计算公式:</div>"
|
|
|
+ for i, entry := range tmpCalculateFormula {
|
|
|
+ if formula, ok := entry["f"]; ok {
|
|
|
+ dateStr := determineDateRange(i, len(tmpCalculateFormula), tmpCalculateFormula)
|
|
|
+ newCalculateFormulaStr += "<div>" + formula + "," + dateStr + "</div>"
|
|
|
+ //singleFormula := make(map[string]string)
|
|
|
+ //singleFormula["公式"] = formula
|
|
|
+ //singleFormula["日期"] = determineDateRange(i, len(tmpCalculateFormula), tmpCalculateFormula)
|
|
|
+ //newCalculateFormula = append(newCalculateFormula, singleFormula)
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ newCalculateFormulaStr += "</div>"
|
|
|
+ ruleTitle = newCalculateFormulaStr
|
|
|
+ //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) {
|