|
@@ -1,16 +1,16 @@
|
|
|
package data_manage
|
|
|
|
|
|
import (
|
|
|
+ "eta/eta_api/global"
|
|
|
"eta/eta_api/utils"
|
|
|
"fmt"
|
|
|
- "github.com/beego/beego/v2/client/orm"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
// AiPredictModelClassify 同花顺高频数据-分类
|
|
|
type AiPredictModelClassify struct {
|
|
|
- AiPredictModelClassifyId int `orm:"column(ai_predict_model_classify_id);pk"`
|
|
|
+ AiPredictModelClassifyId int `gorm:"primaryKey;column:ai_predict_model_classify_id;"`
|
|
|
UniqueCode string `description:"唯一编码"`
|
|
|
ClassifyName string `description:"分类名称"`
|
|
|
ClassifyNameEn string `description:"英文分类名称"`
|
|
@@ -64,12 +64,7 @@ func (m *AiPredictModelClassify) Cols() AiPredictModelClassifyCols {
|
|
|
}
|
|
|
|
|
|
func (m *AiPredictModelClassify) Create() (err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- id, err := o.Insert(m)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- m.AiPredictModelClassifyId = int(id)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Create(m).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -77,21 +72,19 @@ func (m *AiPredictModelClassify) CreateMulti(items []*AiPredictModelClassify) (e
|
|
|
if len(items) == 0 {
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- _, err = o.InsertMulti(len(items), items)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].CreateInBatches(items, utils.MultiAddNum).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *AiPredictModelClassify) Update(cols []string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- _, err = o.Update(m, cols...)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Select(cols).Updates(m).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *AiPredictModelClassify) Remove() (err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
|
|
|
- _, err = o.Raw(sql, m.AiPredictModelClassifyId).Exec()
|
|
|
+ err = o.Exec(sql, m.AiPredictModelClassifyId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -99,9 +92,9 @@ func (m *AiPredictModelClassify) MultiRemove(ids []int) (err error) {
|
|
|
if len(ids) == 0 {
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.Cols().PrimaryId, utils.GetOrmInReplace(len(ids)))
|
|
|
- _, err = o.Raw(sql, ids).Exec()
|
|
|
+ err = o.Exec(sql, ids).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -109,39 +102,39 @@ func (m *AiPredictModelClassify) RemoveByCondition(condition string, pars []inte
|
|
|
if condition == "" {
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
sql := fmt.Sprintf(`DELETE FROM %s WHERE %s`, m.TableName(), condition)
|
|
|
- _, err = o.Raw(sql, pars).Exec()
|
|
|
+ err = o.Exec(sql, pars...).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *AiPredictModelClassify) GetItemById(id int) (item *AiPredictModelClassify, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
|
|
|
- err = o.Raw(sql, id).QueryRow(&item)
|
|
|
+ err = o.Raw(sql, id).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *AiPredictModelClassify) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *AiPredictModelClassify, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
order := ``
|
|
|
if orderRule != "" {
|
|
|
order = ` ORDER BY ` + orderRule
|
|
|
}
|
|
|
sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
|
|
|
- err = o.Raw(sql, pars).QueryRow(&item)
|
|
|
+ err = o.Raw(sql, pars...).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *AiPredictModelClassify) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
|
|
|
- err = o.Raw(sql, pars).QueryRow(&count)
|
|
|
+ err = o.Raw(sql, pars...).Scan(&count).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *AiPredictModelClassify) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*AiPredictModelClassify, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
fields := strings.Join(fieldArr, ",")
|
|
|
if len(fieldArr) == 0 {
|
|
|
fields = `*`
|
|
@@ -151,12 +144,12 @@ func (m *AiPredictModelClassify) GetItemsByCondition(condition string, pars []in
|
|
|
order = ` ORDER BY ` + orderRule
|
|
|
}
|
|
|
sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
|
|
|
- _, err = o.Raw(sql, pars).QueryRows(&items)
|
|
|
+ err = o.Raw(sql, pars...).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *AiPredictModelClassify) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*AiPredictModelClassify, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
fields := strings.Join(fieldArr, ",")
|
|
|
if len(fieldArr) == 0 {
|
|
|
fields = `*`
|
|
@@ -166,7 +159,8 @@ func (m *AiPredictModelClassify) GetPageItemsByCondition(condition string, pars
|
|
|
order = ` ORDER BY ` + orderRule
|
|
|
}
|
|
|
sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
|
|
|
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
|
|
|
+ pars = append(pars, startSize, pageSize)
|
|
|
+ err = o.Exec(sql, pars...).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -209,9 +203,9 @@ type AiPredictModelClassifyEditReq struct {
|
|
|
}
|
|
|
|
|
|
func (m *AiPredictModelClassify) GetSortMax(parentId int) (sort int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
sql := fmt.Sprintf(`SELECT MAX(%s) FROM %s WHERE %s = ?`, m.Cols().Sort, m.TableName(), m.Cols().ParentId)
|
|
|
- err = o.Raw(sql, parentId).QueryRow(&sort)
|
|
|
+ err = o.Raw(sql, parentId).Scan(&sort).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -250,51 +244,51 @@ type AiPredictModelClassifyMoveReq struct {
|
|
|
}
|
|
|
|
|
|
func GetAiPredictModelClassifyById(classifyId int) (item *AiPredictModelClassify, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
sql := `SELECT * FROM ai_predict_model_classify WHERE ai_predict_model_classify_id = ?`
|
|
|
- err = o.Raw(sql, classifyId).QueryRow(&item)
|
|
|
+ err = o.Raw(sql, classifyId).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetAiPredictModelClassifyByRootIdLevel(rootId int, orderStr string) (items []*AiPredictModelClassify, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
sql := ` SELECT * FROM ai_predict_model_classify WHERE root_id = ? `
|
|
|
if orderStr != "" {
|
|
|
sql += orderStr
|
|
|
} else {
|
|
|
sql += ` order by level desc, sort asc, ai_predict_model_classify_id asc`
|
|
|
}
|
|
|
- _, err = o.Raw(sql, rootId).QueryRows(&items)
|
|
|
+ err = o.Raw(sql, rootId).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// UpdateAiPredictModelClassifySortByParentId 根据父类id更新排序
|
|
|
func UpdateAiPredictModelClassifySortByParentId(parentId, classifyId, nowSort int, updateSort string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
sql := ` update ai_predict_model_classify set sort = ` + updateSort + ` WHERE parent_id = ? AND sort > ? `
|
|
|
if classifyId > 0 {
|
|
|
sql += ` or ( ai_predict_model_classify_id > ` + fmt.Sprint(classifyId) + ` and sort = ` + fmt.Sprint(nowSort) + `)`
|
|
|
}
|
|
|
- _, err = o.Raw(sql, parentId, nowSort).Exec()
|
|
|
+ err = o.Exec(sql, parentId, nowSort).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetFirstAiPredictModelClassifyByParentId 获取当前父级分类下,且排序数相同 的排序第一条的数据
|
|
|
func GetFirstAiPredictModelClassifyByParentId(parentId int) (item *AiPredictModelClassify, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
sql := ` SELECT * FROM ai_predict_model_classify WHERE parent_id = ? order by sort asc,ai_predict_model_classify_id asc limit 1`
|
|
|
- err = o.Raw(sql, parentId).QueryRow(&item)
|
|
|
+ err = o.Raw(sql, parentId).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func UpdateAiPredictModelClassifyChildByParentClassifyId(classifyIds []int, rootId int, levelStep int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
var pars []interface{}
|
|
|
pars = append(pars, rootId, levelStep)
|
|
|
pars = append(pars, classifyIds)
|
|
|
// 更新相关联的二级分类的parentId,和classify_name_second
|
|
|
sql := `UPDATE ai_predict_model_classify SET root_id = ?, level = level+? where ai_predict_model_classify_id IN (` + utils.GetOrmInReplace(len(classifyIds)) + `)`
|
|
|
- _, err = o.Raw(sql, pars).Exec()
|
|
|
+ err = o.Exec(sql, pars...).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -303,7 +297,7 @@ func UpdateAiPredictModelClassifyChildByParentClassifyId(classifyIds []int, root
|
|
|
|
|
|
// GetAiPredictModelIndexCountByClassifyId 获取目录下(包含子目录)的指标数量
|
|
|
func GetAiPredictModelIndexCountByClassifyId(classifyId int) (count int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
sql := `SELECT COUNT(1) AS count FROM ai_predict_model_index AS a
|
|
|
WHERE a.classify_id IN(
|
|
|
SELECT t.ai_predict_model_classify_id FROM
|
|
@@ -316,13 +310,13 @@ func GetAiPredictModelIndexCountByClassifyId(classifyId int) (count int, err err
|
|
|
UNION SELECT * FROM ai_predict_model_classify WHERE ai_predict_model_classify_id = @pid
|
|
|
)AS t
|
|
|
)`
|
|
|
- err = o.Raw(sql, classifyId).QueryRow(&count)
|
|
|
+ err = o.Raw(sql, classifyId).Scan(&count).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetAiPredictModelClassifyCountByClassifyId 获取目录下子目录数量
|
|
|
func GetAiPredictModelClassifyCountByClassifyId(chartClassifyId int) (count int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
sql := `SELECT COUNT(1) AS count FROM (
|
|
|
SELECT rd.*
|
|
|
FROM (SELECT * FROM ai_predict_model_classify WHERE parent_id IS NOT NULL) rd,
|
|
@@ -332,13 +326,13 @@ func GetAiPredictModelClassifyCountByClassifyId(chartClassifyId int) (count int,
|
|
|
UNION SELECT * FROM ai_predict_model_classify WHERE ai_predict_model_classify_id = @pid
|
|
|
)AS t
|
|
|
WHERE t.ai_predict_model_classify_id <> ?`
|
|
|
- err = o.Raw(sql, chartClassifyId, chartClassifyId).QueryRow(&count)
|
|
|
+ err = o.Raw(sql, chartClassifyId, chartClassifyId).Scan(&count).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// RemoveAiPredictModelClassify 删除分类及子分类
|
|
|
func RemoveAiPredictModelClassify(classifyId int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
sql := `DELETE FROM ai_predict_model_classify
|
|
|
WHERE ai_predict_model_classify_id IN(
|
|
|
SELECT t.ai_predict_model_classify_id FROM
|
|
@@ -351,6 +345,6 @@ func RemoveAiPredictModelClassify(classifyId int) (err error) {
|
|
|
UNION SELECT * FROM ai_predict_model_classify WHERE ai_predict_model_classify_id = @pid
|
|
|
)AS t
|
|
|
)`
|
|
|
- _, err = o.Raw(sql, classifyId).Exec()
|
|
|
+ err = o.Exec(sql, classifyId).Error
|
|
|
return
|
|
|
}
|