chart_common.go 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_chart_lib/models"
  5. "eta_gn/eta_chart_lib/models/data_manage"
  6. cross_varietyReq "eta_gn/eta_chart_lib/models/data_manage/cross_variety/request"
  7. "eta_gn/eta_chart_lib/models/data_manage/future_good"
  8. "eta_gn/eta_chart_lib/models/data_manage/future_good/request"
  9. "eta_gn/eta_chart_lib/models/data_manage/future_good/response"
  10. line_equationReq "eta_gn/eta_chart_lib/models/data_manage/line_equation/request"
  11. line_featureReq "eta_gn/eta_chart_lib/models/data_manage/line_feature/request"
  12. "eta_gn/eta_chart_lib/services/data"
  13. correlationServ "eta_gn/eta_chart_lib/services/data/correlation"
  14. "eta_gn/eta_chart_lib/services/data/cross_variety"
  15. "eta_gn/eta_chart_lib/services/data/excel"
  16. future_goodServ "eta_gn/eta_chart_lib/services/data/future_good"
  17. "eta_gn/eta_chart_lib/services/data/line_equation"
  18. lineFeatureServ "eta_gn/eta_chart_lib/services/data/line_feature"
  19. "eta_gn/eta_chart_lib/services/data/range_analysis"
  20. dwmini "eta_gn/eta_chart_lib/services/dw_mini"
  21. "eta_gn/eta_chart_lib/utils"
  22. "fmt"
  23. "strconv"
  24. "strings"
  25. "time"
  26. )
  27. // @router /common/detail [get]
  28. func (this *ChartController) CommonChartInfoDetailFromUniqueCode() {
  29. br := new(models.BaseResponse).Init()
  30. defer func() {
  31. this.Data["json"] = br
  32. this.ServeJSON()
  33. }()
  34. uniqueCode := this.GetString("UniqueCode")
  35. token := this.GetString("Token")
  36. source, _ := this.GetInt("Source")
  37. if uniqueCode == "" {
  38. br.Msg = "参数错误"
  39. br.ErrMsg = "参数错误,uniqueCode is empty"
  40. return
  41. }
  42. key := utils.HZ_CHART_LIB_DETAIL + uniqueCode
  43. resp := new(models.ChartInfoDetailResp)
  44. conf, e := models.GetBusinessConf()
  45. if e != nil {
  46. br.Msg = "获取失败"
  47. br.ErrMsg = "获取配置信息失败, Err: " + e.Error()
  48. return
  49. }
  50. var isCollect bool
  51. if source == utils.CHART_SOURCE_DW && token != "" {
  52. tmpIsCollect, err := dwmini.GetMyChartIsCollect(token, uniqueCode)
  53. if err != nil {
  54. br.Msg = "获取失败"
  55. br.ErrMsg = "获取收藏状态失败,Err:" + err.Error()
  56. return
  57. }
  58. isCollect = tmpIsCollect
  59. }
  60. if utils.Re == nil {
  61. if utils.Re == nil && utils.Rc.IsExist(key) {
  62. if data, err1 := utils.Rc.RedisBytes(key); err1 == nil {
  63. err := json.Unmarshal(data, &resp)
  64. if err == nil && resp != nil {
  65. if conf[models.BusinessConfWatermarkChart] == "true" && conf[models.BusinessConfCompanyWatermark] != "" {
  66. resp.WaterMark = conf[models.BusinessConfCompanyWatermark]
  67. }
  68. if isCollect {
  69. resp.IsCollect = isCollect
  70. }
  71. br.Ret = 200
  72. br.Success = true
  73. br.Msg = "获取成功"
  74. br.Data = resp
  75. fmt.Println("source redis")
  76. return
  77. }
  78. }
  79. }
  80. }
  81. chartInfo, err := models.GetChartInfoByUniqueCode(uniqueCode)
  82. if err != nil {
  83. if utils.IsErrNoRow(err) {
  84. br.Msg = "该图已被删除,请刷新页面"
  85. br.ErrMsg = "该图已被删除,请刷新页面,Err:" + err.Error()
  86. return
  87. }
  88. br.Msg = "获取失败"
  89. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  90. return
  91. }
  92. var isOk bool
  93. var msg, errMsg string
  94. switch chartInfo.Source {
  95. case utils.CHART_SOURCE_DEFAULT:
  96. resp, isOk, msg, errMsg = GetChartInfoDetailFromUniqueCode(chartInfo, key)
  97. case utils.CHART_SOURCE_FUTURE_GOOD:
  98. resp, isOk, msg, errMsg = GetFutureGoodChartInfoDetailFromUniqueCode(chartInfo, key)
  99. case utils.CHART_SOURCE_FUTURE_GOOD_PROFIT:
  100. resp, isOk, msg, errMsg = GetFutureGoodProfitChartInfoDetailFromUniqueCode(chartInfo, key)
  101. case utils.CHART_SOURCE_CORRELATION, utils.CHART_SOURCE_ROLLING_CORRELATION:
  102. resp, isOk, msg, errMsg = GetCorrelationChartInfoDetailFromUniqueCode(chartInfo, key)
  103. case utils.CHART_SOURCE_LINE_EQUATION:
  104. resp, isOk, msg, errMsg = GetLineEquationChartInfoDetailFromUniqueCode(chartInfo, key)
  105. case utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY:
  106. resp, isOk, msg, errMsg = GetLineFeatureChartInfoDetailFromUniqueCode(chartInfo, key)
  107. case utils.CHART_SOURCE_CROSS_HEDGING:
  108. resp, isOk, msg, errMsg = GetCrossVarietyChartInfoDetailFromUniqueCode(chartInfo, key)
  109. case utils.CHART_SOURCE_BALANCE_EXCEL:
  110. resp, isOk, msg, errMsg = GetBalanceChartInfoDetailFromUniqueCode(chartInfo, key, this.Lang)
  111. if !isOk {
  112. br.Msg = msg
  113. br.ErrMsg = errMsg
  114. return
  115. }
  116. case utils.CHART_SOURCE_RANGE_ANALYSIS:
  117. resp, isOk, msg, errMsg = GetRangeAnalysisChartInfoDetailFromUniqueCode(chartInfo, key, this.Lang)
  118. if !isOk {
  119. br.Msg = msg
  120. br.ErrMsg = errMsg
  121. return
  122. }
  123. default:
  124. br.Msg = "错误的图表"
  125. br.ErrMsg = "错误的图表"
  126. return
  127. }
  128. if !isOk {
  129. br.Msg = msg
  130. br.ErrMsg = errMsg
  131. return
  132. }
  133. if isCollect {
  134. resp.IsCollect = isCollect
  135. }
  136. if conf[models.BusinessConfWatermarkChart] == "true" && conf[models.BusinessConfCompanyWatermark] != "" {
  137. resp.WaterMark = conf[models.BusinessConfCompanyWatermark]
  138. }
  139. br.Ret = 200
  140. br.Success = true
  141. br.Msg = "获取成功"
  142. br.Data = resp
  143. }
  144. func GetFutureGoodChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfo, key string) (resp *models.ChartInfoDetailResp, isOk bool, msg, errMsg string) {
  145. resp = new(models.ChartInfoDetailResp)
  146. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, utils.CHART_SOURCE_DEFAULT, 1)
  147. if err != nil {
  148. msg = "获取失败"
  149. errMsg = "获取主题信息失败,Err:" + err.Error()
  150. return
  151. }
  152. chartInfo.ChartThemeStyle = chartTheme.Config
  153. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  154. chartInfoId := chartInfo.ChartInfoId
  155. startDate := chartInfo.StartDate
  156. endDate := chartInfo.EndDate
  157. {
  158. if strings.Count(startDate, "-") == 1 {
  159. startDate = startDate + "-01"
  160. }
  161. if strings.Count(endDate, "-") == 1 {
  162. endDate = endDate + "-01"
  163. }
  164. }
  165. edbInfoMappingList, err := models.GetEtaEdbChartEdbMappingList(chartInfoId)
  166. if err != nil {
  167. msg = "获取失败"
  168. errMsg = "获取图表,现货指标信息失败,Err:" + err.Error()
  169. return
  170. }
  171. futureGoodEdbInfoMapping, err := models.GetFutureGoodEdbChartEdbMapping(chartInfoId)
  172. if err != nil {
  173. msg = "获取失败"
  174. errMsg = "获取图表的期货商品指标信息失败,Err:" + err.Error()
  175. return
  176. }
  177. var barConfig data_manage.FutureGoodBarChartInfoReq
  178. if chartInfo.BarConfig == `` {
  179. msg = "商品价格曲线图未配置"
  180. errMsg = "商品价格曲线图未配置"
  181. return
  182. }
  183. err = json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
  184. if err != nil {
  185. msg = "商品价格曲线图配置异常"
  186. errMsg = "商品价格曲线图配置异常"
  187. return
  188. }
  189. baseEdbInfoId := barConfig.BaseEdbInfoId
  190. var baseEdbInfoMapping *models.ChartEdbInfoMapping
  191. if baseEdbInfoId == 0 {
  192. baseEdbInfoId = edbInfoMappingList[0].EdbInfoId
  193. baseEdbInfoMapping = edbInfoMappingList[0]
  194. barConfig.BaseEdbInfoId = baseEdbInfoId
  195. } else {
  196. baseEdbInfoMapping, err = models.GetChartEdbMappingByEdbInfoId(baseEdbInfoId)
  197. if err != nil {
  198. msg = "获取失败"
  199. errMsg = "获取图表,指标信息失败,Err:" + err.Error()
  200. return
  201. }
  202. }
  203. barConfigEdbInfoIdList, edbList, xEdbIdValue, xDataList, yDataList, err := future_goodServ.GetChartEdbData(chartInfoId, startDate, endDate, baseEdbInfoMapping, edbInfoMappingList, futureGoodEdbInfoMapping, barConfig, true)
  204. if err != nil {
  205. msg = "获取失败"
  206. errMsg = "获取图表,指标信息失败,Err:" + err.Error()
  207. return
  208. }
  209. warnEdbList := make([]string, 0)
  210. if len(edbList) <= 0 {
  211. msg = "商品价格曲线图表指标异常"
  212. errMsg = "商品价格曲线图表异常"
  213. return
  214. }
  215. baseEdbInfo := edbList[0] //现货指标
  216. for _, v := range edbList {
  217. if v.IsNullData {
  218. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  219. }
  220. if barConfigEdbInfoIdList != nil && len(barConfigEdbInfoIdList) > 0 {
  221. for _, reqEdb := range barConfigEdbInfoIdList {
  222. if v.EdbInfoId == reqEdb.EdbInfoId {
  223. v.EdbAliasName = reqEdb.Name
  224. v.EdbAliasNameEn = reqEdb.NameEn
  225. }
  226. }
  227. }
  228. }
  229. chartInfo.UnitEn = baseEdbInfo.UnitEn
  230. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  231. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  232. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  233. xDataListFinal := make([]models.XData, 0)
  234. for _, v := range xDataList {
  235. tmp := models.XData{
  236. Name: v.Name,
  237. NameEn: v.NameEn,
  238. IsHide: v.IsHide,
  239. }
  240. xDataListFinal = append(xDataListFinal, tmp)
  241. }
  242. resp.ChartInfo = chartInfo
  243. resp.EdbInfoList = edbList
  244. resp.XEdbIdValue = xEdbIdValue
  245. resp.YDataList = yDataList
  246. resp.XDataList = xDataListFinal
  247. if utils.Re == nil {
  248. data, _ := json.Marshal(resp)
  249. utils.Rc.Put(key, data, 2*time.Hour)
  250. }
  251. isOk = true
  252. return
  253. }
  254. func GetFutureGoodProfitChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfo, key string) (resp *models.ChartInfoDetailResp, isOk bool, msg, errMsg string) {
  255. resp = new(models.ChartInfoDetailResp)
  256. chartInfoId := chartInfo.ChartInfoId
  257. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, utils.CHART_SOURCE_DEFAULT, 1)
  258. if err != nil {
  259. msg = "获取失败"
  260. errMsg = "获取主题信息失败,Err:" + err.Error()
  261. return
  262. }
  263. chartInfo.ChartThemeStyle = chartTheme.Config
  264. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  265. var extraConf request.ChartInfoReq
  266. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &extraConf)
  267. if err != nil {
  268. msg = "商品利润曲线图配置异常"
  269. errMsg = "商品利润曲线图配置异常,Err:" + err.Error()
  270. return
  271. }
  272. if len(extraConf.EdbInfoIdList) == 0 {
  273. extraConf.EdbInfoIdList = append(extraConf.EdbInfoIdList, extraConf.BaseEdbInfoId)
  274. }
  275. edbList := make([]*models.ChartEdbInfoMapping, 0)
  276. edbInfoMappingList, err := models.GetEtaEdbChartEdbMappingList(chartInfoId)
  277. if err != nil {
  278. msg = "获取失败"
  279. errMsg = "获取商品利润图表,基础指标信息失败,Err:" + err.Error()
  280. return
  281. }
  282. baseEdbInfo := new(models.ChartEdbInfoMapping)
  283. for _, v := range edbInfoMappingList {
  284. if v.EdbInfoId == extraConf.BaseEdbInfoId {
  285. baseEdbInfo = v
  286. }
  287. }
  288. edbList = edbInfoMappingList
  289. futureGoodEdbInfoMappingList, err := models.GetFutureGoodEdbChartEdbMappingList(chartInfoId)
  290. if err != nil {
  291. msg = "获取失败"
  292. errMsg = "获取商品利润图表,商品指标信息失败,Err:" + err.Error()
  293. return
  294. }
  295. edbList = append(edbList, futureGoodEdbInfoMappingList...)
  296. if len(edbList) <= 0 {
  297. msg = "商品利润曲线图表指标异常"
  298. errMsg = "商品利润曲线图表指标异常"
  299. return
  300. }
  301. xDataList := make([]models.XData, 0)
  302. yDataList := make([]models.YData, 0)
  303. chartInfoFutureGoodProfit := new(future_good.ChartInfoFutureGoodProfit)
  304. if err = chartInfoFutureGoodProfit.GetItemById(chartInfo.ChartInfoId); err != nil {
  305. msg = "获取失败"
  306. errMsg = "获取基础相关性图表信息失败, Err: " + err.Error()
  307. return
  308. }
  309. err = json.Unmarshal([]byte(chartInfoFutureGoodProfit.XValue), &xDataList)
  310. if err != nil {
  311. msg = "获取失败"
  312. errMsg = "转换X轴数据失败, Err: " + err.Error()
  313. return
  314. }
  315. err = json.Unmarshal([]byte(chartInfoFutureGoodProfit.YValue), &yDataList)
  316. if err != nil {
  317. msg = "获取失败"
  318. errMsg = "转换Y轴数据失败, Err: " + err.Error()
  319. return
  320. }
  321. warnEdbList := make([]string, 0)
  322. for _, v := range edbList {
  323. if v.IsNullData {
  324. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  325. }
  326. }
  327. chartInfo.UnitEn = baseEdbInfo.UnitEn
  328. resp.ChartInfo = chartInfo
  329. resp.EdbInfoList = edbList
  330. resp.DataResp = response.ProfitFutureGoodChartResp{
  331. YDataList: yDataList,
  332. XDataList: xDataList,
  333. ProfitName: chartInfoFutureGoodProfit.ProfitName,
  334. ProfitNameEn: chartInfoFutureGoodProfit.ProfitNameEn,
  335. Extra: extraConf,
  336. }
  337. if utils.Re == nil {
  338. data, _ := json.Marshal(resp)
  339. utils.Rc.Put(key, data, 2*time.Hour)
  340. }
  341. isOk = true
  342. return
  343. }
  344. func GetLineEquationChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfo, key string) (resp *models.ChartInfoDetailResp, isOk bool, msg, errMsg string) {
  345. resp = new(models.ChartInfoDetailResp)
  346. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, utils.CHART_SOURCE_DEFAULT, 1)
  347. if err != nil {
  348. msg = "获取失败"
  349. errMsg = "获取主题信息失败,Err:" + err.Error()
  350. return
  351. }
  352. chartInfo.ChartThemeStyle = chartTheme.Config
  353. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  354. if chartInfo.ExtraConfig == `` {
  355. msg = "获取失败"
  356. errMsg = "获取配置信息失败"
  357. return
  358. }
  359. var lineChartInfoConfig line_equationReq.LineChartInfoReq
  360. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &lineChartInfoConfig)
  361. if err != nil {
  362. msg = "获取失败"
  363. errMsg = "获取图表配置信息失败, Err:" + err.Error()
  364. return
  365. }
  366. var getAData, getBData, getR2Data bool
  367. switch lineChartInfoConfig.Source {
  368. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_ONE:
  369. getAData = true
  370. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_TWO:
  371. getBData = true
  372. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_THREE:
  373. getR2Data = true
  374. }
  375. edbList, dataResp, err, errMsg := line_equation.GetChartEdbData(chartInfo.ChartInfoId, lineChartInfoConfig, getAData, getBData, getR2Data)
  376. if err != nil {
  377. if errMsg == `` {
  378. errMsg = "获取失败"
  379. }
  380. return
  381. }
  382. var resultResp interface{}
  383. switch lineChartInfoConfig.Source {
  384. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_ONE:
  385. resultResp = dataResp.AData
  386. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_TWO:
  387. resultResp = dataResp.BData
  388. case utils.CHART_MULTIPLE_GRAPH_LINE_EQUATION_THREE:
  389. resultResp = dataResp.R2Data
  390. }
  391. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  392. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  393. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  394. resp.ChartInfo = chartInfo
  395. resp.DataResp = resultResp
  396. resp.EdbInfoList = edbList
  397. if utils.Re == nil {
  398. data, _ := json.Marshal(resp)
  399. utils.Rc.Put(key, data, 2*time.Hour)
  400. }
  401. isOk = true
  402. return
  403. }
  404. func GetLineFeatureChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfo, key string) (resp *models.ChartInfoDetailResp, isOk bool, msg, errMsg string) {
  405. resp = new(models.ChartInfoDetailResp)
  406. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, utils.CHART_SOURCE_DEFAULT, 1)
  407. if err != nil {
  408. msg = "获取失败"
  409. errMsg = "获取主题信息失败,Err:" + err.Error()
  410. return
  411. }
  412. chartInfo.ChartThemeStyle = chartTheme.Config
  413. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  414. edbMappingList, err := models.GetChartEdbMappingList(chartInfo.ChartInfoId)
  415. if err != nil {
  416. msg = "获取失败"
  417. errMsg = "获取图表关联指标信息失败,Err:" + err.Error()
  418. return
  419. }
  420. if len(edbMappingList) != 1 {
  421. msg = "获取失败"
  422. errMsg = fmt.Sprint("获取图表关联指标信息异常,数量:", len(edbMappingList))
  423. return
  424. }
  425. edbMapping := edbMappingList[0]
  426. var edbList []*models.ChartEdbInfoMapping
  427. var resultResp interface{}
  428. switch chartInfo.Source {
  429. case utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION:
  430. calculateValue, tmpErr := strconv.Atoi(chartInfo.ExtraConfig)
  431. if tmpErr != nil {
  432. msg = "获取失败"
  433. errMsg = "格式化配置项失败,Err:" + tmpErr.Error()
  434. return
  435. }
  436. startDate, endDate := utils.GetDateByDateType(chartInfo.DateType, chartInfo.StartDate, chartInfo.EndDate)
  437. edbList, resultResp, err, msg = lineFeatureServ.GetStandardDeviationData(chartInfo.ChartInfoId, startDate, endDate, edbMapping, calculateValue)
  438. case utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE:
  439. var percentileConfig line_featureReq.Percentile
  440. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &percentileConfig)
  441. if err != nil {
  442. msg = "获取失败"
  443. errMsg = "格式化配置项失败,Err:" + err.Error()
  444. return
  445. }
  446. startDate, endDate := utils.GetDateByDateType(chartInfo.DateType, chartInfo.StartDate, chartInfo.EndDate)
  447. edbList, resultResp, err, msg = lineFeatureServ.GetPercentileData(chartInfo.ChartInfoId, startDate, endDate, edbMapping, percentileConfig.CalculateValue, percentileConfig.CalculateUnit, percentileConfig.PercentType)
  448. case utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY:
  449. var frequencyDistributionConfig line_featureReq.FrequencyDistribution
  450. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &frequencyDistributionConfig)
  451. if err != nil {
  452. msg = "获取失败"
  453. errMsg = "格式化配置项失败,Err:" + err.Error()
  454. return
  455. }
  456. edbList, resultResp, err, errMsg = lineFeatureServ.GetFrequencyDistributionData(0, edbMapping, frequencyDistributionConfig.DateType, frequencyDistributionConfig.FrequencyValue, frequencyDistributionConfig.StartDate, frequencyDistributionConfig.EndDate)
  457. default:
  458. msg = `错误的图表`
  459. errMsg = fmt.Sprint("错误的图表来源,source", chartInfo.Source)
  460. return
  461. }
  462. if err != nil {
  463. if msg == `` {
  464. msg = "获取失败"
  465. }
  466. errMsg = "获取图表,指标信息失败,Err:" + err.Error()
  467. return
  468. }
  469. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  470. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  471. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  472. resp.ChartInfo = chartInfo
  473. resp.DataResp = resultResp
  474. resp.EdbInfoList = edbList
  475. if utils.Re == nil {
  476. data, _ := json.Marshal(resp)
  477. utils.Rc.Put(key, data, 2*time.Hour)
  478. }
  479. isOk = true
  480. return
  481. }
  482. func GetCrossVarietyChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfo, key string) (resp *models.ChartInfoDetailResp, isOk bool, msg, errMsg string) {
  483. resp = new(models.ChartInfoDetailResp)
  484. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, utils.CHART_SOURCE_DEFAULT, 5)
  485. if err != nil {
  486. msg = "获取失败"
  487. errMsg = "获取主题信息失败,Err:" + err.Error()
  488. return
  489. }
  490. chartInfo.ChartThemeStyle = chartTheme.Config
  491. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  492. if chartInfo.ExtraConfig == `` {
  493. msg = "图表配置信息异常"
  494. errMsg = "图表配置信息异常"
  495. return
  496. }
  497. var config cross_varietyReq.ChartConfigReq
  498. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &config)
  499. if err != nil {
  500. msg = "解析跨品种分析配置失败"
  501. errMsg = "解析跨品种分析配置失败,Err:" + err.Error()
  502. return
  503. }
  504. edbList, dataResp, err, msg, _ := cross_variety.GetChartData(0, config)
  505. if err != nil {
  506. errMsg = "获取图表,指标信息失败,Err:" + err.Error()
  507. return
  508. }
  509. resp.ChartInfo = chartInfo
  510. resp.DataResp = dataResp
  511. resp.EdbInfoList = edbList
  512. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  513. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  514. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  515. if utils.Re == nil {
  516. d, _ := json.Marshal(resp)
  517. _ = utils.Rc.Put(key, d, 2*time.Hour)
  518. }
  519. isOk = true
  520. return
  521. }
  522. func GetBalanceChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfo, key, lang string) (resp *models.ChartInfoDetailResp, isOk bool, msg, errMsg string) {
  523. resp = new(models.ChartInfoDetailResp)
  524. msg = `获取失败`
  525. var err error
  526. defer func() {
  527. if err != nil {
  528. if errMsg != "" {
  529. msg = errMsg
  530. }
  531. errMsg = err.Error()
  532. }
  533. }()
  534. mappingListTmp, dataListMap, err, errMsg := excel.GetBalanceExcelChartSingle(chartInfo.ChartInfoId, 0, lang)
  535. if err != nil {
  536. errMsg = "获取失败"
  537. err = fmt.Errorf(" 获取图表,指标信息失败 Err:%s", err.Error())
  538. return
  539. }
  540. var chartInfoResp *models.ChartInfoDetailResp
  541. chartInfoResp, err, errMsg = data.GetBalanceExcelChartDetail(chartInfo, mappingListTmp, dataListMap)
  542. if err != nil {
  543. msg = "查询图表详情失败"
  544. errMsg = "查询图表详情失败,Err:" + err.Error()
  545. return
  546. }
  547. resp = &models.ChartInfoDetailResp{
  548. ChartInfo: chartInfoResp.ChartInfo,
  549. EdbInfoList: chartInfoResp.EdbInfoList,
  550. XEdbIdValue: chartInfoResp.XEdbIdValue,
  551. YDataList: chartInfoResp.YDataList,
  552. XDataList: chartInfoResp.XDataList,
  553. CorrelationChartInfo: chartInfoResp.CorrelationChartInfo,
  554. DataResp: chartInfoResp.DataResp,
  555. }
  556. if utils.Re == nil {
  557. jsonData, _ := json.Marshal(resp)
  558. utils.Rc.Put(key, jsonData, 10*time.Minute)
  559. }
  560. isOk = true
  561. return
  562. }
  563. // @router /future_good/refresh [get]
  564. func (this *ChartController) FutureGoodChartInfoRefresh() {
  565. br := new(models.BaseResponse).Init()
  566. chartId := 0
  567. defer func() {
  568. if chartId > 0 {
  569. shareChartRefreshLogInfo := &models.ShareChartRefreshLog{
  570. Ip: this.Ctx.Input.IP(),
  571. ChartId: chartId,
  572. CreateTime: time.Now(),
  573. }
  574. models.AddShareChartRefreshLog(shareChartRefreshLogInfo)
  575. }
  576. this.Data["json"] = br
  577. this.ServeJSON()
  578. }()
  579. uniqueCode := this.GetString("UniqueCode")
  580. if uniqueCode == "" {
  581. br.Msg = "参数错误"
  582. br.ErrMsg = "参数错误,uniqueCode is empty"
  583. return
  584. }
  585. chartInfo, err := models.GetChartInfoByUniqueCode(uniqueCode)
  586. if err != nil {
  587. if utils.IsErrNoRow(err) {
  588. br.Msg = "该图已被删除,请刷新页面"
  589. br.ErrMsg = "该图已被删除,请刷新页面,Err:" + err.Error()
  590. return
  591. }
  592. br.Msg = "获取失败"
  593. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  594. return
  595. }
  596. chartId = chartInfo.ChartInfoId
  597. err = future_goodServ.FutureGoodChartInfoRefresh(chartInfo.ChartInfoId)
  598. if err != nil {
  599. br.Msg = "刷新失败"
  600. br.ErrMsg = "刷新图表关联指标信息失败,Err:" + err.Error()
  601. return
  602. }
  603. key := utils.HZ_CHART_LIB_DETAIL + uniqueCode
  604. if utils.Re == nil {
  605. utils.Rc.Delete(key)
  606. }
  607. br.Ret = 200
  608. br.Success = true
  609. br.Msg = "刷新成功"
  610. }
  611. func GetCorrelationChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfo, key string) (resp *models.ChartInfoDetailResp, isOk bool, msg, errMsg string) {
  612. resp = new(models.ChartInfoDetailResp)
  613. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, utils.CHART_SOURCE_DEFAULT, 1)
  614. if err != nil {
  615. msg = "获取失败"
  616. errMsg = "获取主题信息失败,Err:" + err.Error()
  617. return
  618. }
  619. chartInfo.ChartThemeStyle = chartTheme.Config
  620. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  621. chartInfoId := chartInfo.ChartInfoId
  622. startDate := chartInfo.StartDate
  623. endDate := chartInfo.EndDate
  624. {
  625. if strings.Count(startDate, "-") == 1 {
  626. startDate = startDate + "-01"
  627. }
  628. if strings.Count(endDate, "-") == 1 {
  629. endDate = endDate + "-01"
  630. }
  631. }
  632. correlationChart := new(data_manage.ChartInfoCorrelation)
  633. if e := correlationChart.GetItemById(chartInfoId); e != nil {
  634. msg = "获取失败"
  635. errMsg = "获取图表相关性信息失败, Err:" + e.Error()
  636. return
  637. }
  638. edbInfoMappingA, e := models.GetChartEdbMappingByEdbInfoId(correlationChart.EdbInfoIdFirst)
  639. if e != nil {
  640. msg = "获取失败"
  641. errMsg = "获取相关性图表, A指标mapping信息失败, Err:" + e.Error()
  642. return
  643. }
  644. edbInfoMappingB := new(models.ChartEdbInfoMapping)
  645. if correlationChart.AnalysisMode != 1 {
  646. edbInfoMappingB, e = models.GetChartEdbMappingByEdbInfoId(correlationChart.EdbInfoIdSecond)
  647. if e != nil {
  648. msg = "获取失败"
  649. errMsg = "获取相关性图表, B指标mapping信息失败, Err:" + e.Error()
  650. return
  651. }
  652. }
  653. var dataResp interface{} // 绘图数据返回(目前是滚动相关性的图)
  654. var xEdbIdValue []int
  655. var yDataList []models.YData
  656. if correlationChart.AnalysisMode != 1 {
  657. switch chartInfo.Source {
  658. case utils.CHART_SOURCE_CORRELATION: // 相关性图
  659. moveUnitDays, ok := utils.FrequencyDaysMap[correlationChart.CalculateUnit]
  660. if !ok {
  661. msg = "错误的分析周期"
  662. errMsg = "相关性图表数据有误"
  663. return
  664. }
  665. st := time.Now().AddDate(0, 0, -correlationChart.CalculateValue*moveUnitDays).Format(utils.FormatDate)
  666. ed := time.Now().Format(utils.FormatDate)
  667. xEdbIdValue, yDataList, e = correlationServ.GetChartDataByEdbInfo(edbInfoMappingA, edbInfoMappingB, correlationChart.LeadValue, correlationChart.LeadUnit, st, ed, chartInfo.ExtraConfig)
  668. if e != nil {
  669. msg = "获取失败"
  670. errMsg = "获取相关性图表, 图表计算值失败, Err:" + e.Error()
  671. return
  672. }
  673. case utils.CHART_SOURCE_ROLLING_CORRELATION: // 滚动相关性图
  674. st, ed := utils.GetDateByDateType(correlationChart.DateType, correlationChart.StartDate.Format(utils.FormatDate), correlationChart.EndDate.Format(utils.FormatDate))
  675. dataResp, e = correlationServ.GetRollingCorrelationChartDataByEdbInfo(edbInfoMappingA, edbInfoMappingB, correlationChart.LeadValue, correlationChart.LeadUnit, correlationChart.CalculateValue, correlationChart.CalculateUnit, st, ed, chartInfo.ChartName, chartInfo.ChartNameEn)
  676. }
  677. } else {
  678. xEdbIdValue, yDataList, e = correlationServ.GetFactorChartDataByChartId(chartInfoId, chartInfo.ExtraConfig)
  679. if e != nil {
  680. msg = "获取失败"
  681. errMsg = "获取相关性图表, 图表计算值失败, Err:" + e.Error()
  682. return
  683. }
  684. }
  685. edbList, e := correlationServ.GetChartEdbInfoFormat(chartInfo.ChartInfoId, edbInfoMappingA, edbInfoMappingB)
  686. if e != nil {
  687. msg = "获取失败"
  688. errMsg = "获取相关性图表, 完善指标信息失败, Err:" + e.Error()
  689. return
  690. }
  691. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  692. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  693. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  694. correlationInfo := new(models.CorrelationInfo)
  695. correlationInfo.LeadValue = correlationChart.LeadValue
  696. correlationInfo.LeadUnit = correlationChart.LeadUnit
  697. correlationInfo.StartDate = correlationChart.StartDate.Format(utils.FormatDate)
  698. correlationInfo.EndDate = correlationChart.EndDate.Format(utils.FormatDate)
  699. correlationInfo.LeadValue = correlationChart.LeadValue
  700. correlationInfo.EdbInfoIdFirst = correlationChart.EdbInfoIdFirst
  701. correlationInfo.EdbInfoIdSecond = correlationChart.EdbInfoIdSecond
  702. correlationInfo.AnalysisMode = correlationChart.AnalysisMode
  703. resp.ChartInfo = chartInfo
  704. resp.EdbInfoList = edbList
  705. resp.XEdbIdValue = xEdbIdValue
  706. resp.YDataList = yDataList
  707. resp.CorrelationChartInfo = correlationInfo
  708. resp.DataResp = dataResp
  709. if utils.Re == nil {
  710. d, _ := json.Marshal(resp)
  711. _ = utils.Rc.Put(key, d, 2*time.Hour)
  712. }
  713. isOk = true
  714. return
  715. }
  716. // @router /correlation/refresh [get]
  717. func (this *ChartController) CorrelationChartInfoRefresh() {
  718. br := new(models.BaseResponse).Init()
  719. chartId := 0
  720. defer func() {
  721. if chartId > 0 {
  722. shareChartRefreshLogInfo := &models.ShareChartRefreshLog{
  723. Ip: this.Ctx.Input.IP(),
  724. ChartId: chartId,
  725. CreateTime: time.Now(),
  726. }
  727. models.AddShareChartRefreshLog(shareChartRefreshLogInfo)
  728. }
  729. this.Data["json"] = br
  730. this.ServeJSON()
  731. }()
  732. uniqueCode := this.GetString("UniqueCode")
  733. if uniqueCode == "" {
  734. br.Msg = "参数错误"
  735. br.ErrMsg = "参数错误,uniqueCode is empty"
  736. return
  737. }
  738. chartInfo, err := models.GetChartInfoByUniqueCode(uniqueCode)
  739. if err != nil {
  740. if utils.IsErrNoRow(err) {
  741. br.Msg = "该图已被删除,请刷新页面"
  742. br.ErrMsg = "该图已被删除,请刷新页面,Err:" + err.Error()
  743. return
  744. }
  745. br.Msg = "获取失败"
  746. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  747. return
  748. }
  749. chartId = chartInfo.ChartInfoId
  750. err = data.ChartInfoRefreshV2(chartInfo.ChartInfoId)
  751. if err != nil {
  752. br.Msg = "刷新失败"
  753. br.ErrMsg = "刷新图表关联指标信息失败,Err:" + err.Error()
  754. return
  755. }
  756. key := utils.HZ_CHART_LIB_DETAIL + uniqueCode
  757. if utils.Re == nil {
  758. _ = utils.Rc.Delete(key)
  759. }
  760. br.Ret = 200
  761. br.Success = true
  762. br.Msg = "刷新成功"
  763. }
  764. func GetRangeAnalysisChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfo, key, lang string) (resp *models.ChartInfoDetailResp, isOk bool, msg, errMsg string) {
  765. resp = new(models.ChartInfoDetailResp)
  766. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, utils.CHART_SOURCE_DEFAULT, 1)
  767. if err != nil {
  768. msg = "获取失败"
  769. errMsg = "获取主题信息失败,Err:" + err.Error()
  770. return
  771. }
  772. chartInfo.ChartThemeStyle = chartTheme.Config
  773. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  774. chartInfoId := chartInfo.ChartInfoId
  775. edbInfoMappingList, err := models.GetChartEdbMappingList(chartInfoId)
  776. if err != nil {
  777. msg = "获取失败"
  778. errMsg = "获取图表,指标信息失败,Err:" + err.Error()
  779. return
  780. }
  781. dateType := chartInfo.DateType
  782. startYear := chartInfo.StartYear
  783. startDate := chartInfo.StartDate
  784. endDate := chartInfo.EndDate
  785. var extraConfig models.ChartRangeAnalysisExtraConf
  786. if chartInfo.ExtraConfig == `` {
  787. msg = "配置信息错误"
  788. return
  789. }
  790. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &extraConfig)
  791. if err != nil {
  792. msg = "配置信息错误"
  793. errMsg = "图表配置信息错误,Err:" + err.Error()
  794. return
  795. }
  796. if len(edbInfoMappingList) == 0 {
  797. msg = "获取失败"
  798. errMsg = "图表没有指标,无法计算"
  799. return
  800. }
  801. edbList, xEdbIdValue, dataResp, e := range_analysis.GetChartDataByEdbInfoList(chartInfoId, dateType, startYear, startDate, endDate, edbInfoMappingList, &extraConfig)
  802. if e != nil {
  803. msg = "获取失败"
  804. errMsg = "获取区间计算图表, 图表计算值失败, Err:" + e.Error()
  805. return
  806. }
  807. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  808. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  809. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  810. resp.ChartInfo = chartInfo
  811. resp.EdbInfoList = edbList
  812. resp.XEdbIdValue = xEdbIdValue
  813. resp.DataResp = dataResp
  814. if utils.Re == nil {
  815. jsonData, _ := json.Marshal(resp)
  816. utils.Rc.Put(key, jsonData, 10*time.Minute)
  817. }
  818. isOk = true
  819. return
  820. }