chart_common.go 6.6 KB

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