chart.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_chart_lib/facade"
  5. "errors"
  6. "eta/eta_chart_lib/models"
  7. "eta/eta_chart_lib/models/data_manage"
  8. "eta/eta_chart_lib/models/data_manage/cross_variety/request"
  9. "eta/eta_chart_lib/models/data_manage/excel"
  10. requestDTO "eta/eta_chart_lib/models/request"
  11. "eta/eta_chart_lib/services/data"
  12. "eta/eta_chart_lib/services/data/area_graph"
  13. "eta/eta_chart_lib/services/data/cross_variety"
  14. "eta/eta_chart_lib/services/data/range_analysis"
  15. dwmini "eta/eta_chart_lib/services/dw_mini"
  16. "eta/eta_chart_lib/utils"
  17. "fmt"
  18. "strings"
  19. "time"
  20. )
  21. // 图表
  22. type ChartController struct {
  23. BaseAuthController
  24. }
  25. // ChartInfoDetail
  26. // @Title 获取图表详情
  27. // @Description 获取图表详情接口
  28. // @Param UniqueCode query string true "图表唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
  29. // @Success 200 {object} data_manage.ChartInfoDetailResp
  30. // @router /detail [get]
  31. func (this *ChartController) ChartInfoDetail() {
  32. br := new(models.BaseResponse).Init()
  33. defer func() {
  34. this.Data["json"] = br
  35. this.ServeJSON()
  36. }()
  37. uniqueCode := this.GetString("UniqueCode")
  38. token := this.GetString("Token")
  39. source, _ := this.GetInt("Source")
  40. miniSource := this.GetString("MiniSource")
  41. if uniqueCode == "" {
  42. br.Msg = "参数错误"
  43. br.ErrMsg = "参数错误,uniqueCode is empty"
  44. return
  45. }
  46. key := utils.HZ_CHART_LIB_DETAIL + uniqueCode
  47. resp := new(models.ChartInfoDetailResp)
  48. // 图表水印
  49. conf, e := models.GetBusinessConf()
  50. if e != nil {
  51. br.Msg = "获取失败"
  52. br.ErrMsg = "获取配置信息失败, Err: " + e.Error()
  53. return
  54. }
  55. var isCollect bool
  56. if miniSource != "" {
  57. auth := this.Ctx.Request.Header.Get("Authorization")
  58. param := facade.BaseRequest{
  59. Auth: auth,
  60. UniqueCode: uniqueCode,
  61. }
  62. isCollect = facade.FacadeClient.Deal(param).IsCollect(facade.GetInstance(miniSource))
  63. } else {
  64. if source == utils.CHART_SOURCE_DW && token != "" {
  65. tmpIsCollect, err := dwmini.GetMyChartIsCollect(token, uniqueCode)
  66. if err != nil {
  67. br.Msg = "获取失败"
  68. br.ErrMsg = "获取收藏状态失败,Err:" + err.Error()
  69. return
  70. }
  71. isCollect = tmpIsCollect
  72. }
  73. }
  74. //判断是否有缓存
  75. if utils.Re == nil {
  76. if utils.Re == nil && utils.Rc.IsExist(key) {
  77. if data, err1 := utils.Rc.RedisBytes(key); err1 == nil {
  78. err := json.Unmarshal(data, &resp)
  79. if err == nil && resp != nil {
  80. if conf[models.BusinessConfWatermarkChart] == "true" && conf[models.BusinessConfCompanyWatermark] != "" {
  81. resp.WaterMark = conf[models.BusinessConfCompanyWatermark]
  82. }
  83. if isCollect {
  84. resp.IsCollect = isCollect
  85. }
  86. br.Ret = 200
  87. br.Success = true
  88. br.Msg = "获取成功"
  89. br.Data = resp
  90. fmt.Println("source redis")
  91. return
  92. }
  93. }
  94. }
  95. }
  96. chartInfo, err := models.GetChartInfoByUniqueCode(uniqueCode)
  97. if err != nil {
  98. if err.Error() == utils.ErrNoRow() {
  99. br.Msg = "该图已被删除,请刷新页面"
  100. br.ErrMsg = "该图已被删除,请刷新页面,Err:" + err.Error()
  101. return
  102. }
  103. br.Msg = "获取失败"
  104. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  105. return
  106. }
  107. //var resp interface{}
  108. var isOk bool
  109. var msg, errMsg string
  110. switch chartInfo.Source {
  111. case utils.CHART_SOURCE_DEFAULT:
  112. resp, isOk, msg, errMsg = GetChartInfoDetailFromUniqueCode(chartInfo, key)
  113. case utils.CHART_SOURCE_FUTURE_GOOD:
  114. resp, isOk, msg, errMsg = GetFutureGoodChartInfoDetailFromUniqueCode(chartInfo, key)
  115. case utils.CHART_SOURCE_FUTURE_GOOD_PROFIT:
  116. resp, isOk, msg, errMsg = GetFutureGoodProfitChartInfoDetailFromUniqueCode(chartInfo, key)
  117. case utils.CHART_SOURCE_CORRELATION, utils.CHART_SOURCE_ROLLING_CORRELATION:
  118. resp, isOk, msg, errMsg = GetCorrelationChartInfoDetailFromUniqueCode(chartInfo, key)
  119. case utils.CHART_SOURCE_LINE_EQUATION:
  120. resp, isOk, msg, errMsg = GetLineEquationChartInfoDetailFromUniqueCode(chartInfo, key)
  121. case utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY:
  122. resp, isOk, msg, errMsg = GetLineFeatureChartInfoDetailFromUniqueCode(chartInfo, key)
  123. case utils.CHART_SOURCE_CROSS_HEDGING:
  124. resp, isOk, msg, errMsg = GetCrossVarietyChartInfoDetailFromUniqueCode(chartInfo, key)
  125. case utils.CHART_SOURCE_BALANCE_EXCEL:
  126. resp, isOk, msg, errMsg = GetBalanceChartInfoDetailFromUniqueCode(chartInfo, key, this.Lang)
  127. if !isOk {
  128. br.Msg = msg
  129. br.ErrMsg = errMsg
  130. return
  131. }
  132. case utils.CHART_SOURCE_RANGE_ANALYSIS:
  133. resp, isOk, msg, errMsg = GetRangeAnalysisChartInfoDetailFromUniqueCode(chartInfo, key, this.Lang)
  134. if !isOk {
  135. br.Msg = msg
  136. br.ErrMsg = errMsg
  137. return
  138. }
  139. default:
  140. br.Msg = "错误的图表"
  141. br.ErrMsg = "错误的图表"
  142. return
  143. }
  144. if !isOk {
  145. br.Msg = msg
  146. br.ErrMsg = errMsg
  147. return
  148. }
  149. if isCollect {
  150. resp.IsCollect = isCollect
  151. }
  152. if conf[models.BusinessConfWatermarkChart] == "true" && conf[models.BusinessConfCompanyWatermark] != "" {
  153. resp.WaterMark = conf[models.BusinessConfCompanyWatermark]
  154. }
  155. br.Ret = 200
  156. br.Success = true
  157. br.Msg = "获取成功"
  158. br.Data = resp
  159. }
  160. // ChartInfoRefresh
  161. // @Title 图表刷新接口
  162. // @Description 图表刷新接口
  163. // @Param UniqueCode query string true "图表唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
  164. // @Success Ret=200 刷新成功
  165. // @router /refresh [get]
  166. func (this *ChartController) ChartInfoRefresh() {
  167. br := new(models.BaseResponse).Init()
  168. chartId := 0
  169. defer func() {
  170. // 添加日志
  171. if chartId > 0 {
  172. shareChartRefreshLogInfo := &models.ShareChartRefreshLog{
  173. Ip: this.Ctx.Input.IP(),
  174. ChartId: chartId,
  175. CreateTime: time.Now(),
  176. }
  177. models.AddShareChartRefreshLog(shareChartRefreshLogInfo)
  178. }
  179. this.Data["json"] = br
  180. this.ServeJSON()
  181. }()
  182. uniqueCode := this.GetString("UniqueCode")
  183. if uniqueCode == "" {
  184. br.Msg = "参数错误"
  185. br.ErrMsg = "参数错误,uniqueCode is empty"
  186. return
  187. }
  188. chartInfo, err := models.GetChartInfoByUniqueCode(uniqueCode)
  189. if err != nil {
  190. if err.Error() == utils.ErrNoRow() {
  191. br.Msg = "该图已被删除,请刷新页面"
  192. br.ErrMsg = "该图已被删除,请刷新页面,Err:" + err.Error()
  193. return
  194. }
  195. br.Msg = "获取失败"
  196. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  197. return
  198. }
  199. chartId = chartInfo.ChartInfoId
  200. switch chartInfo.Source {
  201. case utils.CHART_SOURCE_CROSS_HEDGING:
  202. var config request.ChartConfigReq
  203. err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &config)
  204. if err != nil {
  205. br.Msg = "解析跨品种分析配置失败"
  206. br.ErrMsg = "解析跨品种分析配置失败,Err:" + err.Error()
  207. return
  208. }
  209. // 获取关联的指标信息
  210. _, _, edbInfoIdList, tmpErr := cross_variety.GetXYEdbIdList(config.TagX, config.TagY, config.VarietyList)
  211. if tmpErr != nil {
  212. br.Msg = "刷新失败,获取指标信息失败"
  213. br.ErrMsg = "刷新失败,获取指标信息失败,Err:" + tmpErr.Error()
  214. return
  215. }
  216. err, _ = data.EdbInfoRefreshAllFromBase(edbInfoIdList, false)
  217. case utils.CHART_SOURCE_BALANCE_EXCEL:
  218. excelDetail, err := excel.GetExcelInfoByChartInfoId(chartInfo.ChartInfoId)
  219. if err != nil {
  220. br.Msg = "图表数据异常"
  221. br.ErrMsg = "未找到对应的表格" + err.Error()
  222. br.IsSendEmail = false
  223. return
  224. }
  225. err = refreshBalanceTable(excelDetail, this.Lang)
  226. if err != nil {
  227. br.Msg = "刷新失败"
  228. br.ErrMsg = "刷新失败,Err:" + err.Error()
  229. return
  230. }
  231. case utils.CHART_SOURCE_RANGE_ANALYSIS:
  232. //// 刷新相关性图表
  233. if _, e := range_analysis.ChartInfoRefresh(chartInfo.ChartInfoId, ""); e != nil {
  234. br.Msg = "刷新失败"
  235. br.ErrMsg = "刷新相关性图表失败, Err:" + e.Error()
  236. return
  237. }
  238. default:
  239. err = data.ChartInfoRefreshV2(chartInfo.ChartInfoId)
  240. }
  241. if err != nil {
  242. br.Msg = "刷新失败"
  243. br.ErrMsg = "刷新图表关联指标信息失败,Err:" + err.Error()
  244. return
  245. }
  246. //清除数据缓存
  247. key := utils.HZ_CHART_LIB_DETAIL + uniqueCode
  248. if utils.Re == nil {
  249. utils.Rc.Delete(key)
  250. }
  251. br.Ret = 200
  252. br.Success = true
  253. br.Msg = "刷新成功"
  254. }
  255. // MiniBookMark
  256. // @Title 小程序收藏/取消收藏通用接口
  257. // @Description 小程序收藏/取消收藏通用接口
  258. // @Param request body models.ChartCollectReq true "type json string"
  259. // @Success Ret=200 取消收藏成功
  260. // @router /mini/bookMark [post]
  261. func (this *ChartController) MiniBookMark() {
  262. br := new(models.BaseResponse).Init()
  263. defer func() {
  264. this.Data["json"] = br
  265. this.ServeJSON()
  266. }()
  267. var req requestDTO.ChartCollectReq
  268. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  269. br.Msg = "参数错误"
  270. br.ErrMsg = "参数错误,Err:" + err.Error()
  271. return
  272. }
  273. if req.UniqueCode == "" {
  274. br.Msg = "参数错误"
  275. br.ErrMsg = "参数错误,UniqueCode is empty"
  276. return
  277. }
  278. if req.Source == "" {
  279. br.Msg = "参数错误"
  280. br.ErrMsg = "参数错误,Source is empty"
  281. return
  282. }
  283. auth := this.Ctx.Request.Header.Get("Authorization")
  284. param := facade.BaseRequest{
  285. Auth: auth,
  286. UniqueCode: req.UniqueCode,
  287. }
  288. action, err := facade.FacadeClient.Deal(param).HandleAction(req.Action, facade.GetInstance(req.Source))
  289. if err != nil {
  290. br.Msg = action + "失败"
  291. br.ErrMsg = action + "失败,Err:" + err.Error()
  292. return
  293. }
  294. br.Ret = 200
  295. br.Success = true
  296. br.Msg = action + "成功"
  297. }
  298. // CollectCancel
  299. // @Title 东吴小程序图表取消收藏接口
  300. // @Description 东吴小程序图表取消收藏接口
  301. // @Param request body models.ChartDwCollectReq true "type json string"
  302. // @Success Ret=200 取消收藏成功
  303. // @router /dw/collectCancel [post]
  304. func (this *ChartController) CollectCancel() {
  305. br := new(models.BaseResponse).Init()
  306. defer func() {
  307. this.Data["json"] = br
  308. this.ServeJSON()
  309. }()
  310. var req models.ChartDwCollectReq
  311. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  312. br.Msg = "参数错误"
  313. br.ErrMsg = "参数错误,Err:" + err.Error()
  314. return
  315. }
  316. if req.UniqueCode == "" {
  317. br.Msg = "参数错误"
  318. br.ErrMsg = "参数错误,UniqueCode is empty"
  319. return
  320. }
  321. if req.Token == "" {
  322. br.Msg = "参数错误"
  323. br.ErrMsg = "参数错误,Token is empty"
  324. return
  325. }
  326. result, err := dwmini.MyChartCollectCancel(req.Token, req.UniqueCode)
  327. if err != nil {
  328. br.Msg = "取消收藏失败"
  329. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  330. return
  331. }
  332. if result.Ret != 200 {
  333. br.Msg = result.Msg
  334. br.ErrMsg = "取消收藏失败,Err:" + result.ErrMsg
  335. return
  336. }
  337. br.Ret = 200
  338. br.Success = true
  339. br.Msg = "取消收藏成功"
  340. }
  341. // Collect
  342. // @Title 东吴小程序图表收藏接口
  343. // @Description 东吴小程序图表收藏接口
  344. // @Param request body models.ChartDwCollectReq true "type json string"
  345. // @Success Ret=200 收藏成功
  346. // @router /dw/collect [post]
  347. func (this *ChartController) Collect() {
  348. br := new(models.BaseResponse).Init()
  349. defer func() {
  350. this.Data["json"] = br
  351. this.ServeJSON()
  352. }()
  353. var req models.ChartDwCollectReq
  354. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  355. br.Msg = "参数错误"
  356. br.ErrMsg = "参数错误,Err:" + err.Error()
  357. return
  358. }
  359. if req.UniqueCode == "" {
  360. br.Msg = "参数错误"
  361. br.ErrMsg = "参数错误,UniqueCode is empty"
  362. return
  363. }
  364. if req.Token == "" {
  365. br.Msg = "参数错误"
  366. br.ErrMsg = "参数错误,Token is empty"
  367. return
  368. }
  369. chartInfo, err := models.GetChartInfoByUniqueCode(req.UniqueCode)
  370. if err != nil {
  371. if err.Error() == utils.ErrNoRow() {
  372. br.Msg = "该图已被删除,请刷新页面"
  373. br.ErrMsg = "该图已被删除,请刷新页面,Err:" + err.Error()
  374. return
  375. }
  376. br.Msg = "获取失败"
  377. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  378. return
  379. }
  380. result, err := dwmini.MyChartCollect(req.Token, req.UniqueCode, chartInfo.ChartName, chartInfo.ChartImage, chartInfo.ChartInfoId)
  381. if err != nil {
  382. br.Msg = "收藏失败"
  383. br.ErrMsg = "收藏失败,Err:" + err.Error()
  384. return
  385. }
  386. if result.Ret != 200 {
  387. br.Msg = result.Msg
  388. br.ErrMsg = "收藏失败,Err:" + result.ErrMsg
  389. return
  390. }
  391. br.Ret = 200
  392. br.Success = true
  393. br.Msg = "收藏成功"
  394. }
  395. // 获取频度的英文版
  396. func GetFrequencyEn(frequency string) (frequencyEn string) {
  397. switch frequency {
  398. case "日度":
  399. frequencyEn = "day"
  400. return
  401. case "周度":
  402. frequencyEn = "week"
  403. return
  404. case "旬度":
  405. frequencyEn = "ten days"
  406. return
  407. case "月度":
  408. frequencyEn = "month"
  409. return
  410. case "季度":
  411. frequencyEn = "quarter"
  412. return
  413. case "年度":
  414. frequencyEn = "year"
  415. return
  416. }
  417. return
  418. }
  419. func GetLeadUnitEn(unit string) (unitEn string) {
  420. switch unit {
  421. case "天":
  422. unitEn = "day"
  423. return
  424. case "周":
  425. unitEn = "week"
  426. return
  427. case "月":
  428. unitEn = "month"
  429. return
  430. case "季":
  431. unitEn = "quarter"
  432. return
  433. case "年":
  434. unitEn = "year"
  435. return
  436. }
  437. return
  438. }
  439. // GetChartInfoDetailFromUniqueCode 根据编码获取图表详情
  440. func GetChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfo, key string) (resp *models.ChartInfoDetailResp, isOk bool, msg, errMsg string) {
  441. resp = new(models.ChartInfoDetailResp)
  442. // 获取主题样式
  443. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, chartInfo.Source, chartInfo.ChartType)
  444. if err != nil {
  445. msg = "获取失败"
  446. errMsg = "获取主题信息失败,Err:" + err.Error()
  447. return
  448. }
  449. chartInfo.ChartThemeStyle = chartTheme.Config
  450. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  451. chartInfoId := chartInfo.ChartInfoId
  452. dateType := chartInfo.DateType
  453. if dateType <= 0 {
  454. dateType = 3
  455. }
  456. startDate := chartInfo.StartDate
  457. endDate := chartInfo.EndDate
  458. startYear := chartInfo.StartYear
  459. calendar := chartInfo.Calendar
  460. chartType := chartInfo.ChartType
  461. if calendar == "" {
  462. calendar = "公历"
  463. }
  464. mappingList, err := models.GetChartEdbMappingList(chartInfoId)
  465. if err != nil {
  466. msg = "获取失败"
  467. errMsg = "获取图表,指标信息失败,Err:" + err.Error()
  468. return
  469. }
  470. var dateMax time.Time
  471. if dateType == utils.DateTypeNYears {
  472. for _, v := range mappingList {
  473. if v.LatestDate != "" {
  474. lastDateT, tErr := time.Parse(utils.FormatDate, v.LatestDate)
  475. if tErr != nil {
  476. msg = "获取失败"
  477. errMsg = "获取图表日期信息失败,Err:" + tErr.Error()
  478. return
  479. }
  480. if lastDateT.After(dateMax) {
  481. dateMax = lastDateT
  482. }
  483. }
  484. }
  485. }
  486. if chartInfo.DateType == utils.DateTypeNYears && chartInfo.ChartType == utils.CHART_TYPE_SEASON {
  487. // 季节性图表,要特殊处理起始日期, 最近N年
  488. dateMax = time.Date(dateMax.Year()+1, 1, 1, 0, 0, 0, 0, time.Local)
  489. }
  490. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, dateMax)
  491. extraConfigStr := chartInfo.ExtraConfig
  492. // 柱方图的一些配置
  493. var barConfig data_manage.BarChartInfoReq
  494. if chartInfo != nil && chartInfo.ChartType == 7 {
  495. if chartInfo.BarConfig == `` {
  496. msg = "柱方图未配置"
  497. errMsg = "柱方图未配置"
  498. return
  499. }
  500. err := json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
  501. if err != nil {
  502. msg = "柱方图配置异常"
  503. errMsg = "柱方图配置异常"
  504. return
  505. }
  506. extraConfigStr = chartInfo.BarConfig
  507. }
  508. edbList, xEdbIdValue, yDataList, dataResp, err, tmpErrMsg := data.GetChartEdbData(chartInfoId, chartType, calendar, startDate, endDate, mappingList, extraConfigStr, chartInfo.SeasonExtraConfig)
  509. if err != nil {
  510. msg = "获取失败"
  511. if tmpErrMsg != `` {
  512. msg = tmpErrMsg
  513. }
  514. errMsg = "获取图表,指标信息失败,Err:" + err.Error()
  515. return
  516. }
  517. // 面积图 面积堆积 数据处理
  518. if chartType == utils.CHART_TYPE_AREA {
  519. err, errMsg = fillAreaGraphData(extraConfigStr, edbList)
  520. if err != nil {
  521. msg = "获取失败"
  522. errMsg = "获取面积图数据失败,Err:" + err.Error()
  523. return
  524. }
  525. }
  526. for _, v := range edbList {
  527. // 指标别名
  528. if barConfig.EdbInfoIdList != nil && len(barConfig.EdbInfoIdList) > 0 {
  529. for _, reqEdb := range barConfig.EdbInfoIdList {
  530. if v.EdbInfoId == reqEdb.EdbInfoId {
  531. v.EdbAliasName = reqEdb.Name
  532. }
  533. }
  534. }
  535. }
  536. // 图表的指标来源
  537. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  538. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  539. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  540. // 单位
  541. if chartType == utils.CHART_TYPE_BAR && len(yDataList) > 0 {
  542. chartInfo.Unit = yDataList[0].Unit
  543. chartInfo.UnitEn = yDataList[0].UnitEn
  544. }
  545. resp.ChartInfo = chartInfo
  546. resp.EdbInfoList = edbList
  547. resp.XEdbIdValue = xEdbIdValue
  548. resp.YDataList = yDataList
  549. resp.DataResp = dataResp
  550. if utils.Re == nil {
  551. jsonData, _ := json.Marshal(resp)
  552. utils.Rc.Put(key, jsonData, 10*time.Minute)
  553. }
  554. isOk = true
  555. return
  556. }
  557. func fillAreaGraphData(extraConfigStr string, edbDataList []*models.ChartEdbInfoMapping) (err error, errMsg string) {
  558. var tmpConfig data_manage.AreaExtraConf
  559. if extraConfigStr != `` {
  560. err = json.Unmarshal([]byte(extraConfigStr), &tmpConfig)
  561. if err != nil {
  562. errMsg = "面积图配置异常"
  563. err = errors.New(errMsg)
  564. return
  565. }
  566. if tmpConfig.StandardEdbInfoId <= 0 {
  567. errMsg = "面积图配置异常"
  568. err = errors.New(errMsg)
  569. return
  570. }
  571. }
  572. if tmpConfig.IsHeap == 1 {
  573. standardIndexMap := make(map[string]*models.EdbDataList)
  574. var startDate, endDate string
  575. for _, v := range edbDataList {
  576. // 判断是否为基准指标
  577. if v.EdbInfoId == tmpConfig.StandardEdbInfoId {
  578. if dataList, ok := v.DataList.([]*models.EdbDataList); ok {
  579. startDate = dataList[0].DataTime
  580. endDate = dataList[len(dataList)-1].DataTime
  581. for _, dataObject := range dataList {
  582. standardIndexMap[dataObject.DataTime] = dataObject
  583. }
  584. }
  585. break
  586. }
  587. }
  588. strategy, err := area_graph.CreateStrategy(tmpConfig.NullDealWay)
  589. if err != nil {
  590. return err, "创建空值处理器失败"
  591. }
  592. err = strategy.Deal(tmpConfig, edbDataList, standardIndexMap, startDate, endDate)
  593. if err != nil {
  594. return err, err.Error()
  595. }
  596. }
  597. return nil, ""
  598. }