|
@@ -51,6 +51,10 @@ type EdbInfo struct {
|
|
|
DataUpdateTime string `description:"最近一次数据发生变化的时间"`
|
|
|
ErDataUpdateDate string `description:"本次更新,数据发生变化的最早日期"`
|
|
|
SourceIndexName string `description:"数据源中的指标名称"`
|
|
|
+ SubSource int `description:"子数据来源:0:经济数据库,1:日期序列"`
|
|
|
+ SubSourceName string `description:"子数据来源名称"`
|
|
|
+ IndicatorCode string `description:"指标代码"`
|
|
|
+ StockCode string `description:"证券代码"`
|
|
|
}
|
|
|
|
|
|
func (e *EdbInfo) Add() (err error) {
|
|
@@ -166,13 +170,14 @@ type EdbInfoSearchData struct {
|
|
|
EdbDataId int `description:"数据ID"`
|
|
|
DataTime string `description:"数据日期"`
|
|
|
Value float64 `description:"数据"`
|
|
|
+ EdbCode string `description:"指标编码"`
|
|
|
}
|
|
|
|
|
|
// GetEdbDataListAll 获取指标数据列表 order:1升序,其余值为降序
|
|
|
-func GetEdbDataListAll(condition string, pars []interface{}, source, order int) (item []*EdbInfoSearchData, err error) {
|
|
|
+func GetEdbDataListAll(condition string, pars []interface{}, source, subSource, order int) (item []*EdbInfoSearchData, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
sql := ``
|
|
|
- tableName := GetEdbDataTableName(source)
|
|
|
+ tableName := GetEdbDataTableName(source, subSource)
|
|
|
sql = ` SELECT * FROM %s WHERE 1=1 `
|
|
|
sql = fmt.Sprintf(sql, tableName)
|
|
|
|
|
@@ -189,9 +194,9 @@ func GetEdbDataListAll(condition string, pars []interface{}, source, order int)
|
|
|
}
|
|
|
|
|
|
// GetEdbDataListAllByTo 根据事务链接获取指标数据列表 order:1升序,其余值为降序
|
|
|
-func GetEdbDataListAllByTo(to orm.TxOrmer, condition string, pars []interface{}, source, order int) (item []*EdbInfoSearchData, err error) {
|
|
|
+func GetEdbDataListAllByTo(to orm.TxOrmer, condition string, pars []interface{}, source, subSource, order int) (item []*EdbInfoSearchData, err error) {
|
|
|
sql := ``
|
|
|
- tableName := GetEdbDataTableName(source)
|
|
|
+ tableName := GetEdbDataTableName(source, subSource)
|
|
|
sql = ` SELECT * FROM %s WHERE 1=1 `
|
|
|
sql = fmt.Sprintf(sql, tableName)
|
|
|
|
|
@@ -218,10 +223,10 @@ type EdbInfoMaxAndMinInfo struct {
|
|
|
}
|
|
|
|
|
|
// GetEdbInfoMaxAndMinInfo 获取指标的最新数据记录信息
|
|
|
-func GetEdbInfoMaxAndMinInfo(source int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
|
|
|
+func GetEdbInfoMaxAndMinInfo(source, subSource int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
sql := ``
|
|
|
- tableName := GetEdbDataTableName(source)
|
|
|
+ tableName := GetEdbDataTableName(source, subSource)
|
|
|
sql = ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date,MIN(value) AS min_value,MAX(value) AS max_value FROM %s WHERE edb_code=? `
|
|
|
sql = fmt.Sprintf(sql, tableName)
|
|
|
err = o.Raw(sql, edbCode).QueryRow(&item)
|
|
@@ -239,10 +244,10 @@ type EdbIndoDataUpdateTime struct {
|
|
|
}
|
|
|
|
|
|
// GetEdbDataUpdateTimeByModify 获取指标的刷新时间获取最早的一条记录
|
|
|
-func GetEdbDataUpdateTimeByModify(source int, edbCode string, dataUpdateTime string) (item *EdbIndoDataUpdateTime, err error) {
|
|
|
+func GetEdbDataUpdateTimeByModify(source, subSource int, edbCode string, dataUpdateTime string) (item *EdbIndoDataUpdateTime, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
sql := ``
|
|
|
- tableName := GetEdbDataTableName(source)
|
|
|
+ tableName := GetEdbDataTableName(source, subSource)
|
|
|
sql = ` SELECT MIN(data_time) AS min_date FROM %s WHERE edb_code=? and modify_time>=?`
|
|
|
sql = fmt.Sprintf(sql, tableName)
|
|
|
err = o.Raw(sql, edbCode, dataUpdateTime).QueryRow(&item)
|
|
@@ -274,10 +279,10 @@ func ModifyEdbDataUpdateTime(edbInfoId int, dataUpdateTime, erDataUpdateDate str
|
|
|
}
|
|
|
|
|
|
// GetEdbDataCount 获取edb指标数据的数量; order:1升序,其余值为降序
|
|
|
-func GetEdbDataCount(condition string, pars []interface{}, source int) (count int, err error) {
|
|
|
+func GetEdbDataCount(condition string, pars []interface{}, source, subSource int) (count int, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
sql := ``
|
|
|
- tableName := GetEdbDataTableName(source)
|
|
|
+ tableName := GetEdbDataTableName(source, subSource)
|
|
|
sql = ` SELECT COUNT(1) AS count FROM %s WHERE 1=1 `
|
|
|
sql = fmt.Sprintf(sql, tableName)
|
|
|
|
|
@@ -289,10 +294,10 @@ func GetEdbDataCount(condition string, pars []interface{}, source int) (count in
|
|
|
}
|
|
|
|
|
|
// GetLastEdbData 获取最近的一条指标数据
|
|
|
-func GetLastEdbData(condition string, pars []interface{}, source int) (item *EdbInfoSearchData, err error) {
|
|
|
+func GetLastEdbData(condition string, pars []interface{}, source, subSource int) (item *EdbInfoSearchData, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
sql := ``
|
|
|
- tableName := GetEdbDataTableName(source)
|
|
|
+ tableName := GetEdbDataTableName(source, subSource)
|
|
|
sql = ` SELECT * FROM %s WHERE 1=1 `
|
|
|
sql = fmt.Sprintf(sql, tableName)
|
|
|
|
|
@@ -324,7 +329,7 @@ func GetEdbInfoOnlyByEdbCode(edbCode string) (item *EdbInfo, err error) {
|
|
|
func GetEdbInfoCalculateListByCondition(condition string, pars []interface{}) (items []*EdbInfoCalculateMapping, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
|
|
|
- sql := ` SELECT * FROM edb_info_calculate_mapping WHERE 1=1 `
|
|
|
+ sql := ` SELECT a.*,b.sub_source AS from_sub_source FROM edb_info_calculate_mapping AS a LEFT JOIN edb_info AS b ON a.from_edb_info_id = b.edb_info_id WHERE 1=1 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
@@ -352,10 +357,10 @@ type EdbInfoSearchDataV1 struct {
|
|
|
}
|
|
|
|
|
|
// 优化版本-处理数据精度问题
|
|
|
-func GetEdbDataListAllV1(condition string, pars []interface{}, source, order int) (item []*EdbInfoSearchDataV1, err error) {
|
|
|
+func GetEdbDataListAllV1(condition string, pars []interface{}, source, subSource, order int) (item []*EdbInfoSearchDataV1, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
sql := ``
|
|
|
- tableName := GetEdbDataTableName(source)
|
|
|
+ tableName := GetEdbDataTableName(source, subSource)
|
|
|
sql = ` SELECT * FROM %s WHERE 1=1 `
|
|
|
sql = fmt.Sprintf(sql, tableName)
|
|
|
|
|
@@ -372,9 +377,9 @@ func GetEdbDataListAllV1(condition string, pars []interface{}, source, order int
|
|
|
}
|
|
|
|
|
|
// GetEdbDataListAllV1ByTo 通过事务链接获取数据列表
|
|
|
-func GetEdbDataListAllV1ByTo(to orm.TxOrmer, condition string, pars []interface{}, source, order int) (item []*EdbInfoSearchDataV1, err error) {
|
|
|
+func GetEdbDataListAllV1ByTo(to orm.TxOrmer, condition string, pars []interface{}, source, subSource, order int) (item []*EdbInfoSearchDataV1, err error) {
|
|
|
sql := ``
|
|
|
- tableName := GetEdbDataTableName(source)
|
|
|
+ tableName := GetEdbDataTableName(source, subSource)
|
|
|
sql = ` SELECT * FROM %s WHERE 1=1 `
|
|
|
sql = fmt.Sprintf(sql, tableName)
|
|
|
|
|
@@ -409,7 +414,7 @@ func GetEdbInfoByCondition(condition string, pars []interface{}, order int) (ite
|
|
|
// UnifiedModifyEdbInfoMaxAndMinInfo 统一修改指标的最大最小值
|
|
|
func UnifiedModifyEdbInfoMaxAndMinInfo(edbInfo *EdbInfo) (err error, errMsg string) {
|
|
|
// 修改最大最小值
|
|
|
- maxAndMinItem, err := GetEdbInfoMaxAndMinInfo(edbInfo.Source, edbInfo.EdbCode)
|
|
|
+ maxAndMinItem, err := GetEdbInfoMaxAndMinInfo(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbCode)
|
|
|
if err != nil {
|
|
|
if err.Error() == utils.ErrNoRow() {
|
|
|
err = nil
|
|
@@ -451,7 +456,7 @@ func UnifiedModifyEdbInfoMaxAndMinInfoDataUpdate(edbInfo *EdbInfo, dataUpdateTim
|
|
|
return
|
|
|
}
|
|
|
// 获取本次刷新,指标数据更新的最早日期
|
|
|
- erDataUpdateTime, tErr := GetEdbDataUpdateTimeByModify(edbInfo.Source, edbInfo.EdbCode, dataUpdateTime)
|
|
|
+ erDataUpdateTime, tErr := GetEdbDataUpdateTimeByModify(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbCode, dataUpdateTime)
|
|
|
if tErr != nil {
|
|
|
if tErr.Error() != utils.ErrNoRow() { //本次刷新指标数据无变化
|
|
|
errMsg = "刷新指标失败!"
|
|
@@ -473,7 +478,7 @@ func UnifiedModifyEdbInfoMaxAndMinInfoDataUpdate(edbInfo *EdbInfo, dataUpdateTim
|
|
|
// UnifiedModifyPredictEdbInfoMaxAndMinInfo 统一修改预测运算指标的最大最小值
|
|
|
func UnifiedModifyPredictEdbInfoMaxAndMinInfo(edbInfo *EdbInfo, latestDateStr string, latestValue float64) (err error, errMsg string) {
|
|
|
// 修改最大最小值
|
|
|
- maxAndMinItem, err := GetEdbInfoMaxAndMinInfo(edbInfo.Source, edbInfo.EdbCode)
|
|
|
+ maxAndMinItem, err := GetEdbInfoMaxAndMinInfo(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbCode)
|
|
|
if err != nil {
|
|
|
if err.Error() == utils.ErrNoRow() {
|
|
|
err = nil
|
|
@@ -890,13 +895,13 @@ func GetPredictDataListByPredictEdbConfList(edbInfo, sourceEdbInfoItem *EdbInfo,
|
|
|
condition += " AND data_time>=? "
|
|
|
pars = append(pars, startDate)
|
|
|
}
|
|
|
- tmpDataList, err := GetEdbDataListAll(condition, pars, sourceEdbInfoItem.Source, 1)
|
|
|
+ tmpDataList, err := GetEdbDataListAll(condition, pars, sourceEdbInfoItem.Source, sourceEdbInfoItem.SubSource, 1)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
// 如果选择了日期,那么需要筛选所有的数据,用于未来指标的生成
|
|
|
if startDate != `` {
|
|
|
- allDataList, err = GetEdbDataListAll(" AND edb_info_id=? ", []interface{}{sourceEdbInfoItem.EdbInfoId}, sourceEdbInfoItem.Source, 1)
|
|
|
+ allDataList, err = GetEdbDataListAll(" AND edb_info_id=? ", []interface{}{sourceEdbInfoItem.EdbInfoId}, sourceEdbInfoItem.Source, sourceEdbInfoItem.SubSource, 1)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -959,7 +964,7 @@ func GetPredictEdbDataListAll(edbInfo *EdbInfo, order int) (items []*EdbInfoSear
|
|
|
var pars []interface{}
|
|
|
condition += " AND edb_info_id=? "
|
|
|
pars = append(pars, edbInfo.EdbInfoId)
|
|
|
- items, err = GetEdbDataListAll(condition, pars, edbInfo.Source, order)
|
|
|
+ items, err = GetEdbDataListAll(condition, pars, edbInfo.Source, edbInfo.SubSource, order)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
@@ -977,7 +982,7 @@ func GetPredictEdbDataListAllByStartDate(edbInfo *EdbInfo, order int, startDate
|
|
|
condition += " AND data_time>=? "
|
|
|
pars = append(pars, startDate)
|
|
|
}
|
|
|
- items, err = GetEdbDataListAll(condition, pars, edbInfo.Source, order)
|
|
|
+ items, err = GetEdbDataListAll(condition, pars, edbInfo.Source, edbInfo.SubSource, order)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
@@ -1181,7 +1186,7 @@ func EdbInfoAdd(req *AddEdbInfoParams, serverUrl string, sysUserId int, sysUserR
|
|
|
edbInfo.Sort = maxSort + 1
|
|
|
timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
|
|
|
edbInfo.UniqueCode = utils.MD5(utils.DATA_PREFIX + "_" + req.EdbCode + timestamp)
|
|
|
- itemVal, err := GetEdbInfoMaxAndMinInfo(source, req.EdbCode)
|
|
|
+ itemVal, err := GetEdbInfoMaxAndMinInfo(source, utils.DATA_SUB_SOURCE_EDB, req.EdbCode)
|
|
|
if itemVal != nil && err == nil {
|
|
|
edbInfo.MaxValue = itemVal.MaxValue
|
|
|
edbInfo.MinValue = itemVal.MinValue
|