Commit e753b17d4fb95c882491a7338fdf5dc130f80c7a

Authored by litao
1 parent a5ad429c24

bug

xiufu

Showing 3 changed files with 99 additions and 4 deletions

platform-operate-api/src/main/java/com/lyms/hospitalapi/pojo/ReportModel.java View file @ e753b17
1 1 package com.lyms.hospitalapi.pojo;
2 2  
  3 +import com.lyms.platform.operate.web.utils.CollectionUtils;
3 4 import com.lymsh.platform.reportdata.model.echarts.Series;
4 5  
  6 +import java.util.ArrayList;
  7 +import java.util.HashMap;
5 8 import java.util.List;
6 9 import java.util.Map;
7 10  
... ... @@ -28,6 +31,78 @@
28 31 private List<Series> series;
29 32  
30 33 private List<Object> doctorInfo;
  34 +
  35 + /**
  36 + * 将 x 轴数据去重并把series数据合并
  37 + */
  38 + public void doMerge() {
  39 + // 用于放x轴数据 所对应的series data的下标list
  40 + Map<String, List<Integer>> mergeMap = new HashMap<>();
  41 + for (int i = 0; i < xAxis.size(); i++) {
  42 + String xVal = xAxis.get(i);
  43 + if(!mergeMap.containsKey(xVal)) {
  44 + List<Integer> list = new ArrayList<>();
  45 + list.add(i);
  46 + mergeMap.put(xAxis.get(i), list);
  47 + } else {
  48 + mergeMap.get(xVal).add(i);
  49 + }
  50 + }
  51 +
  52 + calcSeries(mergeMap);
  53 +
  54 + CollectionUtils.removeDuplicate(xAxis);
  55 +
  56 + /*List<String> xAxis = reportModel.getxAxis();
  57 + List<String> xAxisTemp = new ArrayList<>();
  58 +
  59 + for (Series series : reportModel.getSeries()) {
  60 + List<Object> data = series.getData();
  61 + Map<String, Integer> tempMap = new LinkedHashMap<>();
  62 + for (int i = 0; i < xAxis.size(); i++) {
  63 + int count = Integer.parseInt(data.get(i) + "");
  64 + if(!tempMap.containsKey(xAxis.get(i))) {
  65 + tempMap.put(xAxis.get(i), count);
  66 + xAxisTemp.add(xAxis.get(i) + "");
  67 + } else {
  68 + data.remove(i);
  69 + tempMap.put(xAxis.get(i), tempMap.get(xAxis.get(i)) + count);
  70 + }
  71 + }
  72 +
  73 + data.clear();
  74 + Iterator it = tempMap.keySet().iterator();
  75 + while (it.hasNext()) {
  76 + String key = it.next().toString();
  77 + data.add(tempMap.get(key));
  78 + }
  79 +
  80 + xAxis.clear();
  81 + xAxis.addAll(xAxisTemp);
  82 + }
  83 +
  84 + List<Object> series = reportModel.getSeries().get(1).getData();*/
  85 + }
  86 +
  87 + /**
  88 + * 计算总和
  89 + * @param mergeMap
  90 + */
  91 + private void calcSeries(Map<String, List<Integer>> mergeMap) {
  92 + List<List<Integer>> list = CollectionUtils.transValToList(mergeMap);
  93 + for (Series s : series) {
  94 + List<Object> data = s.getData();
  95 + List<Object> tempData = new ArrayList<>();
  96 + for (List<Integer> integers : list) {
  97 + int count = 0;
  98 + for (Integer i : integers) {
  99 + count += Integer.parseInt(data.get(i) + "");
  100 + }
  101 + tempData.add(count);
  102 + }
  103 + s.setData(tempData);
  104 + }
  105 + }
31 106  
32 107 public List<String> getxAxis() {
33 108 return xAxis;
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java View file @ e753b17
... ... @@ -25,6 +25,7 @@
25 25 import org.springframework.data.mongodb.core.query.Criteria;
26 26 import org.springframework.data.mongodb.core.query.Query;
27 27 import org.springframework.stereotype.Service;
  28 +import scala.util.parsing.combinator.testing.Str;
28 29  
29 30 import javax.servlet.http.HttpServletResponse;
30 31 import java.sql.PreparedStatement;
... ... @@ -470,6 +471,7 @@
470 471 reportModel.setxAxis(xAxis);
471 472 reportModel.setData(Arrays.asList("发放券数", "使用券数"));
472 473 reportModel.setSeries(createSeries(couponReport));
  474 + reportModel.doMerge();
473 475  
474 476 Map<String, Object> titleMap = parseTitle(couponReport);
475 477  
platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/CollectionUtils.java View file @ e753b17
... ... @@ -3,10 +3,7 @@
3 3 import org.apache.commons.lang3.StringUtils;
4 4 import org.springframework.util.Assert;
5 5  
6   -import java.util.ArrayList;
7   -import java.util.HashMap;
8   -import java.util.List;
9   -import java.util.Map;
  6 +import java.util.*;
10 7  
11 8 /**
12 9 * @Author: litao
... ... @@ -89,6 +86,27 @@
89 86 }
90 87 }
91 88 return list;
  89 + }
  90 +
  91 + /**
  92 + * list去重数据
  93 + * @param list
  94 + */
  95 + public static void removeDuplicate(List list) {
  96 + Assert.notNull(list, "list must be not null!");
  97 + Set<Object> temp = new HashSet<>(list);
  98 + list.clear();
  99 + list.addAll(temp);
  100 + }
  101 +
  102 + public static <T> List<T> transValToList(Map<String, T> map) {
  103 + Assert.notNull(map, "参数不能为null");
  104 + List<T> restList = new ArrayList<>();
  105 + Set<String> set = map.keySet();
  106 + for (String s : set) {
  107 + restList.add(map.get(s));
  108 + }
  109 + return restList;
92 110 }
93 111  
94 112 }