package data_manage import ( "context" "errors" "fmt" "hongze/hongze_task/models/data_manage" "hongze/hongze_task/utils" "rdluck_tools/http" "time" ) //刷新同花顺数据 func RefreshDataFromThs() (err error) { defer func() { if err != nil { fmt.Println("RefreshDataFromThs Err:" + err.Error()) go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromThs ErrMsg:"+err.Error(), utils.EmailSendToUsers) } }() var condition string var pars []interface{} condition += " AND source=? " pars = append(pars, utils.DATA_SOURCE_THS) items, err := data_manage.GetEdbInfoByCondition(condition, pars) if err != nil { return errors.New("GetEdbInfoByCondition:" + err.Error()) } now := time.Now() var endDate string if now.Hour() == 0 { endDate = time.Now().AddDate(0, 0, -1).Format(utils.FormatDate) } else { endDate = time.Now().Format(utils.FormatDate) } for _, v := range items { startDate := v.EndDate.AddDate(0, 0, -3).Format(utils.FormatDate) err = SyncEdbDataByThs(int64(v.EdbInfoId), v.EdbCode, startDate, endDate) if err != nil { return errors.New("SyncEdbDataByThs:" + err.Error()) } item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode) if err != nil { return err } if item != nil { err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item) if err != nil { return err } } //minDate, maxDate, err := data_manage.GetEdbDataThsMaxOrMinDate(v.EdbInfoId) //if err != nil { // return errors.New("GetEdbDataThsMaxOrMinDate:" + err.Error()) //} //fmt.Println("minDate:" + minDate + ";maxDate:" + maxDate) //err = data_manage.ModifyEdbDataInfoDate(v.EdbInfoId, maxDate) //if err != nil { // return errors.New("ModifyEdbDataInfoDate:" + err.Error()) //} } return err } //刷新万得数据 func RefreshDataFromWind() (err error) { defer func() { if err != nil { fmt.Println("RefreshDataFromWind Err:" + err.Error()) go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromWind ErrMsg:"+err.Error(), utils.EmailSendToUsers) } }() var condition string var pars []interface{} condition += " AND source=? " pars = append(pars, utils.DATA_SOURCE_WIND) items, err := data_manage.GetEdbInfoByCondition(condition, pars) if err != nil { return err } now := time.Now() var endDate string if now.Hour() == 0 { endDate = time.Now().AddDate(0, 0, -1).Format(utils.FormatDate) } else { endDate = time.Now().Format(utils.FormatDate) } for _, v := range items { startDate := v.EndDate.AddDate(0, 0, -3).Format(utils.FormatDate) err = SyncEdbDataByWind(int64(v.EdbInfoId), v.EdbCode, startDate, endDate) if err != nil { return err } item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode) if err != nil { return err } if item != nil { err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item) if err != nil { return err } } } return err } //刷新彭博数据 func RefreshDataFromPb() (err error) { defer func() { if err != nil { fmt.Println("RefreshDataFromPb Err:" + err.Error()) go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromPb ErrMsg:"+err.Error(), utils.EmailSendToUsers) } }() var condition string var pars []interface{} condition += " AND source=? " pars = append(pars, utils.DATA_SOURCE_PB) items, err := data_manage.GetEdbInfoByCondition(condition, pars) if err != nil { return errors.New("GetEdbInfoByCondition:" + err.Error()) } now := time.Now() var endDate string if now.Hour() == 0 { endDate = time.Now().AddDate(0, 0, -1).Format(utils.FormatDate) } else { endDate = time.Now().Format(utils.FormatDate) } for _, v := range items { startDate := v.EndDate.AddDate(0, 0, -3).Format(utils.FormatDateUnSpace) fmt.Println(startDate, endDate) err = SyncEdbDataByPb(int64(v.EdbInfoId), v.EdbCode, startDate, endDate) if err != nil { return errors.New("SyncEdbDataByPb:" + err.Error()) } item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode) if err != nil { return err } if item != nil { err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item) if err != nil { return err } } //minDate, maxDate, err := data_manage.GetEdbDataPbMaxOrMinDate(v.EdbInfoId) //if err != nil { // return errors.New("GetEdbDataThsMaxOrMinDate:" + err.Error()) //} //fmt.Println("minDate:" + minDate + ";maxDate:" + maxDate) //err = data_manage.ModifyEdbDataInfoDate(v.EdbInfoId, maxDate) //if err != nil { // return errors.New("ModifyEdbDataInfoDate:" + err.Error()) //} } return err } func CheckDataInterface(cont context.Context) (err error) { go func() { checkUrl := utils.Hz_Data_Url + `hz_server` body, err := http.Get(checkUrl) if err != nil { go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "CheckDataInterface ErrMsg:"+err.Error(), utils.EmailSendToUsers) } result := string(body) if result != "1" { go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "CheckDataInterface ErrMsg:"+string(body), utils.EmailSendToUsers) } }() return } func CheckPbDataInterface(cont context.Context) (err error) { go func() { checkUrl := utils.Hz_Data_PB_Url + `hz_server` body, err := http.Get(checkUrl) if err != nil { go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "CheckPbDataInterface ErrMsg:"+err.Error(), utils.EmailSendToUsers) } result := string(body) if result != "1" { go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "CheckPbDataInterface ErrMsg:"+string(body), utils.EmailSendToUsers) } }() return } //刷新计算指标数据 func RefreshDataFromCalculate() (err error) { defer func() { if err != nil { fmt.Println("RefreshDataFromCalculate Err:" + err.Error()) go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromCalculate ErrMsg:"+err.Error(), utils.EmailSendToUsers) } }() var condition string var pars []interface{} condition += " AND source=? " pars = append(pars, utils.DATA_SOURCE_CALCULATE) items, err := data_manage.GetEdbInfoByCondition(condition, pars) if err != nil { return err } now := time.Now() var endDate string if now.Hour() == 0 { endDate = time.Now().AddDate(0, 0, -1).Format(utils.FormatDate) } else { endDate = time.Now().Format(utils.FormatDate) } for _, v := range items { startDate := v.EndDate.AddDate(0, 0, -3).Format(utils.FormatDate) var edbInfoIdBytes []string calculateMap, err := data_manage.GetEdbInfoCalculateDetail(int(v.EdbInfoId)) if err != nil { return err } var formulaStr string edbInfoList := make([]*data_manage.EdbInfo, 0) for _, v := range calculateMap { formulaStr += v.FromTag + "," edbInfoIdBytes = append(edbInfoIdBytes, v.FromTag) edbInfo, _ := data_manage.GetEdbInfoById(v.FromEdbInfoId) edbInfoList = append(edbInfoList, edbInfo) } err = RefreshCalculate(edbInfoList, v.EdbInfoId, v.EdbCode, v.CalculateFormula, startDate, endDate, edbInfoIdBytes) if err != nil { return err } } return err }