Commit fb2540529b3605939cb14d1476631f5ea516b0e7

Authored by litao@lymsh.com
1 parent bf875e3bdd
Exists in master and in 1 other branch dev

优惠券统计的时间改为使用时间

Showing 1 changed file with 264 additions and 0 deletions

platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java View file @ fb25405
... ... @@ -287,6 +287,269 @@
287 287 tabList.add(tempList);
288 288 }
289 289 } else {
  290 + Map<String, Integer> areaCountMap = new HashMap<>();
  291 + String groupKey = StringUtils.isNotEmpty(cityId) ? "areaId" : "cityId"; // 按照区县或者市统计
  292 + for (Patients patient : patients) {
  293 + String hospitalId = patient.getHospitalId();
  294 + if(StringUtils.isEmpty(hospitalId)) {
  295 + continue;
  296 + }
  297 + for (Map<String, Object> map : hospitals) {
  298 + if(hospitalId.equals(map.get("id").toString())) {
  299 + String areaId = (String) map.get(groupKey);
  300 + if(areaCountMap.containsKey(areaId)) {
  301 + areaCountMap.put(areaId, areaCountMap.get(areaId) + 1);
  302 + } else {
  303 + areaCountMap.put(areaId, 1);
  304 + }
  305 + }
  306 + }
  307 + }
  308 + for (Map.Entry<String, Integer> entry : areaCountMap.entrySet()) {
  309 + xDatas.add(mongoUtil.findName(entry.getKey() + ""));
  310 + bar.add(entry.getValue());
  311 + }
  312 +
  313 + // 拼装tab数据
  314 + titleList.add((StringUtils.isNotEmpty(cityId) ? "区县" : "城市") + "名称");
  315 + titleList.add("机构数");
  316 + titleList.add("统计指标(人)");
  317 + for (Map<String, Date> map : range) {
  318 + titleList.add(DateUtil.getyyyy_mm(map.get("cname")));
  319 + }
  320 +
  321 + List<Map<String, Object>> infos = new ArrayList<>();
  322 + for (Patients patient : patients) {
  323 + for (Map<String, Object> map : hospitals) {
  324 + if(patient.getHospitalId().equals(map.get("id").toString())) {
  325 + boolean flag = true;
  326 + for (Map<String, Object> info : infos) {
  327 + if(map.get((StringUtils.isNotEmpty(cityId) ? "areaId" : "cityId")).equals(info.get("id"))) {
  328 + Set<String> hids = (Set<String>) info.get("hids");
  329 + hids.add(patient.getHospitalId());
  330 + for (Map<String, Date> dateMap : range) {
  331 + if(patient.getBookbuildingDate().getTime() >= dateMap.get("start").getTime()
  332 + && patient.getBookbuildingDate().getTime() <= DateUtil.getDayLastSecond(dateMap.get("end")).getTime()) {
  333 + String monthKey = DateUtil.getyyyy_mm(dateMap.get("cname"));
  334 + if(info.containsKey(monthKey)) {
  335 + info.put(monthKey, (Integer) info.get(monthKey) + 1);
  336 + flag = false;
  337 + } else {
  338 + info.put(monthKey, 1);
  339 + flag = false;
  340 + }
  341 + }
  342 + }
  343 + }
  344 + }
  345 + if(flag) {
  346 + for (Map<String, Date> dateMap : range) {
  347 + if(patient.getBookbuildingDate().getTime() >= dateMap.get("start").getTime()
  348 + && patient.getBookbuildingDate().getTime() <= DateUtil.getDayLastSecond(dateMap.get("end")).getTime()) {
  349 + String monthKey = DateUtil.getyyyy_mm(dateMap.get("cname"));
  350 + Map<String, Object> info = new HashMap<>();
  351 + Set<String> hids = new HashSet<>();
  352 + hids.add(patient.getHospitalId());
  353 + info.put(monthKey, 1);
  354 + info.put("id", map.get((StringUtils.isNotEmpty(cityId) ? "areaId" : "cityId")));
  355 + info.put("hids", hids);
  356 + infos.add(info);
  357 + }
  358 + }
  359 + }
  360 +// System.out.println(patient.getId() + " " +patient.getBookbuildingDate().toLocaleString() + " " + range.get(0).get("start").toLocaleString() + " " + range.get(0).get("end").toLocaleString());
  361 + }
  362 + }
  363 + }
  364 + /* for (Patients patient : patients) {
  365 + for (Map<String, Object> map : hospitals) {
  366 + if(patient.getHospitalId().equals(map.get("id").toString())) {
  367 + boolean flag = true;
  368 + for (Map<String, Object> info : infos) {
  369 + if(map.get((StringUtils.isNotEmpty(cityId) ? "areaId" : "cityId")).equals(info.get("id"))) {
  370 + Set<String> hids = (Set<String>) info.get("hids");
  371 + hids.add(patient.getHospitalId());
  372 + for (Map<String, Date> dateMap : range) {
  373 + if(patient.getBookbuildingDate().getTime() >= dateMap.get("start").getTime()
  374 + && patient.getBookbuildingDate().getTime() <= dateMap.get("end").getTime()) {
  375 + String monthKey = DateUtil.getyyyy_mm(dateMap.get("cname"));
  376 + if(info.containsKey(monthKey)) {
  377 + info.put(monthKey, (Integer) info.get(monthKey) + 1);
  378 + flag = false;
  379 + } else {
  380 + info.put(monthKey, 1);
  381 + flag = false;
  382 + }
  383 + }
  384 + }
  385 + }
  386 + }
  387 + if(flag) {
  388 + for (Map<String, Date> dateMap : range) {
  389 + if(patient.getBookbuildingDate().getTime() >= dateMap.get("start").getTime()
  390 + && patient.getBookbuildingDate().getTime() <= dateMap.get("end").getTime()) {
  391 + String monthKey = DateUtil.getyyyy_mm(dateMap.get("cname"));
  392 + Map<String, Object> info = new HashMap<>();
  393 + Set<String> hids = new HashSet<>();
  394 + hids.add(patient.getHospitalId());
  395 + info.put(monthKey, 1);
  396 + info.put("id", map.get((StringUtils.isNotEmpty(cityId) ? "areaId" : "cityId")));
  397 + info.put("hids", hids);
  398 + infos.add(info);
  399 + }
  400 + }
  401 + }
  402 +// System.out.println(patient.getId() + " " +patient.getBookbuildingDate().toLocaleString() + " " + range.get(0).get("start").toLocaleString() + " " + range.get(0).get("end").toLocaleString());
  403 + }
  404 + }
  405 + }*/
  406 +
  407 + for (Map<String, Object> info : infos) {
  408 + List<String> tempList = new ArrayList<>();
  409 + tempList.add(findName(info.get("id")));
  410 + tempList.add(((Set<String>) info.get("hids")).size() + "");
  411 + tempList.add("建档总数");
  412 + for (Map<String, Date> map : range) {
  413 + tempList.add(info.containsKey(DateUtil.getyyyy_mm(map.get("cname"))) ?
  414 + info.get(DateUtil.getyyyy_mm(map.get("cname"))) + "" : "0");
  415 + }
  416 + tabList.add(tempList);
  417 + }
  418 + }
  419 +
  420 + tabList.add(0, titleList);
  421 + setTabListInfo(tabList, StringUtils.isNotEmpty(aredId) ? 2 : 3);
  422 + setCountList(tabList, countList, StringUtils.isNotEmpty(aredId) ? 3 : 4);
  423 +
  424 + barMap.put("data", bar);
  425 + barMap.put("type", "bar");
  426 + barMap.put("name", "建档总数");
  427 + series.add(barMap);
  428 +
  429 + /*if(statistType == 1) {
  430 + Integer count = 0;
  431 + for (Integer num : bar) {
  432 + count += num;
  433 + }
  434 + for (Integer num : bar) {
  435 + line.add(MathUtil.getProportion(num, count));
  436 + }
  437 + }
  438 + lineMap.put("data", line);
  439 + lineMap.put("type", "line");
  440 + lineMap.put("name", "建档总数");
  441 + series.add(lineMap);*/
  442 +
  443 +
  444 + restMap.put("legend", legend);
  445 + restMap.put("series", series);
  446 + restMap.put("xDatas", xDatas);
  447 + restMap.put("tabList", tabList);
  448 +
  449 + return RespBuilder.buildSuccess(restMap);
  450 + }
  451 +
  452 +
  453 + /**
  454 + * 建档统计
  455 + * @param statistType 1=占比 2=环比
  456 + * @param ageType 1=全部年龄 2=20岁以下 3=20-30岁 4=30-40岁 5=40岁以上
  457 + * @param patientType 建档孕周 1=孕早期 2=孕中期 3=孕晚期
  458 + * @return
  459 + */
  460 +// @Override
  461 + 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) {
  462 + List<Patients> patients = getPatients(provinceId, cityId, aredId, streetId, ageType, patientType, startDate, endDate, userId);
  463 + List<Map<String, Object>> hospitals = couponMapper.findAllHospitals();
  464 + Map<String, Object> restMap = new HashMap<>();
  465 + List<List<String>> tabList = new ArrayList<>();
  466 + List<String> titleList = new ArrayList<>();
  467 + List<String> countList = new ArrayList<>();
  468 + List<String> xDatas = new ArrayList<>();
  469 + List<Map<String, Object>> series = new ArrayList<>();
  470 + List<String> legend = Arrays.asList("建档总数");
  471 + List<Integer> bar = new ArrayList<>();
  472 + Map<String, Object> barMap = new HashMap<>();
  473 + List<Map<String, Date>> range = DateUtil.getRange(startDate, endDate);
  474 +
  475 + List<String> patientIds = new ArrayList<>();
  476 + for (Patients patient : patients) {
  477 + patientIds.add(patient.getId());
  478 + }
  479 +
  480 + if(StringUtils.isNotEmpty(aredId)) { // 按照医院统计
  481 + GroupOperation groupOperation = Aggregation.group("hospitalId").count().as("count");
  482 + Aggregation agg = Aggregation.newAggregation(Patients.class, Aggregation.match(Criteria.where("id").in(patientIds)), groupOperation);
  483 + AggregationResults<Map> results = mongoTemplate.aggregate(agg, Patients.class, Map.class);
  484 + List<Map> mappedResults = results.getMappedResults();
  485 + for (Map mappedResult : mappedResults) {
  486 + xDatas.add(couponMapper.findHospitalNameById((String) mappedResult.get("_id")));
  487 + bar.add((Integer) mappedResult.get("count"));
  488 + }
  489 +
  490 + titleList.add("医院名称");
  491 + titleList.add("统计指标(人)");
  492 + for (Map<String, Date> map : range) {
  493 + titleList.add(DateUtil.getyyyy_mm(map.get("cname")));
  494 + }
  495 + Map<String, Map<String, Integer>> tempMap = new HashMap<>();
  496 + /*for (Patients patient : patients) {
  497 + if(tempMap.containsKey(patient.getHospitalId())) {
  498 + Map<String, Integer> map = tempMap.get(patient.getHospitalId());
  499 + for (Map<String, Date> dateMap : range) {
  500 + String cname = DateUtil.getyyyy_mm(dateMap.get("cname"));
  501 + if(patient.getBookbuildingDate().getTime() >= dateMap.get("start").getTime()
  502 + && patient.getBookbuildingDate().getTime() <= dateMap.get("end").getTime()) {
  503 + map.put(cname, map.containsKey(cname) ? map.get(cname) + 1 : 1);
  504 + break;
  505 + }
  506 + }
  507 + } else {
  508 + Map<String, Integer> temp = new HashMap<>();
  509 + for (Map<String, Date> dateMap : range) {
  510 + if(patient.getBookbuildingDate().getTime() >= dateMap.get("start").getTime()
  511 + && patient.getBookbuildingDate().getTime() <= dateMap.get("end").getTime()) {
  512 + temp.put(DateUtil.getyyyy_mm(dateMap.get("cname")), 1);
  513 + break;
  514 + }
  515 + }
  516 + tempMap.put(patient.getHospitalId(), temp);
  517 + }
  518 + }*/
  519 + for (Patients patient : patients) {
  520 + if(tempMap.containsKey(patient.getHospitalId())) {
  521 + Map<String, Integer> map = tempMap.get(patient.getHospitalId());
  522 + for (Map<String, Date> dateMap : range) {
  523 + String cname = DateUtil.getyyyy_mm(dateMap.get("cname"));
  524 + if(patient.getBookbuildingDate().getTime() >= dateMap.get("start").getTime()
  525 + && patient.getBookbuildingDate().getTime() <= DateUtil.getDayLastSecond(dateMap.get("end")).getTime()) {
  526 + map.put(cname, map.containsKey(cname) ? map.get(cname) + 1 : 1);
  527 + break;
  528 + }
  529 + }
  530 + } else {
  531 + Map<String, Integer> temp = new HashMap<>();
  532 + for (Map<String, Date> dateMap : range) {
  533 + if(patient.getBookbuildingDate().getTime() >= dateMap.get("start").getTime()
  534 + && patient.getBookbuildingDate().getTime() <= DateUtil.getDayLastSecond(dateMap.get("end")).getTime()) {
  535 + temp.put(DateUtil.getyyyy_mm(dateMap.get("cname")), 1);
  536 + break;
  537 + }
  538 + }
  539 + tempMap.put(patient.getHospitalId(), temp);
  540 + }
  541 + }
  542 + for (Map.Entry<String, Map<String, Integer>> entry : tempMap.entrySet()) {
  543 + List<String> tempList = new ArrayList<>();
  544 + tempList.add(couponMapper.findHospitalNameById(entry.getKey()));
  545 + tempList.add("建档人数");
  546 + for (Map<String, Date> map : range) {
  547 + tempList.add(entry.getValue().containsKey(DateUtil.getyyyy_mm(map.get("cname"))) ?
  548 + entry.getValue().get(DateUtil.getyyyy_mm(map.get("cname"))) + "" : "0");
  549 + }
  550 + tabList.add(tempList);
  551 + }
  552 + } else {
290 553 Map<Integer, Integer> areaCountMap = new HashMap<>();
291 554 String groupKey = StringUtils.isNotEmpty(cityId) ? "areaId" : "cityId"; // 按照区县或者市统计
292 555 for (Patients patient : patients) {
... ... @@ -448,6 +711,7 @@
448 711  
449 712 return RespBuilder.buildSuccess(restMap);
450 713 }
  714 +
451 715  
452 716 private void setCountList(List<List<String>> tabList, List<String> countList, int index) {
453 717 if(tabList.size() > 1) {