package data import ( "errors" "eta/eta_task/models/data_manage" "eta/eta_task/services/alarm_msg" "eta/eta_task/utils" "fmt" "strings" "sync" ) // RefreshDataFromDl 刷新广期所数据 func RefreshDataFromGz(wg *sync.WaitGroup) (err error) { errMsgList := make([]string, 0) defer func() { if err != nil { errMsg := "刷新广期所数据 ErrMsg:" + err.Error() utils.FileLog.Info(errMsg) go alarm_msg.SendAlarmMsg(errMsg, 3) } if len(errMsgList) > 0 { utils.FileLog.Info("刷新广期所数据 Err:" + strings.Join(errMsgList, "\n")) go alarm_msg.SendAlarmMsg("刷新广期所数据 Err:"+strings.Join(errMsgList, "\n"), 3) } wg.Done() }() var condition string var pars []interface{} condition += " AND source=? " pars = append(pars, utils.DATA_SOURCE_GFEX) 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, tmpErr := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate) if err != nil { errMsgList = append(errMsgList, fmt.Sprintf("指标ID:%d;指标编码:%s;err:%s", v.EdbInfoId, v.EdbCode, tmpErr.Error())) continue } if resp.Ret != 200 { errMsgList = append(errMsgList, fmt.Sprintf("指标ID:%d;指标编码:%s;msg:%s;errMsg:%s", v.EdbInfoId, v.EdbCode, resp.Msg, resp.ErrMsg)) continue } } return err } // RefreshDataFromDl 刷新大商所数据 func RefreshDataFromDl(wg *sync.WaitGroup) (err error) { errMsgList := make([]string, 0) defer func() { if err != nil { errMsg := "刷新大商所数据 ErrMsg:" + err.Error() utils.FileLog.Info(errMsg) go alarm_msg.SendAlarmMsg(errMsg, 3) } if len(errMsgList) > 0 { utils.FileLog.Info("刷新大商所数据 Err:" + strings.Join(errMsgList, "\n")) go alarm_msg.SendAlarmMsg("刷新大商所数据 Err:"+strings.Join(errMsgList, "\n"), 3) } wg.Done() }() var condition string var pars []interface{} condition += " AND source=? " pars = append(pars, utils.DATA_SOURCE_DL) 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, tmpErr := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate) if err != nil { errMsgList = append(errMsgList, fmt.Sprintf("指标ID:%d;指标编码:%s;err:%s", v.EdbInfoId, v.EdbCode, tmpErr.Error())) continue } if resp.Ret != 200 { errMsgList = append(errMsgList, fmt.Sprintf("指标ID:%d;指标编码:%s;msg:%s;errMsg:%s", v.EdbInfoId, v.EdbCode, resp.Msg, resp.ErrMsg)) continue } } return err } // RefreshDataFromCffex 刷新中金所数据 func RefreshDataFromCffex(wg *sync.WaitGroup) (err error) { defer func() { if err != nil { fmt.Println("RefreshDataFromCffex Err:" + err.Error()) go alarm_msg.SendAlarmMsg("RefreshDataFromCffex ErrMsg:"+err.Error(), 3) } wg.Done() }() var condition string var pars []interface{} condition += " AND source=? " pars = append(pars, utils.DATA_SOURCE_CFFEX) 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.SubSource, 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) } } return err } // RefreshDataFromShfe 刷新上期能源数据 func RefreshDataFromShfe(wg *sync.WaitGroup) (err error) { defer func() { if err != nil { fmt.Println("RefreshDataFromShfe Err:" + err.Error()) go alarm_msg.SendAlarmMsg("RefreshDataFromShfe ErrMsg:"+err.Error(), 3) } wg.Done() }() var condition string var pars []interface{} condition += " AND source=? " pars = append(pars, utils.DATA_SOURCE_SHFE) 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.SubSource, 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) } } return err } // RefreshDataFromSh 刷新上期所数据 func RefreshDataFromSh(wg *sync.WaitGroup) (err error) { defer func() { if err != nil { fmt.Println("RefreshDataFromSh Err:" + err.Error()) go alarm_msg.SendAlarmMsg("RefreshDataFromSh ErrMsg:"+err.Error(), 3) } wg.Done() }() var condition string var pars []interface{} condition += " AND source=? " pars = append(pars, utils.DATA_SOURCE_SH) 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.SubSource, 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) } } return err } // RefreshDataFromZz 刷新郑商所数据 func RefreshDataFromZz(wg *sync.WaitGroup) (err error) { defer func() { if err != nil { fmt.Println("RefreshDataFromZz Err:" + err.Error()) go alarm_msg.SendAlarmMsg("RefreshDataFromZz ErrMsg:"+err.Error(), 3) } wg.Done() }() var condition string var pars []interface{} condition += " AND source=? " pars = append(pars, utils.DATA_SOURCE_ZZ) 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.SubSource, 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) } } return err }