zqbao пре 5 месеци
родитељ
комит
6349155a07

+ 10 - 1
models/data_manage/stl/calculate_stl_config_mapping.go

@@ -7,9 +7,10 @@ import (
 )
 
 type CalculateStlConfigMapping struct {
-	Id                   int       `description:"主键"`
+	Id                   int       `orm:"pk" description:"主键"`
 	CalculateStlConfigId int       `description:"stl配置id"`
 	EdbInfoId            int       `description:"edb信息id"`
+	StlEdbType           int       `description:"stl指标类型: 1-Trend, 2-Seasonal, 3-Residual"`
 	CreateTime           time.Time `description:"创建时间"`
 	ModifyTime           time.Time `description:"修改时间"`
 }
@@ -27,3 +28,11 @@ func GetCalculateStlConfigMappingIdByEdbInfoId(edbInfoId int) (configId int, err
 	err = o.Raw(sql, edbInfoId).QueryRow(&configId)
 	return
 }
+
+// GetCalculateStlConfigMappingByConfigId 根据配置文件id获取配置文件映射信息
+func GetCalculateStlConfigMappingByConfigId(configId int) (items []*CalculateStlConfigMapping, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `SELECT * FROM calculate_stl_config_mapping WHERE calculate_stl_config_id=?`
+	_, err = o.Raw(sql, configId).QueryRows(&items)
+	return
+}

+ 6 - 0
models/data_manage/stl/response/stl.go

@@ -36,6 +36,11 @@ type SaveStlConfigResp struct {
 	CalculateStlConfigId int64 `description:"配置文件id"`
 }
 
+type StlEdbInfo struct {
+	StlEdbType int `description:"stl指标类型: 1-Trend, 2-Seasonal, 3-Residual"`
+	EdbInfoId  int `description:"指标ID"`
+}
+
 type StlConfigResp struct {
 	EdbInfoId            int     `description:"指标ID"`
 	EdbInfoName          string  `description:"指标名称"`
@@ -52,4 +57,5 @@ type StlConfigResp struct {
 	TrendDeg             int     `description:"分解中趋势多项式次数,默认为1,不超过5的正整数"`
 	SeasonalDeg          int     `description:"分解中季节性多项次数,默认为1,不超过5的正整数"`
 	LowPassDeg           int     `description:"分解中低通滤波器次数,默认为1,不超过5的正整数"`
+	StlEdbInfo           []*StlEdbInfo
 }

+ 18 - 0
services/data/stl/stl.go

@@ -783,6 +783,10 @@ func SaveStlEdbInfo(req *request.SaveStlEdbInfoReq, adminId int, adminRealName,
 			err = fmt.Errorf("json解析失败,Err:" + er.Error())
 			return
 		}
+	default:
+		msg = "获取失败"
+		err = fmt.Errorf("未知的计算类型")
+		return
 	}
 
 	indexObj := new(stl.EdbDataCalculateStl)
@@ -886,6 +890,7 @@ func SaveStlEdbInfo(req *request.SaveStlEdbInfoReq, adminId int, adminRealName,
 		stlMapping := new(stl.CalculateStlConfigMapping)
 		stlMapping.EdbInfoId = int(edbInfoId)
 		stlMapping.CalculateStlConfigId = req.CalculateStlConfigId
+		stlMapping.StlEdbType = req.StlEdbType
 		stlMapping.CreateTime = time.Now()
 		stlMapping.ModifyTime = time.Now()
 		_, err = stlMapping.Insert()
@@ -968,6 +973,18 @@ func GetStlConfig(edbInfoId int) (resp *response.StlConfigResp, msg string, err
 		msg = "获取失败"
 		return
 	}
+	mappingList, err := stl.GetCalculateStlConfigMappingByConfigId(configId)
+	if err != nil {
+		msg = "获取失败"
+		return
+	}
+	stlEdbInfo := make([]*response.StlEdbInfo, 0)
+	for _, v := range mappingList {
+		stlEdbInfo = append(stlEdbInfo, &response.StlEdbInfo{
+			StlEdbType: v.StlEdbType,
+			EdbInfoId:  v.EdbInfoId,
+		})
+	}
 	resp = &response.StlConfigResp{
 		CalculateStlConfigId: conf.CalculateStlConfigId,
 		EdbInfoId:            req.EdbInfoId,
@@ -984,6 +1001,7 @@ func GetStlConfig(edbInfoId int) (resp *response.StlConfigResp, msg string, err
 		TrendDeg:             req.TrendDeg,
 		SeasonalDeg:          req.SeasonalDeg,
 		LowPassDeg:           req.LowPassDeg,
+		StlEdbInfo:           stlEdbInfo,
 	}
 	return
 }