chart_extra_config.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. package data
  2. import (
  3. "errors"
  4. "eta_gn/eta_chart_lib/models"
  5. "eta_gn/eta_chart_lib/models/data_manage"
  6. "eta_gn/eta_chart_lib/utils"
  7. "fmt"
  8. "sort"
  9. "strconv"
  10. "time"
  11. )
  12. func GetChartSectionCombineData(chartInfo *models.ChartInfo, mappingList []*models.ChartEdbInfoMapping, edbDataListMap map[int][]*models.EdbDataList, extraConfig models.ChartSectionAllExtraConf) (edbIdList []int, dataListResp models.ChartSectionCombineDataResp, err error) {
  13. edbDataMap := make(map[int]map[string]float64)
  14. for edbInfoId, edbDataList := range edbDataListMap {
  15. edbDateData := make(map[string]float64)
  16. for _, edbData := range edbDataList {
  17. edbDateData[edbData.DataTime] = edbData.Value
  18. }
  19. edbDataMap[edbInfoId] = edbDateData
  20. }
  21. edbIdList = make([]int, 0)
  22. edbMappingMap := make(map[int]*models.ChartEdbInfoMapping)
  23. for _, v := range mappingList {
  24. edbIdList = append(edbIdList, v.EdbInfoId)
  25. edbMappingMap[v.EdbInfoId] = v
  26. }
  27. dateConfListMap := make(map[string]*models.ChartSectionDateConfItem)
  28. dateConfEdbIds := make([]int, 0)
  29. for _, v := range extraConfig.DateConfList {
  30. if v.EdbInfoId > 0 {
  31. dateConfEdbIds = append(dateConfEdbIds, v.EdbInfoId)
  32. }
  33. dateConfListMap[v.DateConfName] = v
  34. }
  35. baseSeries := new(models.ChartSectionSeriesItem) //y轴的系列
  36. var firstUnit, leftUnit, rightUnit, right2Unit *models.XData
  37. var (
  38. LeftMin float64
  39. LeftMax float64
  40. RightMin float64
  41. RightMax float64
  42. Right2Min float64
  43. Right2Max float64
  44. )
  45. seriesDataListMap := make(map[string][]float64)
  46. seriesNoDataIndexMap := make(map[string][]int)
  47. for _, seriesItem := range extraConfig.SeriesList {
  48. var maxDate time.Time
  49. var minVal, maxVal float64
  50. noDataEdbIndex := make([]int, 0)
  51. dataList := make([]float64, len(seriesItem.EdbInfoList))
  52. for index, edbConf := range seriesItem.EdbInfoList {
  53. edbInfoId := edbConf.EdbInfoId //X轴的指标
  54. edbMappingInfo, ok := edbMappingMap[edbInfoId]
  55. if !ok {
  56. continue
  57. }
  58. seriesItem.EdbInfoList[index].EdbName = edbMappingInfo.EdbName
  59. seriesItem.EdbInfoList[index].EdbNameEn = edbMappingInfo.EdbNameEn
  60. seriesItem.EdbInfoList[index].EdbInfoType = edbMappingInfo.EdbInfoCategoryType
  61. seriesItem.EdbInfoList[index].Unit = edbMappingInfo.Unit
  62. seriesItem.EdbInfoList[index].UnitEn = edbMappingInfo.UnitEn
  63. if index == 0 {
  64. firstUnit = &models.XData{
  65. Name: edbMappingInfo.Unit,
  66. NameEn: edbMappingInfo.UnitEn,
  67. }
  68. }
  69. edbDataList, ok3 := edbDataListMap[edbInfoId]
  70. if !ok3 {
  71. err = fmt.Errorf("指标%d的日期数据不存在", edbInfoId)
  72. return
  73. }
  74. var findDate string
  75. if edbConf.DateConfType == 0 {
  76. if edbInfoId == 0 {
  77. err = fmt.Errorf("请选择指标")
  78. return
  79. }
  80. findDate, err = GetChartSectionSeriesDateByDateChange(edbInfoId, edbDataList, edbConf.DateConf.DateChange, edbConf.DateConf.MoveForward)
  81. if err != nil {
  82. err = fmt.Errorf("指标%d的日期变换处理失败", edbInfoId)
  83. return
  84. }
  85. } else {
  86. dateConfItem, ok1 := dateConfListMap[edbConf.DateConfName]
  87. if !ok1 {
  88. err = fmt.Errorf("引用日期配置不存在")
  89. return
  90. }
  91. edbDataListTmp := make([]*models.EdbDataList, 0)
  92. if dateConfItem.DateType == 0 {
  93. if dateConfItem.EdbInfoId > 0 {
  94. edbDataListTmp, ok1 = edbDataListMap[dateConfItem.EdbInfoId]
  95. if !ok1 {
  96. err = fmt.Errorf("指标%d的日期数据不存在", dateConfItem.EdbInfoId)
  97. return
  98. }
  99. findDate, err = GetChartSectionSeriesDateByDateChange(dateConfItem.EdbInfoId, edbDataListTmp, dateConfItem.DateChange, dateConfItem.MoveForward)
  100. if err != nil {
  101. err = fmt.Errorf("指标%d的日期变换处理失败", dateConfItem.EdbInfoId)
  102. return
  103. }
  104. } else {
  105. err = fmt.Errorf("请选择指标")
  106. return
  107. }
  108. } else if dateConfItem.DateType == 1 {
  109. findDate, err = GetChartSectionSeriesDateByDateChange(dateConfItem.EdbInfoId, edbDataListTmp, dateConfItem.DateChange, dateConfItem.MoveForward)
  110. if err != nil {
  111. err = fmt.Errorf("指标%d的日期变换处理失败", dateConfItem.EdbInfoId)
  112. return
  113. }
  114. } else if dateConfItem.DateType == 2 {
  115. if dateConfItem.StaticDate == "" {
  116. err = fmt.Errorf("请输入固定日期")
  117. return
  118. }
  119. findDate = dateConfItem.StaticDate
  120. }
  121. }
  122. findDateTime, _ := time.ParseInLocation(utils.FormatDate, findDate, time.Local)
  123. if maxDate.IsZero() {
  124. maxDate = findDateTime
  125. } else {
  126. if findDateTime.After(maxDate) {
  127. maxDate = findDateTime
  128. }
  129. }
  130. if tmpValue, ok := edbDataMap[edbInfoId][findDate]; ok {
  131. dataList[index] = tmpValue
  132. if index == 0 {
  133. minVal = tmpValue
  134. maxVal = tmpValue
  135. } else {
  136. if tmpValue < minVal {
  137. minVal = tmpValue
  138. }
  139. if tmpValue > maxVal {
  140. maxVal = tmpValue
  141. }
  142. }
  143. } else {
  144. dataList[index] = 0
  145. noDataEdbIndex = append(noDataEdbIndex, index)
  146. continue
  147. }
  148. }
  149. seriesDataListMap[seriesItem.SeriesName] = dataList
  150. seriesNoDataIndexMap[seriesItem.SeriesName] = noDataEdbIndex
  151. seriesItem.DataList = dataList
  152. seriesItem.MinData = minVal
  153. seriesItem.MaxData = maxVal
  154. seriesItem.NoDataEdbIndex = noDataEdbIndex
  155. if extraConfig.BaseChartSeriesName == seriesItem.SeriesName {
  156. baseSeries = seriesItem
  157. }
  158. if seriesItem.IsAxis == 1 && leftUnit == nil { //左轴,右轴
  159. leftUnit = firstUnit
  160. } else if seriesItem.IsAxis == 0 && rightUnit == nil {
  161. rightUnit = firstUnit
  162. } else if seriesItem.IsAxis == 2 && right2Unit == nil {
  163. right2Unit = firstUnit
  164. }
  165. var minData, maxData float64
  166. for _, d := range seriesItem.DataList {
  167. if minData > d {
  168. minData = d
  169. }
  170. if maxData < d {
  171. maxData = d
  172. }
  173. }
  174. if seriesItem.IsAxis == 1 {
  175. if LeftMin > minData {
  176. LeftMin = minData
  177. }
  178. if LeftMax < maxData {
  179. LeftMax = maxData
  180. }
  181. } else if seriesItem.IsAxis == 0 {
  182. if RightMin > minData {
  183. RightMin = minData
  184. }
  185. if RightMax < maxData {
  186. RightMax = maxData
  187. }
  188. } else {
  189. if Right2Min > minData {
  190. Right2Min = minData
  191. }
  192. if Right2Max < maxData {
  193. Right2Max = maxData
  194. }
  195. }
  196. }
  197. if baseSeries == nil {
  198. err = fmt.Errorf("基准系列不存在")
  199. return
  200. }
  201. defaultIndexXDataList := make([]int, 0) //默认排序时的横轴
  202. defaultXDataMap := make(map[int]models.XData) //默认排序时的横轴单位
  203. for index, item := range baseSeries.EdbInfoList {
  204. if index == 0 {
  205. firstUnit = &models.XData{
  206. Name: item.Unit,
  207. NameEn: item.UnitEn,
  208. }
  209. }
  210. tmp := models.XData{
  211. Name: item.EdbName,
  212. NameEn: item.EdbNameEn,
  213. }
  214. defaultXDataMap[index] = tmp
  215. defaultIndexXDataList = append(defaultIndexXDataList, index)
  216. }
  217. if extraConfig.SortType > 0 {
  218. newSeriesDataListMap, newSeriesNoDataIndexMap, newIndexXDataList := SortChartSeriesDataSet(baseSeries.SeriesName, baseSeries.DataList, baseSeries.NoDataEdbIndex, seriesDataListMap, seriesNoDataIndexMap, extraConfig.SortType)
  219. for k, item := range extraConfig.SeriesList {
  220. dataList, ok := newSeriesDataListMap[item.SeriesName]
  221. if ok {
  222. extraConfig.SeriesList[k].DataList = dataList
  223. }
  224. noIndex, ok := newSeriesNoDataIndexMap[item.SeriesName]
  225. if ok {
  226. extraConfig.SeriesList[k].NoDataEdbIndex = noIndex
  227. }
  228. }
  229. defaultIndexXDataList = newIndexXDataList
  230. }
  231. xDataList := make([]models.XData, 0)
  232. for index, itemIndex := range defaultIndexXDataList {
  233. nameItem, ok := defaultXDataMap[itemIndex]
  234. if !ok {
  235. err = fmt.Errorf("单位不存在")
  236. return
  237. }
  238. if len(extraConfig.XDataList) > index {
  239. newItem := extraConfig.XDataList[index]
  240. if newItem.Name != "" {
  241. nameItem = newItem
  242. }
  243. }
  244. xDataList = append(xDataList, nameItem)
  245. }
  246. dataListResp.XDataList = xDataList
  247. unitList := new(models.ChartSectionCombineUnit)
  248. if baseSeries.IsAxis == 1 { //左轴,右轴
  249. leftUnit = firstUnit
  250. } else if baseSeries.IsAxis == 2 {
  251. rightUnit = firstUnit
  252. } else {
  253. right2Unit = firstUnit
  254. }
  255. if leftUnit != nil {
  256. unitList.LeftName = leftUnit.Name
  257. unitList.LeftNameEn = leftUnit.NameEn
  258. }
  259. if rightUnit != nil {
  260. unitList.RightName = rightUnit.Name
  261. unitList.RightNameEn = rightUnit.NameEn
  262. }
  263. if right2Unit != nil {
  264. unitList.RightTwoName = right2Unit.Name
  265. unitList.RightTwoNameEn = right2Unit.NameEn
  266. }
  267. if extraConfig.UnitList.LeftName != "" {
  268. unitList.LeftName = extraConfig.UnitList.LeftName
  269. unitList.LeftNameEn = extraConfig.UnitList.LeftNameEn
  270. }
  271. if extraConfig.UnitList.RightName != "" {
  272. unitList.RightName = extraConfig.UnitList.RightName
  273. unitList.RightNameEn = extraConfig.UnitList.RightNameEn
  274. }
  275. if extraConfig.UnitList.RightTwoName != "" {
  276. unitList.RightTwoName = extraConfig.UnitList.RightTwoName
  277. unitList.RightTwoNameEn = extraConfig.UnitList.RightTwoNameEn
  278. }
  279. if chartInfo != nil && chartInfo.MinMaxSave == 1 {
  280. dataListResp.LeftMin = chartInfo.LeftMin
  281. dataListResp.LeftMax = chartInfo.LeftMax
  282. dataListResp.RightMin = chartInfo.RightMin
  283. dataListResp.RightMax = chartInfo.RightMax
  284. dataListResp.Right2Min = chartInfo.Right2Min
  285. dataListResp.Right2Max = chartInfo.Right2Max
  286. } else {
  287. dataListResp.LeftMin = strconv.FormatFloat(LeftMin, 'f', -1, 64)
  288. dataListResp.LeftMax = strconv.FormatFloat(LeftMax, 'f', -1, 64)
  289. dataListResp.RightMin = strconv.FormatFloat(RightMin, 'f', -1, 64)
  290. dataListResp.RightMax = strconv.FormatFloat(RightMax, 'f', -1, 64)
  291. dataListResp.Right2Min = strconv.FormatFloat(Right2Min, 'f', -1, 64)
  292. dataListResp.Right2Max = strconv.FormatFloat(Right2Max, 'f', -1, 64)
  293. }
  294. if len(dateConfEdbIds) > 0 {
  295. dateConfEdbList, e := data_manage.GetEdbInfoByIdList(dateConfEdbIds)
  296. if e != nil {
  297. err = fmt.Errorf("查询引用日期里的指标信息失败,错误信息:%s", e.Error())
  298. return
  299. }
  300. dateConfEdbMap := make(map[int]*data_manage.EdbInfo)
  301. for _, dateConfEdb := range dateConfEdbList {
  302. dateConfEdbMap[dateConfEdb.EdbInfoId] = dateConfEdb
  303. }
  304. for i, dateConf := range extraConfig.DateConfList {
  305. if dateConf.EdbInfoId > 0 {
  306. edbItem, ok := dateConfEdbMap[dateConf.EdbInfoId]
  307. if ok {
  308. extraConfig.DateConfList[i].EdbName = edbItem.EdbName
  309. extraConfig.DateConfList[i].EdbInfoId = edbItem.EdbInfoId
  310. extraConfig.DateConfList[i].EdbInfoType = edbItem.EdbInfoType
  311. extraConfig.DateConfList[i].Frequency = edbItem.Frequency
  312. extraConfig.DateConfList[i].EndDate = edbItem.EndDate
  313. }
  314. }
  315. }
  316. }
  317. dataListResp.SeriesList = extraConfig.SeriesList
  318. dataListResp.DateConfList = extraConfig.DateConfList
  319. dataListResp.BaseChartSeriesName = extraConfig.BaseChartSeriesName
  320. dataListResp.UnitList = unitList
  321. dataListResp.IsHeap = extraConfig.IsHeap
  322. dataListResp.SortType = extraConfig.SortType
  323. return
  324. }
  325. func GetChartSectionSeriesDateByDateChange(edbInfoId int, dataList []*models.EdbDataList, dateChange []*models.ChartSectionDateChange, moveForward int) (newDate string, err error) {
  326. if edbInfoId > 0 { //指标日期
  327. newDate = GetEdbDateByMoveForward(moveForward, dataList)
  328. } else {
  329. newDate = time.Now().Format(utils.FormatDate)
  330. }
  331. if newDate != "" && len(dateChange) > 0 {
  332. newDate, err = HandleChartSectionSeriesDateChange(newDate, dateChange)
  333. }
  334. return
  335. }
  336. func GetEdbDateByMoveForward(moveForward int, edbDataList []*models.EdbDataList) (date string) {
  337. dateList := make([]string, 0)
  338. for _, v := range edbDataList {
  339. dateList = append(dateList, v.DataTime)
  340. }
  341. date = GetEdbDateByMoveForwardByDateList(moveForward, dateList)
  342. return
  343. }
  344. func GetEdbDateByMoveForwardByDateList(moveForward int, dateList []string) (date string) {
  345. index := len(dateList) - 1 - moveForward
  346. for k, v := range dateList {
  347. if k == index {
  348. date = v
  349. return
  350. }
  351. }
  352. return
  353. }
  354. func HandleChartSectionSeriesDateChange(date string, dateChange []*models.ChartSectionDateChange) (newDate string, err error) {
  355. newDate = date
  356. if newDate != "" {
  357. if len(dateChange) > 0 {
  358. var dateTime time.Time
  359. dateTime, err = time.ParseInLocation(utils.FormatDate, newDate, time.Local)
  360. if err != nil {
  361. err = fmt.Errorf("日期解析失败: %s", err.Error())
  362. return
  363. }
  364. for _, v := range dateChange {
  365. if v.ChangeType == 1 {
  366. dateTime = dateTime.AddDate(v.Year, v.Month, v.Day)
  367. newDate = dateTime.Format(utils.FormatDate)
  368. } else if v.ChangeType == 2 {
  369. newDate, err, _ = handleSystemAppointDateT(dateTime, v.FrequencyDay, v.Frequency)
  370. if err != nil {
  371. return
  372. }
  373. dateTime, err = time.ParseInLocation(utils.FormatDate, newDate, time.Local)
  374. if err != nil {
  375. err = fmt.Errorf("日期解析失败: %s", err.Error())
  376. return
  377. }
  378. }
  379. }
  380. }
  381. }
  382. return
  383. }
  384. func handleSystemAppointDateT(currDate time.Time, appointDay, frequency string) (date string, err error, errMsg string) {
  385. switch frequency {
  386. case "本周":
  387. day := int(currDate.Weekday())
  388. if day == 0 { // 周日
  389. day = 7
  390. }
  391. num := 0
  392. switch appointDay {
  393. case "周一":
  394. num = 1
  395. case "周二":
  396. num = 2
  397. case "周三":
  398. num = 3
  399. case "周四":
  400. num = 4
  401. case "周五":
  402. num = 5
  403. case "周六":
  404. num = 6
  405. case "周日":
  406. num = 7
  407. }
  408. day = num - day
  409. date = currDate.AddDate(0, 0, day).Format(utils.FormatDate)
  410. case "本旬":
  411. day := currDate.Day()
  412. var tmpDate time.Time
  413. switch appointDay {
  414. case "第一天":
  415. if day <= 10 {
  416. tmpDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, currDate.Location())
  417. } else if day <= 20 {
  418. tmpDate = time.Date(currDate.Year(), currDate.Month(), 11, 0, 0, 0, 0, currDate.Location())
  419. } else {
  420. tmpDate = time.Date(currDate.Year(), currDate.Month(), 21, 0, 0, 0, 0, currDate.Location())
  421. }
  422. case "最后一天":
  423. if day <= 10 {
  424. tmpDate = time.Date(currDate.Year(), currDate.Month(), 10, 0, 0, 0, 0, currDate.Location())
  425. } else if day <= 20 {
  426. tmpDate = time.Date(currDate.Year(), currDate.Month(), 20, 0, 0, 0, 0, currDate.Location())
  427. } else {
  428. tmpDate = time.Date(currDate.Year(), currDate.Month()+1, 1, 0, 0, 0, 0, currDate.Location()).AddDate(0, 0, -1)
  429. }
  430. }
  431. date = tmpDate.Format(utils.FormatDate)
  432. case "本月":
  433. var tmpDate time.Time
  434. switch appointDay {
  435. case "第一天":
  436. tmpDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, currDate.Location())
  437. case "最后一天":
  438. tmpDate = time.Date(currDate.Year(), currDate.Month()+1, 1, 0, 0, 0, 0, currDate.Location()).AddDate(0, 0, -1)
  439. }
  440. date = tmpDate.Format(utils.FormatDate)
  441. case "本季":
  442. month := currDate.Month()
  443. var tmpDate time.Time
  444. switch appointDay {
  445. case "第一天":
  446. if month <= 3 {
  447. tmpDate = time.Date(currDate.Year(), 1, 1, 0, 0, 0, 0, currDate.Location())
  448. } else if month <= 6 {
  449. tmpDate = time.Date(currDate.Year(), 4, 1, 0, 0, 0, 0, currDate.Location())
  450. } else if month <= 9 {
  451. tmpDate = time.Date(currDate.Year(), 7, 1, 0, 0, 0, 0, currDate.Location())
  452. } else {
  453. tmpDate = time.Date(currDate.Year(), 10, 1, 0, 0, 0, 0, currDate.Location())
  454. }
  455. case "最后一天":
  456. if month <= 3 {
  457. tmpDate = time.Date(currDate.Year(), 3, 31, 0, 0, 0, 0, currDate.Location())
  458. } else if month <= 6 {
  459. tmpDate = time.Date(currDate.Year(), 6, 30, 0, 0, 0, 0, currDate.Location())
  460. } else if month <= 9 {
  461. tmpDate = time.Date(currDate.Year(), 9, 30, 0, 0, 0, 0, currDate.Location())
  462. } else {
  463. tmpDate = time.Date(currDate.Year(), 12, 31, 0, 0, 0, 0, currDate.Location())
  464. }
  465. }
  466. date = tmpDate.Format(utils.FormatDate)
  467. case "本半年":
  468. month := currDate.Month()
  469. var tmpDate time.Time
  470. switch appointDay {
  471. case "第一天":
  472. if month <= 6 {
  473. tmpDate = time.Date(currDate.Year(), 1, 1, 0, 0, 0, 0, currDate.Location())
  474. } else {
  475. tmpDate = time.Date(currDate.Year(), 7, 1, 0, 0, 0, 0, currDate.Location())
  476. }
  477. case "最后一天":
  478. if month <= 6 {
  479. tmpDate = time.Date(currDate.Year(), 6, 30, 0, 0, 0, 0, currDate.Location())
  480. } else {
  481. tmpDate = time.Date(currDate.Year(), 12, 31, 0, 0, 0, 0, currDate.Location())
  482. }
  483. }
  484. date = tmpDate.Format(utils.FormatDate)
  485. case "本年":
  486. var tmpDate time.Time
  487. switch appointDay {
  488. case "第一天":
  489. tmpDate = time.Date(currDate.Year(), 1, 1, 0, 0, 0, 0, currDate.Location())
  490. case "最后一天":
  491. tmpDate = time.Date(currDate.Year(), 12, 31, 0, 0, 0, 0, currDate.Location())
  492. }
  493. date = tmpDate.Format(utils.FormatDate)
  494. default:
  495. errMsg = "错误的日期频度:" + frequency
  496. err = errors.New(errMsg)
  497. return
  498. }
  499. return
  500. }
  501. func SortChartSeriesDataSet(baseName string, baseDataList []float64, baseSeriesNoDataIndexList []int, dataListMap map[string][]float64, noDataListIndexMap map[string][]int, asc int) (newDataListMap map[string][]float64, newNoDataListIndexMap map[string][]int, newIndexXDataList []int) {
  502. newDataListMap = make(map[string][]float64)
  503. newNoDataListIndexMap = make(map[string][]int)
  504. indices := make([]int, len(baseDataList))
  505. newIndices := make([]int, len(baseDataList)-len(baseSeriesNoDataIndexList))
  506. for i := range indices {
  507. indices[i] = i
  508. }
  509. if len(baseSeriesNoDataIndexList) > 0 { //把空值移动到最右边
  510. j := 0
  511. for i := range indices {
  512. isEmpty := false
  513. for _, v := range baseSeriesNoDataIndexList {
  514. if i == v {
  515. isEmpty = true
  516. break
  517. }
  518. }
  519. if isEmpty {
  520. continue
  521. }
  522. newIndices[j] = i
  523. j += 1
  524. }
  525. newIndices = append(newIndices, baseSeriesNoDataIndexList...)
  526. for i, idx := range newIndices {
  527. for k, _ := range dataListMap {
  528. if _, ok := newDataListMap[k]; !ok {
  529. newDataListMap[k] = make([]float64, len(baseDataList))
  530. }
  531. if utils.InArrayByInt(noDataListIndexMap[k], idx) { //如果i位置上的数据为空,那么
  532. newNoDataListIndexMap[k] = append(newNoDataListIndexMap[k], i)
  533. }
  534. newDataListMap[k][i] = dataListMap[k][idx]
  535. }
  536. }
  537. dataListMap = newDataListMap
  538. noDataListIndexMap = newNoDataListIndexMap
  539. newDataListMap = make(map[string][]float64)
  540. newNoDataListIndexMap = make(map[string][]int)
  541. baseDataList, _ = dataListMap[baseName]
  542. indices = make([]int, len(baseDataList)-len(baseSeriesNoDataIndexList)) //空值不参与排序
  543. newIndices = make([]int, len(baseDataList)) //空值不参与排序
  544. for i := range indices {
  545. indices[i] = i
  546. }
  547. }
  548. length := len(indices)
  549. baseDataSortList := make([]models.ChartSectionSeriesValSort, length)
  550. for i, value := range baseDataList {
  551. if i < length {
  552. baseDataSortList[i] = models.ChartSectionSeriesValSort{Index: i, Value: value}
  553. }
  554. }
  555. if asc == 1 {
  556. sort.Sort(models.ChartSectionSeriesValSortAsc(baseDataSortList))
  557. } else {
  558. sort.Sort(models.ChartSectionSeriesValSortDesc(baseDataSortList))
  559. }
  560. for k, v := range baseDataSortList {
  561. indices[k] = v.Index
  562. }
  563. for i := range newIndices {
  564. if i < length {
  565. newIndices[i] = indices[i]
  566. } else {
  567. newIndices[i] = i
  568. }
  569. }
  570. for i, idx := range newIndices {
  571. for k, _ := range dataListMap {
  572. if _, ok := newDataListMap[k]; !ok {
  573. newDataListMap[k] = make([]float64, len(baseDataList))
  574. }
  575. if utils.InArrayByInt(noDataListIndexMap[k], idx) { //如果i位置上的数据为空,那么
  576. newNoDataListIndexMap[k] = append(newNoDataListIndexMap[k], i)
  577. }
  578. newDataListMap[k][i] = dataListMap[k][idx]
  579. }
  580. }
  581. newIndexXDataList = newIndices
  582. return
  583. }