1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021 |
- package controllers
- import (
- "encoding/json"
- "eta_gn/eta_chart_lib/models"
- "eta_gn/eta_chart_lib/models/data_manage"
- cross_varietyReq "eta_gn/eta_chart_lib/models/data_manage/cross_variety/request"
- "eta_gn/eta_chart_lib/models/data_manage/future_good"
- "eta_gn/eta_chart_lib/models/data_manage/future_good/request"
- "eta_gn/eta_chart_lib/models/data_manage/future_good/response"
- line_equationReq "eta_gn/eta_chart_lib/models/data_manage/line_equation/request"
- line_featureReq "eta_gn/eta_chart_lib/models/data_manage/line_feature/request"
- "eta_gn/eta_chart_lib/services/data"
- correlationServ "eta_gn/eta_chart_lib/services/data/correlation"
- "eta_gn/eta_chart_lib/services/data/cross_variety"
- "eta_gn/eta_chart_lib/services/data/excel"
- future_goodServ "eta_gn/eta_chart_lib/services/data/future_good"
- "eta_gn/eta_chart_lib/services/data/line_equation"
- lineFeatureServ "eta_gn/eta_chart_lib/services/data/line_feature"
- "eta_gn/eta_chart_lib/services/data/range_analysis"
- dwmini "eta_gn/eta_chart_lib/services/dw_mini"
- "eta_gn/eta_chart_lib/utils"
- "fmt"
- "strconv"
- "strings"
- "time"
- )
- // CommonChartInfoDetailFromUniqueCode
- // @Title 根据编码获取图表详情
- // @Description 根据编码获取图表详情接口
- // @Param UniqueCode query int true "图表唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
- // @Param IsCache query bool true "是否走缓存,默认false"
- // @Param Token query string true "东吴小程序token"
- // @Param Source query int true "查询来源 1:东吴"
- // @Success 200 {object} data_manage.ChartInfoDetailFromUniqueCodeResp
- // @router /common/detail [get]
- func (this *ChartController) CommonChartInfoDetailFromUniqueCode() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- uniqueCode := this.GetString("UniqueCode")
- token := this.GetString("Token")
- source, _ := this.GetInt("Source")
- if uniqueCode == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,uniqueCode is empty"
- return
- }
- key := utils.HZ_CHART_LIB_DETAIL + uniqueCode
- resp := new(models.ChartInfoDetailResp)
- // 图表水印
- conf, e := models.GetBusinessConf()
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取配置信息失败, Err: " + e.Error()
- return
- }
- var isCollect bool
- if source == utils.CHART_SOURCE_DW && token != "" {
- tmpIsCollect, err := dwmini.GetMyChartIsCollect(token, uniqueCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取收藏状态失败,Err:" + err.Error()
- return
- }
- isCollect = tmpIsCollect
- }
- //判断是否有缓存
- if utils.Re == nil {
- if utils.Re == nil && utils.Rc.IsExist(key) {
- if data, err1 := utils.Rc.RedisBytes(key); err1 == nil {
- err := json.Unmarshal(data, &resp)
- if err == nil && resp != nil {
- if conf[models.BusinessConfWatermarkChart] == "true" && conf[models.BusinessConfCompanyWatermark] != "" {
- resp.WaterMark = conf[models.BusinessConfCompanyWatermark]
- }
- if isCollect {
- resp.IsCollect = isCollect
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- fmt.Println("source redis")
- return
- }
- }
- }
- }
- chartInfo, err := models.GetChartInfoByUniqueCode(uniqueCode)
- if err != nil {
- if utils.IsErrNoRow(err) {
- br.Msg = "该图已被删除,请刷新页面"
- br.ErrMsg = "该图已被删除,请刷新页面,Err:" + err.Error()
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- //var resp interface{}
- var isOk bool
- var msg, errMsg string
- switch chartInfo.Source {
- case utils.CHART_SOURCE_DEFAULT:
- resp, isOk, msg, errMsg = GetChartInfoDetailFromUniqueCode(chartInfo, key)
- case utils.CHART_SOURCE_FUTURE_GOOD:
- resp, isOk, msg, errMsg = GetFutureGoodChartInfoDetailFromUniqueCode(chartInfo, key)
- case utils.CHART_SOURCE_FUTURE_GOOD_PROFIT:
- resp, isOk, msg, errMsg = GetFutureGoodProfitChartInfoDetailFromUniqueCode(chartInfo, key)
- case utils.CHART_SOURCE_CORRELATION, utils.CHART_SOURCE_ROLLING_CORRELATION:
- resp, isOk, msg, errMsg = GetCorrelationChartInfoDetailFromUniqueCode(chartInfo, key)
- case utils.CHART_SOURCE_LINE_EQUATION:
- resp, isOk, msg, errMsg = GetLineEquationChartInfoDetailFromUniqueCode(chartInfo, key)
- case utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY:
- resp, isOk, msg, errMsg = GetLineFeatureChartInfoDetailFromUniqueCode(chartInfo, key)
- case utils.CHART_SOURCE_CROSS_HEDGING:
- resp, isOk, msg, errMsg = GetCrossVarietyChartInfoDetailFromUniqueCode(chartInfo, key)
- case utils.CHART_SOURCE_BALANCE_EXCEL:
- resp, isOk, msg, errMsg = GetBalanceChartInfoDetailFromUniqueCode(chartInfo, key, this.Lang)
- if !isOk {
- br.Msg = msg
- br.ErrMsg = errMsg
- return
- }
- case utils.CHART_SOURCE_RANGE_ANALYSIS:
- resp, isOk, msg, errMsg = GetRangeAnalysisChartInfoDetailFromUniqueCode(chartInfo, key, this.Lang)
- if !isOk {
- br.Msg = msg
- br.ErrMsg = errMsg
- return
- }
- default:
- br.Msg = "错误的图表"
- br.ErrMsg = "错误的图表"
- return
- }
- if !isOk {
- br.Msg = msg
- br.ErrMsg = errMsg
- return
- }
- if isCollect {
- resp.IsCollect = isCollect
- }
- if conf[models.BusinessConfWatermarkChart] == "true" && conf[models.BusinessConfCompanyWatermark] != "" {
- resp.WaterMark = conf[models.BusinessConfCompanyWatermark]
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // GetFutureGoodChartInfoDetailFromUniqueCode 根据编码获取图表详情
- func GetFutureGoodChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfo, key string) (resp *models.ChartInfoDetailResp, isOk bool, msg, errMsg string) {
- resp = new(models.ChartInfoDetailResp)
- // 获取主题样式
- chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, utils.CHART_SOURCE_DEFAULT, 1)
- if err != nil {
- msg = "获取失败"
- errMsg = "获取主题信息失败,Err:" + err.Error()
- return
- }
- chartInfo.ChartThemeStyle = chartTheme.Config
- chartInfo.ChartThemeId = chartTheme.ChartThemeId
- chartInfoId := chartInfo.ChartInfoId
- startDate := chartInfo.StartDate
- endDate := chartInfo.EndDate
- // 兼容日期错误
- {
- if strings.Count(startDate, "-") == 1 {
- startDate = startDate + "-01"
- }
- if strings.Count(endDate, "-") == 1 {
- endDate = endDate + "-01"
- }
- }
- edbInfoMappingList, err := models.GetEtaEdbChartEdbMappingList(chartInfoId)
- if err != nil {
- msg = "获取失败"
- errMsg = "获取图表,现货指标信息失败,Err:" + err.Error()
- return
- }
- futureGoodEdbInfoMapping, err := models.GetFutureGoodEdbChartEdbMapping(chartInfoId)
- if err != nil {
- msg = "获取失败"
- errMsg = "获取图表的期货商品指标信息失败,Err:" + err.Error()
- return
- }
- // 商品价格曲线图的一些配置
- var barConfig data_manage.FutureGoodBarChartInfoReq
- //barChartInfoSort := data_manage.BarChartInfoSortReq{}
- if chartInfo.BarConfig == `` {
- msg = "商品价格曲线图未配置"
- errMsg = "商品价格曲线图未配置"
- return
- }
- err = json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
- if err != nil {
- msg = "商品价格曲线图配置异常"
- errMsg = "商品价格曲线图配置异常"
- return
- }
- baseEdbInfoId := barConfig.BaseEdbInfoId
- var baseEdbInfoMapping *models.ChartEdbInfoMapping
- // todo 兼容历史数据,
- if baseEdbInfoId == 0 {
- // 默认取第一个现货指标
- baseEdbInfoId = edbInfoMappingList[0].EdbInfoId
- baseEdbInfoMapping = edbInfoMappingList[0]
- barConfig.BaseEdbInfoId = baseEdbInfoId
- } else {
- baseEdbInfoMapping, err = models.GetChartEdbMappingByEdbInfoId(baseEdbInfoId)
- if err != nil {
- msg = "获取失败"
- errMsg = "获取图表,指标信息失败,Err:" + err.Error()
- return
- }
- }
- // 获取图表中的指标数据
- barConfigEdbInfoIdList, edbList, xEdbIdValue, xDataList, yDataList, err := future_goodServ.GetChartEdbData(chartInfoId, startDate, endDate, baseEdbInfoMapping, edbInfoMappingList, futureGoodEdbInfoMapping, barConfig, true)
- if err != nil {
- msg = "获取失败"
- errMsg = "获取图表,指标信息失败,Err:" + err.Error()
- return
- }
- warnEdbList := make([]string, 0)
- if len(edbList) <= 0 {
- msg = "商品价格曲线图表指标异常"
- errMsg = "商品价格曲线图表异常"
- return
- }
- baseEdbInfo := edbList[0] //现货指标
- for _, v := range edbList {
- if v.IsNullData {
- warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
- }
- // 指标别名
- if barConfigEdbInfoIdList != nil && len(barConfigEdbInfoIdList) > 0 {
- for _, reqEdb := range barConfigEdbInfoIdList {
- if v.EdbInfoId == reqEdb.EdbInfoId {
- v.EdbAliasName = reqEdb.Name
- v.EdbAliasNameEn = reqEdb.NameEn
- }
- }
- }
- }
- chartInfo.UnitEn = baseEdbInfo.UnitEn
- // 图表的指标来源
- sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
- chartInfo.ChartSource = strings.Join(sourceNameList, ",")
- chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
- xDataListFinal := make([]models.XData, 0)
- for _, v := range xDataList {
- tmp := models.XData{
- Name: v.Name,
- NameEn: v.NameEn,
- IsHide: v.IsHide,
- }
- xDataListFinal = append(xDataListFinal, tmp)
- }
- resp.ChartInfo = chartInfo
- resp.EdbInfoList = edbList
- resp.XEdbIdValue = xEdbIdValue
- resp.YDataList = yDataList
- resp.XDataList = xDataListFinal
- //resp.BarChartInfo = barConfig
- //resp.Status = true
- // 将数据加入缓存
- if utils.Re == nil {
- data, _ := json.Marshal(resp)
- utils.Rc.Put(key, data, 2*time.Hour)
- }
- isOk = true
- return
- }
- // GetFutureGoodProfitChartInfoDetailFromUniqueCode 根据编码获取商品利润图表详情
- func GetFutureGoodProfitChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfo, key string) (resp *models.ChartInfoDetailResp, isOk bool, msg, errMsg string) {
- resp = new(models.ChartInfoDetailResp)
- chartInfoId := chartInfo.ChartInfoId
- // 获取主题样式
- chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, utils.CHART_SOURCE_DEFAULT, 1)
- if err != nil {
- msg = "获取失败"
- errMsg = "获取主题信息失败,Err:" + err.Error()
- return
- }
- chartInfo.ChartThemeStyle = chartTheme.Config
- chartInfo.ChartThemeId = chartTheme.ChartThemeId
- // 商品利润曲线图的一些配置
- var extraConf request.ChartInfoReq
- err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &extraConf)
- if err != nil {
- msg = "商品利润曲线图配置异常"
- errMsg = "商品利润曲线图配置异常,Err:" + err.Error()
- return
- }
- if len(extraConf.EdbInfoIdList) == 0 {
- extraConf.EdbInfoIdList = append(extraConf.EdbInfoIdList, extraConf.BaseEdbInfoId)
- }
- edbList := make([]*models.ChartEdbInfoMapping, 0)
- edbInfoMappingList, err := models.GetEtaEdbChartEdbMappingList(chartInfoId)
- if err != nil {
- msg = "获取失败"
- errMsg = "获取商品利润图表,基础指标信息失败,Err:" + err.Error()
- return
- }
- baseEdbInfo := new(models.ChartEdbInfoMapping)
- for _, v := range edbInfoMappingList {
- if v.EdbInfoId == extraConf.BaseEdbInfoId {
- baseEdbInfo = v
- }
- }
- edbList = edbInfoMappingList
- futureGoodEdbInfoMappingList, err := models.GetFutureGoodEdbChartEdbMappingList(chartInfoId)
- if err != nil {
- msg = "获取失败"
- errMsg = "获取商品利润图表,商品指标信息失败,Err:" + err.Error()
- return
- }
- edbList = append(edbList, futureGoodEdbInfoMappingList...)
- if len(edbList) <= 0 {
- msg = "商品利润曲线图表指标异常"
- errMsg = "商品利润曲线图表指标异常"
- return
- }
- xDataList := make([]models.XData, 0)
- yDataList := make([]models.YData, 0)
- // 查找商品利润图表的扩展信息
- chartInfoFutureGoodProfit := new(future_good.ChartInfoFutureGoodProfit)
- if err = chartInfoFutureGoodProfit.GetItemById(chartInfo.ChartInfoId); err != nil {
- msg = "获取失败"
- errMsg = "获取基础相关性图表信息失败, Err: " + err.Error()
- return
- }
- err = json.Unmarshal([]byte(chartInfoFutureGoodProfit.XValue), &xDataList)
- if err != nil {
- msg = "获取失败"
- errMsg = "转换X轴数据失败, Err: " + err.Error()
- return
- }
- err = json.Unmarshal([]byte(chartInfoFutureGoodProfit.YValue), &yDataList)
- if err != nil {
- msg = "获取失败"
- errMsg = "转换Y轴数据失败, Err: " + err.Error()
- return
- }
- warnEdbList := make([]string, 0)
- for _, v := range edbList {
- if v.IsNullData {
- warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
- }
- }
- chartInfo.UnitEn = baseEdbInfo.UnitEn
- resp.ChartInfo = chartInfo
- resp.EdbInfoList = edbList
- resp.DataResp = response.ProfitFutureGoodChartResp{
- YDataList: yDataList,
- XDataList: xDataList,
- ProfitName: chartInfoFutureGoodProfit.ProfitName,
- ProfitNameEn: chartInfoFutureGoodProfit.ProfitNameEn,
- Extra: extraConf,
- }
- // 将数据加入缓存
- if utils.Re == nil {
- data, _ := json.Marshal(resp)
- utils.Rc.Put(key, data, 2*time.Hour)
- }
- isOk = true
- return
- }
- // GetLineEquationChartInfoDetailFromUniqueCode 根据编码获取拟合方程图表详情
- func GetLineEquationChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfo, key string) (resp *models.ChartInfoDetailResp, isOk bool, msg, errMsg string) {
- resp = new(models.ChartInfoDetailResp)
- // 获取主题样式
- chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, utils.CHART_SOURCE_DEFAULT, 1)
- if err != nil {
- msg = "获取失败"
- errMsg = "获取主题信息失败,Err:" + err.Error()
- return
- }
- chartInfo.ChartThemeStyle = chartTheme.Config
- chartInfo.ChartThemeId = chartTheme.ChartThemeId
- //chartInfoId := chartInfo.ChartInfoId
- if chartInfo.ExtraConfig == `` {
- msg = "获取失败"
- errMsg = "获取配置信息失败"
- return
- }
- var lineChartInfoConfig line_equationReq.LineChartInfoReq
- err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &lineChartInfoConfig)
- if err != nil {
- msg = "获取失败"
- errMsg = "获取图表配置信息失败, Err:" + err.Error()
- return
- }
- var getAData, getBData, getR2Data bool
- switch lineChartInfoConfig.Source {
- case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_ONE:
- getAData = true
- case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_TWO:
- getBData = true
- case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_THREE:
- getR2Data = true
- }
- edbList, dataResp, err, errMsg := line_equation.GetChartEdbData(chartInfo.ChartInfoId, lineChartInfoConfig, getAData, getBData, getR2Data)
- if err != nil {
- if errMsg == `` {
- errMsg = "获取失败"
- }
- return
- }
- var resultResp interface{}
- switch lineChartInfoConfig.Source {
- case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_ONE:
- resultResp = dataResp.AData
- case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_TWO:
- resultResp = dataResp.BData
- case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_THREE:
- resultResp = dataResp.R2Data
- }
- //chartInfo.UnitEn = baseEdbInfo.UnitEn
- // 图表的指标来源
- sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
- chartInfo.ChartSource = strings.Join(sourceNameList, ",")
- chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
- resp.ChartInfo = chartInfo
- resp.DataResp = resultResp
- resp.EdbInfoList = edbList
- // 将数据加入缓存
- if utils.Re == nil {
- data, _ := json.Marshal(resp)
- utils.Rc.Put(key, data, 2*time.Hour)
- }
- isOk = true
- return
- }
- // GetLineFeatureChartInfoDetailFromUniqueCode 根据编码获取统计特征图表详情
- func GetLineFeatureChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfo, key string) (resp *models.ChartInfoDetailResp, isOk bool, msg, errMsg string) {
- resp = new(models.ChartInfoDetailResp)
- // 获取主题样式
- chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, utils.CHART_SOURCE_DEFAULT, 1)
- if err != nil {
- msg = "获取失败"
- errMsg = "获取主题信息失败,Err:" + err.Error()
- return
- }
- chartInfo.ChartThemeStyle = chartTheme.Config
- chartInfo.ChartThemeId = chartTheme.ChartThemeId
- // 获取图表关联指标
- edbMappingList, err := models.GetChartEdbMappingList(chartInfo.ChartInfoId)
- if err != nil {
- msg = "获取失败"
- errMsg = "获取图表关联指标信息失败,Err:" + err.Error()
- return
- }
- if len(edbMappingList) != 1 {
- msg = "获取失败"
- errMsg = fmt.Sprint("获取图表关联指标信息异常,数量:", len(edbMappingList))
- return
- }
- edbMapping := edbMappingList[0]
- var edbList []*models.ChartEdbInfoMapping
- var resultResp interface{}
- switch chartInfo.Source {
- case utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION:
- calculateValue, tmpErr := strconv.Atoi(chartInfo.ExtraConfig)
- if tmpErr != nil {
- msg = "获取失败"
- errMsg = "格式化配置项失败,Err:" + tmpErr.Error()
- return
- }
- startDate, endDate := utils.GetDateByDateType(chartInfo.DateType, chartInfo.StartDate, chartInfo.EndDate)
- edbList, resultResp, err, msg = lineFeatureServ.GetStandardDeviationData(chartInfo.ChartInfoId, startDate, endDate, edbMapping, calculateValue)
- case utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE:
- var percentileConfig line_featureReq.Percentile
- err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &percentileConfig)
- if err != nil {
- msg = "获取失败"
- errMsg = "格式化配置项失败,Err:" + err.Error()
- return
- }
- startDate, endDate := utils.GetDateByDateType(chartInfo.DateType, chartInfo.StartDate, chartInfo.EndDate)
- edbList, resultResp, err, msg = lineFeatureServ.GetPercentileData(chartInfo.ChartInfoId, startDate, endDate, edbMapping, percentileConfig.CalculateValue, percentileConfig.CalculateUnit, percentileConfig.PercentType)
- case utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY:
- var frequencyDistributionConfig line_featureReq.FrequencyDistribution
- err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &frequencyDistributionConfig)
- if err != nil {
- msg = "获取失败"
- errMsg = "格式化配置项失败,Err:" + err.Error()
- return
- }
- // 获取图表中的指标数据
- edbList, resultResp, err, errMsg = lineFeatureServ.GetFrequencyDistributionData(0, edbMapping, frequencyDistributionConfig.DateType, frequencyDistributionConfig.FrequencyValue, frequencyDistributionConfig.StartDate, frequencyDistributionConfig.EndDate)
- default:
- msg = `错误的图表`
- errMsg = fmt.Sprint("错误的图表来源,source", chartInfo.Source)
- return
- }
- if err != nil {
- if msg == `` {
- msg = "获取失败"
- }
- errMsg = "获取图表,指标信息失败,Err:" + err.Error()
- return
- }
- //chartInfo.UnitEn = baseEdbInfo.UnitEn
- // 图表的指标来源
- sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
- chartInfo.ChartSource = strings.Join(sourceNameList, ",")
- chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
- resp.ChartInfo = chartInfo
- resp.DataResp = resultResp
- resp.EdbInfoList = edbList
- // 将数据加入缓存
- if utils.Re == nil {
- data, _ := json.Marshal(resp)
- utils.Rc.Put(key, data, 2*time.Hour)
- }
- isOk = true
- return
- }
- // GetCrossVarietyChartInfoDetailFromUniqueCode 根据编码获取图表详情
- func GetCrossVarietyChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfo, key string) (resp *models.ChartInfoDetailResp, isOk bool, msg, errMsg string) {
- resp = new(models.ChartInfoDetailResp)
- // 获取主题样式
- chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, utils.CHART_SOURCE_DEFAULT, 5)
- if err != nil {
- msg = "获取失败"
- errMsg = "获取主题信息失败,Err:" + err.Error()
- return
- }
- chartInfo.ChartThemeStyle = chartTheme.Config
- chartInfo.ChartThemeId = chartTheme.ChartThemeId
- if chartInfo.ExtraConfig == `` {
- msg = "图表配置信息异常"
- errMsg = "图表配置信息异常"
- return
- }
- var config cross_varietyReq.ChartConfigReq
- err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &config)
- if err != nil {
- msg = "解析跨品种分析配置失败"
- errMsg = "解析跨品种分析配置失败,Err:" + err.Error()
- return
- }
- // 获取图表x轴y轴
- edbList, dataResp, err, msg, _ := cross_variety.GetChartData(0, config)
- if err != nil {
- errMsg = "获取图表,指标信息失败,Err:" + err.Error()
- return
- }
- //判断是否需要展示英文标识
- //chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList[0:1], chartInfo.Source, chartInfo.ChartType)
- //chartInfo.UnitEn = edbInfoMappingA.UnitEn
- // 另存为
- resp.ChartInfo = chartInfo
- resp.DataResp = dataResp
- resp.EdbInfoList = edbList
- // 图表的指标来源
- sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
- chartInfo.ChartSource = strings.Join(sourceNameList, ",")
- chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
- // 将数据加入缓存
- if utils.Re == nil {
- d, _ := json.Marshal(resp)
- _ = utils.Rc.Put(key, d, 2*time.Hour)
- }
- isOk = true
- return
- }
- func GetBalanceChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfo, key, lang string) (resp *models.ChartInfoDetailResp, isOk bool, msg, errMsg string) {
- resp = new(models.ChartInfoDetailResp)
- msg = `获取失败`
- var err error
- defer func() {
- if err != nil {
- if errMsg != "" {
- msg = errMsg
- }
- errMsg = err.Error()
- }
- }()
- // 相关联指标
- mappingListTmp, dataListMap, err, errMsg := excel.GetBalanceExcelChartSingle(chartInfo.ChartInfoId, 0, lang)
- if err != nil {
- errMsg = "获取失败"
- err = fmt.Errorf(" 获取图表,指标信息失败 Err:%s", err.Error())
- return
- }
- var chartInfoResp *models.ChartInfoDetailResp
- chartInfoResp, err, errMsg = data.GetBalanceExcelChartDetail(chartInfo, mappingListTmp, dataListMap)
- if err != nil {
- msg = "查询图表详情失败"
- errMsg = "查询图表详情失败,Err:" + err.Error()
- return
- }
- resp = &models.ChartInfoDetailResp{
- ChartInfo: chartInfoResp.ChartInfo,
- EdbInfoList: chartInfoResp.EdbInfoList,
- XEdbIdValue: chartInfoResp.XEdbIdValue,
- YDataList: chartInfoResp.YDataList,
- XDataList: chartInfoResp.XDataList,
- CorrelationChartInfo: chartInfoResp.CorrelationChartInfo,
- DataResp: chartInfoResp.DataResp,
- }
- if utils.Re == nil {
- jsonData, _ := json.Marshal(resp)
- utils.Rc.Put(key, jsonData, 10*time.Minute)
- }
- isOk = true
- return
- }
- // FutureGoodChartInfoRefresh
- // @Title 商品价格图表刷新接口
- // @Description 商品价格图表刷新接口
- // @Param UniqueCode query string true "图表唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
- // @Success Ret=200 刷新成功
- // @router /future_good/refresh [get]
- func (this *ChartController) FutureGoodChartInfoRefresh() {
- br := new(models.BaseResponse).Init()
- chartId := 0
- defer func() {
- // 添加日志
- if chartId > 0 {
- shareChartRefreshLogInfo := &models.ShareChartRefreshLog{
- Ip: this.Ctx.Input.IP(),
- ChartId: chartId,
- CreateTime: time.Now(),
- }
- models.AddShareChartRefreshLog(shareChartRefreshLogInfo)
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- uniqueCode := this.GetString("UniqueCode")
- if uniqueCode == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,uniqueCode is empty"
- return
- }
- chartInfo, err := models.GetChartInfoByUniqueCode(uniqueCode)
- if err != nil {
- if utils.IsErrNoRow(err) {
- br.Msg = "该图已被删除,请刷新页面"
- br.ErrMsg = "该图已被删除,请刷新页面,Err:" + err.Error()
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- chartId = chartInfo.ChartInfoId
- err = future_goodServ.FutureGoodChartInfoRefresh(chartInfo.ChartInfoId)
- if err != nil {
- br.Msg = "刷新失败"
- br.ErrMsg = "刷新图表关联指标信息失败,Err:" + err.Error()
- return
- }
- //err = data.ChartInfoRefresh(chartInfo.ChartInfoId)
- //if err != nil {
- // br.Msg = "刷新失败"
- // br.ErrMsg = "刷新图表关联指标信息失败,Err:" + err.Error()
- // return
- //}
- //err = data.ChartInfoRefreshV2(chartInfo.ChartInfoId)
- //if err != nil {
- // br.Msg = "刷新失败"
- // br.ErrMsg = "刷新图表关联指标信息失败,Err:" + err.Error()
- // return
- //}
- //清除数据缓存
- key := utils.HZ_CHART_LIB_DETAIL + uniqueCode
- if utils.Re == nil {
- utils.Rc.Delete(key)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "刷新成功"
- }
- // GetCorrelationChartInfoDetailFromUniqueCode 根据编码获取相关性图表详情
- func GetCorrelationChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfo, key string) (resp *models.ChartInfoDetailResp, isOk bool, msg, errMsg string) {
- resp = new(models.ChartInfoDetailResp)
- // 获取主题样式
- chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, utils.CHART_SOURCE_DEFAULT, 1)
- if err != nil {
- msg = "获取失败"
- errMsg = "获取主题信息失败,Err:" + err.Error()
- return
- }
- chartInfo.ChartThemeStyle = chartTheme.Config
- chartInfo.ChartThemeId = chartTheme.ChartThemeId
- chartInfoId := chartInfo.ChartInfoId
- startDate := chartInfo.StartDate
- endDate := chartInfo.EndDate
- // 兼容日期错误
- {
- if strings.Count(startDate, "-") == 1 {
- startDate = startDate + "-01"
- }
- if strings.Count(endDate, "-") == 1 {
- endDate = endDate + "-01"
- }
- }
- // 相关性图表信息
- correlationChart := new(data_manage.ChartInfoCorrelation)
- if e := correlationChart.GetItemById(chartInfoId); e != nil {
- msg = "获取失败"
- errMsg = "获取图表相关性信息失败, Err:" + e.Error()
- return
- }
- // 获取指标信息
- edbInfoMappingA, e := models.GetChartEdbMappingByEdbInfoId(correlationChart.EdbInfoIdFirst)
- if e != nil {
- msg = "获取失败"
- errMsg = "获取相关性图表, A指标mapping信息失败, Err:" + e.Error()
- return
- }
- edbInfoMappingB := new(models.ChartEdbInfoMapping)
- if correlationChart.AnalysisMode != 1 {
- edbInfoMappingB, e = models.GetChartEdbMappingByEdbInfoId(correlationChart.EdbInfoIdSecond)
- if e != nil {
- msg = "获取失败"
- errMsg = "获取相关性图表, B指标mapping信息失败, Err:" + e.Error()
- return
- }
- }
- var dataResp interface{} // 绘图数据返回(目前是滚动相关性的图)
- var xEdbIdValue []int
- var yDataList []models.YData
- if correlationChart.AnalysisMode != 1 {
- switch chartInfo.Source {
- case utils.CHART_SOURCE_CORRELATION: // 相关性图
- moveUnitDays, ok := utils.FrequencyDaysMap[correlationChart.CalculateUnit]
- if !ok {
- msg = "错误的分析周期"
- errMsg = "相关性图表数据有误"
- return
- }
- st := time.Now().AddDate(0, 0, -correlationChart.CalculateValue*moveUnitDays).Format(utils.FormatDate)
- ed := time.Now().Format(utils.FormatDate)
- xEdbIdValue, yDataList, e = correlationServ.GetChartDataByEdbInfo(edbInfoMappingA, edbInfoMappingB, correlationChart.LeadValue, correlationChart.LeadUnit, st, ed, chartInfo.ExtraConfig)
- if e != nil {
- msg = "获取失败"
- errMsg = "获取相关性图表, 图表计算值失败, Err:" + e.Error()
- return
- }
- case utils.CHART_SOURCE_ROLLING_CORRELATION: // 滚动相关性图
- st, ed := utils.GetDateByDateType(correlationChart.DateType, correlationChart.StartDate.Format(utils.FormatDate), correlationChart.EndDate.Format(utils.FormatDate))
- dataResp, e = correlationServ.GetRollingCorrelationChartDataByEdbInfo(edbInfoMappingA, edbInfoMappingB, correlationChart.LeadValue, correlationChart.LeadUnit, correlationChart.CalculateValue, correlationChart.CalculateUnit, st, ed, chartInfo.ChartName, chartInfo.ChartNameEn)
- }
- } else {
- xEdbIdValue, yDataList, e = correlationServ.GetFactorChartDataByChartId(chartInfoId, chartInfo.ExtraConfig)
- if e != nil {
- msg = "获取失败"
- errMsg = "获取相关性图表, 图表计算值失败, Err:" + e.Error()
- return
- }
- }
- // 完善指标信息
- edbList, e := correlationServ.GetChartEdbInfoFormat(chartInfo.ChartInfoId, edbInfoMappingA, edbInfoMappingB)
- if e != nil {
- msg = "获取失败"
- errMsg = "获取相关性图表, 完善指标信息失败, Err:" + e.Error()
- return
- }
- // 图表的指标来源
- sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
- chartInfo.ChartSource = strings.Join(sourceNameList, ",")
- chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
- correlationInfo := new(models.CorrelationInfo)
- correlationInfo.LeadValue = correlationChart.LeadValue
- correlationInfo.LeadUnit = correlationChart.LeadUnit
- correlationInfo.StartDate = correlationChart.StartDate.Format(utils.FormatDate)
- correlationInfo.EndDate = correlationChart.EndDate.Format(utils.FormatDate)
- correlationInfo.LeadValue = correlationChart.LeadValue
- correlationInfo.EdbInfoIdFirst = correlationChart.EdbInfoIdFirst
- correlationInfo.EdbInfoIdSecond = correlationChart.EdbInfoIdSecond
- correlationInfo.AnalysisMode = correlationChart.AnalysisMode
- resp.ChartInfo = chartInfo
- resp.EdbInfoList = edbList
- resp.XEdbIdValue = xEdbIdValue
- resp.YDataList = yDataList
- resp.CorrelationChartInfo = correlationInfo
- resp.DataResp = dataResp
- // 将数据加入缓存
- if utils.Re == nil {
- d, _ := json.Marshal(resp)
- _ = utils.Rc.Put(key, d, 2*time.Hour)
- }
- isOk = true
- return
- }
- // CorrelationChartInfoRefresh
- // @Title 商品价格图表刷新接口
- // @Description 商品价格图表刷新接口
- // @Param UniqueCode query string true "图表唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
- // @Success Ret=200 刷新成功
- // @router /correlation/refresh [get]
- func (this *ChartController) CorrelationChartInfoRefresh() {
- br := new(models.BaseResponse).Init()
- chartId := 0
- defer func() {
- // 添加日志
- if chartId > 0 {
- shareChartRefreshLogInfo := &models.ShareChartRefreshLog{
- Ip: this.Ctx.Input.IP(),
- ChartId: chartId,
- CreateTime: time.Now(),
- }
- models.AddShareChartRefreshLog(shareChartRefreshLogInfo)
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- uniqueCode := this.GetString("UniqueCode")
- if uniqueCode == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,uniqueCode is empty"
- return
- }
- chartInfo, err := models.GetChartInfoByUniqueCode(uniqueCode)
- if err != nil {
- if utils.IsErrNoRow(err) {
- br.Msg = "该图已被删除,请刷新页面"
- br.ErrMsg = "该图已被删除,请刷新页面,Err:" + err.Error()
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- chartId = chartInfo.ChartInfoId
- err = data.ChartInfoRefreshV2(chartInfo.ChartInfoId)
- if err != nil {
- br.Msg = "刷新失败"
- br.ErrMsg = "刷新图表关联指标信息失败,Err:" + err.Error()
- return
- }
- //// 刷新相关性图表
- //if e := correlationServ.ChartInfoRefresh(chartInfo.ChartInfoId); e != nil {
- // br.Msg = "刷新失败"
- // br.ErrMsg = "刷新相关性图表失败, Err:" + e.Error()
- // return
- //}
- //清除数据缓存
- key := utils.HZ_CHART_LIB_DETAIL + uniqueCode
- if utils.Re == nil {
- _ = utils.Rc.Delete(key)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "刷新成功"
- }
- // GetRangeAnalysisChartInfoDetailFromUniqueCode 根据编码获取区间计算图表详情
- func GetRangeAnalysisChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfo, key, lang string) (resp *models.ChartInfoDetailResp, isOk bool, msg, errMsg string) {
- resp = new(models.ChartInfoDetailResp)
- // 获取主题样式
- chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, utils.CHART_SOURCE_DEFAULT, 1)
- if err != nil {
- msg = "获取失败"
- errMsg = "获取主题信息失败,Err:" + err.Error()
- return
- }
- chartInfo.ChartThemeStyle = chartTheme.Config
- chartInfo.ChartThemeId = chartTheme.ChartThemeId
- chartInfoId := chartInfo.ChartInfoId
- // 获取指标信息
- //chartInfo.CorrelationLeadUnit = req.LeadUnit
- edbInfoMappingList, err := models.GetChartEdbMappingList(chartInfoId)
- if err != nil {
- msg = "获取失败"
- errMsg = "获取图表,指标信息失败,Err:" + err.Error()
- return
- }
- dateType := chartInfo.DateType
- // 开始/结束日期
- startYear := chartInfo.StartYear
- startDate := chartInfo.StartDate
- endDate := chartInfo.EndDate
- // 区间计算图表配置校验
- var extraConfig models.ChartRangeAnalysisExtraConf
- if chartInfo.ExtraConfig == `` {
- msg = "配置信息错误"
- return
- }
- err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &extraConfig)
- if err != nil {
- msg = "配置信息错误"
- errMsg = "图表配置信息错误,Err:" + err.Error()
- return
- }
- // 获取图表数据
- if len(edbInfoMappingList) == 0 {
- msg = "获取失败"
- errMsg = "图表没有指标,无法计算"
- return
- }
- // 获取图表x轴y轴
- edbList, xEdbIdValue, dataResp, e := range_analysis.GetChartDataByEdbInfoList(chartInfoId, dateType, startYear, startDate, endDate, edbInfoMappingList, &extraConfig)
- if e != nil {
- msg = "获取失败"
- errMsg = "获取区间计算图表, 图表计算值失败, Err:" + e.Error()
- return
- }
- // 图表的指标来源
- sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
- chartInfo.ChartSource = strings.Join(sourceNameList, ",")
- chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
- resp.ChartInfo = chartInfo
- resp.EdbInfoList = edbList
- resp.XEdbIdValue = xEdbIdValue
- resp.DataResp = dataResp
- if utils.Re == nil {
- jsonData, _ := json.Marshal(resp)
- utils.Rc.Put(key, jsonData, 10*time.Minute)
- }
- isOk = true
- return
- }
|