|
@@ -17,63 +17,111 @@ import (
|
|
|
)
|
|
|
|
|
|
type EdbInfo struct {
|
|
|
- //EdbInfoId int `orm:"column(edb_info_id);pk"`
|
|
|
- EdbInfoId int `gorm:"column:edb_info_id;primaryKey"`
|
|
|
- EdbInfoType int `description:"指标类型,0:普通指标,1:预测指标"`
|
|
|
- SourceName string `description:"来源名称"`
|
|
|
- Source int `description:"来源id"`
|
|
|
- EdbCode string `description:"指标编码"`
|
|
|
- EdbName string `description:"指标名称"`
|
|
|
- EdbNameEn string `description:"英文指标名称"`
|
|
|
- EdbNameSource string `description:"指标名称来源"`
|
|
|
- Frequency string `description:"频率"`
|
|
|
- Unit string `description:"单位"`
|
|
|
- UnitEn string `description:"英文单位"`
|
|
|
- StartDate string `description:"起始日期"`
|
|
|
- EndDate string `description:"终止日期"`
|
|
|
- ClassifyId int `description:"分类id"`
|
|
|
- SysUserId int
|
|
|
- SysUserRealName string
|
|
|
- UniqueCode string `description:"指标唯一编码"`
|
|
|
- CreateTime time.Time
|
|
|
- ModifyTime time.Time
|
|
|
- BaseModifyTime time.Time
|
|
|
- MinValue float64 `description:"指标最小值"`
|
|
|
- MaxValue float64 `description:"指标最大值"`
|
|
|
- CalculateFormula string `description:"计算公式"`
|
|
|
- EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
|
|
|
- IsUpdate int `description:"当天是否已更新,1:未更新,2:已更新"`
|
|
|
- Sort int `description:"排序字段"`
|
|
|
- LatestDate string `description:"数据最新日期(实际日期)"`
|
|
|
- LatestValue float64 `description:"数据最新值(实际值)"`
|
|
|
- EndValue float64 `description:"数据的最新值(预测日期的最新值)"`
|
|
|
- MoveType int `description:"移动方式:1:领先(默认),2:滞后"`
|
|
|
- MoveFrequency string `description:"移动频度"`
|
|
|
- NoUpdate int8 `description:"是否停止更新,0:继续更新;1:停止更新"`
|
|
|
- ServerUrl string `description:"服务器地址"`
|
|
|
- ChartImage string `description:"图表图片"`
|
|
|
- Calendar string `description:"公历/农历" orm:"default(公历);"`
|
|
|
- EmptyType int `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
|
|
|
- MaxEmptyType int `description:"MAX、MIN公式空值处理类型(1、等于0;2、跳过空值)"`
|
|
|
- DataDateType string `orm:"column(data_date_type);size(255);null;default(交易日)"`
|
|
|
- ManualSave int `description:"是否有手动保存过上下限: 0-否; 1-是"`
|
|
|
- TerminalCode string `description:"终端编码,用于配置在机器上"`
|
|
|
- DataUpdateTime string `description:"最近一次数据发生变化的时间"`
|
|
|
- ErDataUpdateDate string `description:"本次更新,数据发生变化的最早日期"`
|
|
|
- SourceIndexName string `description:"数据源中的指标名称"`
|
|
|
- SubSource int `description:"子数据来源:0:经济数据库,1:日期序列"`
|
|
|
- SubSourceName string `description:"子数据来源名称"`
|
|
|
- IndicatorCode string `description:"指标代码"`
|
|
|
- StockCode string `description:"证券代码"`
|
|
|
- Extra string `description:"指标的额外配置"`
|
|
|
- IsStaticData int `description:"是否是静态指标,0否,1是"`
|
|
|
- EndDateType int `description:"预测指标截止日期类型:0:未来日期,1未来期数"`
|
|
|
+ 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 time.Time `gorm:"column:create_time" description:"创建时间"`
|
|
|
+ ModifyTime time.Time `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:"指标的额外配置"`
|
|
|
+ IsStaticData int `description:"是否是静态指标,0否,1是"`
|
|
|
+ EndDateType int `description:"预测指标截止日期类型:0:未来日期,1未来期数"`
|
|
|
}
|
|
|
|
|
|
func (e *EdbInfo) Add() (err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- //_, err = o.Insert(e)
|
|
|
- err = global.DEFAULT_DB.Create(&e).Error
|
|
|
+
|
|
|
+ err = global.DEFAULT_DB.Create(e).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)
|
|
|
+ if e != nil {
|
|
|
+ err = e
|
|
|
+ return
|
|
|
+ }
|
|
|
+ m.StartDate = minDateTmp.Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+ if m.EndDate != "" {
|
|
|
+ maxDateTmp, e := time.ParseInLocation(utils.FormatDateWallWithLoc, m.EndDate, time.Local)
|
|
|
+ if e != nil {
|
|
|
+ err = e
|
|
|
+ return
|
|
|
+ }
|
|
|
+ m.EndDate = maxDateTmp.Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+ if m.LatestDate != "" {
|
|
|
+ maxDateTmp, e := time.ParseInLocation(utils.FormatDateWallWithLoc, m.LatestDate, time.Local)
|
|
|
+ if e != nil {
|
|
|
+ err = e
|
|
|
+ return
|
|
|
+ }
|
|
|
+ m.LatestDate = maxDateTmp.Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+ if m.DataUpdateTime != "" {
|
|
|
+ maxDateTmp, e := time.ParseInLocation(utils.FormatDateWallWithLoc, m.DataUpdateTime, time.Local)
|
|
|
+ if e != nil {
|
|
|
+ err = e
|
|
|
+ return
|
|
|
+ }
|
|
|
+ m.DataUpdateTime = maxDateTmp.Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// ConvertDate
|
|
|
+// @Description: 格式化EdbInfo的日期
|
|
|
+// @receiver e
|
|
|
+func (e *EdbInfo) ConvertDate() {
|
|
|
+ e.StartDate = utils.GormDateStrToDateStr(e.StartDate)
|
|
|
+ e.EndDate = utils.GormDateStrToDateStr(e.EndDate)
|
|
|
+ e.LatestDate = utils.GormDateStrToDateStr(e.LatestDate)
|
|
|
+ e.DataUpdateTime = utils.GormDateStrToDateStr(e.DataUpdateTime)
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -91,46 +139,74 @@ func AddEdbInfo(item *EdbInfo) (lastId int64, err error) {
|
|
|
|
|
|
// EdbInfoList 指标数据列表
|
|
|
type EdbInfoList struct {
|
|
|
- EdbInfoId int `gorm:"column:edb_info_id;primaryKey"`
|
|
|
- //EdbInfoId int `orm:"column(edb_info_id);pk"`
|
|
|
- EdbInfoType int `description:"指标类型,0:普通指标,1:预测指标"`
|
|
|
- SourceName string `description:"来源名称"`
|
|
|
- Source int `description:"来源id"`
|
|
|
- EdbCode string `description:"指标编码"`
|
|
|
- EdbNameEn string `description:"英文指标名称"`
|
|
|
- EdbName string `description:"指标名称"`
|
|
|
- Frequency string `description:"频率"`
|
|
|
- FrequencyEn string `description:"英文频率"`
|
|
|
- Unit string `description:"单位"`
|
|
|
- UnitEn string `description:"英文单位"`
|
|
|
- StartDate string `description:"起始日期"`
|
|
|
- EndDate string `description:"终止日期"`
|
|
|
- LatestDate string `description:"数据最新日期(实际日期)"`
|
|
|
- LatestValue float64 `description:"数据最新值(实际值)"`
|
|
|
- EndValue float64 `description:"数据的最新值(预测日期的最新值)"`
|
|
|
- ClassifyId int `description:"分类id"`
|
|
|
- UniqueCode string `description:"指标唯一编码"`
|
|
|
- SysUserId int `description:"创建人id"`
|
|
|
- SysUserRealName string `description:"创建人姓名"`
|
|
|
- ModifyTime string `description:"最新修改时间"`
|
|
|
- CreateTime string `description:"创建时间"`
|
|
|
- EdbNameAlias string `json:"-" description:"指标名称,别名"`
|
|
|
- EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
|
|
|
- ChartImage string `description:"图表图片"`
|
|
|
- RuleType int `description:"预测规则,1:最新,2:固定值"`
|
|
|
- FixedValue float64 `description:"固定值"`
|
|
|
- DataList []*EdbData `description:"实际指标数据"`
|
|
|
- PredictDataList []*EdbData `description:"预测指标数据"`
|
|
|
- Button EdbClassifyItemsButton `description:"操作权限"`
|
|
|
- IsEnEdb bool `description:"是否展示英文标识"`
|
|
|
- DataDateType string `description:"数据日期类型,枚举值:交易日、自然日"`
|
|
|
- EmptyType int `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
|
|
|
- MaxEmptyType int `description:"MAX、MIN公式空值处理类型(1、等于0;2、跳过空值)"`
|
|
|
- SubSource int `description:"子数据来源:0:经济数据库,1:日期序列"`
|
|
|
- SubSourceName string `description:"子数据来源名称"`
|
|
|
- IndicatorCode string `description:"指标代码"`
|
|
|
- StockCode string `description:"证券代码"`
|
|
|
- NoUpdate int8 `description:"是否停止更新,0:继续更新;1:停止更新"`
|
|
|
+ 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:"公历/农历"`
|
|
|
+ EdbNameAlias string `json:"-" description:"指标名称,别名"`
|
|
|
+ //RuleType int `description:"预测规则,1:最新,2:固定值"`
|
|
|
+ //FixedValue float64 `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:"指标的额外配置"`
|
|
|
+ DataList []*EdbData `gorm:"column:-" description:"实际指标数据"`
|
|
|
+ //PredictDataList []*EdbData `description:"预测指标数据"`
|
|
|
+ //Button EdbClassifyItemsButton `description:"操作权限"`
|
|
|
+ //IsEnEdb bool `description:"是否展示英文标识"`
|
|
|
+}
|
|
|
+
|
|
|
+// ConvertDate
|
|
|
+// @Description: 格式化EdbInfoList的日期
|
|
|
+// @receiver e
|
|
|
+func (e *EdbInfoList) ConvertDate() {
|
|
|
+ e.CreateTime = utils.GormDateStrToDateTimeStr(e.CreateTime)
|
|
|
+ e.ModifyTime = utils.GormDateStrToDateTimeStr(e.ModifyTime)
|
|
|
+ e.StartDate = utils.GormDateStrToDateStr(e.StartDate)
|
|
|
+ e.EndDate = utils.GormDateStrToDateStr(e.EndDate)
|
|
|
+ e.LatestDate = utils.GormDateStrToDateStr(e.LatestDate)
|
|
|
+
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
// EdbClassifyItemsButton 操作按钮
|
|
@@ -145,37 +221,53 @@ type EdbClassifyItemsButton struct {
|
|
|
|
|
|
// GetEdbInfoByName 根据指标名称获取所有的指标数据列表
|
|
|
func GetEdbInfoByName(edbName string) (items []*EdbInfoList, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
sql := ` SELECT * FROM edb_info WHERE edb_name=? `
|
|
|
- //_, err = o.Raw(sql, edbName).QueryRows(&items)
|
|
|
- err = global.DEFAULT_DB.Raw(sql, edbName).Find(&items).Error
|
|
|
+ err = global.DEFAULT_DB.Raw(sql, edbName).Scan(&items).Error
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, edbInfoItem := range items {
|
|
|
+ // 时间转格式
|
|
|
+ edbInfoItem.ConvertDate()
|
|
|
+ }
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// ModifyEdbInfoNameSource 根据来源修改指标名称
|
|
|
func ModifyEdbInfoNameSource(edbNameSource string, edbInfoId int) (err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
+
|
|
|
sql := ` UPDATE edb_info SET edb_name_source=? WHERE edb_info_id = ? `
|
|
|
- //_, err = o.Raw(sql, edbNameSource, edbInfoId).Exec()
|
|
|
err = global.DEFAULT_DB.Exec(sql, edbNameSource, edbInfoId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetEdbInfoById 根据指标id获取指标信息
|
|
|
func GetEdbInfoById(edbInfoId int) (item *EdbInfo, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- sql := ` SELECT * FROM edb_info WHERE edb_info_id=? `
|
|
|
- //err = o.Raw(sql, edbInfoId).QueryRow(&item)
|
|
|
+ sql := ` SELECT * FROM edb_info WHERE edb_info_id = ? `
|
|
|
err = global.DEFAULT_DB.Raw(sql, edbInfoId).First(&item).Error
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 格式化日期
|
|
|
+ item.ConvertDate()
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetEdbInfoByUniqueCode 根据指标唯一编码获取指标信息
|
|
|
func GetEdbInfoByUniqueCode(uniqueCode string) (item *EdbInfo, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
+
|
|
|
sql := ` SELECT * FROM edb_info WHERE unique_code=? `
|
|
|
- //err = o.Raw(sql, uniqueCode).QueryRow(&item)
|
|
|
err = global.DEFAULT_DB.Raw(sql, uniqueCode).First(&item).Error
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 格式化日期
|
|
|
+ item.ConvertDate()
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -185,11 +277,13 @@ func GetEdbInfoByIdList(edbInfoIdList []int) (items []*EdbInfo, err error) {
|
|
|
if num <= 0 {
|
|
|
return
|
|
|
}
|
|
|
- //o := orm.NewOrm()
|
|
|
- //sql := ` SELECT * FROM edb_info WHERE edb_info_id in (` + utils.GetOrmInReplace(num) + `) `
|
|
|
- //_, err = o.Raw(sql, edbInfoIdList).QueryRows(&items)
|
|
|
- sql := ` SELECT * FROM edb_info WHERE edb_info_id in ? `
|
|
|
- err = global.DEFAULT_DB.Raw(sql, edbInfoIdList).Find(&items).Error
|
|
|
+
|
|
|
+ sql := ` SELECT * FROM edb_info WHERE edb_info_id in (` + utils.GetOrmInReplace(num) + `) `
|
|
|
+ err = global.DEFAULT_DB.Raw(sql, edbInfoIdList).Scan(&items).Error
|
|
|
+ // 日期格式转换
|
|
|
+ for _, v := range items {
|
|
|
+ v.ConvertDate()
|
|
|
+ }
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -208,13 +302,13 @@ func GetEdbInfoListByIds(edbInfoIdList []int) (items []*EdbInfoList, err error)
|
|
|
|
|
|
// Update 更新EdbInfo信息
|
|
|
func (edbInfo *EdbInfo) Update(cols []string) (err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- //_, err = o.Update(edbInfo, cols...)
|
|
|
- err = global.DEFAULT_DB.Model(&edbInfo).Select(cols).Updates(&edbInfo).Error
|
|
|
+
|
|
|
+ err = global.DEFAULT_DB.Model(edbInfo).Select(cols).Updates(edbInfo).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// EdbInfoSearchData
|
|
|
+// @Description: 指标数据
|
|
|
type EdbInfoSearchData struct {
|
|
|
EdbDataId int `description:"数据ID"`
|
|
|
EdbInfoId int `description:"指标ID"`
|
|
@@ -224,6 +318,15 @@ type EdbInfoSearchData struct {
|
|
|
DataTimestamp int64 `description:"时间戳"`
|
|
|
}
|
|
|
|
|
|
+// ConvertTimeStr
|
|
|
+// @Description: 转成需要输出的格式
|
|
|
+// @receiver m
|
|
|
+func (m *EdbInfoSearchData) ConvertTimeStr() {
|
|
|
+ m.DataTime = utils.GormDateStrToDateStr(m.DataTime)
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
type FindEdbDataListAllCond struct {
|
|
|
EdbInfoId int
|
|
|
StartDataTime string
|
|
@@ -258,14 +361,13 @@ func GetEdbDataListAll(source, subSource int, findEdbDataListAllCond FindEdbData
|
|
|
// @param subSource int
|
|
|
// @param findEdbDataListAllCond FindEdbDataListAllCond
|
|
|
// @param order int
|
|
|
-// @return item []*EdbInfoSearchData
|
|
|
+// @return items []*EdbInfoSearchData
|
|
|
// @return err error
|
|
|
-func GetEdbDataListAllByMysql(source, subSource int, findEdbDataListAllCond FindEdbDataListAllCond, order int) (item []*EdbInfoSearchData, err error) {
|
|
|
+func GetEdbDataListAllByMysql(source, subSource int, findEdbDataListAllCond FindEdbDataListAllCond, order int) (items []*EdbInfoSearchData, err error) {
|
|
|
if findEdbDataListAllCond.EdbInfoId <= 0 {
|
|
|
return
|
|
|
}
|
|
|
- //to := orm.NewOrm()
|
|
|
- to := global.DEFAULT_DB.Begin()
|
|
|
+
|
|
|
sql := ``
|
|
|
tableName := GetEdbDataTableName(source, subSource)
|
|
|
sql = ` SELECT * FROM %s WHERE 1=1 `
|
|
@@ -295,8 +397,16 @@ func GetEdbDataListAllByMysql(source, subSource int, findEdbDataListAllCond Find
|
|
|
} else {
|
|
|
sql += ` ORDER BY data_time DESC `
|
|
|
}
|
|
|
- //_, err = to.Raw(sql, pars).QueryRows(&item)
|
|
|
- err = to.Raw(sql, pars...).Find(&item).Error
|
|
|
+ // todo
|
|
|
+ err = global.DEFAULT_DB.Raw(sql, pars...).Scan(&items).Error
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 统一处理日期
|
|
|
+ for _, v := range items {
|
|
|
+ v.ConvertTimeStr()
|
|
|
+ }
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -304,7 +414,7 @@ func GetEdbDataListAllByMysql(source, subSource int, findEdbDataListAllCond Find
|
|
|
// @Description: 根据事务链接获取指标数据列表 order:1升序,其余值为降序
|
|
|
// @author: Roc
|
|
|
// @datetime 2024-05-08 15:34:06
|
|
|
-// @param to orm.TxOrmer
|
|
|
+// @param to *gorm.DB
|
|
|
// @param source int
|
|
|
// @param subSource int
|
|
|
// @param findEdbDataListAllCond FindEdbDataListAllCond
|
|
@@ -323,14 +433,14 @@ func GetEdbDataListAllByTo(to *gorm.DB, source, subSource int, findEdbDataListAl
|
|
|
// @Description: 根据事务链接获取指标数据列表 order:1升序,其余值为降序(Mysql)
|
|
|
// @author: Roc
|
|
|
// @datetime 2024-05-08 15:34:13
|
|
|
-// @param to orm.TxOrmer
|
|
|
+// @param to *gorm.DB
|
|
|
// @param source int
|
|
|
// @param subSource int
|
|
|
// @param findEdbDataListAllCond FindEdbDataListAllCond
|
|
|
// @param order int
|
|
|
-// @return item []*EdbInfoSearchData
|
|
|
+// @return items []*EdbInfoSearchData
|
|
|
// @return err error
|
|
|
-func GetEdbDataListAllByMysqlTo(to *gorm.DB, source, subSource int, findEdbDataListAllCond FindEdbDataListAllCond, order int) (item []*EdbInfoSearchData, err error) {
|
|
|
+func GetEdbDataListAllByMysqlTo(to *gorm.DB, source, subSource int, findEdbDataListAllCond FindEdbDataListAllCond, order int) (items []*EdbInfoSearchData, err error) {
|
|
|
if findEdbDataListAllCond.EdbInfoId <= 0 {
|
|
|
return
|
|
|
}
|
|
@@ -363,9 +473,15 @@ func GetEdbDataListAllByMysqlTo(to *gorm.DB, source, subSource int, findEdbDataL
|
|
|
} else {
|
|
|
sql += ` ORDER BY data_time DESC `
|
|
|
}
|
|
|
- //_, err = to.Raw(sql, pars).QueryRows(&item)
|
|
|
- //err = to.Raw(sql, pars...).Find(&item).Error
|
|
|
- err = to.Raw(sql, pars...).Find(&item).Error
|
|
|
+ err = to.Raw(sql, pars...).Scan(&items).Error
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 统一处理日期
|
|
|
+ for _, v := range items {
|
|
|
+ v.ConvertTimeStr()
|
|
|
+ }
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -428,25 +544,56 @@ type EdbInfoMaxAndMinInfo struct {
|
|
|
MaxDate string `description:"最大日期" bson:"max_date"`
|
|
|
MinValue float64 `description:"最小值" bson:"min_value"`
|
|
|
MaxValue float64 `description:"最大值" bson:"max_value"`
|
|
|
- LatestValue float64 `description:"最新值" bson:"latest_value"`
|
|
|
- LatestDate string `description:"实际数据最新日期" bson:"latest_date"`
|
|
|
+ LatestValue float64 `gorm:"-" description:"最新值" bson:"latest_value"`
|
|
|
+ LatestDate string `gorm:"-" description:"实际数据最新日期" bson:"latest_date"`
|
|
|
EndValue float64 `description:"最新值" bson:"end_value"`
|
|
|
IndexCode string `description:"指标编码" bson:"index_code"`
|
|
|
}
|
|
|
|
|
|
+// 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)
|
|
|
+ if e != nil {
|
|
|
+ err = e
|
|
|
+ return
|
|
|
+ }
|
|
|
+ m.MinDate = minDateTmp.Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+ if m.MaxDate != "" {
|
|
|
+ maxDateTmp, e := time.ParseInLocation(utils.FormatDateWallWithLoc, m.MaxDate, time.Local)
|
|
|
+ if e != nil {
|
|
|
+ err = e
|
|
|
+ return
|
|
|
+ }
|
|
|
+ m.MaxDate = maxDateTmp.Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// EdbInfoMaxAndMinInfoTmp 指标最新数据记录结构体
|
|
|
+type EdbInfoMaxAndMinInfoTmp struct {
|
|
|
+ MinDate time.Time `description:"最小日期" bson:"min_date"`
|
|
|
+ MaxDate time.Time `description:"最大日期" bson:"max_date"`
|
|
|
+ MinValue float64 `description:"最小值" bson:"min_value"`
|
|
|
+ MaxValue float64 `description:"最大值" bson:"max_value"`
|
|
|
+ LatestValue float64 `gorm:"-" description:"最新值" bson:"latest_value"`
|
|
|
+ LatestDate time.Time `gorm:"-" description:"实际数据最新日期" bson:"latest_date"`
|
|
|
+ EndValue float64 `description:"最新值" bson:"end_value"`
|
|
|
+}
|
|
|
+
|
|
|
// GetEdbInfoMaxAndMinInfo 获取指标的最新数据记录信息
|
|
|
func GetEdbInfoMaxAndMinInfo(source, subSource int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
sql := ``
|
|
|
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)
|
|
|
err = global.DEFAULT_DB.Raw(sql, edbCode).First(&item).Error
|
|
|
+
|
|
|
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)
|
|
|
- //err = o.Raw(sql, edbCode).QueryRow(&latest_value)
|
|
|
+ // todo 测试查询单个字段
|
|
|
err = global.DEFAULT_DB.Raw(sql, edbCode).Scan(&latest_value).Error
|
|
|
item.LatestValue = latest_value
|
|
|
return
|
|
@@ -456,42 +603,51 @@ type EdbIndoDataUpdateTime struct {
|
|
|
MinDate string `description:"本次更新,数据发生变化的最早日期"`
|
|
|
}
|
|
|
|
|
|
+// AfterFind 在该模型上设置钩子函数,把日期转成正确的string,所以查询函数只能用Find函数,First或者Scan是不会触发该函数的来获取数据
|
|
|
+func (m *EdbIndoDataUpdateTime) AfterFind(db *gorm.DB) (err error) {
|
|
|
+ if m.MinDate == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ minDateTmp, err := time.ParseInLocation(utils.FormatDateWallWithLoc, m.MinDate, time.Local)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ m.MinDate = minDateTmp.Format(utils.FormatDate)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// GetEdbDataUpdateTimeByModify 获取指标的刷新时间获取最早的一条记录
|
|
|
func GetEdbDataUpdateTimeByModify(source, subSource int, edbCode string, dataUpdateTime string) (item *EdbIndoDataUpdateTime, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
sql := ``
|
|
|
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)
|
|
|
err = global.DEFAULT_DB.Raw(sql, edbCode, dataUpdateTime).First(&item).Error
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// ModifyEdbInfoMaxAndMinInfo 修改指标的最新数据信息
|
|
|
func ModifyEdbInfoMaxAndMinInfo(edbInfoId int, item *EdbInfoMaxAndMinInfo) (err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
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 = o.Raw(sql, item.MinDate, item.MaxDate, item.MinValue, item.MaxValue, item.MaxDate, item.LatestValue, item.LatestValue, edbInfoId).Exec()
|
|
|
err = global.DEFAULT_DB.Exec(sql, item.MinDate, item.MaxDate, item.MinValue, item.MaxValue, item.MaxDate, item.LatestValue, item.LatestValue, edbInfoId).Error
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// ModifyEdbTimeAndLastInfo 修改指标的最新数据信息(除上下限)
|
|
|
func ModifyEdbTimeAndLastInfo(edbInfoId int, item *EdbInfoMaxAndMinInfo) (err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
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 = o.Raw(sql, item.MinDate, item.MaxDate, item.MaxDate, item.LatestValue, item.LatestValue, edbInfoId).Exec()
|
|
|
err = global.DEFAULT_DB.Exec(sql, item.MinDate, item.MaxDate, item.MaxDate, item.LatestValue, item.LatestValue, edbInfoId).Error
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// ModifyEdbDataUpdateTime 修改指标刷新,本次数据刷新的最早日期
|
|
|
func ModifyEdbDataUpdateTime(edbInfoId int, dataUpdateTime, erDataUpdateDate string) (err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
sql := `UPDATE edb_info SET data_update_time = ?, er_data_update_date = ?, modify_time = NOW() WHERE edb_info_id = ?`
|
|
|
- //_, err = o.Raw(sql, dataUpdateTime, erDataUpdateDate, edbInfoId).Exec()
|
|
|
err = global.DEFAULT_DB.Exec(sql, dataUpdateTime, erDataUpdateDate, edbInfoId).Error
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -549,19 +705,16 @@ func GetLteZeroEdbDataCountByMongo(source, subSource, edbInfoId int) (count int,
|
|
|
// @return count int
|
|
|
// @return err error
|
|
|
func GetLteZeroEdbDataCountByMysql(source, subSource, edbInfoId int) (count int, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
sql := ``
|
|
|
tableName := GetEdbDataTableName(source, subSource)
|
|
|
sql = ` SELECT COUNT(1) AS count FROM %s WHERE 1=1 AND edb_info_id =? AND value <=0 `
|
|
|
sql = fmt.Sprintf(sql, tableName)
|
|
|
- //err = o.Raw(sql, edbInfoId).QueryRow(&count)
|
|
|
err = global.DEFAULT_DB.Raw(sql, edbInfoId).Scan(&count).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetLastEdbData 获取最近的一条指标数据
|
|
|
func GetLastEdbData(condition string, pars []interface{}, source, subSource int) (item *EdbInfoSearchData, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
sql := ``
|
|
|
tableName := GetEdbDataTableName(source, subSource)
|
|
|
sql = ` SELECT * FROM %s WHERE 1=1 `
|
|
@@ -571,19 +724,20 @@ func GetLastEdbData(condition string, pars []interface{}, source, subSource int)
|
|
|
sql += condition
|
|
|
}
|
|
|
sql += ` ORDER BY data_time DESC `
|
|
|
- //err = o.Raw(sql, pars).QueryRow(&item)
|
|
|
err = global.DEFAULT_DB.Raw(sql, pars...).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetEdbInfoByEdbCode 根据指标code获取指标信息
|
|
|
func GetEdbInfoByEdbCode(source int, edbCode string) (item *EdbInfo, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
sql := ` SELECT * FROM edb_info WHERE source=? AND edb_code=? `
|
|
|
- //err = o.Raw(sql, source, edbCode).QueryRow(&item)
|
|
|
err = global.DEFAULT_DB.Raw(sql, source, edbCode).First(&item).Error
|
|
|
- if utils.IsErrNoRow(err) {
|
|
|
+
|
|
|
+ if errors.Is(err, orm.ErrNoRows) {
|
|
|
err = nil
|
|
|
+ } else {
|
|
|
+ // 格式化日期
|
|
|
+ item.ConvertDate()
|
|
|
}
|
|
|
|
|
|
return
|
|
@@ -591,36 +745,37 @@ func GetEdbInfoByEdbCode(source int, edbCode string) (item *EdbInfo, err error)
|
|
|
|
|
|
// GetEdbInfoOnlyByEdbCode 仅根据指标code获取指标信息
|
|
|
func GetEdbInfoOnlyByEdbCode(edbCode string) (item *EdbInfo, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
sql := ` SELECT * FROM edb_info WHERE edb_code=? `
|
|
|
- //err = o.Raw(sql, edbCode).QueryRow(&item)
|
|
|
err = global.DEFAULT_DB.Raw(sql, edbCode).First(&item).Error
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 格式化日期
|
|
|
+ item.ConvertDate()
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetEdbInfoCalculateListByCondition 获取指标关系列表
|
|
|
func GetEdbInfoCalculateListByCondition(condition string, pars []interface{}) (items []*EdbInfoCalculateMapping, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
-
|
|
|
sql := ` SELECT * FROM edb_info_calculate_mapping WHERE 1=1 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
- err = global.DEFAULT_DB.Raw(sql, pars...).Find(&items).Error
|
|
|
- //_, err = o.Raw(sql, pars).QueryRows(&items)
|
|
|
+ err = global.DEFAULT_DB.Raw(sql, pars...).Scan(&items).Error
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetEdbInfoCalculateCountByCondition 获取关联指标数量
|
|
|
func GetEdbInfoCalculateCountByCondition(condition string, pars []interface{}) (count int, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
-
|
|
|
sql := ` SELECT COUNT(1) AS count FROM edb_info_calculate_mapping WHERE 1=1 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
- //err = o.Raw(sql, pars).QueryRow(&count)
|
|
|
err = global.DEFAULT_DB.Raw(sql, pars...).Scan(&count).Error
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -631,9 +786,8 @@ type EdbInfoSearchDataV1 struct {
|
|
|
Value string `description:"数据"`
|
|
|
}
|
|
|
|
|
|
-// 优化版本-处理数据精度问题
|
|
|
-func GetEdbDataListAllV1(condition string, pars []interface{}, source, subSource, order int) (item []*EdbInfoSearchDataV1, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
+// GetEdbDataListAllV1ByTo 通过事务链接获取数据列表
|
|
|
+func GetEdbDataListAllV1ByTo(to *gorm.DB, condition string, pars []interface{}, source, subSource, order int) (items []*EdbInfoSearchDataV1, err error) {
|
|
|
sql := ``
|
|
|
tableName := GetEdbDataTableName(source, subSource)
|
|
|
sql = ` SELECT * FROM %s WHERE 1=1 `
|
|
@@ -647,28 +801,16 @@ func GetEdbDataListAllV1(condition string, pars []interface{}, source, subSource
|
|
|
} else {
|
|
|
sql += ` ORDER BY data_time DESC `
|
|
|
}
|
|
|
- //_, err = o.Raw(sql, pars).QueryRows(&item)
|
|
|
- err = global.DEFAULT_DB.Raw(sql, pars...).Find(&item).Error
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-// GetEdbDataListAllV1ByTo 通过事务链接获取数据列表
|
|
|
-func GetEdbDataListAllV1ByTo(to *gorm.DB, condition string, pars []interface{}, source, subSource, order int) (item []*EdbInfoSearchDataV1, err error) {
|
|
|
- sql := ``
|
|
|
- tableName := GetEdbDataTableName(source, subSource)
|
|
|
- sql = ` SELECT * FROM %s WHERE 1=1 `
|
|
|
- sql = fmt.Sprintf(sql, tableName)
|
|
|
-
|
|
|
- if condition != "" {
|
|
|
- sql += condition
|
|
|
+ err = to.Raw(sql, pars...).Scan(&items).Error
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
}
|
|
|
- if order == 1 {
|
|
|
- sql += ` ORDER BY data_time ASC `
|
|
|
- } else {
|
|
|
- sql += ` ORDER BY data_time DESC `
|
|
|
+
|
|
|
+ // 日期格式化
|
|
|
+ for _, item := range items {
|
|
|
+ item.ConvertDate()
|
|
|
}
|
|
|
- //_, err = to.Raw(sql, pars).QueryRows(&item)
|
|
|
- err = to.Raw(sql, pars...).Find(&item).Error
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -726,7 +868,6 @@ func UnifiedModifyEdbInfoMaxAndMinInfo(edbInfo *EdbInfo) (err error, errMsg stri
|
|
|
// 刷新关联的预测指标
|
|
|
go RefreshPredictStandardBaseByGeneralEdbInfoId(edbInfo.EdbInfoId)
|
|
|
|
|
|
- //go ModifyPredictEdbInfoMaxAndMinInfoBySourceEdbInfoId(edbInfo.EdbInfoId, maxAndMinItem)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -739,7 +880,7 @@ func UnifiedModifyEdbInfoMaxAndMinInfoDataUpdate(edbInfo *EdbInfo, dataUpdateTim
|
|
|
// 获取本次刷新,指标数据更新的最早日期
|
|
|
erDataUpdateTime, tErr := GetEdbDataUpdateTimeByModify(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbCode, dataUpdateTime)
|
|
|
if tErr != nil {
|
|
|
- if !utils.IsErrNoRow(tErr) { //本次刷新指标数据无变化
|
|
|
+ if tErr.Error() != utils.ErrNoRow() { //本次刷新指标数据无变化
|
|
|
errMsg = "刷新指标失败!"
|
|
|
err = errors.New("查询指标刷新,数据更新的最早日期失败,err:" + tErr.Error())
|
|
|
return
|
|
@@ -1345,47 +1486,24 @@ func GetPredictEdbDataListAllByStartDate(edbInfo *EdbInfo, order int, startDate
|
|
|
|
|
|
// ModifyPredictEdbInfoMaxAndMinInfo 修改预测指标的最新数据信息
|
|
|
func ModifyPredictEdbInfoMaxAndMinInfo(edbInfoId int, item *EdbInfoMaxAndMinInfo) (err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
+
|
|
|
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 = o.Raw(sql, item.MinDate, item.MaxDate, item.MinValue, item.MaxValue, item.LatestDate, item.LatestValue, item.EndValue, edbInfoId).Exec()
|
|
|
err = global.DEFAULT_DB.Exec(sql, item.MinDate, item.MaxDate, item.MinValue, item.MaxValue, item.LatestDate, item.LatestValue, item.EndValue, edbInfoId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// ModifyCalculateEdbInfo 修改计算指标信息
|
|
|
-func ModifyCalculateEdbInfo(edbName, frequency, unit, calculateFormula string, classifyId, edbInfoId int) (err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- sql := ` UPDATE edb_info
|
|
|
- SET
|
|
|
- edb_name =?,
|
|
|
- edb_name_source =?,
|
|
|
- frequency = ?,
|
|
|
- unit = ?,
|
|
|
- classify_id = ?,
|
|
|
- calculate_formula=?,
|
|
|
- modify_time = NOW()
|
|
|
- WHERE edb_info_id = ?`
|
|
|
- //_, err = o.Raw(sql, edbName, edbName, frequency, unit, classifyId, calculateFormula, edbInfoId).Exec()
|
|
|
- err = global.DEFAULT_DB.Exec(sql, edbName, edbName, frequency, unit, classifyId, calculateFormula, edbInfoId).Error
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
func GetEdbInfoItemByCondition(condition string, pars []interface{}) (item *EdbInfoList, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
sql := ` SELECT * FROM edb_info WHERE 1=1 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
- //err = o.Raw(sql, pars).QueryRow(&item)
|
|
|
- err = global.DEFAULT_DB.Raw(sql, pars...).Find(&item).Error
|
|
|
- return
|
|
|
-}
|
|
|
+ err = global.DEFAULT_DB.Raw(sql, pars...).First(&item).Error
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ item.ConvertDate()
|
|
|
|
|
|
-func GetEdbInfoItemListByCondition() (items []*EdbInfoList, err error) {
|
|
|
- //o := orm.NewOrm()
|
|
|
- sql := ` SELECT * FROM edb_info WHERE 1=1 `
|
|
|
- //_, err = o.Raw(sql).QueryRows(&items)
|
|
|
- err = global.DEFAULT_DB.Raw(sql).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -1756,3 +1874,12 @@ func ModifyEdbInfoDataStatus(edbInfoId int64, source, subSource int, edbCode str
|
|
|
err = global.DEFAULT_DB.Exec(sql, edbInfoId, edbCode).Error
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// ConvertDate
|
|
|
+// @Description: 格式化EdbData的日期
|
|
|
+// @receiver e
|
|
|
+func (m *EdbInfoSearchDataV1) ConvertDate() {
|
|
|
+ m.DataTime = utils.GormDateStrToDateStr(m.DataTime)
|
|
|
+
|
|
|
+ return
|
|
|
+}
|