|
@@ -5,7 +5,6 @@ import (
|
|
|
"eta/eta_index_lib/utils"
|
|
|
"fmt"
|
|
|
"github.com/beego/beego/v2/client/orm"
|
|
|
- "github.com/shopspring/decimal"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
@@ -228,73 +227,58 @@ func refreshAllPredictCalculatePhaseShift(to orm.TxOrmer, edbInfoId, source, sub
|
|
|
dataMap[v.DataTime] = v
|
|
|
}
|
|
|
|
|
|
- fmt.Println("source:", source)
|
|
|
-
|
|
|
- existDataList := make([]*EdbData, 0)
|
|
|
- dataTableName := GetEdbDataTableName(source, subSource)
|
|
|
- fmt.Println("dataTableName:", dataTableName)
|
|
|
- sql := `SELECT * FROM %s WHERE edb_info_id=? `
|
|
|
- sql = fmt.Sprintf(sql, dataTableName)
|
|
|
- _, err = to.Raw(sql, edbInfoId).QueryRows(&existDataList)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- existDataMap := make(map[string]string)
|
|
|
- removeDateMap := make(map[string]string)
|
|
|
- for _, v := range existDataList {
|
|
|
- existDataMap[v.DataTime] = v.Value
|
|
|
- }
|
|
|
- fmt.Println("existDataMap:", existDataMap)
|
|
|
addSql := ` INSERT INTO edb_data_predict_calculate_phase_shift(edb_info_id,edb_code,data_time,value,create_time,modify_time,data_timestamp) values `
|
|
|
var isAdd bool
|
|
|
|
|
|
- existMap := make(map[string]string)
|
|
|
+ resultMap := make(map[string]float64)
|
|
|
dataLen := len(dataList)
|
|
|
for i := 0; i < dataLen; i++ {
|
|
|
-
|
|
|
- currentItem := dataList[i]
|
|
|
- existKey := edbCode + currentItem.DataTime
|
|
|
- if _, ok := existMap[existKey]; !ok {
|
|
|
- currentDate, _ := time.ParseInLocation(utils.FormatDate, currentItem.DataTime, time.Local)
|
|
|
-
|
|
|
- shiftDay := CalculateIntervalDays(moveFrequency, formulaInt, currentDate)
|
|
|
- if moveType == 2 {
|
|
|
- shiftDay = -shiftDay
|
|
|
- }
|
|
|
- latestDateStr = latestDate.AddDate(0, 0, shiftDay).Format(utils.FormatDate)
|
|
|
- newDate := currentDate.AddDate(0, 0, shiftDay)
|
|
|
+
|
|
|
+ currentIndex := dataList[i]
|
|
|
|
|
|
- timestamp := newDate.UnixNano() / 1e6
|
|
|
- timestampStr := fmt.Sprintf("%d", timestamp)
|
|
|
- valStr := decimal.NewFromFloat(currentItem.Value).Round(4).String()
|
|
|
- if latestDateStr == newDate.Format(utils.FormatDate) {
|
|
|
- latestValue = currentItem.Value
|
|
|
- }
|
|
|
- if existVal, ok := existDataMap[newDate.Format(utils.FormatDate)]; !ok {
|
|
|
- isAdd = true
|
|
|
- addSql += GetAddSql(edbInfoIdStr, edbCode, newDate.Format(utils.FormatDate), timestampStr, valStr)
|
|
|
+
|
|
|
+ if moveType != 2 {
|
|
|
+ periods := dataLen - i + formulaInt - 1
|
|
|
+ if periods < dataLen {
|
|
|
+ newIndex := dataList[i]
|
|
|
+ resultMap[newIndex.DataTime] = currentIndex.Value
|
|
|
} else {
|
|
|
- var existValDecimal decimal.Decimal
|
|
|
- existValDecimal, err = decimal.NewFromString(existVal)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- existStr := existValDecimal.String()
|
|
|
- if existStr != valStr {
|
|
|
- sql = ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
|
|
|
- sql = fmt.Sprintf(sql, dataTableName)
|
|
|
- _, err = to.Raw(sql, valStr, edbInfoId, newDate.Format(utils.FormatDate)).Exec()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+ currentDate, _ := time.ParseInLocation(utils.FormatDate, currentIndex.DataTime, time.Local)
|
|
|
+
|
|
|
+ shiftDay := CalculateIntervalDays(moveFrequency, formulaInt, currentDate, resultMap, moveType)
|
|
|
+
|
|
|
+ latestDateStr = latestDate.AddDate(0, 0, shiftDay).Format(utils.FormatDate)
|
|
|
+ newDate := currentDate.AddDate(0, 0, shiftDay)
|
|
|
+ format := newDate.Format(utils.FormatDate)
|
|
|
+ resultMap[format] = currentIndex.Value
|
|
|
}
|
|
|
+ } else {
|
|
|
+
|
|
|
+ periods := dataLen - i - formulaInt
|
|
|
+ if periods > 0 {
|
|
|
+ newIndex := dataList[periods]
|
|
|
+ resultMap[newIndex.DataTime] = currentIndex.Value
|
|
|
+ } else {
|
|
|
+
|
|
|
+ currentDate, _ := time.ParseInLocation(utils.FormatDate, currentIndex.DataTime, time.Local)
|
|
|
|
|
|
-
|
|
|
- delete(removeDateMap, newDate.Format(utils.FormatDate))
|
|
|
+ shiftDay := CalculateIntervalDays(moveFrequency, formulaInt, currentDate, resultMap, moveType)
|
|
|
+
|
|
|
+ latestDateStr = latestDate.AddDate(0, 0, -shiftDay).Format(utils.FormatDate)
|
|
|
+ newDate := currentDate.AddDate(0, 0, -shiftDay)
|
|
|
+ format := newDate.Format(utils.FormatDate)
|
|
|
+ resultMap[format] = currentIndex.Value
|
|
|
+ }
|
|
|
}
|
|
|
- existMap[existKey] = currentItem.DataTime
|
|
|
+ }
|
|
|
+
|
|
|
+ for key, value := range resultMap {
|
|
|
+ currentDate, _ := time.ParseInLocation(utils.FormatDate, key, time.Local)
|
|
|
+ timestamp := currentDate.UnixNano() / 1e6
|
|
|
+ timestampStr := fmt.Sprintf("%d", timestamp)
|
|
|
+ addSql += GetAddSql(edbInfoIdStr, edbCode, key, timestampStr, fmt.Sprintf("%f", value))
|
|
|
+ isAdd = true
|
|
|
}
|
|
|
|
|
|
if isAdd {
|
|
@@ -305,18 +289,5 @@ func refreshAllPredictCalculatePhaseShift(to orm.TxOrmer, edbInfoId, source, sub
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- if len(removeDateMap) > 0 {
|
|
|
- removeDateList := make([]string, 0)
|
|
|
- for k := range removeDateMap {
|
|
|
- removeDateList = append(removeDateList, k)
|
|
|
- }
|
|
|
- err = DelEdbDataByMysql(to, edbInfoId, dataTableName, removeDateList)
|
|
|
- if err != nil {
|
|
|
- err = fmt.Errorf("删除年化指标数据失败,Err:" + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
return
|
|
|
}
|