Commit 350ef214d1ff4605527063133a34f20517978b8f

Authored by litao@lymsh.com
1 parent a5e216a811

改bug

Showing 2 changed files with 106 additions and 57 deletions

platform-biz-service/src/main/resources/mainOrm/master/CouponMapper.xml View file @ 350ef21
... ... @@ -711,7 +711,7 @@
711 711  
712 712  
713 713 <select id="findUnUsed2" parameterType="map" resultType="map">
714   - select a.user_id, c.type, d.city_id, d.area_id, d.name as hospitalName, d.province_id, a.create_hospital_id as hospitalId
  714 + select a.user_id, a.create_date, b.coupon_order, c.type, d.city_id, d.area_id, d.name as hospitalName, d.province_id, a.create_hospital_id as hospitalId
715 715 from coupon_info a, coupon_template b, coupon_type c, organization d
716 716 where a.coupon_template_id = b.id and b.type_id = c.id and a.status = 1 and d.id = a.create_hospital_id
717 717 and a.create_hospital_id = #{hid} and a.user_id in
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java View file @ 350ef21
... ... @@ -30,7 +30,6 @@
30 30 import org.springframework.data.mongodb.core.query.Query;
31 31 import org.springframework.stereotype.Service;
32 32 import org.springframework.util.Assert;
33   -import scala.annotation.target.param;
34 33  
35 34 import javax.servlet.http.HttpServletResponse;
36 35 import java.sql.PreparedStatement;
... ... @@ -579,7 +578,7 @@
579 578 for (Patients patient : patients) {
580 579 userIds.add(patient.getPid());
581 580 }
582   - List<Map<String, Object>> list = couponMapper.findUnUsedInfo(CollectionUtils.createMap("hospitalId", hospitalId, "userIds", userIds, "page", (page - 1) * limit, "limit", limit));
  581 + List<Map<String, Object>> list = couponMapper.findUnUsedInfo(CollectionUtils.createMap("hospitalId", hospitalId, "userIds", userIds));
583 582 List<Map<String, Object>> restList = new ArrayList<>();
584 583 for (Map<String, Object> map : list) {
585 584 map.put("couponName", (couponReportMap.get(map.get("type") + "_" + map.get("coupon_order"))).toString()
... ... @@ -597,7 +596,7 @@
597 596 map.put("hospitalName", couponMapper.findHospitalNameById(patient.getHospitalId()));
598 597 }
599 598 }
600   - map.put("checkTime", getCheckTime((Integer) map.get("type"), (String) map.get("user_id")));
  599 + map.put("checkTime", getCheckTime((Integer) map.get("type"), (String) map.get("user_id"), (Date) map.get("create_date")));
601 600 restList.add(map);
602 601 }
603 602 Integer count = couponMapper.findUnUsedInfoCount(CollectionUtils.createMap("userIds", userIds, "hospitalId", hospitalId));
604 603  
605 604  
606 605  
607 606  
608 607  
... ... @@ -619,55 +618,63 @@
619 618 * 9=新生儿访视 lyms_newborn_visit
620 619 * 10=血红蛋白检查 lyms_babycheck
621 620 */
622   - private String getCheckTime(Integer type, String userId) {
623   - if(type != null && StringUtils.isNotEmpty(userId)) {
624   - if(type == 1 || type == 3) {
625   - Patients patients = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)).with(new Sort(Sort.Direction.DESC, "created")), Patients.class);
626   - if(patients != null) {
627   - return DateUtil.getyyyy_MM_dd(patients.getBookbuildingDate());
  621 + private String getCheckTime(Integer type, String userId, Date createDate) {
  622 + String parentId = null;
  623 + List<Patients> patients = mongoTemplate.find(Query.query(Criteria.where("pid").is(userId)).with(new Sort(Sort.Direction.DESC, "created")), Patients.class);
  624 + for (Patients patient : patients) {
  625 + if(patient.getCreated().getTime() < createDate.getTime()) {
  626 + parentId = patient.getId();
  627 + if(type == 1 || type == 3) {
  628 + return DateUtil.getyyyy_MM_dd(patient.getBookbuildingDate());
628 629 }
629   - } else if(type == 2) {
630   - AntExChuModel exChuModel = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)).with(new Sort(Sort.Direction.DESC, "created")), AntExChuModel.class);
631   - if(exChuModel != null) {
632   - return DateUtil.getyyyy_MM_dd(exChuModel.getCheckTime());
633   - }
634   - AntenatalExaminationModel antenatalExaminationModel = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)).with(new Sort(Sort.Direction.DESC, "created")), AntenatalExaminationModel.class);
635   - if(antenatalExaminationModel != null) {
636   - return DateUtil.getyyyy_MM_dd(antenatalExaminationModel.getCheckDate());
637   - }
638   - } else if(type == 4) {
639   - MaternalDeliverModel md = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)).with(new Sort(Sort.Direction.DESC, "created")), MaternalDeliverModel.class);
640   - if(md != null) {
641   - return md.getDueDate();
642   - }
643   - } else if(type == 5) {
644   - DischargeAbstractMotherModel dischargeAbstractMotherModel = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)).with(new Sort(Sort.Direction.DESC, "created")), DischargeAbstractMotherModel.class);
645   - if(dischargeAbstractMotherModel != null) {
646   - return DateUtil.getyyyy_MM_dd(dischargeAbstractMotherModel.getLeaveHospitalDate());
647   - }
648   - } else if(type == 6) {
649   - PostReviewModel p = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)).with(new Sort(Sort.Direction.DESC, "created")), PostReviewModel.class);
650   - if(p != null) {
651   - return DateUtil.getyyyy_MM_dd(p.getCheckTime());
652   - }
653   - } else if(type == 7) {
654   - BabyModel b = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)).with(new Sort(Sort.Direction.DESC, "created")), BabyModel.class);
  630 + }
  631 + }
  632 + if(StringUtils.isEmpty(parentId) && type != 8 && type != 10) {
  633 + return "";
  634 + }
  635 + if(type == 2) {
  636 + AntExChuModel exChuModel = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId).and("parentId").is(parentId)).with(new Sort(Sort.Direction.DESC, "created")), AntExChuModel.class);
  637 + if(exChuModel != null) {
  638 + return DateUtil.getyyyy_MM_dd(exChuModel.getCheckTime());
  639 + }
  640 + AntenatalExaminationModel antenatalExaminationModel = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId).and("parentId").is(parentId)).with(new Sort(Sort.Direction.DESC, "created")), AntenatalExaminationModel.class);
  641 + if(antenatalExaminationModel != null) {
  642 + return DateUtil.getyyyy_MM_dd(antenatalExaminationModel.getCheckDate());
  643 + }
  644 + } else if(type == 4) {
  645 + MaternalDeliverModel md = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId).and("parentId").is(parentId)).with(new Sort(Sort.Direction.DESC, "created")), MaternalDeliverModel.class);
  646 + if(md != null) {
  647 + return md.getDueDate();
  648 + }
  649 + } else if(type == 5) {
  650 + DischargeAbstractMotherModel dischargeAbstractMotherModel = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId).and("parentId").is(parentId)).with(new Sort(Sort.Direction.DESC, "created")), DischargeAbstractMotherModel.class);
  651 + if(dischargeAbstractMotherModel != null) {
  652 + return DateUtil.getyyyy_MM_dd(dischargeAbstractMotherModel.getLeaveHospitalDate());
  653 + }
  654 + } else if(type == 6) {
  655 + PostReviewModel p = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId).and("parentId").is(parentId)).with(new Sort(Sort.Direction.DESC, "created")), PostReviewModel.class);
  656 + if(p != null) {
  657 + return DateUtil.getyyyy_MM_dd(p.getCheckTime());
  658 + }
  659 + } else if(type == 7) {
  660 + BabyModel b = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId).and("parentId").is(parentId)).with(new Sort(Sort.Direction.DESC, "created")), BabyModel.class);
  661 + if(b != null) {
  662 + return DateUtil.getyyyy_MM_dd(b.getBuildDate());
  663 + }
  664 + } else if(type == 8 || type == 10) {
  665 + BabyModel babyModel = mongoTemplate.findById(userId, BabyModel.class);
  666 + if(babyModel != null) {
  667 + BabyCheckModel b = mongoTemplate.findOne(Query.query(Criteria.where("buildId").is(babyModel.getId())).with(new Sort(Sort.Direction.DESC, "created")), BabyCheckModel.class);
655 668 if(b != null) {
656   - return DateUtil.getyyyy_MM_dd(b.getBuildDate());
657   - }
658   - } else if(type == 8 || type == 10) {
659   - BabyCheckModel b = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)).with(new Sort(Sort.Direction.DESC, "created")), BabyCheckModel.class);
660   - if(b != null) {
661 669 return DateUtil.getyyyy_MM_dd(b.getCheckDate());
662 670 }
663   - } else if(type == 9) {
664   - NewbornVisit b = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)).with(new Sort(Sort.Direction.DESC, "created")), NewbornVisit.class);
665   - if(b != null) {
666   - return DateUtil.getyyyy_MM_dd(b.getCheckTime());
667   - }
668 671 }
  672 + } else if(type == 9) {
  673 + NewbornVisit b = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)).with(new Sort(Sort.Direction.DESC, "created")), NewbornVisit.class);
  674 + if(b != null) {
  675 + return DateUtil.getyyyy_MM_dd(b.getCheckTime());
  676 + }
669 677 }
670   -
671 678 return "";
672 679 }
673 680  
674 681  
675 682  
676 683  
677 684  
... ... @@ -682,12 +689,18 @@
682 689 if(startDate != null && endDate != null) {
683 690 c.and("bookbuildingDate").gte(startDate).lt(DateUtil.addDay(endDate, 1));
684 691 }
685   - List<Patients> patients = mongoTemplate.find(Query.query(c).with(new Sort(Sort.Direction.DESC, "bookbuildingDate")), Patients.class);
  692 + List<Patients> patients = mongoTemplate.find(Query.query(c).with(new Sort(Sort.Direction.DESC, "created")), Patients.class);
686 693  
687   - Set<String> userIds = new HashSet<>();
  694 + List<String> userIds = new ArrayList<>();
  695 + List<Map<String, String>> patientInfos = new ArrayList<>();
688 696 for (Patients patient : patients) {
  697 + Map<String, String> temp = new HashMap<>();
  698 + temp.put("userId", patient.getPid());
  699 + temp.put("date", DateUtil.getyyyy_MM_dd(patient.getCreated()));
689 700 userIds.add(patient.getPid());
  701 + patientInfos.add(temp);
690 702 }
  703 + System.out.println(userIds);
691 704 // Map<String, Object> param = CollectionUtils.createMap("hospitalIds", hospitalIds, "userIds", userIds, "provinceId", provinceId, "cityId", cityId, "areaId", areaId, "page", (page - 1) * limit, "limit", limit);
692 705 if(CollectionUtils.isNotEmpty(userIds)) {
693 706 Map<String, Object> param = CollectionUtils.createMap("hospitalIds", hospitalIds, "userIds", userIds, "provinceId", provinceId, "cityId", cityId, "areaId", areaId, "page", (page - 1) * limit, "limit", limit);
694 707  
695 708  
... ... @@ -697,20 +710,56 @@
697 710 List<Map<String, Object>> list = couponMapper.findUnUsed2(param);
698 711 if(CollectionUtils.isNotEmpty(list)) {
699 712 Map<String, Object> temp = new HashMap<>();
700   - Set<String> unUsedUids = new HashSet<>();
  713 + Set<String> unUsedIds = new HashSet<>(); // 存储patientId或者是babyId
  714 + List<Map<String, Object>> unUsedCoupons = new ArrayList<>();
701 715 Integer unUsedCouponCount = 0;
702 716 temp.putAll(list.get(0));
703 717 temp.put("cityName", findName(list.get(0).get("city_id")));
704 718 temp.put("areaName", findName(list.get(0).get("area_id")));
705 719 temp.remove("user_id");
706   - for (Map<String, Object> map : list) {
707   - /** 如果没有做检查 那么返回的时间就是空字符串 */
708   - if (StringUtils.isNotEmpty(getCheckTime((Integer) map.get("type"), (String) map.get("user_id")))) {
709   - unUsedUids.add((String) map.get("user_id"));
710   - unUsedCouponCount++;
  720 +
  721 + Map<String, List<Map<String, Object>>> infos = new HashMap<>(); // key = patientId, value = 该patient所对应的所有优惠券
  722 + for (Patients p : patients) {
  723 + for (Map<String,Object> coupon : list) {
  724 + if(p.getPid().equals(coupon.get("user_id").toString())) {
  725 + List<Map<String, Object>> coupons = infos.containsKey(p.getId()) ? infos.get(p.getId()) : new ArrayList<Map<String, Object>>();
  726 + coupons.add(coupon);
  727 + infos.put(p.getId(), coupons);
  728 + }
711 729 }
712 730 }
713   - temp.put("un_used_people", unUsedUids.size());
  731 + for (Map.Entry<String, List<Map<String, Object>>> entry : infos.entrySet()) {
  732 + String patientId = entry.getKey();
  733 + for (Patients p : patients) {
  734 + if(p.getId().equals(patientId)) {
  735 + for (Map<String, Object> map : entry.getValue()) {
  736 + String checkTime = getCheckTime((Integer) map.get("type"), (String) map.get("user_id"), (Date) map.get("create_date"));
  737 + if(StringUtils.isNotEmpty(checkTime)) { /** 如果没有做检查 那么返回的时间就是空字符串 这里等于做了检查但是没用券 */
  738 + unUsedIds.add(p.getId());
  739 + unUsedCouponCount ++;
  740 + map.put("couponName", (couponReportMap.get(map.get("type") + "_" + map.get("coupon_order"))).toString()
  741 + .replaceAll("使用人次", "")
  742 + .replaceAll("<div class='ag-double-line'>", "")
  743 + .replaceAll("<div>", "")
  744 + .replaceAll("</div>", ""));
  745 + map.put("username", p.getUsername());
  746 + map.put("phone", com.lyms.platform.common.utils.StringUtils.encryPhone(p.getPhone()));
  747 + map.put("cardNo", com.lyms.platform.common.utils.StringUtils.encryCardNo(p.getCardNo()));
  748 + map.put("week", DateUtil.getWeekDesc(p.getLastMenses(), new Date()));
  749 + map.put("doctorName", couponMapper.getUserName(p.getBookbuildingDoctor()));
  750 + map.put("hospitalName", couponMapper.findHospitalNameById(p.getHospitalId()));
  751 + map.put("checkTime", checkTime);
  752 + unUsedCoupons.add(map);
  753 + }
  754 + }
  755 + }
  756 + }
  757 + }
  758 +
  759 +
  760 + temp.put("un_used_people", unUsedIds.size());
  761 + temp.put("unUsedIds", unUsedIds);
  762 + temp.put("un_used_coupons", unUsedCoupons);
714 763 temp.put("un_used_coupon_count", unUsedCouponCount);
715 764 restList.add(temp);
716 765 }
... ... @@ -811,7 +860,7 @@
811 860 for (Map<String, Object> map : lists) {
812 861 Integer type = (Integer) map.get("type");
813 862 String userId = (String) map.get("user_id");
814   - String checkTime = getCheckTime(type, userId);
  863 + String checkTime = getCheckTime(type, userId, (Date) map.get("create_date"));
815 864 if(!"".equals(checkTime)) { // 找到对应信息
816 865 temp.put(userId, false);
817 866 }