|
@@ -2,9 +2,9 @@ package data_manage
|
|
|
|
|
|
import (
|
|
|
"errors"
|
|
|
+ "eta_gn/eta_task/global"
|
|
|
"eta_gn/eta_task/utils"
|
|
|
"fmt"
|
|
|
- "github.com/beego/beego/v2/client/orm"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
)
|
|
@@ -65,7 +65,7 @@ type EdbInfoSearchDataV1 struct {
|
|
|
}
|
|
|
|
|
|
func GetEdbInfoByCondition(condition string, pars []interface{}, order int) (item []*EdbInfoList, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
sql := ` SELECT * FROM edb_info WHERE 1=1 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
@@ -75,14 +75,18 @@ func GetEdbInfoByCondition(condition string, pars []interface{}, order int) (ite
|
|
|
} else {
|
|
|
sql += ` ORDER BY edb_info_id ASC `
|
|
|
}
|
|
|
- _, err = o.Raw(sql, pars).QueryRows(&item)
|
|
|
+ //_, err = o.Raw(sql, pars).QueryRows(&item)
|
|
|
+
|
|
|
+ err = global.DEFAULT_DmSQL.Raw(sql, pars).Find(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func ModifyEdbDataInfoDate(edbInfoId int, maxDate string) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
sql := ` UPDATE edb_info SET end_date=?,modify_time=NOW() WHERE edb_info_id=? `
|
|
|
- _, err = o.Raw(sql, maxDate, edbInfoId).Exec()
|
|
|
+ //_, err = o.Raw(sql, maxDate, edbInfoId).Exec()
|
|
|
+
|
|
|
+ err = global.DEFAULT_DmSQL.Exec(sql, maxDate, edbInfoId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -95,7 +99,7 @@ type EdbInfoMaxAndMinInfo struct {
|
|
|
}
|
|
|
|
|
|
func GetEdbInfoMaxAndMinInfo(source, subSource int, edbCode string) (item *EdbInfoMaxAndMinInfo, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
sql := ``
|
|
|
tableName := GetEdbDataTableName(source, subSource)
|
|
|
if tableName == "" {
|
|
@@ -104,26 +108,30 @@ func GetEdbInfoMaxAndMinInfo(source, subSource int, edbCode string) (item *EdbIn
|
|
|
}
|
|
|
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 %s WHERE edb_code=? `
|
|
|
sql = fmt.Sprintf(sql, tableName)
|
|
|
- err = o.Raw(sql, edbCode).QueryRow(&item)
|
|
|
+ //err = o.Raw(sql, edbCode).QueryRow(&item)
|
|
|
|
|
|
+ err = global.DEFAULT_DmSQL.Raw(sql, edbCode).First(&item).Error
|
|
|
var latest_value float64
|
|
|
sql = ` SELECT value AS latest_value FROM %s WHERE edb_code=? ORDER BY data_time DESC LIMIT 1 `
|
|
|
sql = fmt.Sprintf(sql, tableName)
|
|
|
- err = o.Raw(sql, edbCode).QueryRow(&latest_value)
|
|
|
+ //err = o.Raw(sql, edbCode).QueryRow(&latest_value)
|
|
|
+ err = global.DEFAULT_DmSQL.Raw(sql, edbCode).First(&latest_value).Error
|
|
|
item.LatestValue = latest_value
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func ModifyEdbInfoMaxAndMinInfo(edbInfoId int, item *EdbInfoMaxAndMinInfo) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
sql := ` UPDATE edb_info SET start_date=?,end_date=?,min_value=?,max_value=?,is_update=2,latest_date=?,latest_value=?,modify_time=NOW() WHERE edb_info_id=? `
|
|
|
- _, err = o.Raw(sql, item.MinDate, item.MaxDate, item.MinValue, item.MaxValue, item.MaxDate, item.LatestValue, edbInfoId).Exec()
|
|
|
+ //_, err = o.Raw(sql, item.MinDate, item.MaxDate, item.MinValue, item.MaxValue, item.MaxDate, item.LatestValue, edbInfoId).Exec()
|
|
|
+
|
|
|
+ err = global.DEFAULT_DmSQL.Exec(sql, item.MinDate, item.MaxDate, item.MinValue, item.MaxValue, item.MaxDate, item.LatestValue, edbInfoId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//order:1升序,其余值为降序
|
|
|
func GetEdbDataListAll(condition string, pars []interface{}, source, subSource, order int) (item []*EdbInfoSearchData, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
sql := ``
|
|
|
tableName := GetEdbDataTableName(source, subSource)
|
|
|
sql = ` SELECT * FROM %s WHERE 1=1 `
|
|
@@ -137,12 +145,14 @@ func GetEdbDataListAll(condition string, pars []interface{}, source, subSource,
|
|
|
} else {
|
|
|
sql += ` ORDER BY data_time DESC `
|
|
|
}
|
|
|
- _, err = o.Raw(sql, pars).QueryRows(&item)
|
|
|
+ //_, err = o.Raw(sql, pars).QueryRows(&item)
|
|
|
+
|
|
|
+ err = global.DEFAULT_DmSQL.Raw(sql, pars).Find(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetEdbDataListAllV1(condition string, pars []interface{}, source, subSource, order int) (item []*EdbInfoSearchDataV1, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
sql := ``
|
|
|
tableName := GetEdbDataTableName(source, subSource)
|
|
|
sql = ` SELECT * FROM %s WHERE 1=1 `
|
|
@@ -156,39 +166,47 @@ func GetEdbDataListAllV1(condition string, pars []interface{}, source, subSource
|
|
|
} else {
|
|
|
sql += ` ORDER BY data_time DESC `
|
|
|
}
|
|
|
- _, err = o.Raw(sql, pars).QueryRows(&item)
|
|
|
+ //_, err = o.Raw(sql, pars).QueryRows(&item)
|
|
|
+
|
|
|
+ err = global.DEFAULT_DmSQL.Raw(sql, pars).Find(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetEdbInfoById(edbInfoId int) (item *EdbInfo, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
sql := ` SELECT * FROM edb_info WHERE edb_info_id=? `
|
|
|
- err = o.Raw(sql, edbInfoId).QueryRow(&item)
|
|
|
+ //err = o.Raw(sql, edbInfoId).QueryRow(&item)
|
|
|
+
|
|
|
+ err = global.DEFAULT_DmSQL.Raw(sql, edbInfoId).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetQuarterEdbInfo() (item []*EdbInfo, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
sql := ` SELECT c.* FROM chart_info AS a
|
|
|
INNER JOIN chart_edb_mapping AS b ON a.chart_info_id=b.chart_info_id
|
|
|
INNER JOIN edb_info AS c ON b.edb_info_id=c.edb_info_id
|
|
|
WHERE a.chart_type=2
|
|
|
GROUP BY b.edb_info_id
|
|
|
ORDER BY b.edb_info_id ASC `
|
|
|
- _, err = o.Raw(sql).QueryRows(&item)
|
|
|
+ //_, err = o.Raw(sql).QueryRows(&item)
|
|
|
+
|
|
|
+ err = global.DEFAULT_DmSQL.Raw(sql).Find(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func ResetEdbInfoIsUpdate() (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
sql := ` UPDATE edb_info SET is_update=1 `
|
|
|
- _, err = o.Raw(sql).Exec()
|
|
|
+ //_, err = o.Raw(sql).Exec()
|
|
|
+
|
|
|
+ err = global.DEFAULT_DmSQL.Exec(sql).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetEdbInfoCalculateListByCondition 获取指标关系列表
|
|
|
func GetEdbInfoCalculateListByCondition(condition string, pars []interface{}) (items []*EdbInfoCalculateMapping, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
//calculateTableName := GetEdbInfoCalculateTableName(source)
|
|
|
//if calculateTableName == "" {
|
|
|
// err = errors.New("无效的表名")
|
|
@@ -200,7 +218,9 @@ func GetEdbInfoCalculateListByCondition(condition string, pars []interface{}) (i
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
- _, err = o.Raw(sql, pars).QueryRows(&items)
|
|
|
+ //_, err = o.Raw(sql, pars).QueryRows(&items)
|
|
|
+
|
|
|
+ err = global.DEFAULT_DmSQL.Raw(sql).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -209,8 +229,9 @@ func DeleteEdbDataByIdAndSource(edbDataId, source, subSource int) (err error) {
|
|
|
tableName := GetEdbDataTableName(source, subSource)
|
|
|
sql = fmt.Sprintf(sql, tableName)
|
|
|
|
|
|
- o := orm.NewOrm()
|
|
|
- _, err = o.Raw(sql, edbDataId).Exec()
|
|
|
+ //o := orm.NewOrm()
|
|
|
+ //_, err = o.Raw(sql, edbDataId).Exec()
|
|
|
+ err = global.DEFAULT_DmSQL.Exec(sql, edbDataId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -236,14 +257,15 @@ type EdbInfoClassify struct {
|
|
|
// @return item []*EdbInfoUpdateLog
|
|
|
// @return err error
|
|
|
func GetAllEdbInfoClassifyListByCondition(condition string, pars []interface{}) (item []*EdbInfoClassify, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT * FROM edb_info WHERE 1=1 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
sql += `ORDER BY edb_info_id ASC `
|
|
|
- _, err = o.Raw(sql, pars).QueryRows(&item)
|
|
|
+ //_, err = o.Raw(sql, pars).QueryRows(&item)
|
|
|
|
|
|
+ err = global.DmSQL["data"].Raw(sql, pars).Find(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -256,10 +278,11 @@ func GetAllEdbInfoClassifyListByCondition(condition string, pars []interface{})
|
|
|
// @return item *EdbInfo
|
|
|
// @return err error
|
|
|
func GetEdbInfoItemByCodeAndSource(source int, edbCode string) (item *EdbInfoItem, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
sql := ` SELECT * FROM edb_info WHERE edb_code=? AND source = ?`
|
|
|
- err = o.Raw(sql, source, edbCode).QueryRow(&item)
|
|
|
+ //err = o.Raw(sql, source, edbCode).QueryRow(&item)
|
|
|
|
|
|
+ err = global.DEFAULT_DmSQL.Raw(sql, source, edbCode).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -272,7 +295,7 @@ func GetEdbInfoItemByCodeAndSource(source int, edbCode string) (item *EdbInfoIte
|
|
|
// @return modifyTime string
|
|
|
// @return err error
|
|
|
func GetEdbInfoMaxModifyTime(source, subSource int, edbCode string) (modifyTime string, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //o := orm.NewOrmUsingDB("data")
|
|
|
tableName := GetEdbDataTableName(source, subSource)
|
|
|
if tableName == "" {
|
|
|
err = errors.New("无效的表名称:source:" + strconv.Itoa(source))
|
|
@@ -281,29 +304,35 @@ func GetEdbInfoMaxModifyTime(source, subSource int, edbCode string) (modifyTime
|
|
|
|
|
|
sql := ` SELECT MAX(modify_time) AS modify_time FROM %s WHERE edb_code=? `
|
|
|
sql = fmt.Sprintf(sql, tableName)
|
|
|
- err = o.Raw(sql, edbCode).QueryRow(&modifyTime)
|
|
|
+ //err = o.Raw(sql, edbCode).QueryRow(&modifyTime)
|
|
|
+
|
|
|
+ err = global.DmSQL["data"].Raw(sql, edbCode).Scan(&modifyTime).Error
|
|
|
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetEdbInfoPageByCondition(condition string, pars []interface{}, startPage, pageSize int) (item []*EdbInfo, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
sql := ` SELECT * FROM edb_info WHERE 1=1 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
sql += ` LIMIT ?,? `
|
|
|
- _, err = o.Raw(sql, pars, startPage, pageSize).QueryRows(&item)
|
|
|
+ //_, err = o.Raw(sql, pars, startPage, pageSize).QueryRows(&item)
|
|
|
+
|
|
|
+ err = global.DEFAULT_DmSQL.Raw(sql, pars, startPage, pageSize).Find(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetEdbInfoCountByCondition(condition string, pars []interface{}) (total int64, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
sql := ` SELECT count(*) FROM edb_info WHERE 1=1 `
|
|
|
if condition != "" {
|
|
|
sql += condition
|
|
|
}
|
|
|
- err = o.Raw(sql, pars).QueryRow(&total)
|
|
|
+ //err = o.Raw(sql, pars).QueryRow(&total)
|
|
|
+
|
|
|
+ err = global.DEFAULT_DmSQL.Raw(sql, pars).Scan(&total).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -312,7 +341,9 @@ func ModifyEdbUpdateStatus(edbIdList []int, indexCodeList []string, calculateEdb
|
|
|
if idNum <= 0 {
|
|
|
return
|
|
|
}
|
|
|
- o, err := orm.NewOrmUsingDB("data").Begin()
|
|
|
+ //o, err := orm.NewOrmUsingDB("data").Begin()
|
|
|
+
|
|
|
+ o := global.DmSQL["data"].Begin()
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -326,7 +357,8 @@ func ModifyEdbUpdateStatus(edbIdList []int, indexCodeList []string, calculateEdb
|
|
|
|
|
|
// 更改指标的更新状态
|
|
|
sql := ` UPDATE edb_info SET no_update = 1 WHERE source in (?, ?) AND edb_info_id IN (` + utils.GetOrmInReplace(idNum) + `) AND no_update = 0`
|
|
|
- _, err = o.Raw(sql, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_WIND, edbIdList).Exec()
|
|
|
+ //_, err = o.Raw(sql, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_WIND, edbIdList).Exec()
|
|
|
+ err = o.Exec(sql, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_WIND, edbIdList).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -335,7 +367,8 @@ func ModifyEdbUpdateStatus(edbIdList []int, indexCodeList []string, calculateEdb
|
|
|
if len(indexCodeList) > 0 {
|
|
|
// 更改数据源的更新状态
|
|
|
sql = ` UPDATE base_from_mysteel_chemical_index SET is_stop = 1 WHERE index_code IN (` + utils.GetOrmInReplace(len(indexCodeList)) + `) and is_stop=0`
|
|
|
- _, err = o.Raw(sql, indexCodeList).Exec()
|
|
|
+ //_, err = o.Raw(sql, indexCodeList).Exec()
|
|
|
+ err = o.Exec(sql, indexCodeList).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -345,7 +378,8 @@ func ModifyEdbUpdateStatus(edbIdList []int, indexCodeList []string, calculateEdb
|
|
|
if len(calculateEdbInfoIds) > 0 {
|
|
|
// 批量更新相关联的指标ID
|
|
|
sql = ` UPDATE edb_info SET no_update = 1 WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(calculateEdbInfoIds)) + `) AND no_update = 0`
|
|
|
- _, err = o.Raw(sql, calculateEdbInfoIds).Exec()
|
|
|
+ //_, err = o.Raw(sql, calculateEdbInfoIds).Exec()
|
|
|
+ err = o.Exec(sql, calculateEdbInfoIds).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -359,8 +393,9 @@ func GetEdbInfoByIdList(edbInfoIdList []int) (items []*EdbInfo, err error) {
|
|
|
if num <= 0 {
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ //o := orm.NewOrmUsingDB("data")
|
|
|
sql := ` SELECT * FROM edb_info WHERE edb_info_id in (` + utils.GetOrmInReplace(num) + `) `
|
|
|
- _, err = o.Raw(sql, edbInfoIdList).QueryRows(&items)
|
|
|
+ //_, err = o.Raw(sql, edbInfoIdList).QueryRows(&items)
|
|
|
+ err = global.DmSQL["data"].Raw(sql, edbInfoIdList).Find(&items).Error
|
|
|
return
|
|
|
}
|