Commit ce30087bbd821bc62250bf5e30e184937d3c2b49
1 parent
4e7242e46a
Exists in
master
and in
1 other branch
统计
Showing 5 changed files with 120 additions and 41 deletions
- platform-common/src/main/java/com/lyms/platform/common/result/PageResult.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/ReportController.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/IReportService.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/CollectionUtils.java
platform-common/src/main/java/com/lyms/platform/common/result/PageResult.java
View file @
ce30087
| ... | ... | @@ -18,8 +18,8 @@ |
| 18 | 18 | public PageResult(Integer count, Integer page, Integer limit, |
| 19 | 19 | Object rows) { |
| 20 | 20 | this.count = count; |
| 21 | - this.page = page; | |
| 22 | - this.limit = limit; | |
| 21 | + this.page = page == null ? 1 : page;; | |
| 22 | + this.limit = limit == null ? 15 : limit; | |
| 23 | 23 | this.grid = rows; |
| 24 | 24 | // this.page = ((count - 1)/this.limit) + 1; |
| 25 | 25 | this.lastPage = ((count - 1)/this.limit) + 1; |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/ReportController.java
View file @
ce30087
| ... | ... | @@ -36,11 +36,25 @@ |
| 36 | 36 | @RequestMapping(value = "/coupon/unSend", method = RequestMethod.GET) |
| 37 | 37 | @ResponseBody |
| 38 | 38 | @TokenRequired |
| 39 | - public BaseObjectResponse unSend(Date startDate, Date endDate, String provinceId, String cityId, String areaId, String hospitalId, HttpServletRequest request) { | |
| 40 | - return reportService.unSend(startDate, endDate, provinceId, cityId, areaId, hospitalId, getUserId(request)); | |
| 39 | + public BaseObjectResponse unSend(Date startDate, Date endDate, String provinceId, String cityId, String areaId, String hospitalId, Integer page, Integer limit, HttpServletRequest request) { | |
| 40 | + return reportService.unSend(startDate, endDate, provinceId, cityId, areaId, hospitalId, page, limit, getUserId(request)); | |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - @RequestMapping(value = "/coupon/unSend/info", method = RequestMethod.POST) | |
| 43 | + /** | |
| 44 | + * 未发放优惠券统计导出 | |
| 45 | + */ | |
| 46 | + @RequestMapping(value = "/coupon/unSend/export", method = RequestMethod.GET) | |
| 47 | + @ResponseBody | |
| 48 | +// @TokenRequired | |
| 49 | + public void unSendExport(Date startDate, Date endDate, String provinceId, String cityId, String areaId, String hospitalId, HttpServletRequest request, HttpServletResponse response) { | |
| 50 | +// reportService.unSendExport(startDate, endDate, provinceId, cityId, areaId, hospitalId, getUserId(request), response); | |
| 51 | + reportService.unSendExport(startDate, endDate, provinceId, cityId, areaId, hospitalId, 1000000185, response); | |
| 52 | + } | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * 未发放优惠券统计详情 | |
| 56 | + */ | |
| 57 | + @RequestMapping(value = "/coupon/unSend/info", method = RequestMethod.GET) | |
| 44 | 58 | @ResponseBody |
| 45 | 59 | @TokenRequired |
| 46 | 60 | public BaseObjectResponse unSendInfo(Date startDate, Date endDate, String provinceId, String cityId, String areaId, String hospitalId, Integer page, Integer limit, HttpServletRequest request) { |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/IReportService.java
View file @
ce30087
| ... | ... | @@ -84,8 +84,10 @@ |
| 84 | 84 | |
| 85 | 85 | void checkNumberInfoExport(Integer childBirth, Date startDate, Date endDate, Integer startWeek, Integer endWeek, Integer number, Integer id, HttpServletResponse resp); |
| 86 | 86 | |
| 87 | - BaseObjectResponse unSend(Date startDate, Date endDate, String provinceId, String cityId, String areaId, String hospitalId, Integer userId); | |
| 87 | + BaseObjectResponse unSend(Date startDate, Date endDate, String provinceId, String cityId, String areaId, String hospitalId, Integer page, Integer limit, Integer userId); | |
| 88 | 88 | |
| 89 | 89 | BaseObjectResponse unSendInfo(Date startDate, Date endDate, String provinceId, String cityId, String areaId, String hospitalId, Integer page, Integer limit, Integer userId); |
| 90 | + | |
| 91 | + void unSendExport(Date startDate, Date endDate, String provinceId, String cityId, String areaId, String hospitalId, Integer userId, HttpServletResponse response); | |
| 90 | 92 | } |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java
View file @
ce30087
| ... | ... | @@ -493,47 +493,26 @@ |
| 493 | 493 | } |
| 494 | 494 | return null; |
| 495 | 495 | } |
| 496 | - | |
| 497 | - @Override | |
| 498 | - public BaseObjectResponse unSend(Date startDate, Date endDate, String provinceId, String cityId, String areaId, String hospitalId, Integer userId) { | |
| 496 | + | |
| 497 | + private List<String> getHospitalIds(Integer userId, String hospitalId) { | |
| 499 | 498 | List<String> hospitalIds = new ArrayList<>(); |
| 500 | 499 | if(StringUtils.isEmpty(hospitalId)) { |
| 501 | 500 | hospitalIds.addAll(accessPermissionFacade.getCurrentUserHospPermissions(userId)); |
| 502 | 501 | } else { |
| 503 | 502 | hospitalIds.add(hospitalId); |
| 504 | 503 | } |
| 504 | + return hospitalIds; | |
| 505 | + } | |
| 505 | 506 | |
| 507 | + @Override | |
| 508 | + public BaseObjectResponse unSend(Date startDate, Date endDate, String provinceId, String cityId, String areaId, String hospitalId, Integer page, Integer limit, Integer userId) { | |
| 509 | + List<String> hospitalIds = getHospitalIds(userId, hospitalId); | |
| 506 | 510 | List<Map<String, Object>> datas = couponMapper.findHospitalInfoByIds(hospitalIds); |
| 507 | - Iterator<String> iterator = hospitalIds.iterator(); | |
| 508 | - while (iterator.hasNext()) { | |
| 509 | - String id = iterator.next(); | |
| 510 | - if(StringUtils.isNotEmpty(provinceId)) { | |
| 511 | - if(!provinceId.equals(getValByKey(datas, id, "province_id"))) { | |
| 512 | - iterator.remove(); | |
| 513 | - } | |
| 514 | - } | |
| 515 | - if(StringUtils.isNotEmpty(cityId)) { | |
| 516 | - if(!cityId.equals(getValByKey(datas, id, "city_id"))) { | |
| 517 | - iterator.remove(); | |
| 518 | - } | |
| 519 | - } | |
| 520 | - if(StringUtils.isNotEmpty(areaId)) { | |
| 521 | - if(!areaId.equals(getValByKey(datas, id, "area_id"))) { | |
| 522 | - iterator.remove(); | |
| 523 | - } | |
| 524 | - } | |
| 525 | - } | |
| 526 | - | |
| 527 | 511 | List<Map<String, Object>> restList = new ArrayList<>(); |
| 528 | 512 | Map<String, Integer> hospitalPatientCount = new HashMap<>(); |
| 529 | - if(CollectionUtils.isNotEmpty(hospitalIds)) { | |
| 530 | - Criteria c = new Criteria(); | |
| 531 | - c.and("hospitalId").in(hospitalIds).and("isSendCoupon").ne(true).and("yn").ne(0); | |
| 532 | - if(startDate != null && endDate != null) { | |
| 533 | - c.and("bookbuildingDate").gte(startDate).lt(DateUtil.addDay(endDate, 1)); | |
| 534 | - } | |
| 535 | 513 | |
| 536 | - List<Patients> patients = mongoTemplate.find(Query.query(c), Patients.class); | |
| 514 | + if(CollectionUtils.isNotEmpty(hospitalIds)) { | |
| 515 | + List<Patients> patients = getPatients(hospitalIds, datas, startDate, endDate, provinceId, cityId, areaId, hospitalId, userId); | |
| 537 | 516 | for (Patients patient : patients) { |
| 538 | 517 | if(hospitalPatientCount.containsKey(patient.getHospitalId())) { |
| 539 | 518 | hospitalPatientCount.put(patient.getHospitalId(), hospitalPatientCount.get(patient.getHospitalId()) + 1); |
| ... | ... | @@ -544,7 +523,6 @@ |
| 544 | 523 | |
| 545 | 524 | for (Map.Entry<String, Integer> entry : hospitalPatientCount.entrySet()) { |
| 546 | 525 | Map<String, Object> tempMap = new HashMap<>(); |
| 547 | - tempMap.put("id", entry.getValue()); | |
| 548 | 526 | tempMap.put("areaId", getValByKey(datas, entry.getKey(), "area_id")); |
| 549 | 527 | tempMap.put("areaName", findName(tempMap.get("areaId"))); |
| 550 | 528 | tempMap.put("cityId", getValByKey(datas, entry.getKey(), "city_id")); |
| 551 | 529 | |
| 552 | 530 | |
| 553 | 531 | |
| 554 | 532 | |
| ... | ... | @@ -557,16 +535,99 @@ |
| 557 | 535 | restList.add(tempMap); |
| 558 | 536 | } |
| 559 | 537 | } |
| 560 | - return RespBuilder.buildSuccess(restList); | |
| 538 | + return RespBuilder.buildSuccess(new PageResult(restList.size(), page, limit, CollectionUtils.getPageIds(restList, page, limit))); | |
| 561 | 539 | } |
| 562 | 540 | |
| 563 | 541 | @Override |
| 542 | + public void unSendExport(Date startDate, Date endDate, String provinceId, String cityId, String areaId, String hospitalId, Integer userId, HttpServletResponse response) { | |
| 543 | + BaseObjectResponse rest = unSend(startDate, endDate, provinceId, cityId, areaId, hospitalId, 1, Integer.MAX_VALUE, userId); | |
| 544 | + PageResult pageResult = (PageResult) rest.getData(); | |
| 545 | + List<Map<String, Object>> datas = (List<Map<String, Object>>) pageResult.getGrid(); | |
| 546 | + Map<String, String> cnames = new LinkedHashMap<>(); | |
| 547 | + cnames.put("id", "#"); | |
| 548 | + cnames.put("cityName", "地市名称"); | |
| 549 | + cnames.put("areaName", "区县名称"); | |
| 550 | + cnames.put("hospitalName", "医院名称"); | |
| 551 | + cnames.put("count", "未发放人数"); | |
| 552 | + | |
| 553 | + List<Map<String,Object>> results = new ArrayList<>(); | |
| 554 | + if(org.apache.commons.collections.CollectionUtils.isNotEmpty(datas)) { | |
| 555 | + int i = 0; | |
| 556 | + for (Map<String, Object> data : datas) { | |
| 557 | + Map<String, Object> result = new LinkedHashMap<>(); | |
| 558 | + result.put("id", ++i); | |
| 559 | + result.put("cityName", data.get("cityName")); | |
| 560 | + result.put("areaName", data.get("areaName")); | |
| 561 | + result.put("hospitalName", data.get("hospitalName")); | |
| 562 | + result.put("count", data.get("count")); | |
| 563 | + results.add(result); | |
| 564 | + } | |
| 565 | + } | |
| 566 | + | |
| 567 | + ResponseUtil.responseExcel(cnames, results, response); | |
| 568 | + } | |
| 569 | + | |
| 570 | + | |
| 571 | + @Override | |
| 564 | 572 | public BaseObjectResponse unSendInfo(Date startDate, Date endDate, String provinceId, String cityId, String areaId, String hospitalId, Integer page, Integer limit, Integer userId) { |
| 565 | - return null; | |
| 573 | + List<String> hospitalIds = getHospitalIds(userId, hospitalId); | |
| 574 | + List<Map<String, Object>> datas = couponMapper.findHospitalInfoByIds(hospitalIds); | |
| 575 | + if(CollectionUtils.isNotEmpty(hospitalIds)) { | |
| 576 | + List<Patients> patients = getPatients(hospitalIds, datas, startDate, endDate, provinceId, cityId, areaId, hospitalId, userId); | |
| 577 | + List<Map<String, Object>> restList = new ArrayList<>(); | |
| 578 | + List<Patients> pageRows = CollectionUtils.getPageIds(patients, page, limit); | |
| 579 | + for (Patients patient : pageRows) { | |
| 580 | + Map<String, Object> temp = new HashMap<>(); | |
| 581 | + temp.put("username", patient.getUsername()); | |
| 582 | + temp.put("phone", com.lyms.platform.common.utils.StringUtils.encryPhone(patient.getPhone())); | |
| 583 | + String residenceAddress = findName(patient.getProvinceRegisterId()) + findName(patient.getCityRegisterId()) + findName(patient.getAreaRegisterId()) + findName(patient.getStreetRegisterId()) + patient.getAddressRegister(); | |
| 584 | + temp.put("residenceAddress", residenceAddress.replace("null", "")); /** 居住地 */ | |
| 585 | + String householdAddress = findName(patient.getProvinceId()) + findName(patient.getCityId()) + findName(patient.getAreaId()) + findName(patient.getStreetId()) + patient.getAddress(); | |
| 586 | + temp.put("householdAddress", householdAddress.replace("null", "")); /** 户籍地 */ | |
| 587 | + temp.put("lastMenses", DateUtil.getyyyy_MM_dd(patient.getLastMenses())); | |
| 588 | + temp.put("week", DateUtil.getWeekDesc(patient.getLastMenses(), new Date())); | |
| 589 | + temp.put("buildWeek", DateUtil.getWeekDesc(patient.getBookbuildingDate(), new Date())); | |
| 590 | + temp.put("buildWeek", DateUtil.getyyyy_MM_dd(patient.getBookbuildingDate())); | |
| 591 | + temp.put("doctorName", couponMapper.getUserName(patient.getBookbuildingDoctor())); | |
| 592 | + temp.put("hospitalName", couponMapper.findHospitalNameById(patient.getHospitalId())); | |
| 593 | + restList.add(temp); | |
| 594 | + } | |
| 595 | + PageResult pageResult = new PageResult(patients.size(), page, limit, restList); | |
| 596 | + return RespBuilder.buildSuccess(pageResult); | |
| 597 | + } | |
| 598 | + return RespBuilder.buildSuccess("hospitalIds为null"); | |
| 566 | 599 | } |
| 600 | + private List<Patients> getPatients(List<String> hospitalIds, List<Map<String, Object>> datas, Date startDate, Date endDate, String provinceId, String cityId, String areaId, String hospitalId, Integer userId) { | |
| 601 | + Iterator<String> iterator = hospitalIds.iterator(); | |
| 602 | + while (iterator.hasNext()) { | |
| 603 | + String id = iterator.next(); | |
| 604 | + if(StringUtils.isNotEmpty(provinceId)) { | |
| 605 | + if(!provinceId.equals(getValByKey(datas, id, "province_id"))) { | |
| 606 | + iterator.remove(); | |
| 607 | + continue; | |
| 608 | + } | |
| 609 | + } | |
| 610 | + if(StringUtils.isNotEmpty(cityId)) { | |
| 611 | + if(!cityId.equals(getValByKey(datas, id, "city_id"))) { | |
| 612 | + iterator.remove(); | |
| 613 | + continue; | |
| 614 | + } | |
| 615 | + } | |
| 616 | + if(StringUtils.isNotEmpty(areaId)) { | |
| 617 | + if(!areaId.equals(getValByKey(datas, id, "area_id"))) { | |
| 618 | + iterator.remove(); | |
| 619 | + continue; | |
| 620 | + } | |
| 621 | + } | |
| 622 | + } | |
| 623 | + Criteria c = new Criteria(); | |
| 624 | + c.and("hospitalId").in(hospitalIds).and("isSendCoupon").ne(true).and("yn").ne(0); | |
| 625 | + if(startDate != null && endDate != null) { | |
| 626 | + c.and("bookbuildingDate").gte(startDate).lt(DateUtil.addDay(endDate, 1)); | |
| 627 | + } | |
| 567 | 628 | |
| 568 | - private List<Patients> getPatients(Date startDate, Date endDate, String provinceId, String cityId, String areaId, String hospitalId, Integer userId) { | |
| 569 | - return null; | |
| 629 | + List<Patients> patients = mongoTemplate.find(Query.query(c), Patients.class); | |
| 630 | + return patients; | |
| 570 | 631 | } |
| 571 | 632 | |
| 572 | 633 | @Override |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/CollectionUtils.java
View file @
ce30087
| ... | ... | @@ -186,6 +186,8 @@ |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | public static <T> List<T> getPageIds(List<T> data, Integer page, Integer limit) { |
| 189 | + page = page == null ? 1 : page; | |
| 190 | + limit = limit == null ? 15 : limit; | |
| 189 | 191 | Integer startIndex = (page - 1) * limit; |
| 190 | 192 | Integer endIndex = startIndex + limit; |
| 191 | 193 | if(startIndex >= data.size()) { |