|
@@ -3,6 +3,7 @@ package models
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
"errors"
|
|
|
+ "eta_gn/eta_index_lib/global"
|
|
|
"eta_gn/eta_index_lib/models/mgo"
|
|
|
"eta_gn/eta_index_lib/utils"
|
|
|
"fmt"
|
|
@@ -17,110 +18,128 @@ import (
|
|
|
)
|
|
|
|
|
|
type EdbInfo struct {
|
|
|
- EdbInfoId int `orm:"column(edb_info_id);pk"`
|
|
|
- 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:"指标的额外配置"`
|
|
|
+ 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:"指标的额外配置"`
|
|
|
}
|
|
|
|
|
|
func (e *EdbInfo) Add() (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
- _, err = o.Insert(e)
|
|
|
+
|
|
|
+ err = global.DEFAULT_DmSQL.Create(e).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// AddEdbInfo 添加指标
|
|
|
func AddEdbInfo(item *EdbInfo) (lastId int64, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
- lastId, err = o.Insert(item)
|
|
|
+
|
|
|
+ err = global.DEFAULT_DmSQL.Create(item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// EdbInfoList 指标数据列表
|
|
|
type EdbInfoList struct {
|
|
|
- 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 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:"指标的额外配置"`
|
|
|
}
|
|
|
|
|
|
// EdbClassifyItemsButton 操作按钮
|
|
@@ -135,33 +154,33 @@ 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_DmSQL.Raw(sql, edbName).Scan(&items).Error
|
|
|
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_DmSQL.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)
|
|
|
+ err = global.DEFAULT_DmSQL.Raw(sql, edbInfoId).First(&item).Error
|
|
|
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_DmSQL.Raw(sql, uniqueCode).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -171,16 +190,16 @@ 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)
|
|
|
+ err = global.DEFAULT_DmSQL.Raw(sql, edbInfoIdList).Scan(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// Update 更新EdbInfo信息
|
|
|
func (edbInfo *EdbInfo) Update(cols []string) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
- _, err = o.Update(edbInfo, cols...)
|
|
|
+
|
|
|
+ err = global.DEFAULT_DmSQL.Model(edbInfo).Select(cols).Updates(edbInfo).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -234,7 +253,6 @@ func GetEdbDataListAllByMysql(source, subSource int, findEdbDataListAllCond Find
|
|
|
if findEdbDataListAllCond.EdbInfoId <= 0 {
|
|
|
return
|
|
|
}
|
|
|
- to := orm.NewOrm()
|
|
|
|
|
|
sql := ``
|
|
|
tableName := GetEdbDataTableName(source, subSource)
|
|
@@ -265,7 +283,8 @@ func GetEdbDataListAllByMysql(source, subSource int, findEdbDataListAllCond Find
|
|
|
} else {
|
|
|
sql += ` ORDER BY data_time DESC `
|
|
|
}
|
|
|
- _, err = to.Raw(sql, pars).QueryRows(&item)
|
|
|
+ // todo
|
|
|
+ err = global.DEFAULT_DmSQL.Raw(sql, pars).Scan(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -402,17 +421,18 @@ type EdbInfoMaxAndMinInfo struct {
|
|
|
|
|
|
// 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_DmSQL.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_DmSQL.Raw(sql, edbCode).Scan(&latest_value).Error
|
|
|
item.LatestValue = latest_value
|
|
|
return
|
|
|
}
|
|
@@ -423,36 +443,36 @@ type EdbIndoDataUpdateTime struct {
|
|
|
|
|
|
// 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_DmSQL.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_DmSQL.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_DmSQL.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_DmSQL.Exec(sql, dataUpdateTime, erDataUpdateDate, edbInfoId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -510,18 +530,18 @@ 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_DmSQL.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 `
|
|
@@ -531,15 +551,15 @@ 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_DmSQL.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_DmSQL.Raw(sql, source, edbCode).First(&item).Error
|
|
|
|
|
|
if errors.Is(err, orm.ErrNoRows) {
|
|
|
err = nil
|
|
@@ -550,33 +570,31 @@ 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_DmSQL.Raw(sql, edbCode).First(&item).Error
|
|
|
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 = o.Raw(sql, pars).QueryRows(&items)
|
|
|
+ err = global.DEFAULT_DmSQL.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_DmSQL.Raw(sql, pars).Scan(&count).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -589,7 +607,7 @@ type EdbInfoSearchDataV1 struct {
|
|
|
|
|
|
// 优化版本-处理数据精度问题
|
|
|
func GetEdbDataListAllV1(condition string, pars []interface{}, source, subSource, order int) (item []*EdbInfoSearchDataV1, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+
|
|
|
sql := ``
|
|
|
tableName := GetEdbDataTableName(source, subSource)
|
|
|
sql = ` SELECT * FROM %s WHERE 1=1 `
|
|
@@ -603,7 +621,7 @@ 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_DmSQL.Raw(sql, pars).Scan(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -628,7 +646,7 @@ func GetEdbDataListAllV1ByTo(to *gorm.DB, condition string, pars []interface{},
|
|
|
|
|
|
// GetEdbInfoByCondition 获取指标列表
|
|
|
func GetEdbInfoByCondition(condition string, pars []interface{}, order int) (item []*EdbInfo, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+
|
|
|
sql := ` SELECT * FROM edb_info WHERE 1=1 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
@@ -638,7 +656,7 @@ func GetEdbInfoByCondition(condition string, pars []interface{}, order int) (ite
|
|
|
} else {
|
|
|
sql += ` ORDER BY edb_info_id ASC `
|
|
|
}
|
|
|
- _, err = o.Raw(sql, pars).QueryRows(&item)
|
|
|
+ err = global.DEFAULT_DmSQL.Raw(sql, pars).Scan(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -1220,15 +1238,15 @@ 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_DmSQL.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 =?,
|
|
@@ -1239,24 +1257,24 @@ func ModifyCalculateEdbInfo(edbName, frequency, unit, calculateFormula string, c
|
|
|
calculate_formula=?,
|
|
|
modify_time = NOW()
|
|
|
WHERE edb_info_id = ?`
|
|
|
- _, err = o.Raw(sql, edbName, edbName, frequency, unit, classifyId, calculateFormula, edbInfoId).Exec()
|
|
|
+ err = global.DEFAULT_DmSQL.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_DmSQL.Raw(sql, pars).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
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_DmSQL.Raw(sql).Scan(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -1321,8 +1339,8 @@ func EdbInfoAdd(req *AddEdbInfoParams, serverUrl string, sysUserId int, sysUserR
|
|
|
|
|
|
if len(items) > 0 {
|
|
|
sql := ` UPDATE edb_info SET classify_id=?,modify_time=NOW() WHERE edb_code=? `
|
|
|
- o := orm.NewOrm()
|
|
|
- _, err = o.Raw(sql, req.ClassifyId, req.EdbCode).Exec()
|
|
|
+
|
|
|
+ err = global.DEFAULT_DmSQL.Exec(sql, req.ClassifyId, req.EdbCode).Error
|
|
|
if err != nil {
|
|
|
err = errors.New("更新指标分类信息失败,Err:" + err.Error())
|
|
|
return
|
|
@@ -1440,10 +1458,10 @@ func EdbInfoAdd(req *AddEdbInfoParams, serverUrl string, sysUserId int, sysUserR
|
|
|
}
|
|
|
|
|
|
func ModifyEdbInfoBaseTimeById(edbInfoId int, cTime time.Time) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+
|
|
|
// 更新修改时间
|
|
|
sql := ` UPDATE edb_info SET base_modify_time = ? WHERE edb_info_id = ? `
|
|
|
- _, err = o.Raw(sql, cTime, edbInfoId).Exec()
|
|
|
+ err = global.DEFAULT_DmSQL.Exec(sql, cTime, edbInfoId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -1470,9 +1488,9 @@ type ResetEdbClassifyReq struct {
|
|
|
|
|
|
// GetEdbInfoMaxSortByClassifyId 获取分类下指标的最大的排序数
|
|
|
func GetEdbInfoMaxSortByClassifyId(classifyId int) (sort int, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+
|
|
|
sql := `SELECT Max(sort) AS sort FROM edb_info WHERE classify_id=? `
|
|
|
- err = o.Raw(sql, classifyId).QueryRow(&sort)
|
|
|
+ err = global.DEFAULT_DmSQL.Raw(sql, classifyId).Scan(&sort).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -1527,9 +1545,9 @@ func GetEdbInfoByEdbCodeList(source int, edbCodeList []string) (items []*EdbInfo
|
|
|
if num <= 0 {
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrm()
|
|
|
+
|
|
|
sql := ` SELECT * FROM edb_info WHERE source=? AND edb_code IN (` + utils.GetOrmInReplace(num) + `) `
|
|
|
- _, err = o.Raw(sql, source, edbCodeList).QueryRows(&items)
|
|
|
+ err = global.DEFAULT_DmSQL.Raw(sql, source, edbCodeList).Scan(&items).Error
|
|
|
|
|
|
return
|
|
|
}
|
|
@@ -1559,9 +1577,9 @@ func GetEdbInfoNoUpdateTotalByIdList(edbInfoIdList []int) (total int, err error)
|
|
|
if num <= 0 {
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrm()
|
|
|
+
|
|
|
sql := ` SELECT count(*) FROM edb_info WHERE edb_info_id in (` + utils.GetOrmInReplace(num) + `) and no_update=1`
|
|
|
- err = o.Raw(sql, edbInfoIdList).QueryRow(&total)
|
|
|
+ err = global.DEFAULT_DmSQL.Raw(sql, edbInfoIdList).Scan(&total).Error
|
|
|
return
|
|
|
}
|
|
|
|