123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044 |
- package controllers
- import (
- "encoding/json"
- "eta/eta_chart_lib/models"
- "eta/eta_chart_lib/models/data_manage"
- cross_varietyReq "eta/eta_chart_lib/models/data_manage/cross_variety/request"
- "eta/eta_chart_lib/models/data_manage/future_good"
- "eta/eta_chart_lib/models/data_manage/future_good/request"
- "eta/eta_chart_lib/models/data_manage/future_good/response"
- line_equationReq "eta/eta_chart_lib/models/data_manage/line_equation/request"
- line_featureReq "eta/eta_chart_lib/models/data_manage/line_feature/request"
- "eta/eta_chart_lib/services/data"
- correlationServ "eta/eta_chart_lib/services/data/correlation"
- "eta/eta_chart_lib/services/data/cross_variety"
- "eta/eta_chart_lib/services/data/excel"
- future_goodServ "eta/eta_chart_lib/services/data/future_good"
- "eta/eta_chart_lib/services/data/line_equation"
- lineFeatureServ "eta/eta_chart_lib/services/data/line_feature"
- "eta/eta_chart_lib/services/data/range_analysis"
- dwmini "eta/eta_chart_lib/services/dw_mini"
- "eta/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 err.Error() == utils.ErrNoRow() {
- 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
- }
- }
- }
- if v.Source == 0 {
- name := strings.Split(v.EdbName, "(")
- if barConfig.FutureGoodEdbName != "" {
- name[0] = barConfig.FutureGoodEdbName
- }
- v.EdbName = name[0]
- if len(name) > 1 {
- v.EdbName = v.EdbName + "(" + name[1]
- }
- //英文
- // 编译正则表达式,匹配一个或多个数字
- if v.EdbNameEn != "" {
- name = strings.Split(v.EdbNameEn, "(")
- if barConfig.FutureGoodEdbNameEn != "" {
- name[0] = barConfig.FutureGoodEdbNameEn
- }
- v.EdbNameEn = name[0]
- if len(name) > 1 {
- v.EdbNameEn = v.EdbNameEn + "(" + name[1]
- }
- }
- }
- }
- 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 err.Error() == utils.ErrNoRow() {
- 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 err.Error() == utils.ErrNoRow() {
- 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
- }
|