|
@@ -75,7 +75,6 @@ func (e *EdbInfo) Add() (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// AfterFind 在该模型上设置钩子函数,把日期转成正确的string,所以查询函数只能用Find函数,First或者Scan是不会触发该函数的来获取数据
|
|
|
func (m *EdbInfo) AfterFind(db *gorm.DB) (err error) {
|
|
|
if m.StartDate != "" {
|
|
|
minDateTmp, e := time.ParseInLocation(utils.FormatDateWallWithLoc, m.StartDate, time.Local)
|
|
@@ -113,9 +112,6 @@ func (m *EdbInfo) AfterFind(db *gorm.DB) (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// ConvertDate
|
|
|
-// @Description: 格式化EdbInfo的日期
|
|
|
-// @receiver e
|
|
|
func (e *EdbInfo) ConvertDate() {
|
|
|
e.StartDate = utils.GormDateStrToDateStr(e.StartDate)
|
|
|
e.EndDate = utils.GormDateStrToDateStr(e.EndDate)
|
|
@@ -125,14 +121,12 @@ func (e *EdbInfo) ConvertDate() {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// AddEdbInfo 添加指标
|
|
|
func AddEdbInfo(item *EdbInfo) (lastId int64, err error) {
|
|
|
|
|
|
err = global.DEFAULT_DmSQL.Create(item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// EdbInfoList 指标数据列表
|
|
|
type EdbInfoList struct {
|
|
|
FrequencyEn string `gorm:"-" description:"英文频率"`
|
|
|
EdbNameAlias string `gorm:"-" json:"-" description:"指标名称,别名"`
|
|
@@ -143,59 +137,39 @@ type EdbInfoList struct {
|
|
|
Button EdbClassifyItemsButton `gorm:"-" description:"操作权限"`
|
|
|
IsEnEdb bool `gorm:"-" description:"是否展示英文标识"`
|
|
|
|
|
|
- EdbInfoId int `gorm:"primaryKey;autoIncrement;column:edb_info_id" description:"唯一标识"`
|
|
|
- EdbInfoType int `gorm:"column:edb_info_type" description:"指标类型,0:普通指标,1:预测指标"`
|
|
|
- SourceName string `gorm:"column:source_name" description:"来源名称"`
|
|
|
- Source int `gorm:"column:source" description:"来源id"`
|
|
|
- EdbCode string `gorm:"column:edb_code" description:"指标编码"`
|
|
|
- EdbName string `gorm:"column:edb_name" description:"指标名称"`
|
|
|
- EdbNameEn string `gorm:"column:edb_name_en" description:"英文指标名称"`
|
|
|
- //EdbNameSource string `gorm:"column:edb_name_source" description:"指标名称来源"`
|
|
|
- Frequency string `gorm:"column:frequency" description:"频率"`
|
|
|
- Unit string `gorm:"column:unit" description:"单位"`
|
|
|
- UnitEn string `gorm:"column:unit_en" description:"英文单位"`
|
|
|
- StartDate string `gorm:"column:start_date" description:"起始日期"`
|
|
|
- EndDate string `gorm:"column:end_date" description:"终止日期"`
|
|
|
- ClassifyId int `gorm:"column:classify_id" description:"分类id"`
|
|
|
- SysUserId int `gorm:"column:sys_user_id" description:"系统用户ID"`
|
|
|
- SysUserRealName string `gorm:"column:sys_user_real_name" description:"系统用户真实姓名"`
|
|
|
- UniqueCode string `gorm:"column:unique_code" description:"指标唯一编码"`
|
|
|
- CreateTime string `gorm:"column:create_time" description:"创建时间"`
|
|
|
- ModifyTime string `gorm:"column:modify_time" description:"修改时间"`
|
|
|
- //BaseModifyTime time.Time `gorm:"column:base_modify_time" description:"基础修改时间"`
|
|
|
- //MinValue float64 `gorm:"column:min_value" description:"指标最小值"`
|
|
|
- /*MaxValue float64 `gorm:"column:max_value" description:"指标最大值"`
|
|
|
- CalculateFormula string `gorm:"column:calculate_formula" description:"计算公式"`*/
|
|
|
- EdbType int `gorm:"column:edb_type" description:"指标类型:1:基础指标,2:计算指标"`
|
|
|
- //IsUpdate int `gorm:"column:is_update" description:"当天是否已更新,1:未更新,2:已更新"`
|
|
|
- //Sort int `gorm:"column:sort" description:"排序字段"`
|
|
|
- LatestDate string `gorm:"column:latest_date" description:"数据最新日期(实际日期)"`
|
|
|
- LatestValue float64 `gorm:"column:latest_value" description:"数据最新值(实际值)"`
|
|
|
- EndValue float64 `gorm:"column:end_value" description:"数据的最新值(预测日期的最新值)"`
|
|
|
- //MoveType int `gorm:"column:move_type" description:"移动方式:1:领先(默认),2:滞后"`
|
|
|
- //MoveFrequency string `gorm:"column:move_frequency" description:"移动频度"`
|
|
|
- NoUpdate int8 `gorm:"column:no_update" description:"是否停止更新,0:继续更新;1:停止更新"`
|
|
|
- //ServerUrl string `gorm:"column:server_url" description:"服务器地址"`
|
|
|
- ChartImage string `gorm:"column:chart_image" description:"图表图片"`
|
|
|
- //Calendar string `gorm:"column:calendar;default:公历" description:"公历/农历"`
|
|
|
- EmptyType int `gorm:"column:empty_type" description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
|
|
|
- MaxEmptyType int `gorm:"column:max_empty_type" description:"MAX、MIN公式空值处理类型(1、等于0;2、跳过空值)"`
|
|
|
- DataDateType string `gorm:"column:data_date_type;size:255;default:交易日" description:"数据日期类型"`
|
|
|
- /*ManualSave int `gorm:"column:manual_save" description:"是否有手动保存过上下限: 0-否; 1-是"`
|
|
|
- TerminalCode string `gorm:"column:terminal_code" description:"终端编码,用于配置在机器上"`
|
|
|
- DataUpdateTime string `gorm:"column:data_update_time" description:"最近一次数据发生变化的时间"`
|
|
|
- ErDataUpdateDate string `gorm:"column:er_data_update_date" description:"本次更新,数据发生变化的最早日期"`
|
|
|
- SourceIndexName string `gorm:"column:source_index_name" description:"数据源中的指标名称"`*/
|
|
|
- SubSource int `gorm:"column:sub_source" description:"子数据来源:0:经济数据库,1:日期序列"`
|
|
|
- SubSourceName string `gorm:"column:sub_source_name" description:"子数据来源名称"`
|
|
|
- IndicatorCode string `gorm:"column:indicator_code" description:"指标代码"`
|
|
|
- StockCode string `gorm:"column:stock_code" description:"证券代码"`
|
|
|
- //Extra string `gorm:"column:extra" description:"指标的额外配置"`
|
|
|
+ EdbInfoId int `gorm:"primaryKey;autoIncrement;column:edb_info_id" description:"唯一标识"`
|
|
|
+ EdbInfoType int `gorm:"column:edb_info_type" description:"指标类型,0:普通指标,1:预测指标"`
|
|
|
+ SourceName string `gorm:"column:source_name" description:"来源名称"`
|
|
|
+ Source int `gorm:"column:source" description:"来源id"`
|
|
|
+ EdbCode string `gorm:"column:edb_code" description:"指标编码"`
|
|
|
+ EdbName string `gorm:"column:edb_name" description:"指标名称"`
|
|
|
+ EdbNameEn string `gorm:"column:edb_name_en" description:"英文指标名称"`
|
|
|
+ Frequency string `gorm:"column:frequency" description:"频率"`
|
|
|
+ Unit string `gorm:"column:unit" description:"单位"`
|
|
|
+ UnitEn string `gorm:"column:unit_en" description:"英文单位"`
|
|
|
+ StartDate string `gorm:"column:start_date" description:"起始日期"`
|
|
|
+ EndDate string `gorm:"column:end_date" description:"终止日期"`
|
|
|
+ ClassifyId int `gorm:"column:classify_id" description:"分类id"`
|
|
|
+ SysUserId int `gorm:"column:sys_user_id" description:"系统用户ID"`
|
|
|
+ SysUserRealName string `gorm:"column:sys_user_real_name" description:"系统用户真实姓名"`
|
|
|
+ UniqueCode string `gorm:"column:unique_code" description:"指标唯一编码"`
|
|
|
+ CreateTime string `gorm:"column:create_time" description:"创建时间"`
|
|
|
+ ModifyTime string `gorm:"column:modify_time" description:"修改时间"`
|
|
|
+ EdbType int `gorm:"column:edb_type" description:"指标类型:1:基础指标,2:计算指标"`
|
|
|
+ LatestDate string `gorm:"column:latest_date" description:"数据最新日期(实际日期)"`
|
|
|
+ LatestValue float64 `gorm:"column:latest_value" description:"数据最新值(实际值)"`
|
|
|
+ EndValue float64 `gorm:"column:end_value" description:"数据的最新值(预测日期的最新值)"`
|
|
|
+ NoUpdate int8 `gorm:"column:no_update" description:"是否停止更新,0:继续更新;1:停止更新"`
|
|
|
+ ChartImage string `gorm:"column:chart_image" description:"图表图片"`
|
|
|
+ EmptyType int `gorm:"column:empty_type" description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
|
|
|
+ MaxEmptyType int `gorm:"column:max_empty_type" description:"MAX、MIN公式空值处理类型(1、等于0;2、跳过空值)"`
|
|
|
+ DataDateType string `gorm:"column:data_date_type;size:255;default:交易日" description:"数据日期类型"`
|
|
|
+ SubSource int `gorm:"column:sub_source" description:"子数据来源:0:经济数据库,1:日期序列"`
|
|
|
+ SubSourceName string `gorm:"column:sub_source_name" description:"子数据来源名称"`
|
|
|
+ IndicatorCode string `gorm:"column:indicator_code" description:"指标代码"`
|
|
|
+ StockCode string `gorm:"column:stock_code" description:"证券代码"`
|
|
|
}
|
|
|
|
|
|
-// ConvertDate
|
|
|
-// @Description: 格式化EdbInfoList的日期
|
|
|
-// @receiver e
|
|
|
func (e *EdbInfoList) ConvertDate() {
|
|
|
e.CreateTime = utils.GormDateStrToDateTimeStr(e.CreateTime)
|
|
|
e.ModifyTime = utils.GormDateStrToDateTimeStr(e.ModifyTime)
|
|
@@ -206,7 +180,6 @@ func (e *EdbInfoList) ConvertDate() {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// EdbClassifyItemsButton 操作按钮
|
|
|
type EdbClassifyItemsButton struct {
|
|
|
AddButton bool `description:"是否可添加"`
|
|
|
OpButton bool `description:"是否可编辑"`
|
|
@@ -216,7 +189,6 @@ type EdbClassifyItemsButton struct {
|
|
|
ShowChartRelation bool `description:"是否展示关联图表"`
|
|
|
}
|
|
|
|
|
|
-// GetEdbInfoByName 根据指标名称获取所有的指标数据列表
|
|
|
func GetEdbInfoByName(edbName string) (items []*EdbInfoList, err error) {
|
|
|
sql := ` SELECT * FROM edb_info WHERE edb_name=? `
|
|
|
err = global.DEFAULT_DmSQL.Raw(sql, edbName).Scan(&items).Error
|
|
@@ -225,14 +197,12 @@ func GetEdbInfoByName(edbName string) (items []*EdbInfoList, err error) {
|
|
|
return
|
|
|
}
|
|
|
for _, edbInfoItem := range items {
|
|
|
- // 时间转格式
|
|
|
edbInfoItem.ConvertDate()
|
|
|
}
|
|
|
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// ModifyEdbInfoNameSource 根据来源修改指标名称
|
|
|
func ModifyEdbInfoNameSource(edbNameSource string, edbInfoId int) (err error) {
|
|
|
|
|
|
sql := ` UPDATE edb_info SET edb_name_source=? WHERE edb_info_id = ? `
|
|
@@ -240,7 +210,6 @@ func ModifyEdbInfoNameSource(edbNameSource string, edbInfoId int) (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetEdbInfoById 根据指标id获取指标信息
|
|
|
func GetEdbInfoById(edbInfoId int) (item *EdbInfo, err error) {
|
|
|
sql := ` SELECT * FROM edb_info WHERE edb_info_id = ? `
|
|
|
err = global.DEFAULT_DmSQL.Raw(sql, edbInfoId).First(&item).Error
|
|
@@ -248,13 +217,11 @@ func GetEdbInfoById(edbInfoId int) (item *EdbInfo, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 格式化日期
|
|
|
item.ConvertDate()
|
|
|
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetEdbInfoByUniqueCode 根据指标唯一编码获取指标信息
|
|
|
func GetEdbInfoByUniqueCode(uniqueCode string) (item *EdbInfo, err error) {
|
|
|
|
|
|
sql := ` SELECT * FROM edb_info WHERE unique_code=? `
|
|
@@ -263,12 +230,10 @@ func GetEdbInfoByUniqueCode(uniqueCode string) (item *EdbInfo, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 格式化日期
|
|
|
item.ConvertDate()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetEdbInfoByIdList 根据指标id列表获取指标信息
|
|
|
func GetEdbInfoByIdList(edbInfoIdList []int) (items []*EdbInfo, err error) {
|
|
|
num := len(edbInfoIdList)
|
|
|
if num <= 0 {
|
|
@@ -280,15 +245,12 @@ func GetEdbInfoByIdList(edbInfoIdList []int) (items []*EdbInfo, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// Update 更新EdbInfo信息
|
|
|
func (edbInfo *EdbInfo) Update(cols []string) (err error) {
|
|
|
|
|
|
err = global.DEFAULT_DmSQL.Model(edbInfo).Select(cols).Updates(edbInfo).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// EdbInfoSearchData
|
|
|
-// @Description: 指标数据
|
|
|
type EdbInfoSearchData struct {
|
|
|
EdbDataId int `description:"数据ID"`
|
|
|
EdbInfoId int `description:"指标ID"`
|
|
@@ -298,9 +260,6 @@ type EdbInfoSearchData struct {
|
|
|
DataTimestamp int64 `description:"时间戳"`
|
|
|
}
|
|
|
|
|
|
-// ConvertTimeStr
|
|
|
-// @Description: 转成需要输出的格式
|
|
|
-// @receiver m
|
|
|
func (m *EdbInfoSearchData) ConvertTimeStr() {
|
|
|
m.DataTime = utils.GormDateStrToDateStr(m.DataTime)
|
|
|
|
|
@@ -315,16 +274,6 @@ type FindEdbDataListAllCond struct {
|
|
|
EndDataTimeCond string
|
|
|
}
|
|
|
|
|
|
-// GetEdbDataListAll
|
|
|
-// @Description: 获取指标数据列表 order:1升序,其余值为降序
|
|
|
-// @author: Roc
|
|
|
-// @datetime 2024-05-08 15:34:01
|
|
|
-// @param source int
|
|
|
-// @param subSource int
|
|
|
-// @param findEdbDataListAllCond FindEdbDataListAllCond
|
|
|
-// @param order int order:1升序,其余值为降序
|
|
|
-// @return item []*EdbInfoSearchData
|
|
|
-// @return err error
|
|
|
func GetEdbDataListAll(source, subSource int, findEdbDataListAllCond FindEdbDataListAllCond, order int) (item []*EdbInfoSearchData, err error) {
|
|
|
if source == utils.DATA_SOURCE_BUSINESS && utils.UseMongo {
|
|
|
return GetEdbDataListAllByMongo(source, subSource, findEdbDataListAllCond, order)
|
|
@@ -333,16 +282,6 @@ func GetEdbDataListAll(source, subSource int, findEdbDataListAllCond FindEdbData
|
|
|
return GetEdbDataListAllByMysql(source, subSource, findEdbDataListAllCond, order)
|
|
|
}
|
|
|
|
|
|
-// GetEdbDataListAllByMysql
|
|
|
-// @Description: 从mysql数据库中获取指标数据列表 order:1升序,其余值为降序
|
|
|
-// @author: Roc
|
|
|
-// @datetime 2024-05-08 15:32:55
|
|
|
-// @param source int
|
|
|
-// @param subSource int
|
|
|
-// @param findEdbDataListAllCond FindEdbDataListAllCond
|
|
|
-// @param order int
|
|
|
-// @return items []*EdbInfoSearchData
|
|
|
-// @return err error
|
|
|
func GetEdbDataListAllByMysql(source, subSource int, findEdbDataListAllCond FindEdbDataListAllCond, order int) (items []*EdbInfoSearchData, err error) {
|
|
|
if findEdbDataListAllCond.EdbInfoId <= 0 {
|
|
|
return
|
|
@@ -358,12 +297,10 @@ func GetEdbDataListAllByMysql(source, subSource int, findEdbDataListAllCond Find
|
|
|
condition += " AND edb_info_id=? "
|
|
|
pars = append(pars, findEdbDataListAllCond.EdbInfoId)
|
|
|
|
|
|
- // 开始日期
|
|
|
if findEdbDataListAllCond.StartDataTime != "" && findEdbDataListAllCond.StartDataTimeCond != `` {
|
|
|
condition += fmt.Sprintf(" AND data_time %s ? ", findEdbDataListAllCond.StartDataTimeCond)
|
|
|
pars = append(pars, findEdbDataListAllCond.StartDataTime)
|
|
|
}
|
|
|
- // 结束日期
|
|
|
if findEdbDataListAllCond.EndDataTime != "" && findEdbDataListAllCond.EndDataTimeCond != `` {
|
|
|
condition += fmt.Sprintf(" AND data_time %s ? ", findEdbDataListAllCond.EndDataTimeCond)
|
|
|
pars = append(pars, findEdbDataListAllCond.EndDataTime)
|
|
@@ -377,12 +314,10 @@ func GetEdbDataListAllByMysql(source, subSource int, findEdbDataListAllCond Find
|
|
|
} else {
|
|
|
sql += ` ORDER BY data_time DESC `
|
|
|
}
|
|
|
- // todo
|
|
|
err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&items).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
- // 统一处理日期
|
|
|
for _, v := range items {
|
|
|
v.ConvertTimeStr()
|
|
|
}
|
|
@@ -390,17 +325,6 @@ func GetEdbDataListAllByMysql(source, subSource int, findEdbDataListAllCond Find
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetEdbDataListAllByTo
|
|
|
-// @Description: 根据事务链接获取指标数据列表 order:1升序,其余值为降序
|
|
|
-// @author: Roc
|
|
|
-// @datetime 2024-05-08 15:34:06
|
|
|
-// @param to *gorm.DB
|
|
|
-// @param source int
|
|
|
-// @param subSource int
|
|
|
-// @param findEdbDataListAllCond FindEdbDataListAllCond
|
|
|
-// @param order int
|
|
|
-// @return item []*EdbInfoSearchData
|
|
|
-// @return err error
|
|
|
func GetEdbDataListAllByTo(to *gorm.DB, source, subSource int, findEdbDataListAllCond FindEdbDataListAllCond, order int) (item []*EdbInfoSearchData, err error) {
|
|
|
if source == utils.DATA_SOURCE_BUSINESS && utils.UseMongo {
|
|
|
return GetEdbDataListAllByMongo(source, subSource, findEdbDataListAllCond, order)
|
|
@@ -409,17 +333,6 @@ func GetEdbDataListAllByTo(to *gorm.DB, source, subSource int, findEdbDataListAl
|
|
|
return GetEdbDataListAllByMysqlTo(to, source, subSource, findEdbDataListAllCond, order)
|
|
|
}
|
|
|
|
|
|
-// GetEdbDataListAllByMysqlTo
|
|
|
-// @Description: 根据事务链接获取指标数据列表 order:1升序,其余值为降序(Mysql)
|
|
|
-// @author: Roc
|
|
|
-// @datetime 2024-05-08 15:34:13
|
|
|
-// @param to *gorm.DB
|
|
|
-// @param source int
|
|
|
-// @param subSource int
|
|
|
-// @param findEdbDataListAllCond FindEdbDataListAllCond
|
|
|
-// @param order int
|
|
|
-// @return items []*EdbInfoSearchData
|
|
|
-// @return err error
|
|
|
func GetEdbDataListAllByMysqlTo(to *gorm.DB, source, subSource int, findEdbDataListAllCond FindEdbDataListAllCond, order int) (items []*EdbInfoSearchData, err error) {
|
|
|
if findEdbDataListAllCond.EdbInfoId <= 0 {
|
|
|
return
|
|
@@ -434,12 +347,10 @@ func GetEdbDataListAllByMysqlTo(to *gorm.DB, source, subSource int, findEdbDataL
|
|
|
condition += " AND edb_info_id=? "
|
|
|
pars = append(pars, findEdbDataListAllCond.EdbInfoId)
|
|
|
|
|
|
- // 开始日期
|
|
|
if findEdbDataListAllCond.StartDataTime != "" && findEdbDataListAllCond.StartDataTimeCond != `` {
|
|
|
condition += fmt.Sprintf(" AND data_time %s ? ", findEdbDataListAllCond.StartDataTimeCond)
|
|
|
pars = append(pars, findEdbDataListAllCond.StartDataTime)
|
|
|
}
|
|
|
- // 结束日期
|
|
|
if findEdbDataListAllCond.EndDataTime != "" && findEdbDataListAllCond.EndDataTimeCond != `` {
|
|
|
condition += fmt.Sprintf(" AND data_time %s ? ", findEdbDataListAllCond.EndDataTimeCond)
|
|
|
pars = append(pars, findEdbDataListAllCond.EndDataTime)
|
|
@@ -457,7 +368,6 @@ func GetEdbDataListAllByMysqlTo(to *gorm.DB, source, subSource int, findEdbDataL
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
- // 统一处理日期
|
|
|
for _, v := range items {
|
|
|
v.ConvertTimeStr()
|
|
|
}
|
|
@@ -465,23 +375,12 @@ func GetEdbDataListAllByMysqlTo(to *gorm.DB, source, subSource int, findEdbDataL
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetEdbDataListAllByMongo
|
|
|
-// @Description: 根据事务链接获取指标数据列表 order:1升序,其余值为降序(Mongo)
|
|
|
-// @author: Roc
|
|
|
-// @datetime 2024-05-08 15:34:24
|
|
|
-// @param source int
|
|
|
-// @param subSource int
|
|
|
-// @param findEdbDataListAllCond FindEdbDataListAllCond
|
|
|
-// @param order int
|
|
|
-// @return dataList []*EdbInfoSearchData
|
|
|
-// @return err error
|
|
|
func GetEdbDataListAllByMongo(source, subSource int, findEdbDataListAllCond FindEdbDataListAllCond, order int) (dataList []*EdbInfoSearchData, err error) {
|
|
|
dataList = make([]*EdbInfoSearchData, 0)
|
|
|
if findEdbDataListAllCond.EdbInfoId <= 0 {
|
|
|
return
|
|
|
}
|
|
|
mogDataObj := mgo.EdbDataBusiness{}
|
|
|
- // 构建查询条件
|
|
|
queryConditions := bson.M{
|
|
|
"edb_info_id": findEdbDataListAllCond.EdbInfoId,
|
|
|
}
|
|
@@ -499,7 +398,6 @@ func GetEdbDataListAllByMongo(source, subSource int, findEdbDataListAllCond Find
|
|
|
} else {
|
|
|
sortList = append(sortList, "-data_time")
|
|
|
}
|
|
|
- // 获取列表数据
|
|
|
tmpDataList, tmpErr := mogDataObj.GetAllDataList(queryConditions, sortList)
|
|
|
if tmpErr != nil {
|
|
|
err = tmpErr
|
|
@@ -518,7 +416,6 @@ func GetEdbDataListAllByMongo(source, subSource int, findEdbDataListAllCond Find
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// EdbInfoMaxAndMinInfo 指标最新数据记录结构体
|
|
|
type EdbInfoMaxAndMinInfo struct {
|
|
|
MinDate string `description:"最小日期" bson:"min_date"`
|
|
|
MaxDate string `description:"最大日期" bson:"max_date"`
|
|
@@ -529,7 +426,6 @@ type EdbInfoMaxAndMinInfo struct {
|
|
|
EndValue float64 `description:"最新值" bson:"end_value"`
|
|
|
}
|
|
|
|
|
|
-// AfterFind 在该模型上设置钩子函数,把日期转成正确的string,所以查询函数只能用Find函数,First或者Scan是不会触发该函数的来获取数据
|
|
|
func (m *EdbInfoMaxAndMinInfo) AfterFind(db *gorm.DB) (err error) {
|
|
|
if m.MinDate != "" {
|
|
|
minDateTmp, e := time.ParseInLocation(utils.FormatDateWallWithLoc, m.MinDate, time.Local)
|
|
@@ -550,7 +446,6 @@ func (m *EdbInfoMaxAndMinInfo) AfterFind(db *gorm.DB) (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// EdbInfoMaxAndMinInfoTmp 指标最新数据记录结构体
|
|
|
type EdbInfoMaxAndMinInfoTmp struct {
|
|
|
MinDate time.Time `description:"最小日期" bson:"min_date"`
|
|
|
MaxDate time.Time `description:"最大日期" bson:"max_date"`
|
|
@@ -561,7 +456,6 @@ type EdbInfoMaxAndMinInfoTmp struct {
|
|
|
EndValue float64 `description:"最新值" bson:"end_value"`
|
|
|
}
|
|
|
|
|
|
-// GetEdbInfoMaxAndMinInfo 获取指标的最新数据记录信息
|
|
|
func GetEdbInfoMaxAndMinInfo(source, subSource int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
|
|
|
sql := ``
|
|
|
tableName := GetEdbDataTableName(source, subSource)
|
|
@@ -572,7 +466,6 @@ func GetEdbInfoMaxAndMinInfo(source, subSource int, edbCode string) (item *EdbIn
|
|
|
var latest_value float64
|
|
|
sql = ` SELECT value AS latest_value FROM %s WHERE edb_code=? ORDER BY data_time DESC LIMIT 1 `
|
|
|
sql = fmt.Sprintf(sql, tableName)
|
|
|
- // todo 测试查询单个字段
|
|
|
err = global.DEFAULT_DmSQL.Raw(sql, edbCode).Scan(&latest_value).Error
|
|
|
item.LatestValue = latest_value
|
|
|
return
|
|
@@ -582,7 +475,6 @@ type EdbIndoDataUpdateTime struct {
|
|
|
MinDate string `description:"本次更新,数据发生变化的最早日期"`
|
|
|
}
|
|
|
|
|
|
-// AfterFind 在该模型上设置钩子函数,把日期转成正确的string,所以查询函数只能用Find函数,First或者Scan是不会触发该函数的来获取数据
|
|
|
func (m *EdbIndoDataUpdateTime) AfterFind(db *gorm.DB) (err error) {
|
|
|
if m.MinDate == "" {
|
|
|
return
|
|
@@ -595,7 +487,6 @@ func (m *EdbIndoDataUpdateTime) AfterFind(db *gorm.DB) (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetEdbDataUpdateTimeByModify 获取指标的刷新时间获取最早的一条记录
|
|
|
func GetEdbDataUpdateTimeByModify(source, subSource int, edbCode string, dataUpdateTime string) (item *EdbIndoDataUpdateTime, err error) {
|
|
|
sql := ``
|
|
|
tableName := GetEdbDataTableName(source, subSource)
|
|
@@ -606,7 +497,6 @@ func GetEdbDataUpdateTimeByModify(source, subSource int, edbCode string, dataUpd
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// ModifyEdbInfoMaxAndMinInfo 修改指标的最新数据信息
|
|
|
func ModifyEdbInfoMaxAndMinInfo(edbInfoId int, item *EdbInfoMaxAndMinInfo) (err error) {
|
|
|
sql := ` UPDATE edb_info SET start_date=?,end_date=?,min_value=?,max_value=?,is_update=2,latest_date=?,latest_value=?, end_value = ?,modify_time=NOW() WHERE edb_info_id=? `
|
|
|
err = global.DEFAULT_DmSQL.Exec(sql, item.MinDate, item.MaxDate, item.MinValue, item.MaxValue, item.MaxDate, item.LatestValue, item.LatestValue, edbInfoId).Error
|
|
@@ -614,7 +504,6 @@ func ModifyEdbInfoMaxAndMinInfo(edbInfoId int, item *EdbInfoMaxAndMinInfo) (err
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// ModifyEdbTimeAndLastInfo 修改指标的最新数据信息(除上下限)
|
|
|
func ModifyEdbTimeAndLastInfo(edbInfoId int, item *EdbInfoMaxAndMinInfo) (err error) {
|
|
|
sql := `UPDATE edb_info SET start_date = ?, end_date = ?, is_update = 2,latest_date = ?, latest_value = ?, end_value = ?, modify_time = NOW() WHERE edb_info_id = ?`
|
|
|
err = global.DEFAULT_DmSQL.Exec(sql, item.MinDate, item.MaxDate, item.MaxDate, item.LatestValue, item.LatestValue, edbInfoId).Error
|
|
@@ -622,7 +511,6 @@ func ModifyEdbTimeAndLastInfo(edbInfoId int, item *EdbInfoMaxAndMinInfo) (err er
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// ModifyEdbDataUpdateTime 修改指标刷新,本次数据刷新的最早日期
|
|
|
func ModifyEdbDataUpdateTime(edbInfoId int, dataUpdateTime, erDataUpdateDate string) (err error) {
|
|
|
sql := `UPDATE edb_info SET data_update_time = ?, er_data_update_date = ?, modify_time = NOW() WHERE edb_info_id = ?`
|
|
|
err = global.DEFAULT_DmSQL.Exec(sql, dataUpdateTime, erDataUpdateDate, edbInfoId).Error
|
|
@@ -630,15 +518,6 @@ func ModifyEdbDataUpdateTime(edbInfoId int, dataUpdateTime, erDataUpdateDate str
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetLteZeroEdbDataCount
|
|
|
-// @Description: 获取小于等于0的数据数量
|
|
|
-// @author: Roc
|
|
|
-// @datetime 2024-05-31 10:44:39
|
|
|
-// @param source int
|
|
|
-// @param subSource int
|
|
|
-// @param edbInfoId int
|
|
|
-// @return count int
|
|
|
-// @return err error
|
|
|
func GetLteZeroEdbDataCount(source, subSource, edbInfoId int) (count int, err error) {
|
|
|
if source == utils.DATA_SOURCE_BUSINESS && utils.UseMongo {
|
|
|
return GetLteZeroEdbDataCountByMongo(source, subSource, edbInfoId)
|
|
@@ -647,23 +526,12 @@ func GetLteZeroEdbDataCount(source, subSource, edbInfoId int) (count int, err er
|
|
|
return GetLteZeroEdbDataCountByMysql(source, subSource, edbInfoId)
|
|
|
}
|
|
|
|
|
|
-// GetLteZeroEdbDataCountByMongo
|
|
|
-// @Description: 获取小于等于0的数据数量(从mongo)
|
|
|
-// @author: Roc
|
|
|
-// @datetime 2024-05-31 10:41:04
|
|
|
-// @param source int
|
|
|
-// @param subSource int
|
|
|
-// @param edbInfoId int
|
|
|
-// @return count int
|
|
|
-// @return err error
|
|
|
func GetLteZeroEdbDataCountByMongo(source, subSource, edbInfoId int) (count int, err error) {
|
|
|
mogDataObj := mgo.EdbDataBusiness{}
|
|
|
- // 构建查询条件
|
|
|
whereQuery := bson.M{
|
|
|
"edb_info_id": edbInfoId,
|
|
|
"value": bson.M{"$lte": 0},
|
|
|
}
|
|
|
- // 获数量数据
|
|
|
tmpCount, err := mogDataObj.GetCountDataList(whereQuery)
|
|
|
if err != nil {
|
|
|
return
|
|
@@ -674,15 +542,6 @@ func GetLteZeroEdbDataCountByMongo(source, subSource, edbInfoId int) (count int,
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetLteZeroEdbDataCountByMysql
|
|
|
-// @Description: 获取小于等于0的数据数量(从mysql)
|
|
|
-// @author: Roc
|
|
|
-// @datetime 2024-05-31 10:29:19
|
|
|
-// @param source int
|
|
|
-// @param subSource int
|
|
|
-// @param edbInfoId int
|
|
|
-// @return count int
|
|
|
-// @return err error
|
|
|
func GetLteZeroEdbDataCountByMysql(source, subSource, edbInfoId int) (count int, err error) {
|
|
|
sql := ``
|
|
|
tableName := GetEdbDataTableName(source, subSource)
|
|
@@ -692,7 +551,6 @@ func GetLteZeroEdbDataCountByMysql(source, subSource, edbInfoId int) (count int,
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetLastEdbData 获取最近的一条指标数据
|
|
|
func GetLastEdbData(condition string, pars []interface{}, source, subSource int) (item *EdbInfoSearchData, err error) {
|
|
|
sql := ``
|
|
|
tableName := GetEdbDataTableName(source, subSource)
|
|
@@ -707,7 +565,6 @@ func GetLastEdbData(condition string, pars []interface{}, source, subSource int)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetEdbInfoByEdbCode 根据指标code获取指标信息
|
|
|
func GetEdbInfoByEdbCode(source int, edbCode string) (item *EdbInfo, err error) {
|
|
|
sql := ` SELECT * FROM edb_info WHERE source=? AND edb_code=? `
|
|
|
err = global.DEFAULT_DmSQL.Raw(sql, source, edbCode).First(&item).Error
|
|
@@ -715,14 +572,12 @@ func GetEdbInfoByEdbCode(source int, edbCode string) (item *EdbInfo, err error)
|
|
|
if errors.Is(err, orm.ErrNoRows) {
|
|
|
err = nil
|
|
|
} else {
|
|
|
- // 格式化日期
|
|
|
item.ConvertDate()
|
|
|
}
|
|
|
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetEdbInfoOnlyByEdbCode 仅根据指标code获取指标信息
|
|
|
func GetEdbInfoOnlyByEdbCode(edbCode string) (item *EdbInfo, err error) {
|
|
|
sql := ` SELECT * FROM edb_info WHERE edb_code=? `
|
|
|
err = global.DEFAULT_DmSQL.Raw(sql, edbCode).First(&item).Error
|
|
@@ -730,13 +585,11 @@ func GetEdbInfoOnlyByEdbCode(edbCode string) (item *EdbInfo, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 格式化日期
|
|
|
item.ConvertDate()
|
|
|
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetEdbInfoCalculateListByCondition 获取指标关系列表
|
|
|
func GetEdbInfoCalculateListByCondition(condition string, pars []interface{}) (items []*EdbInfoCalculateMapping, err error) {
|
|
|
sql := ` SELECT * FROM edb_info_calculate_mapping WHERE 1=1 `
|
|
|
if condition != "" {
|
|
@@ -747,7 +600,6 @@ func GetEdbInfoCalculateListByCondition(condition string, pars []interface{}) (i
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetEdbInfoCalculateCountByCondition 获取关联指标数量
|
|
|
func GetEdbInfoCalculateCountByCondition(condition string, pars []interface{}) (count int, err error) {
|
|
|
sql := ` SELECT COUNT(1) AS count FROM edb_info_calculate_mapping WHERE 1=1 `
|
|
|
if condition != "" {
|
|
@@ -758,14 +610,12 @@ func GetEdbInfoCalculateCountByCondition(condition string, pars []interface{}) (
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// 优化版本-处理数据精度问题
|
|
|
type EdbInfoSearchDataV1 struct {
|
|
|
EdbDataId int `description:"数据ID"`
|
|
|
DataTime string `description:"数据日期"`
|
|
|
Value string `description:"数据"`
|
|
|
}
|
|
|
|
|
|
-// GetEdbDataListAllV1ByTo 通过事务链接获取数据列表
|
|
|
func GetEdbDataListAllV1ByTo(to *gorm.DB, condition string, pars []interface{}, source, subSource, order int) (items []*EdbInfoSearchDataV1, err error) {
|
|
|
sql := ``
|
|
|
tableName := GetEdbDataTableName(source, subSource)
|
|
@@ -785,7 +635,6 @@ func GetEdbDataListAllV1ByTo(to *gorm.DB, condition string, pars []interface{},
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 日期格式化
|
|
|
for _, item := range items {
|
|
|
item.ConvertDate()
|
|
|
}
|
|
@@ -793,9 +642,7 @@ func GetEdbDataListAllV1ByTo(to *gorm.DB, condition string, pars []interface{},
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// UnifiedModifyEdbInfoMaxAndMinInfo 统一修改指标的最大最小值
|
|
|
func UnifiedModifyEdbInfoMaxAndMinInfo(edbInfo *EdbInfo) (err error, errMsg string) {
|
|
|
- // 修改最大最小值
|
|
|
maxAndMinItem, err := GetEdbInfoMaxAndMinInfo(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbCode)
|
|
|
if err != nil {
|
|
|
if err.Error() == utils.ErrNoRow() {
|
|
@@ -808,7 +655,6 @@ func UnifiedModifyEdbInfoMaxAndMinInfo(edbInfo *EdbInfo) (err error, errMsg stri
|
|
|
return
|
|
|
}
|
|
|
if maxAndMinItem != nil {
|
|
|
- // ETA1.0.3改-如果指标有手动保存过, 那么就不更新指标的最大最小值
|
|
|
if edbInfo.ManualSave == 1 {
|
|
|
err = ModifyEdbTimeAndLastInfo(edbInfo.EdbInfoId, maxAndMinItem)
|
|
|
if err != nil {
|
|
@@ -826,19 +672,16 @@ func UnifiedModifyEdbInfoMaxAndMinInfo(edbInfo *EdbInfo) (err error, errMsg stri
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 刷新关联的预测指标
|
|
|
go RefreshPredictStandardBaseByGeneralEdbInfoId(edbInfo.EdbInfoId)
|
|
|
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// UnifiedModifyEdbInfoMaxAndMinInfoDataUpdate 统一修改指标的最大最小值以及数据更新时间点
|
|
|
func UnifiedModifyEdbInfoMaxAndMinInfoDataUpdate(edbInfo *EdbInfo, dataUpdateTime string) (erDataUpdateDate string, err error, errMsg string) {
|
|
|
err, errMsg = UnifiedModifyEdbInfoMaxAndMinInfo(edbInfo)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
- // 获取本次刷新,指标数据更新的最早日期
|
|
|
erDataUpdateTime, tErr := GetEdbDataUpdateTimeByModify(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbCode, dataUpdateTime)
|
|
|
if tErr != nil {
|
|
|
if tErr.Error() != utils.ErrNoRow() { //本次刷新指标数据无变化
|
|
@@ -859,9 +702,7 @@ func UnifiedModifyEdbInfoMaxAndMinInfoDataUpdate(edbInfo *EdbInfo, dataUpdateTim
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// UnifiedModifyPredictEdbInfoMaxAndMinInfo 统一修改预测运算指标的最大最小值
|
|
|
func UnifiedModifyPredictEdbInfoMaxAndMinInfo(edbInfo *EdbInfo, latestDateStr string, latestValue float64) (err error, errMsg string) {
|
|
|
- // 修改最大最小值
|
|
|
maxAndMinItem, err := GetEdbInfoMaxAndMinInfo(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbCode)
|
|
|
if err != nil {
|
|
|
if err.Error() == utils.ErrNoRow() {
|
|
@@ -874,7 +715,6 @@ func UnifiedModifyPredictEdbInfoMaxAndMinInfo(edbInfo *EdbInfo, latestDateStr st
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 最晚的日期的值
|
|
|
maxAndMinItem.EndValue = maxAndMinItem.LatestValue
|
|
|
|
|
|
if maxAndMinItem != nil {
|
|
@@ -892,7 +732,6 @@ func UnifiedModifyPredictEdbInfoMaxAndMinInfo(edbInfo *EdbInfo, latestDateStr st
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetChartPredictEdbInfoDataListByConfList 获取图表的预测指标的未来数据
|
|
|
func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*PredictEdbConfAndData, filtrateStartDateStr, latestDateStr, endDateStr, frequency, dataDateType string, realPredictEdbInfoData []*EdbInfoSearchData) (predictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64, err error) {
|
|
|
endDate, err := time.ParseInLocation(utils.FormatDate, endDateStr, time.Local)
|
|
|
if err != nil {
|
|
@@ -904,31 +743,25 @@ func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*PredictEdbCo
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 开始预测数据的时间
|
|
|
startDate := latestDate
|
|
|
|
|
|
- // 如果有筛选时间的话
|
|
|
if filtrateStartDateStr != `` {
|
|
|
filtrateStartDate, tmpErr := time.ParseInLocation(utils.FormatDate, filtrateStartDateStr, time.Local)
|
|
|
if tmpErr != nil {
|
|
|
err = tmpErr
|
|
|
return
|
|
|
}
|
|
|
- //如果筛选时间晚于实际数据时间,那么就以筛选时间作为获取预测数据的时间
|
|
|
if filtrateStartDate.After(latestDate) {
|
|
|
startDate = filtrateStartDate.AddDate(0, 0, -1)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 对应日期的值
|
|
|
existMap := make(map[string]float64)
|
|
|
for _, v := range realPredictEdbInfoData {
|
|
|
- //dateArr = append(dateArr, v.DataTime)
|
|
|
existMap[v.DataTime] = v.Value
|
|
|
}
|
|
|
|
|
|
predictEdbInfoData = make([]*EdbInfoSearchData, 0)
|
|
|
- //预测规则,1:最新,2:固定值,3:同比,4:同差,5:环比,6:环差,7:N期移动均值,8:N期段线性外推值
|
|
|
|
|
|
for _, predictEdbConf := range predictEdbConfList {
|
|
|
endDate = predictEdbConf.EndDate
|
|
@@ -1033,7 +866,6 @@ func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*PredictEdbCo
|
|
|
if tmpErr != nil {
|
|
|
continue
|
|
|
}
|
|
|
- // 只处理时间段内的数据
|
|
|
if currentDate.Before(startDate) || currentDate.After(endDate) {
|
|
|
continue
|
|
|
}
|
|
@@ -1062,7 +894,6 @@ func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*PredictEdbCo
|
|
|
calendar = "农历"
|
|
|
}
|
|
|
yearList := make([]int, 0)
|
|
|
- //选择方式,1:连续N年;2:指定年份
|
|
|
if seasonConf.YearType == 1 {
|
|
|
if seasonConf.NValue < 1 {
|
|
|
err = errors.New("连续N年不允许小于1")
|
|
@@ -1107,7 +938,6 @@ func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*PredictEdbCo
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 规则计算的拟合残差值map
|
|
|
newNhccDataMap := make(map[string]float64)
|
|
|
if predictEdbConf.PredictEdbInfoId > 0 { //已经生成的动态数据
|
|
|
tmpPredictEdbRuleDataList, tmpErr := GetPredictEdbRuleDataItemList(predictEdbConf.PredictEdbInfoId, predictEdbConf.ConfigId, startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate))
|
|
@@ -1140,7 +970,6 @@ func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*PredictEdbCo
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 下一个规则的开始日期
|
|
|
{
|
|
|
lenPredictEdbInfoData := len(predictEdbInfoData)
|
|
|
if lenPredictEdbInfoData > 0 {
|
|
@@ -1162,7 +991,6 @@ func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*PredictEdbCo
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetPredictEdbDayList 获取预测指标日期列表
|
|
|
func getPredictEdbDayList(startDate, endDate time.Time, frequency, dataDateType string) (dayList []time.Time) {
|
|
|
if dataDateType == `` {
|
|
|
dataDateType = `交易日`
|
|
@@ -1170,7 +998,6 @@ func getPredictEdbDayList(startDate, endDate time.Time, frequency, dataDateType
|
|
|
switch frequency {
|
|
|
case "日度":
|
|
|
for currDate := startDate.AddDate(0, 0, 1); currDate.Before(endDate) || currDate.Equal(endDate); currDate = currDate.AddDate(0, 0, 1) {
|
|
|
- // 如果日期类型是交易日的时候,那么需要将周六、日排除
|
|
|
if dataDateType == `交易日` && (currDate.Weekday() == time.Sunday || currDate.Weekday() == time.Saturday) {
|
|
|
continue
|
|
|
}
|
|
@@ -1183,7 +1010,6 @@ func getPredictEdbDayList(startDate, endDate time.Time, frequency, dataDateType
|
|
|
case "旬度":
|
|
|
for currDate := startDate.AddDate(0, 0, 1); currDate.Before(endDate) || currDate.Equal(endDate); {
|
|
|
nextDate := currDate.AddDate(0, 0, 1)
|
|
|
- //每个月的10号、20号、最后一天,那么就写入
|
|
|
if nextDate.Day() == 11 || nextDate.Day() == 21 || nextDate.Day() == 1 {
|
|
|
dayList = append(dayList, currDate)
|
|
|
}
|
|
@@ -1199,10 +1025,8 @@ func getPredictEdbDayList(startDate, endDate time.Time, frequency, dataDateType
|
|
|
}
|
|
|
case "季度":
|
|
|
for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
|
|
|
- // 每月的最后一天
|
|
|
currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
|
|
|
if !currDate.After(endDate) && !currDate.Equal(startDate) {
|
|
|
- // 季度日期就写入,否则不写入
|
|
|
if currDate.Month() == 3 || currDate.Month() == 6 || currDate.Month() == 9 || currDate.Month() == 12 {
|
|
|
dayList = append(dayList, currDate)
|
|
|
}
|
|
@@ -1211,10 +1035,8 @@ func getPredictEdbDayList(startDate, endDate time.Time, frequency, dataDateType
|
|
|
}
|
|
|
case "半年度":
|
|
|
for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
|
|
|
- // 每月的最后一天
|
|
|
currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
|
|
|
if !currDate.After(endDate) && !currDate.Equal(startDate) {
|
|
|
- // 半年度日期就写入,否则不写入
|
|
|
if currDate.Month() == 6 || currDate.Month() == 12 {
|
|
|
dayList = append(dayList, currDate)
|
|
|
}
|
|
@@ -1232,9 +1054,7 @@ func getPredictEdbDayList(startDate, endDate time.Time, frequency, dataDateType
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetPredictDataListByPredictEdbInfo 根据预测指标信息获取预测指标的数据,order:1升序,其余值为降序
|
|
|
func GetPredictDataListByPredictEdbInfo(edbInfo *EdbInfo, order int, startDate string) (dataList []*EdbInfoSearchData, sourceEdbInfoItem *EdbInfo, err error, errMsg string) {
|
|
|
- // 查找该预测指标配置
|
|
|
predictEdbConfList, err := GetPredictEdbConfAndDataListById(edbInfo.EdbInfoId)
|
|
|
if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
errMsg = "获取预测指标配置信息失败"
|
|
@@ -1247,7 +1067,6 @@ func GetPredictDataListByPredictEdbInfo(edbInfo *EdbInfo, order int, startDate s
|
|
|
}
|
|
|
predictEdbConf := predictEdbConfList[0]
|
|
|
|
|
|
- // 来源指标
|
|
|
sourceEdbInfoItem, err = GetEdbInfoById(predictEdbConf.SourceEdbInfoId)
|
|
|
if err != nil {
|
|
|
if err.Error() == utils.ErrNoRow() {
|
|
@@ -1262,10 +1081,8 @@ func GetPredictDataListByPredictEdbInfo(edbInfo *EdbInfo, order int, startDate s
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetPredictDataListByPredictEdbConfList 根据预测指标信息获取预测指标的数据,order:1升序,其余值为降序
|
|
|
func GetPredictDataListByPredictEdbConfList(edbInfo, sourceEdbInfoItem *EdbInfo, predictEdbConfList []*PredictEdbConfAndData, order int, startDate string) (dataList []*EdbInfoSearchData, err error, errMsg string) {
|
|
|
allDataList := make([]*EdbInfoSearchData, 0)
|
|
|
- //获取指标数据(实际已生成)
|
|
|
tmpDataList, err := GetEdbDataListAll(sourceEdbInfoItem.Source, sourceEdbInfoItem.SubSource, FindEdbDataListAllCond{
|
|
|
EdbInfoId: sourceEdbInfoItem.EdbInfoId,
|
|
|
StartDataTime: startDate,
|
|
@@ -1275,11 +1092,8 @@ func GetPredictDataListByPredictEdbConfList(edbInfo, sourceEdbInfoItem *EdbInfo,
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 默认认为上一个查询是把所有的数据查出来了
|
|
|
allDataList = tmpDataList
|
|
|
|
|
|
- // 如果条件中有选择了日期,那么上次查询实际并不是把所有的数据查出来了
|
|
|
- // 那么需要把日期给过滤掉,然后筛选所有的数据,用于未来指标的生成
|
|
|
if startDate != `` {
|
|
|
allDataList, err = GetEdbDataListAll(sourceEdbInfoItem.Source, sourceEdbInfoItem.SubSource, FindEdbDataListAllCond{
|
|
|
EdbInfoId: sourceEdbInfoItem.EdbInfoId,
|
|
@@ -1289,13 +1103,11 @@ func GetPredictDataListByPredictEdbConfList(edbInfo, sourceEdbInfoItem *EdbInfo,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 获取预测指标未来的数据
|
|
|
predictDataList := make([]*EdbInfoSearchData, 0)
|
|
|
|
|
|
endDateStr := edbInfo.EndDate //预测指标的结束日期
|
|
|
|
|
|
var predictMinValue, predictMaxValue float64
|
|
|
- // 如果有配置的预测规则,那么就进行预测
|
|
|
if len(predictEdbConfList) > 0 {
|
|
|
predictDataList, predictMinValue, predictMaxValue, err = GetChartPredictEdbInfoDataListByConfList(predictEdbConfList, startDate, sourceEdbInfoItem.LatestDate, endDateStr, edbInfo.Frequency, edbInfo.DataDateType, allDataList)
|
|
|
if err != nil {
|
|
@@ -1303,11 +1115,9 @@ func GetPredictDataListByPredictEdbConfList(edbInfo, sourceEdbInfoItem *EdbInfo,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //order:1升序,其余值为降序
|
|
|
if order == 1 {
|
|
|
dataList = append(tmpDataList, predictDataList...)
|
|
|
} else {
|
|
|
- // 先倒序预测数据
|
|
|
lenPredictDataList := len(predictDataList)
|
|
|
if lenPredictDataList > 0 {
|
|
|
for k := range predictDataList {
|
|
@@ -1315,19 +1125,16 @@ func GetPredictDataListByPredictEdbConfList(edbInfo, sourceEdbInfoItem *EdbInfo,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 接着倒序实际指标
|
|
|
lenDataList := len(tmpDataList)
|
|
|
for k := range tmpDataList {
|
|
|
dataList = append(dataList, tmpDataList[lenDataList-k-1])
|
|
|
}
|
|
|
}
|
|
|
if len(predictDataList) > 0 {
|
|
|
- // 如果最小值 大于 预测值,那么将预测值作为最小值数据返回
|
|
|
if edbInfo.MinValue > predictMinValue {
|
|
|
edbInfo.MinValue = predictMinValue
|
|
|
}
|
|
|
|
|
|
- // 如果最大值 小于 预测值,那么将预测值作为最大值数据返回
|
|
|
if edbInfo.MaxValue < predictMaxValue {
|
|
|
edbInfo.MaxValue = predictMaxValue
|
|
|
}
|
|
@@ -1335,7 +1142,6 @@ func GetPredictDataListByPredictEdbConfList(edbInfo, sourceEdbInfoItem *EdbInfo,
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetPredictEdbDataListAll 获取该预测指标所有的数据 ,order:1升序,其余值为降序
|
|
|
func GetPredictEdbDataListAll(edbInfo *EdbInfo, order int) (items []*EdbInfoSearchData, err error) {
|
|
|
items, err = GetEdbDataListAll(edbInfo.Source, edbInfo.SubSource, FindEdbDataListAllCond{
|
|
|
EdbInfoId: edbInfo.EdbInfoId,
|
|
@@ -1344,7 +1150,6 @@ func GetPredictEdbDataListAll(edbInfo *EdbInfo, order int) (items []*EdbInfoSear
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetPredictEdbDataListAllByStartDate 根据开始日期获取该预测指标所有的数据 ,order:1升序,其余值为降序
|
|
|
func GetPredictEdbDataListAllByStartDate(edbInfo *EdbInfo, order int, startDate string) (items []*EdbInfoSearchData, err error) {
|
|
|
items, err = GetEdbDataListAll(edbInfo.Source, edbInfo.SubSource, FindEdbDataListAllCond{
|
|
|
EdbInfoId: edbInfo.EdbInfoId,
|
|
@@ -1355,7 +1160,6 @@ func GetPredictEdbDataListAllByStartDate(edbInfo *EdbInfo, order int, startDate
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// ModifyPredictEdbInfoMaxAndMinInfo 修改预测指标的最新数据信息
|
|
|
func ModifyPredictEdbInfoMaxAndMinInfo(edbInfoId int, item *EdbInfoMaxAndMinInfo) (err error) {
|
|
|
|
|
|
sql := ` UPDATE edb_info SET start_date=?,end_date=?,min_value=?,max_value=?,is_update=2,latest_date=?,latest_value=?,end_value=?,modify_time=NOW() WHERE edb_info_id=? `
|
|
@@ -1378,13 +1182,11 @@ func GetEdbInfoItemByCondition(condition string, pars []interface{}) (item *EdbI
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// EdbInfoDetailReq 指标详情请求
|
|
|
type EdbInfoDetailReq struct {
|
|
|
UniqueCode string `description:"指标唯一编码"`
|
|
|
EdbCode string `description:"指标编码"`
|
|
|
}
|
|
|
|
|
|
-// EdbInfoDetailResp 指标详情返回
|
|
|
type EdbInfoDetailResp struct {
|
|
|
SourceName string `description:"来源名称"`
|
|
|
EdbCode string `description:"指标编码"`
|
|
@@ -1421,26 +1223,22 @@ type AddEdbInfoParams struct {
|
|
|
|
|
|
func ModifyEdbInfoBaseTimeById(edbInfoId int, cTime time.Time) (err error) {
|
|
|
|
|
|
- // 更新修改时间
|
|
|
sql := ` UPDATE edb_info SET base_modify_time = ? WHERE edb_info_id = ? `
|
|
|
err = global.DEFAULT_DmSQL.Exec(sql, cTime, edbInfoId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// EdbInfoRefreshCheckReq 指标数据更新情况查询
|
|
|
type EdbInfoRefreshCheckReq struct {
|
|
|
Source int `description:"来源id"`
|
|
|
LatestDate string `description:"数据最新日期"`
|
|
|
FrequencyBatch string `description:"更新频度"`
|
|
|
}
|
|
|
|
|
|
-// EdbInfoRefreshCheckResp 指标数据更新情况查询
|
|
|
type EdbInfoRefreshCheckResp struct {
|
|
|
UpdateNum int `description:"已更新指标数"`
|
|
|
UnUpdateNum int `description:"未更新指标数"`
|
|
|
}
|
|
|
|
|
|
-// ResetEdbClassifyReq 指标重新分类请求体
|
|
|
type ResetEdbClassifyReq struct {
|
|
|
IndexCode string `description:"指标编码"`
|
|
|
ClassifyFirst string `description:"一级分类名称"`
|
|
@@ -1448,7 +1246,6 @@ type ResetEdbClassifyReq struct {
|
|
|
ClassifyThird string `description:"三级分类名称"`
|
|
|
}
|
|
|
|
|
|
-// GetEdbInfoMaxSortByClassifyId 获取分类下指标的最大的排序数
|
|
|
func GetEdbInfoMaxSortByClassifyId(classifyId int) (sort int, err error) {
|
|
|
|
|
|
sql := `SELECT COALESCE(MAX(sort), 0) as sort FROM edb_info WHERE classify_id=? `
|
|
@@ -1457,7 +1254,6 @@ func GetEdbInfoMaxSortByClassifyId(classifyId int) (sort int, err error) {
|
|
|
}
|
|
|
|
|
|
func GetEdbAndClassifyMaxSort(parentId int, classifyType uint8) (maxSort int, err error) {
|
|
|
- //获取该层级下最大的排序数
|
|
|
classifyMaxSort, err := GetEdbClassifyMaxSort(parentId, classifyType)
|
|
|
if err != nil {
|
|
|
return
|
|
@@ -1473,12 +1269,10 @@ func GetEdbAndClassifyMaxSort(parentId int, classifyType uint8) (maxSort int, er
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// CalculateEdbExtra 指标运算额外配置
|
|
|
type CalculateEdbExtra struct {
|
|
|
DateTag string `description:"时间序列的生成方式,all 表示所选指标的时间序列并集"`
|
|
|
}
|
|
|
|
|
|
-// CalculateLjzEdbExtra 累计值额外配置
|
|
|
type CalculateLjzEdbExtra struct {
|
|
|
LastValType int `description:"最新值处理:0默认、均值填充"`
|
|
|
}
|
|
@@ -1494,14 +1288,6 @@ type EdbInfoEditRecord struct {
|
|
|
OperateUserRealName string `description:"操作人姓名"`
|
|
|
}
|
|
|
|
|
|
-// GetEdbInfoByEdbCodeList
|
|
|
-// @Description: 根据来源和指标编码列表获取指标信息列表
|
|
|
-// @author: Roc
|
|
|
-// @datetime 2024-05-31 16:31:52
|
|
|
-// @param source int
|
|
|
-// @param edbCodeList []string
|
|
|
-// @return items []*EdbInfo
|
|
|
-// @return err error
|
|
|
func GetEdbInfoByEdbCodeList(source int, edbCodeList []string) (items []*EdbInfo, err error) {
|
|
|
num := len(edbCodeList)
|
|
|
if num <= 0 {
|
|
@@ -1514,13 +1300,6 @@ func GetEdbInfoByEdbCodeList(source int, edbCodeList []string) (items []*EdbInfo
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// GetAddEdbMaxSortByClassifyId
|
|
|
-// @Description: 获取添加指标时,该分类下最大的排序(忽略错误信息)
|
|
|
-// @author: Roc
|
|
|
-// @datetime 2024-07-05 09:39:46
|
|
|
-// @param classifyId int
|
|
|
-// @param classifyType uint8
|
|
|
-// @return sort int
|
|
|
func GetAddEdbMaxSortByClassifyId(classifyId int, classifyType uint8) (sort int) {
|
|
|
sort, _ = GetEdbAndClassifyMaxSort(classifyId, classifyType)
|
|
|
sort = sort + 1
|
|
@@ -1528,12 +1307,10 @@ func GetAddEdbMaxSortByClassifyId(classifyId int, classifyType uint8) (sort int)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// EdbInfoExtra 指标额外数据-extra字段
|
|
|
type EdbInfoExtra struct {
|
|
|
ApiExtraPars string `description:"API-额外参数(如同花顺日期序列)"`
|
|
|
}
|
|
|
|
|
|
-// GetEdbInfoNoUpdateTotalByIdList 根据指标id列表获取指标信息
|
|
|
func GetEdbInfoNoUpdateTotalByIdList(edbInfoIdList []int) (total int, err error) {
|
|
|
num := len(edbInfoIdList)
|
|
|
if num <= 0 {
|
|
@@ -1576,9 +1353,6 @@ func (m SortEdbDataList) Swap(i, j int) {
|
|
|
m[i], m[j] = m[j], m[i]
|
|
|
}
|
|
|
|
|
|
-// ConvertDate
|
|
|
-// @Description: 格式化EdbData的日期
|
|
|
-// @receiver e
|
|
|
func (m *EdbInfoSearchDataV1) ConvertDate() {
|
|
|
m.DataTime = utils.GormDateStrToDateStr(m.DataTime)
|
|
|
|