Преглед изворни кода

feat:彭博数据未来数据不延5年,统计数据刷新量

Roc пре 1 месец
родитељ
комит
6aa773ecff

+ 14 - 2
controllers/base_from_pb.go

@@ -43,7 +43,13 @@ func (this *PbController) Add() {
 	cacheKey = utils.CACHE_EDB_DATA_ADD + strconv.Itoa(source) + "_" + req.EdbCode
 	if !utils.Rc.IsExist(cacheKey) {
 		utils.Rc.SetNX(cacheKey, 1, 1*time.Minute)
-		dataItem, err := services.GetEdbDataFromPb(req.EdbCode, utils.BASE_START_DATE_UnSpace, utils.BASE_END_DATE_UnSpace, "")
+		dataItem, err := services.GetEdbDataFromPb(req.EdbCode, utils.BASE_START_DATE_UnSpace, utils.PB_BASE_END_DATE_UnSpace, "")
+		// 日志记录
+		num := 0
+		if dataItem != nil {
+			num = len(dataItem.Date)
+		}
+		models.AddEdbRefreshApiRecordByRefresh(&models.EdbInfo{EdbCode: req.EdbCode, Source: source}, utils.BASE_START_DATE_UnSpace, num, err)
 		if err != nil {
 			br.Msg = "获取指标信息失败!"
 			br.ErrMsg = "获取指标信息失败 GetEdbDataFromPb,Err:" + err.Error()
@@ -115,7 +121,13 @@ func (this *PbController) Refresh() {
 
 	//开始日期格式化
 	startDateTime, _ := time.ParseInLocation(utils.FormatDate, req.StartDate, time.Local)
-	dataItem, err := services.GetEdbDataFromPb(req.EdbCode, startDateTime.Format(utils.FormatDateUnSpace), utils.BASE_END_DATE_UnSpace, edbInfo.TerminalCode)
+	dataItem, err := services.GetEdbDataFromPb(req.EdbCode, startDateTime.Format(utils.FormatDateUnSpace), utils.PB_BASE_END_DATE_UnSpace, edbInfo.TerminalCode)
+	// 日志记录
+	num := 0
+	if dataItem != nil {
+		num = len(dataItem.Date)
+	}
+	models.AddEdbRefreshApiRecordByRefresh(edbInfo, startDateTime.Format(utils.FormatDateUnSpace), num, err)
 	if err != nil {
 		br.Msg = "获取指标信息失败!"
 		br.ErrMsg = "获取指标信息失败 GetEdbDataFromPb,Err:" + err.Error()

+ 14 - 2
controllers/base_from_pb_finance.go

@@ -54,7 +54,13 @@ func (this *PbFinanceController) Add() {
 			br.ErrMsg = "指标编码异常,请传入客户编码"
 			return
 		}
-		dataItem, err := services.GetEdbDataFromPbFinance(edbCodeArr[0], edbCodeArr[1], utils.BASE_START_DATE_UnSpace, utils.BASE_END_DATE_UnSpace, "")
+		dataItem, err := services.GetEdbDataFromPbFinance(edbCodeArr[0], edbCodeArr[1], utils.BASE_START_DATE_UnSpace, utils.PB_BASE_END_DATE_UnSpace, "")
+		// 日志记录
+		num := 0
+		if dataItem != nil {
+			num = len(dataItem.Date)
+		}
+		models.AddEdbRefreshApiRecordByRefresh(&models.EdbInfo{EdbCode: edbCode, Source: source}, utils.BASE_START_DATE_UnSpace, num, err)
 		if err != nil {
 			br.Msg = "获取指标信息失败!"
 			br.ErrMsg = "获取指标信息失败 GetEdbDataFromPb,Err:" + err.Error()
@@ -136,7 +142,13 @@ func (this *PbFinanceController) Refresh() {
 		br.ErrMsg = "指标编码异常,请传入客户编码"
 		return
 	}
-	dataItem, err := services.GetEdbDataFromPbFinance(edbCodeArr[0], edbCodeArr[1], startDateTime.Format(utils.FormatDateUnSpace), utils.BASE_END_DATE_UnSpace, edbInfo.TerminalCode)
+	dataItem, err := services.GetEdbDataFromPbFinance(edbCodeArr[0], edbCodeArr[1], startDateTime.Format(utils.FormatDateUnSpace), utils.PB_BASE_END_DATE_UnSpace, edbInfo.TerminalCode)
+	// 日志记录
+	num := 0
+	if dataItem != nil {
+		num = len(dataItem.Date)
+	}
+	models.AddEdbRefreshApiRecordByRefresh(edbInfo, startDateTime.Format(utils.FormatDateUnSpace), num, err)
 	if err != nil {
 		br.Msg = "获取指标信息失败!"
 		br.ErrMsg = "获取指标信息失败 GetEdbDataFromPb,Err:" + err.Error()

+ 57 - 0
models/edb_refresh_api_record.go

@@ -0,0 +1,57 @@
+package models
+
+import (
+	"eta/eta_index_lib/global"
+	"eta/eta_index_lib/utils"
+	"fmt"
+	"time"
+)
+
+type EdbRefreshApiRecord struct {
+	EdbRefreshApiRecordId int       `gorm:"column:edb_refresh_api_record_id;type:int(10) UNSIGNED;primaryKey;not null;" json:"edb_refresh_api_record_id"`
+	EdbCode               string    `gorm:"column:edb_code;type:varchar(255);comment:指标编码;" json:"edb_code"`                            // 指标编码
+	EdbName               string    `gorm:"column:edb_name;type:varchar(255);comment:指标名称;" json:"edb_name"`                            // 指标名称
+	Source                int       `gorm:"column:source;type:int(9) UNSIGNED;comment:指标来源;default:0;" json:"source"`                   // 指标来源
+	Frequency             string    `gorm:"column:frequency;type:varchar(32);comment:指标频度;" json:"frequency"`                           // 指标频度
+	StartDate             string    `gorm:"column:start_date;type:varchar(64);comment:刷新开始时间;" json:"start_date"`                       // 刷新开始时间
+	Result                int       `gorm:"column:result;type:tinyint(4) UNSIGNED;comment:刷新成功与否,0:未成功,1:已成功;default:0;" json:"result"` // 刷新成功与否,0:未成功,1:已成功
+	RefreshDesc           string    `gorm:"column:refresh_desc;type:text;comment:刷新的备注;" json:"refresh_desc"`                           // 刷新的备注
+	RefreshNum            int       `gorm:"column:refresh_num;type:int(9) UNSIGNED;comment:刷新到了的数据数量;default:0;" json:"refresh_num"`    // 刷新到了的数据数量
+	CreateTime            time.Time `gorm:"column:create_time;type:datetime;comment:刷新时间;default:NULL;" json:"create_time"`             // 刷新时间
+}
+
+func (m *EdbRefreshApiRecord) Add() (err error) {
+	err = global.DEFAULT_DB.Create(m).Error
+
+	return
+}
+
+func AddEdbRefreshApiRecordByRefresh(edbInfo *EdbInfo, startDate string, num int, resultErr error) {
+	var err error
+	defer func() {
+		if err != nil {
+			utils.FileLog.Info(fmt.Sprintf("AddEdbRefreshApiRecordByRefresh, err: %v", err))
+		}
+	}()
+	result := 1
+	resultErrMsg := ``
+	if resultErr != nil {
+		result = 0
+		resultErrMsg = resultErr.Error()
+	}
+	record := &EdbRefreshApiRecord{
+		EdbRefreshApiRecordId: 0,
+		EdbCode:               edbInfo.EdbCode,
+		EdbName:               edbInfo.EdbName,
+		Source:                edbInfo.Source,
+		Frequency:             edbInfo.Frequency,
+		StartDate:             startDate,
+		Result:                result,
+		RefreshDesc:           resultErrMsg,
+		RefreshNum:            num,
+		CreateTime:            time.Now(),
+	}
+	err = global.DEFAULT_DB.Create(record).Error
+
+	return
+}

+ 5 - 4
utils/constants.go

@@ -223,10 +223,11 @@ const (
 
 // 基础数据初始化日期
 var (
-	BASE_START_DATE         = `1900-01-01`                                          //基础数据开始日期
-	BASE_END_DATE           = time.Now().AddDate(4, 0, 0).Format(FormatDate)        //基础数据结束日期
-	BASE_START_DATE_UnSpace = "19000101"                                            //基础数据开始日期
-	BASE_END_DATE_UnSpace   = time.Now().AddDate(4, 0, 0).Format(FormatDateUnSpace) //基础数据结束日期
+	BASE_START_DATE          = `1900-01-01`                                          //基础数据开始日期
+	BASE_END_DATE            = time.Now().AddDate(4, 0, 0).Format(FormatDate)        //基础数据结束日期
+	BASE_START_DATE_UnSpace  = "19000101"                                            //基础数据开始日期
+	BASE_END_DATE_UnSpace    = time.Now().AddDate(4, 0, 0).Format(FormatDateUnSpace) //基础数据结束日期
+	PB_BASE_END_DATE_UnSpace = time.Now().Format(FormatDateUnSpace)                  //彭博的基础数据结束日期
 )
 
 const (