|
@@ -27,7 +27,7 @@ func GetEdbDataManualMaxOrMinDate(edbCode string) (min_date, max_date string, er
|
|
|
type ManualEdbdata struct {
|
|
|
TradeCode string `orm:"column(TRADE_CODE);pk" description:"指标编码"`
|
|
|
Dt string `orm:"column(DT)" description:"日期"`
|
|
|
- Close string `orm:"column(CLOSE)" description:"值"`
|
|
|
+ Close float64 `orm:"column(CLOSE)" description:"值"`
|
|
|
ModifyTime time.Time `orm:"column(modify_time)" description:"修改时间"`
|
|
|
}
|
|
|
|
|
@@ -38,7 +38,7 @@ func GetEdbdataManualByTradeCode(condition string, pars []interface{}) (item []*
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
- sql+=` ORDER BY DT DESC `
|
|
|
+ sql += ` ORDER BY DT DESC `
|
|
|
_, err = o.Raw(sql, pars).QueryRows(&item)
|
|
|
return
|
|
|
}
|
|
@@ -60,7 +60,8 @@ func ModifyEdbDataManual(edbInfoId int64, dataTime, value string) (err error) {
|
|
|
}
|
|
|
|
|
|
//刷新手工指标数据
|
|
|
-func RefreshManual(edbInfoId int, edbCode, startDate, endDate string) (err error) {
|
|
|
+func RefreshManual(item *EdbInfoList) (err error) {
|
|
|
+ //edbInfoId int, edbCode, startDate, endDate string
|
|
|
o := orm.NewOrm()
|
|
|
o.Using("data")
|
|
|
o.Begin()
|
|
@@ -72,6 +73,9 @@ func RefreshManual(edbInfoId int, edbCode, startDate, endDate string) (err error
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
+ edbInfoId := item.EdbInfoId
|
|
|
+ edbCode := item.EdbCode
|
|
|
+
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -79,36 +83,40 @@ func RefreshManual(edbInfoId int, edbCode, startDate, endDate string) (err error
|
|
|
//计算数据
|
|
|
var condition string
|
|
|
var pars []interface{}
|
|
|
-
|
|
|
if edbCode != "" {
|
|
|
condition += " AND TRADE_CODE=? "
|
|
|
pars = append(pars, edbCode)
|
|
|
}
|
|
|
|
|
|
- if startDate != "" {
|
|
|
- condition += " AND DT>=? "
|
|
|
- pars = append(pars, startDate)
|
|
|
- }
|
|
|
+ //获取已存在的手工数据
|
|
|
+ manualDataList, err := GetEdbdataManualByTradeCode(condition, pars)
|
|
|
|
|
|
- if endDate != "" {
|
|
|
- condition += " AND DT<=? "
|
|
|
- pars = append(pars, endDate)
|
|
|
+ var existCondition string
|
|
|
+ var existPars []interface{}
|
|
|
+ if edbCode != "" {
|
|
|
+ existCondition += " AND edb_code=? "
|
|
|
+ existPars = append(existPars, edbCode)
|
|
|
+ }
|
|
|
+ //获取ETA指标库已存在的所有数据
|
|
|
+ existDataList, err := GetEdbDataListAll(existCondition, existPars, utils.DATA_SOURCE_MANUAL, 0)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
}
|
|
|
|
|
|
- manualDataList, err := GetEdbdataManualByTradeCode(condition, pars)
|
|
|
+ existMap := make(map[string]*EdbInfoSearchData)
|
|
|
+ for _, v := range existDataList {
|
|
|
+ existMap[v.DataTime] = v
|
|
|
+ }
|
|
|
|
|
|
addSql := ` INSERT INTO edb_data_manual(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
|
|
|
var isAdd bool
|
|
|
+ manualMap := make(map[string]*ManualEdbdata)
|
|
|
for _, v := range manualDataList {
|
|
|
item := v
|
|
|
- count, err := GetEdbDataManualByCodeAndDate(v.TradeCode, v.Dt)
|
|
|
- if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
- return err
|
|
|
- }
|
|
|
- if count <= 0 {
|
|
|
+ eDate := item.Dt
|
|
|
+ sValue := utils.SubFloatToString(item.Close, 4)
|
|
|
+ if findItem, ok := existMap[v.Dt]; !ok {
|
|
|
nowStr := time.Now().Format(utils.FormatDateTime)
|
|
|
- eDate := item.Dt
|
|
|
- sValue := item.Close
|
|
|
dataTime, err := time.Parse(utils.FormatDate, eDate)
|
|
|
if err != nil {
|
|
|
return err
|
|
@@ -121,12 +129,22 @@ func RefreshManual(edbInfoId int, edbCode, startDate, endDate string) (err error
|
|
|
addSql += "),"
|
|
|
isAdd = true
|
|
|
} else {
|
|
|
- err = ModifyEdbDataManual(int64(edbInfoId), v.Dt, v.Close)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
+ if item.Close != findItem.Value {
|
|
|
+ err = ModifyEdbDataManual(int64(edbInfoId), eDate, sValue)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ manualMap[v.Dt] = v
|
|
|
}
|
|
|
+
|
|
|
+ for _, v := range existDataList {
|
|
|
+ if _, ok := manualMap[v.DataTime]; !ok {
|
|
|
+ go DeleteEdbDataByIdAndSource(v.EdbDataId, utils.DATA_SOURCE_MANUAL)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if isAdd {
|
|
|
addSql = strings.TrimRight(addSql, ",")
|
|
|
_, err = o.Raw(addSql).Exec()
|