123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package future_good
- import (
- "errors"
- "fmt"
- "hongze/hongze_task/models/data_manage/future_good"
- "hongze/hongze_task/services/alarm_msg"
- "hongze/hongze_task/utils"
- "strings"
- "time"
- )
- // RefreshFutureGoodDataFromThs 刷新同花顺的商品期货数据
- func RefreshFutureGoodDataFromThs() (err error) {
- errMsgList := make([]string,0)
- 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)
- }
- if len(errMsgList)>0{
- go alarm_msg.SendAlarmMsg("部分商品数据刷新失败 ErrMsg:"+strings.Join(errMsgList,"/n"), 3)
- //fmt.Println("总共",len(errMsgList),"条商品数据刷新失败:")
- //for _,v:=range errMsgList{
- // fmt.Println(v)
- //}
- }
- }()
- var condition string
- var pars []interface{}
- //condition += " AND exchange=? "
- //pars = append(pars, "上海期货")
- list, err := future_good.GetFutureGoodEdbInfoList(condition, pars)
- if err != nil {
- err = errors.New("GetEdbInfoByCondition:" + err.Error())
- return
- }
- lenList := len(list)
- fmt.Println("总共",lenList,"条")
- for k, v := range list {
- fmt.Println("剩余",lenList-k-1,"条")
- fmt.Println("编码:",v.FutureGoodEdbCode,";名称:",v.FutureGoodEdbName)
- var startDateTime time.Time
- startDateTime = v.EndDate
- // 如果指标结束日期不是空的话,那么就按照刷配置的刷新周期进行兼容性的刷新吧
- if v.EndDate.IsZero(){
- startDateTime = time.Now()
- }
- startDate := startDateTime.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- resp, err := RefreshEdbData(v.FutureGoodEdbInfoId, v.FutureGoodEdbCode, startDate)
- if err != nil {
- errMsgList = append(errMsgList,fmt.Sprint(v.FutureGoodEdbCode,";刷新数据失败,err:",err.Error()))
- continue
- }
- if resp.Ret != 200 {
- errMsgList = append(errMsgList,fmt.Sprint(v.FutureGoodEdbCode,";刷新数据失败,err:",resp.Msg,";ErrMsg:" , resp.ErrMsg))
- continue
- }
- }
- // 刷新商品期货指标相关的数据
- for _, bv := range list {
- if bv.ParentId == 0 {
- RefreshEdbRelation(bv.FutureGoodEdbInfoId)
- }
- }
- return err
- }
|