|
@@ -1,79 +1,77 @@
|
|
|
package data_manage
|
|
|
|
|
|
import (
|
|
|
+ "database/sql"
|
|
|
+ "eta/eta_api/global"
|
|
|
"eta/eta_api/utils"
|
|
|
"github.com/rdlucklib/rdluck_tools/paging"
|
|
|
"time"
|
|
|
-
|
|
|
- "github.com/beego/beego/v2/client/orm"
|
|
|
)
|
|
|
|
|
|
type BaseFromClarksonsIndex struct {
|
|
|
- BaseFromClarksonsIndexId int `orm:"pk"`
|
|
|
- ClassifyId int `description:"指标分类id"`
|
|
|
- IndexCode string `description:"指标编码"`
|
|
|
- IndexName string `description:"指标名称"`
|
|
|
- Unit string `description:"单位"`
|
|
|
- Frequency string `description:"频度"`
|
|
|
- StartDate string `description:"开始日期"`
|
|
|
- EndDate string `description:"结束日期"`
|
|
|
- Sort int `description:"排序"`
|
|
|
- CreateTime time.Time
|
|
|
- ModifyTime time.Time
|
|
|
+ BaseFromClarksonsIndexId int `orm:"pk"`
|
|
|
+ ClassifyId int `description:"指标分类id"`
|
|
|
+ IndexCode string `description:"指标编码"`
|
|
|
+ IndexName string `description:"指标名称"`
|
|
|
+ Unit string `description:"单位"`
|
|
|
+ Frequency string `description:"频度"`
|
|
|
+ StartDate string `description:"开始日期"`
|
|
|
+ EndDate string `description:"结束日期"`
|
|
|
+ Sort int `description:"排序"`
|
|
|
+ CreateTime time.Time
|
|
|
+ ModifyTime time.Time
|
|
|
}
|
|
|
|
|
|
type BaseFromClarksonsIndexView struct {
|
|
|
- BaseFromClarksonsIndexId int `orm:"pk"`
|
|
|
- EdbInfoId int `description:"指标库id"`
|
|
|
- ClassifyId int `description:"指标分类id"`
|
|
|
- IndexCode string `description:"指标编码"`
|
|
|
- IndexName string `description:"指标名称"`
|
|
|
- UniqueCode string `description:"唯一code"`
|
|
|
- Frequency string `description:"频度"`
|
|
|
- Unit string `description:"单位"`
|
|
|
- StartDate string `description:"开始日期"`
|
|
|
- EndDate string `description:"结束日期"`
|
|
|
- Sort int `description:"排序"`
|
|
|
- LatestDate string `description:"最后更新时间"`
|
|
|
- EdbExist int `description:"edb是否存在"`
|
|
|
- ModifyTime string
|
|
|
+ BaseFromClarksonsIndexId int `orm:"pk"`
|
|
|
+ EdbInfoId int `description:"指标库id"`
|
|
|
+ ClassifyId int `description:"指标分类id"`
|
|
|
+ IndexCode string `description:"指标编码"`
|
|
|
+ IndexName string `description:"指标名称"`
|
|
|
+ UniqueCode string `description:"唯一code"`
|
|
|
+ Frequency string `description:"频度"`
|
|
|
+ Unit string `description:"单位"`
|
|
|
+ StartDate string `description:"开始日期"`
|
|
|
+ EndDate string `description:"结束日期"`
|
|
|
+ Sort int `description:"排序"`
|
|
|
+ LatestDate string `description:"最后更新时间"`
|
|
|
+ EdbExist int `description:"edb是否存在"`
|
|
|
+ ModifyTime string
|
|
|
}
|
|
|
|
|
|
type BaseFromClarksonsIndexList struct {
|
|
|
- BaseFromClarksonsIndexId int `orm:"pk"`
|
|
|
- IndexCode string // 指标编码
|
|
|
- IndexName string // 指标名称
|
|
|
- ClassifyId int // 分类Id
|
|
|
- Unit string // 单位
|
|
|
- Frequency string // 频度
|
|
|
- Describe string // 指标描述
|
|
|
- CreateTime string // 创建时间
|
|
|
- ModifyTime string // 修改时间
|
|
|
- DataList []*BaseFromClarksonsData
|
|
|
- Paging *paging.PagingItem `description:"分页数据"`
|
|
|
+ BaseFromClarksonsIndexId int `orm:"pk"`
|
|
|
+ IndexCode string // 指标编码
|
|
|
+ IndexName string // 指标名称
|
|
|
+ ClassifyId int // 分类Id
|
|
|
+ Unit string // 单位
|
|
|
+ Frequency string // 频度
|
|
|
+ Describe string // 指标描述
|
|
|
+ CreateTime string // 创建时间
|
|
|
+ ModifyTime string // 修改时间
|
|
|
+ DataList []*BaseFromClarksonsData
|
|
|
+ Paging *paging.PagingItem `description:"分页数据"`
|
|
|
}
|
|
|
+
|
|
|
func (b *BaseFromClarksonsIndex) Update(cols []string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- _, err = o.Update(b, cols...)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Select(cols).Updates(b).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetClarksonsIndexByCondition 根据条件获取克拉克森指标列表
|
|
|
func GetClarksonsIndexByCondition(condition string, pars []interface{}) (items []*BaseFromClarksonsIndex, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT * FROM base_from_clarksons_index WHERE 1=1 `
|
|
|
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
sql += ` ORDER BY sort ASC, base_from_clarksons_index_id ASC`
|
|
|
- _, err = o.Raw(sql, pars).QueryRows(&items)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, pars).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetClarksonsIndexByCondition 根据条件获取克拉克森指标列表
|
|
|
func GetClarksonsIndexByConditionAndFrequency(condition, frequency string, pars []interface{}) (items []*BaseFromClarksonsIndex, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT * FROM base_from_clarksons_index WHERE 1=1 `
|
|
|
|
|
|
if condition != "" {
|
|
@@ -81,48 +79,51 @@ func GetClarksonsIndexByConditionAndFrequency(condition, frequency string, pars
|
|
|
}
|
|
|
sql += ` AND frequency=?`
|
|
|
sql += ` ORDER BY sort ASC, base_from_clarksons_index_id ASC`
|
|
|
- _, err = o.Raw(sql, pars, frequency).QueryRows(&items)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, pars, frequency).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetClarksonsIndexCountByCondition(condition string, pars []interface{}) (count int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- sql := ` SELECT COUNT(*) AS count FROM base_from_clarksons_index WHERE 1=1 `
|
|
|
+ sqlStr := ` SELECT COUNT(*) AS count FROM base_from_clarksons_index WHERE 1=1 `
|
|
|
|
|
|
if condition != "" {
|
|
|
- sql += condition
|
|
|
+ sqlStr += condition
|
|
|
}
|
|
|
- sql += ` ORDER BY sort ASC, base_from_clarksons_index_id ASC`
|
|
|
- err = o.Raw(sql, pars).QueryRow(&count)
|
|
|
+ sqlStr += ` ORDER BY sort ASC, base_from_clarksons_index_id ASC`
|
|
|
+ var totalNull sql.NullInt64
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sqlStr, pars).Scan(&totalNull).Error
|
|
|
+ if !totalNull.Valid {
|
|
|
+ count = 0
|
|
|
+ } else {
|
|
|
+ count = int(totalNull.Int64)
|
|
|
+ }
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetClarksonsIndexAndEdbInfoByCondition 根据条件获取克拉克森index和指标库的信息
|
|
|
func GetClarksonsIndexAndEdbInfoByCondition(condition string, pars []interface{}) (items []*BaseFromClarksonsIndexView, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT b.*, e.edb_info_id FROM base_from_clarksons_index AS b LEFT JOIN edb_info AS e ON b.index_code=e.edb_code AND e.source=? WHERE 1=1 `
|
|
|
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
sql += ` ORDER BY sort ASC `
|
|
|
- _, err = o.Raw(sql, utils.DATA_SOURCE_SCI_HQ, pars).QueryRows(&items)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, utils.DATA_SOURCE_SCI_HQ, pars).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetClarksonsIndexByIndexCode 根据指标编码获取指标信息
|
|
|
func GetClarksonsIndexByIndexCode(indexCode string) (item *BaseFromClarksonsIndex, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT * FROM base_from_clarksons_index WHERE index_code=? `
|
|
|
- err = o.Raw(sql, indexCode).QueryRow(&item)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, indexCode).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetClarksonsIndexByIndexId 根据指标id获取指标信息
|
|
|
func GetClarksonsIndexByIndexId(indexId int) (item *BaseFromClarksonsIndex, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT * FROM base_from_clarksons_index WHERE base_from_clarksons_index_id=? `
|
|
|
- err = o.Raw(sql, indexId).QueryRow(&item)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, indexId).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -131,33 +132,36 @@ func GetClarksonsIndexListByIndexIds(indexIds []int) (items []*BaseFromClarksons
|
|
|
if len(indexIds) == 0 {
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT * FROM base_from_clarksons_index WHERE base_from_clarksons_index_id IN (` + utils.GetOrmInReplace(len(indexIds)) + `) `
|
|
|
- _, err = o.Raw(sql, indexIds).QueryRows(&items)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, indexIds).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetClarksonsIndexCountByClassifyIds 获取分类下指标的个数
|
|
|
func GetClarksonsIndexCountByClassifyIds(classifyIds []int) (count int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
num := len(classifyIds)
|
|
|
if num <= 0 {
|
|
|
return
|
|
|
}
|
|
|
- sql := `SELECT COUNT(1) AS count FROM base_from_clarksons_index WHERE classify_id IN (` + utils.GetOrmInReplace(num) + `) `
|
|
|
- err = o.Raw(sql, classifyIds).QueryRow(&count)
|
|
|
+ sqlStr := `SELECT COUNT(1) AS count FROM base_from_clarksons_index WHERE classify_id IN (` + utils.GetOrmInReplace(num) + `) `
|
|
|
+ var totalNull sql.NullInt64
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sqlStr, classifyIds).Scan(&totalNull).Error
|
|
|
+ if !totalNull.Valid {
|
|
|
+ count = 0
|
|
|
+ } else {
|
|
|
+ count = int(totalNull.Int64)
|
|
|
+ }
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetClarksonsIndexByClassifyId 根据分类id获取克拉克森指标列表
|
|
|
func GetClarksonsIndexByClassifyId(classifyIds []int, startSize, pageSize int) (items []*BaseFromClarksonsIndexView, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT b.*, e.edb_info_id,
|
|
|
CASE WHEN e.edb_info_id IS NULL THEN 0 ELSE 1 END AS edb_exist
|
|
|
FROM base_from_clarksons_index AS b
|
|
|
LEFT JOIN edb_info AS e ON b.index_code=e.edb_code AND e.source=101
|
|
|
WHERE b.classify_id IN (` + utils.GetOrmInReplace(len(classifyIds)) + `) ORDER BY b.sort ASC LIMIT ?,? `
|
|
|
- _, err = o.Raw(sql, classifyIds, startSize, pageSize).QueryRows(&items)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, classifyIds, startSize, pageSize).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -166,74 +170,92 @@ func GetClarksonsIndexCountByClassifyId(classifyIds []int) (count int, err error
|
|
|
if len(classifyIds) == 0 {
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- sql := ` SELECT COUNT(*) AS count FROM base_from_clarksons_index WHERE classify_id IN (` + utils.GetOrmInReplace(len(classifyIds)) + `) `
|
|
|
- err = o.Raw(sql, classifyIds).QueryRow(&count)
|
|
|
+ sqlStr := ` SELECT COUNT(*) AS count FROM base_from_clarksons_index WHERE classify_id IN (` + utils.GetOrmInReplace(len(classifyIds)) + `) `
|
|
|
+
|
|
|
+ var totalNull sql.NullInt64
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sqlStr, classifyIds).Scan(&totalNull).Error
|
|
|
+ if !totalNull.Valid {
|
|
|
+ count = 0
|
|
|
+ } else {
|
|
|
+ count = int(totalNull.Int64)
|
|
|
+ }
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetClarksonsIndexCount 获取克拉克森指标数量
|
|
|
func GetClarksonsIndexCount() (count int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- sql := ` SELECT COUNT(*) AS count FROM base_from_clarksons_index `
|
|
|
- err = o.Raw(sql).QueryRow(&count)
|
|
|
+ sqlStr := ` SELECT COUNT(*) AS count FROM base_from_clarksons_index `
|
|
|
+ var totalNull sql.NullInt64
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sqlStr).Scan(&totalNull).Error
|
|
|
+ if !totalNull.Valid {
|
|
|
+ count = 0
|
|
|
+ } else {
|
|
|
+ count = int(totalNull.Int64)
|
|
|
+ }
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetClarksonsIndexByPage(startSize, pageSize int) (items []*BaseFromClarksonsIndexView, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT b.*, e.edb_info_id,
|
|
|
CASE WHEN e.edb_info_id IS NULL THEN 0 ELSE 1 END AS edb_exist
|
|
|
FROM base_from_clarksons_index AS b
|
|
|
LEFT JOIN edb_info AS e ON b.index_code=e.edb_code AND e.source=101
|
|
|
ORDER BY b.modify_time DESC LIMIT ?,?`
|
|
|
- _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, startSize, pageSize).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetClarksonsIndexBaseInfoByClassifyId 根据分类id获取克拉克森指标列表
|
|
|
func GetClarksonsIndexBaseInfoByClassifyId(classifyId int) (items []*BaseFromClarksonsIndexView, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT base_from_clarksons_index_id, classify_id, index_code, index_name, CONCAT(classify_id, '_', base_from_clarksons_index_id) AS unique_code FROM base_from_clarksons_index WHERE classify_id = ? ORDER BY sort ASC `
|
|
|
- _, err = o.Raw(sql, classifyId).QueryRows(&items)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, classifyId).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetClarksonsIndexBaseInfoByClassifyId 根据分类id获取克拉克森指标列表
|
|
|
func GetClarksonsIndexBaseInfoByCondition(condition string, pars []interface{}) (items []*BaseFromClarksonsIndex, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT base_from_clarksons_index_id, index_code, index_name FROM base_from_clarksons_index WHERE 1=1 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
sql += ` ORDER BY sort ASC `
|
|
|
- _, err = o.Raw(sql, pars...).QueryRows(&items)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetClarksonsDataMaxCount(condition string, pars []interface{}) (count int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- sql := `SELECT MAX(t.num) AS count FROM ( SELECT COUNT(1) AS num FROM base_from_clarksons_index AS a INNER JOIN base_from_clarksons_data AS b ON a.index_code=b.index_code WHERE 1=1 `
|
|
|
+ sqlStr := `SELECT MAX(t.num) AS count FROM ( SELECT COUNT(1) AS num FROM base_from_clarksons_index AS a INNER JOIN base_from_clarksons_data AS b ON a.index_code=b.index_code WHERE 1=1 `
|
|
|
if condition != "" {
|
|
|
- sql += condition
|
|
|
+ sqlStr += condition
|
|
|
+ }
|
|
|
+ sqlStr += ` GROUP BY a.base_from_clarksons_index_id) AS t `
|
|
|
+
|
|
|
+ var totalNull sql.NullInt64
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sqlStr, pars).Scan(&totalNull).Error
|
|
|
+ if !totalNull.Valid {
|
|
|
+ count = 0
|
|
|
+ } else {
|
|
|
+ count = int(totalNull.Int64)
|
|
|
}
|
|
|
- sql += ` GROUP BY a.base_from_clarksons_index_id) AS t `
|
|
|
- err = o.Raw(sql, pars).QueryRow(&count)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetClarksonsIndexMaxSortByClassifyId 根据分类id获取指标最大排序
|
|
|
func GetClarksonsIndexMaxSortByClassifyId(classifyId int) (sort int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- sql := `SELECT MAX(sort) FROM base_from_clarksons_index WHERE classify_id=? `
|
|
|
- err = o.Raw(sql, classifyId).QueryRow(&sort)
|
|
|
+ sqlStr := `SELECT MAX(sort) FROM base_from_clarksons_index WHERE classify_id=? `
|
|
|
+ var totalNull sql.NullInt64
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sqlStr, classifyId).Scan(&totalNull).Error
|
|
|
+ if !totalNull.Valid {
|
|
|
+ sort = 0
|
|
|
+ } else {
|
|
|
+ sort = int(totalNull.Int64)
|
|
|
+ }
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetClarksonsFrequency(classifyId int) (items []*string, err error) {
|
|
|
sql := `SELECT DISTINCT frequency FROM base_from_clarksons_index WHERE classify_id=? ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年','年度') `
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- _, err = o.Raw(sql, classifyId).QueryRows(&items)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, classifyId).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -243,15 +265,13 @@ func GetClarksonsFrequencyByCondition(condition string, pars []interface{}) (ite
|
|
|
sql += condition
|
|
|
}
|
|
|
sql += ` ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年','年度') `
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- _, err = o.Raw(sql, pars...).QueryRows(&items)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetClarksonsFrequencyByCode(code string) (items []*string, err error) {
|
|
|
sql := `SELECT DISTINCT frequency FROM base_from_clarksons_index WHERE index_code=? ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年','年度') `
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- _, err = o.Raw(sql, code).QueryRows(&items)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, code).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -260,7 +280,6 @@ func GetClarksonsClassifyMaxSortByClassifyIds(classifyIds []int) (items []*BaseF
|
|
|
if len(classifyIds) == 0 {
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := `SELECT bc.base_from_clarksons_classify_id, COALESCE(MAX(bi.sort), 0) AS max_sort FROM base_from_clarksons_classify AS bc
|
|
|
LEFT JOIN base_from_clarksons_index AS bi
|
|
|
ON bc.base_from_clarksons_classify_id=bi.classify_id
|
|
@@ -268,22 +287,14 @@ func GetClarksonsClassifyMaxSortByClassifyIds(classifyIds []int) (items []*BaseF
|
|
|
GROUP BY bc.base_from_clarksons_classify_id
|
|
|
`
|
|
|
// sql = ` SELECT classify_id, MAX(sort) AS max_sort FROM base_from_clarksons_index WHERE classify_id IN (` + utils.GetOrmInReplace(len(classifyIds)) + `) GROUP BY classify_id `
|
|
|
- _, err = o.Raw(sql, classifyIds).QueryRows(&items)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, classifyIds).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func BatchModifyClarksonsIndexClassify(items []*BaseFromClarksonsIndex) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := `UPDATE base_from_clarksons_index SET classify_id=?, sort=? WHERE base_from_clarksons_index_id=? `
|
|
|
- p, err := o.Raw(sql).Prepare()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- defer func() {
|
|
|
- p.Close()
|
|
|
- }()
|
|
|
for _, v := range items {
|
|
|
- _, err = p.Exec(v.ClassifyId, v.Sort, v.BaseFromClarksonsIndexId)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Exec(sql, v.ClassifyId, v.Sort, v.BaseFromClarksonsIndexId).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -293,41 +304,35 @@ func BatchModifyClarksonsIndexClassify(items []*BaseFromClarksonsIndex) (err err
|
|
|
|
|
|
// MoveDownClarksonsIndexBySort 往下移动
|
|
|
func MoveDownClarksonsIndexBySort(classifyId, prevSort, currentSort int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := `update base_from_clarksons_index set sort = sort - 1 where classify_id=? and sort <= ? and sort> ? `
|
|
|
- _, err = o.Raw(sql, classifyId, prevSort, currentSort).Exec()
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Exec(sql, classifyId, prevSort, currentSort).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// MoveUpClarksonsIndexBySort 往上移动
|
|
|
func MoveUpClarksonsIndexBySort(classifyId, nextSort, currentSort int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := `update base_from_clarksons_index set sort = sort + 1 where classify_id=? and sort >= ? and sort< ?`
|
|
|
- _, err = o.Raw(sql, classifyId, nextSort, currentSort).Exec()
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Exec(sql, classifyId, nextSort, currentSort).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func DeleteClarksonsIndexById(indexId int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- to, err := o.Begin()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
+ tx := global.DbMap[utils.DbNameIndex].Begin()
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
- _ = to.Rollback()
|
|
|
+ _ = tx.Rollback()
|
|
|
} else {
|
|
|
- _ = to.Commit()
|
|
|
+ _ = tx.Commit()
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
sql := `DELETE FROM base_from_clarksons_index WHERE base_from_clarksons_index_id=? `
|
|
|
- _, err = to.Raw(sql, indexId).Exec()
|
|
|
+ err = tx.Exec(sql, indexId).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
sql = `DELETE FROM base_from_clarksons_data WHERE base_from_clarksons_index_id=? `
|
|
|
- _, err = to.Raw(sql, indexId).Exec()
|
|
|
+ err = tx.Exec(sql, indexId).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -338,25 +343,21 @@ func DeleteClarksonsIndexByIds(indexIds []int) (err error) {
|
|
|
if len(indexIds) == 0 {
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- to, err := o.Begin()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
+ tx := global.DbMap[utils.DbNameIndex].Begin()
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
- _ = to.Rollback()
|
|
|
+ _ = tx.Rollback()
|
|
|
} else {
|
|
|
- _ = to.Commit()
|
|
|
+ _ = tx.Commit()
|
|
|
}
|
|
|
}()
|
|
|
sql := `DELETE FROM base_from_clarksons_index WHERE base_from_clarksons_index_id IN (` + utils.GetOrmInReplace(len(indexIds)) + `) `
|
|
|
- _, err = o.Raw(sql, indexIds).Exec()
|
|
|
+ err = tx.Exec(sql, indexIds).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
sql = `DELETE FROM base_from_clarksons_data WHERE base_from_clarksons_index_id IN (` + utils.GetOrmInReplace(len(indexIds)) + `) `
|
|
|
- _, err = o.Raw(sql, indexIds).Exec()
|
|
|
+ err = tx.Exec(sql, indexIds).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -365,60 +366,66 @@ func DeleteClarksonsIndexByIds(indexIds []int) (err error) {
|
|
|
|
|
|
// MoveClarksonsIndex 移动指标分类
|
|
|
func MoveClarksonsIndex(indexId, classifyId int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` UPDATE base_from_clarksons_index
|
|
|
SET
|
|
|
classify_id = ?, modify_time=NOW()
|
|
|
WHERE base_from_clarksons_index_id = ?`
|
|
|
- _, err = o.Raw(sql, classifyId, indexId).Exec()
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, classifyId, indexId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetClarksonsIndexMinSortByClassifyId 获取最小不等于0的排序
|
|
|
func GetClarksonsIndexMinSortByClassifyId(classifyId int) (sort int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- sql := `SELECT min(sort) FROM base_from_clarksons_index WHERE classify_id=? and sort <> 0 `
|
|
|
- err = o.Raw(sql, classifyId).QueryRow(&sort)
|
|
|
+ sqlStr := `SELECT min(sort) FROM base_from_clarksons_index WHERE classify_id=? and sort <> 0 `
|
|
|
+ var totalNull sql.NullInt64
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sqlStr, classifyId).Scan(&totalNull).Error
|
|
|
+ if !totalNull.Valid {
|
|
|
+ sort = 0
|
|
|
+ } else {
|
|
|
+ sort = int(totalNull.Int64)
|
|
|
+ }
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetClarksonsIndexInfoCount 分页查询指标信息行数
|
|
|
func GetClarksonsIndexInfoCount(condition string, pars []interface{}) (count int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- sql := ` SELECT count(1) FROM base_from_clarksons_index WHERE index_code not in (select edb_code from edb_info) `
|
|
|
+ sqlStr := ` SELECT count(1) FROM base_from_clarksons_index WHERE index_code not in (select edb_code from edb_info) `
|
|
|
if condition != "" {
|
|
|
- sql += condition
|
|
|
+ sqlStr += condition
|
|
|
+ }
|
|
|
+ var totalNull sql.NullInt64
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sqlStr, pars).Scan(&totalNull).Error
|
|
|
+ if !totalNull.Valid {
|
|
|
+ count = 0
|
|
|
+ } else {
|
|
|
+ count = int(totalNull.Int64)
|
|
|
}
|
|
|
- err = o.Raw(sql, pars).QueryRow(&count)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetClarksonsIndexInfoPage 分页查询指标信息
|
|
|
func GetClarksonsIndexInfoPage(condition string, pars []interface{}) (items []*BaseFromRzdIndexAndData, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT * FROM base_from_clarksons_index WHERE index_code not in (select edb_code from edb_info) `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
- _, err = o.Raw(sql, pars).QueryRows(&items)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, pars).Find(&items).Error
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
func GetClarksonsIndex(condition string, pars interface{}) (items []*BaseFromClarksonsIndexView, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT * FROM base_from_clarksons_index WHERE 1=1 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
sql += `ORDER BY base_from_clarksons_index_id ASC `
|
|
|
- _, err = o.Raw(sql, pars).QueryRows(&items)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, pars).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetClarksonsIndexLatestDate(indexCode string) (ModifyTime string, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT modify_time FROM base_from_clarksons_data WHERE index_code=? ORDER BY modify_time DESC limit 1 `
|
|
|
- err = o.Raw(sql, indexCode).QueryRow(&ModifyTime)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, indexCode).Scan(&ModifyTime).Error
|
|
|
return
|
|
|
}
|