|
@@ -2,9 +2,9 @@ package data_manage
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
+ "eta/eta_chart_lib/global"
|
|
|
"eta/eta_chart_lib/utils"
|
|
|
"fmt"
|
|
|
- "github.com/beego/beego/v2/client/orm"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
@@ -17,7 +17,8 @@ const (
|
|
|
|
|
|
// FactorEdbSeries 因子指标系列表
|
|
|
type FactorEdbSeries struct {
|
|
|
- FactorEdbSeriesId int `orm:"column(factor_edb_series_id);pk"`
|
|
|
+ //FactorEdbSeriesId int `orm:"column(factor_edb_series_id);pk"`
|
|
|
+ FactorEdbSeriesId int `gorm:"column:factor_edb_series_id;primaryKey"`
|
|
|
SeriesName string `description:"系列名称"`
|
|
|
EdbInfoType int `description:"关联指标类型:0-普通指标;1-预测指标"`
|
|
|
CalculateStep string `description:"计算步骤-JSON"`
|
|
@@ -53,12 +54,13 @@ func (m *FactorEdbSeries) Cols() FactorEdbSeriesCols {
|
|
|
}
|
|
|
|
|
|
func (m *FactorEdbSeries) Create() (err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- id, err := o.Insert(m)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- m.FactorEdbSeriesId = int(id)
|
|
|
+ //o := orm.NewOrmUsingDB("data")
|
|
|
+ //id, err := o.Insert(m)
|
|
|
+ //if err != nil {
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //m.FactorEdbSeriesId = int(id)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Create(&m).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -66,21 +68,24 @@ func (m *FactorEdbSeries) CreateMulti(items []*FactorEdbSeries) (err error) {
|
|
|
if len(items) == 0 {
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- _, err = o.InsertMulti(len(items), items)
|
|
|
+ //o := orm.NewOrmUsingDB("data")
|
|
|
+ //_, err = o.InsertMulti(len(items), items)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].CreateInBatches(items, len(items)).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *FactorEdbSeries) Update(cols []string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- _, err = o.Update(m, cols...)
|
|
|
+ //o := orm.NewOrmUsingDB("data")
|
|
|
+ //_, err = o.Update(m, cols...)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Model(&m).Select(cols).Updates(&m).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *FactorEdbSeries) Remove() (err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //o := orm.NewOrmUsingDB("data")
|
|
|
sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
|
|
|
- _, err = o.Raw(sql, m.FactorEdbSeriesId).Exec()
|
|
|
+ //_, err = o.Raw(sql, m.FactorEdbSeriesId).Exec()
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Exec(sql, m.FactorEdbSeriesId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -88,39 +93,44 @@ func (m *FactorEdbSeries) MultiRemove(ids []int) (err error) {
|
|
|
if len(ids) == 0 {
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- 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()
|
|
|
+ //o := orm.NewOrmUsingDB("data")
|
|
|
+ //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()
|
|
|
+ sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN ?`, m.TableName(), m.Cols().PrimaryId)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Exec(sql, ids).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *FactorEdbSeries) GetItemById(id int) (item *FactorEdbSeries, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //o := orm.NewOrmUsingDB("data")
|
|
|
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).QueryRow(&item)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, id).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *FactorEdbSeries) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *FactorEdbSeries, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //o := orm.NewOrmUsingDB("data")
|
|
|
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 = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).First(&item).Error
|
|
|
+ //err = o.Raw(sql, pars).QueryRow(&item)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *FactorEdbSeries) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //o := orm.NewOrmUsingDB("data")
|
|
|
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).QueryRow(&count)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).Scan(&count).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *FactorEdbSeries) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*FactorEdbSeries, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //o := orm.NewOrmUsingDB("data")
|
|
|
fields := strings.Join(fieldArr, ",")
|
|
|
if len(fieldArr) == 0 {
|
|
|
fields = `*`
|
|
@@ -130,12 +140,13 @@ func (m *FactorEdbSeries) GetItemsByCondition(condition string, pars []interface
|
|
|
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 = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).Find(&items).Error
|
|
|
+ //_, err = o.Raw(sql, pars).QueryRows(&items)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *FactorEdbSeries) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*FactorEdbSeries, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //o := orm.NewOrmUsingDB("data")
|
|
|
fields := strings.Join(fieldArr, ",")
|
|
|
if len(fieldArr) == 0 {
|
|
|
fields = `*`
|
|
@@ -145,7 +156,9 @@ func (m *FactorEdbSeries) GetPageItemsByCondition(condition string, pars []inter
|
|
|
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)
|
|
|
+ //_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
|
|
|
+ pars = append(pars, startSize, pageSize)
|
|
|
+ err = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -190,12 +203,13 @@ func (m *FactorEdbSeries) CreateSeriesAndMapping(item *FactorEdbSeries, mappings
|
|
|
err = fmt.Errorf("series is nil")
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- tx, e := o.Begin()
|
|
|
- if e != nil {
|
|
|
- err = fmt.Errorf("orm begin err: %v", e)
|
|
|
- return
|
|
|
- }
|
|
|
+ //o := orm.NewOrmUsingDB("data")
|
|
|
+ //tx, e := o.Begin()
|
|
|
+ tx := global.DbMap[utils.DbNameIndex].Begin()
|
|
|
+ //if e != nil {
|
|
|
+ // err = fmt.Errorf("orm begin err: %v", e)
|
|
|
+ // return
|
|
|
+ //}
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
_ = tx.Rollback()
|
|
@@ -204,19 +218,21 @@ func (m *FactorEdbSeries) CreateSeriesAndMapping(item *FactorEdbSeries, mappings
|
|
|
_ = tx.Commit()
|
|
|
}()
|
|
|
|
|
|
- id, e := tx.Insert(item)
|
|
|
+ //id, e := tx.Insert(item)
|
|
|
+ e := tx.Create(&item).Error
|
|
|
if e != nil {
|
|
|
err = fmt.Errorf("insert series err: %v", e)
|
|
|
return
|
|
|
}
|
|
|
- seriesId = int(id)
|
|
|
- item.FactorEdbSeriesId = seriesId
|
|
|
+ //seriesId = int(id)
|
|
|
+ //item.FactorEdbSeriesId = seriesId
|
|
|
|
|
|
if len(mappings) > 0 {
|
|
|
for _, v := range mappings {
|
|
|
v.FactorEdbSeriesId = seriesId
|
|
|
}
|
|
|
- _, e = tx.InsertMulti(200, mappings)
|
|
|
+ e = tx.CreateInBatches(mappings, 200).Error
|
|
|
+ //_, e = tx.InsertMulti(200, mappings)
|
|
|
if e != nil {
|
|
|
err = fmt.Errorf("insert multi mapping err: %v", e)
|
|
|
return
|
|
@@ -231,12 +247,13 @@ func (m *FactorEdbSeries) EditSeriesAndMapping(item *FactorEdbSeries, mappings [
|
|
|
err = fmt.Errorf("series is nil")
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- tx, e := o.Begin()
|
|
|
- if e != nil {
|
|
|
- err = fmt.Errorf("orm begin err: %v", e)
|
|
|
- return
|
|
|
- }
|
|
|
+ //o := orm.NewOrmUsingDB("data")
|
|
|
+ //tx, e := o.Begin()
|
|
|
+ //if e != nil {
|
|
|
+ // err = fmt.Errorf("orm begin err: %v", e)
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ tx := global.DbMap[utils.DbNameIndex].Begin()
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
_ = tx.Rollback()
|
|
@@ -245,7 +262,8 @@ func (m *FactorEdbSeries) EditSeriesAndMapping(item *FactorEdbSeries, mappings [
|
|
|
_ = tx.Commit()
|
|
|
}()
|
|
|
|
|
|
- _, e = tx.Update(item, updateCols...)
|
|
|
+ //_, e = tx.Update(item, updateCols...)
|
|
|
+ e := tx.Model(&item).Select(updateCols).Updates(&item).Error
|
|
|
if e != nil {
|
|
|
err = fmt.Errorf("update series err: %v", e)
|
|
|
return
|
|
@@ -257,7 +275,8 @@ func (m *FactorEdbSeries) EditSeriesAndMapping(item *FactorEdbSeries, mappings [
|
|
|
pars := make([]interface{}, 0)
|
|
|
pars = append(pars, item.FactorEdbSeriesId)
|
|
|
sql := fmt.Sprintf(`DELETE FROM %s WHERE %s`, mappingOb.TableName(), cond)
|
|
|
- _, e = tx.Raw(sql, pars).Exec()
|
|
|
+ //_, e = tx.Raw(sql, pars).Exec()
|
|
|
+ e = tx.Exec(sql, pars...).Error
|
|
|
if e != nil {
|
|
|
err = fmt.Errorf("remove mapping err: %v", e)
|
|
|
return
|
|
@@ -267,7 +286,8 @@ func (m *FactorEdbSeries) EditSeriesAndMapping(item *FactorEdbSeries, mappings [
|
|
|
for _, v := range mappings {
|
|
|
v.FactorEdbSeriesId = item.FactorEdbSeriesId
|
|
|
}
|
|
|
- _, e = tx.InsertMulti(200, mappings)
|
|
|
+ //_, e = tx.InsertMulti(200, mappings)
|
|
|
+ e = tx.CreateInBatches(mappings, 200).Error
|
|
|
if e != nil {
|
|
|
err = fmt.Errorf("insert multi mapping err: %v", e)
|
|
|
return
|