diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java index 12f5847..5bb4c39 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java @@ -1120,12 +1120,10 @@ public class ReportServiceImpl extends BaseServiceImpl implements IReportService List> mapList = mongoUtil.getListByGroup(patients); - - List series = createPatientSeries(mapList); reportModel.setSeries(series); - Map countMap = new HashMap<>(); + /*Map countMap = new HashMap<>(); countMap.put("id", -1); countMap.put("parentId", null); countMap.put("name", "建册人数(按居住地)"); @@ -1137,7 +1135,7 @@ public class ReportServiceImpl extends BaseServiceImpl implements IReportService count += Integer.parseInt(qhdData.get(i) + "") + Integer.parseInt(otherData.get(i) + ""); } countMap.put("count", count); - mapList.add(countMap); + mapList.add(countMap);*/ return RespBuilder.buildSuccess("patients", mapList, "report", reportModel); } @@ -1149,38 +1147,52 @@ public class ReportServiceImpl extends BaseServiceImpl implements IReportService qhdSeries.setName("秦皇岛市"); qhdSeries.setType("bar"); qhdSeries.setStack("总计"); - List qhdDatas = new ArrayList<>(); - - Series otherSeries = new Series(); - otherSeries.setName("辖区外"); - otherSeries.setType("bar"); - otherSeries.setStack("总计"); - List otherDatas = new ArrayList<>(); - Map temp = new HashMap<>(); - for(int i = 1; i < 13; i++) { - temp.put(i + "", 0); - } String provinceId = mongoUtil.findId("河北省"); - if(StringUtils.isNotEmpty(provinceId)) {} - for (Map data : datas) { - if(provinceId.equals(data.get("id"))) { - for(int i = 1; i < 13; i++) { - qhdDatas.add(data.get(i + "")); - } - qhdSeries.setData(qhdDatas); - } else { - for(int i = 1; i < 13; i++) { - temp.put(i + "", temp.get(i + "") + Integer.parseInt(data.get(i + "") + "")); + if(StringUtils.isNotEmpty(provinceId)) { + Map qhdTemp = new HashMap<>();/** key = month . value = count*/ + for (int i = 1; i < 13; i++) { + qhdTemp.put(i, 0); + } + Map otherTemp = new HashMap<>();/** key = month . value = count*/ + for (int i = 1; i < 13; i++) { + otherTemp.put(i, 0); + } + for (Map data : datas) { + if(provinceId.equals(data.get("province_id"))) { + for(int i = 1; i < 13; i++) { + qhdTemp.put(i, qhdTemp.get(i) + Integer.parseInt(data.get(i + "") + "")); + } + } else { + for(int i = 1; i < 13; i++) { + otherTemp.put(i, otherTemp.get(i) + Integer.parseInt(data.get(i + "") + "")); + } } } + List qhdDatas = new ArrayList<>(); + Set> entries = qhdTemp.entrySet(); + for (Map.Entry entry : entries) { + qhdDatas.add(entry.getValue()); + } + qhdSeries.setData(qhdDatas); + + /** 设置其他辖区 */ + Series otherSeries = new Series(); + otherSeries.setName("辖区外"); + otherSeries.setType("bar"); + otherSeries.setStack("总计"); + List otherDatas = new ArrayList<>(); + + Set> entries2 = otherTemp.entrySet(); + for (Map.Entry entry : entries2) { + otherDatas.add(entry.getValue()); + } + otherSeries.setData(otherDatas); + + series.add(qhdSeries); + series.add(otherSeries); } - List integers = CollectionUtils.transValToList(temp); - otherDatas.addAll(integers); - otherSeries.setData(otherDatas); - series.add(qhdSeries); - series.add(otherSeries); return series; } diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/MongoUtil.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/MongoUtil.java index c79b508..1855364 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/MongoUtil.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/MongoUtil.java @@ -51,18 +51,9 @@ public class MongoUtil { * @return */ public List> getListByGroup(List patients) { - Map codeMap = new HashMap<>(); /** key为 id_month */ + Map codeMap = new HashMap<>(); /** key为 provinceId_cityId_areaId_month */ + Map otherMap = new HashMap<>(); /** key为 month */ - Map otherMonthMap = new HashMap<>(); - for (int i = 1; i <= 12; i++) { - otherMonthMap.put(i + "", 0); - } - - Integer otherCount = 0; - /* for (Patients patient : patients) { - System.out.println("month:" + DateUtil.getMonth(patient.getBookbuildingDate()) + "\tprovinceId: " + patient.getProvinceId() - + "\tcityId: " + patient.getCityId() + "\tareaId:" + patient.getAreaId()); - }*/ for (Patients patient : patients) { Date bookbuildingDate = patient.getBookbuildingDate(); if(bookbuildingDate == null) { @@ -75,30 +66,84 @@ public class MongoUtil { Integer month = DateUtil.getMonth(bookbuildingDate); if (StringUtils.isEmpty(provinceId) || StringUtils.isEmpty(cityId) || StringUtils.isEmpty(areaId)) { - otherMonthMap.put(month + "", otherMonthMap.get(month + "") + 1); - ++otherCount; + if(otherMap.containsKey(month)) { + otherMap.put(month, otherMap.get(month) + 1); + } else { + otherMap.put(month, 1); + } continue; } - if(codeMap.containsKey(provinceId + "_" + month)) { - codeMap.put(provinceId + "_" + month, codeMap.get(provinceId + "_" + month) + 1); + String key = provinceId + "_" + cityId + "_" + areaId + "_" + month; + if(codeMap.containsKey(key)) { + codeMap.put(key, codeMap.get(key) + 1); } else { - codeMap.put(provinceId + "_" + month, 1); + codeMap.put(key, 1); } - if(codeMap.containsKey(cityId + "_" + month)) { - codeMap.put(cityId + "_" + month, codeMap.get(cityId + "_" + month) + 1); - } else { - codeMap.put(cityId + "_" + month, 1); +// + } + } + + Set> entrySet = codeMap.entrySet(); + List> rest = new ArrayList<>(); + for (Map.Entry map : entrySet) { + String[] keys = map.getKey().split("_"); + String provinceId = keys[0]; + String cityId = keys[1]; + String areaId = keys[2]; + String month = keys[3]; + + boolean flag = true; + for (Map data : rest) { + if(areaId.equals(data.get("area_id"))) { /** 合并相同省市区月份数据 */ + data.put(month, map.getValue()); + flag = false; + continue; } - if(codeMap.containsKey(areaId + "_" + month)) { - codeMap.put(areaId + "_" + month, codeMap.get(areaId + "_" + month) + 1); - } else { - codeMap.put(areaId + "_" + month, 1); + } + + if(flag) { + Map tempMap = new HashMap<>(); + tempMap.put("province_id", provinceId); + tempMap.put("province_name", findName(provinceId)); + tempMap.put("city_id", cityId); + tempMap.put("city_name", findName(cityId)); + tempMap.put("area_id", areaId); + tempMap.put("area_name", findName(areaId)); + tempMap.put("level", "建册人数"); + tempMap.put(month, map.getValue()); + rest.add(tempMap); + } + } + + + /** 把没有月份的数据设置为0*/ + for (Map map : rest) { + for (int i = 1; i < 13; i++) { + if(!map.containsKey(i + "")) { + map.put(i + "", 0); } } } - List>> datas = new ArrayList<>(); + /** 处理其他 */ + Set> otherDatas = otherMap.entrySet(); + Map tempMap = new HashMap<>(); + tempMap.put("province_id", null); + tempMap.put("province_name", "其他"); + tempMap.put("city_id", null); + tempMap.put("city_name", "其他"); + tempMap.put("area_id", null); + tempMap.put("area_name", "其他"); + tempMap.put("level", "建册人数"); + for (int i = 1; i < 13; i++) { + tempMap.put(i + "", 0); + } + for (Map.Entry data : otherDatas) { + tempMap.put(data.getKey() + "", data.getValue()); + } + rest.add(tempMap); + /* List>> datas = new ArrayList<>(); Set> entries = codeMap.entrySet(); for (Map.Entry entry : entries) { String key = entry.getKey(); @@ -126,7 +171,7 @@ public class MongoUtil { tempMap.put(id, map); datas.add(tempMap); } - } + }*/ /* System.out.println("===================================== codemap ================================="); Set> codeMapEntries = codeMap.entrySet(); @@ -141,9 +186,9 @@ public class MongoUtil { } }*/ - List> restMap = new ArrayList<>(); + /*List> restMap = new ArrayList<>(); - /** 设置没数据的月份为0 */ + *//** 设置没数据的月份为0 *//* for (Map> data : datas) { Integer count = 0; Set>> set = data.entrySet(); @@ -167,11 +212,11 @@ public class MongoUtil { restMap.add(tempMap); } } - +*/ /** 处理 其他 数据 */ - Map tempMap = new HashMap<>(); - tempMap.put("count", otherCount); + /* Map tempMap = new HashMap<>(); + otherMonthMap.put("count", otherCount); tempMap.put("name", "其他"); tempMap.put("id", null); tempMap.put("parentId", -1); @@ -182,7 +227,7 @@ public class MongoUtil { tempMap.put(i + "", 0); } } - restMap.add(tempMap); + restMap.add(tempMap);*/ /* for (Map> data : datas) { System.out.println("data>>> " + data); @@ -191,7 +236,7 @@ public class MongoUtil { for (Map map : restMap) { System.out.println("rest>> " + map); }*/ - return restMap; + return rest; } private String findParentId(String key) {