|
@@ -138,7 +138,7 @@ func AddPredictEdbInfo(sourceEdbInfoId, classifyId int, edbName string, ruleList
|
|
|
calculateMappingList = append(calculateMappingList, calculateMappingItem)
|
|
|
|
|
|
// 动态环差 计算列表
|
|
|
- calculateRule9List := make([]models.CalculateRule, 0)
|
|
|
+ calculateRuleList := make([]models.CalculateRule, 0)
|
|
|
|
|
|
// 预测指标配置
|
|
|
predictEdbConfList := make([]*models.PredictEdbConf, 0)
|
|
@@ -253,7 +253,7 @@ func AddPredictEdbInfo(sourceEdbInfoId, classifyId int, edbName string, ruleList
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- calculateRule9List = append(calculateRule9List, models.CalculateRule{
|
|
|
+ calculateRuleList = append(calculateRuleList, models.CalculateRule{
|
|
|
TrendsCalculateMappingList: trendsMappingList,
|
|
|
EdbInfoList: edbInfoList,
|
|
|
EdbInfoIdBytes: edbInfoIdBytes,
|
|
@@ -279,7 +279,7 @@ func AddPredictEdbInfo(sourceEdbInfoId, classifyId int, edbName string, ruleList
|
|
|
|
|
|
predictEdbConfList = append(predictEdbConfList, tmpPredictEdbConf)
|
|
|
}
|
|
|
- err = models.AddPredictEdb(edbInfo, calculateMappingList, predictEdbConfList, calculateRule9List)
|
|
|
+ err = models.AddPredictEdb(edbInfo, calculateMappingList, predictEdbConfList, calculateRuleList)
|
|
|
if err != nil {
|
|
|
errMsg = "保存失败"
|
|
|
err = errors.New("保存失败,Err:" + err.Error())
|
|
@@ -411,7 +411,7 @@ func EditPredictEdbInfo(edbInfoId, classifyId int, edbName string, ruleList []mo
|
|
|
calculateMappingList = append(calculateMappingList, calculateMappingItem)
|
|
|
|
|
|
// 动态环差 计算列表
|
|
|
- calculateRule9List := make([]models.CalculateRule, 0)
|
|
|
+ calculateRuleList := make([]models.CalculateRule, 0)
|
|
|
|
|
|
// 预测指标配置
|
|
|
predictEdbConfList := make([]*models.PredictEdbConf, 0)
|
|
@@ -526,7 +526,7 @@ func EditPredictEdbInfo(edbInfoId, classifyId int, edbName string, ruleList []mo
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- calculateRule9List = append(calculateRule9List, models.CalculateRule{
|
|
|
+ calculateRuleList = append(calculateRuleList, models.CalculateRule{
|
|
|
TrendsCalculateMappingList: trendsMappingList,
|
|
|
EdbInfoList: edbInfoList,
|
|
|
EdbInfoIdBytes: edbInfoIdBytes,
|
|
@@ -553,7 +553,7 @@ func EditPredictEdbInfo(edbInfoId, classifyId int, edbName string, ruleList []mo
|
|
|
predictEdbConfList = append(predictEdbConfList, tmpPredictEdbConf)
|
|
|
}
|
|
|
|
|
|
- err = models.EditPredictEdb(edbInfo, updateEdbInfoCol, calculateMappingList, predictEdbConfList, calculateRule9List)
|
|
|
+ err = models.EditPredictEdb(edbInfo, updateEdbInfoCol, calculateMappingList, predictEdbConfList, calculateRuleList)
|
|
|
if err != nil {
|
|
|
errMsg = "保存失败"
|
|
|
err = errors.New("保存失败,Err:" + err.Error())
|
|
@@ -561,3 +561,150 @@ func EditPredictEdbInfo(edbInfoId, classifyId int, edbName string, ruleList []mo
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// RefreshPredictEdbInfo 更新基础预测指标规则中的动态数据
|
|
|
+func RefreshPredictEdbInfo(edbInfoId int) (edbInfo *models.EdbInfo, err error, errMsg string) {
|
|
|
+ // 指标信息校验
|
|
|
+ {
|
|
|
+ edbInfo, err = models.GetEdbInfoById(edbInfoId)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ errMsg = "刷新失败"
|
|
|
+ err = errors.New("获取预测指标失败,Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if edbInfo == nil {
|
|
|
+ errMsg = "找不到该预测指标"
|
|
|
+ err = nil
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //必须是普通的指标
|
|
|
+ if edbInfo.EdbInfoType != 1 {
|
|
|
+ errMsg = "指标异常,不是预测指标"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 配置 与 指标的 关联关系表
|
|
|
+ list, err := models.GetPredictEdbConfCalculateMappingListByEdbInfoId(edbInfoId)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 没有关联指标,不需要刷新
|
|
|
+ if len(list) <= 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 配置关联的指标信息
|
|
|
+ predictEdbConfCalculateMappingListMap := make(map[int][]*models.PredictEdbConfCalculateMapping)
|
|
|
+ configIdList := make([]int, 0) //关联配置id
|
|
|
+ edbInfoIdList := make([]int, 0) //关联指标配置id
|
|
|
+ edbInfoIdMap := make(map[int]int, 0) //关联指标配置map
|
|
|
+ for _, v := range list {
|
|
|
+ configList, ok := predictEdbConfCalculateMappingListMap[v.ConfigId]
|
|
|
+ if !ok {
|
|
|
+ configList = make([]*models.PredictEdbConfCalculateMapping, 0)
|
|
|
+ configIdList = append(configIdList, v.ConfigId)
|
|
|
+ }
|
|
|
+ if _, ok := edbInfoIdMap[v.FromEdbInfoId]; !ok {
|
|
|
+ edbInfoIdList = append(edbInfoIdList, v.FromEdbInfoId)
|
|
|
+ }
|
|
|
+ configList = append(configList, v)
|
|
|
+ predictEdbConfCalculateMappingListMap[v.ConfigId] = configList
|
|
|
+ }
|
|
|
+
|
|
|
+ predictEdbConfList, err := models.GetPredictEdbConfListByConfigIdList(configIdList)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = "刷新失败"
|
|
|
+ err = errors.New("获取预测指标配置信息失败,Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(predictEdbConfList) == 0 {
|
|
|
+ errMsg = "找不到该预测指标配置"
|
|
|
+ err = nil
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 指标信息
|
|
|
+ edbInfoList, err := models.GetEdbInfoByIdList(edbInfoIdList)
|
|
|
+ if err != nil {
|
|
|
+ err = errors.New("获取关联指标失败,Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 指标信息map
|
|
|
+ edbInfoListMap := make(map[int]*models.EdbInfo)
|
|
|
+ for _, v := range edbInfoList {
|
|
|
+ edbInfoListMap[v.EdbInfoId] = v
|
|
|
+ }
|
|
|
+
|
|
|
+ // 刷新所有的规则
|
|
|
+ for _, v := range predictEdbConfList {
|
|
|
+ switch v.RuleType {
|
|
|
+ case 9:
|
|
|
+ if v.Value == "" {
|
|
|
+ errMsg = "请填写计算规则"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ formula := v.Value
|
|
|
+
|
|
|
+ // 动态环差规则 关系表
|
|
|
+ trendsMappingList := predictEdbConfCalculateMappingListMap[v.ConfigId]
|
|
|
+
|
|
|
+ // 关联标签
|
|
|
+ edbInfoIdArr := make([]models.EdbInfoFromTag, 0)
|
|
|
+
|
|
|
+ //关联的指标信息
|
|
|
+ edbInfoList := make([]*models.EdbInfo, 0)
|
|
|
+ for _, trendsMapping := range trendsMappingList {
|
|
|
+ tmpEdbInfo, ok := edbInfoListMap[trendsMapping.FromEdbInfoId]
|
|
|
+ if ok {
|
|
|
+ edbInfoList = append(edbInfoList, tmpEdbInfo)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 关联标签
|
|
|
+ edbInfoIdArr = append(edbInfoIdArr, models.EdbInfoFromTag{
|
|
|
+ EdbInfoId: trendsMapping.FromEdbInfoId,
|
|
|
+ FromTag: trendsMapping.FromTag,
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ //检验公式
|
|
|
+ var formulaStr string
|
|
|
+ var edbInfoIdBytes []string
|
|
|
+ for _, tmpEdbInfoId := range edbInfoIdArr {
|
|
|
+ formulaStr += tmpEdbInfoId.FromTag + ","
|
|
|
+ edbInfoIdBytes = append(edbInfoIdBytes, tmpEdbInfoId.FromTag)
|
|
|
+ }
|
|
|
+ formulaMap := services.CheckFormula(formula)
|
|
|
+ for _, formula := range formulaMap {
|
|
|
+ if !strings.Contains(formulaStr, formula) {
|
|
|
+ errMsg = "公式错误,请重新填写"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ok, _ := models.CheckFormula2(edbInfoList, formulaMap, formula, edbInfoIdBytes)
|
|
|
+ if !ok {
|
|
|
+ errMsg = "生成计算指标失败,请使用正确的计算公式"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ rule := models.CalculateRule{
|
|
|
+ EdbInfoId: v.PredictEdbInfoId,
|
|
|
+ ConfigId: v.ConfigId,
|
|
|
+ TrendsCalculateMappingList: trendsMappingList,
|
|
|
+ EdbInfoList: edbInfoList,
|
|
|
+ EdbInfoIdBytes: edbInfoIdBytes,
|
|
|
+ Formula: formula,
|
|
|
+ RuleType: v.RuleType,
|
|
|
+ EndDate: v.EndDate.Format(utils.FormatDate),
|
|
|
+ EdbInfoIdArr: edbInfoIdArr,
|
|
|
+ }
|
|
|
+ err = models.RefreshCalculateByRuleBy9(rule)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|