Commit 978670a523724936df37e7b164ce4f2f03a3dfe8
1 parent
03a1edd733
Exists in
master
and in
6 other branches
报表数据返回结构修改
Showing 1 changed file with 56 additions and 48 deletions
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java
View file @
978670a
| ... | ... | @@ -29,68 +29,69 @@ | 
| 29 | 29 | List<Object> params = new ArrayList<>(); | 
| 30 | 30 | List<Map<String, Object>> mapList = reportDao.findList(getAreaCountFacadeSql(startDate, endDate, startWeek, endWeek, childBirth, params), params); | 
| 31 | 31 | |
| 32 | - List<Map<String, Object>> calcData = calcData(mapList);/** 计算报表数据 */ | |
| 33 | - | |
| 34 | - restMap.put("reportData", calcData); /** 报表数据*/ | |
| 32 | + List<Object> peopleList = createPeoples(mapList); | |
| 33 | + restMap.put("grid", createGrid( createPeoples(mapList), createProportion(peopleList))); | |
| 35 | 34 | restMap.put("xAxis", Arrays.asList("1次", "2次", "3次", "4次", "5次", "6次", "7次", "8次", "9次", "10次", "11次", "12次", "≥13次")); /** x轴数据 */ | 
| 36 | - restMap.put("yAxis", createYData(calcData)); | |
| 35 | + restMap.put("yAxis", createYData(peopleList)); | |
| 37 | 36 | |
| 38 | - if(StringUtils.isNotBlank(startDate) && StringUtils.isNotBlank(endDate)) { | |
| 39 | - restMap.put("recordDate", startDate.replace("-", "/") + " - " + endDate.replace("-", "/")); | |
| 40 | - } | |
| 41 | - | |
| 42 | 37 | rest.setData(restMap); | 
| 43 | 38 | return rest; | 
| 44 | 39 | } | 
| 45 | 40 | |
| 46 | - private List<Object> createYData(List<Map<String, Object>> calcData) { | |
| 47 | - List<Object> yData = new ArrayList<>(); | |
| 48 | - for (Map<String, Object> map : calcData) { | |
| 49 | - yData.add(map.get("people")); | |
| 41 | + private Map<String, Object> createGrid(List<Object> peopleList, List<Object> proportionList) { | |
| 42 | + Map<String, Object> map = new HashMap<>(); | |
| 43 | + map.put("peoples", peopleList); | |
| 44 | + map.put("proportion", proportionList); | |
| 45 | + map.put("header", Arrays.asList("产检次数", "总计", "1次", "2次", "3次", "4次", "5次", "6次", "7次", "8次", "9次", "10次", "11次", "12次", "≥13次")); | |
| 46 | + return map; | |
| 47 | + } | |
| 48 | + | |
| 49 | + private List<Object> createProportion(List<Object> peopleList) { | |
| 50 | + List<Object> proportions = new ArrayList<>(); | |
| 51 | + proportions.add("占比"); | |
| 52 | + int countPeople = Integer.parseInt(peopleList.get(1).toString()); | |
| 53 | + proportions.add("100%"); | |
| 54 | + for (int i = 1; i < peopleList.size(); i++) { | |
| 55 | + proportions.add(MathUtil.doubleFormat(Double.parseDouble(MathUtil.division(Integer.valueOf(peopleList.get(i).toString()) * 100, countPeople))) + "%"); | |
| 50 | 56 | } | 
| 51 | - return yData; | |
| 57 | + return proportions; | |
| 52 | 58 | } | 
| 53 | 59 | |
| 54 | - private List<Map<String, Object>> calcData(List<Map<String, Object>> mapList) { | |
| 55 | - List<Map<String, Object>> restMap = new ArrayList<>(); | |
| 60 | + private List<Object> createPeoples(List<Map<String, Object>> mapList) { | |
| 61 | + List<Object> peoples = new ArrayList<>(); | |
| 62 | + peoples.add("产检人数"); | |
| 56 | 63 | int countPeople = 0; /** 体检所有人数 */ | 
| 57 | - int otherPeople = 0; /** 存储 >= 13次的 所有人数 */ | |
| 58 | - double residualRatio = 1; /** 所剩比率 */ | |
| 59 | - for (Map<String, Object> map : mapList) { | |
| 60 | - countPeople += Integer.parseInt(map.get("EXAMINE_CNT").toString()); | |
| 61 | - } | |
| 62 | 64 | |
| 63 | - for (Map<String, Object> map : mapList) { | |
| 64 | - String number = map.get("EXAMINE_HISTORY_NUM").toString(); /** 次数 */ | |
| 65 | - String people = map.get("EXAMINE_CNT").toString(); /** 人数 */ | |
| 66 | - if(StringUtils.isNotBlank(number) && StringUtils.isNotBlank(people)) { | |
| 67 | - Integer count = Integer.valueOf(number); | |
| 68 | - if(count >= 13) { | |
| 69 | - otherPeople += Integer.valueOf(people); | |
| 70 | - } else { | |
| 71 | - String proportion = MathUtil.division(Integer.valueOf(people), countPeople); | |
| 72 | - residualRatio -= Double.valueOf(proportion); | |
| 73 | - Map<String, Object> m = new HashMap<>(); | |
| 74 | - m.put("number", number); | |
| 75 | - m.put("people", people); | |
| 76 | - m.put("proportion", MathUtil.doubleFormat(Double.valueOf(proportion) * 100) + "%"); | |
| 77 | - restMap.add(m); | |
| 78 | - } | |
| 65 | + /** 通过下标循环取map里面数据 有就设置value 没有就设置0 */ | |
| 66 | + for(int i = 1; i <= 30; i++) { | |
| 67 | + String count = null; | |
| 68 | + for (Map<String, Object> map : mapList) { | |
| 69 | + if(map.get("EXAMINE_HISTORY_NUM").toString().equals("" + i)) { | |
| 70 | + count = map.get("EXAMINE_CNT").toString(); | |
| 71 | + countPeople += Integer.valueOf(count); | |
| 72 | + } | |
| 79 | 73 | } | 
| 74 | + if(i <= 13) { | |
| 75 | + if(StringUtils.isNotBlank(count)) { | |
| 76 | + peoples.add(count); | |
| 77 | + } else { | |
| 78 | + peoples.add("0"); | |
| 79 | + } | |
| 80 | + } else { | |
| 81 | + if(StringUtils.isNotBlank(count)) { | |
| 82 | + peoples.set(12, Integer.valueOf(peoples.get(12).toString()) + Integer.valueOf(count) + ""); | |
| 83 | + } | |
| 84 | + } | |
| 80 | 85 | } | 
| 86 | + peoples.add(1, countPeople + ""); | |
| 87 | + return peoples; | |
| 88 | + } | |
| 81 | 89 | |
| 82 | - /** 处理13次以上的 */ | |
| 83 | - Map<String, Object> m = new HashMap<>(); | |
| 84 | - m.put("number", 13); | |
| 85 | - m.put("people", otherPeople); | |
| 86 | - m.put("proportion", MathUtil.doubleFormat(Double.valueOf(residualRatio) * 100) + "%"); | |
| 87 | - restMap.add(m); | |
| 88 | - | |
| 89 | - /** 处理总数 */ | |
| 90 | - m.put("people", countPeople); | |
| 91 | - m.put("proportion", "100%"); | |
| 92 | - restMap.add(m); | |
| 93 | - return restMap; | |
| 90 | + private List<Object> createYData(List<Object> list) { | |
| 91 | + List<Object> newList = new ArrayList<>(); | |
| 92 | + newList.addAll(list); | |
| 93 | + newList.remove(0); | |
| 94 | + return newList; | |
| 94 | 95 | } | 
| 95 | 96 | |
| 96 | 97 | private String getAreaCountFacadeSql(String startDate, String endDate, Integer startWeek, Integer endWeek, Integer childBirth, List<Object> params) { | 
| ... | ... | @@ -127,5 +128,12 @@ | 
| 127 | 128 | return sql.toString(); | 
| 128 | 129 | } | 
| 129 | 130 | |
| 131 | + public static void main(String[] args) { | |
| 132 | + System.out.println("1".equals("" + 1)); | |
| 133 | + System.out.println(StringUtils.isNotBlank("")); | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + } | |
| 130 | 138 | } |