chart_common.go 8.1 KB

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