chart_extra_config.go 20 KB

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