package residual_analysis_model import ( "github.com/beego/beego/v2/client/orm" "time" ) type CalculateResidualAnalysisConfig struct { CalculateResidualAnalysisConfigId int `orm:"column(calculate_residual_analysis_config_id);pk;auto" description:"自增id"` Config string `orm:"column(config)" description:"计算参数配置"` SysUserId int `orm:"column(sys_user_id)" description:"操作人id"` CreateTime time.Time `orm:"column(create_time)" description:"创建时间"` ModifyTime time.Time `orm:"column(modify_time)" description:"修改时间"` } func init() { orm.RegisterModel(new(CalculateResidualAnalysisConfig)) } // ResidualAnalysisReq 残差分析预览请求 type ResidualAnalysisReq struct { EdbInfoIdA int `description:"指标A"` EdbInfoIdB int `description:"指标B"` EdbInfoId int `description:"残差指标id"` ConfigId int `description:"配置id"` QueryType int `description:"查询类型区分 避免查询过慢 1-查询第一个表格 2-查询需要计算的表格"` ResidualType int `description:"残差类型: 1-映射残差 2-拟合残差"` DateType int `description:"时间类型 -1-自定义时间 0-至今 n-枚举时间(近n年)"` StartDate string `description:"自定义开始日期"` EndDate string `description:"自定义结束日期"` IsOrder bool `description:"true:正序,false:逆序"` IndexType int `description:"1-标准指标 2-领先指标"` LeadValue int `description:"领先值"` LeadFrequency string `description:"领先频度"` LeftIndexMin float64 `description:"指标A左侧下限"` LeftIndexMax float64 `description:"指标A左侧上限"` RightIndexMin float64 `description:"指标B右侧下限"` RightIndexMax float64 `description:"指标B右侧上限"` ResidualIndexMin float64 `description:"残差指标下限"` ResidualIndexMax float64 `description:"残差指标上限"` ContrastIndexMin float64 `description:"对比指标下限"` ContrastIndexMax float64 `description:"对比指标上限"` } // ResidualAnalysisResp 残差分析预览响应 type ResidualAnalysisResp struct { OriginalChartData ChartResp `description:"原始图数据"` MappingChartData ChartResp `description:"映射图数据"` ResidualChartData ChartResp `description:"残差图数据"` A float64 `description:"斜率"` B float64 `description:"截距"` R float64 `description:"相关系数"` R2 float64 `description:"决定系数"` } type ChartResp struct { ChartInfo ResidualAnalysisChartInfo EdbInfoList []ResidualAnalysisChartEdbInfoMapping } type ResidualAnalysisChartInfo struct { ChartName string `description:"来源名称"` ChartNameEn string `description:"英文图表名称"` Unit string `description:"中文单位名称"` UnitEn string `description:"英文单位名称"` UniqueCode string `description:"图表唯一编码"` DateType int `description:"时间类型 0-自定义时间 1-至今 n-枚举时间(近n年)"` StartDate string `description:"自定义开始日期"` EndDate string `description:"自定义结束日期"` ChartType int `description:"生成样式:1:曲线图,2:季节性图"` ChartWidth float64 `description:"线条大小"` Calendar string `description:"公历/农历"` Disabled int `description:"是否禁用,0:启用,1:禁用,默认:0"` Source int `description:"1:ETA图库;2:商品价格曲线;3:相关性图表"` ChartSource string `description:"图表来源str"` ChartSourceEn string `description:"图表来源(英文)"` SourcesFrom string `description:"图表来源"` Instructions string `description:"图表说明"` } type ResidualAnalysisChartEdbInfoMapping struct { EdbInfoId int `description:"指标id"` SourceName string `description:"来源名称"` Source int `description:"来源id"` EdbCode string `description:"指标编码"` EdbName string `description:"指标名称"` EdbNameEn string `description:"英文指标名称"` EdbType int `description:"指标类型:1:基础指标,2:计算指标"` Frequency string `description:"频率"` FrequencyEn string `description:"英文频率"` Unit string `description:"单位"` UnitEn string `description:"英文单位"` StartDate string `description:"起始日期"` EndDate string `description:"终止日期"` ModifyTime string `description:"指标最后更新时间"` MaxData float64 `description:"上限"` MinData float64 `description:"下限"` IsOrder bool `description:"true:逆序:,false:正序"` IsAxis int `description:"1:左轴,0:右轴"` EdbInfoType int `description:"1:标准指标,0:领先指标"` EdbInfoCategoryType int `description:"0:普通指标,1:预测指标"` LeadValue int `description:"领先值"` LeadUnit string `description:"领先单位"` LeadUnitEn string `description:"领先英文单位"` ChartStyle string `description:"图表类型"` ChartColor string `description:"颜色"` PredictChartColor string `description:"预测数据的颜色"` ChartWidth float64 `description:"线条大小"` ChartType int `description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图,7:柱方图,8:商品价格曲线图,9:相关性图"` LatestDate string `description:"数据最新日期"` LatestValue float64 `description:"数据最新值"` MinValue float64 `description:"最小值"` MaxValue float64 `description:"最大值"` DataList interface{} } type ResidualAnalysisIndexSaveReq struct { EdbInfoIdA int `description:"指标A"` EdbInfoIdB int `description:"指标B"` Source int `description:"99-映射残差 100-拟合残差"` EdbCode string `description:"指标编码"` EdbName string `description:"指标名称"` EdbNameEn string `description:"英文指标名称"` EdbType int `description:"指标类型:1:基础指标,2:计算指标"` Frequency string `description:"频率"` FrequencyEn string `description:"英文频率"` Unit string `description:"单位"` UnitEn string `description:"英文单位"` Calendar string `description:"公历/农历"` ClassifyId int `description:"分类id"` ConfigId int `description:"残差配置id"` ResidualType int `orm:"column(residual_type)" description:"残差类型: 1-映射残差 2-拟合残差"` IndexType int `orm:"column(index_type)" description:"指标类型:1-映射指标 2-残差指标 3-因变量指标 4-自变量指标"` DataList []edbDataResidualAnalysis `description:"指标数据"` } // ResidualAnalysisConfigVo 残差分析配置vo type ResidualAnalysisConfigVo struct { DateType int `description:"时间类型 -1-自定义时间 0-至今 n-枚举时间(近n年)"` StartDate string `description:"自定义开始日期"` EndDate string `description:"自定义结束日期"` IsOrder bool `description:"true:正序,false:逆序"` IndexType int `description:"1-标准指标 2-领先指标"` LeadValue int `description:"领先值"` LeadFrequency string `description:"领先频度"` LeftIndexMin float64 `description:"指标A左侧下限"` LeftIndexMax float64 `description:"指标A左侧上限"` RightIndexMin float64 `description:"指标B右侧下限"` RightIndexMax float64 `description:"指标B右侧上限"` ResidualIndexMin float64 `description:"残差指标下限"` ResidualIndexMax float64 `description:"残差指标上限"` ContrastIndexMin float64 `description:"对比指标下限"` ContrastIndexMax float64 `description:"对比指标上限"` } type DetailEdbInfoList struct { EdbInfoId int `orm:"column(edb_info_id);pk"` EdbInfoType int `description:"指标类型,0:普通指标,1:预测指标"` IndexType int `orm:"column(index_type)" description:"指标类型:1-映射指标 2-残差指标 3-因变量指标 4-自变量指标"` SourceName string `description:"来源名称"` Source int `description:"来源id"` EdbCode string `description:"指标编码"` EdbNameEn string `description:"英文指标名称"` EdbName string `description:"指标名称"` Frequency string `description:"频率"` FrequencyEn string `description:"英文频率"` Unit string `description:"单位"` UnitEn string `description:"英文单位"` ClassifyId int `description:"分类id"` } // ResidualAnalysisDetailResp 详情响应接口 type ResidualAnalysisDetailResp struct { ConfigInfo *CalculateResidualAnalysisConfig EdbInfoList []*DetailEdbInfoList ResidualType int `description:"残差类型: 1-映射残差 2-拟合残差"` } // GetResidualAnalysisConfigById 根据配置id查询配置信息 func GetResidualAnalysisConfigById(configId int) (residualAnalysisConfig CalculateResidualAnalysisConfig, err error) { o := orm.NewOrmUsingDB("data") sql := "SELECT * FROM calculate_residual_analysis_config WHERE calculate_residual_analysis_config_id=?" err = o.Raw(sql, configId).QueryRow(&residualAnalysisConfig) return residualAnalysisConfig, nil } // UpdateResidualAnalysisConfig 更新配置信息 func UpdateResidualAnalysisConfig(config CalculateResidualAnalysisConfig) (err error) { o := orm.NewOrmUsingDB("data") _, err = o.Update(&config) if err != nil { return err } return nil } // SaveResidualAnalysisConfig 保存配置信息 func SaveResidualAnalysisConfig(config CalculateResidualAnalysisConfig) (id int64, err error) { o := orm.NewOrmUsingDB("data") id, err = o.Insert(&config) if err != nil { return 0, err } return id, nil }