package data import ( "context" "errors" "fmt" "github.com/rdlucklib/rdluck_tools/http" "hongze/hongze_task/models/data_manage" "hongze/hongze_task/services/alarm_msg" "hongze/hongze_task/utils" "strings" "sync" ) // 刷新同花顺数据 func RefreshDataFromThs(wg *sync.WaitGroup) (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) go alarm_msg.SendAlarmMsg("RefreshDataFromThs ErrMsg:"+err.Error(), 3) } wg.Done() }() var condition string var pars []interface{} condition += " AND source=? " pars = append(pars, utils.DATA_SOURCE_THS) items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0) if err != nil { err = errors.New("GetEdbInfoByCondition:" + err.Error()) return } //var endDate string //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate) for _, v := range items { startDate := "" if v.Frequency == "日度" { startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) } else if v.Frequency == "周度" { startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate) } else if v.Frequency == "月度" { startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate) } else if v.Frequency == "季度" { startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate) } else if v.Frequency == "年度" { startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate) } else { startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) } //err = SyncEdbDataByThs(int64(v.EdbInfoId), v.EdbCode, startDate, endDate) //if err != nil { // err = errors.New("SyncEdbDataByThs Err:" + err.Error()) // return err //} resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate) if err != nil { return errors.New("RefreshEdbData Err:" + err.Error()) } if resp.Ret != 200 { return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg) } //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode) //if err != nil { // err = errors.New("GetEdbInfoMaxAndMinInfo Err:" + err.Error()) // return err //} //if item != nil { // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item) // if err != nil { // err = errors.New("ModifyEdbInfoMaxAndMinInfo Err:" + err.Error()) // return err // } //} } return err } // 刷新万得数据 func RefreshDataFromWind(wg *sync.WaitGroup) (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) go alarm_msg.SendAlarmMsg("RefreshDataFromWind ErrMsg:"+err.Error(), 3) } wg.Done() }() var condition string var pars []interface{} condition += ` AND source=? AND no_update = 0 ` pars = append(pars, utils.DATA_SOURCE_WIND) items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0) if err != nil { return err } //var endDate string //endDate = time.Now().Format(utils.FormatDate) for _, v := range items { startDate := "" if v.Frequency == "日度" { startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) } else if v.Frequency == "周度" { startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate) } else if v.Frequency == "月度" { startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate) } else if v.Frequency == "季度" { startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate) } else if v.Frequency == "年度" { startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate) } else { startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) } //err = SyncEdbDataByWind(int64(v.EdbInfoId), v.EdbCode, startDate, endDate) //if err != nil { // return err //} //edbInfoId, source int, edbCode, startDate string) (resp *models.BaseResponse, err error) { resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate) if err != nil { return errors.New("RefreshEdbData Err:" + err.Error()) } if resp.Ret != 200 { return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg) } //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(wg *sync.WaitGroup) (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) go alarm_msg.SendAlarmMsg("RefreshDataFromPb ErrMsg:"+err.Error(), 3) } wg.Done() }() var condition string var pars []interface{} condition += " AND source=? " pars = append(pars, utils.DATA_SOURCE_PB) items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0) if err != nil { return errors.New("GetEdbInfoByCondition:" + err.Error()) } //var endDate string //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace) for _, v := range items { startDate := "" if v.Frequency == "日度" { startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) } else if v.Frequency == "周度" { startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate) } else if v.Frequency == "月度" { startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate) } else if v.Frequency == "季度" { startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate) } else if v.Frequency == "年度" { startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate) } else { startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) } //err = SyncEdbDataByPb(int64(v.EdbInfoId), v.EdbCode, startDate, endDate) //if err != nil { // return errors.New("SyncEdbDataByPb:" + err.Error()) //} resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate) if err != nil { return errors.New("RefreshEdbData Err:" + err.Error()) } if resp.Ret != 200 { return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg) } //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.GetEdbDataPbMaxOrMinDate(v.EdbInfoId) //if err != nil { // return errors.New("GetEdbDataThsMaxOrMinDate:" + err.Error()) //} //fmt.Println("minDate:" + minDate + ";maxDate:" + maxDate) //err = data.ModifyEdbDataInfoDate(v.EdbInfoId, maxDate) //if err != nil { // return errors.New("ModifyEdbDataInfoDate:" + err.Error()) //} } return err } // RefreshDataFromPbFinance 刷新彭博财务指标数据 func RefreshDataFromPbFinance(wg *sync.WaitGroup) (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) go alarm_msg.SendAlarmMsg("RefreshDataFromPb ErrMsg:"+err.Error(), 3) } wg.Done() }() var condition string var pars []interface{} condition += " AND source=? " pars = append(pars, utils.DATA_SOURCE_PB_FINANCE) items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0) if err != nil { return errors.New("GetEdbInfoByCondition:" + err.Error()) } //var endDate string //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace) for _, v := range items { startDate := "" if v.Frequency == "日度" { startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) } else if v.Frequency == "周度" { startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate) } else if v.Frequency == "月度" { startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate) } else if v.Frequency == "季度" { startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate) } else if v.Frequency == "年度" { startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate) } else { startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) } //err = SyncEdbDataByPb(int64(v.EdbInfoId), v.EdbCode, startDate, endDate) //if err != nil { // return errors.New("SyncEdbDataByPb:" + err.Error()) //} resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate) if err != nil { return errors.New("RefreshEdbData Err:" + err.Error()) } if resp.Ret != 200 { return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg) } //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.GetEdbDataPbMaxOrMinDate(v.EdbInfoId) //if err != nil { // return errors.New("GetEdbDataThsMaxOrMinDate:" + err.Error()) //} //fmt.Println("minDate:" + minDate + ";maxDate:" + maxDate) //err = data.ModifyEdbDataInfoDate(v.EdbInfoId, maxDate) //if err != nil { // return errors.New("ModifyEdbDataInfoDate:" + err.Error()) //} } return err } 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) msg := "检测彭博数据服务器失败:CheckPbDataInterface ErrMsg:" + err.Error() go alarm_msg.SendAlarmMsg(msg, 3) } else { result := string(body) if result != "1" { //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "CheckPbDataInterface ErrMsg:"+string(body), utils.EmailSendToUsers) msg := "检测彭博数据服务器失败:CheckPbDataInterface ErrMsg:" + string(body) go alarm_msg.SendAlarmMsg(msg, 3) } } }() return } // CheckLtDataInterface 检测路透数据服务器 func CheckLtDataInterface(cont context.Context) (err error) { go func() { checkUrl := utils.Hz_Data_LT_Url + `hz_server` body, err := http.Get(checkUrl) if err != nil { //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "检测路透数据服务器失败:CheckLtDataInterface ErrMsg:"+err.Error(), utils.EmailSendToUsers) msg := "检测路透数据服务器失败:CheckLtDataInterface ErrMsg:" + err.Error() go alarm_msg.SendAlarmMsg(msg, 3) } else { result := string(body) if result != `"ek true"` { //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "检测路透数据服务器失败:CheckLtDataInterface ErrMsg:"+string(body), utils.EmailSendToUsers) msg := "检测路透数据服务器失败:CheckLtDataInterface ErrMsg:" + string(body) go alarm_msg.SendAlarmMsg(msg, 3) } } }() return } // CheckThsDataInterface 检测同花顺数据服务器 func CheckThsDataInterface(cont context.Context) (err error) { go func() { checkUrl := utils.Hz_Server_Data_Url + `hz_server` body, err := http.Get(checkUrl) if err != nil { //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "CheckPbDataInterface ErrMsg:"+err.Error(), utils.EmailSendToUsers) msg := "检测同花顺数据服务器失败:CheckThsDataInterface ErrMsg:" + err.Error() go alarm_msg.SendAlarmMsg(msg, 3) } else { result := string(body) if result != "1" { //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "CheckPbDataInterface ErrMsg:"+string(body), utils.EmailSendToUsers) msg := "检测同花顺数据服务器失败:CheckThsDataInterface ErrMsg:" + string(body) go alarm_msg.SendAlarmMsg(msg, 3) } } }() return } ////刷新所有计算指标 //func RefreshDataFromCalculateAll() (err error) { // defer func() { // if err != nil { // utils.FileLog.Info("RefreshDataFromCalculateAll Err:" + err.Error()) // go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromCalculateAll ErrMsg:"+err.Error(), utils.EmailSendToUsers) // } // }() // var condition string // var pars []interface{} // condition += " AND edb_type=? " // pars = append(pars, 2) // // //condition += " AND is_update=1 " // // items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0) // if err != nil { // return err // } // for _, v := range items { // edbInfoId := v.EdbInfoId // edbCode := v.EdbCode // source := v.Source // fmt.Println(v.EdbInfoId, v.EdbCode, v.EdbName, v.SourceName, source) // if source == utils.DATA_SOURCE_CALCULATE { // startDate := "" // if v.Frequency == "日度" { // startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) // } else if v.Frequency == "周度" { // startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate) // } else if v.Frequency == "月度" { // startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate) // } else if v.Frequency == "季度" { // startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate) // } else if v.Frequency == "年度" { // startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate) // } else { // startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) // } // endDate := time.Now().Format(utils.FormatDate) // var edbInfoIdBytes []string // calculateMap, err := data_manage.GetEdbInfoCalculateDetail(int(v.EdbInfoId)) // if err != nil { // return errors.New("GetEdbInfoCalculateDetail Err:" + err.Error()) // } // 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) // } // //endDate = "" // err = RefreshCalculate(edbInfoList, edbInfoId, edbCode, v.CalculateFormula, startDate, endDate, edbInfoIdBytes) // if err != nil { // return errors.New("RefreshCalculate Err:" + err.Error()) // } // } else if source == utils.DATA_SOURCE_CALCULATE_LJZZY { // calculateLjzzy, err := data_manage.GetEdbInfoCalculateLjzzyDetail(edbInfoId) // if err != nil { // if err.Error() == utils.ErrNoRow() { // continue // } // return errors.New("GetEdbInfoCalculateLjzzyDetail Err:" + err.Error()) // } // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateLjzzy.FromEdbInfoId) // if err != nil { // if err.Error() == utils.ErrNoRow() { // continue // } // return errors.New("GetEdbInfoById Err:" + err.Error()) // } // year := time.Now().Year() - 1 // startDate := strconv.Itoa(year) + "-01" + "-01" // endDate := "" //time.Now().Format(utils.FormatDate) // err = data_manage.RefreshCalculateLjzzy(edbInfoId, fromEdbInfo, edbCode, startDate, endDate) // if err != nil { // return errors.New("RefreshCalculateLjzzy Err:" + err.Error()) // } // } else if source == utils.DATA_SOURCE_CALCULATE_TBZ { // calculateTbz, err := data_manage.GetEdbInfoCalculateTbzDetail(edbInfoId) // if err != nil { // return errors.New("GetEdbInfoCalculateTbzDetail Err:" + err.Error()) // } // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId) // if err != nil { // if err.Error() == utils.ErrNoRow() { // continue // } // return errors.New("GetEdbInfoById Err:" + err.Error()) // } // startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate) // endDate := "" //time.Now().Format(utils.FormatDate) // err = data_manage.RefreshCalculateTbz(edbInfoId, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate) // if err != nil { // return errors.New("RefreshCalculateTbz Err:" + err.Error()) // } // } else if source == utils.DATA_SOURCE_CALCULATE_TCZ { // calculateTcz, err := data_manage.GetEdbInfoCalculateTczDetail(edbInfoId) // if err != nil { // return errors.New("GetEdbInfoCalculateTczDetail Err:" + err.Error()) // } // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTcz.FromEdbInfoId) // if err != nil { // if err.Error() == utils.ErrNoRow() { // continue // } // return errors.New("GetEdbInfoById Err:" + err.Error()) // } // startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate) // endDate := "" //time.Now().Format(utils.FormatDate) // err = data_manage.RefreshCalculateTcz(edbInfoId, fromEdbInfo, calculateTcz.EdbCode, startDate, endDate) // if err != nil { // return errors.New("RefreshCalculateTcz Err:" + err.Error()) // } // } else if source == utils.DATA_SOURCE_CALCULATE_NSZYDPJJS { // calculateNszydpjjs, err := data_manage.GetEdbInfoCalculateNszydpjjsDetail(edbInfoId) // if err != nil { // return errors.New("GetEdbInfoCalculateNszydpjjsDetail Err:" + err.Error()) // } // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateNszydpjjs.FromEdbInfoId) // if err != nil { // if err.Error() == utils.ErrNoRow() { // continue // } // return errors.New("GetEdbInfoById Err:" + err.Error()) // } // formulaInt, _ := strconv.Atoi(v.CalculateFormula) // err = data_manage.RefreshCalculateNszydpjjs(edbInfoId, v.Source, formulaInt, fromEdbInfo, calculateNszydpjjs.EdbCode) // if err != nil { // return errors.New("RefreshCalculateNszydpjjs Err:" + err.Error()) // } // } else if source == utils.DATA_SOURCE_CALCULATE_HBZ { // calculateHbz, err := data_manage.GetEdbInfoCalculateHbzDetail(edbInfoId) // if err != nil { // return errors.New("GetEdbInfoCalculateHbzDetail Err:" + err.Error()) // } // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateHbz.FromEdbInfoId) // if err != nil { // if err.Error() == utils.ErrNoRow() { // continue // } // return errors.New("GetEdbInfoById Err:" + err.Error()) // } // startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate) // endDate := "" //time.Now().Format(utils.FormatDate) // formulaInt, _ := strconv.Atoi(v.CalculateFormula) // err = data_manage.RefreshCalculateHbz(edbInfoId, source, fromEdbInfo, calculateHbz.EdbCode, startDate, endDate, formulaInt) // if err != nil { // return errors.New("RefreshCalculateTbz Err:" + err.Error()) // } // } else if source == utils.DATA_SOURCE_CALCULATE_HCZ { // calculateHcz, err := data_manage.GetEdbInfoCalculateHczDetail(edbInfoId) // if err != nil { // return errors.New("GetEdbInfoCalculateHczDetail Err:" + err.Error()) // } // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateHcz.FromEdbInfoId) // if err != nil { // if err.Error() == utils.ErrNoRow() { // continue // } // return errors.New("GetEdbInfoById Err:" + err.Error()) // } // startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate) // endDate := "" //time.Now().Format(utils.FormatDate) // err = data_manage.RefreshCalculateHcz(edbInfoId, source, fromEdbInfo, calculateHcz.EdbCode, startDate, endDate) // if err != nil { // return errors.New("RefreshCalculateTbz Err:" + err.Error()) // } // } else if source == utils.DATA_SOURCE_CALCULATE_BP { // calculateBp, err := data_manage.GetEdbInfoCalculateBpDetail(edbInfoId) // if err != nil && err.Error() != utils.ErrNoRow() { // return errors.New("GetEdbInfoCalculateBpDetail Err:" + err.Error()) // } // if calculateBp != nil { // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateBp.FromEdbInfoId) // if err != nil { // if err.Error() == utils.ErrNoRow() { // continue // } // return errors.New("GetEdbInfoById Err:" + err.Error()) // } // startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate) // endDate := "" //time.Now().Format(utils.FormatDate) // err = data_manage.RefreshCalculateBp(edbInfoId, fromEdbInfo, calculateBp.EdbCode, startDate, endDate) // if err != nil { // return errors.New("RefreshCalculateTbz Err:" + err.Error()) // } // } // } else if source == utils.DATA_SOURCE_CALCULATE_TIME_SHIFT { // calculate, err := data_manage.GetEdbInfoCalculateMappingDetail(edbInfoId) // if err != nil { // return fmt.Errorf("GetEdbInfoCalculateTbzDetail Err:" + err.Error()) // } // fromEdbInfo, err := data_manage.GetEdbInfoById(calculate.FromEdbInfoId) // if err != nil { // if err.Error() == utils.ErrNoRow() { // continue // } // return fmt.Errorf("GetEdbInfoById Err:" + err.Error()) // } // //startDate := v.StartDate.Format(utils.FormatDate) // //endDate := time.Now().Format(utils.FormatDate) // formulaInt, _ := strconv.Atoi(calculate.CalculateFormula) // err = data_manage.RefreshAllCalculateTimeShift(edbInfoId, source, formulaInt, calculate.MoveType, fromEdbInfo, calculate.EdbCode, calculate.MoveFrequency) // if err != nil { // return fmt.Errorf("RefreshAllCalculateTimeShift Err:" + err.Error()) // } // // } else if source == utils.DATA_SOURCE_CALCULATE_ZJPJ { //刷新直接拼接 // tmpEdbInfo, err := data_manage.GetEdbInfoById(v.EdbInfoId) // if err != nil { // if err.Error() == utils.ErrNoRow() { // continue // } // return fmt.Errorf("GetEdbInfoById Err:" + err.Error()) // } // err = data_manage.RefreshAllCalculateZjpj(tmpEdbInfo) // if err != nil { // return fmt.Errorf("RefreshAllCalculateZjpj Err:" + err.Error()) // } // } else if source == utils.DATA_SOURCE_CALCULATE_LJZTBPJ { //刷新累计值同比拼接 // tmpEdbInfo, err := data_manage.GetEdbInfoById(v.EdbInfoId) // if err != nil { // if err.Error() == utils.ErrNoRow() { // continue // } // return fmt.Errorf("GetEdbInfoById Err:" + err.Error()) // } // err = data_manage.RefreshAllCalculateLjztbpj(tmpEdbInfo) // if err != nil { // return fmt.Errorf("RefreshAllCalculateLjztbpj Err:" + err.Error()) // } // } else { // msg := "刷新失败,无效的指标渠道:source:" + strconv.Itoa(source) + " EdbCode:" + v.EdbCode // err = errors.New(msg) // return err // } // // maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode) // if err != nil { // fmt.Println("GetEdbInfoMaxAndMinInfo Err:" + err.Error() + ";source:" + strconv.Itoa(source) + ";edbCode:" + edbCode) // err = errors.New("GetEdbInfoMaxAndMinInfo Err:" + err.Error() + ";source:" + strconv.Itoa(source) + ";edbCode:" + edbCode) // return err // } // if maxAndMinItem != nil { // err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem) // if err != nil { // return err // } // } // } // return err //} // RefreshDataFromCalculateAll 刷新所有计算指标 func RefreshDataFromCalculateAll() (err error) { var errmsg string defer func() { if err != nil { utils.FileLog.Info("RefreshDataFromCalculateAll Err:" + err.Error()) //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromCalculateAll ErrMsg:"+err.Error(), utils.EmailSendToUsers) go alarm_msg.SendAlarmMsg("RefreshDataFromCalculateAll ErrMsg:"+err.Error(), 3) } }() var condition string var pars []interface{} // 查询 普通指标的计算指标 condition += " AND edb_type=? AND edb_info_type=? " pars = append(pars, 2, 0) //condition += " AND modify_time 0 { fmt.Println("RefreshDataFromLt Err:", errMsgList) //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromLt ErrMsg:"+err.Error(), utils.EmailSendToUsers) go alarm_msg.SendAlarmMsg("RefreshDataFromLt ErrMsg:"+strings.Join(errMsgList, `
`), 3) } wg.Done() }() var condition string var pars []interface{} condition += " AND source=? " pars = append(pars, utils.DATA_SOURCE_LT) items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0) if err != nil { errMsgList = append(errMsgList, "GetEdbInfoByCondition:"+err.Error()) return errors.New("GetEdbInfoByCondition:" + err.Error()) } //endDate := time.Now().Format(utils.FormatDate) for _, v := range items { startDate := v.StartDate.Format(utils.FormatDate) //err = data_manage.RefreshAllEdbDataByLt(v.EdbInfoId, utils.DATA_SOURCE_LT, v.EdbCode, startDate, endDate) //if err != nil { // return errors.New("RefreshEdbDataByLt:" + err.Error()) //} resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate) if err != nil { errMsgList = append(errMsgList, "RefreshEdbData Err:"+err.Error()) continue } if resp.Ret != 200 { errMsgList = append(errMsgList, "RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg) continue } //更新指标的最新数据 //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 ResetEdbInfoIsUpdate(cont context.Context) (err error) { go data_manage.ResetEdbInfoIsUpdate() return nil } // CheckWindDataInterface 检测wind数据服务器 func CheckWindDataInterface(cont context.Context) (err error) { for _, hzDataWindUrl := range utils.Hz_Data_WIND_Url_List { go func(urlStr string) { checkUrl := urlStr + `hz_server` body, err := http.Get(checkUrl) if err != nil { msg := fmt.Sprintf("检测:%s ;失败:CheckWindDataInterface ErrMsg:%s", checkUrl, err.Error()) //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "检测路透数据服务器失败:CheckLtDataInterface ErrMsg:"+err.Error(), utils.EmailSendToUsers) go alarm_msg.SendAlarmMsg(msg, 3) } else { result := string(body) if result != `1` { //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "检测路透数据服务器失败:CheckLtDataInterface ErrMsg:"+string(body), utils.EmailSendToUsers) //msg := "检测Wind数据服务器2失败:CheckWindDataInterface ErrMsg:" + string(body) msg := fmt.Sprintf("检测%s ;失败:CheckWindDataInterface ErrMsg:%s", checkUrl, string(body)) go alarm_msg.SendAlarmMsg(msg, 3) } } }(hzDataWindUrl) } return } // RefreshDataFromCoal 刷新煤炭网数据 func RefreshDataFromCoal(wg *sync.WaitGroup) (err error) { defer func() { if err != nil { fmt.Println("RefreshDataFromCoal Err:" + err.Error()) //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromCoal ErrMsg:"+err.Error(), utils.EmailSendToUsers) go alarm_msg.SendAlarmMsg("RefreshDataFromCoal ErrMsg:"+err.Error(), 3) } wg.Done() }() var condition string var pars []interface{} condition += " AND source=? " pars = append(pars, utils.DATA_SOURCE_COAL) items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0) if err != nil { return errors.New("GetEdbInfoByCondition:" + err.Error()) } //var endDate string //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace) for _, v := range items { startDate := "" if v.Frequency == "日度" { startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) } else if v.Frequency == "周度" { startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate) } else if v.Frequency == "月度" { startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate) } else if v.Frequency == "季度" { startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate) } else if v.Frequency == "年度" { startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate) } else { startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) } //fmt.Println(startDate, endDate) //err = data_manage.RefreshEdbDataByZz(v.EdbInfoId, v.EdbCode, startDate, endDate) //if err != nil { // return errors.New("RefreshEdbDataByZz:" + err.Error()) //} resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate) if err != nil { return errors.New("RefreshEdbData Err:" + err.Error()) } if resp.Ret != 200 { return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg) } //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 } // RefreshDataFromEic 刷欧洲天然气数据 func RefreshDataFromEic(wg *sync.WaitGroup) (err error) { defer func() { if err != nil { fmt.Println("RefreshDataFromEic Err:" + err.Error()) //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromCoal ErrMsg:"+err.Error(), utils.EmailSendToUsers) go alarm_msg.SendAlarmMsg("RefreshDataFromEic ErrMsg:"+err.Error(), 3) } wg.Done() }() var condition string var pars []interface{} condition += " AND source=? " pars = append(pars, utils.DATA_SOURCE_GIE) items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0) if err != nil { return errors.New("GetEdbInfoByCondition:" + err.Error()) } //var endDate string //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace) for _, v := range items { startDate := "" if v.Frequency == "日度" { startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) } else if v.Frequency == "周度" { startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate) } else if v.Frequency == "月度" { startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate) } else if v.Frequency == "季度" { startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate) } else if v.Frequency == "年度" { startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate) } else { startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) } //fmt.Println(startDate, endDate) //err = data_manage.RefreshEdbDataByZz(v.EdbInfoId, v.EdbCode, startDate, endDate) //if err != nil { // return errors.New("RefreshEdbDataByZz:" + err.Error()) //} resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate) if err != nil { return errors.New("RefreshEdbData Err:" + err.Error()) } if resp.Ret != 200 { return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg) } //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 } // RefreshDataFromEic 刷新谷歌出行数据 func RefreshDataFromGoogleTravel(wg *sync.WaitGroup) (err error) { defer func() { if err != nil { fmt.Println("RefreshDataFromGoogleTravel Err:" + err.Error()) go alarm_msg.SendAlarmMsg("RefreshDataFromGoogleTravel ErrMsg:"+err.Error(), 3) } wg.Done() }() var condition string var pars []interface{} condition += " AND source=? " pars = append(pars, utils.DATA_SOURCE_GOOGLE_TRAVEL) items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0) if err != nil { return errors.New("GetEdbInfoByCondition:" + err.Error()) } for _, v := range items { startDate := "" if v.Frequency == "日度" { startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) } else if v.Frequency == "周度" { startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate) } else if v.Frequency == "月度" { startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate) } else if v.Frequency == "季度" { startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate) } else if v.Frequency == "年度" { startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate) } else { startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) } resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate) if err != nil { return errors.New("RefreshEdbData Err:" + err.Error()) } if resp.Ret != 200 { return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg) } //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 } // RefreshDataFromMysteelChemical 刷新钢联化工数据 func RefreshDataFromMysteelChemical(wg *sync.WaitGroup) (err error) { defer func() { if err != nil { fmt.Println("RefreshDataFromMysteelChemical Err:" + err.Error()) //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromGl ErrMsg:"+err.Error(), utils.EmailSendToUsers) go alarm_msg.SendAlarmMsg("RefreshDataFromMysteelChemical ErrMsg:"+err.Error(), 3) } wg.Done() }() var condition string var pars []interface{} condition += " AND source=? " pars = append(pars, utils.DATA_SOURCE_MYSTEEL_CHEMICAL) items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0) if err != nil { return errors.New("GetEdbInfoByCondition:" + err.Error()) } //var endDate string //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace) for _, v := range items { startDate := "" if v.Frequency == "日度" { startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) } else if v.Frequency == "周度" { startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate) } else if v.Frequency == "月度" { startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate) } else if v.Frequency == "季度" { startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate) } else if v.Frequency == "年度" { startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate) } else { startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) } //fmt.Println(startDate, endDate) //err = data_manage.RefreshEdbDataByGl(v.EdbInfoId, v.EdbCode, startDate, endDate) //if err != nil { // return errors.New("RefreshEdbDataByGl:" + err.Error()) //} resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate) if err != nil { return errors.New("RefreshEdbData Err:" + err.Error()) } if resp.Ret != 200 { return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg) } //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 } // RefreshDataFromEiaSteo 刷新eia steo 报告数据 func RefreshDataFromEiaSteo(wg *sync.WaitGroup) (err error) { defer func() { if err != nil { fmt.Println("RefreshDataFromEiaSteo Err:" + err.Error()) //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromGl ErrMsg:"+err.Error(), utils.EmailSendToUsers) go alarm_msg.SendAlarmMsg("RefreshDataFromEiaSteo ErrMsg:"+err.Error(), 3) } wg.Done() }() var condition string var pars []interface{} condition += " AND source=? " pars = append(pars, utils.DATA_SOURCE_EIA_STEO) items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0) if err != nil { return errors.New("GetEdbInfoByCondition:" + err.Error()) } //var endDate string //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace) for _, v := range items { startDate := "" if v.Frequency == "日度" { startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) } else if v.Frequency == "周度" { startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate) } else if v.Frequency == "月度" { startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate) } else if v.Frequency == "季度" { startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate) } else if v.Frequency == "年度" { startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate) } else { startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) } resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate) if err != nil { return errors.New("RefreshDataFromEiaSteoData Err:" + err.Error()) } if resp.Ret != 200 { return errors.New("RefreshDataFromEiaSteoData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg) } //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 } // RefreshDataFromComTrade 刷新 UN 数据 func RefreshDataFromComTrade(wg *sync.WaitGroup) (err error) { defer func() { if err != nil { fmt.Println("RefreshDataFromComTrade Err:" + err.Error()) //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromGl ErrMsg:"+err.Error(), utils.EmailSendToUsers) go alarm_msg.SendAlarmMsg("RefreshDataFromComTrade ErrMsg:"+err.Error(), 3) } wg.Done() }() var condition string var pars []interface{} condition += " AND source=? " pars = append(pars, utils.DATA_SOURCE_COM_TRADE) items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0) if err != nil { return errors.New("GetEdbInfoByCondition:" + err.Error()) } for _, v := range items { startDate := "" if v.Frequency == "日度" { startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) } else if v.Frequency == "周度" { startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate) } else if v.Frequency == "月度" { startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate) } else if v.Frequency == "季度" { startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate) } else if v.Frequency == "年度" { startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate) } else { startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) } resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate) if err != nil { return errors.New("RefreshDataFromComTrade Err:" + err.Error()) } if resp.Ret != 200 { return errors.New("RefreshDataFromComTrade Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg) } } return err } // RefreshDataFromSci 刷新 卓创 数据 func RefreshDataFromSci(wg *sync.WaitGroup) (err error) { defer func() { if err != nil { fmt.Println("RefreshDataFromSci Err:" + err.Error()) //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromGl ErrMsg:"+err.Error(), utils.EmailSendToUsers) go alarm_msg.SendAlarmMsg("RefreshDataFromSci ErrMsg:"+err.Error(), 3) } wg.Done() }() var condition string var pars []interface{} condition += " AND source=? " pars = append(pars, utils.DATA_SOURCE_SCI) items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0) if err != nil { return errors.New("GetEdbInfoByCondition:" + err.Error()) } for _, v := range items { startDate := "" if v.Frequency == "日度" { startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) } else if v.Frequency == "周度" { startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate) } else if v.Frequency == "月度" { startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate) } else if v.Frequency == "季度" { startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate) } else if v.Frequency == "年度" { startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate) } else { startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) } resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate) if err != nil { return errors.New("RefreshDataFromSci Err:" + err.Error()) } if resp.Ret != 200 { return errors.New("RefreshDataFromSci Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg) } } return err } // RefreshDataFromNationalStatistics 刷新统计局数据 func RefreshDataFromNationalStatistics(wg *sync.WaitGroup) (err error) { defer func() { if err != nil { fmt.Println("RefreshDataFromNationalStatistics Err:" + err.Error()) go alarm_msg.SendAlarmMsg("RefreshDataFromNationalStatistics ErrMsg:"+err.Error(), 3) } wg.Done() }() var condition string var pars []interface{} condition += ` AND source = ? ` pars = append(pars, utils.DATA_SOURCE_NATIONAL_STATISTICS) items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0) if err != nil { return errors.New("GetEdbInfoByCondition:" + err.Error()) } for _, v := range items { startDate := "" if v.Frequency == "日度" { startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) } else if v.Frequency == "周度" { startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate) } else if v.Frequency == "月度" { startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate) } else if v.Frequency == "季度" { startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate) } else if v.Frequency == "年度" { startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate) } else { startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate) } resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate) if err != nil { return errors.New("RefreshDataFromNationalStatistics Err:" + err.Error()) } if resp.Ret != 200 { return errors.New("RefreshDataFromNationalStatistics Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg) } } return err }