chart_common.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/controllers/data_manage/correlation"
  5. "eta_gn/eta_api/controllers/data_manage/cross_variety"
  6. "eta_gn/eta_api/controllers/data_manage/future_good"
  7. "eta_gn/eta_api/controllers/data_manage/line_equation"
  8. "eta_gn/eta_api/controllers/data_manage/line_feature"
  9. "eta_gn/eta_api/controllers/data_manage/range_analysis"
  10. "eta_gn/eta_api/models"
  11. "eta_gn/eta_api/models/data_manage"
  12. "eta_gn/eta_api/models/system"
  13. "eta_gn/eta_api/services/data"
  14. "eta_gn/eta_api/services/data/excel"
  15. "eta_gn/eta_api/utils"
  16. "fmt"
  17. "time"
  18. )
  19. // @router /chart_info/common/detail/from_unique_code [get]
  20. func (this *ChartInfoController) CommonChartInfoDetailFromUniqueCode() {
  21. br := new(models.BaseResponse).Init()
  22. defer func() {
  23. this.Data["json"] = br
  24. this.ServeJSON()
  25. }()
  26. sysUser := this.SysUser
  27. if sysUser == nil {
  28. br.Msg = "请登录"
  29. br.ErrMsg = "请登录,SysUser Is Empty"
  30. br.Ret = 408
  31. return
  32. }
  33. uniqueCode := this.GetString("UniqueCode")
  34. if uniqueCode == "" {
  35. br.Msg = "参数错误"
  36. br.ErrMsg = "参数错误,uniqueCode is empty"
  37. return
  38. }
  39. isCache, _ := this.GetBool("IsCache")
  40. status := true
  41. chartInfo, err := data_manage.GetChartInfoViewByUniqueCode(uniqueCode)
  42. if err != nil {
  43. if utils.IsErrNoRow(err) {
  44. status = false
  45. } else {
  46. br.Msg = "获取失败"
  47. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  48. return
  49. }
  50. }
  51. if chartInfo == nil {
  52. status = false
  53. }
  54. if !status {
  55. resp := new(data_manage.ChartInfoDetailFromUniqueCodeResp)
  56. endInfoList := make([]*data_manage.ChartEdbInfoMapping, 0)
  57. resp.EdbInfoList = endInfoList
  58. resp.ChartInfo = chartInfo
  59. resp.Status = false
  60. br.Data = resp
  61. br.Ret = 200
  62. br.Success = true
  63. br.Msg = "获取成功"
  64. return
  65. }
  66. switch chartInfo.Source {
  67. case utils.CHART_SOURCE_DEFAULT:
  68. resp, isOk, msg, errMsg := GetChartInfoDetailFromUniqueCode(chartInfo, isCache, sysUser)
  69. if !isOk {
  70. br.Msg = msg
  71. br.ErrMsg = errMsg
  72. return
  73. }
  74. br.Ret = 200
  75. br.Success = true
  76. br.Msg = "获取成功"
  77. br.Data = resp
  78. case utils.CHART_SOURCE_FUTURE_GOOD:
  79. resp, isOk, msg, errMsg := future_good.GetChartInfoDetailFromUniqueCode(chartInfo, isCache, sysUser)
  80. if !isOk {
  81. br.Msg = msg
  82. br.ErrMsg = errMsg
  83. return
  84. }
  85. br.Ret = 200
  86. br.Success = true
  87. br.Msg = "获取成功"
  88. br.Data = resp
  89. case utils.CHART_SOURCE_FUTURE_GOOD_PROFIT:
  90. resp, isOk, msg, errMsg := future_good.GetFutureGoodProfitChartInfoDetailFromUniqueCode(chartInfo, isCache, sysUser)
  91. if !isOk {
  92. br.Msg = msg
  93. br.ErrMsg = errMsg
  94. return
  95. }
  96. br.Ret = 200
  97. br.Success = true
  98. br.Msg = "获取成功"
  99. br.Data = resp
  100. case utils.CHART_SOURCE_CORRELATION, utils.CHART_SOURCE_ROLLING_CORRELATION:
  101. resp, isOk, msg, errMsg := correlation.GetChartInfoDetailFromUniqueCode(chartInfo, isCache, sysUser)
  102. if !isOk {
  103. br.Msg = msg
  104. br.ErrMsg = errMsg
  105. return
  106. }
  107. br.Ret = 200
  108. br.Success = true
  109. br.Msg = "获取成功"
  110. br.Data = resp
  111. case utils.CHART_SOURCE_LINE_EQUATION:
  112. resp, isOk, msg, errMsg := line_equation.GetChartInfoDetailFromUniqueCode(chartInfo, isCache, sysUser)
  113. if !isOk {
  114. br.Msg = msg
  115. br.ErrMsg = errMsg
  116. return
  117. }
  118. br.Ret = 200
  119. br.Success = true
  120. br.Msg = "获取成功"
  121. br.Data = resp
  122. case utils.CHART_SOURCE_LINE_FEATURE_STANDARD_DEVIATION, utils.CHART_SOURCE_LINE_FEATURE_PERCENTILE, utils.CHART_SOURCE_LINE_FEATURE_FREQUENCY:
  123. resp, isOk, msg, errMsg := line_feature.GetChartInfoDetailFromUniqueCode(chartInfo, isCache, sysUser)
  124. if !isOk {
  125. br.Msg = msg
  126. br.ErrMsg = errMsg
  127. return
  128. }
  129. br.Ret = 200
  130. br.Success = true
  131. br.Msg = "获取成功"
  132. br.Data = resp
  133. case utils.CHART_SOURCE_CROSS_HEDGING:
  134. resp, isOk, msg, errMsg := cross_variety.GetChartInfoDetailFromUniqueCode(chartInfo, isCache, sysUser)
  135. if !isOk {
  136. br.Msg = msg
  137. br.ErrMsg = errMsg
  138. return
  139. }
  140. br.Ret = 200
  141. br.Success = true
  142. br.Msg = "获取成功"
  143. br.Data = resp
  144. case utils.CHART_SOURCE_BALANCE_EXCEL:
  145. resp, isOk, msg, errMsg := getBalanceChartInfoDetailFromUniqueCode(chartInfo, isCache, sysUser)
  146. if !isOk {
  147. br.Msg = msg
  148. br.ErrMsg = errMsg
  149. return
  150. }
  151. br.Ret = 200
  152. br.Success = true
  153. br.Msg = "获取成功"
  154. br.Data = resp
  155. case utils.CHART_SOURCE_RANGE_ANALYSIS:
  156. resp, isOk, msg, errMsg := range_analysis.GetChartInfoDetailFromUniqueCode(chartInfo, isCache, sysUser)
  157. if !isOk {
  158. br.Msg = msg
  159. br.ErrMsg = errMsg
  160. return
  161. }
  162. br.Ret = 200
  163. br.Success = true
  164. br.Msg = "获取成功"
  165. br.Data = resp
  166. default:
  167. br.Msg = "错误的图表"
  168. br.ErrMsg = "错误的图表"
  169. return
  170. }
  171. }
  172. func getBalanceChartInfoDetailFromUniqueCode(chartInfo *data_manage.ChartInfoView, isCache bool, sysUser *system.Admin) (resp *data_manage.ChartInfoDetailFromUniqueCodeResp, isOk bool, msg, errMsg string) {
  173. resp = new(data_manage.ChartInfoDetailFromUniqueCodeResp)
  174. resp, isOk, msg, errMsg = data.CheckBalanceChartCacheAndPermission(chartInfo, isCache, sysUser)
  175. if isOk {
  176. return
  177. }
  178. msg = `获取失败`
  179. mappingListTmp, dataListMap, err, errMsg := excel.GetBalanceExcelChartSingle(chartInfo.ChartInfoId, 0, "")
  180. if err != nil {
  181. errMsg = "获取失败"
  182. err = fmt.Errorf(" 获取图表,指标信息失败 Err:%s", err.Error())
  183. return
  184. }
  185. var chartInfoResp *data_manage.ChartInfoDetailResp
  186. chartInfoResp, err, errMsg = data.GetBalanceExcelChartDetail(chartInfo, mappingListTmp, sysUser, dataListMap)
  187. if err != nil {
  188. msg = "查询图表详情失败"
  189. errMsg = "查询图表详情失败,Err:" + err.Error()
  190. return
  191. }
  192. resp = &data_manage.ChartInfoDetailFromUniqueCodeResp{
  193. ChartInfo: chartInfoResp.ChartInfo,
  194. Status: true,
  195. EdbInfoList: chartInfoResp.EdbInfoList,
  196. XEdbIdValue: chartInfoResp.XEdbIdValue,
  197. YDataList: chartInfoResp.YDataList,
  198. XDataList: chartInfoResp.XDataList,
  199. BarChartInfo: chartInfoResp.BarChartInfo,
  200. CorrelationChartInfo: chartInfoResp.CorrelationChartInfo,
  201. DataResp: chartInfoResp.DataResp,
  202. }
  203. if utils.Re == nil {
  204. cacheData, _ := json.Marshal(resp)
  205. key := data.GetChartInfoDataKey(chartInfo.ChartInfoId)
  206. utils.Rc.Put(key, cacheData, 2*time.Hour)
  207. }
  208. isOk = true
  209. return
  210. }