chart_extra_config.go 19 KB

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