|
@@ -1,14 +1,15 @@
|
|
|
package data_manage
|
|
|
|
|
|
import (
|
|
|
+ "eta/eta_api/global"
|
|
|
"eta/eta_api/utils"
|
|
|
- "github.com/beego/beego/v2/client/orm"
|
|
|
- "github.com/rdlucklib/rdluck_tools/paging"
|
|
|
"time"
|
|
|
+
|
|
|
+ "github.com/rdlucklib/rdluck_tools/paging"
|
|
|
)
|
|
|
|
|
|
type EdbInfoRelation struct {
|
|
|
- EdbInfoRelationId int `orm:"column(edb_info_relation_id);pk"`
|
|
|
+ EdbInfoRelationId int `orm:"column(edb_info_relation_id);pk" gorm:"primaryKey"`
|
|
|
EdbInfoId int `description:"指标id"`
|
|
|
Source int `description:"来源:1:同花顺,2:wind,3:彭博,4:指标运算,5:累计值转月,6:同比值,7:同差值,8:N数值移动平均计算,9:手工指标,10:隆众"`
|
|
|
EdbName string `description:"指标名称"`
|
|
@@ -32,41 +33,41 @@ func (e *EdbInfoRelation) TableName() string {
|
|
|
|
|
|
// GetEdbInfoRelationByRelationIds 查询引用的指标ID
|
|
|
func GetEdbInfoRelationByRelationIds(ids []int) (items []*EdbInfoRelation, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
msql := ` SELECT * FROM edb_info_relation WHERE edb_info_relation_id in (` + utils.GetOrmInReplace(len(ids)) + `) `
|
|
|
- _, err = o.Raw(msql, ids).QueryRows(&items)
|
|
|
+ err = o.Raw(msql, ids).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetEdbInfoRelationByReferObjectId 查询直接引用的指标ID
|
|
|
func GetEdbInfoRelationByReferObjectId(referObjectId int, referObjectType int) (items []*EdbInfoRelation, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
msql := ` SELECT * FROM edb_info_relation WHERE refer_object_id =? and relation_type=0 AND refer_object_type=? GROUP BY edb_info_id `
|
|
|
- _, err = o.Raw(msql, referObjectId, referObjectType).QueryRows(&items)
|
|
|
+ err = o.Raw(msql, referObjectId, referObjectType).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetEdbInfoRelationByReferObjectIds 查询引用的指标ID
|
|
|
func GetEdbInfoRelationByReferObjectIds(referObjectIds []int, referObjectType int) (items []*EdbInfoRelation, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
msql := ` SELECT * FROM edb_info_relation WHERE refer_object_id in (` + utils.GetOrmInReplace(len(referObjectIds)) + `) AND refer_object_type=? and relation_type=0`
|
|
|
- _, err = o.Raw(msql, referObjectIds, referObjectType).QueryRows(&items)
|
|
|
+ err = o.Raw(msql, referObjectIds, referObjectType).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetEdbInfoRelationAllByReferObjectIds 查询引用的指标ID
|
|
|
func GetEdbInfoRelationAllByReferObjectIds(referObjectIds []int, referObjectType int) (items []*EdbInfoRelation, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
msql := ` SELECT * FROM edb_info_relation WHERE refer_object_id in (` + utils.GetOrmInReplace(len(referObjectIds)) + `) AND refer_object_type=?`
|
|
|
- _, err = o.Raw(msql, referObjectIds, referObjectType).QueryRows(&items)
|
|
|
+ err = o.Raw(msql, referObjectIds, referObjectType).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 新增记录
|
|
|
func AddOrUpdateEdbInfoRelation(objectId, objectType int, relationList []*EdbInfoRelation, deleteEdbInfoIds []int, refreshEdbInfoIds []int, indexCodeList []string) (err error) {
|
|
|
- o, err := orm.NewOrmUsingDB("data").Begin()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
+ o := global.DbMap[utils.DbNameIndex].Begin()
|
|
|
+ if o.Error != nil {
|
|
|
+ return o.Error
|
|
|
}
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
@@ -78,13 +79,13 @@ func AddOrUpdateEdbInfoRelation(objectId, objectType int, relationList []*EdbInf
|
|
|
|
|
|
if len(deleteEdbInfoIds) > 0 {
|
|
|
sql := ` DELETE FROM edb_info_relation WHERE refer_object_id = ? AND refer_object_type=? AND edb_info_id in (` + utils.GetOrmInReplace(len(deleteEdbInfoIds)) + `) AND relation_type=0`
|
|
|
- _, err = o.Raw(sql, objectId, objectType, deleteEdbInfoIds).Exec()
|
|
|
+ err = o.Exec(sql, objectId, objectType, deleteEdbInfoIds).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
// 同时删除相关连的间接引用的指标ID
|
|
|
sql = ` DELETE FROM edb_info_relation WHERE refer_object_id = ? AND refer_object_type=? AND root_edb_info_id in (` + utils.GetOrmInReplace(len(deleteEdbInfoIds)) + `) AND relation_type=1 `
|
|
|
- _, err = o.Raw(sql, objectId, objectType, deleteEdbInfoIds).Exec()
|
|
|
+ err = o.Exec(sql, objectId, objectType, deleteEdbInfoIds).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -96,7 +97,7 @@ func AddOrUpdateEdbInfoRelation(objectId, objectType int, relationList []*EdbInf
|
|
|
relationCodesMap[relation.RelationCode] = struct{}{}
|
|
|
}
|
|
|
}
|
|
|
- _, err = o.InsertMulti(len(relationList), relationList)
|
|
|
+ err = o.CreateInBatches(relationList, utils.MultiAddNum).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -105,7 +106,7 @@ func AddOrUpdateEdbInfoRelation(objectId, objectType int, relationList []*EdbInf
|
|
|
if len(refreshEdbInfoIds) > 0 {
|
|
|
//todo 是否需要所有指标的刷新状态
|
|
|
sql := ` UPDATE edb_info SET no_update = 0, set_update_time=? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(refreshEdbInfoIds)) + `) `
|
|
|
- _, err = o.Raw(sql, time.Now(), refreshEdbInfoIds).Exec()
|
|
|
+ err = o.Exec(sql, time.Now(), refreshEdbInfoIds).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -115,7 +116,7 @@ func AddOrUpdateEdbInfoRelation(objectId, objectType int, relationList []*EdbInf
|
|
|
if len(indexCodeList) > 0 {
|
|
|
// 更改数据源的更新状态
|
|
|
sql := ` UPDATE base_from_mysteel_chemical_index SET is_stop = 0 WHERE index_code IN (` + utils.GetOrmInReplace(len(indexCodeList)) + `) and is_stop=1`
|
|
|
- _, err = o.Raw(sql, indexCodeList).Exec()
|
|
|
+ err = o.Exec(sql, indexCodeList).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -134,7 +135,7 @@ SET e1.parent_relation_id = e2.edb_info_relation_id
|
|
|
WHERE
|
|
|
e1.relation_type = 1
|
|
|
AND e2.relation_type = 0 AND e1.parent_relation_id !=e2.edb_info_relation_id AND e1.relation_code in (` + utils.GetOrmInReplace(len(relationCodes)) + `)`
|
|
|
- _, err = o.Raw(sql, relationCodes).Exec()
|
|
|
+ err = o.Exec(sql, relationCodes).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -145,9 +146,9 @@ WHERE
|
|
|
|
|
|
// 新增记录
|
|
|
func AddOrUpdateEdbInfoRelationMulti(relationList []*EdbInfoRelation, refreshEdbInfoIds []int, indexCodeList []string) (err error) {
|
|
|
- o, err := orm.NewOrmUsingDB("data").Begin()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
+ o := global.DbMap[utils.DbNameIndex].Begin()
|
|
|
+ if o.Error != nil {
|
|
|
+ return o.Error
|
|
|
}
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
@@ -164,7 +165,7 @@ func AddOrUpdateEdbInfoRelationMulti(relationList []*EdbInfoRelation, refreshEdb
|
|
|
relationCodesMap[relation.RelationCode] = struct{}{}
|
|
|
}
|
|
|
}
|
|
|
- _, err = o.InsertMulti(len(relationList), relationList)
|
|
|
+ err = o.CreateInBatches(relationList, utils.MultiAddNum).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -173,7 +174,7 @@ func AddOrUpdateEdbInfoRelationMulti(relationList []*EdbInfoRelation, refreshEdb
|
|
|
if len(refreshEdbInfoIds) > 0 {
|
|
|
// todo 更新指标的刷新状态
|
|
|
sql := ` UPDATE edb_info SET no_update = 0, set_update_time=? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(refreshEdbInfoIds)) + `) `
|
|
|
- _, err = o.Raw(sql, time.Now(), refreshEdbInfoIds).Exec()
|
|
|
+ err = o.Exec(sql, time.Now(), refreshEdbInfoIds).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -183,7 +184,7 @@ func AddOrUpdateEdbInfoRelationMulti(relationList []*EdbInfoRelation, refreshEdb
|
|
|
if len(indexCodeList) > 0 {
|
|
|
// 更改数据源的更新状态
|
|
|
sql := ` UPDATE base_from_mysteel_chemical_index SET is_stop = 0 WHERE index_code IN (` + utils.GetOrmInReplace(len(indexCodeList)) + `) and is_stop=1`
|
|
|
- _, err = o.Raw(sql, indexCodeList).Exec()
|
|
|
+ err = o.Exec(sql, indexCodeList).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -202,7 +203,7 @@ SET e1.parent_relation_id = e2.edb_info_relation_id
|
|
|
WHERE
|
|
|
e1.relation_type = 1
|
|
|
AND e2.relation_type = 0 AND e1.parent_relation_id !=e2.edb_info_relation_id AND e1.relation_code in (` + utils.GetOrmInReplace(len(relationCodes)) + `)`
|
|
|
- _, err = o.Raw(sql, relationCodes).Exec()
|
|
|
+ err = o.Exec(sql, relationCodes).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -213,17 +214,17 @@ WHERE
|
|
|
|
|
|
// 删除指标引用内容
|
|
|
func DeleteEdbRelationByObjectIds(referObjectIds []int, referObjectType int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
sql := ` DELETE FROM edb_info_relation WHERE refer_object_id in (` + utils.GetOrmInReplace(len(referObjectIds)) + `) AND refer_object_type=?`
|
|
|
- _, err = o.Raw(sql, referObjectIds, referObjectType).Exec()
|
|
|
+ err = o.Exec(sql, referObjectIds, referObjectType).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// DeleteEdbRelationByObjectId 删除指标引用内容
|
|
|
func DeleteEdbRelationByObjectId(referObjectId int, referObjectType int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
sql := ` DELETE FROM edb_info_relation WHERE refer_object_id =? AND refer_object_type=?`
|
|
|
- _, err = o.Raw(sql, referObjectId, referObjectType).Exec()
|
|
|
+ err = o.Exec(sql, referObjectId, referObjectType).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -247,7 +248,7 @@ type BaseRelationEdbInfoResp struct {
|
|
|
}
|
|
|
|
|
|
type EdbInfoRelationDetail struct {
|
|
|
- EdbInfoRelationId int `orm:"column(edb_info_relation_id);pk"`
|
|
|
+ EdbInfoRelationId int `orm:"column(edb_info_relation_id);pk" gorm:"primaryKey"`
|
|
|
EdbInfoId int `description:"指标id"`
|
|
|
ReferObjectId int `description:"引用对象ID(图表ID,ETA逻辑ID等)"`
|
|
|
ReferObjectTypeName string `description:"引用对象类型"`
|
|
@@ -263,7 +264,7 @@ type BaseRelationEdbInfoDetailResp struct {
|
|
|
|
|
|
// 查询指标引用列表
|
|
|
func GetEdbInfoRelationList(condition string, pars []interface{}, addFieldStr, joinTableStr, orderBy string, startSize, pageSize int) (total int, items []*BaseRelationEdbInfo, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
// 数量汇总
|
|
|
totalSql := ` SELECT count(1) FROM edb_info e LEFT JOIN (
|
|
|
SELECT count(edb_info_id) as relation_num, edb_info_id, max(relation_time) as relation_time FROM edb_info_relation GROUP BY edb_info_id) r on e.edb_info_id=r.edb_info_id `
|
|
@@ -275,7 +276,7 @@ SELECT count(edb_info_id) as relation_num, edb_info_id, max(relation_time) as re
|
|
|
if condition != "" {
|
|
|
totalSql += condition
|
|
|
}
|
|
|
- err = o.Raw(totalSql, pars).QueryRow(&total)
|
|
|
+ err = o.Raw(totalSql, pars...).Scan(&total).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -299,17 +300,18 @@ SELECT count(edb_info_id) as relation_num, edb_info_id, max(relation_time) as re
|
|
|
sql += ` ORDER BY edb_info_id ASC `
|
|
|
}
|
|
|
sql += ` LIMIT ?,? `
|
|
|
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
|
|
|
+ pars = append(pars, startSize, pageSize)
|
|
|
+ err = o.Raw(sql, pars...).Find(&items).Error
|
|
|
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetEdbInfoRelationDetailList 查询指标引用详情列表
|
|
|
func GetEdbInfoRelationDetailList(edbInfoId int, startSize, pageSize int) (total int, items []*EdbInfoRelation, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
// 数量汇总
|
|
|
totalSql := ` SELECT count(*) FROM edb_info_relation where edb_info_id=?`
|
|
|
- err = o.Raw(totalSql, edbInfoId).QueryRow(&total)
|
|
|
+ err = o.Raw(totalSql, edbInfoId).Scan(&total).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -317,17 +319,17 @@ func GetEdbInfoRelationDetailList(edbInfoId int, startSize, pageSize int) (total
|
|
|
// 列表数据
|
|
|
sql := ` SELECT *FROM edb_info_relation where edb_info_id=? ORDER BY relation_time desc, edb_info_id ASC `
|
|
|
sql += ` LIMIT ?,? `
|
|
|
- _, err = o.Raw(sql, edbInfoId, startSize, pageSize).QueryRows(&items)
|
|
|
+ err = o.Raw(sql, edbInfoId, startSize, pageSize).Find(&items).Error
|
|
|
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 查询相关的指标记录总数
|
|
|
func GetReplaceChildEdbInfoRelationTotal(edbInfoId int) (total int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
// 数量汇总
|
|
|
totalSql := ` SELECT count(*) FROM edb_info_relation where relation_type=1 and (child_edb_info_id=? or edb_info_id=? ) group by parent_relation_id`
|
|
|
- err = o.Raw(totalSql, edbInfoId, edbInfoId).QueryRow(&total)
|
|
|
+ err = o.Raw(totalSql, edbInfoId, edbInfoId).Scan(&total).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -336,19 +338,19 @@ func GetReplaceChildEdbInfoRelationTotal(edbInfoId int) (total int, err error) {
|
|
|
|
|
|
// 查询相关的指标记录列表
|
|
|
func GetReplaceChildEdbInfoRelationList(edbInfoId int, startSize, pageSize int) (items []*EdbInfoRelation, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
// 列表数据
|
|
|
sql := ` SELECT * FROM edb_info_relation where relation_type=1 and (child_edb_info_id=? or edb_info_id=? ) group by parent_relation_id ORDER BY edb_info_relation_id ASC LIMIT ?,? `
|
|
|
- _, err = o.Raw(sql, edbInfoId, edbInfoId, startSize, pageSize).QueryRows(&items)
|
|
|
+ err = o.Raw(sql, edbInfoId, edbInfoId, startSize, pageSize).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 查询相关的指标记录总数
|
|
|
func GetReplaceEdbInfoRelationTotal(edbInfoId int) (total int, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
// 数量汇总
|
|
|
totalSql := ` SELECT count(*) FROM edb_info_relation where edb_info_id=? and relation_type = 0`
|
|
|
- err = o.Raw(totalSql, edbInfoId).QueryRow(&total)
|
|
|
+ err = o.Raw(totalSql, edbInfoId).Scan(&total).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -357,18 +359,18 @@ func GetReplaceEdbInfoRelationTotal(edbInfoId int) (total int, err error) {
|
|
|
|
|
|
// 查询相关的指标记录列表
|
|
|
func GetReplaceEdbInfoRelationList(edbInfoId int, startSize, pageSize int) (items []*EdbInfoRelation, err error) {
|
|
|
- o := orm.NewOrmUsingDB("data")
|
|
|
+ o := global.DbMap[utils.DbNameIndex]
|
|
|
// 列表数据
|
|
|
sql := ` SELECT * FROM edb_info_relation where edb_info_id=? and relation_type = 0 ORDER BY edb_info_relation_id ASC LIMIT ?,? `
|
|
|
- _, err = o.Raw(sql, edbInfoId, startSize, pageSize).QueryRows(&items)
|
|
|
+ err = o.Raw(sql, edbInfoId, startSize, pageSize).Find(&items).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 替换指标引用表中直接引用的指标
|
|
|
func ReplaceRelationEdbInfoId(oldEdbInfo, newEdbInfo *EdbInfo, edbRelationIds []int, relationList []*EdbInfoRelation, refreshEdbInfoIds []int, indexCodeList []string) (err error) {
|
|
|
- o, err := orm.NewOrmUsingDB("data").Begin()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
+ o := global.DbMap[utils.DbNameIndex].Begin()
|
|
|
+ if o.Error != nil {
|
|
|
+ return o.Error
|
|
|
}
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
@@ -381,7 +383,7 @@ func ReplaceRelationEdbInfoId(oldEdbInfo, newEdbInfo *EdbInfo, edbRelationIds []
|
|
|
now := time.Now()
|
|
|
// 删除相关的间接引用
|
|
|
sql := ` DELETE FROM edb_info_relation WHERE root_edb_info_id=? and relation_type=1 and parent_relation_id in (` + utils.GetOrmInReplace(len(edbRelationIds)) + `)`
|
|
|
- _, err = o.Raw(sql, oldEdbInfo.EdbInfoId, edbRelationIds).Exec()
|
|
|
+ err = o.Exec(sql, oldEdbInfo.EdbInfoId, edbRelationIds).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -389,14 +391,14 @@ func ReplaceRelationEdbInfoId(oldEdbInfo, newEdbInfo *EdbInfo, edbRelationIds []
|
|
|
sourceWhere := ` and (refer_object_type in (1,2,5) or (refer_object_type=4 and refer_object_sub_type !=5) )` //平衡表和事件日历中的直接引用无需替换,
|
|
|
// 替换edb_info_id
|
|
|
sql = ` UPDATE edb_info_relation SET edb_info_id=?, source=?, edb_name=?, edb_code=?, modify_time=?, relation_time=? WHERE edb_info_id=? ` + sourceWhere + ` and relation_type=0 and edb_info_relation_id in (` + utils.GetOrmInReplace(len(edbRelationIds)) + `)`
|
|
|
- _, err = o.Raw(sql, newEdbInfo.EdbInfoId, newEdbInfo.Source, newEdbInfo.EdbName, newEdbInfo.EdbCode, now, now, oldEdbInfo.EdbInfoId, edbRelationIds).Exec()
|
|
|
+ err = o.Exec(sql, newEdbInfo.EdbInfoId, newEdbInfo.Source, newEdbInfo.EdbName, newEdbInfo.EdbCode, now, now, oldEdbInfo.EdbInfoId, edbRelationIds).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 更新code值
|
|
|
sql = ` UPDATE edb_info_relation SET relation_code=CONCAT_WS("_", edb_info_id,refer_object_id,refer_object_type,refer_object_sub_type) WHERE relation_type=0 ` + sourceWhere + ` and edb_info_relation_id in (` + utils.GetOrmInReplace(len(edbRelationIds)) + `)`
|
|
|
- _, err = o.Raw(sql, edbRelationIds).Exec()
|
|
|
+ err = o.Exec(sql, edbRelationIds).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -408,7 +410,7 @@ func ReplaceRelationEdbInfoId(oldEdbInfo, newEdbInfo *EdbInfo, edbRelationIds []
|
|
|
relationCodesMap[relation.RelationCode] = struct{}{}
|
|
|
}
|
|
|
}
|
|
|
- _, err = o.InsertMulti(len(relationList), relationList)
|
|
|
+ err = o.CreateInBatches(relationList, utils.MultiAddNum).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -417,7 +419,7 @@ func ReplaceRelationEdbInfoId(oldEdbInfo, newEdbInfo *EdbInfo, edbRelationIds []
|
|
|
if len(refreshEdbInfoIds) > 0 {
|
|
|
// todo 更新指标的刷新状态
|
|
|
sql := ` UPDATE edb_info SET no_update = 0, set_update_time=? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(refreshEdbInfoIds)) + `) `
|
|
|
- _, err = o.Raw(sql, time.Now(), refreshEdbInfoIds).Exec()
|
|
|
+ err = o.Exec(sql, time.Now(), refreshEdbInfoIds).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -427,7 +429,7 @@ func ReplaceRelationEdbInfoId(oldEdbInfo, newEdbInfo *EdbInfo, edbRelationIds []
|
|
|
if len(indexCodeList) > 0 {
|
|
|
// 更改数据源的更新状态
|
|
|
sql := ` UPDATE base_from_mysteel_chemical_index SET is_stop = 0 WHERE index_code IN (` + utils.GetOrmInReplace(len(indexCodeList)) + `) and is_stop=1`
|
|
|
- _, err = o.Raw(sql, indexCodeList).Exec()
|
|
|
+ err = o.Exec(sql, indexCodeList).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -445,7 +447,7 @@ SET e1.parent_relation_id = e2.edb_info_relation_id
|
|
|
WHERE
|
|
|
e1.relation_type = 1
|
|
|
AND e2.relation_type = 0 AND e1.parent_relation_id !=e2.edb_info_relation_id AND e1.relation_code in (` + utils.GetOrmInReplace(len(relationCodes)) + `)`
|
|
|
- _, err = o.Raw(sql, relationCodes).Exec()
|
|
|
+ err = o.Exec(sql, relationCodes).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -456,9 +458,9 @@ WHERE
|
|
|
|
|
|
// UpdateSecondRelationEdbInfoId 更新指标替换后的间接引用记录
|
|
|
func UpdateSecondRelationEdbInfoId(edbRelationIds []int, relationList []*EdbInfoRelation, refreshEdbInfoIds []int, indexCodeList []string) (err error) {
|
|
|
- o, err := orm.NewOrmUsingDB("data").Begin()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
+ o := global.DbMap[utils.DbNameIndex].Begin()
|
|
|
+ if o.Error != nil {
|
|
|
+ return o.Error
|
|
|
}
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
@@ -469,7 +471,7 @@ func UpdateSecondRelationEdbInfoId(edbRelationIds []int, relationList []*EdbInfo
|
|
|
}()
|
|
|
// 删除相关的间接引用
|
|
|
sql := ` DELETE FROM edb_info_relation WHERE relation_type=1 and parent_relation_id in (` + utils.GetOrmInReplace(len(edbRelationIds)) + `)`
|
|
|
- _, err = o.Raw(sql, edbRelationIds).Exec()
|
|
|
+ err = o.Exec(sql, edbRelationIds).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -482,7 +484,7 @@ func UpdateSecondRelationEdbInfoId(edbRelationIds []int, relationList []*EdbInfo
|
|
|
relationCodesMap[relation.RelationCode] = struct{}{}
|
|
|
}
|
|
|
}
|
|
|
- _, err = o.InsertMulti(len(relationList), relationList)
|
|
|
+ err = o.CreateInBatches(relationList, utils.MultiAddNum).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -491,7 +493,7 @@ func UpdateSecondRelationEdbInfoId(edbRelationIds []int, relationList []*EdbInfo
|
|
|
if len(refreshEdbInfoIds) > 0 {
|
|
|
// todo 更新指标的刷新状态
|
|
|
sql = ` UPDATE edb_info SET no_update = 0, set_update_time=? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(refreshEdbInfoIds)) + `) `
|
|
|
- _, err = o.Raw(sql, time.Now(), refreshEdbInfoIds).Exec()
|
|
|
+ err = o.Exec(sql, time.Now(), refreshEdbInfoIds).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -501,7 +503,7 @@ func UpdateSecondRelationEdbInfoId(edbRelationIds []int, relationList []*EdbInfo
|
|
|
if len(indexCodeList) > 0 {
|
|
|
// 更改数据源的更新状态
|
|
|
sql = ` UPDATE base_from_mysteel_chemical_index SET is_stop = 0 WHERE index_code IN (` + utils.GetOrmInReplace(len(indexCodeList)) + `) and is_stop=1`
|
|
|
- _, err = o.Raw(sql, indexCodeList).Exec()
|
|
|
+ err = o.Exec(sql, indexCodeList).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -519,7 +521,7 @@ SET e1.parent_relation_id = e2.edb_info_relation_id
|
|
|
WHERE
|
|
|
e1.relation_type = 1
|
|
|
AND e2.relation_type = 0 AND e1.parent_relation_id !=e2.edb_info_relation_id AND e1.relation_code in (` + utils.GetOrmInReplace(len(relationCodes)) + `)`
|
|
|
- _, err = o.Raw(sql, relationCodes).Exec()
|
|
|
+ err = o.Exec(sql, relationCodes).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|