|
@@ -2,9 +2,9 @@ package data_manage
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
+ "eta_gn/eta_api/global"
|
|
|
"eta_gn/eta_api/utils"
|
|
|
"fmt"
|
|
|
- "github.com/beego/beego/v2/client/orm"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
@@ -53,12 +53,8 @@ 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)
|
|
|
+ err = global.DmSQL["data"].Create(m).Error
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -66,21 +62,21 @@ func (m *FactorEdbSeries) CreateMulti(items []*FactorEdbSeries) (err error) {
|
|
|
if len(items) == 0 {
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- _, err = o.InsertMulti(len(items), items)
|
|
|
+ err = global.DmSQL["data"].CreateInBatches(items, utils.MultiAddNum).Error
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *FactorEdbSeries) Update(cols []string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- _, err = o.Update(m, cols...)
|
|
|
+ err = global.DmSQL["data"].Select(cols).Updates(m).Error
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *FactorEdbSeries) Remove() (err error) {
|
|
|
- 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 = global.DmSQL["data"].Exec(sql, m.FactorEdbSeriesId).Error
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -88,9 +84,9 @@ 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()
|
|
|
+ err = global.DmSQL["data"].Exec(sql, ids).Error
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -98,39 +94,39 @@ func (m *FactorEdbSeries) RemoveByCondition(condition string, pars []interface{}
|
|
|
if condition == "" {
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
sql := fmt.Sprintf(`DELETE FROM %s WHERE %s`, m.TableName(), condition)
|
|
|
- _, err = o.Raw(sql, pars).Exec()
|
|
|
+ err = global.DmSQL["data"].Exec(sql, pars).Error
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *FactorEdbSeries) GetItemById(id int) (item *FactorEdbSeries, err error) {
|
|
|
- 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 = global.DmSQL["data"].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")
|
|
|
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.DmSQL["data"].Raw(sql, pars...).First(&item).Error
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *FactorEdbSeries) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
|
|
|
- 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 = global.DmSQL["data"].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 := global.DmSQL["data"]
|
|
|
fields := strings.Join(fieldArr, ",")
|
|
|
if len(fieldArr) == 0 {
|
|
|
fields = `*`
|
|
@@ -140,12 +136,12 @@ 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 = o.Raw(sql, pars...).Scan(&items).Error
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *FactorEdbSeries) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*FactorEdbSeries, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
fields := strings.Join(fieldArr, ",")
|
|
|
if len(fieldArr) == 0 {
|
|
|
fields = `*`
|
|
@@ -157,7 +153,8 @@ func (m *FactorEdbSeries) GetPageItemsByCondition(condition string, pars []inter
|
|
|
sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
|
|
|
pars = append(pars, startSize)
|
|
|
pars = append(pars, pageSize)
|
|
|
- _, err = o.Raw(sql, pars...).QueryRows(&items)
|
|
|
+ err = global.DmSQL["data"].Raw(sql, pars...).Scan(&items).Error
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -202,12 +199,7 @@ 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
|
|
|
- }
|
|
|
+ tx := global.DmSQL["data"].Begin()
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
_ = tx.Rollback()
|
|
@@ -216,24 +208,24 @@ func (m *FactorEdbSeries) CreateSeriesAndMapping(item *FactorEdbSeries, mappings
|
|
|
_ = tx.Commit()
|
|
|
}()
|
|
|
|
|
|
- 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
|
|
|
|
|
|
if len(mappings) > 0 {
|
|
|
for _, v := range mappings {
|
|
|
v.FactorEdbSeriesId = seriesId
|
|
|
}
|
|
|
- _, e = tx.InsertMulti(200, mappings)
|
|
|
+ e = tx.CreateInBatches(mappings, utils.MultiAddNum).Error
|
|
|
if e != nil {
|
|
|
err = fmt.Errorf("insert multi mapping err: %v", e)
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -243,12 +235,8 @@ 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 := global.DmSQL["data"]
|
|
|
+ tx := o.Begin()
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
_ = tx.Rollback()
|
|
@@ -257,7 +245,7 @@ func (m *FactorEdbSeries) EditSeriesAndMapping(item *FactorEdbSeries, mappings [
|
|
|
_ = tx.Commit()
|
|
|
}()
|
|
|
|
|
|
- _, e = tx.Update(item, updateCols...)
|
|
|
+ e := tx.Select(updateCols).Updates(item).Error
|
|
|
if e != nil {
|
|
|
err = fmt.Errorf("update series err: %v", e)
|
|
|
return
|
|
@@ -269,7 +257,7 @@ 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.Exec(sql, pars).Error
|
|
|
if e != nil {
|
|
|
err = fmt.Errorf("remove mapping err: %v", e)
|
|
|
return
|
|
@@ -279,12 +267,13 @@ func (m *FactorEdbSeries) EditSeriesAndMapping(item *FactorEdbSeries, mappings [
|
|
|
for _, v := range mappings {
|
|
|
v.FactorEdbSeriesId = item.FactorEdbSeriesId
|
|
|
}
|
|
|
- _, e = tx.InsertMulti(200, mappings)
|
|
|
+ e = tx.CreateInBatches(mappings, utils.MultiAddNum).Error
|
|
|
if e != nil {
|
|
|
err = fmt.Errorf("insert multi mapping err: %v", e)
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -364,12 +353,8 @@ func (a FactorEdbSeriesCorrelationMatrixOrder) Less(i, j int) bool {
|
|
|
|
|
|
// RemoveSeriesAndMappingByFactorEdbSeriesId 删除系列和指标关联
|
|
|
func (m *FactorEdbSeries) RemoveSeriesAndMappingByFactorEdbSeriesId(factorEdbSeriesChartMapping *FactorEdbSeriesChartMapping) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
- tx, e := o.Begin()
|
|
|
- if e != nil {
|
|
|
- err = fmt.Errorf("orm begin err: %v", e)
|
|
|
- return
|
|
|
- }
|
|
|
+ o := global.DmSQL["data"]
|
|
|
+ tx := o.Begin()
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
_ = tx.Rollback()
|
|
@@ -393,7 +378,7 @@ func (m *FactorEdbSeries) RemoveSeriesAndMappingByFactorEdbSeriesId(factorEdbSer
|
|
|
pars := make([]interface{}, 0)
|
|
|
pars = append(pars, factorEdbSeriesId)
|
|
|
sql := fmt.Sprintf(`DELETE FROM %s WHERE %s`, seriesOb.TableName(), cond)
|
|
|
- _, e = tx.Raw(sql, pars).Exec()
|
|
|
+ e := tx.Exec(sql, pars).Error
|
|
|
if e != nil {
|
|
|
err = fmt.Errorf("remove FactorEdbSeries err: %v", e)
|
|
|
return
|
|
@@ -405,7 +390,7 @@ func (m *FactorEdbSeries) RemoveSeriesAndMappingByFactorEdbSeriesId(factorEdbSer
|
|
|
pars1 := make([]interface{}, 0)
|
|
|
pars1 = append(pars1, factorEdbSeriesId)
|
|
|
sql = fmt.Sprintf(`DELETE FROM %s WHERE %s`, mappingOb.TableName(), cond1)
|
|
|
- _, e = tx.Raw(sql, pars1).Exec()
|
|
|
+ e = tx.Exec(sql, pars1).Error
|
|
|
if e != nil {
|
|
|
err = fmt.Errorf("remove mapping err: %v", e)
|
|
|
return
|
|
@@ -416,11 +401,12 @@ func (m *FactorEdbSeries) RemoveSeriesAndMappingByFactorEdbSeriesId(factorEdbSer
|
|
|
pars2 := make([]interface{}, 0)
|
|
|
pars2 = append(pars2, factorEdbSeriesId)
|
|
|
sql = fmt.Sprintf(`DELETE FROM %s WHERE %s`, dataOb.TableName(), cond2)
|
|
|
- _, e = tx.Raw(sql, pars2).Exec()
|
|
|
+ e = tx.Exec(sql, pars2).Error
|
|
|
if e != nil {
|
|
|
err = fmt.Errorf("remove mapping err: %v", e)
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|