chart_info.go 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048
  1. package future_good
  2. import (
  3. "errors"
  4. "eta_gn/eta_api/models/data_manage"
  5. future_good2 "eta_gn/eta_api/models/data_manage/future_good"
  6. "eta_gn/eta_api/services/alarm_msg"
  7. "eta_gn/eta_api/services/data"
  8. "eta_gn/eta_api/utils"
  9. "fmt"
  10. "github.com/shopspring/decimal"
  11. "sort"
  12. "strconv"
  13. "time"
  14. )
  15. // GetChartEdbData 获取图表的指标数据
  16. func GetChartEdbData(chartInfoId int, startDate, endDate string, baseEdbInfoMapping *data_manage.ChartEdbInfoMapping, edbInfoMappingList []*data_manage.ChartEdbInfoMapping, futureGoodEdbInfoMapping *data_manage.ChartEdbInfoMapping, barChartInfoConf data_manage.FutureGoodBarChartInfoReq, needData bool) (barConfigEdbInfoIdList []data_manage.BarChartInfoEdbItemReq, edbList []*data_manage.ChartEdbInfoMapping, xEdbIdValue []int, xDataList []data_manage.XData, yDataList []data_manage.YData, err error) {
  17. edbList = make([]*data_manage.ChartEdbInfoMapping, 0)
  18. barChartInfoDateList := barChartInfoConf.DateList
  19. if futureGoodEdbInfoMapping == nil {
  20. err = errors.New("商品指标未选取")
  21. return
  22. }
  23. if len(edbInfoMappingList) == 0 {
  24. err = errors.New("ETA指标未选取")
  25. return
  26. }
  27. // 指标对应的所有数据
  28. edbDataListMap := make(map[int][]*data_manage.EdbDataList)
  29. // todo item
  30. //item := new(data_manage.ChartEdbInfoMapping)
  31. if futureGoodEdbInfoMapping.Unit == `无` {
  32. futureGoodEdbInfoMapping.Unit = ``
  33. }
  34. if chartInfoId <= 0 {
  35. for k, edbInfoMapping := range edbInfoMappingList {
  36. edbInfoMapping.FrequencyEn = data.GetFrequencyEn(edbInfoMapping.Frequency)
  37. if edbInfoMapping.Unit == `无` {
  38. edbInfoMapping.Unit = ``
  39. }
  40. edbInfoMapping.IsAxis = 1
  41. edbInfoMapping.LeadValue = 0
  42. edbInfoMapping.LeadUnit = ""
  43. edbInfoMapping.ChartEdbMappingId = 0
  44. edbInfoMapping.ChartInfoId = 0
  45. edbInfoMapping.IsOrder = false
  46. edbInfoMapping.EdbInfoType = 1
  47. edbInfoMapping.ChartStyle = ""
  48. edbInfoMapping.ChartColor = ""
  49. edbInfoMapping.ChartWidth = 0
  50. edbInfoMappingList[k] = edbInfoMapping
  51. }
  52. futureGoodEdbInfoMapping.IsAxis = 1
  53. futureGoodEdbInfoMapping.LeadValue = 0
  54. futureGoodEdbInfoMapping.LeadUnit = ""
  55. futureGoodEdbInfoMapping.ChartEdbMappingId = 0
  56. futureGoodEdbInfoMapping.ChartInfoId = 0
  57. futureGoodEdbInfoMapping.IsOrder = false
  58. futureGoodEdbInfoMapping.EdbInfoType = 1
  59. futureGoodEdbInfoMapping.ChartStyle = ""
  60. futureGoodEdbInfoMapping.ChartColor = ""
  61. futureGoodEdbInfoMapping.ChartWidth = 0
  62. } else {
  63. for k, edbInfoMapping := range edbInfoMappingList {
  64. edbInfoMapping.FrequencyEn = data.GetFrequencyEn(edbInfoMapping.Frequency)
  65. if edbInfoMapping.Unit == `无` {
  66. edbInfoMapping.Unit = ``
  67. }
  68. edbInfoMapping.LeadUnitEn = data.GetLeadUnitEn(edbInfoMapping.LeadUnit)
  69. edbInfoMappingList[k] = edbInfoMapping
  70. }
  71. futureGoodEdbInfoMapping.LeadUnitEn = data.GetLeadUnitEn(futureGoodEdbInfoMapping.LeadUnit)
  72. }
  73. //查询横轴配置项
  74. xDataItemMap := make(map[int]data_manage.XData)
  75. for k, v := range barChartInfoConf.XDataList {
  76. xDataItemMap[k] = v
  77. }
  78. // 普通的指标数据
  79. {
  80. edbList = edbInfoMappingList
  81. for k, edbInfoMapping := range edbInfoMappingList {
  82. tmp := data_manage.BarChartInfoEdbItemReq{
  83. EdbInfoId: edbInfoMapping.EdbInfoId,
  84. Name: edbInfoMapping.EdbName,
  85. NameEn: edbInfoMapping.EdbNameEn,
  86. Source: edbInfoMapping.Source,
  87. }
  88. // 如果有配置,则用配置中的指标名称替换
  89. xItem, ok := xDataItemMap[k]
  90. if ok && xItem.Name != "" {
  91. tmp.Name = xItem.Name
  92. tmp.NameEn = xItem.NameEn
  93. tmp.IsHide = xItem.IsHide
  94. }
  95. barConfigEdbInfoIdList = append(barConfigEdbInfoIdList, tmp)
  96. }
  97. }
  98. // 获取主力合约和最新日期
  99. var zlFutureGoodEdbInfo *future_good2.FutureGoodEdbInfo
  100. var latestDate string // 最新日期是这个
  101. var regionType string // 交易所来源:“国内”,“海外”
  102. var futureGoodEdbType int
  103. {
  104. // 寻找主力合约
  105. zlFutureGoodEdbInfo, err = future_good2.GetFutureGoodEdbInfo(futureGoodEdbInfoMapping.EdbInfoId)
  106. if err != nil {
  107. err = fmt.Errorf("查不到期货指标,GetFutureGoodEdbInfo err: %v", err)
  108. return
  109. }
  110. regionType = zlFutureGoodEdbInfo.RegionType
  111. futureGoodEdbType = zlFutureGoodEdbInfo.FutureGoodEdbType
  112. // 如果当前合约配置的 "画图时,日期来源的指标id" 并不是自己的话,那么就去查找对应配置的合约
  113. if zlFutureGoodEdbInfo.DateSourceId != zlFutureGoodEdbInfo.FutureGoodEdbInfoId {
  114. sourceDateFutureGoodEdbInfo, tmpErr := future_good2.GetFutureGoodEdbInfo(zlFutureGoodEdbInfo.DateSourceId)
  115. if tmpErr != nil {
  116. err = fmt.Errorf("获取期货指标 %d 的日期来源的指标信息失败,错误:%s", zlFutureGoodEdbInfo.DateSourceId, tmpErr.Error())
  117. return
  118. }
  119. latestDate = sourceDateFutureGoodEdbInfo.EndDate // 最新日期是这个
  120. } else {
  121. latestDate = zlFutureGoodEdbInfo.EndDate // 最新日期是这个
  122. }
  123. if latestDate == `0000-00-00` {
  124. err = errors.New("日期异常")
  125. return
  126. }
  127. }
  128. // 获取期货指标以及期货数据
  129. tmpFutureGoodEdbInfoList, err := future_good2.GetFutureGoodEdbInfoListByParentId(futureGoodEdbInfoMapping.EdbInfoId)
  130. if err != nil {
  131. return
  132. }
  133. latestDateTime, _ := time.ParseInLocation(utils.FormatDate, latestDate, time.Local)
  134. _, futureGoodEdbInfoList, err := getFutureGoodEdbInfoList(latestDateTime, tmpFutureGoodEdbInfoList, barChartInfoDateList)
  135. if err != nil {
  136. err = fmt.Errorf("获取期货指标列表失败,getFutureGoodEdbInfoList 错误:%s", err.Error())
  137. return
  138. }
  139. futureGoodMappingList := make([]*data_manage.ChartEdbInfoMapping, 0)
  140. for k, v := range futureGoodEdbInfoList {
  141. newMappingInfo := &data_manage.ChartEdbInfoMapping{
  142. EdbInfoId: v.FutureGoodEdbInfoId,
  143. SourceName: v.Exchange,
  144. Source: 0,
  145. EdbCode: v.FutureGoodEdbCode,
  146. EdbName: v.FutureGoodEdbName,
  147. EdbAliasName: v.FutureGoodEdbName,
  148. EdbNameEn: v.FutureGoodEdbNameEn,
  149. EdbType: baseEdbInfoMapping.EdbType,
  150. Frequency: baseEdbInfoMapping.Frequency,
  151. FrequencyEn: baseEdbInfoMapping.FrequencyEn,
  152. Unit: baseEdbInfoMapping.Unit,
  153. UnitEn: baseEdbInfoMapping.UnitEn,
  154. StartDate: v.StartDate,
  155. EndDate: v.EndDate,
  156. ModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
  157. ChartEdbMappingId: v.FutureGoodEdbInfoId,
  158. ChartInfoId: baseEdbInfoMapping.ChartInfoId,
  159. MaxData: v.MaxValue,
  160. MinData: v.MinValue,
  161. IsOrder: baseEdbInfoMapping.IsOrder,
  162. IsAxis: baseEdbInfoMapping.IsAxis,
  163. EdbInfoType: baseEdbInfoMapping.EdbInfoType,
  164. EdbInfoCategoryType: baseEdbInfoMapping.EdbInfoCategoryType,
  165. LeadValue: baseEdbInfoMapping.LeadValue,
  166. LeadUnit: baseEdbInfoMapping.LeadUnit,
  167. LeadUnitEn: baseEdbInfoMapping.LeadUnitEn,
  168. ChartStyle: baseEdbInfoMapping.ChartStyle,
  169. ChartColor: baseEdbInfoMapping.ChartColor,
  170. PredictChartColor: baseEdbInfoMapping.PredictChartColor,
  171. ChartWidth: baseEdbInfoMapping.ChartWidth,
  172. ChartType: baseEdbInfoMapping.ChartType,
  173. LatestDate: v.LatestDate.Format(utils.FormatDateTime),
  174. LatestValue: v.LatestValue,
  175. UniqueCode: futureGoodEdbInfoMapping.UniqueCode + strconv.Itoa(k),
  176. MinValue: v.MinValue,
  177. MaxValue: v.MaxValue,
  178. DataList: nil,
  179. IsNullData: false,
  180. }
  181. futureGoodMappingList = append(futureGoodMappingList, newMappingInfo)
  182. tmp := data_manage.BarChartInfoEdbItemReq{
  183. EdbInfoId: newMappingInfo.EdbInfoId,
  184. Name: fmt.Sprint("M+", v.Month),
  185. NameEn: fmt.Sprint("M+", v.Month),
  186. Source: newMappingInfo.Source,
  187. }
  188. // 判断如果有配置,需要替换为配置内容
  189. xItem, ok := xDataItemMap[k]
  190. if ok && xItem.Name != "" {
  191. tmp.Name = xItem.Name
  192. tmp.NameEn = xItem.NameEn
  193. tmp.IsHide = xItem.IsHide
  194. }
  195. barConfigEdbInfoIdList = append(barConfigEdbInfoIdList, tmp)
  196. }
  197. if regionType == `海外` {
  198. zlFutureGoodEdbMapping := &data_manage.ChartEdbInfoMapping{
  199. EdbInfoId: zlFutureGoodEdbInfo.FutureGoodEdbInfoId,
  200. SourceName: zlFutureGoodEdbInfo.Exchange,
  201. Source: 0,
  202. EdbCode: zlFutureGoodEdbInfo.FutureGoodEdbCode,
  203. EdbName: zlFutureGoodEdbInfo.FutureGoodEdbName,
  204. EdbAliasName: zlFutureGoodEdbInfo.FutureGoodEdbName,
  205. EdbNameEn: zlFutureGoodEdbInfo.FutureGoodEdbNameEn,
  206. EdbType: baseEdbInfoMapping.EdbType,
  207. Frequency: baseEdbInfoMapping.Frequency,
  208. FrequencyEn: baseEdbInfoMapping.FrequencyEn,
  209. Unit: baseEdbInfoMapping.Unit,
  210. UnitEn: baseEdbInfoMapping.UnitEn,
  211. StartDate: zlFutureGoodEdbInfo.StartDate,
  212. EndDate: zlFutureGoodEdbInfo.EndDate,
  213. ModifyTime: zlFutureGoodEdbInfo.ModifyTime.Format(utils.FormatDateTime),
  214. ChartEdbMappingId: zlFutureGoodEdbInfo.FutureGoodEdbInfoId,
  215. ChartInfoId: baseEdbInfoMapping.ChartInfoId,
  216. MaxData: zlFutureGoodEdbInfo.MaxValue,
  217. MinData: zlFutureGoodEdbInfo.MinValue,
  218. IsOrder: baseEdbInfoMapping.IsOrder,
  219. IsAxis: baseEdbInfoMapping.IsAxis,
  220. EdbInfoType: baseEdbInfoMapping.EdbInfoType,
  221. EdbInfoCategoryType: baseEdbInfoMapping.EdbInfoCategoryType,
  222. LeadValue: baseEdbInfoMapping.LeadValue,
  223. LeadUnit: baseEdbInfoMapping.LeadUnit,
  224. LeadUnitEn: baseEdbInfoMapping.LeadUnitEn,
  225. ChartStyle: baseEdbInfoMapping.ChartStyle,
  226. ChartColor: baseEdbInfoMapping.ChartColor,
  227. PredictChartColor: baseEdbInfoMapping.PredictChartColor,
  228. ChartWidth: baseEdbInfoMapping.ChartWidth,
  229. ChartType: baseEdbInfoMapping.ChartType,
  230. LatestDate: zlFutureGoodEdbInfo.LatestDate.Format(utils.FormatDateTime),
  231. LatestValue: zlFutureGoodEdbInfo.LatestValue,
  232. UniqueCode: futureGoodEdbInfoMapping.UniqueCode + strconv.Itoa(0),
  233. MinValue: zlFutureGoodEdbInfo.MinValue,
  234. MaxValue: zlFutureGoodEdbInfo.MaxValue,
  235. DataList: nil,
  236. IsNullData: false,
  237. }
  238. edbList = append(edbList, zlFutureGoodEdbMapping)
  239. edbList = append(edbList, futureGoodMappingList...)
  240. } else {
  241. edbList = append(edbList, futureGoodMappingList...)
  242. }
  243. if !needData {
  244. return
  245. }
  246. // 获取数据
  247. // 现货数据
  248. for _, edbInfoMapping := range edbInfoMappingList {
  249. dataList := make([]*data_manage.EdbDataList, 0)
  250. dataList, err = data_manage.GetEdbDataList(edbInfoMapping.Source, edbInfoMapping.SubSource, edbInfoMapping.EdbInfoId, startDate, endDate)
  251. if err != nil {
  252. return
  253. }
  254. edbDataListMap[edbInfoMapping.EdbInfoId] = dataList
  255. // todo item
  256. //item.DataList = dataList
  257. }
  258. futureEdbInfoIds := make([]int, 0)
  259. for _, v := range futureGoodMappingList {
  260. futureEdbInfoIds = append(futureEdbInfoIds, v.EdbInfoId)
  261. }
  262. tmpDataListMap := make(map[int][]*future_good2.FutureGoodEdbData)
  263. if len(futureEdbInfoIds) > 0 {
  264. // 期货数据
  265. tmpDataList, tmpErr := future_good2.GetFutureGoodEdbDataListByIdsAndDate(futureEdbInfoIds, startDate, endDate)
  266. if tmpErr != nil {
  267. err = tmpErr
  268. return
  269. }
  270. for _, v := range tmpDataList {
  271. if _, ok := tmpDataListMap[v.FutureGoodEdbInfoId]; !ok {
  272. tmpDataListMap[v.FutureGoodEdbInfoId] = make([]*future_good2.FutureGoodEdbData, 0)
  273. }
  274. tmpDataListMap[v.FutureGoodEdbInfoId] = append(tmpDataListMap[v.FutureGoodEdbInfoId], v)
  275. }
  276. }
  277. for _, v := range futureGoodMappingList {
  278. dataList := make([]*data_manage.EdbDataList, 0)
  279. tmpDataList, ok := tmpDataListMap[v.EdbInfoId]
  280. if !ok {
  281. /*err = fmt.Errorf("期货数据不存在 FutureGoodEdbInfoId: %d", v.EdbInfoId)
  282. return*/
  283. continue
  284. }
  285. for _, tmpData := range tmpDataList {
  286. dataList = append(dataList, &data_manage.EdbDataList{
  287. EdbDataId: tmpData.FutureGoodEdbDataId,
  288. EdbInfoId: tmpData.FutureGoodEdbInfoId,
  289. DataTime: tmpData.DataTime.Format(utils.FormatDate),
  290. DataTimestamp: tmpData.DataTimestamp,
  291. Value: tmpData.Close,
  292. })
  293. }
  294. edbDataListMap[v.EdbInfoId] = dataList
  295. v.DataList = dataList
  296. }
  297. xEdbIdValue, yDataList, err = BarChartData(baseEdbInfoMapping, edbInfoMappingList, futureGoodEdbInfoList, edbDataListMap, barChartInfoDateList, regionType, baseEdbInfoMapping.EndDate)
  298. if len(barChartInfoConf.XDataList) > 0 {
  299. xDataList = barChartInfoConf.XDataList
  300. } else {
  301. for _, v := range edbInfoMappingList {
  302. xDataList = append(xDataList, data_manage.XData{
  303. Name: v.EdbName,
  304. NameEn: v.EdbNameEn,
  305. IsHide: 0,
  306. })
  307. }
  308. }
  309. futureGoodEdbInfoIndexMap := make(map[int]int)
  310. for index, v := range futureGoodEdbInfoList {
  311. futureGoodEdbInfoIndexMap[v.FutureGoodEdbInfoId] = index
  312. }
  313. nMap := make(map[int]int)
  314. maxIndex := 0 // 最大x轴的下标
  315. for k, tmpYData := range yDataList {
  316. yDataMap := tmpYData.EdbValMap
  317. edbInfoIdList := make([]int, 0)
  318. noDataEdbInfoIdList := make([]int, 0)
  319. valueList := make([]float64, 0)
  320. noDataEdbIdMap := make(map[int]int)
  321. // 所有的N值
  322. for _, n := range tmpYData.M {
  323. nMap[n] = n
  324. }
  325. // 基础指标
  326. baseEdbIds := make([]int, 0)
  327. for _, tmp := range edbInfoMappingList {
  328. edbInfoIdList = append(edbInfoIdList, tmp.EdbInfoId)
  329. baseEdbIds = append(baseEdbIds, tmp.EdbInfoId)
  330. tmpVal, ok := yDataMap[tmp.EdbInfoId]
  331. valueList = append(valueList, tmpVal)
  332. if !ok || tmpVal == 0 {
  333. noDataEdbInfoIdList = append(noDataEdbInfoIdList, tmp.EdbInfoId)
  334. noDataEdbIdMap[tmp.EdbInfoId] = tmp.EdbInfoId
  335. }
  336. }
  337. for _, futureGoodEdbInfo := range futureGoodEdbInfoList {
  338. tmpEdbInfId := futureGoodEdbInfo.FutureGoodEdbInfoId
  339. edbInfoIdList = append(edbInfoIdList, tmpEdbInfId)
  340. tmpVal, ok := yDataMap[tmpEdbInfId]
  341. valueList = append(valueList, tmpVal)
  342. if !ok || tmpVal == 0 {
  343. noDataEdbInfoIdList = append(noDataEdbInfoIdList, tmpEdbInfId)
  344. noDataEdbIdMap[tmpEdbInfId] = tmpEdbInfId
  345. }
  346. }
  347. //tmpYData.Value = valueList
  348. tmpYData.NoDataEdbList = noDataEdbInfoIdList
  349. yDataList[k] = tmpYData
  350. lenEdbId := len(edbInfoIdList)
  351. tmpMaxIndex := lenEdbId - 1 // 当前数据的最大x轴的下标
  352. for i := lenEdbId - 1; i >= 0; i-- {
  353. // 如果没有在无数据的指标列表中找到,那么就找到了最大x轴的下标
  354. if _, ok := noDataEdbIdMap[edbInfoIdList[i]]; !ok || utils.InArrayByInt(baseEdbIds, edbInfoIdList[i]) { //以往的逻辑是碰到第一个无数据的期货指标,那后续的月份都是无数据的,因此需要特殊处理,改成多个现货指标之后需要排除无值的现货指标
  355. // 如果最大x轴的下标 小于 当前下标,那么就重新赋值,
  356. if maxIndex < i-1 {
  357. maxIndex = i - 1
  358. }
  359. break
  360. }
  361. tmpMaxIndex = i - 1
  362. }
  363. // 如果最大x轴的下标 小于 当前下标,那么就重新赋值
  364. if maxIndex < tmpMaxIndex {
  365. maxIndex = tmpMaxIndex
  366. }
  367. }
  368. // 找出所有的N值,并进行正序排列
  369. nList := make([]int, 0)
  370. for _, n := range nMap {
  371. nList = append(nList, n)
  372. }
  373. sort.Slice(nList, func(i, j int) bool {
  374. return nList[i] < nList[j]
  375. })
  376. for k, v := range yDataList {
  377. if len(v.XEdbInfoIdList) >= maxIndex+1 {
  378. yDataList[k].XEdbInfoIdList = v.XEdbInfoIdList[0 : maxIndex+1]
  379. }
  380. if len(v.Value) >= maxIndex+1 {
  381. yDataList[k].Value = v.Value[0 : maxIndex+1]
  382. }
  383. }
  384. baseEdbLen := len(edbInfoMappingList)
  385. tmpXDataList, newYDataList, err := handleResultData(regionType, futureGoodEdbType, baseEdbLen, yDataList, futureGoodEdbInfoList, maxIndex)
  386. if err != nil {
  387. return
  388. }
  389. if len(barChartInfoConf.XDataList) == 0 {
  390. xDataList = append(xDataList, tmpXDataList...)
  391. }
  392. yDataList = newYDataList
  393. return
  394. }
  395. // BarChartData 获取数据
  396. func BarChartData(baseEdbInfoMapping *data_manage.ChartEdbInfoMapping, edbInfoMappingList []*data_manage.ChartEdbInfoMapping, futureGoodMappingList []*future_good2.FutureGoodEdbInfo, edbDataListMap map[int][]*data_manage.EdbDataList, barChartInfoDateList []data_manage.BarChartInfoDateReq, regionType, latestDate string) (edbIdList []int, yDataList []data_manage.YData, err error) {
  397. // 指标数据数组(10086:{"2022-12-02":100.01,"2022-12-01":102.3})
  398. // 现货指标数据map
  399. baseEdbDataMap := make(map[int]map[string]float64)
  400. edbInfoMappingMap := make(map[int]struct{})
  401. for _, v := range edbInfoMappingList {
  402. edbInfoMappingMap[v.EdbInfoId] = struct{}{}
  403. }
  404. for edbInfoId, edbDataList := range edbDataListMap {
  405. if _, ok1 := edbInfoMappingMap[edbInfoId]; ok1 {
  406. edbDateData := make(map[string]float64)
  407. for _, edbData := range edbDataList {
  408. edbDateData[edbData.DataTime] = edbData.Value
  409. }
  410. baseEdbDataMap[edbInfoId] = edbDateData
  411. }
  412. }
  413. edbDataMap := make(map[int]map[string]float64)
  414. for edbInfoId, edbDataList := range edbDataListMap {
  415. if _, ok := edbInfoMappingMap[edbInfoId]; ok {
  416. continue
  417. }
  418. edbDateData := make(map[string]float64)
  419. for _, edbData := range edbDataList {
  420. edbDateData[edbData.DataTime] = edbData.Value
  421. }
  422. edbDataMap[edbInfoId] = edbDateData
  423. }
  424. // edbIdList 指标展示顺序;x轴的指标顺序
  425. edbIdList = make([]int, 0)
  426. for _, v := range edbInfoMappingList {
  427. edbIdList = append(edbIdList, v.EdbInfoId)
  428. }
  429. for _, v := range futureGoodMappingList {
  430. edbIdList = append(edbIdList, v.FutureGoodEdbInfoId)
  431. }
  432. latestDateTime, _ := time.ParseInLocation(utils.FormatDate, latestDate, time.Local)
  433. yDataList = make([]data_manage.YData, 0) //y轴的数据列表
  434. for _, barChartInfoDate := range barChartInfoDateList {
  435. yDataMap := make(map[int]float64)
  436. var maxDate time.Time
  437. var findDateTime time.Time
  438. switch barChartInfoDate.Type {
  439. case 1: //最新值
  440. findDateTime = latestDateTime
  441. case 2: //近期几天
  442. findDateTime = latestDateTime.AddDate(0, 0, -barChartInfoDate.Value)
  443. case 3: // 固定日期
  444. //寻找固定日期的数据
  445. tmpFindDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, barChartInfoDate.Date, time.Local)
  446. if tmpErr != nil {
  447. err = tmpErr
  448. return
  449. }
  450. findDateTime = tmpFindDateTime
  451. default:
  452. err = errors.New(fmt.Sprint("日期类型异常,Type:", barChartInfoDate.Type))
  453. return
  454. }
  455. if findDateTime.IsZero() {
  456. err = errors.New("错误的日期")
  457. return
  458. }
  459. findDataList := make([]float64, 0) // 当前日期的数据值
  460. noDataIdList := make([]int, 0) // 没有数据的指标id
  461. noDataIdMap := make(map[int]int, 0) // 没有数据的指标map
  462. xEdbInfoIdList := make([]int, 0) // 当前数据的指标id列表
  463. // 先找到基准日期
  464. var realDateTime time.Time
  465. realDateTime, findDataValue, isFind, tmpErr := GetNeedDateData(findDateTime, edbDataListMap[baseEdbInfoMapping.EdbInfoId], baseEdbDataMap[baseEdbInfoMapping.EdbInfoId], edbDataMap)
  466. if tmpErr != nil {
  467. err = tmpErr
  468. return
  469. }
  470. // 处理其余现货指标
  471. for _, v := range edbInfoMappingList {
  472. if v.EdbInfoId == baseEdbInfoMapping.EdbInfoId {
  473. findDataList = append(findDataList, findDataValue)
  474. yDataMap[baseEdbInfoMapping.EdbInfoId] = findDataValue
  475. if isFind {
  476. maxDate = realDateTime
  477. } else {
  478. noDataIdList = append(noDataIdList, baseEdbInfoMapping.EdbInfoId)
  479. noDataIdMap[baseEdbInfoMapping.EdbInfoId] = baseEdbInfoMapping.EdbInfoId
  480. }
  481. xEdbInfoIdList = append(xEdbInfoIdList, v.EdbInfoId)
  482. continue
  483. }
  484. findDataValueTmp, isFindTmp := baseEdbDataMap[v.EdbInfoId][realDateTime.Format(utils.FormatDate)]
  485. findDataList = append(findDataList, findDataValueTmp)
  486. yDataMap[v.EdbInfoId] = findDataValueTmp
  487. if !isFindTmp {
  488. noDataIdList = append(noDataIdList, v.EdbInfoId)
  489. noDataIdMap[v.EdbInfoId] = v.EdbInfoId
  490. }
  491. xEdbInfoIdList = append(xEdbInfoIdList, v.EdbInfoId)
  492. }
  493. // 用实际日期的月份作为基准,往前推12个月(2024-5-13 16:26:43修改)
  494. currMonth := realDateTime.Month() // 当前月份
  495. currYear := realDateTime.Year() // 当前年份
  496. mList := make([]int, 0) // 间隔月份
  497. indexList := make([]int, 0)
  498. if regionType == `国内` {
  499. for i := currMonth + 1; i <= 12; i++ {
  500. indexList = append(indexList, int(i))
  501. mList = append(mList, int(i-currMonth))
  502. }
  503. for i := 1; i < int(currMonth); i++ {
  504. indexList = append(indexList, i)
  505. mList = append(mList, 12+i-int(currMonth))
  506. }
  507. } else {
  508. for i, v := range futureGoodMappingList {
  509. if v.FutureGoodEdbType == 2 {
  510. if i == 0 {
  511. continue
  512. }
  513. indexList = append(indexList, i)
  514. mList = append(mList, v.Month)
  515. } else {
  516. if v.Year > currYear || (v.Year == currYear && v.Month > int(currMonth)) {
  517. indexList = append(indexList, i)
  518. mList = append(mList, (v.Year-currYear)*12+v.Month-int(currMonth))
  519. }
  520. }
  521. }
  522. }
  523. for _, i := range indexList {
  524. futureGoodMapping := futureGoodMappingList[i] // 当前的期货指标
  525. tmpRealDateTime := realDateTime // 实际现货的日期
  526. tmpFindDataValue, tmpIsFind := edbDataMap[futureGoodMapping.FutureGoodEdbInfoId][tmpRealDateTime.Format(utils.FormatDate)]
  527. yDataMap[futureGoodMapping.FutureGoodEdbInfoId] = tmpFindDataValue
  528. findDataList = append(findDataList, tmpFindDataValue)
  529. if tmpIsFind {
  530. if maxDate.IsZero() || maxDate.Before(tmpRealDateTime) {
  531. maxDate = tmpRealDateTime
  532. }
  533. } else {
  534. noDataIdList = append(noDataIdList, futureGoodMapping.FutureGoodEdbInfoId)
  535. noDataIdMap[futureGoodMapping.FutureGoodEdbInfoId] = futureGoodMapping.FutureGoodEdbInfoId
  536. }
  537. // 当前期货合约的指标
  538. xEdbInfoIdList = append(xEdbInfoIdList, futureGoodMapping.FutureGoodEdbInfoId)
  539. }
  540. yName := barChartInfoDate.Name
  541. yNameEn := barChartInfoDate.Name
  542. if yName == `` {
  543. if barChartInfoDate.Type == 2 {
  544. yName = strconv.Itoa(barChartInfoDate.Value) + "天前"
  545. if barChartInfoDate.Value == 1 {
  546. yNameEn = strconv.Itoa(barChartInfoDate.Value) + "day ago"
  547. } else {
  548. yNameEn = strconv.Itoa(barChartInfoDate.Value) + " days ago"
  549. }
  550. } else {
  551. yName = maxDate.Format(utils.FormatDate)
  552. yNameEn = maxDate.Format(utils.FormatDate)
  553. }
  554. }
  555. yDate := "0000-00-00"
  556. if !maxDate.IsZero() {
  557. yDate = maxDate.Format(utils.FormatDate)
  558. }
  559. // 数据处理,将没有数据的下标,赋值平均值
  560. {
  561. hasDataIndexList := make([]int, 0)
  562. for dataK, edbInfoId := range xEdbInfoIdList {
  563. if _, ok := noDataIdMap[edbInfoId]; !ok { // 如果是没有数据的指标id
  564. hasDataIndexList = append(hasDataIndexList, dataK)
  565. }
  566. }
  567. lenHasDataIndex := len(hasDataIndexList)
  568. if lenHasDataIndex > 0 {
  569. for lenHasDataI := 1; lenHasDataI < lenHasDataIndex; lenHasDataI++ {
  570. perK := hasDataIndexList[lenHasDataI-1] //上一个有数据的指标下标
  571. currK := hasDataIndexList[lenHasDataI] //当前有数据的指标下标
  572. preVal := findDataList[perK] //上一个有数据的坐标的值
  573. currVal := findDataList[currK] //当前有数据的指标的值
  574. // 环差值
  575. hcValDeci := decimal.NewFromFloat(currVal).Sub(decimal.NewFromFloat(preVal)).Div(decimal.NewFromInt(int64(currK - perK)))
  576. var tmpI int64
  577. // 将两个中间的数据做平均值补全
  578. for hcI := perK + 1; hcI < currK; hcI++ {
  579. tmpI++
  580. findDataList[hcI], _ = decimal.NewFromFloat(preVal).Add(hcValDeci.Mul(decimal.NewFromInt(tmpI))).RoundCeil(4).Float64()
  581. }
  582. }
  583. }
  584. }
  585. yDataList = append(yDataList, data_manage.YData{
  586. Date: yDate,
  587. ConfigDate: realDateTime,
  588. Value: findDataList,
  589. NoDataEdbList: noDataIdList,
  590. XEdbInfoIdList: xEdbInfoIdList,
  591. Color: barChartInfoDate.Color,
  592. Name: yName,
  593. NameEn: yNameEn,
  594. EdbValMap: yDataMap,
  595. M: mList,
  596. })
  597. }
  598. return
  599. }
  600. // handleResultData 处理成最终的结果数据
  601. func handleResultData(regionType string, futureGoodEdbType, baseEdbLen int, yDataList []data_manage.YData, futureGoodEdbInfoList []*future_good2.FutureGoodEdbInfo, maxIndex int) (xDataList []data_manage.XData, newYDataList []data_manage.YData, err error) {
  602. xDataList = make([]data_manage.XData, 0)
  603. newYDataList = yDataList
  604. if regionType == `国内` {
  605. for i := 1; i < 12; i++ {
  606. if i > maxIndex {
  607. break
  608. }
  609. xDataList = append(xDataList, data_manage.XData{
  610. Name: fmt.Sprint("M+", i),
  611. NameEn: fmt.Sprint("M+", i),
  612. })
  613. }
  614. return
  615. }
  616. futureGoodEdbInfoMap := make(map[int]*future_good2.FutureGoodEdbInfo)
  617. for _, v := range futureGoodEdbInfoList {
  618. futureGoodEdbInfoMap[v.FutureGoodEdbInfoId] = v
  619. }
  620. if futureGoodEdbType == 2 { // FutureGoodEdbType int `description:"指标类型,1:年月是固定的合约;2:只有M+N期的合约,未固定年月"`
  621. nList := []int{3, 15, 27}
  622. for _, i := range nList {
  623. xDataList = append(xDataList, data_manage.XData{
  624. Name: fmt.Sprint("M+", i),
  625. NameEn: fmt.Sprint("M+", i),
  626. })
  627. }
  628. for yIndex, yData := range yDataList {
  629. newYDataList[yIndex].XEdbInfoIdList = []int{}
  630. newYDataList[yIndex].Value = []float64{}
  631. tmpNList := nList
  632. //当前的主力合约
  633. newYDataList[yIndex].XEdbInfoIdList = append(newYDataList[yIndex].XEdbInfoIdList, yData.XEdbInfoIdList[0:baseEdbLen]...)
  634. newYDataList[yIndex].Value = append(newYDataList[yIndex].Value, yData.Value[0:baseEdbLen]...)
  635. xEdbInfoIdList := yData.XEdbInfoIdList[baseEdbLen:]
  636. valIndex := baseEdbLen
  637. needNum := 0
  638. for _, n := range tmpNList {
  639. if len(xEdbInfoIdList) > 0 {
  640. edbInfoId := xEdbInfoIdList[0]
  641. futureGoodEdbInfo, ok := futureGoodEdbInfoMap[edbInfoId]
  642. if !ok {
  643. err = errors.New("找不到指标")
  644. return
  645. }
  646. // 当前距离最早的日期相差的N数
  647. if futureGoodEdbInfo.Month == n {
  648. if needNum > 0 {
  649. currVal := yData.Value[valIndex]
  650. preVal := yData.Value[valIndex-1]
  651. hcValDeci := decimal.NewFromFloat(currVal).Sub(decimal.NewFromFloat(preVal)).Div(decimal.NewFromInt(int64(needNum + 1)))
  652. for tmpNum := 0; tmpNum < needNum; tmpNum++ {
  653. newYDataList[yIndex].XEdbInfoIdList = append(newYDataList[yIndex].XEdbInfoIdList, 0)
  654. // 赋值平均值
  655. tmpVal, _ := decimal.NewFromFloat(preVal).Add(hcValDeci.Mul(decimal.NewFromInt(int64(tmpNum + 1)))).RoundCeil(4).Float64()
  656. newYDataList[yIndex].Value = append(newYDataList[yIndex].Value, tmpVal)
  657. }
  658. }
  659. newYDataList[yIndex].XEdbInfoIdList = append(newYDataList[yIndex].XEdbInfoIdList, edbInfoId)
  660. newYDataList[yIndex].Value = append(newYDataList[yIndex].Value, yData.Value[valIndex])
  661. valIndex++
  662. needNum = 0
  663. if len(xEdbInfoIdList) > 0 {
  664. xEdbInfoIdList = xEdbInfoIdList[1:]
  665. }
  666. } else {
  667. needNum++
  668. }
  669. }
  670. }
  671. }
  672. maxI := 0
  673. for _, yData := range newYDataList {
  674. lenEdb := len(yData.XEdbInfoIdList)
  675. for i := 0; i < lenEdb; i++ {
  676. if yData.XEdbInfoIdList[i] != 0 && !utils.InArrayByInt(yData.NoDataEdbList, yData.XEdbInfoIdList[i]) {
  677. if maxI < i {
  678. maxI = i
  679. }
  680. }
  681. }
  682. }
  683. xDataList = xDataList[0:maxI]
  684. for yIndex, yData := range newYDataList {
  685. if len(yData.XEdbInfoIdList) > maxI+1 {
  686. newYDataList[yIndex].XEdbInfoIdList = yData.XEdbInfoIdList[0 : maxI+1]
  687. }
  688. if len(yData.Value) > maxI+1 {
  689. newYDataList[yIndex].Value = yData.Value[0 : maxI+1]
  690. }
  691. }
  692. return
  693. }
  694. nMap := make(map[int]int)
  695. for _, v := range yDataList {
  696. findDateTime := v.ConfigDate
  697. currMonth := findDateTime.Month() // 当前月份
  698. currYear := findDateTime.Year() // 当前年份
  699. //v.XEdbInfoIdList
  700. for edbInfoIndex, edbInfoId := range v.XEdbInfoIdList {
  701. // 现货指标不处理
  702. if edbInfoIndex <= baseEdbLen-1 {
  703. continue
  704. }
  705. futureGoodEdbInfo, ok := futureGoodEdbInfoMap[edbInfoId]
  706. if !ok {
  707. err = errors.New("找不到指标")
  708. return
  709. }
  710. n := (futureGoodEdbInfo.Year-currYear)*12 + futureGoodEdbInfo.Month - int(currMonth)
  711. nMap[n] = n
  712. }
  713. }
  714. // 找出所有的N值,并进行正序排列
  715. nList := make([]int, 0)
  716. for _, n := range nMap {
  717. nList = append(nList, n)
  718. }
  719. sort.Slice(nList, func(i, j int) bool {
  720. return nList[i] < nList[j]
  721. })
  722. //prevMonth := 1
  723. for _, n := range nList {
  724. xDataList = append(xDataList, data_manage.XData{
  725. Name: fmt.Sprint("M+", n),
  726. NameEn: fmt.Sprint("M+", n),
  727. })
  728. }
  729. for yIndex, yData := range yDataList {
  730. newYDataList[yIndex].XEdbInfoIdList = []int{}
  731. newYDataList[yIndex].Value = []float64{}
  732. tmpNList := nList
  733. //当前的主力合约
  734. newYDataList[yIndex].XEdbInfoIdList = append(newYDataList[yIndex].XEdbInfoIdList, yData.XEdbInfoIdList[0:baseEdbLen]...)
  735. newYDataList[yIndex].Value = append(newYDataList[yIndex].Value, yData.Value[0:baseEdbLen]...)
  736. xEdbInfoIdList := yData.XEdbInfoIdList[baseEdbLen:]
  737. currDataTime := yData.ConfigDate
  738. valIndex := baseEdbLen
  739. needNum := 0
  740. for _, n := range tmpNList {
  741. if len(xEdbInfoIdList) > 0 {
  742. edbInfoId := xEdbInfoIdList[0]
  743. futureGoodEdbInfo, ok := futureGoodEdbInfoMap[edbInfoId]
  744. if !ok {
  745. err = errors.New("找不到指标")
  746. return
  747. }
  748. // 当前距离最早的日期相差的N数
  749. divMonth := (futureGoodEdbInfo.Year-currDataTime.Year())*12 + (futureGoodEdbInfo.Month - int(currDataTime.Month()))
  750. if divMonth == n {
  751. if needNum > 0 {
  752. currVal := yData.Value[valIndex]
  753. preVal := yData.Value[valIndex-1]
  754. hcValDeci := decimal.NewFromFloat(currVal).Sub(decimal.NewFromFloat(preVal)).Div(decimal.NewFromInt(int64(needNum + 1)))
  755. for tmpNum := 0; tmpNum < needNum; tmpNum++ {
  756. newYDataList[yIndex].XEdbInfoIdList = append(newYDataList[yIndex].XEdbInfoIdList, 0)
  757. // 赋值平均值
  758. tmpVal, _ := decimal.NewFromFloat(preVal).Add(hcValDeci.Mul(decimal.NewFromInt(int64(tmpNum + 1)))).RoundCeil(4).Float64()
  759. newYDataList[yIndex].Value = append(newYDataList[yIndex].Value, tmpVal)
  760. }
  761. }
  762. newYDataList[yIndex].XEdbInfoIdList = append(newYDataList[yIndex].XEdbInfoIdList, edbInfoId)
  763. newYDataList[yIndex].Value = append(newYDataList[yIndex].Value, yData.Value[valIndex])
  764. valIndex++
  765. needNum = 0
  766. if len(xEdbInfoIdList) > 0 {
  767. xEdbInfoIdList = xEdbInfoIdList[1:]
  768. }
  769. } else {
  770. needNum++
  771. }
  772. }
  773. }
  774. }
  775. maxI := 0
  776. for _, yData := range newYDataList {
  777. lenEdb := len(yData.XEdbInfoIdList)
  778. for i := 0; i < lenEdb; i++ {
  779. if yData.XEdbInfoIdList[i] != 0 && !utils.InArrayByInt(yData.NoDataEdbList, yData.XEdbInfoIdList[i]) {
  780. if maxI < i {
  781. maxI = i
  782. }
  783. }
  784. }
  785. }
  786. xDataList = xDataList[0:maxI]
  787. for yIndex, yData := range newYDataList {
  788. if len(yData.XEdbInfoIdList) > maxI+1 {
  789. newYDataList[yIndex].XEdbInfoIdList = yData.XEdbInfoIdList[0 : maxI+1]
  790. }
  791. if len(yData.Value) > maxI+1 {
  792. newYDataList[yIndex].Value = yData.Value[0 : maxI+1]
  793. }
  794. }
  795. return
  796. }
  797. // getFutureGoodEdbInfoList 获取适用的指标列表
  798. func getFutureGoodEdbInfoList(latestDateTime time.Time, tmpFutureGoodEdbInfoList []*future_good2.FutureGoodEdbInfo, barChartInfoDateList []data_manage.BarChartInfoDateReq) (earliestDateTime time.Time, futureGoodEdbInfoList []*future_good2.FutureGoodEdbInfo, err error) {
  799. maxM := 36 //最大36期合约
  800. futureGoodEdbInfoList = make([]*future_good2.FutureGoodEdbInfo, 0)
  801. earliestDateTime = latestDateTime // 数据的最早日期,目的是为了找出最早的合约
  802. for _, barChartInfoDate := range barChartInfoDateList {
  803. var findDateTime time.Time
  804. switch barChartInfoDate.Type {
  805. case 1: //最新值
  806. findDateTime = latestDateTime
  807. case 2: //近期几天
  808. findDateTime = latestDateTime.AddDate(0, 0, -barChartInfoDate.Value)
  809. case 3: // 固定日期
  810. //寻找固定日期的数据
  811. tmpFindDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, barChartInfoDate.Date, time.Local)
  812. if tmpErr != nil {
  813. err = tmpErr
  814. return
  815. }
  816. findDateTime = tmpFindDateTime
  817. default:
  818. err = errors.New(fmt.Sprint("日期类型异常,Type:", barChartInfoDate.Type))
  819. return
  820. }
  821. if findDateTime.IsZero() {
  822. err = errors.New("错误的日期")
  823. return
  824. }
  825. if findDateTime.Before(earliestDateTime) {
  826. earliestDateTime = findDateTime
  827. }
  828. }
  829. for _, v := range tmpFutureGoodEdbInfoList {
  830. if v.RegionType == `国内` {
  831. futureGoodEdbInfoList = append(futureGoodEdbInfoList, v)
  832. continue
  833. }
  834. //海外的连续日期,目前
  835. if v.FutureGoodEdbType == 2 {
  836. if v.Month <= maxM {
  837. futureGoodEdbInfoList = append(futureGoodEdbInfoList, v)
  838. }
  839. continue
  840. }
  841. if v.Year < earliestDateTime.Year() {
  842. continue
  843. }
  844. // 小于等于当前年,那么就肯定是ok的
  845. if v.Year <= earliestDateTime.Year() {
  846. futureGoodEdbInfoList = append(futureGoodEdbInfoList, v)
  847. continue
  848. }
  849. // 如果(当前年-最新日期的年份) * 12个月 + (当前月-最新日期的月份) 小于总月份
  850. if (v.Year-earliestDateTime.Year())*12+(v.Month-int(earliestDateTime.Month())) <= maxM {
  851. futureGoodEdbInfoList = append(futureGoodEdbInfoList, v)
  852. continue
  853. }
  854. }
  855. return
  856. }
  857. // GetNeedDateData 获取合约内需要的日期数据
  858. func GetNeedDateData(needDateTime time.Time, dataList []*data_manage.EdbDataList, edbDataMap map[string]float64, allEdbDataMap map[int]map[string]float64) (findDateTime time.Time, findDataValue float64, isFind bool, err error) {
  859. //dataList := edbDataListMap[edbInfoId] //指标的所有数据值
  860. if len(dataList) <= 0 {
  861. // 没有数据的指标id
  862. return
  863. }
  864. //最早的日期
  865. minDateTime, err := time.ParseInLocation(utils.FormatDate, dataList[0].DataTime, time.Local)
  866. if err != nil {
  867. return
  868. }
  869. // 该日期存在数据的期货指标的最小数量,目前是现货和期货各1个,总共2个
  870. maxCount := 1
  871. for tmpDateTime := needDateTime; tmpDateTime.After(minDateTime) || tmpDateTime.Equal(minDateTime); tmpDateTime = tmpDateTime.AddDate(0, 0, -1) {
  872. tmpDate := tmpDateTime.Format(utils.FormatDate)
  873. tmpValue, ok := edbDataMap[tmpDate]
  874. if !ok {
  875. continue
  876. }
  877. // 该日期存在数据的指标数量
  878. count := 0
  879. for _, currEdbDataMap := range allEdbDataMap {
  880. _, tmpIsFind := currEdbDataMap[tmpDate]
  881. if tmpIsFind {
  882. count++
  883. if count >= maxCount {
  884. continue
  885. }
  886. }
  887. }
  888. // 该日期存在数据的期货指标数量小于2个,那么要继续往前找
  889. if count < maxCount {
  890. continue
  891. }
  892. //如果能找到数据,那么就返回
  893. // 数据为0,也直接返回,做无值处理
  894. if tmpValue == 0 {
  895. return
  896. }
  897. findDateTime, _ = time.ParseInLocation(utils.FormatDate, tmpDate, time.Local)
  898. findDataValue = tmpValue
  899. isFind = true
  900. return
  901. }
  902. return
  903. }
  904. // FutureGoodChartInfoRefresh
  905. // @author Roc
  906. // @datetime 2023-2-2 18:44:46
  907. // @description 商品价格曲线图表刷新
  908. func FutureGoodChartInfoRefresh(chartInfoId int) (err error) {
  909. var errMsg string
  910. defer func() {
  911. if err != nil {
  912. go alarm_msg.SendAlarmMsg("ChartInfoRefresh:"+errMsg, 3)
  913. fmt.Println("ChartInfoRefresh Err:" + errMsg)
  914. }
  915. }()
  916. edbInfoMappingList, err := data_manage.GetEtaEdbChartEdbMappingList(chartInfoId)
  917. if err != nil {
  918. errMsg = "获取需要刷新的ETA指标失败:Err:" + err.Error()
  919. return
  920. }
  921. edbInfoIds := make([]int, 0)
  922. for _, edbInfoMapping := range edbInfoMappingList {
  923. edbInfoIds = append(edbInfoIds, edbInfoMapping.EdbInfoId)
  924. }
  925. // 获取期货指标
  926. futureGoodEdbInfoMapping, err := data_manage.GetFutureGoodEdbChartEdbMapping(chartInfoId)
  927. if err != nil {
  928. errMsg = "获取需要刷新的商品期货指标失败:Err:" + err.Error()
  929. return
  930. }
  931. // 获取期货指标以及期货数据
  932. futureGoodEdbInfoList, err := future_good2.GetFutureGoodEdbInfoListByParentId(futureGoodEdbInfoMapping.EdbInfoId)
  933. if err != nil {
  934. return
  935. }
  936. // 批量刷新ETA指标
  937. err, _ = data.EdbInfoRefreshAllFromBaseV3(edbInfoIds, false, true, false)
  938. if err != nil {
  939. return
  940. }
  941. // 批量刷新期货指标
  942. err = FutureGoodEdbInfoRefreshAllFromBase(futureGoodEdbInfoList, false)
  943. if err != nil {
  944. return
  945. }
  946. return
  947. }