Browse Source

删除source=94

xyxie 6 months ago
parent
commit
702a207061

+ 7 - 0
controllers/base_from_predict.go

@@ -153,6 +153,13 @@ func (this *PredictController) Refresh() {
 		return
 	}
 
+	if edbInfo.IsStaticData == 1 {
+		//静态数据直接返回
+		br.Ret = 200
+		br.Success = true
+		br.Msg = "获取成功"
+		return
+	}
 	cacheKey = utils.CACHE_EDB_DATA_REFRESH + strconv.Itoa(edbInfo.Source) + "_" + req.EdbCode
 	if utils.Rc.IsExist(cacheKey) {
 		br.Ret = 501

+ 7 - 1
controllers/base_from_predict_calculate.go

@@ -970,7 +970,13 @@ func (this *PredictCalculateController) Refresh() {
 		br.ErrMsg = "指标不存在"
 		return
 	}
-
+	if edbInfo.IsStaticData == 1 {
+		//静态数据直接返回
+		br.Ret = 200
+		br.Success = true
+		br.Msg = "获取成功"
+		return
+	}
 	cacheKey = utils.CACHE_EDB_DATA_REFRESH + strconv.Itoa(edbInfo.Source) + "_" + req.EdbCode
 	if utils.Rc.IsExist(cacheKey) {
 		br.Ret = 501

+ 32 - 3
logic/predict_edb.go

@@ -1140,7 +1140,7 @@ func AddStaticPredictEdbInfo(sourceEdbInfoId, classifyId int, edbName, frequency
 		//EdbInfoId:   0,
 		EdbInfoType:      sourceEdbInfo.EdbInfoType,
 		SourceName:       sourceEdbInfo.SourceName,
-		Source:           utils.DATA_SOURCE_PREDICT_STATIC,
+		Source:           sourceEdbInfo.Source,
 		EdbCode:          edbCode,
 		EdbName:          edbName,
 		EdbNameSource:    edbName,
@@ -1158,7 +1158,7 @@ func AddStaticPredictEdbInfo(sourceEdbInfoId, classifyId int, edbName, frequency
 		MaxValue:         sourceEdbInfo.MaxValue,
 		EndValue:         sourceEdbInfo.EndValue,
 		CalculateFormula: sourceEdbInfo.CalculateFormula,
-		EdbType:          2,
+		EdbType:          sourceEdbInfo.EdbType,
 		//Sort:             sourceEdbInfo.,
 		LatestDate:    sourceEdbInfo.LatestDate,
 		LatestValue:   sourceEdbInfo.LatestValue,
@@ -1197,8 +1197,37 @@ func AddStaticPredictEdbInfo(sourceEdbInfoId, classifyId int, edbName, frequency
 	}
 	fromEdbMap[sourceEdbInfoId] = sourceEdbInfoId
 	calculateMappingList = append(calculateMappingList, calculateMappingItem)
+	newPredictEdbConfList := make([]*models.PredictEdbConf, 0)
+	//查询原先的预测指标配置项
+	if sourceEdbInfo.EdbType == 1 {
+		// 查找该预测指标配置
+		predictEdbConfList, tmpErr := models.GetPredictEdbConfListById(sourceEdbInfo.EdbInfoId)
+		if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
+			errMsg = "获取预测指标配置信息失败"
+			err = errors.New("获取预测指标配置信息失败,Err:" + tmpErr.Error())
+			return
+		}
+		if len(predictEdbConfList) > 0 {
+			// 遍历
+			for _, v := range predictEdbConfList {
+				tmpPredictEdbConf := &models.PredictEdbConf{
+					PredictEdbInfoId: 0,
+					SourceEdbInfoId:  sourceEdbInfoId,
+					RuleType:         v.RuleType,
+					FixedValue:       v.FixedValue,
+					Value:            v.Value,
+					EmptyType:        v.EmptyType,
+					MaxEmptyType:     v.MaxEmptyType,
+					EndDate:          v.EndDate,
+					ModifyTime:       time.Now(),
+					CreateTime:       time.Now(),
+				}
+				newPredictEdbConfList = append(newPredictEdbConfList, tmpPredictEdbConf)
+			}
+		}
+	}
 
-	err, errMsg = models.AddPredictStaticEdb(edbInfo, sourceEdbInfo, calculateMappingList)
+	err, errMsg = models.AddPredictStaticEdb(edbInfo, sourceEdbInfo, calculateMappingList, newPredictEdbConfList)
 
 	return
 }

+ 1 - 1
models/edb_info.go

@@ -64,7 +64,7 @@ type EdbInfo struct {
 	IndicatorCode    string  `description:"指标代码"`
 	StockCode        string  `description:"证券代码"`
 	Extra            string  `description:"指标的额外配置"`
-	IsStaticData     int     `description:"指标额外配置"`
+	IsStaticData     int     `description:"是否是静态指标,0否,1是"`
 }
 
 func (e *EdbInfo) Add() (err error) {

+ 12 - 33
models/predict_edb_data_static.go

@@ -1,8 +1,6 @@
 package models
 
 import (
-	"errors"
-	"eta/eta_index_lib/utils"
 	"fmt"
 	"github.com/beego/beego/v2/client/orm"
 	"github.com/shopspring/decimal"
@@ -10,9 +8,6 @@ import (
 	"strings"
 )
 
-type PredictEdbStatic struct {
-}
-
 // AddStaticPredictEdbInfoReq 添加预测指标静态指标请求
 type AddStaticPredictEdbInfoReq struct {
 	ClassifyId      int    `description:"分类id"`
@@ -26,7 +21,7 @@ type AddStaticPredictEdbInfoReq struct {
 
 // AddPredictStaticEdb 添加预测指标
 // edbInfo, calculateMappingList, predictEdbConfList,calculateRule9List,trendsMappingList
-func AddPredictStaticEdb(edbInfo, sourceEdbInfoItem *EdbInfo, calculateMappingList []*EdbInfoCalculateMapping) (err error, errMsg string) {
+func AddPredictStaticEdb(edbInfo, sourceEdbInfoItem *EdbInfo, calculateMappingList []*EdbInfoCalculateMapping, predictEdbConfList []*PredictEdbConf) (err error, errMsg string) {
 	o := orm.NewOrm()
 	tx, err := o.Begin()
 	if err != nil {
@@ -58,6 +53,17 @@ func AddPredictStaticEdb(edbInfo, sourceEdbInfoItem *EdbInfo, calculateMappingLi
 			return
 		}
 	}
+	if len(predictEdbConfList) > 0 {
+		// 新增预测指标配置
+		for _, v := range predictEdbConfList {
+			v.PredictEdbInfoId = edbInfo.EdbInfoId
+			_, tmpErr := tx.Insert(v)
+			if tmpErr != nil {
+				err = fmt.Errorf(`新增预测指标配置失败:%v`, tmpErr)
+				return
+			}
+		}
+	}
 	// 新增预测指标数据
 	dataTableName := GetEdbDataTableName(edbInfo.Source, edbInfo.SubSource)
 	edbInfoIdStr := strconv.Itoa(int(edbInfoId))
@@ -104,30 +110,3 @@ func AddPredictStaticEdb(edbInfo, sourceEdbInfoItem *EdbInfo, calculateMappingLi
 
 	return
 }
-
-// Add 添加
-func (obj PredictEdbStatic) Add(params BatchSaveCalculateBatchParams) (edbInfo *EdbInfo, latestDateStr string, latestValue float64, err error, errMsg string) {
-	err = errors.New("暂不支持该方法")
-	return
-}
-
-// Edit 编辑
-func (obj PredictEdbStatic) Edit(params BatchSaveCalculateBatchParams) (latestDateStr string, latestValue float64, err error, errMsg string) {
-	err = errors.New("暂不支持该方法")
-	return
-}
-
-// Refresh 刷新
-func (obj PredictEdbStatic) Refresh(params RefreshParams) (latestDateStr string, latestValue float64, err error, errMsg string) {
-	return
-}
-
-// GetSource 获取来源编码id
-func (obj PredictEdbStatic) GetSource() int {
-	return utils.DATA_SOURCE_PREDICT_STATIC
-}
-
-// GetSourceName 获取来源名称
-func (obj PredictEdbStatic) GetSourceName() string {
-	return utils.DATA_SOURCE_NAME_PREDICT
-}

+ 10 - 4
models/predict_edb_info_rule.go

@@ -1454,9 +1454,10 @@ func GetChartPredictEdbInfoDataListByRuleNAnnualAverage(edbInfoId int, configVal
 
 // AnnualValueInversionConf 年度值倒推规则
 type AnnualValueInversionConf struct {
-	Value float64 `description:"年度值"`
-	Type  int     `description:"分配方式,1:均值法;2:同比法"`
-	Year  int     `description:"同比年份"`
+	Value    float64 `description:"年度值"`
+	Type     int     `description:"分配方式,1:均值法;2:同比法"`
+	Year     int     `description:"同比年份"`
+	YearList []int   `description:"指定年份列表"`
 }
 
 // GetChartPredictEdbInfoDataListByRuleAnnualValueInversion 根据 年度值倒推 规则获取预测数据
@@ -1642,7 +1643,11 @@ func GetChartPredictEdbInfoDataListByRuleAnnualValueInversion(edbInfoId int, con
 	// 同比法分配
 	// 同比法保证每期同比相等(同比增速=余额/同比年份相应日期的余额,预测值等于同比年份同期值*同比增速);
 	// 同比法分配:同比增速=900/同比年份5.19的余额
-
+	yearList := annualValueInversionConf.YearList
+	if len(yearList) == 0 {
+		//兼容历史数据
+		yearList = append(yearList, annualValueInversionConf.Year)
+	}
 	// 每年截止到当前日期的累计值
 	dateTotalMap := make(map[time.Time]float64)
 	// 每年的累计值(计算使用)
@@ -1659,6 +1664,7 @@ func GetChartPredictEdbInfoDataListByRuleAnnualValueInversion(edbInfoId int, con
 		dateTotalMap[currTime] = yearVal
 	}
 
+	// todo 如果是日度和周度,用后置填充变频成连续自然日日度数据。计算1/1至指标最新日期(2024/3/3/1)的累计值
 	//(同比增速=余额/同比年份相应日期的余额,预测值等于同比年份同期值*同比增速);
 	for k, currentDate := range dayList {
 		currYearBalance := yearValueConfig - yearTotalMap[currentDate.Year()] // 当年的余额

+ 3 - 5
utils/constants.go

@@ -111,7 +111,6 @@ const (
 	DATA_SOURCE_CCF                                  = 86 // CCF化纤信息
 	DATA_SOURCE_SCI_HQ                               = 88 // 卓创红期->88
 	DATA_SOURCE_OILCHEM                              = 89 // 隆众资讯 -> 89
-	DATA_SOURCE_PREDICT_STATIC                       = 94 // 静态指标 -> 94
 )
 
 // 指标来源的中文展示
@@ -197,10 +196,9 @@ const (
 	DATA_SOURCE_NAME_CALCULATE_SUM                        = `多指标求和`
 	DATA_SOURCE_NAME_CALCULATE_AVG                        = `多指标求平均`
 	DATA_SOURCE_NAME_BUSINESS                             = `自有数据`
-	DATA_SOURCE_NAME_CCF                                  = `CCF`    // CCF化纤信息
-	DATA_SOURCE_NAME_SCI_HQ                               = `卓创红期`   // 卓创红期
-	DATA_SOURCE_NAME_OILCHEM                              = `隆众资讯`   // 隆众资讯 -> 89
-	DATA_SOURCE_NAME_PREDICT_STATIC                       = "预测静态指标" //预测静态指标 94
+	DATA_SOURCE_NAME_CCF                                  = `CCF`  // CCF化纤信息
+	DATA_SOURCE_NAME_SCI_HQ                               = `卓创红期` // 卓创红期
+	DATA_SOURCE_NAME_OILCHEM                              = `隆众资讯` // 隆众资讯 -> 89
 )
 
 // 基础数据初始化日期