123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- 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
- }
|