|
@@ -1,10 +1,9 @@
|
|
|
package models
|
|
|
|
|
|
import (
|
|
|
- "errors"
|
|
|
+ "eta/eta_index_lib/global"
|
|
|
"eta/eta_index_lib/utils"
|
|
|
"fmt"
|
|
|
- "github.com/beego/beego/v2/client/orm"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
@@ -14,7 +13,8 @@ import (
|
|
|
type BaseFromFenwei struct{}
|
|
|
|
|
|
type BaseFromFenweiData struct {
|
|
|
- FenweiDataId int `orm:"column(fenwei_data_id);pk"`
|
|
|
+ FenweiDataId int `gorm:"column:fenwei_data_id;primaryKey"`
|
|
|
+ //enweiDataId int `orm:"column(fenwei_data_id);pk"`
|
|
|
FenweiIndexId int
|
|
|
IndexCode string
|
|
|
DataTime string
|
|
@@ -29,18 +29,19 @@ func (m *BaseFromFenweiData) TableName() string {
|
|
|
}
|
|
|
|
|
|
func GetBaseFromFenweiDataByCondition(condition string, pars []interface{}) (list []*BaseFromFenweiData, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
sql := `SELECT * FROM base_from_fenwei_data WHERE 1=1 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
- _, err = o.Raw(sql, pars).QueryRows(&list)
|
|
|
+ //_, err = o.Raw(sql, pars).QueryRows(&list)
|
|
|
+ err = global.DEFAULT_DB.Raw(sql, pars...).Find(&list).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// Add 添加
|
|
|
func (obj BaseFromFenwei) Add(edbCode string) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
|
|
|
var condition string
|
|
|
var pars []interface{}
|
|
@@ -72,7 +73,8 @@ func (obj BaseFromFenwei) Add(edbCode string) (err error) {
|
|
|
if isAdd {
|
|
|
addSql = strings.TrimRight(addSql, ",")
|
|
|
utils.FileLog.Info("addSql:" + addSql)
|
|
|
- _, err = o.Raw(addSql).Exec()
|
|
|
+ //_, err = o.Raw(addSql).Exec()
|
|
|
+ err = global.DEFAULT_DB.Exec(addSql).Error
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -83,7 +85,7 @@ func (obj BaseFromFenwei) Add(edbCode string) (err error) {
|
|
|
// Refresh 刷新汾渭数据指标数据
|
|
|
func (obj BaseFromFenwei) Refresh(edbInfoId int, edbCode, startDate string) (err error) {
|
|
|
source := obj.GetSource()
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -181,7 +183,8 @@ func (obj BaseFromFenwei) Refresh(edbInfoId int, edbCode, startDate string) (err
|
|
|
|
|
|
if isAdd {
|
|
|
addSql = strings.TrimRight(addSql, ",")
|
|
|
- _, err = o.Raw(addSql).Exec()
|
|
|
+ //_, err = o.Raw(addSql).Exec()
|
|
|
+ err = global.DEFAULT_DB.Exec(addSql).Error
|
|
|
if err != nil {
|
|
|
fmt.Println("RefreshEdbDataFromBaiinfo add Err", err.Error())
|
|
|
return
|
|
@@ -201,18 +204,19 @@ func (obj BaseFromFenwei) GetSourceName() string {
|
|
|
}
|
|
|
|
|
|
type BaseFromFenweiIndex struct {
|
|
|
- FenweiIndexId int64 `orm:"column(fenwei_index_id);pk"`
|
|
|
- IndexCode string
|
|
|
- IndexName string
|
|
|
- Frequency string
|
|
|
- Unit string
|
|
|
- ClassifyId int
|
|
|
- StartDate string
|
|
|
- EndDate string
|
|
|
- Sort int
|
|
|
- TerminalCode string
|
|
|
- CreateTime time.Time
|
|
|
- ModifyTime time.Time
|
|
|
+ FenweiIndexId int64 `gorm:"column:fenwei_index_id;primaryKey"`
|
|
|
+ //FenweiIndexId int64 `orm:"column(fenwei_index_id);pk"`
|
|
|
+ IndexCode string
|
|
|
+ IndexName string
|
|
|
+ Frequency string
|
|
|
+ Unit string
|
|
|
+ ClassifyId int
|
|
|
+ StartDate string
|
|
|
+ EndDate string
|
|
|
+ Sort int
|
|
|
+ TerminalCode string
|
|
|
+ CreateTime time.Time
|
|
|
+ ModifyTime time.Time
|
|
|
}
|
|
|
|
|
|
func (m *BaseFromFenweiIndex) TableName() string {
|
|
@@ -220,34 +224,42 @@ func (m *BaseFromFenweiIndex) TableName() string {
|
|
|
}
|
|
|
|
|
|
func (m *BaseFromFenweiIndex) Add() (lastId int64, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
- lastId, err = o.Insert(m)
|
|
|
+ //o := orm.NewOrm()
|
|
|
+ //lastId, err = o.Insert(m)
|
|
|
+ err = global.DEFAULT_DB.Create(&m).Error
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ lastId = int64(m.FenweiIndexId)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *BaseFromFenweiIndex) Update(updateCols []string) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
- _, err = o.Update(m, updateCols...)
|
|
|
+ //o := orm.NewOrm()
|
|
|
+ //_, err = o.Update(m, updateCols...)
|
|
|
+ err = global.DEFAULT_DB.Model(&m).Select(updateCols).Updates(&m).Error
|
|
|
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *BaseFromFenweiIndex) ModifyIndexMaxAndMinDate(indexCode string, item *EdbInfoMaxAndMinInfo) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
sql := ` UPDATE base_from_fenwei_index SET start_date=?,end_date=?,latest_value=?,modify_time=NOW() WHERE index_code=? `
|
|
|
- _, err = o.Raw(sql, item.MinDate, item.MaxDate, item.LatestValue, indexCode).Exec()
|
|
|
+ //_, err = o.Raw(sql, item.MinDate, item.MaxDate, item.LatestValue, indexCode).Exec()
|
|
|
+ err = global.DEFAULT_DB.Exec(sql, item.MinDate, item.MaxDate, item.LatestValue, indexCode).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *BaseFromFenweiIndex) GetByIndexCode(indexCode string) (item *BaseFromFenweiIndex, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
sql := ` SELECT * FROM base_from_fenwei_index WHERE index_code=? `
|
|
|
- err = o.Raw(sql, indexCode).QueryRow(&item)
|
|
|
+ //err = o.Raw(sql, indexCode).QueryRow(&item)
|
|
|
+ err = global.DEFAULT_DB.Raw(sql, indexCode).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *BaseFromFenweiIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromFenweiIndex, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
fields := strings.Join(fieldArr, ",")
|
|
|
if len(fieldArr) == 0 {
|
|
|
fields = `*`
|
|
@@ -257,12 +269,14 @@ func (m *BaseFromFenweiIndex) GetItemsByCondition(condition string, pars []inter
|
|
|
order = ` ORDER BY ` + orderRule
|
|
|
}
|
|
|
sql := fmt.Sprintf(`SELECT %s FROM base_from_fenwei_index WHERE 1=1 %s %s`, fields, condition, order)
|
|
|
- _, err = o.Raw(sql, pars).QueryRows(&items)
|
|
|
+ //_, err = o.Raw(sql, pars).QueryRows(&items)
|
|
|
+ err = global.DEFAULT_DB.Raw(sql, pars...).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
type BaseFromFenweiIndexList struct {
|
|
|
- FenweiIndexId int64 `orm:"column(fenwei_index_id);pk"`
|
|
|
+ //FenweiIndexId int64 `orm:"column(fenwei_index_id);pk"`
|
|
|
+ FenweiIndexId int64 `gorm:"column:fenwei_index_id;primaryKey"`
|
|
|
IndexCode string
|
|
|
IndexName string
|
|
|
Frequency string
|
|
@@ -276,15 +290,17 @@ type BaseFromFenweiIndexList struct {
|
|
|
}
|
|
|
|
|
|
func (y *BaseFromFenweiData) GetByIndexCode(indexCode string) (list []*BaseFromFenweiData, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
sql := ` SELECT * FROM base_from_fenwei_data WHERE index_code=? `
|
|
|
- _, err = o.Raw(sql, indexCode).QueryRows(&list)
|
|
|
+ //_, err = o.Raw(sql, indexCode).QueryRows(&list)
|
|
|
+ err = global.DEFAULT_DB.Raw(sql, indexCode).Find(&list).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (y *BaseFromFenweiData) AddMulti(item []*BaseFromFenweiData) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
- _, err = o.InsertMulti(1, item)
|
|
|
+ //o := orm.NewOrm()
|
|
|
+ //_, err = o.InsertMulti(1, item)
|
|
|
+ err = global.DEFAULT_DB.CreateInBatches(&item, 1).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -324,13 +340,15 @@ type HandleFenWeiNetDataReq struct {
|
|
|
}
|
|
|
|
|
|
func (y *BaseFromFenweiData) GetMaxAndMinDateByIndexCode(indexCode string) (item *EdbInfoMaxAndMinInfo, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
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 base_from_fenwei_data WHERE index_code=? `
|
|
|
- err = o.Raw(sql, indexCode).QueryRow(&item)
|
|
|
+ //err = o.Raw(sql, indexCode).QueryRow(&item)
|
|
|
+ err = global.DEFAULT_DB.Raw(sql, indexCode).First(&item).Error
|
|
|
// 获取最新值
|
|
|
var lastVal float64
|
|
|
sql = ` SELECT value AS latest_value FROM base_from_fenwei_data WHERE index_code = ? ORDER BY data_time DESC LIMIT 1 `
|
|
|
- err = o.Raw(sql, indexCode).QueryRow(&lastVal)
|
|
|
+ //err = o.Raw(sql, indexCode).QueryRow(&lastVal)
|
|
|
+ err = global.DEFAULT_DB.Raw(sql, indexCode).Scan(&lastVal).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -340,7 +358,8 @@ func (y *BaseFromFenweiData) GetMaxAndMinDateByIndexCode(indexCode string) (item
|
|
|
|
|
|
// BaseFromFenweiClassify 汾渭数据分类表
|
|
|
type BaseFromFenweiClassify struct {
|
|
|
- ClassifyId int `orm:"column(classify_id);pk"`
|
|
|
+ //ClassifyId int `orm:"column(classify_id);pk"`
|
|
|
+ ClassifyId int `gorm:"column:classify_id;primaryKey"`
|
|
|
ClassifyName string `description:"分类名称"`
|
|
|
ParentId int `description:"父级id"`
|
|
|
SysUserId int `description:"创建人id"`
|
|
@@ -352,32 +371,37 @@ type BaseFromFenweiClassify struct {
|
|
|
}
|
|
|
|
|
|
func (y *BaseFromFenweiClassify) Add() (lastId int64, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
- lastId, err = o.Insert(y)
|
|
|
+ //o := orm.NewOrm()
|
|
|
+ //lastId, err = o.Insert(y)
|
|
|
+ err = global.DEFAULT_DB.Create(&y).Error
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ lastId = int64(y.ClassifyId)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (y *BaseFromFenweiClassify) Update(updateCols []string) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
- _, err = o.Update(y, updateCols...)
|
|
|
-
|
|
|
+ //o := orm.NewOrm()
|
|
|
+ //_, err = o.Update(y, updateCols...)
|
|
|
+ err = global.DEFAULT_DB.Model(&y).Select(updateCols).Updates(&y).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (y *BaseFromFenweiClassify) GetByClassifyName(classifyName string) (item []*BaseFromFenweiClassify, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
sql := ` SELECT * FROM base_from_fenwei_classify WHERE classify_name=? `
|
|
|
- _, err = o.Raw(sql, classifyName).QueryRows(&item)
|
|
|
+ //_, err = o.Raw(sql, classifyName).QueryRows(&item)
|
|
|
|
|
|
- if errors.Is(err, orm.ErrNoRows) {
|
|
|
+ err = global.DEFAULT_DB.Raw(sql, classifyName).Find(&item).Error
|
|
|
+ if utils.IsErrNoRow(err) {
|
|
|
return nil, nil
|
|
|
}
|
|
|
-
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (y *BaseFromFenweiClassify) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromFenweiClassify, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
fields := strings.Join(fieldArr, ",")
|
|
|
if len(fieldArr) == 0 {
|
|
|
fields = `*`
|
|
@@ -387,7 +411,8 @@ func (y *BaseFromFenweiClassify) GetItemsByCondition(condition string, pars []in
|
|
|
order = ` ORDER BY ` + orderRule
|
|
|
}
|
|
|
sql := fmt.Sprintf(`SELECT %s FROM base_from_fenwei_classify WHERE 1=1 %s %s`, fields, condition, order)
|
|
|
- _, err = o.Raw(sql, pars).QueryRows(&items)
|
|
|
+ //_, err = o.Raw(sql, pars).QueryRows(&items)
|
|
|
+ err = global.DEFAULT_DB.Raw(sql, pars...).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -424,34 +449,37 @@ func MultiUpdateBaseFromFenweiDataValue(items []*BaseFromFenweiData) (err error)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- o := orm.NewOrm()
|
|
|
- sql := `UPDATE base_from_fenwei_data SET value = ?, modify_time = NOW() WHERE index_code = ? AND data_time = ? LIMIT 1`
|
|
|
- p, err := o.Raw(sql).Prepare()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
+ //o := orm.NewOrm()
|
|
|
+ to := global.DEFAULT_DB.Begin()
|
|
|
+
|
|
|
defer func() {
|
|
|
- _ = p.Close()
|
|
|
+ if err != nil {
|
|
|
+ _ = to.Rollback()
|
|
|
+ } else {
|
|
|
+ _ = to.Commit()
|
|
|
+ }
|
|
|
}()
|
|
|
+ sql := `UPDATE base_from_fenwei_data SET value = ?, modify_time = NOW() WHERE index_code = ? AND data_time = ? LIMIT 1`
|
|
|
for _, v := range items {
|
|
|
if v.IndexCode == "" || v.DataTime == "" {
|
|
|
continue
|
|
|
}
|
|
|
- _, err = p.Exec(v.Value, v.IndexCode, v.DataTime)
|
|
|
+ err = to.Exec(sql, v.Value, v.IndexCode, v.DataTime).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetBaseFromFenWeiIndexByIndexName 根据指标名称查询指标
|
|
|
func GetBaseFromFenWeiIndexByIndexName(indexName string) (item *BaseFromFenweiIndex, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
sql := ` SELECT * FROM base_from_fenwei_index WHERE index_name=? `
|
|
|
- err = o.Raw(sql, indexName).QueryRow(&item)
|
|
|
-
|
|
|
- if errors.Is(err, orm.ErrNoRows) {
|
|
|
+ //err = o.Raw(sql, indexName).QueryRow(&item)
|
|
|
+ err = global.DEFAULT_DB.Raw(sql, indexName).First(&item).Error
|
|
|
+ if utils.IsErrNoRow(err) {
|
|
|
return nil, nil
|
|
|
}
|
|
|
return
|
|
@@ -459,11 +487,11 @@ func GetBaseFromFenWeiIndexByIndexName(indexName string) (item *BaseFromFenweiIn
|
|
|
|
|
|
// GetBaseFromFenweiDataByIndexCodeAndDataTime 根据指标编码和dataTime查询指标数据
|
|
|
func GetBaseFromFenweiDataByIndexCodeAndDataTime(indexCode, dataTime string) (item *BaseFromFenweiData, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
sql := ` SELECT * FROM base_from_fenwei_data WHERE index_code=? AND data_time=? `
|
|
|
- err = o.Raw(sql, indexCode, dataTime).QueryRow(&item)
|
|
|
-
|
|
|
- if errors.Is(err, orm.ErrNoRows) {
|
|
|
+ //err = o.Raw(sql, indexCode, dataTime).QueryRow(&item)
|
|
|
+ err = global.DEFAULT_DB.Raw(sql, indexCode, dataTime).First(&item).Error
|
|
|
+ if utils.IsErrNoRow(err) {
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
@@ -476,25 +504,31 @@ func BatchAddBaseFromFenWeiData(items []*BaseFromFenweiData) (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- o := orm.NewOrm()
|
|
|
- _, err = o.InsertMulti(1, items)
|
|
|
+ //o := orm.NewOrm()
|
|
|
+ //_, err = o.InsertMulti(1, items)
|
|
|
+ err = global.DEFAULT_DB.CreateInBatches(items, 1).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// AddBaseFromFenWeiClassify 新增汾渭分类
|
|
|
func AddBaseFromFenWeiClassify(item *BaseFromFenweiClassify) (classifyId int64, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
- classifyId, err = o.Insert(item)
|
|
|
+ //o := orm.NewOrm()
|
|
|
+ //classifyId, err = o.Insert(item)
|
|
|
+ err = global.DEFAULT_DB.Create(&item).Error
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ classifyId = int64(item.ClassifyId)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetBaseFromFenWeiIndexByIndexCode 跟据指标编码查询指标信息
|
|
|
func GetBaseFromFenWeiIndexByIndexCode(indexCode string) (item *BaseFromFenweiIndex, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
sql := ` SELECT * FROM base_from_fenwei_index WHERE index_code=? `
|
|
|
- err = o.Raw(sql, indexCode).QueryRow(&item)
|
|
|
-
|
|
|
- if errors.Is(err, orm.ErrNoRows) {
|
|
|
+ //err = o.Raw(sql, indexCode).QueryRow(&item)
|
|
|
+ err = global.DEFAULT_DB.Raw(sql, indexCode).First(&item).Error
|
|
|
+ if utils.IsErrNoRow(err) {
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
@@ -503,7 +537,8 @@ func GetBaseFromFenWeiIndexByIndexCode(indexCode string) (item *BaseFromFenweiIn
|
|
|
|
|
|
// UpdateBaseFromFenweiData 更新汾渭数据
|
|
|
func UpdateBaseFromFenweiData(data *BaseFromFenweiData) error {
|
|
|
- o := orm.NewOrm()
|
|
|
- _, err := o.Update(data)
|
|
|
+ //o := orm.NewOrm()
|
|
|
+ //_, err := o.Update(data)
|
|
|
+ err := global.DEFAULT_DB.Save(&data).Error
|
|
|
return err
|
|
|
}
|