|
@@ -998,28 +998,28 @@ func EdbInfoReplace(oldEdbInfo, newEdbInfo *EdbInfo, sysAdminId int, sysAdminRea
|
|
|
}
|
|
|
|
|
|
// EdbInfoReplaceV2 替换指标v2版本(更换时间:2022年01月05日15:33:42)
|
|
|
-func EdbInfoReplaceV2(oldEdbInfo, newEdbInfo *EdbInfo, sysAdminId int, sysAdminRealName string) (replaceChartTotal, replaceCalculateTotal int, err error) {
|
|
|
- defer func() {
|
|
|
- if err != nil {
|
|
|
- fmt.Println("ERR:", err.Error())
|
|
|
- }
|
|
|
- }()
|
|
|
- mappingList, replaceChartTotal, replaceCalculateTotal, err := replaceChartEdb(oldEdbInfo, newEdbInfo)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- err = replaceRelationEdbInfo(mappingList, oldEdbInfo, newEdbInfo, sysAdminId, sysAdminRealName)
|
|
|
- return
|
|
|
-}
|
|
|
+//func EdbInfoReplaceV2(oldEdbInfo, newEdbInfo *EdbInfo, sysAdminId int, sysAdminRealName string) (mappingList,replaceChartTotal, replaceCalculateTotal int, err error) {
|
|
|
+// defer func() {
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("ERR:", err.Error())
|
|
|
+// }
|
|
|
+// }()
|
|
|
+//
|
|
|
+// // 替换关联表中的source_edb_info_id
|
|
|
+// mappingList, replaceChartTotal, replaceCalculateTotal, err := replaceChartEdb(oldEdbInfo, newEdbInfo)
|
|
|
+// if err != nil {
|
|
|
+// return
|
|
|
+// }
|
|
|
+// err = replaceRelationEdbInfo(mappingList, oldEdbInfo, newEdbInfo, sysAdminId, sysAdminRealName)
|
|
|
+// return
|
|
|
+//}
|
|
|
|
|
|
// ReplaceChartEdb 替换图表中的指标
|
|
|
-func ReplaceChartEdb(oldEdbInfo, newEdbInfo *EdbInfo) (mappingList []*EdbInfoCalculateMapping, replaceChartTotal, replaceCalculateTotal int, err error) {
|
|
|
- return replaceChartEdb(oldEdbInfo, newEdbInfo)
|
|
|
-}
|
|
|
-
|
|
|
-// replaceChartEdb 替换图表中的指标
|
|
|
-func replaceChartEdb(oldEdbInfo, newEdbInfo *EdbInfo) (mappingList []*EdbInfoCalculateMapping, replaceChartTotal, replaceCalculateTotal int, err error) {
|
|
|
+func ReplaceChartEdb(oldEdbInfo, newEdbInfo *EdbInfo) (relationEdbInfoIdList []int, replaceChartTotal, replaceCalculateTotal int, err error) {
|
|
|
var errmsg string
|
|
|
+ relationEdbInfoIdList = make([]int, 0) // 关联的指标id
|
|
|
+ logMsg := `` // 记录替换的日志
|
|
|
+
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
|
to, err := o.Begin()
|
|
|
if err != nil {
|
|
@@ -1030,6 +1030,9 @@ func replaceChartEdb(oldEdbInfo, newEdbInfo *EdbInfo) (mappingList []*EdbInfoCal
|
|
|
_ = to.Rollback()
|
|
|
} else {
|
|
|
_ = to.Commit()
|
|
|
+ if logMsg != `` {
|
|
|
+ utils.FileLog.Info(fmt.Sprintf("替换指标记录,旧的指标id:%d,新的指标id:%d;%s", oldEdbInfo.EdbInfoId, newEdbInfo.EdbInfoId, logMsg))
|
|
|
+ }
|
|
|
}
|
|
|
if errmsg != "" {
|
|
|
fmt.Println("errmsg:" + errmsg)
|
|
@@ -1040,68 +1043,115 @@ func replaceChartEdb(oldEdbInfo, newEdbInfo *EdbInfo) (mappingList []*EdbInfoCal
|
|
|
}
|
|
|
}()
|
|
|
//替换图表
|
|
|
- chartEdbMappingList := make([]*ChartEdbInfoMapping, 0)
|
|
|
- csql := `SELECT * FROM chart_edb_mapping WHERE edb_info_id=?`
|
|
|
- _, err = to.Raw(csql, oldEdbInfo.EdbInfoId).QueryRows(&chartEdbMappingList)
|
|
|
- if err != nil {
|
|
|
- errmsg = "获取指标关联图表信息失败:Err:" + err.Error()
|
|
|
- return
|
|
|
- }
|
|
|
- replaceChartTotal = len(chartEdbMappingList)
|
|
|
-
|
|
|
- for _, mv := range chartEdbMappingList {
|
|
|
- //获取图表所有指标信息
|
|
|
- chartEdbList := make([]*ChartEdbInfoMapping, 0)
|
|
|
- csql := `SELECT * FROM chart_edb_mapping WHERE chart_info_id=?`
|
|
|
- _, err = to.Raw(csql, mv.ChartInfoId).QueryRows(&chartEdbList)
|
|
|
+ {
|
|
|
+ chartEdbMappingList := make([]*ChartEdbInfoMapping, 0)
|
|
|
+ csql := `SELECT * FROM chart_edb_mapping WHERE edb_info_id=?`
|
|
|
+ _, err = to.Raw(csql, oldEdbInfo.EdbInfoId).QueryRows(&chartEdbMappingList)
|
|
|
if err != nil {
|
|
|
- errmsg = "获取图表所有指标信息失败:Err:" + err.Error()
|
|
|
+ errmsg = "获取指标关联图表信息失败:Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
- var minData, maxData float64
|
|
|
- minData = newEdbInfo.MinValue
|
|
|
- maxData = newEdbInfo.MaxValue
|
|
|
-
|
|
|
- for _, cv := range chartEdbList {
|
|
|
- if mv.IsAxis == cv.IsAxis {
|
|
|
- if minData > cv.MinData {
|
|
|
- minData = cv.MinData
|
|
|
+ replaceChartTotal = len(chartEdbMappingList)
|
|
|
+
|
|
|
+ if len(chartEdbMappingList) > 0 {
|
|
|
+ chartInfoIdList := make([]string, 0)
|
|
|
+ for _, mv := range chartEdbMappingList {
|
|
|
+ //获取图表所有指标信息
|
|
|
+ chartEdbList := make([]*ChartEdbInfoMapping, 0)
|
|
|
+ csql := `SELECT * FROM chart_edb_mapping WHERE chart_info_id=?`
|
|
|
+ _, err = to.Raw(csql, mv.ChartInfoId).QueryRows(&chartEdbList)
|
|
|
+ if err != nil {
|
|
|
+ errmsg = "获取图表所有指标信息失败:Err:" + err.Error()
|
|
|
+ return
|
|
|
}
|
|
|
- if maxData < cv.MaxData {
|
|
|
- maxData = cv.MaxData
|
|
|
+ var minData, maxData float64
|
|
|
+ minData = newEdbInfo.MinValue
|
|
|
+ maxData = newEdbInfo.MaxValue
|
|
|
+
|
|
|
+ for _, cv := range chartEdbList {
|
|
|
+ if mv.IsAxis == cv.IsAxis {
|
|
|
+ if minData > cv.MinData {
|
|
|
+ minData = cv.MinData
|
|
|
+ }
|
|
|
+ if maxData < cv.MaxData {
|
|
|
+ maxData = cv.MaxData
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //修改图表关联指标
|
|
|
+ rsql := ` UPDATE chart_edb_mapping SET edb_info_id=?,max_data=?,min_data=?,modify_time=NOW() WHERE chart_edb_mapping_id=? `
|
|
|
+ _, err = to.Raw(rsql, newEdbInfo.EdbInfoId, maxData, minData, mv.ChartEdbMappingId).Exec()
|
|
|
+ if err != nil {
|
|
|
+ errmsg = "更新图库指标信息失败:Err:" + err.Error()
|
|
|
+ return
|
|
|
}
|
|
|
+
|
|
|
+ chartInfoIdList = append(chartInfoIdList, fmt.Sprint(mv.ChartInfoId))
|
|
|
}
|
|
|
+ logMsg += `涉及到的图表id:` + strings.Join(chartInfoIdList, ",") + ";"
|
|
|
}
|
|
|
- //修改图表关联指标
|
|
|
- rsql := ` UPDATE chart_edb_mapping SET edb_info_id=?,max_data=?,min_data=?,modify_time=NOW() WHERE chart_edb_mapping_id=? `
|
|
|
- _, err = to.Raw(rsql, newEdbInfo.EdbInfoId, maxData, minData, mv.ChartEdbMappingId).Exec()
|
|
|
+ }
|
|
|
+
|
|
|
+ //替换计算指标
|
|
|
+ {
|
|
|
+ //获取所有包含的计算指标
|
|
|
+ mappingList := make([]*EdbInfoCalculateMapping, 0)
|
|
|
+ msql := ` SELECT * FROM edb_info_calculate_mapping WHERE from_edb_info_id=? GROUP BY edb_info_id `
|
|
|
+ _, err = to.Raw(msql, oldEdbInfo.EdbInfoId).QueryRows(&mappingList)
|
|
|
if err != nil {
|
|
|
- errmsg = "更新图库指标信息失败:Err:" + err.Error()
|
|
|
+ errmsg = "获取计算指标关联基础指标信息失败:Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
+ replaceCalculateTotal = len(mappingList)
|
|
|
+ //计算指标
|
|
|
+ if len(mappingList) > 0 {
|
|
|
+ edbInfoIdList := make([]string, 0)
|
|
|
+ for _, mv := range mappingList {
|
|
|
+ //如果即将替换的指标与当前指标id一致,那么就退出当前循环,进入下一循环
|
|
|
+ if mv.EdbInfoId == newEdbInfo.EdbInfoId {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ //替换原指标
|
|
|
+ msql := `UPDATE edb_info_calculate_mapping SET from_edb_info_id=?,from_edb_code=?,from_edb_name=?,from_source=?,from_source_name=? WHERE edb_info_calculate_mapping_id=? `
|
|
|
+ _, err = to.Raw(msql, newEdbInfo.EdbInfoId, newEdbInfo.EdbCode, newEdbInfo.EdbName, newEdbInfo.Source, newEdbInfo.SourceName, mv.EdbInfoCalculateMappingId).Exec()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ relationEdbInfoIdList = append(relationEdbInfoIdList, mv.EdbInfoId)
|
|
|
+
|
|
|
+ edbInfoIdList = append(edbInfoIdList, fmt.Sprint(mv.EdbInfoId))
|
|
|
+ }
|
|
|
+ logMsg += `涉及到的指标id:` + strings.Join(edbInfoIdList, ",") + ";"
|
|
|
+ }
|
|
|
}
|
|
|
- //替换计算指标
|
|
|
- //获取所有包含的计算指标
|
|
|
- mappingList = make([]*EdbInfoCalculateMapping, 0)
|
|
|
- msql := ` SELECT * FROM edb_info_calculate_mapping WHERE from_edb_info_id=? GROUP BY edb_info_id `
|
|
|
- _, err = to.Raw(msql, oldEdbInfo.EdbInfoId).QueryRows(&mappingList)
|
|
|
- if err != nil {
|
|
|
- errmsg = "获取计算指标关联基础指标信息失败:Err:" + err.Error()
|
|
|
- return
|
|
|
- }
|
|
|
- replaceCalculateTotal = len(mappingList)
|
|
|
- //计算指标
|
|
|
- for _, mv := range mappingList {
|
|
|
- //如果即将替换的指标与当前指标id一致,那么就退出当前循环,进入下一循环
|
|
|
- if mv.EdbInfoId == newEdbInfo.EdbInfoId {
|
|
|
- continue
|
|
|
+
|
|
|
+ // 替换预测指标中的来源指标
|
|
|
+ {
|
|
|
+ //获取所有包含的计算指标
|
|
|
+ predictEdbConfList := make([]*PredictEdbConf, 0)
|
|
|
+ msql := ` SELECT * FROM predict_edb_conf WHERE source_edb_info_id=? GROUP BY predict_edb_info_id `
|
|
|
+ _, err = to.Raw(msql, oldEdbInfo.EdbInfoId).QueryRows(&predictEdbConfList)
|
|
|
+ if err != nil {
|
|
|
+ errmsg = "获取关联的预测指标信息失败:Err:" + err.Error()
|
|
|
+ return
|
|
|
}
|
|
|
- //替换原指标
|
|
|
- msql := `UPDATE edb_info_calculate_mapping SET from_edb_info_id=?,from_edb_code=?,from_edb_name=?,from_source=?,from_source_name=? WHERE edb_info_calculate_mapping_id=? `
|
|
|
- _, err = to.Raw(msql, newEdbInfo.EdbInfoId, newEdbInfo.EdbCode, newEdbInfo.EdbName, newEdbInfo.Source, newEdbInfo.SourceName, mv.EdbInfoCalculateMappingId).Exec()
|
|
|
+ replaceCalculateTotal += len(predictEdbConfList)
|
|
|
+
|
|
|
+ //替换预测指标的来源指标
|
|
|
+ msql = `UPDATE predict_edb_conf SET source_edb_info_id=? WHERE source_edb_info_id=? `
|
|
|
+ _, err = to.Raw(msql, newEdbInfo.EdbInfoId, oldEdbInfo.EdbInfoId).Exec()
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+ if len(predictEdbConfList) > 0 {
|
|
|
+ edbInfoIdList := make([]string, 0)
|
|
|
+ for _, v := range predictEdbConfList {
|
|
|
+ relationEdbInfoIdList = append(relationEdbInfoIdList, v.PredictEdbInfoId)
|
|
|
+ edbInfoIdList = append(edbInfoIdList, fmt.Sprint(v.PredictEdbInfoId))
|
|
|
+ }
|
|
|
+ logMsg += `涉及到的预测指标id:` + strings.Join(edbInfoIdList, ",") + ";"
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return
|