|
@@ -40,10 +40,10 @@ type ChartRangeAnalysisAutoDateConf struct {
|
|
|
type ChartRangeAnalysisAutoDateChangeConf struct {
|
|
|
BaseDateType int `description:"基准日期类型:0指标日期,1系统日期,2固定日期"`
|
|
|
MoveForward int `description:"前移的期数"`
|
|
|
- DateChange []*EdbDateConfDateChange
|
|
|
+ DateChange []*EdbDataDateChangeConf
|
|
|
}
|
|
|
|
|
|
-type EdbDateConfDateChange struct {
|
|
|
+type EdbDataDateChangeConf struct {
|
|
|
Year int
|
|
|
Month int
|
|
|
Day int
|
|
@@ -436,7 +436,7 @@ func HandleRangeAnalysisDataByCalculateType(originList []*ChartRangeAnalysisDate
|
|
|
switch calculateType {
|
|
|
case 0:
|
|
|
var sum float64
|
|
|
- if req.DateRangeType == 0 {
|
|
|
+ if req.DateRangeType == 0 && req.AutoDateConf.IsAutoStartDate > 0 {
|
|
|
for _, item := range originList {
|
|
|
for _, v := range item.DataList {
|
|
|
sum = 0
|
|
@@ -476,7 +476,7 @@ func HandleRangeAnalysisDataByCalculateType(originList []*ChartRangeAnalysisDate
|
|
|
|
|
|
case 1:
|
|
|
var sum float64
|
|
|
- if req.DateRangeType == 0 {
|
|
|
+ if req.DateRangeType == 0 && req.AutoDateConf.IsAutoStartDate > 0 {
|
|
|
for _, item := range originList {
|
|
|
sum = 0
|
|
|
for _, v := range item.DataList {
|
|
@@ -516,7 +516,7 @@ func HandleRangeAnalysisDataByCalculateType(originList []*ChartRangeAnalysisDate
|
|
|
}
|
|
|
|
|
|
case 2:
|
|
|
- if req.DateRangeType == 0 {
|
|
|
+ if req.DateRangeType == 0 && req.AutoDateConf.IsAutoStartDate > 0 {
|
|
|
for _, item := range originList {
|
|
|
for _, v := range item.DataList {
|
|
|
var baseVal float64
|
|
@@ -530,9 +530,13 @@ func HandleRangeAnalysisDataByCalculateType(originList []*ChartRangeAnalysisDate
|
|
|
continue
|
|
|
}
|
|
|
baseVal = calDataList[len(calDataList)-1].Value
|
|
|
+ baseDate := calDataList[len(calDataList)-1].DataTime
|
|
|
if baseVal == 0 {
|
|
|
continue
|
|
|
}
|
|
|
+ if v.DataTime == baseDate {
|
|
|
+ continue
|
|
|
+ }
|
|
|
|
|
|
val := (v.Value - baseVal) / baseVal
|
|
|
val, _ = decimal.NewFromFloat(val).Round(4).Float64()
|
|
@@ -545,13 +549,17 @@ func HandleRangeAnalysisDataByCalculateType(originList []*ChartRangeAnalysisDate
|
|
|
}
|
|
|
} else {
|
|
|
for _, item := range originList {
|
|
|
- var baseVal float64
|
|
|
- for k, v := range item.DataList {
|
|
|
- if k == 0 {
|
|
|
- baseVal = v.Value
|
|
|
- if baseVal == 0 {
|
|
|
- break
|
|
|
- }
|
|
|
+ if len(item.DataList) == 0 {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ baseVal := item.DataList[len(item.DataList)-1].Value
|
|
|
+ baseDate := item.DataList[len(item.DataList)-1].DataTime
|
|
|
+ if baseVal == 0 {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ for _, v := range item.DataList {
|
|
|
+ if v.DataTime == baseDate {
|
|
|
+ continue
|
|
|
}
|
|
|
val := (v.Value - baseVal) / baseVal
|
|
|
val, _ = decimal.NewFromFloat(val).Round(4).Float64()
|
|
@@ -564,7 +572,7 @@ func HandleRangeAnalysisDataByCalculateType(originList []*ChartRangeAnalysisDate
|
|
|
}
|
|
|
}
|
|
|
case 3:
|
|
|
- if req.DateRangeType == 0 {
|
|
|
+ if req.DateRangeType == 0 && req.AutoDateConf.IsAutoStartDate > 0 {
|
|
|
for _, item := range originList {
|
|
|
for _, v := range item.DataList {
|
|
|
var baseVal float64
|
|
@@ -606,15 +614,16 @@ func HandleRangeAnalysisDataByCalculateType(originList []*ChartRangeAnalysisDate
|
|
|
}
|
|
|
} else {
|
|
|
for _, item := range originList {
|
|
|
- var baseVal float64
|
|
|
- var baseDate string
|
|
|
- for k, v := range item.DataList {
|
|
|
- if k == 0 {
|
|
|
- baseVal = v.Value
|
|
|
- baseDate = v.DataTime
|
|
|
- if baseVal == 0 {
|
|
|
- break
|
|
|
- }
|
|
|
+ if len(item.DataList) == 0 {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ baseVal := item.DataList[len(item.DataList)-1].Value
|
|
|
+ baseDate := item.DataList[len(item.DataList)-1].DataTime
|
|
|
+ if baseVal == 0 {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ for _, v := range item.DataList {
|
|
|
+ if v.DataTime == baseDate {
|
|
|
continue
|
|
|
}
|
|
|
baseDateT, e := time.ParseInLocation(utils.FormatDate, baseDate, time.Local)
|
|
@@ -638,7 +647,7 @@ func HandleRangeAnalysisDataByCalculateType(originList []*ChartRangeAnalysisDate
|
|
|
}
|
|
|
case 4:
|
|
|
var maxVal float64
|
|
|
- if req.DateRangeType == 0 {
|
|
|
+ if req.DateRangeType == 0 && req.AutoDateConf.IsAutoStartDate > 0 {
|
|
|
for _, item := range originList {
|
|
|
for _, v := range item.DataList {
|
|
|
calDataList, e := GetAutoCalculateDateDataList(v.DataTime, originDataList, req)
|
|
@@ -677,7 +686,7 @@ func HandleRangeAnalysisDataByCalculateType(originList []*ChartRangeAnalysisDate
|
|
|
}
|
|
|
case 5:
|
|
|
var minVal float64
|
|
|
- if req.DateRangeType == 0 {
|
|
|
+ if req.DateRangeType == 0 && req.AutoDateConf.IsAutoStartDate > 0 {
|
|
|
for _, item := range originList {
|
|
|
for _, v := range item.DataList {
|
|
|
calDataList, e := GetAutoCalculateDateDataList(v.DataTime, originDataList, req)
|
|
@@ -753,7 +762,13 @@ func GetRangeAnalysisChartDataByEdbInfo(fromEdbInfo *EdbInfo, calculateFormula R
|
|
|
|
|
|
var startDateTime, endDateTime time.Time
|
|
|
startDateTime = edbStartDateTime
|
|
|
-
|
|
|
+ if calculateFormula.AutoDateConf.IsAutoStartDate == 0 {
|
|
|
+ startDate := calculateFormula.AutoDateConf.StartDate
|
|
|
+ if startDate == "" {
|
|
|
+ startDate = "2020-01-01"
|
|
|
+ }
|
|
|
+ startDateTime, _ = time.ParseInLocation(utils.FormatDate, startDate, time.Local)
|
|
|
+ }
|
|
|
if calculateFormula.AutoDateConf.IsAutoEndDate == 0 {
|
|
|
endDate := calculateFormula.AutoDateConf.EndDate
|
|
|
if endDate == "" {
|
|
@@ -891,20 +906,21 @@ func GetEdbDateByMoveForward(startDate string, moveForward int, edbDataList []*E
|
|
|
for _, v := range edbDataList {
|
|
|
if v.DataTime == startDate {
|
|
|
index += 1
|
|
|
+ continue
|
|
|
}
|
|
|
- if index > 0 {
|
|
|
- index += 1
|
|
|
- }
|
|
|
- if index == moveForward {
|
|
|
+ if index >= moveForward {
|
|
|
date = v.DataTime
|
|
|
break
|
|
|
}
|
|
|
+ if index > 0 {
|
|
|
+ index += 1
|
|
|
+ }
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
|
|
|
-func HandleEdbDateChange(date string, dateChange []*EdbDateConfDateChange) (newDate string, err error) {
|
|
|
+func HandleEdbDateChange(date string, dateChange []*EdbDataDateChangeConf) (newDate string, err error) {
|
|
|
newDate = date
|
|
|
if newDate != "" {
|
|
|
if len(dateChange) > 0 {
|