From fb2540529b3605939cb14d1476631f5ea516b0e7 Mon Sep 17 00:00:00 2001 From: "litao@lymsh.com" Date: Tue, 9 Jan 2018 21:48:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E9=97=B4=E6=94=B9=E4=B8=BA=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/service/impl/ReportServiceImpl.java | 264 +++++++++++++++++++++ 1 file changed, 264 insertions(+) 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 ce00244..3b57e61 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 @@ -287,6 +287,269 @@ public class ReportServiceImpl extends BaseServiceImpl implements IReportService tabList.add(tempList); } } else { + Map areaCountMap = new HashMap<>(); + String groupKey = StringUtils.isNotEmpty(cityId) ? "areaId" : "cityId"; // 按照区县或者市统计 + for (Patients patient : patients) { + String hospitalId = patient.getHospitalId(); + if(StringUtils.isEmpty(hospitalId)) { + continue; + } + for (Map map : hospitals) { + if(hospitalId.equals(map.get("id").toString())) { + String areaId = (String) map.get(groupKey); + if(areaCountMap.containsKey(areaId)) { + areaCountMap.put(areaId, areaCountMap.get(areaId) + 1); + } else { + areaCountMap.put(areaId, 1); + } + } + } + } + for (Map.Entry entry : areaCountMap.entrySet()) { + xDatas.add(mongoUtil.findName(entry.getKey() + "")); + bar.add(entry.getValue()); + } + + // 拼装tab数据 + titleList.add((StringUtils.isNotEmpty(cityId) ? "区县" : "城市") + "名称"); + titleList.add("机构数"); + titleList.add("统计指标(人)"); + for (Map map : range) { + titleList.add(DateUtil.getyyyy_mm(map.get("cname"))); + } + + List> infos = new ArrayList<>(); + for (Patients patient : patients) { + for (Map map : hospitals) { + if(patient.getHospitalId().equals(map.get("id").toString())) { + boolean flag = true; + for (Map info : infos) { + if(map.get((StringUtils.isNotEmpty(cityId) ? "areaId" : "cityId")).equals(info.get("id"))) { + Set hids = (Set) info.get("hids"); + hids.add(patient.getHospitalId()); + for (Map dateMap : range) { + if(patient.getBookbuildingDate().getTime() >= dateMap.get("start").getTime() + && patient.getBookbuildingDate().getTime() <= DateUtil.getDayLastSecond(dateMap.get("end")).getTime()) { + String monthKey = DateUtil.getyyyy_mm(dateMap.get("cname")); + if(info.containsKey(monthKey)) { + info.put(monthKey, (Integer) info.get(monthKey) + 1); + flag = false; + } else { + info.put(monthKey, 1); + flag = false; + } + } + } + } + } + if(flag) { + for (Map dateMap : range) { + if(patient.getBookbuildingDate().getTime() >= dateMap.get("start").getTime() + && patient.getBookbuildingDate().getTime() <= DateUtil.getDayLastSecond(dateMap.get("end")).getTime()) { + String monthKey = DateUtil.getyyyy_mm(dateMap.get("cname")); + Map info = new HashMap<>(); + Set hids = new HashSet<>(); + hids.add(patient.getHospitalId()); + info.put(monthKey, 1); + info.put("id", map.get((StringUtils.isNotEmpty(cityId) ? "areaId" : "cityId"))); + info.put("hids", hids); + infos.add(info); + } + } + } +// System.out.println(patient.getId() + " " +patient.getBookbuildingDate().toLocaleString() + " " + range.get(0).get("start").toLocaleString() + " " + range.get(0).get("end").toLocaleString()); + } + } + } + /* for (Patients patient : patients) { + for (Map map : hospitals) { + if(patient.getHospitalId().equals(map.get("id").toString())) { + boolean flag = true; + for (Map info : infos) { + if(map.get((StringUtils.isNotEmpty(cityId) ? "areaId" : "cityId")).equals(info.get("id"))) { + Set hids = (Set) info.get("hids"); + hids.add(patient.getHospitalId()); + for (Map dateMap : range) { + if(patient.getBookbuildingDate().getTime() >= dateMap.get("start").getTime() + && patient.getBookbuildingDate().getTime() <= dateMap.get("end").getTime()) { + String monthKey = DateUtil.getyyyy_mm(dateMap.get("cname")); + if(info.containsKey(monthKey)) { + info.put(monthKey, (Integer) info.get(monthKey) + 1); + flag = false; + } else { + info.put(monthKey, 1); + flag = false; + } + } + } + } + } + if(flag) { + for (Map dateMap : range) { + if(patient.getBookbuildingDate().getTime() >= dateMap.get("start").getTime() + && patient.getBookbuildingDate().getTime() <= dateMap.get("end").getTime()) { + String monthKey = DateUtil.getyyyy_mm(dateMap.get("cname")); + Map info = new HashMap<>(); + Set hids = new HashSet<>(); + hids.add(patient.getHospitalId()); + info.put(monthKey, 1); + info.put("id", map.get((StringUtils.isNotEmpty(cityId) ? "areaId" : "cityId"))); + info.put("hids", hids); + infos.add(info); + } + } + } +// System.out.println(patient.getId() + " " +patient.getBookbuildingDate().toLocaleString() + " " + range.get(0).get("start").toLocaleString() + " " + range.get(0).get("end").toLocaleString()); + } + } + }*/ + + for (Map info : infos) { + List tempList = new ArrayList<>(); + tempList.add(findName(info.get("id"))); + tempList.add(((Set) info.get("hids")).size() + ""); + tempList.add("建档总数"); + for (Map map : range) { + tempList.add(info.containsKey(DateUtil.getyyyy_mm(map.get("cname"))) ? + info.get(DateUtil.getyyyy_mm(map.get("cname"))) + "" : "0"); + } + tabList.add(tempList); + } + } + + tabList.add(0, titleList); + setTabListInfo(tabList, StringUtils.isNotEmpty(aredId) ? 2 : 3); + setCountList(tabList, countList, StringUtils.isNotEmpty(aredId) ? 3 : 4); + + barMap.put("data", bar); + barMap.put("type", "bar"); + barMap.put("name", "建档总数"); + series.add(barMap); + + /*if(statistType == 1) { + Integer count = 0; + for (Integer num : bar) { + count += num; + } + for (Integer num : bar) { + line.add(MathUtil.getProportion(num, count)); + } + } + lineMap.put("data", line); + lineMap.put("type", "line"); + lineMap.put("name", "建档总数"); + series.add(lineMap);*/ + + + restMap.put("legend", legend); + restMap.put("series", series); + restMap.put("xDatas", xDatas); + restMap.put("tabList", tabList); + + return RespBuilder.buildSuccess(restMap); + } + + + /** + * 建档统计 + * @param statistType 1=占比 2=环比 + * @param ageType 1=全部年龄 2=20岁以下 3=20-30岁 4=30-40岁 5=40岁以上 + * @param patientType 建档孕周 1=孕早期 2=孕中期 3=孕晚期 + * @return + */ +// @Override + public BaseObjectResponse patients2(String provinceId, String cityId, String aredId, String streetId, Integer statistType, Integer statistVal, Integer ageType, Integer patientType, Date startDate, Date endDate, Integer userId) { + List patients = getPatients(provinceId, cityId, aredId, streetId, ageType, patientType, startDate, endDate, userId); + List> hospitals = couponMapper.findAllHospitals(); + Map restMap = new HashMap<>(); + List> tabList = new ArrayList<>(); + List titleList = new ArrayList<>(); + List countList = new ArrayList<>(); + List xDatas = new ArrayList<>(); + List> series = new ArrayList<>(); + List legend = Arrays.asList("建档总数"); + List bar = new ArrayList<>(); + Map barMap = new HashMap<>(); + List> range = DateUtil.getRange(startDate, endDate); + + List patientIds = new ArrayList<>(); + for (Patients patient : patients) { + patientIds.add(patient.getId()); + } + + if(StringUtils.isNotEmpty(aredId)) { // 按照医院统计 + GroupOperation groupOperation = Aggregation.group("hospitalId").count().as("count"); + Aggregation agg = Aggregation.newAggregation(Patients.class, Aggregation.match(Criteria.where("id").in(patientIds)), groupOperation); + AggregationResults results = mongoTemplate.aggregate(agg, Patients.class, Map.class); + List mappedResults = results.getMappedResults(); + for (Map mappedResult : mappedResults) { + xDatas.add(couponMapper.findHospitalNameById((String) mappedResult.get("_id"))); + bar.add((Integer) mappedResult.get("count")); + } + + titleList.add("医院名称"); + titleList.add("统计指标(人)"); + for (Map map : range) { + titleList.add(DateUtil.getyyyy_mm(map.get("cname"))); + } + Map> tempMap = new HashMap<>(); + /*for (Patients patient : patients) { + if(tempMap.containsKey(patient.getHospitalId())) { + Map map = tempMap.get(patient.getHospitalId()); + for (Map dateMap : range) { + String cname = DateUtil.getyyyy_mm(dateMap.get("cname")); + if(patient.getBookbuildingDate().getTime() >= dateMap.get("start").getTime() + && patient.getBookbuildingDate().getTime() <= dateMap.get("end").getTime()) { + map.put(cname, map.containsKey(cname) ? map.get(cname) + 1 : 1); + break; + } + } + } else { + Map temp = new HashMap<>(); + for (Map dateMap : range) { + if(patient.getBookbuildingDate().getTime() >= dateMap.get("start").getTime() + && patient.getBookbuildingDate().getTime() <= dateMap.get("end").getTime()) { + temp.put(DateUtil.getyyyy_mm(dateMap.get("cname")), 1); + break; + } + } + tempMap.put(patient.getHospitalId(), temp); + } + }*/ + for (Patients patient : patients) { + if(tempMap.containsKey(patient.getHospitalId())) { + Map map = tempMap.get(patient.getHospitalId()); + for (Map dateMap : range) { + String cname = DateUtil.getyyyy_mm(dateMap.get("cname")); + if(patient.getBookbuildingDate().getTime() >= dateMap.get("start").getTime() + && patient.getBookbuildingDate().getTime() <= DateUtil.getDayLastSecond(dateMap.get("end")).getTime()) { + map.put(cname, map.containsKey(cname) ? map.get(cname) + 1 : 1); + break; + } + } + } else { + Map temp = new HashMap<>(); + for (Map dateMap : range) { + if(patient.getBookbuildingDate().getTime() >= dateMap.get("start").getTime() + && patient.getBookbuildingDate().getTime() <= DateUtil.getDayLastSecond(dateMap.get("end")).getTime()) { + temp.put(DateUtil.getyyyy_mm(dateMap.get("cname")), 1); + break; + } + } + tempMap.put(patient.getHospitalId(), temp); + } + } + for (Map.Entry> entry : tempMap.entrySet()) { + List tempList = new ArrayList<>(); + tempList.add(couponMapper.findHospitalNameById(entry.getKey())); + tempList.add("建档人数"); + for (Map map : range) { + tempList.add(entry.getValue().containsKey(DateUtil.getyyyy_mm(map.get("cname"))) ? + entry.getValue().get(DateUtil.getyyyy_mm(map.get("cname"))) + "" : "0"); + } + tabList.add(tempList); + } + } else { Map areaCountMap = new HashMap<>(); String groupKey = StringUtils.isNotEmpty(cityId) ? "areaId" : "cityId"; // 按照区县或者市统计 for (Patients patient : patients) { @@ -449,6 +712,7 @@ public class ReportServiceImpl extends BaseServiceImpl implements IReportService return RespBuilder.buildSuccess(restMap); } + private void setCountList(List> tabList, List countList, int index) { if(tabList.size() > 1) { countList.add(tabList.size() + ""); -- 1.8.3.1