123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839 |
- 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
- }
- maxYear := 0
- 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)
- maxYear = latestDateT.Year()
- }
- }
- 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, maxYear)
- // 获取图表中的指标数据
- 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, maxYear)
- 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"
- }
- 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("指标更新完成")
- // }
- //}
|