Browse Source

新增广期所数据

tuoling805 1 year ago
parent
commit
d28ed78fe1
4 changed files with 50 additions and 1 deletions
  1. 2 0
      services/data/base_edb_lib.go
  2. 44 0
      services/data/edb_info.go
  3. 3 1
      services/task.go
  4. 1 0
      utils/constants.go

+ 2 - 0
services/data/base_edb_lib.go

@@ -74,6 +74,8 @@ func RefreshEdbData(edbInfoId, source, subSource int, edbCode, startDate string)
 		urlStr = "national_statistics/refresh"
 	case utils.DATA_SOURCE_FUBAO:
 		urlStr = "fubao/refresh"
+	case utils.DATA_SOURCE_GFEX:
+		urlStr = "gz/refresh"
 	default:
 		urlStr = data_manage.EdbDataRefreshMethodMap[source] // 没有对应的从edb_source中取
 	}

+ 44 - 0
services/data/edb_info.go

@@ -1155,3 +1155,47 @@ func RefreshDataFromFubao(wg *sync.WaitGroup) (err error) {
 	fmt.Println("Fubao刷新结束")
 	return err
 }
+
+// RefreshDataFromDl 刷新广期所数据
+func RefreshDataFromGz(wg *sync.WaitGroup) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println("RefreshDataFromGz Err:" + err.Error())
+			go alarm_msg.SendAlarmMsg("RefreshDataFromGz ErrMsg:"+err.Error(), 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, 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
+}

+ 3 - 1
services/task.go

@@ -196,7 +196,7 @@ func RefreshFutureGoodData(cont context.Context) (err error) {
 // RefreshTradeData 刷新交易所数据
 func RefreshTradeData(cont context.Context) (err error) {
 	wg := sync.WaitGroup{}
-	wg.Add(5)
+	wg.Add(6)
 
 	//郑商所
 	go data.RefreshDataFromZz(&wg)
@@ -208,6 +208,8 @@ func RefreshTradeData(cont context.Context) (err error) {
 	go data.RefreshDataFromCffex(&wg)
 	//大商所
 	go data.RefreshDataFromDl(&wg)
+	//大商所
+	go data.RefreshDataFromGz(&wg)
 	wg.Wait()
 	//计算指标
 	data.RefreshDataFromCalculateAll()

+ 1 - 0
utils/constants.go

@@ -100,6 +100,7 @@ const (
 	DATA_SOURCE_PREDICT_CALCULATE_ZSXY                          // 预测指数修匀->73
 	DATA_SOURCE_CALCULATE_ZDYFX                                 // 自定义分析->74
 	DATA_SOURCE_CALCULATE_RJZ                                   // 日均值计算->75
+	DATA_SOURCE_GFEX                                 = 78       // 广州期货交易所->78
 
 )