|
@@ -49,6 +49,14 @@ type EdbInfo struct {
|
|
|
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:"证券代码"`
|
|
|
}
|
|
|
|
|
|
func (e *EdbInfo) Add() (err error) {
|
|
@@ -164,13 +172,14 @@ type EdbInfoSearchData struct {
|
|
|
EdbDataId int `description:"数据ID"`
|
|
|
DataTime string `description:"数据日期"`
|
|
|
Value float64 `description:"数据"`
|
|
|
+ EdbCode string `description:"指标编码"`
|
|
|
}
|
|
|
|
|
|
// GetEdbDataListAll 获取指标数据列表 order:1升序,其余值为降序
|
|
|
-func GetEdbDataListAll(condition string, pars []interface{}, source, order int) (item []*EdbInfoSearchData, err error) {
|
|
|
+func GetEdbDataListAll(condition string, pars []interface{}, source, subSource, order int) (item []*EdbInfoSearchData, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
sql := ``
|
|
|
- tableName := GetEdbDataTableName(source)
|
|
|
+ tableName := GetEdbDataTableName(source, subSource)
|
|
|
sql = ` SELECT * FROM %s WHERE 1=1 `
|
|
|
sql = fmt.Sprintf(sql, tableName)
|
|
|
|
|
@@ -187,9 +196,9 @@ func GetEdbDataListAll(condition string, pars []interface{}, source, order int)
|
|
|
}
|
|
|
|
|
|
// GetEdbDataListAllByTo 根据事务链接获取指标数据列表 order:1升序,其余值为降序
|
|
|
-func GetEdbDataListAllByTo(to orm.TxOrmer, condition string, pars []interface{}, source, order int) (item []*EdbInfoSearchData, err error) {
|
|
|
+func GetEdbDataListAllByTo(to orm.TxOrmer, condition string, pars []interface{}, source, subSource, order int) (item []*EdbInfoSearchData, err error) {
|
|
|
sql := ``
|
|
|
- tableName := GetEdbDataTableName(source)
|
|
|
+ tableName := GetEdbDataTableName(source, subSource)
|
|
|
sql = ` SELECT * FROM %s WHERE 1=1 `
|
|
|
sql = fmt.Sprintf(sql, tableName)
|
|
|
|
|
@@ -216,10 +225,10 @@ type EdbInfoMaxAndMinInfo struct {
|
|
|
}
|
|
|
|
|
|
// GetEdbInfoMaxAndMinInfo 获取指标的最新数据记录信息
|
|
|
-func GetEdbInfoMaxAndMinInfo(source int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
|
|
|
+func GetEdbInfoMaxAndMinInfo(source, subSource int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
sql := ``
|
|
|
- tableName := GetEdbDataTableName(source)
|
|
|
+ tableName := GetEdbDataTableName(source, subSource)
|
|
|
sql = ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date,MIN(value) AS min_value,MAX(value) AS max_value FROM %s WHERE edb_code=? `
|
|
|
sql = fmt.Sprintf(sql, tableName)
|
|
|
err = o.Raw(sql, edbCode).QueryRow(&item)
|
|
@@ -232,6 +241,21 @@ func GetEdbInfoMaxAndMinInfo(source int, edbCode string) (item *EdbInfoMaxAndMin
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+type EdbIndoDataUpdateTime struct {
|
|
|
+ MinDate string `description:"本次更新,数据发生变化的最早日期"`
|
|
|
+}
|
|
|
+
|
|
|
+// 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)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// ModifyEdbInfoMaxAndMinInfo 修改指标的最新数据信息
|
|
|
func ModifyEdbInfoMaxAndMinInfo(edbInfoId int, item *EdbInfoMaxAndMinInfo) (err error) {
|
|
|
o := orm.NewOrm()
|
|
@@ -248,11 +272,19 @@ func ModifyEdbTimeAndLastInfo(edbInfoId int, item *EdbInfoMaxAndMinInfo) (err er
|
|
|
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()
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// GetEdbDataCount 获取edb指标数据的数量; order:1升序,其余值为降序
|
|
|
-func GetEdbDataCount(condition string, pars []interface{}, source int) (count int, err error) {
|
|
|
+func GetEdbDataCount(condition string, pars []interface{}, source, subSource int) (count int, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
sql := ``
|
|
|
- tableName := GetEdbDataTableName(source)
|
|
|
+ tableName := GetEdbDataTableName(source, subSource)
|
|
|
sql = ` SELECT COUNT(1) AS count FROM %s WHERE 1=1 `
|
|
|
sql = fmt.Sprintf(sql, tableName)
|
|
|
|
|
@@ -264,10 +296,10 @@ func GetEdbDataCount(condition string, pars []interface{}, source int) (count in
|
|
|
}
|
|
|
|
|
|
// GetLastEdbData 获取最近的一条指标数据
|
|
|
-func GetLastEdbData(condition string, pars []interface{}, source int) (item *EdbInfoSearchData, err error) {
|
|
|
+func GetLastEdbData(condition string, pars []interface{}, source, subSource int) (item *EdbInfoSearchData, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
sql := ``
|
|
|
- tableName := GetEdbDataTableName(source)
|
|
|
+ tableName := GetEdbDataTableName(source, subSource)
|
|
|
sql = ` SELECT * FROM %s WHERE 1=1 `
|
|
|
sql = fmt.Sprintf(sql, tableName)
|
|
|
|
|
@@ -327,10 +359,10 @@ type EdbInfoSearchDataV1 struct {
|
|
|
}
|
|
|
|
|
|
// 优化版本-处理数据精度问题
|
|
|
-func GetEdbDataListAllV1(condition string, pars []interface{}, source, order int) (item []*EdbInfoSearchDataV1, err error) {
|
|
|
+func GetEdbDataListAllV1(condition string, pars []interface{}, source, subSource, order int) (item []*EdbInfoSearchDataV1, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
sql := ``
|
|
|
- tableName := GetEdbDataTableName(source)
|
|
|
+ tableName := GetEdbDataTableName(source, subSource)
|
|
|
sql = ` SELECT * FROM %s WHERE 1=1 `
|
|
|
sql = fmt.Sprintf(sql, tableName)
|
|
|
|
|
@@ -347,9 +379,9 @@ func GetEdbDataListAllV1(condition string, pars []interface{}, source, order int
|
|
|
}
|
|
|
|
|
|
// GetEdbDataListAllV1ByTo 通过事务链接获取数据列表
|
|
|
-func GetEdbDataListAllV1ByTo(to orm.TxOrmer, condition string, pars []interface{}, source, order int) (item []*EdbInfoSearchDataV1, err error) {
|
|
|
+func GetEdbDataListAllV1ByTo(to orm.TxOrmer, condition string, pars []interface{}, source, subSource, order int) (item []*EdbInfoSearchDataV1, err error) {
|
|
|
sql := ``
|
|
|
- tableName := GetEdbDataTableName(source)
|
|
|
+ tableName := GetEdbDataTableName(source, subSource)
|
|
|
sql = ` SELECT * FROM %s WHERE 1=1 `
|
|
|
sql = fmt.Sprintf(sql, tableName)
|
|
|
|
|
@@ -384,7 +416,7 @@ func GetEdbInfoByCondition(condition string, pars []interface{}, order int) (ite
|
|
|
// UnifiedModifyEdbInfoMaxAndMinInfo 统一修改指标的最大最小值
|
|
|
func UnifiedModifyEdbInfoMaxAndMinInfo(edbInfo *EdbInfo) (err error, errMsg string) {
|
|
|
// 修改最大最小值
|
|
|
- maxAndMinItem, err := GetEdbInfoMaxAndMinInfo(edbInfo.Source, edbInfo.EdbCode)
|
|
|
+ maxAndMinItem, err := GetEdbInfoMaxAndMinInfo(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbCode)
|
|
|
if err != nil {
|
|
|
if err.Error() == utils.ErrNoRow() {
|
|
|
err = nil
|
|
@@ -419,10 +451,36 @@ func UnifiedModifyEdbInfoMaxAndMinInfo(edbInfo *EdbInfo) (err error, errMsg stri
|
|
|
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() { //本次刷新指标数据无变化
|
|
|
+ errMsg = "刷新指标失败!"
|
|
|
+ err = errors.New("查询指标刷新,数据更新的最早日期失败,err:" + tErr.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else if erDataUpdateTime.MinDate != "" {
|
|
|
+ err = ModifyEdbDataUpdateTime(edbInfo.EdbInfoId, dataUpdateTime, erDataUpdateTime.MinDate)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "刷新指标失败!"
|
|
|
+ err = errors.New("修改指标数据更新的最早日期失败,err:" + tErr.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ erDataUpdateDate = erDataUpdateTime.MinDate
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// UnifiedModifyPredictEdbInfoMaxAndMinInfo 统一修改预测运算指标的最大最小值
|
|
|
func UnifiedModifyPredictEdbInfoMaxAndMinInfo(edbInfo *EdbInfo, latestDateStr string, latestValue float64) (err error, errMsg string) {
|
|
|
// 修改最大最小值
|
|
|
- maxAndMinItem, err := GetEdbInfoMaxAndMinInfo(edbInfo.Source, edbInfo.EdbCode)
|
|
|
+ maxAndMinItem, err := GetEdbInfoMaxAndMinInfo(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbCode)
|
|
|
if err != nil {
|
|
|
if err.Error() == utils.ErrNoRow() {
|
|
|
err = nil
|
|
@@ -839,13 +897,13 @@ func GetPredictDataListByPredictEdbConfList(edbInfo, sourceEdbInfoItem *EdbInfo,
|
|
|
condition += " AND data_time>=? "
|
|
|
pars = append(pars, startDate)
|
|
|
}
|
|
|
- tmpDataList, err := GetEdbDataListAll(condition, pars, sourceEdbInfoItem.Source, 1)
|
|
|
+ tmpDataList, err := GetEdbDataListAll(condition, pars, sourceEdbInfoItem.Source, sourceEdbInfoItem.SubSource, 1)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
// 如果选择了日期,那么需要筛选所有的数据,用于未来指标的生成
|
|
|
if startDate != `` {
|
|
|
- allDataList, err = GetEdbDataListAll(" AND edb_info_id=? ", []interface{}{sourceEdbInfoItem.EdbInfoId}, sourceEdbInfoItem.Source, 1)
|
|
|
+ allDataList, err = GetEdbDataListAll(" AND edb_info_id=? ", []interface{}{sourceEdbInfoItem.EdbInfoId}, sourceEdbInfoItem.Source, sourceEdbInfoItem.SubSource, 1)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -908,7 +966,7 @@ func GetPredictEdbDataListAll(edbInfo *EdbInfo, order int) (items []*EdbInfoSear
|
|
|
var pars []interface{}
|
|
|
condition += " AND edb_info_id=? "
|
|
|
pars = append(pars, edbInfo.EdbInfoId)
|
|
|
- items, err = GetEdbDataListAll(condition, pars, edbInfo.Source, order)
|
|
|
+ items, err = GetEdbDataListAll(condition, pars, edbInfo.Source, edbInfo.SubSource, order)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
@@ -926,7 +984,7 @@ func GetPredictEdbDataListAllByStartDate(edbInfo *EdbInfo, order int, startDate
|
|
|
condition += " AND data_time>=? "
|
|
|
pars = append(pars, startDate)
|
|
|
}
|
|
|
- items, err = GetEdbDataListAll(condition, pars, edbInfo.Source, order)
|
|
|
+ items, err = GetEdbDataListAll(condition, pars, edbInfo.Source, edbInfo.SubSource, order)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
@@ -1003,14 +1061,15 @@ type EdbInfoDetailResp struct {
|
|
|
}
|
|
|
|
|
|
type AddEdbInfoParams struct {
|
|
|
- Source int `description:"来源id"`
|
|
|
- EdbCode string `description:"指标编码"`
|
|
|
- EdbName string `description:"指标名称"`
|
|
|
- Frequency string `description:"频率"`
|
|
|
- Unit string `description:"单位"`
|
|
|
- ClassifyId int `description:"分类id"`
|
|
|
- AdminId int `description:"创建人ID"`
|
|
|
- AdminName string `description:"创建人姓名"`
|
|
|
+ Source int `description:"来源id"`
|
|
|
+ EdbCode string `description:"指标编码"`
|
|
|
+ EdbName string `description:"指标名称"`
|
|
|
+ Frequency string `description:"频率"`
|
|
|
+ Unit string `description:"单位"`
|
|
|
+ ClassifyId int `description:"分类id"`
|
|
|
+ TerminalCode string `description:"终端编码"`
|
|
|
+ AdminId int `description:"创建人ID"`
|
|
|
+ AdminName string `description:"创建人姓名"`
|
|
|
}
|
|
|
|
|
|
// EdbInfoAdd 添加指标到指标库
|
|
@@ -1091,6 +1150,8 @@ func EdbInfoAdd(req *AddEdbInfoParams, serverUrl string, sysUserId int, sysUserR
|
|
|
edbType = 2 //计算指标
|
|
|
}
|
|
|
|
|
|
+ var sourceIndexName string
|
|
|
+
|
|
|
// 钢联化工需要校验下信息是否完整
|
|
|
if source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
|
|
|
indexObj := new(BaseFromMysteelChemicalIndex)
|
|
@@ -1104,6 +1165,12 @@ func EdbInfoAdd(req *AddEdbInfoParams, serverUrl string, sysUserId int, sysUserR
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
+ //获取该层级下最大的排序数
|
|
|
+ maxSort, err := GetEdbAndClassifyMaxSort(req.ClassifyId, 0)
|
|
|
+ if err != nil {
|
|
|
+ err = errors.New("查询排序信息失败,Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
edbInfo.EdbCode = req.EdbCode
|
|
|
edbInfo.EdbName = req.EdbName
|
|
@@ -1117,14 +1184,17 @@ func EdbInfoAdd(req *AddEdbInfoParams, serverUrl string, sysUserId int, sysUserR
|
|
|
edbInfo.CreateTime = time.Now()
|
|
|
edbInfo.ModifyTime = time.Now()
|
|
|
edbInfo.ServerUrl = serverUrl
|
|
|
+ edbInfo.TerminalCode = req.TerminalCode
|
|
|
+ edbInfo.Sort = maxSort + 1
|
|
|
timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
|
|
|
edbInfo.UniqueCode = utils.MD5(utils.DATA_PREFIX + "_" + req.EdbCode + timestamp)
|
|
|
- itemVal, err := GetEdbInfoMaxAndMinInfo(source, req.EdbCode)
|
|
|
+ itemVal, err := GetEdbInfoMaxAndMinInfo(source, utils.DATA_SUB_SOURCE_EDB, req.EdbCode)
|
|
|
if itemVal != nil && err == nil {
|
|
|
edbInfo.MaxValue = itemVal.MaxValue
|
|
|
edbInfo.MinValue = itemVal.MinValue
|
|
|
}
|
|
|
edbInfo.EdbType = edbType
|
|
|
+ edbInfo.SourceIndexName = sourceIndexName
|
|
|
edbInfoId, err := AddEdbInfo(edbInfo)
|
|
|
if err != nil {
|
|
|
err = errors.New("保存失败,Err:" + err.Error())
|
|
@@ -1154,3 +1224,28 @@ type ResetEdbClassifyReq struct {
|
|
|
ClassifySecond string `description:"二级分类名称"`
|
|
|
ClassifyThird string `description:"三级分类名称"`
|
|
|
}
|
|
|
+
|
|
|
+// 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)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetEdbAndClassifyMaxSort(parentId int, classifyType uint8) (maxSort int, err error) {
|
|
|
+ //获取该层级下最大的排序数
|
|
|
+ classifyMaxSort, err := GetEdbClassifyMaxSort(parentId, classifyType)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ maxSort = classifyMaxSort
|
|
|
+ edbMaxSort, err := GetEdbInfoMaxSortByClassifyId(parentId)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if maxSort < edbMaxSort {
|
|
|
+ maxSort = edbMaxSort
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|