12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844 |
- package data_manage
- import (
- "encoding/json"
- "eta_gn/eta_api/models"
- "eta_gn/eta_api/models/data_manage"
- "eta_gn/eta_api/models/data_manage/request"
- "eta_gn/eta_api/models/data_manage/response"
- "eta_gn/eta_api/models/system"
- "eta_gn/eta_api/services/data"
- correlationServ "eta_gn/eta_api/services/data/correlation"
- "eta_gn/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 utils.IsErrNoRow(err) {
- 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 utils.IsErrNoRow(err) {
- 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 && !utils.IsErrNoRow(err) {
- br.Msg = `保存失败`
- br.ErrMsg = "获取配置与图表的关联关系失败,ERR:" + err.Error()
- return
- }
- err = nil
- var isAdd bool
- var chartInfoId int
- if multipleGraphConfigChartMapping == nil || multipleGraphConfigChartMapping.Id <= 0 {
- isAdd = true
- } else {
- chartInfo, err := data_manage.GetChartInfoById(multipleGraphConfigChartMapping.ChartInfoId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = `保存失败`
- br.ErrMsg = "获取图表信息失败,ERR:" + err.Error()
- return
- }
- // 说明图还在,没有被删除
- if chartInfo != nil && chartInfo.ChartInfoId > 0 {
- 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 {
- br.Msg = `保存失败`
- br.ErrMsg = "获取配置与图表的关联关系失败,ERR:" + err.Error()
- return
- }
- // 原图
- oldChartInfo, err := data_manage.GetChartInfoById(multipleGraphConfigChartMapping.ChartInfoId)
- if err != nil {
- if !utils.IsErrNoRow(err) {
- br.Msg = `保存失败`
- br.ErrMsg = "获取图表信息失败,ERR:" + err.Error()
- return
- }
- br.Msg = "原图不存在"
- br.IsSendEmail = false
- return
- }
- // 说明图还在,没有被删除
- if oldChartInfo == nil || oldChartInfo.ChartInfoId <= 0 {
- 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 && !utils.IsErrNoRow(err) {
- br.Msg = `保存失败`
- br.ErrMsg = "获取配置与图表的关联关系失败,ERR:" + err.Error()
- return
- }
- err = nil
- var isAdd bool
- var edbInfoId int
- if multipleGraphConfigEdbMapping == nil || multipleGraphConfigEdbMapping.MultipleGraphConfigId <= 0 {
- isAdd = true
- } else {
- edbInfo, err := data_manage.GetEdbInfoById(multipleGraphConfigEdbMapping.EdbInfoId)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = `保存失败`
- br.ErrMsg = "获取图表信息失败,ERR:" + err.Error()
- return
- }
- // 说明指标还在,没有被删除
- if edbInfo != nil && edbInfo.EdbInfoId > 0 && !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 && !utils.IsErrNoRow(tmpErr) {
- // 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("指标更新完成")
- // }
- //}
|