1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843 |
- package data_manage
- import (
- "encoding/json"
- "eta/eta_api/models"
- "eta/eta_api/models/data_manage"
- "eta/eta_api/models/data_manage/request"
- "eta/eta_api/models/data_manage/response"
- "eta/eta_api/models/system"
- "eta/eta_api/services/data"
- correlationServ "eta/eta_api/services/data/correlation"
- "eta/eta_api/utils"
- "fmt"
- "math"
- "strconv"
- "strings"
- "time"
- )
- //多图配置
- // MultipleGraphConfigSave
- // @Title 保存配置接口
- // @Description 保存配置接口
- // @Param request body request.SaveMultipleGraphConfigReq true "type json string"
- // @Success Ret=200 返回图表id
- // @router /multiple_graph/config/save [post]
- func (this *ChartInfoController) MultipleGraphConfigSave() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.SaveMultipleGraphConfigReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.EdbInfoIdA <= 0 {
- if this.Lang == utils.EnLangVersion {
- br.Msg = "Indicator A not selected"
- } else {
- br.Msg = "指标A未选择"
- }
- br.IsSendEmail = false
- return
- }
- _, err = data_manage.GetEdbInfoById(req.EdbInfoIdA)
- if err != nil {
- br.Msg = "指标A异常"
- br.ErrMsg = "指标A异常,err:" + err.Error()
- if err.Error() == utils.ErrNoRow() {
- br.Msg = `指标A不存在`
- br.IsSendEmail = false
- }
- return
- }
- if req.EdbInfoIdB <= 0 {
- if this.Lang == utils.EnLangVersion {
- br.Msg = "Indicator B not selected"
- } else {
- br.Msg = "指标B未选择"
- }
- br.IsSendEmail = false
- return
- }
- _, err = data_manage.GetEdbInfoById(req.EdbInfoIdB)
- if err != nil {
- br.Msg = "指标B异常"
- br.ErrMsg = "指标B异常,err:" + err.Error()
- if err.Error() == utils.ErrNoRow() {
- br.Msg = `指标B不存在`
- br.IsSendEmail = false
- }
- return
- }
- curveStrByte, err := json.Marshal(req.Curve)
- if err != nil {
- br.Msg = `曲线图配置异常`
- br.ErrMsg = `曲线图配置异常,ERR:` + err.Error()
- return
- }
- if req.Correlation.LeadValue <= 0 {
- br.Msg = `分析周期不允许设置为负数或0`
- br.IsSendEmail = false
- return
- }
- correlationStrByte, err := json.Marshal(req.Correlation)
- if err != nil {
- br.Msg = `相关性配置异常`
- br.ErrMsg = `相关性配置异常,ERR:` + err.Error()
- return
- }
- rollingCorrelationStrByte, err := json.Marshal(req.RollingCorrelation)
- if err != nil {
- br.Msg = `滚动相关性配置异常`
- br.ErrMsg = `滚动相关性配置异常,ERR:` + err.Error()
- return
- }
- var multipleGraphConfig *data_manage.MultipleGraphConfig
- if req.MultipleGraphConfigId > 0 {
- multipleGraphConfig, err = data_manage.GetMultipleGraphConfigById(req.MultipleGraphConfigId)
- if err != nil {
- br.Msg = `不存在该配置`
- br.ErrMsg = `不存在该配置`
- return
- }
- multipleGraphConfig.EdbInfoIdA = req.EdbInfoIdA
- multipleGraphConfig.EdbInfoIdB = req.EdbInfoIdB
- multipleGraphConfig.Curve = string(curveStrByte)
- multipleGraphConfig.Correlation = string(correlationStrByte)
- multipleGraphConfig.RollingCorrelation = string(rollingCorrelationStrByte)
- multipleGraphConfig.ModifyTime = time.Now()
- err = multipleGraphConfig.Update([]string{"EdbInfoIdA", "EdbInfoIdB", "Curve", "Correlation", "RollingCorrelation", "ModifyTime"})
- } else {
- multipleGraphConfig = &data_manage.MultipleGraphConfig{
- //MultipleGraphConfigId: 0,
- EdbInfoIdA: req.EdbInfoIdA,
- EdbInfoIdB: req.EdbInfoIdB,
- Curve: string(curveStrByte),
- Correlation: string(correlationStrByte),
- RollingCorrelation: string(rollingCorrelationStrByte),
- SysUserId: this.SysUser.AdminId,
- SysUserRealName: this.SysUser.RealName,
- ModifyTime: time.Now(),
- CreateTime: time.Now(),
- }
- err = data_manage.AddMultipleGraphConfig(multipleGraphConfig)
- }
- if err != nil {
- br.Msg = `保存失败`
- br.ErrMsg = `保存失败,Err:` + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = multipleGraphConfig
- br.IsAddLog = true
- }
- // MultipleGraphPreview
- // @Title 批量添加图表的预览接口
- // @Description 批量添加图表的预览接口
- // @Param request body request.SaveMultipleGraphConfigReq true "type json string"
- // @Success Ret=200 返回图表id
- // @router /multiple_graph/preview [post]
- func (this *ChartInfoController) MultipleGraphPreview() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.SaveMultipleGraphConfigReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList([]int{req.EdbInfoIdA, req.EdbInfoIdB})
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
- return
- }
- var maxDate time.Time
- var edbInfoMappingA, edbInfoMappingB *data_manage.ChartEdbInfoMapping
- for _, v := range mappingList {
- if v.EdbInfoId == req.EdbInfoIdA {
- edbInfoMappingA = v
- }
- if v.EdbInfoId == req.EdbInfoIdB {
- edbInfoMappingB = v
- }
- if v.LatestDate != "" {
- latestDateT, _ := time.Parse(utils.FormatDate, v.LatestDate)
- maxDate = latestDateT
- }
- }
- if edbInfoMappingA == nil {
- br.Msg = "指标A不存在"
- br.IsSendEmail = false
- return
- }
- if edbInfoMappingB == nil {
- br.Msg = "指标B不存在"
- br.IsSendEmail = false
- return
- }
- resp := response.PreviewMultipleGraphConfigResp{}
- chartInfo := new(data_manage.ChartInfoView)
- chartInfo.Calendar = `公历`
- chartInfo.ChartName = edbInfoMappingA.EdbName + "与" + edbInfoMappingB.EdbName
- // 曲线图表信息
- {
- tmpChartInfo := *chartInfo
- curveConf := req.Curve
- edbInfoType := 0
- if curveConf.EdbInfoType {
- edbInfoType = 1
- }
- for _, v := range mappingList {
- v.EdbInfoType = 1
- v.IsOrder = false
- if v.EdbInfoId == req.EdbInfoIdB {
- v.LeadValue = curveConf.LeadValue
- v.LeadUnit = curveConf.LeadUnit
- v.EdbInfoType = edbInfoType
- v.IsOrder = curveConf.IsOrder
- }
- }
- startDate, endDate := utils.GetDateByDateTypeV2(curveConf.DateType, curveConf.StartDate, curveConf.EndDate, curveConf.StartYear, maxDate)
- // 获取图表中的指标数据
- edbList, _, _, _, err, errMsg := data.GetChartEdbData(tmpChartInfo.ChartInfoId, tmpChartInfo.ChartType, tmpChartInfo.Calendar, startDate, endDate, mappingList, tmpChartInfo.ExtraConfig, tmpChartInfo.SeasonExtraConfig)
- if err != nil {
- br.Msg = "获取失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
- return
- }
- warnEdbList := make([]string, 0)
- tmpEdbList := make([]data_manage.ChartEdbInfoMapping, 0)
- for _, v := range edbList {
- if v.IsNullData {
- warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
- }
- chartEdbInfoMapping := *v
- chartEdbInfoMapping.IsOrder = false
- if v.EdbInfoId == req.EdbInfoIdA {
- chartEdbInfoMapping.IsAxis = 1
- chartEdbInfoMapping.MinData = curveConf.LeftMin
- chartEdbInfoMapping.MaxData = curveConf.LeftMax
- chartEdbInfoMapping.ChartColor = `#00F`
- chartEdbInfoMapping.LeadValue = curveConf.LeadValue
- chartEdbInfoMapping.LeadUnit = curveConf.LeadUnit
- chartEdbInfoMapping.ChartWidth = 3
- chartEdbInfoMapping.EdbInfoType = edbInfoType
- } else {
- chartEdbInfoMapping.IsAxis = 0
- chartEdbInfoMapping.MinData = curveConf.RightMin
- chartEdbInfoMapping.MaxData = curveConf.RightMax
- chartEdbInfoMapping.ChartColor = `#F00`
- chartEdbInfoMapping.LeadValue = curveConf.LeadValue
- chartEdbInfoMapping.LeadUnit = curveConf.LeadUnit
- chartEdbInfoMapping.ChartWidth = 1
- chartEdbInfoMapping.IsOrder = curveConf.IsOrder
- chartEdbInfoMapping.EdbInfoType = edbInfoType
- }
- tmpEdbList = append(tmpEdbList, chartEdbInfoMapping)
- }
- if len(warnEdbList) > 0 {
- tmpChartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
- }
- tmpChartInfo.Source = utils.CHART_SOURCE_DEFAULT
- tmpChartInfo.DateType = curveConf.DateType
- tmpChartInfo.StartDate = startDate
- tmpChartInfo.EndDate = endDate
- tmpChartInfo.ChartType = utils.CHART_TYPE_CURVE
- resp.CurveData = response.CurveResp{
- ChartInfo: tmpChartInfo,
- EdbInfoList: tmpEdbList,
- }
- }
- // 相关性图表信息
- {
- correlationConf := req.Correlation
- // 配置了数据才有返回
- if correlationConf.LeadValue > 0 {
- tmpChartInfo := *chartInfo
- moveUnitDays, ok := utils.FrequencyDaysMap[correlationConf.CalculateUnit]
- if !ok {
- br.Msg = "错误的分析周期"
- br.IsSendEmail = false
- return
- }
- startDate := time.Now().AddDate(0, 0, -correlationConf.CalculateValue*moveUnitDays).Format(utils.FormatDate)
- endDate := time.Now().Format(utils.FormatDate)
- xEdbIdValue, yDataList, e := correlationServ.GetChartDataByEdbInfo(edbInfoMappingA, edbInfoMappingB, correlationConf.LeadValue, correlationConf.LeadUnit, startDate, endDate, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取相关性图表, 图表计算值失败, Err:" + e.Error()
- return
- }
- tmpChartInfo.ChartName += fmt.Sprint(`(`, correlationConf.CalculateValue, correlationConf.CalculateUnit, `)`)
- tmpChartInfo.Source = utils.CHART_SOURCE_CORRELATION
- resp.CorrelationData = response.CorrelationResp{
- ChartInfo: tmpChartInfo,
- EdbInfoList: mappingList,
- XEdbIdValue: xEdbIdValue,
- YDataList: yDataList,
- CorrelationChartInfo: data_manage.CorrelationInfo{
- LeadValue: correlationConf.LeadValue,
- LeadUnit: correlationConf.LeadUnit,
- StartDate: startDate,
- EndDate: endDate,
- EdbInfoIdFirst: edbInfoMappingA.EdbInfoId,
- EdbInfoIdSecond: edbInfoMappingB.EdbInfoId,
- },
- }
- }
- }
- // 滚动相关性图表信息
- {
- correlationConf := req.Correlation
- rollingCorrelationConfList := req.RollingCorrelation
- // 配置了数据才有返回
- if correlationConf.LeadValue > 0 {
- //moveUnitDays, ok := utils.FrequencyDaysMap[correlationConf.CalculateUnit]
- //if !ok {
- // br.Msg = "错误的分析周期"
- // br.IsSendEmail = false
- // return
- //}
- //startDate := time.Now().AddDate(0, 0, -correlationConf.CalculateValue*moveUnitDays).Format(utils.FormatDate)
- //endDate := time.Now().Format(utils.FormatDate)
- // 数据的开始/结束日期
- curveConf := req.Curve
- startDate, endDate := utils.GetDateByDateTypeV2(curveConf.DateType, curveConf.StartDate, curveConf.EndDate, curveConf.StartYear, maxDate)
- rollingCorrelationData := make([]interface{}, 0)
- for _, rollingCorrelationConf := range rollingCorrelationConfList {
- if rollingCorrelationConf.CalculateValue > 0 && rollingCorrelationConf.CalculateUnit != `` {
- tmpChartInfo := *chartInfo
- tmpChartInfo.Source = utils.CHART_SOURCE_ROLLING_CORRELATION
- // ”指标A名称“+”指标B名称“+"滚动相关性"+”滚动相关性计算窗口值“+”滚动相关性计算窗口单位“
- // 若滚动相关性的计算周期为30天
- // 1、B即不领先也不滞后时:“指标A名称”与“指标B名称"30天滚动相关性;
- // 2、B有领先时:“指标A名称”与“指标B名称(领先15天)"30天滚动相关性;
- // 3、B滞后时:“指标A名称”与“指标B名称(滞后15天)"30天滚动相关性
- if rollingCorrelationConf.LeadValue == 0 {
- tmpChartInfo.ChartName = fmt.Sprintf(`%s与%s%d%s滚动相关性`, edbInfoMappingA.EdbName, edbInfoMappingB.EdbName, rollingCorrelationConf.CalculateValue, rollingCorrelationConf.CalculateUnit)
- } else if rollingCorrelationConf.LeadValue < 0 {
- tmpChartInfo.ChartName = fmt.Sprintf(`%s与%s(滞后%d%s)%d%s滚动相关性`, edbInfoMappingA.EdbName, edbInfoMappingB.EdbName, int(math.Abs(float64(rollingCorrelationConf.LeadValue))), rollingCorrelationConf.LeadUnit, rollingCorrelationConf.CalculateValue, rollingCorrelationConf.CalculateUnit)
- } else {
- tmpChartInfo.ChartName = fmt.Sprintf(`%s与%s(领先%d%s)%d%s滚动相关性`, edbInfoMappingA.EdbName, edbInfoMappingB.EdbName, int(math.Abs(float64(rollingCorrelationConf.LeadValue))), rollingCorrelationConf.LeadUnit, rollingCorrelationConf.CalculateValue, rollingCorrelationConf.CalculateUnit)
- }
- dataResp, e := correlationServ.GetRollingCorrelationChartDataByEdbInfo(edbInfoMappingA, edbInfoMappingB, rollingCorrelationConf.LeadValue, rollingCorrelationConf.LeadUnit, rollingCorrelationConf.CalculateValue, rollingCorrelationConf.CalculateUnit, startDate, endDate, tmpChartInfo.ChartName, tmpChartInfo.ChartNameEn)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取滚动相关性图表, 图表计算值失败, Err:" + e.Error()
- return
- }
- rollingCorrelationData = append(rollingCorrelationData, response.RollingCorrelationResp{
- ChartInfo: tmpChartInfo,
- EdbInfoList: mappingList,
- DataResp: dataResp,
- CorrelationChartInfo: data_manage.CorrelationInfo{
- LeadValue: rollingCorrelationConf.LeadValue,
- LeadUnit: rollingCorrelationConf.LeadUnit,
- CalculateValue: rollingCorrelationConf.CalculateValue,
- CalculateUnit: rollingCorrelationConf.CalculateUnit,
- StartDate: startDate,
- EndDate: endDate,
- EdbInfoIdFirst: edbInfoMappingA.EdbInfoId,
- EdbInfoIdSecond: edbInfoMappingB.EdbInfoId,
- },
- })
- } else {
- rollingCorrelationData = append(rollingCorrelationData, nil)
- }
- }
- resp.RollingCorrelationData = rollingCorrelationData
- } else {
- resp.RollingCorrelationData = []interface{}{nil, nil}
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // MultipleGraphPreviewCurve
- // @Title 批量添加图表的预览曲线图接口(只返回曲线图的数据)
- // @Description 批量添加图表的预览曲线图接口
- // @Param request body request.SaveMultipleGraphConfigReq true "type json string"
- // @Success Ret=200 返回图表id
- // @router /multiple_graph/preview_cure [post]
- func (this *ChartInfoController) MultipleGraphPreviewCurve() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.SaveMultipleGraphConfigReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList([]int{req.EdbInfoIdA, req.EdbInfoIdB})
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
- return
- }
- var edbInfoMappingA, edbInfoMappingB *data_manage.ChartEdbInfoMapping
- for _, v := range mappingList {
- if v.EdbInfoId == req.EdbInfoIdA {
- edbInfoMappingA = v
- }
- if v.EdbInfoId == req.EdbInfoIdB {
- edbInfoMappingB = v
- }
- }
- if edbInfoMappingA == nil {
- br.Msg = "指标A不存在"
- br.IsSendEmail = false
- return
- }
- if edbInfoMappingB == nil {
- br.Msg = "指标B不存在"
- br.IsSendEmail = false
- return
- }
- resp := response.PreviewMultipleGraphConfigResp{}
- chartInfo := new(data_manage.ChartInfoView)
- chartInfo.Calendar = `公历`
- chartInfo.ChartName = edbInfoMappingA.EdbName + "与" + edbInfoMappingB.EdbName
- // 曲线图表信息
- {
- tmpChartInfo := *chartInfo
- curveConf := req.Curve
- startDate := curveConf.StartDate
- endDate := curveConf.EndDate
- switch curveConf.DateType {
- case 1:
- startDate = "2000-01-01"
- case 2:
- startDate = "2010-01-01"
- case 3:
- startDate = "2015-01-01"
- case 4:
- //startDate = strconv.Itoa(time.Now().Year()) + "-01-01"
- startDate = "2021-01-01"
- case 5:
- startDate = startDate + "-01"
- endDate = endDate + "-01"
- case 6:
- startDate = startDate + "-01"
- case 7:
- startDate = "2018-01-01"
- case 8:
- startDate = "2019-01-01"
- case 9:
- startDate = "2020-01-01"
- case 11:
- startDate = "2022-01-01"
- case 12:
- startDate = "2023-01-01"
- case 13:
- startDate = "2024-01-01"
- }
- edbInfoType := 0
- if curveConf.EdbInfoType {
- edbInfoType = 1
- }
- for _, v := range mappingList {
- v.EdbInfoType = 1
- v.IsOrder = false
- if v.EdbInfoId == req.EdbInfoIdB {
- v.LeadValue = curveConf.LeadValue
- v.LeadUnit = curveConf.LeadUnit
- v.EdbInfoType = edbInfoType
- v.IsOrder = curveConf.IsOrder
- }
- }
- // 获取图表中的指标数据
- edbList, _, _, _, err, errMsg := data.GetChartEdbData(tmpChartInfo.ChartInfoId, tmpChartInfo.ChartType, tmpChartInfo.Calendar, startDate, endDate, mappingList, tmpChartInfo.ExtraConfig, tmpChartInfo.SeasonExtraConfig)
- if err != nil {
- br.Msg = "获取失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
- return
- }
- warnEdbList := make([]string, 0)
- tmpEdbList := make([]data_manage.ChartEdbInfoMapping, 0)
- for _, v := range edbList {
- if v.IsNullData {
- warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
- }
- chartEdbInfoMapping := *v
- chartEdbInfoMapping.IsOrder = false
- chartEdbInfoMapping.EdbInfoType = 1
- if v.EdbInfoId == req.EdbInfoIdA {
- chartEdbInfoMapping.IsAxis = 1
- chartEdbInfoMapping.MinData = curveConf.LeftMin
- chartEdbInfoMapping.MaxData = curveConf.LeftMax
- chartEdbInfoMapping.ChartColor = `#00F`
- //chartEdbInfoMapping.LeadValue = curveConf.LeadValue
- //chartEdbInfoMapping.LeadUnit = curveConf.LeadUnit
- chartEdbInfoMapping.ChartWidth = 3
- } else {
- chartEdbInfoMapping.IsAxis = 0
- chartEdbInfoMapping.MinData = curveConf.RightMin
- chartEdbInfoMapping.MaxData = curveConf.RightMax
- chartEdbInfoMapping.ChartColor = `#F00`
- chartEdbInfoMapping.LeadValue = curveConf.LeadValue
- chartEdbInfoMapping.LeadUnit = curveConf.LeadUnit
- chartEdbInfoMapping.ChartWidth = 1
- chartEdbInfoMapping.IsOrder = curveConf.IsOrder
- chartEdbInfoMapping.EdbInfoType = edbInfoType
- }
- tmpEdbList = append(tmpEdbList, chartEdbInfoMapping)
- }
- if len(warnEdbList) > 0 {
- tmpChartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
- }
- tmpChartInfo.Source = utils.CHART_SOURCE_DEFAULT
- tmpChartInfo.DateType = curveConf.DateType
- tmpChartInfo.StartDate = startDate
- tmpChartInfo.EndDate = endDate
- tmpChartInfo.ChartType = utils.CHART_TYPE_CURVE
- resp.CurveData = response.CurveResp{
- ChartInfo: tmpChartInfo,
- EdbInfoList: tmpEdbList,
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // MultipleGraphConfigSaveChart
- // @Title 保存图表接口
- // @Description 保存图表接口
- // @Param request body request.SaveMultipleGraphChartReq true "type json string"
- // @Success Ret=200 返回图表id
- // @router /multiple_graph/chart/save [post]
- func (this *ChartInfoController) MultipleGraphConfigSaveChart() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.SaveMultipleGraphChartReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- cacheKey := "CACHE_CHART_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
- if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
- br.Msg = "系统处理中,请稍后重试!"
- br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
- return
- }
- defer func() {
- _ = utils.Rc.Delete(cacheKey)
- }()
- if req.MultipleGraphConfigId <= 0 {
- br.Msg = "配置未保存"
- br.IsSendEmail = false
- return
- }
- if req.IsSaveAs {
- CopyMultipleGraphConfigSaveChart(req, this, br, sysUser)
- return
- }
- mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList([]int{req.EdbInfoIdA, req.EdbInfoIdB})
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
- return
- }
- var edbInfoMappingA, edbInfoMappingB *data_manage.ChartEdbInfoMapping
- for _, v := range mappingList {
- if v.EdbInfoId == req.EdbInfoIdA {
- edbInfoMappingA = v
- }
- if v.EdbInfoId == req.EdbInfoIdB {
- edbInfoMappingB = v
- }
- }
- if edbInfoMappingA == nil {
- br.Msg = "指标A不存在"
- br.IsSendEmail = false
- return
- }
- if edbInfoMappingB == nil {
- br.Msg = "指标B不存在"
- br.IsSendEmail = false
- return
- }
- multipleGraphConfigChartMapping, err := data_manage.GetMultipleGraphConfigChartMappingByIdAndSource(req.MultipleGraphConfigId, req.Source)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = `保存失败`
- br.ErrMsg = "获取配置与图表的关联关系失败,ERR:" + err.Error()
- return
- }
- err = nil
- var isAdd bool
- var chartInfoId int
- if multipleGraphConfigChartMapping == nil {
- isAdd = true
- } else {
- chartInfo, err := data_manage.GetChartInfoById(multipleGraphConfigChartMapping.ChartInfoId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = `保存失败`
- br.ErrMsg = "获取图表信息失败,ERR:" + err.Error()
- return
- }
- // 说明图还在,没有被删除
- if chartInfo != nil {
- chartInfoId = multipleGraphConfigChartMapping.ChartInfoId
- req.ChartName = chartInfo.ChartName
- req.ClassifyId = chartInfo.ChartClassifyId
- }
- }
- var chartInfo *data_manage.ChartInfo
- var errMsg string
- isSendEmail := true
- switch req.Source {
- case 1: // 曲线图
- curveConf := req.Curve
- edbInfoType := 1 //1:标准指标,0:领先指标
- if !curveConf.EdbInfoType {
- edbInfoType = 0
- }
- chartSaveItemList := []*data_manage.ChartSaveItem{
- {
- EdbInfoId: edbInfoMappingA.EdbInfoId,
- MaxData: curveConf.LeftMax,
- MinData: curveConf.LeftMin,
- IsOrder: false,
- IsAxis: 1,
- EdbInfoType: 1,
- //LeadValue: curveConf.LeadValue,
- //LeadUnit: curveConf.LeadUnit,
- ChartStyle: "spline",
- ChartColor: `#00F`,
- PredictChartColor: "",
- ChartWidth: 3,
- Source: utils.CHART_SOURCE_DEFAULT,
- }, {
- EdbInfoId: edbInfoMappingB.EdbInfoId,
- MaxData: curveConf.RightMax,
- MinData: curveConf.RightMin,
- IsOrder: curveConf.IsOrder,
- IsAxis: 0,
- EdbInfoType: edbInfoType,
- LeadValue: curveConf.LeadValue,
- LeadUnit: curveConf.LeadUnit,
- ChartStyle: "spline",
- ChartColor: `#F00`,
- PredictChartColor: "",
- ChartWidth: 1,
- Source: utils.CHART_SOURCE_DEFAULT,
- },
- }
- if chartInfoId <= 0 {
- addChartReq := data_manage.AddChartInfoReq{
- ChartEdbInfoList: chartSaveItemList,
- ChartClassifyId: req.ClassifyId,
- ChartName: req.ChartName,
- ChartType: utils.CHART_TYPE_CURVE,
- DateType: curveConf.DateType,
- StartDate: curveConf.StartDate,
- EndDate: curveConf.EndDate,
- StartYear: curveConf.StartYear,
- Calendar: "公历",
- LeftMin: fmt.Sprint(curveConf.LeftMin),
- LeftMax: fmt.Sprint(curveConf.LeftMax),
- RightMin: fmt.Sprint(curveConf.RightMin),
- RightMax: fmt.Sprint(curveConf.RightMax),
- Right2Min: fmt.Sprint(curveConf.Right2Min),
- Right2Max: fmt.Sprint(curveConf.Right2Max),
- }
- chartInfo, err, errMsg, isSendEmail = data.AddChartInfo(addChartReq, sysUser.AdminId, sysUser.RealName, this.Lang)
- } else {
- editChartReq := data_manage.EditChartInfoReq{
- ChartInfoId: multipleGraphConfigChartMapping.ChartInfoId,
- ChartName: req.ChartName,
- ChartClassifyId: req.ClassifyId,
- ChartEdbInfoList: chartSaveItemList,
- ChartType: utils.CHART_TYPE_CURVE,
- DateType: curveConf.DateType,
- StartDate: curveConf.StartDate,
- EndDate: curveConf.EndDate,
- StartYear: curveConf.StartYear,
- Calendar: "公历",
- LeftMin: fmt.Sprint(curveConf.LeftMin),
- LeftMax: fmt.Sprint(curveConf.LeftMax),
- RightMin: fmt.Sprint(curveConf.RightMin),
- RightMax: fmt.Sprint(curveConf.RightMax),
- Right2Min: fmt.Sprint(curveConf.Right2Min),
- Right2Max: fmt.Sprint(curveConf.Right2Max),
- }
- chartInfo, err, errMsg, isSendEmail = data.EditChartInfo(editChartReq, sysUser, this.Lang)
- if err != nil {
- br.Msg = "保存失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = err.Error()
- br.IsSendEmail = isSendEmail
- return
- }
- }
- case 2, 3, 4: // 相关性图(滚动相关性)
- correlationConf := req.Correlation
- // 配置了数据才有返回
- if correlationConf.LeadValue > 0 {
- leadValue := correlationConf.LeadValue
- leadUnit := correlationConf.LeadUnit
- baseCalculateValue := correlationConf.CalculateValue
- baseCalculateUnit := correlationConf.CalculateUnit
- calculateValue := baseCalculateValue
- calculateUnit := baseCalculateUnit
- chartSource := utils.CHART_SOURCE_CORRELATION // 默认是相关性图
- moveUnitDays, ok := utils.FrequencyDaysMap[calculateUnit]
- if !ok {
- br.Msg = "错误的分析周期"
- br.IsSendEmail = false
- return
- }
- startDate := time.Now().AddDate(0, 0, -correlationConf.CalculateValue*moveUnitDays).Format(utils.FormatDate)
- endDate := time.Now().Format(utils.FormatDate)
- // 日期类型
- var dateType int
- if req.Source != 2 {
- chartSource = utils.CHART_SOURCE_ROLLING_CORRELATION
- var rollingCorrelation data_manage.RollingCorrelationConfig
- if req.Source == 3 {
- rollingCorrelation = req.RollingCorrelation[0]
- } else {
- rollingCorrelation = req.RollingCorrelation[1]
- }
- leadValue = rollingCorrelation.LeadValue
- leadUnit = rollingCorrelation.LeadUnit
- calculateValue = rollingCorrelation.CalculateValue
- calculateUnit = rollingCorrelation.CalculateUnit
- // 开始日期,结束日期
- dateType = req.Curve.DateType
- startDate, endDate = utils.GetDateByDateType(req.Curve.DateType, req.Curve.StartDate, req.Curve.EndDate)
- }
- // 图例, 图表来源
- var sourceFrom, extraConfig string
- if req.CorrelationExtraConfig != nil {
- b, e := json.Marshal(req.CorrelationExtraConfig)
- if e != nil {
- br.Msg = "保存失败"
- br.ErrMsg = fmt.Sprintf("相关性图表图例信息JSON格式化失败, Err: %v", e)
- return
- }
- extraConfig = string(b)
- }
- if req.SourcesFrom != nil {
- b, e := json.Marshal(req.SourcesFrom)
- if e != nil {
- br.Msg = "保存失败"
- br.ErrMsg = fmt.Sprintf("图表来源JSON格式化失败, Err: %v", e)
- return
- }
- sourceFrom = string(b)
- }
- correlationChartInfoReq := data_manage.CorrelationChartInfoReq{
- LeadValue: leadValue,
- LeadUnit: leadUnit,
- CalculateValue: calculateValue,
- CalculateUnit: calculateUnit,
- BaseCalculateValue: baseCalculateValue,
- BaseCalculateUnit: baseCalculateUnit,
- DateType: dateType,
- StartDate: startDate,
- EndDate: endDate,
- EdbInfoIdList: []data_manage.CorrelationChartInfoEdbItemReq{
- {
- EdbInfoId: edbInfoMappingA.EdbInfoId,
- Name: "",
- NameEn: "",
- }, {
- EdbInfoId: edbInfoMappingB.EdbInfoId,
- Name: "",
- NameEn: "",
- },
- },
- }
- if chartInfoId <= 0 {
- addChartReq := data_manage.AddChartInfoReq{
- ChartClassifyId: req.ClassifyId,
- ChartName: req.ChartName,
- ChartType: utils.CHART_TYPE_CURVE,
- Calendar: "公历",
- CorrelationChartInfo: correlationChartInfoReq,
- ExtraConfig: extraConfig,
- SourcesFrom: sourceFrom,
- }
- chartInfo, err, errMsg, isSendEmail = correlationServ.AddChartInfo(addChartReq, chartSource, sysUser, this.Lang)
- } else {
- editChartReq := data_manage.EditChartInfoReq{
- ChartInfoId: multipleGraphConfigChartMapping.ChartInfoId,
- ChartName: req.ChartName,
- ChartClassifyId: req.ClassifyId,
- ChartType: utils.CHART_TYPE_CURVE,
- Calendar: "公历",
- CorrelationChartInfo: correlationChartInfoReq,
- ExtraConfig: extraConfig,
- SourcesFrom: sourceFrom,
- }
- chartInfo, err, errMsg, isSendEmail = correlationServ.EditChartInfo(editChartReq, sysUser, this.Lang)
- if err != nil {
- br.Msg = "保存失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = err.Error()
- br.IsSendEmail = isSendEmail
- return
- }
- }
- }
- default:
- br.Msg = "错误的来源"
- br.ErrMsg = "错误的来源,source:" + strconv.Itoa(req.Source)
- br.IsSendEmail = false
- return
- }
- if err != nil {
- br.Msg = "保存失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = err.Error()
- br.IsSendEmail = isSendEmail
- return
- }
- // 如果图没有建立关联关系,那么就需要添加关系
- if isAdd {
- multipleGraphConfigChartMapping = &data_manage.MultipleGraphConfigChartMapping{
- //Id: 0,
- MultipleGraphConfigId: req.MultipleGraphConfigId,
- ChartInfoId: chartInfo.ChartInfoId,
- Source: req.Source,
- ModifyTime: time.Now(),
- CreateTime: time.Now(),
- }
- err = data_manage.AddMultipleGraphConfigChartMapping(multipleGraphConfigChartMapping)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存配置与图表的关联关系失败,ERR:" + err.Error()
- return
- }
- } else if multipleGraphConfigChartMapping != nil {
- multipleGraphConfigChartMapping.ChartInfoId = chartInfo.ChartInfoId
- multipleGraphConfigChartMapping.ModifyTime = time.Now()
- err = multipleGraphConfigChartMapping.Update([]string{"ChartInfoId", "ModifyTime"})
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存配置与图表的关联关系失败,ERR:" + err.Error()
- return
- }
- }
- //新增操作日志
- {
- chartLog := new(data_manage.ChartInfoLog)
- chartLog.ChartInfoId = chartInfo.ChartInfoId
- chartLog.ChartName = req.ChartName
- chartLog.ChartClassifyId = req.ClassifyId
- chartLog.SysUserId = sysUser.AdminId
- chartLog.SysUserRealName = sysUser.RealName
- chartLog.UniqueCode = chartInfo.UniqueCode
- chartLog.CreateTime = time.Now()
- chartLog.Content = string(this.Ctx.Input.RequestBody)
- chartLog.Status = "多图配置保存图表"
- chartLog.Method = this.Ctx.Input.URI()
- go data_manage.AddChartInfoLog(chartLog)
- }
- resp := new(data_manage.AddChartInfoResp)
- resp.ChartInfoId = chartInfo.ChartInfoId
- resp.UniqueCode = chartInfo.UniqueCode
- resp.ChartType = chartInfo.ChartType
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- br.IsAddLog = true
- }
- // CopyMultipleGraphConfigSaveChart 图表另存为
- func CopyMultipleGraphConfigSaveChart(req request.SaveMultipleGraphChartReq, this *ChartInfoController, br *models.BaseResponse, sysUser *system.Admin) {
- mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList([]int{req.EdbInfoIdA, req.EdbInfoIdB})
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
- return
- }
- var edbInfoMappingA, edbInfoMappingB *data_manage.ChartEdbInfoMapping
- for _, v := range mappingList {
- if v.EdbInfoId == req.EdbInfoIdA {
- edbInfoMappingA = v
- }
- if v.EdbInfoId == req.EdbInfoIdB {
- edbInfoMappingB = v
- }
- }
- if edbInfoMappingA == nil {
- br.Msg = "指标A不存在"
- br.IsSendEmail = false
- return
- }
- if edbInfoMappingB == nil {
- br.Msg = "指标B不存在"
- br.IsSendEmail = false
- return
- }
- multipleGraphConfigChartMapping, err := data_manage.GetMultipleGraphConfigChartMappingByIdAndSource(req.MultipleGraphConfigId, req.Source)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = `保存失败`
- br.ErrMsg = "获取配置与图表的关联关系失败,ERR:" + err.Error()
- return
- }
- // 原图
- oldChartInfo, err := data_manage.GetChartInfoById(multipleGraphConfigChartMapping.ChartInfoId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = `保存失败`
- br.ErrMsg = "获取图表信息失败,ERR:" + err.Error()
- return
- }
- // 说明图还在,没有被删除
- if oldChartInfo == nil {
- br.Msg = "原图不存在"
- br.IsSendEmail = false
- }
- var chartInfo *data_manage.ChartInfo
- var errMsg string
- isSendEmail := true
- switch req.Source {
- case 1: // 曲线图
- curveConf := req.Curve
- edbInfoType := 1 //1:标准指标,0:领先指标
- if !curveConf.EdbInfoType {
- edbInfoType = 0
- }
- chartSaveItemList := []*data_manage.ChartSaveItem{
- {
- EdbInfoId: edbInfoMappingA.EdbInfoId,
- MaxData: curveConf.LeftMax,
- MinData: curveConf.LeftMin,
- IsOrder: false,
- IsAxis: 1,
- EdbInfoType: 1,
- //LeadValue: curveConf.LeadValue,
- //LeadUnit: curveConf.LeadUnit,
- ChartStyle: "spline",
- ChartColor: `#00F`,
- PredictChartColor: "",
- ChartWidth: 3,
- Source: utils.CHART_SOURCE_DEFAULT,
- }, {
- EdbInfoId: edbInfoMappingB.EdbInfoId,
- MaxData: curveConf.RightMax,
- MinData: curveConf.RightMin,
- IsOrder: curveConf.IsOrder,
- IsAxis: 0,
- EdbInfoType: edbInfoType,
- LeadValue: curveConf.LeadValue,
- LeadUnit: curveConf.LeadUnit,
- ChartStyle: "spline",
- ChartColor: `#F00`,
- PredictChartColor: "",
- ChartWidth: 1,
- Source: utils.CHART_SOURCE_DEFAULT,
- },
- }
- addChartReq := data_manage.AddChartInfoReq{
- ChartEdbInfoList: chartSaveItemList,
- ChartClassifyId: req.ClassifyId,
- ChartName: req.ChartName,
- ChartType: utils.CHART_TYPE_CURVE,
- DateType: curveConf.DateType,
- StartDate: curveConf.StartDate,
- EndDate: curveConf.EndDate,
- StartYear: curveConf.StartYear,
- Calendar: "公历",
- LeftMin: fmt.Sprint(curveConf.LeftMin),
- LeftMax: fmt.Sprint(curveConf.LeftMax),
- RightMin: fmt.Sprint(curveConf.RightMin),
- RightMax: fmt.Sprint(curveConf.RightMax),
- }
- chartInfo, err, errMsg, isSendEmail = data.AddChartInfo(addChartReq, sysUser.AdminId, sysUser.RealName, this.Lang)
- case 2: // 相关性图
- correlationConf := req.Correlation
- // 配置了数据才有返回
- if correlationConf.LeadValue > 0 {
- leadValue := correlationConf.LeadValue
- leadUnit := correlationConf.LeadUnit
- calculateValue := correlationConf.CalculateValue
- calculateUnit := correlationConf.CalculateUnit
- moveUnitDays, ok := utils.FrequencyDaysMap[calculateUnit]
- if !ok {
- br.Msg = "错误的分析周期"
- br.IsSendEmail = false
- return
- }
- startDate := time.Now().AddDate(0, 0, -correlationConf.CalculateValue*moveUnitDays).Format(utils.FormatDate)
- endDate := time.Now().Format(utils.FormatDate)
- correlationChartInfoReq := data_manage.CorrelationChartInfoReq{
- LeadValue: leadValue,
- LeadUnit: leadUnit,
- CalculateValue: calculateValue,
- CalculateUnit: calculateUnit,
- StartDate: startDate,
- EndDate: endDate,
- EdbInfoIdList: []data_manage.CorrelationChartInfoEdbItemReq{
- {
- EdbInfoId: edbInfoMappingA.EdbInfoId,
- Name: "",
- NameEn: "",
- }, {
- EdbInfoId: edbInfoMappingB.EdbInfoId,
- Name: "",
- NameEn: "",
- },
- },
- }
- chartInfo, err, errMsg, isSendEmail = correlationServ.CopyChartInfo(multipleGraphConfigChartMapping.MultipleGraphConfigId, req.ClassifyId, req.ChartName, correlationChartInfoReq, oldChartInfo, sysUser, this.Lang)
- }
- default:
- br.Msg = "错误的来源"
- br.ErrMsg = "错误的来源,source:" + strconv.Itoa(req.Source)
- br.IsSendEmail = false
- return
- }
- if err != nil {
- br.Msg = "保存失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = err.Error()
- br.IsSendEmail = isSendEmail
- return
- }
- //新增操作日志
- {
- chartLog := new(data_manage.ChartInfoLog)
- chartLog.ChartInfoId = chartInfo.ChartInfoId
- chartLog.ChartName = req.ChartName
- chartLog.ChartClassifyId = req.ClassifyId
- chartLog.SysUserId = sysUser.AdminId
- chartLog.SysUserRealName = sysUser.RealName
- chartLog.UniqueCode = chartInfo.UniqueCode
- chartLog.CreateTime = time.Now()
- chartLog.Content = string(this.Ctx.Input.RequestBody)
- chartLog.Status = "多图配置另存为图表"
- chartLog.Method = this.Ctx.Input.URI()
- go data_manage.AddChartInfoLog(chartLog)
- }
- resp := new(data_manage.AddChartInfoResp)
- resp.ChartInfoId = chartInfo.ChartInfoId
- resp.UniqueCode = chartInfo.UniqueCode
- resp.ChartType = chartInfo.ChartType
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- br.IsAddLog = true
- }
- // MultipleGraphConfigSaveEdb
- // @Title 保存指标接口
- // @Description 保存指标接口
- // @Param request body request.SaveMultipleGraphEdbReq true "type json string"
- // @Success Ret=200 返回指标id
- // @router /multiple_graph/edb/save [post]
- func (this *ChartInfoController) MultipleGraphConfigSaveEdb() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.SaveMultipleGraphEdbReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- cacheKey := "CACHE_CHART_EDB_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
- if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
- br.Msg = "系统处理中,请稍后重试!"
- br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
- return
- }
- defer func() {
- _ = utils.Rc.Delete(cacheKey)
- }()
- mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList([]int{req.EdbInfoIdA, req.EdbInfoIdB})
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
- return
- }
- var edbInfoMappingA, edbInfoMappingB *data_manage.ChartEdbInfoMapping
- for _, v := range mappingList {
- if v.EdbInfoId == req.EdbInfoIdA {
- edbInfoMappingA = v
- }
- if v.EdbInfoId == req.EdbInfoIdB {
- edbInfoMappingB = v
- }
- }
- if edbInfoMappingA == nil {
- br.Msg = "指标A不存在"
- br.IsSendEmail = false
- return
- }
- if edbInfoMappingB == nil {
- br.Msg = "指标B不存在"
- br.IsSendEmail = false
- return
- }
- correlationConf := req.Correlation
- // 配置了数据才有返回
- if correlationConf.LeadValue <= 0 {
- br.Msg = "相关性计算窗口必须大于0"
- br.IsSendEmail = false
- return
- }
- // 滚动相关性配置
- var rollingCorrelation data_manage.RollingCorrelationConfig
- switch req.Source {
- case 3:
- rollingCorrelation = req.RollingCorrelation[0]
- case 4:
- rollingCorrelation = req.RollingCorrelation[1]
- default:
- br.Msg = "错误的来源"
- br.ErrMsg = "错误的来源,source:" + strconv.Itoa(req.Source)
- br.IsSendEmail = false
- return
- }
- // 配置了数据才有返回
- if rollingCorrelation.CalculateValue <= 0 {
- br.Msg = "滚动相关性计算窗口必须大于0"
- br.IsSendEmail = false
- return
- }
- multipleGraphConfigEdbMapping, err := data_manage.GetMultipleGraphConfigEdbMappingByIdAndSource(req.MultipleGraphConfigId, req.Source)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = `保存失败`
- br.ErrMsg = "获取配置与图表的关联关系失败,ERR:" + err.Error()
- return
- }
- err = nil
- var isAdd bool
- var edbInfoId int
- if multipleGraphConfigEdbMapping == nil {
- isAdd = true
- } else {
- edbInfo, err := data_manage.GetEdbInfoById(multipleGraphConfigEdbMapping.EdbInfoId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = `保存失败`
- br.ErrMsg = "获取图表信息失败,ERR:" + err.Error()
- return
- }
- // 说明指标还在,没有被删除
- if edbInfo != nil && !req.IsSaveAs {
- edbInfoId = multipleGraphConfigEdbMapping.EdbInfoId
- req.EdbName = edbInfo.EdbName
- req.ClassifyId = edbInfo.ClassifyId
- req.Frequency = edbInfo.Frequency
- req.Unit = edbInfo.Unit
- }
- }
- // 关联指标
- edbInfoIdArr := []data_manage.EdbInfoFromTag{
- {
- EdbInfoId: edbInfoMappingA.EdbInfoId,
- FromTag: "A",
- MoveValue: 0,
- }, {
- EdbInfoId: edbInfoMappingB.EdbInfoId,
- FromTag: "B",
- MoveValue: 0,
- },
- }
- calculateFormula := request.EdbCalculateFormula{
- BaseCalculateValue: correlationConf.CalculateValue,
- BaseCalculateUnit: correlationConf.CalculateUnit,
- LeadValue: rollingCorrelation.LeadValue,
- LeadUnit: rollingCorrelation.LeadUnit,
- CalculateValue: rollingCorrelation.CalculateValue,
- CalculateUnit: rollingCorrelation.CalculateUnit,
- }
- calculateFormulaByte, err := json.Marshal(calculateFormula)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- var respItem *data.AddPredictEdbDataResponse
- if edbInfoId <= 0 || req.IsSaveAs {
- req2 := &data_manage.EdbInfoCalculateBatchSaveReqByEdbLib{
- AdminId: sysUser.AdminId,
- AdminName: sysUser.RealName,
- EdbName: req.EdbName,
- Frequency: req.Frequency,
- Unit: req.Unit,
- ClassifyId: req.ClassifyId,
- Formula: string(calculateFormulaByte),
- Source: utils.DATA_SOURCE_CALCULATE_CORRELATION,
- EdbInfoIdArr: edbInfoIdArr,
- Calendar: `公历`,
- }
- // 调用指标库去添加
- reqJson, err := json.Marshal(req2)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- respItem, err = data.BatchSaveEdbCalculateData(string(reqJson), this.Lang)
- if err != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,Err:" + err.Error()
- return
- }
- } else {
- req2 := &data_manage.EdbInfoCalculateBatchEditReqByEdbLib{
- EdbInfoId: edbInfoId,
- EdbName: req.EdbName,
- Frequency: req.Frequency,
- Unit: req.Unit,
- ClassifyId: req.ClassifyId,
- Formula: string(calculateFormulaByte),
- Source: utils.DATA_SOURCE_CALCULATE_CORRELATION,
- EdbInfoIdArr: edbInfoIdArr,
- Calendar: `公历`,
- }
- // 调用指标库去更新
- reqJson, err := json.Marshal(req2)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- respItem, err = data.BatchEditEdbCalculateData(string(reqJson), this.Lang)
- if err != nil {
- br.Msg = "编辑失败"
- br.ErrMsg = "编辑失败,Err:" + err.Error()
- return
- }
- }
- if respItem == nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败"
- return
- }
- if respItem.Ret != 200 {
- br.Msg = respItem.Msg
- br.ErrMsg = respItem.ErrMsg
- return
- }
- resp := respItem.Data
- //添加es
- data.AddOrEditEdbInfoToEs(resp.EdbInfoId)
- // 如果不是另存为的话,那么需要建立配置与指标的关系
- if !req.IsSaveAs {
- // 如果指标没有建立关联关系,那么就需要添加关系
- if isAdd {
- multipleGraphConfigEdbMapping = &data_manage.MultipleGraphConfigEdbMapping{
- //Id: 0,
- MultipleGraphConfigId: req.MultipleGraphConfigId,
- EdbInfoId: resp.EdbInfoId,
- Source: req.Source,
- ModifyTime: time.Now(),
- CreateTime: time.Now(),
- }
- err = data_manage.AddMultipleGraphConfigEdbMapping(multipleGraphConfigEdbMapping)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存配置与指标的关联关系失败,ERR:" + err.Error()
- return
- }
- } else if multipleGraphConfigEdbMapping != nil {
- multipleGraphConfigEdbMapping.EdbInfoId = resp.EdbInfoId
- multipleGraphConfigEdbMapping.ModifyTime = time.Now()
- err = multipleGraphConfigEdbMapping.Update([]string{"EdbInfoId", "ModifyTime"})
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存配置与指标的关联关系失败,ERR:" + err.Error()
- return
- }
- }
- }
- //新增操作日志
- //{
- // edbLog := new(data_manage.EdbInfoLog)
- // edbLog.EdbInfoId = resp.EdbInfoId
- // edbLog.SourceName = edbInfo.SourceName
- // edbLog.Source = edbInfo.Source
- // edbLog.EdbCode = edbInfo.EdbCode
- // edbLog.EdbName = req2.EdbName
- // edbLog.ClassifyId = req2.ClassifyId
- // edbLog.SysUserId = sysUser.AdminId
- // edbLog.SysUserRealName = sysUser.RealName
- // edbLog.CreateTime = time.Now()
- // edbLog.Content = string(this.Ctx.Input.RequestBody)
- // edbLog.Status = "多图配置保存指标"
- // edbLog.Method = this.Ctx.Input.URI()
- // go data_manage.AddEdbInfoLog(edbLog)
- //}
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- br.IsAddLog = true
- }
- // GetMultipleGraphConfig
- // @Title 保存配置接口
- // @Description 保存配置接口
- // @Param UniqueCode query int true "图表唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
- // @Success Ret=200 返回图表id
- // @router /multiple_graph/config/detail [get]
- func (this *ChartInfoController) GetMultipleGraphConfig() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- uniqueCode := this.GetString("UniqueCode")
- if uniqueCode == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,uniqueCode is empty"
- return
- }
- chartInfo, err := data_manage.GetChartInfoViewByUniqueCode(uniqueCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- if chartInfo == nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- multipleGraphConfigChartMapping, err := data_manage.GetMultipleGraphConfigChartMappingByChartId(chartInfo.ChartInfoId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取滚动相关性图表的配置信息失败,Err:" + err.Error()
- return
- }
- multipleGraphConfig, err := data_manage.GetMultipleGraphConfigById(multipleGraphConfigChartMapping.MultipleGraphConfigId)
- if err != nil {
- br.Msg = `获取失败`
- br.ErrMsg = `获取配置失败,ERR:` + err.Error()
- return
- }
- // 生成的图表
- multipleGraphConfigChartMappingList := make([]response.MultipleGraphConfigChartMapping, 0)
- {
- chartMappingList, err := data_manage.GetMultipleGraphConfigChartMappingListById(multipleGraphConfigChartMapping.MultipleGraphConfigId)
- if err != nil {
- br.Msg = `获取失败`
- br.ErrMsg = `获取关联图表配置失败,ERR:` + err.Error()
- return
- }
- chartInfoIdList := make([]int, 0)
- chartMappingMap := make(map[int]*data_manage.MultipleGraphConfigChartMapping)
- for _, v := range chartMappingList {
- chartInfoIdList = append(chartInfoIdList, v.ChartInfoId)
- chartMappingMap[v.ChartInfoId] = v
- }
- chartList, err := data_manage.GetChartInfoByIdList(chartInfoIdList)
- if err != nil {
- br.Msg = `获取失败`
- br.ErrMsg = `获取关联图表列表失败,ERR:` + err.Error()
- return
- }
- for _, v := range chartList {
- var mapping response.MultipleGraphConfigChartMapping
- if tmpInfo, ok := chartMappingMap[v.ChartInfoId]; ok {
- mapping.ChartInfoId = tmpInfo.ChartInfoId
- mapping.Source = tmpInfo.Source
- mapping.MultipleLocationSource = tmpInfo.Source
- if v.ChartInfoId == chartInfo.ChartInfoId {
- mapping.CorrelationExtraConfig = chartInfo.ExtraConfig
- mapping.SourcesFrom = chartInfo.SourcesFrom
- }
- multipleGraphConfigChartMappingList = append(multipleGraphConfigChartMappingList, mapping)
- }
- }
- }
- // 生成的指标
- multipleGraphConfigEdbMappingList := make([]response.MultipleGraphConfigEdbMapping, 0)
- {
- edbMappingList, err := data_manage.GetMultipleGraphConfigEdbMappingListById(multipleGraphConfigChartMapping.MultipleGraphConfigId)
- if err != nil {
- br.Msg = `获取失败`
- br.ErrMsg = `获取关联指标配置失败,ERR:` + err.Error()
- return
- }
- edbInfoIdList := make([]int, 0)
- edbMappingMap := make(map[int]*data_manage.MultipleGraphConfigEdbMapping)
- for _, v := range edbMappingList {
- edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
- edbMappingMap[v.EdbInfoId] = v
- }
- edbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
- if err != nil {
- br.Msg = `获取失败`
- br.ErrMsg = `获取关联图表列表失败,ERR:` + err.Error()
- return
- }
- for _, v := range edbList {
- if tmpInfo, ok := edbMappingMap[v.EdbInfoId]; ok {
- multipleGraphConfigEdbMappingList = append(multipleGraphConfigEdbMappingList, response.MultipleGraphConfigEdbMapping{
- EdbInfoId: tmpInfo.EdbInfoId,
- Source: tmpInfo.Source,
- MultipleLocationSource: tmpInfo.Source,
- })
- }
- }
- }
- // 关联指标
- mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList([]int{multipleGraphConfig.EdbInfoIdA, multipleGraphConfig.EdbInfoIdB})
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
- return
- }
- resp := response.MultipleGraphConfigDetailResp{
- EdbInfoList: mappingList,
- MultipleGraphConfig: *multipleGraphConfig,
- ChartMappingList: multipleGraphConfigChartMappingList,
- EdbMappingList: multipleGraphConfigEdbMappingList,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- br.IsAddLog = true
- }
- // func init() {
- // //correlationChart := new(data_manage.ChartInfoCorrelation)
- //
- // condition := ` AND source = 3 `
- // list, err := data_manage.GetChartListByCondition(condition, []interface{}{}, 0, 1000)
- // if err != nil {
- // fmt.Println("err:", err)
- // return
- // }
- // timeNowFormat := time.Now().Format(utils.FormatDate)
- // for _, v := range list {
- // item, tmpErr := data_manage.GetMultipleGraphConfigChartMappingByChartIdAndSource(v.ChartInfoId)
- // if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
- // fmt.Println("tmpErr:", tmpErr)
- // continue
- // }
- // if item == nil {
- // correlationChart := new(data_manage.ChartInfoCorrelation)
- // e := correlationChart.GetItemById(v.ChartInfoId)
- // if e != nil {
- // fmt.Println("获取历史配置失败:", e)
- // continue
- // }
- // day, _ := utils.GetDaysBetween2Date(utils.FormatDate, timeNowFormat, correlationChart.StartDate.Format(utils.FormatDate))
- // req := request.SaveMultipleGraphConfigReq{
- // MultipleGraphConfigId: 0,
- // EdbInfoIdA: correlationChart.EdbInfoIdFirst,
- // EdbInfoIdB: correlationChart.EdbInfoIdSecond,
- // Curve: data_manage.CurveConfig{},
- // Correlation: data_manage.CorrelationConfig{
- // LeadValue: correlationChart.LeadValue,
- // LeadUnit: correlationChart.LeadUnit,
- // CalculateValue: day,
- // CalculateUnit: "天",
- // },
- // RollingCorrelation: []data_manage.RollingCorrelationConfig{
- // {}, {},
- // },
- // }
- // curveStrByte, _ := json.Marshal(req.Curve)
- // correlationStrByte, _ := json.Marshal(req.Correlation)
- // rollingCorrelationStrByte, _ := json.Marshal(req.RollingCorrelation)
- //
- // multipleGraphConfig := &data_manage.MultipleGraphConfig{
- // //MultipleGraphConfigId: 0,
- // EdbInfoIdA: req.EdbInfoIdA,
- // EdbInfoIdB: req.EdbInfoIdB,
- // Curve: string(curveStrByte),
- // Correlation: string(correlationStrByte),
- // RollingCorrelation: string(rollingCorrelationStrByte),
- // SysUserId: v.SysUserId,
- // SysUserRealName: v.SysUserRealName,
- // ModifyTime: v.ModifyTime,
- // CreateTime: v.CreateTime,
- // }
- // err = data_manage.AddMultipleGraphConfig(multipleGraphConfig)
- //
- // if err != nil {
- // fmt.Println(v.ChartInfoId, "创建配置失败:", err)
- // continue
- // }
- //
- // multipleGraphConfigChartMapping := &data_manage.MultipleGraphConfigChartMapping{
- // //Id: 0,
- // MultipleGraphConfigId: multipleGraphConfig.MultipleGraphConfigId,
- // ChartInfoId: v.ChartInfoId,
- // Source: 2,
- // ModifyTime: time.Now(),
- // CreateTime: time.Now(),
- // }
- // err = data_manage.AddMultipleGraphConfigChartMapping(multipleGraphConfigChartMapping)
- // if err != nil {
- // fmt.Println(v.ChartInfoId, "保存配置与图表的关联关系失败:", err)
- // }
- //
- // correlationChart.CalculateUnit = "天"
- // correlationChart.CalculateValue = day
- // err = correlationChart.Update([]string{"CalculateUnit", "CalculateValue"})
- // if err != nil {
- // fmt.Println(v.ChartInfoId, "修复历史数据失败:", err)
- // }
- // }
- // }
- // }
- // 修复相关性图表与滚动相关性图表的强关联关系
- //func init() {
- // condition := ` AND source = ? `
- // pars := []interface{}{utils.CHART_SOURCE_ROLLING_CORRELATION}
- // list, err := data_manage.GetChartListByCondition(condition, pars, 0, 1000)
- // if err != nil {
- // fmt.Println("err:", err)
- // return
- // }
- // for _, chartInfo := range list {
- // multipleGraphConfigChartMapping, e := data_manage.GetMultipleGraphConfigChartMappingByChartId(chartInfo.ChartInfoId)
- // if e != nil {
- // fmt.Println(chartInfo.ChartInfoId, ";获取滚动相关性图表的配置信息失败, Err:"+e.Error())
- // continue
- // }
- // baseChartMultipleGraphConfigChartMapping, e := data_manage.GetMultipleGraphConfigChartMappingByIdAndSource(multipleGraphConfigChartMapping.MultipleGraphConfigId, 2)
- // if e != nil {
- // fmt.Println(chartInfo.ChartInfoId, ";获取相关性图表的配置信息失败, Err:"+e.Error())
- // continue
- // }
- // baseChartCorrelationChart := new(data_manage.ChartInfoCorrelation)
- // if e := baseChartCorrelationChart.GetItemById(baseChartMultipleGraphConfigChartMapping.ChartInfoId); e != nil {
- // fmt.Println(chartInfo.ChartInfoId, ";获取基础相关性图表信息失败, Err:"+e.Error())
- // continue
- // }
- //
- // // 自己的配置
- // selfChartCorrelationChart := new(data_manage.ChartInfoCorrelation)
- // if e := selfChartCorrelationChart.GetItemById(chartInfo.ChartInfoId); e != nil {
- // fmt.Println(chartInfo.ChartInfoId, ";获取自己的相关性图表信息失败, Err:"+e.Error())
- // continue
- // }
- //
- // selfChartCorrelationChart.BaseCalculateUnit = baseChartCorrelationChart.CalculateUnit
- // selfChartCorrelationChart.BaseCalculateValue = baseChartCorrelationChart.CalculateValue
- // err = selfChartCorrelationChart.Update([]string{"BaseCalculateUnit", "BaseCalculateValue"})
- // if err != nil {
- // fmt.Println(chartInfo.ChartInfoId, ";更新相关性图表信息失败, Err:"+err.Error())
- // continue
- // }
- // }
- //
- //}
- // 修复相关性图表与滚动相关性图表的强关联关系
- //func init() {
- // {
- // condition := ` AND source = ? `
- // pars := []interface{}{utils.CHART_SOURCE_ROLLING_CORRELATION}
- // list, err := data_manage.GetChartListByCondition(condition, pars, 0, 1000)
- // if err != nil {
- // fmt.Println("err:", err)
- // return
- // }
- // for _, chartInfo := range list {
- // multipleGraphConfigChartMapping, e := data_manage.GetMultipleGraphConfigChartMappingByChartId(chartInfo.ChartInfoId)
- // if e != nil {
- // fmt.Println(chartInfo.ChartInfoId, ";获取滚动相关性图表的配置信息失败, Err:"+e.Error())
- // continue
- // }
- // multipleGraphConfig, e := data_manage.GetMultipleGraphConfigById(multipleGraphConfigChartMapping.MultipleGraphConfigId)
- // if e != nil {
- // fmt.Println(chartInfo.ChartInfoId, ";获取相关性图表的配置信息失败, Err:"+e.Error())
- // continue
- // }
- // var curveConf data_manage.CurveConfig
- // e = json.Unmarshal([]byte(multipleGraphConfig.Curve), &curveConf)
- // if e != nil {
- // fmt.Println(chartInfo.ChartInfoId, ";格式化曲线图数据失败, Err:"+e.Error())
- // continue
- // }
- //
- // // 自己的配置
- // selfChartCorrelationChart := new(data_manage.ChartInfoCorrelation)
- // if e := selfChartCorrelationChart.GetItemById(chartInfo.ChartInfoId); e != nil {
- // fmt.Println(chartInfo.ChartInfoId, ";获取自己的相关性图表信息失败, Err:"+e.Error())
- // continue
- // }
- //
- // selfChartCorrelationChart.DateType = curveConf.DateType
- //
- // startDate, endDate := utils.GetDateByDateType(curveConf.DateType, curveConf.StartDate, curveConf.EndDate)
- // if startDate != `` {
- // startDateTime, e := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
- // if e != nil {
- // fmt.Println(chartInfo.ChartInfoId, ";开始日期格式化失败,开始日期:", startDate, ", Err:"+e.Error())
- // continue
- // }
- // selfChartCorrelationChart.StartDate = startDateTime
- // }
- // if endDate != `` {
- // endDateTime, e := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
- // if e != nil {
- // fmt.Println(chartInfo.ChartInfoId, ";开始日期格式化失败,开始日期:", startDate, ", Err:"+e.Error())
- // continue
- // }
- // selfChartCorrelationChart.EndDate = endDateTime
- // }
- // err = selfChartCorrelationChart.Update([]string{"DateType", "StartDate", "EndDate"})
- // if err != nil {
- // fmt.Println(chartInfo.ChartInfoId, ";更新相关性图表信息失败, Err:"+err.Error())
- // continue
- // }
- // }
- //
- // fmt.Println("图表更新完成")
- // }
- //
- // {
- // // 更新指标
- // condition := ` AND source = ? `
- // pars := []interface{}{utils.DATA_SOURCE_CALCULATE_CORRELATION}
- // list, err := data_manage.GetEdbInfoListV2ByCondition(condition, pars, 0, 10000)
- // if err != nil {
- // fmt.Println("err:", err)
- // return
- // }
- // for _, edbInfo := range list {
- // multipleGraphConfigEdbMappingInfo, e := data_manage.GetMultipleGraphConfigEdbMappingByEdbInfoId(edbInfo.EdbInfoId)
- // if e != nil {
- // fmt.Println(edbInfo.EdbInfoId, ";获取滚动相关性指标的配置信息失败, Err:"+e.Error())
- // continue
- // }
- // multipleGraphConfig, e := data_manage.GetMultipleGraphConfigById(multipleGraphConfigEdbMappingInfo.MultipleGraphConfigId)
- // if e != nil {
- // fmt.Println(edbInfo.EdbInfoId, ";获取相关性图表的配置信息失败, Err:"+e.Error())
- // continue
- // }
- //
- // // 曲线图配置
- // var curveConf data_manage.CurveConfig
- // e = json.Unmarshal([]byte(multipleGraphConfig.Curve), &curveConf)
- // if e != nil {
- // fmt.Println(edbInfo.EdbInfoId, ";格式化曲线图数据失败, Err:"+e.Error())
- // continue
- // }
- //
- // var formulaConf request.EdbCalculateFormula
- // e = json.Unmarshal([]byte(edbInfo.CalculateFormula), &formulaConf)
- // if e != nil {
- // fmt.Println(edbInfo.EdbInfoId, ";格式化指标计算配置数据失败, Err:"+e.Error())
- // continue
- // }
- // formulaConf.DateType = curveConf.DateType
- // formulaConf.StartDate = curveConf.StartDate
- // formulaConf.EndDate = curveConf.EndDate
- // calculateFormulaByte, err := json.Marshal(formulaConf)
- // edbInfo.CalculateFormula = string(calculateFormulaByte)
- // err = edbInfo.Update([]string{"CalculateFormula"})
- // if err != nil {
- // fmt.Println(edbInfo.EdbInfoId, ";更新指标信息失败, Err:"+err.Error())
- // continue
- // }
- // }
- //
- // fmt.Println("指标更新完成")
- // }
- //}
|