Commit 54643a26db30dfd0a27e69272ea1eb04fc38c530
Exists in
master
and in
6 other branches
Merge remote-tracking branch 'origin/master'
Showing 2 changed files
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/TempFacade.java
View file @
54643a2
| ... | ... | @@ -271,7 +271,7 @@ |
| 271 | 271 | |
| 272 | 272 | public BaseResponse getTemp(String parentId) { |
| 273 | 273 | List<Map<String, Object>> restList = new ArrayList<>(); |
| 274 | - List<TempModel> tempList = mongoTemplate.find(Query.query(Criteria.where("pid").is(parentId)).with(new Sort(Sort.Direction.ASC, "modified")), TempModel.class); | |
| 274 | + List<TempModel> tempList = mongoTemplate.find(Query.query(Criteria.where("pid").is(parentId)).with(new Sort(Sort.Direction.ASC, "created")), TempModel.class); | |
| 275 | 275 | if (CollectionUtils.isNotEmpty(tempList)) { |
| 276 | 276 | for (TempModel temp : tempList) { |
| 277 | 277 | if (temp != null && MapUtils.isNotEmpty(temp.getTempList())) { |
| ... | ... | @@ -287,7 +287,7 @@ |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | // com.lyms.platform.operate.web.utils.CollectionUtils.reverseList(restList); |
| 290 | - com.lyms.platform.operate.web.utils.CollectionUtils.sortListByMapKeyWithDate(restList, "date"); | |
| 290 | +// com.lyms.platform.operate.web.utils.CollectionUtils.sortListByMapKeyWithDate(restList, "date"); | |
| 291 | 291 | return RespBuilder.buildSuccess(restList); |
| 292 | 292 | } |
| 293 | 293 | } |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java
View file @
54643a2
| ... | ... | @@ -7,9 +7,11 @@ |
| 7 | 7 | import com.lyms.platform.common.enums.CouponEnums; |
| 8 | 8 | import com.lyms.platform.common.enums.FetalEnums; |
| 9 | 9 | import com.lyms.platform.common.enums.FuZhongEnums; |
| 10 | +import com.lyms.platform.common.enums.YnEnums; | |
| 10 | 11 | import com.lyms.platform.common.result.BaseObjectResponse; |
| 11 | 12 | import com.lyms.platform.common.result.PageResult; |
| 12 | 13 | import com.lyms.platform.common.result.RespBuilder; |
| 14 | +import com.lyms.platform.common.result.ResponseCode; | |
| 13 | 15 | import com.lyms.platform.common.utils.DateUtil; |
| 14 | 16 | import com.lyms.platform.common.utils.EnumUtil; |
| 15 | 17 | import com.lyms.platform.common.utils.PingYinUtil; |
| ... | ... | @@ -43,6 +45,9 @@ |
| 43 | 45 | import java.sql.ResultSet; |
| 44 | 46 | import java.sql.SQLException; |
| 45 | 47 | import java.util.*; |
| 48 | +import java.util.concurrent.Callable; | |
| 49 | +import java.util.concurrent.ExecutorService; | |
| 50 | +import java.util.concurrent.Executors; | |
| 46 | 51 | |
| 47 | 52 | /** |
| 48 | 53 | * @Author: litao |
| 49 | 54 | |
| ... | ... | @@ -1555,8 +1560,203 @@ |
| 1555 | 1560 | return ""; |
| 1556 | 1561 | } |
| 1557 | 1562 | |
| 1563 | + static class MongoDataCallable implements Callable<List> { | |
| 1564 | + | |
| 1565 | + private MongoTemplate mongoTemplate; | |
| 1566 | + | |
| 1567 | + private List<String> parentIds; | |
| 1568 | + | |
| 1569 | + private Class<?> clazz; | |
| 1570 | + | |
| 1571 | + public MongoDataCallable(MongoTemplate mongoTemplate, List<String> parentIds, Class<?> clazz) { | |
| 1572 | + this.mongoTemplate = mongoTemplate; | |
| 1573 | + this.parentIds = parentIds; | |
| 1574 | + this.clazz = clazz; | |
| 1575 | + } | |
| 1576 | + | |
| 1577 | + @Override | |
| 1578 | + public List call() throws Exception { | |
| 1579 | + return mongoTemplate.find(Query.query(Criteria.where("yn").is(YnEnums.YES.getId()).and("parentId").in(parentIds)), clazz); | |
| 1580 | + } | |
| 1581 | + | |
| 1582 | + } | |
| 1583 | + | |
| 1558 | 1584 | @Override |
| 1559 | 1585 | public BaseObjectResponse unUsed(Date startDate, Date endDate, String provinceId, String cityId, String areaId, String hospitalId, Integer page, Integer limit, Integer userId) { |
| 1586 | + try { | |
| 1587 | + List<String> hospitalIds = getHospitalIds(userId, hospitalId); | |
| 1588 | + List<Map<String, Object>> hospitals= couponMapper.findHospitalInfoByIds2(CollectionUtils.createMap("list", hospitalIds, "provinceId", provinceId, "cityId", cityId, "areaId", areaId)); | |
| 1589 | + | |
| 1590 | + Criteria c = new Criteria(); | |
| 1591 | + List<String> hids = CollectionUtils.getListByKey(hospitals, "id"); | |
| 1592 | + c.and("hospitalId").in(hids).and("yn").ne(0).and("enable").ne("2").and("buildType").ne(1).and("isSendCoupon").is(true); | |
| 1593 | + if(startDate != null && endDate != null) { | |
| 1594 | + c.and("bookbuildingDate").gte(startDate).lt(DateUtil.addDay(endDate, 1)); | |
| 1595 | + } | |
| 1596 | + | |
| 1597 | + /** 建档自动被使用 所以不统计 */ | |
| 1598 | + List<Patients> patients = mongoTemplate.find(Query.query(c).with(new Sort(Sort.Direction.DESC, "created")), Patients.class); | |
| 1599 | + List<String> parentIds = new ArrayList<>(); | |
| 1600 | + for (Patients patient : patients) { | |
| 1601 | + parentIds.add(patient.getId()); | |
| 1602 | + } | |
| 1603 | + | |
| 1604 | + ExecutorService executorService = Executors.newFixedThreadPool(5); | |
| 1605 | + List<AntExChuModel> antExChuModels = executorService.submit(new MongoDataCallable(mongoTemplate, parentIds, AntExChuModel.class)).get(); | |
| 1606 | + List<AntenatalExaminationModel> antenatalExaminationModels = executorService.submit(new MongoDataCallable(mongoTemplate, parentIds, AntenatalExaminationModel.class)).get(); | |
| 1607 | + List<MaternalDeliverModel> maternalDeliverModels = executorService.submit(new MongoDataCallable(mongoTemplate, parentIds, MaternalDeliverModel.class)).get(); | |
| 1608 | + List<DischargeAbstractMotherModel> deliverModels = executorService.submit(new MongoDataCallable(mongoTemplate, parentIds, DischargeAbstractMotherModel.class)).get(); | |
| 1609 | + List<PostReviewModel> postReviewModels = executorService.submit(new MongoDataCallable(mongoTemplate, parentIds, PostReviewModel.class)).get(); | |
| 1610 | + executorService.shutdown(); | |
| 1611 | + | |
| 1612 | + List<String> usedIds = getNeedUsedIds(patients, antExChuModels, antenatalExaminationModels, maternalDeliverModels, deliverModels, postReviewModels); | |
| 1613 | + List<Map<String, Object>> restList = new ArrayList<>(); | |
| 1614 | + if(CollectionUtils.isNotEmpty(usedIds)) { | |
| 1615 | + List<String> list = couponMapper.findUsededId(usedIds); | |
| 1616 | + usedIds.removeAll(list); | |
| 1617 | + | |
| 1618 | + Map<String, String> hospitalNameCache = new HashMap<>(); | |
| 1619 | + for (String hid : hids) { | |
| 1620 | + boolean flag = false; | |
| 1621 | + Set<String> unUsedIds = new HashSet<>(); // 未使用优惠券patientid | |
| 1622 | + List<Map<String, Object>> un_used_coupons = new ArrayList<>(); // 未使用优惠券详情 | |
| 1623 | + for (String usedId : usedIds) { | |
| 1624 | + if(checkHospital(patients, antExChuModels, antenatalExaminationModels, maternalDeliverModels, deliverModels, postReviewModels, hid, usedId)) { | |
| 1625 | + flag = true; | |
| 1626 | + Patients p = getParentByUsedId(patients, antExChuModels, antenatalExaminationModels, maternalDeliverModels, deliverModels, postReviewModels, usedId); | |
| 1627 | + if(p != null) { | |
| 1628 | + unUsedIds.add(p.getId()); | |
| 1629 | + Map<String, Object> map = new HashMap<>(); | |
| 1630 | + | |
| 1631 | + map.put("username", p.getUsername()); | |
| 1632 | + map.put("phone", com.lyms.platform.common.utils.StringUtils.encryPhone(p.getPhone())); | |
| 1633 | + map.put("cardNo", com.lyms.platform.common.utils.StringUtils.encryCardNo(p.getCardNo())); | |
| 1634 | + if(p.getType() == 3 || p.getBuildType() == 2) { | |
| 1635 | + map.put("week", "已分娩"); | |
| 1636 | + } else { | |
| 1637 | + map.put("week", DateUtil.getWeekDesc(p.getLastMenses(), new Date())); | |
| 1638 | + } | |
| 1639 | + Map<String, String> doctorNameCacheMap = new HashMap<>(); | |
| 1640 | + String doctorName = doctorNameCacheMap.get(p.getBookbuildingDoctor()); | |
| 1641 | + if(StringUtils.isEmpty(doctorName)) { | |
| 1642 | + doctorName = couponMapper.getUserName(p.getBookbuildingDoctor()); | |
| 1643 | + doctorNameCacheMap.put(p.getBookbuildingDoctor(), doctorName); | |
| 1644 | + } | |
| 1645 | + map.put("doctorName", doctorName); | |
| 1646 | + String hName = hospitalNameCache.get(p.getHospitalId()); | |
| 1647 | + if(StringUtils.isEmpty(hName)) { | |
| 1648 | + hName = couponMapper.findHospitalNameById(p.getHospitalId()); | |
| 1649 | + hospitalNameCache.put(p.getHospitalId(), hName); | |
| 1650 | + } | |
| 1651 | + map.put("hospitalName", hName); | |
| 1652 | + map.put("checkTime", getCheckTimeByUsedId(patients, antExChuModels, antenatalExaminationModels, maternalDeliverModels, deliverModels, postReviewModels, usedId)); | |
| 1653 | + un_used_coupons.add(map); | |
| 1654 | + } | |
| 1655 | + } | |
| 1656 | + | |
| 1657 | + } | |
| 1658 | + if(flag) { | |
| 1659 | + Map<String, Object> hospitalInfo = couponMapper.findHospitalInfoById(hid); | |
| 1660 | + hospitalInfo.put("cityName", findName(hospitalInfo.get("city_id"))); | |
| 1661 | + hospitalInfo.put("areaName", findName(hospitalInfo.get("area_id"))); | |
| 1662 | + hospitalInfo.put("un_used_coupons", un_used_coupons); | |
| 1663 | + hospitalInfo.put("un_used_coupon_count", un_used_coupons.size()); | |
| 1664 | + hospitalInfo.put("unUsedIds", unUsedIds); | |
| 1665 | + hospitalInfo.put("un_used_people", unUsedIds.size()); | |
| 1666 | + hospitalInfo.put("hospitalId", hid); | |
| 1667 | + hospitalInfo.put("hospitalName", hospitalInfo.get("name")); | |
| 1668 | + restList.add(hospitalInfo); | |
| 1669 | + } | |
| 1670 | + } | |
| 1671 | + } | |
| 1672 | + return RespBuilder.buildSuccess(new PageResult(restList.size(), page, limit, restList)); | |
| 1673 | + } catch (Exception e) { | |
| 1674 | + e.printStackTrace(); | |
| 1675 | + return RespBuilder.buildErro(ResponseCode.ERROR); | |
| 1676 | + } | |
| 1677 | + /*List<String> userIds = new ArrayList<>(); // 存储patientId | |
| 1678 | + for (Patients patient : patients) { | |
| 1679 | + userIds.add(patient.getPid()); | |
| 1680 | + } | |
| 1681 | + System.out.println(userIds); | |
| 1682 | +// Map<String, Object> param = CollectionUtils.createMap("hospitalIds", hospitalIds, "userIds", userIds, "provinceId", provinceId, "cityId", cityId, "areaId", areaId, "page", (page - 1) * limit, "limit", limit); | |
| 1683 | + if(CollectionUtils.isNotEmpty(userIds)) { | |
| 1684 | + Map<String, Object> param = CollectionUtils.createMap("hospitalIds", hospitalIds, "userIds", userIds, "provinceId", provinceId, "cityId", cityId, "areaId", areaId, "page", (page - 1) * limit, "limit", limit); | |
| 1685 | + List<Map<String, Object>> restList = new ArrayList<>(); | |
| 1686 | + for (String hid : hids) { | |
| 1687 | + param.put("hid", hid); | |
| 1688 | + List<Map<String, Object>> list = couponMapper.findUnUsed2(param); | |
| 1689 | + if(CollectionUtils.isNotEmpty(list)) { | |
| 1690 | + Map<String, Object> temp = new HashMap<>(); | |
| 1691 | + Set<String> unUsedIds = new HashSet<>(); // 存储patientId或者是babyId | |
| 1692 | + List<Map<String, Object>> unUsedCoupons = new ArrayList<>(); | |
| 1693 | + Integer unUsedCouponCount = 0; | |
| 1694 | + temp.putAll(list.get(0)); | |
| 1695 | + temp.put("cityName", findName(list.get(0).get("city_id"))); | |
| 1696 | + temp.put("areaName", findName(list.get(0).get("area_id"))); | |
| 1697 | + temp.remove("user_id"); | |
| 1698 | + | |
| 1699 | + Map<String, List<Map<String, Object>>> infos = new HashMap<>(); // key = patientId, value = 该patient所对应的所有优惠券 | |
| 1700 | + for (Patients p : patients) { | |
| 1701 | + for (Map<String,Object> coupon : list) { | |
| 1702 | + if(p.getPid().equals(coupon.get("user_id").toString())) { | |
| 1703 | + List<Map<String, Object>> coupons = infos.containsKey(p.getId()) ? infos.get(p.getId()) : new ArrayList<Map<String, Object>>(); | |
| 1704 | + coupons.add(coupon); | |
| 1705 | + infos.put(p.getId(), coupons); | |
| 1706 | + } | |
| 1707 | + } | |
| 1708 | + } | |
| 1709 | + for (Map.Entry<String, List<Map<String, Object>>> entry : infos.entrySet()) { | |
| 1710 | + String patientId = entry.getKey(); | |
| 1711 | + for (Patients p : patients) { | |
| 1712 | + if(p.getId().equals(patientId)) { | |
| 1713 | + for (Map<String, Object> map : entry.getValue()) { | |
| 1714 | + System.out.println(DateUtil.getyyyy_MM_dd_hms(p.getCreated()) + " >> " + DateUtil.getyyyy_MM_dd_hms(((Date) map.get("create_date")))); | |
| 1715 | + if(p.getFmDate() != null && p.getFmDate().getTime() < ((Date) map.get("create_date")).getTime()) { // 如果手动终止妊娠了, 那么fmDate应该小于优惠券发放的时间 | |
| 1716 | + continue; | |
| 1717 | + } | |
| 1718 | + if(p.getCreated().getTime() > ((Date) map.get("create_date")).getTime()) { // 同一个产程中 patient的创建时间肯定小于优惠券的创建时间 | |
| 1719 | + continue; | |
| 1720 | + } | |
| 1721 | + String checkTime = getCheckTime((Integer) map.get("type"), (String) map.get("user_id"), patientId); | |
| 1722 | + if(StringUtils.isNotEmpty(checkTime)) { * 如果没有做检查 那么返回的时间就是空字符串 这里等于做了检查但是没用券 | |
| 1723 | + unUsedIds.add(p.getId()); | |
| 1724 | + unUsedCouponCount ++; | |
| 1725 | + map.put("couponName", (couponReportMap.get(map.get("type") + "_" + map.get("coupon_order"))).toString() | |
| 1726 | + .replaceAll("使用人次", "") | |
| 1727 | + .replaceAll("<div class='ag-double-line'>", "") | |
| 1728 | + .replaceAll("<div>", "") | |
| 1729 | + .replaceAll("</div>", "")); | |
| 1730 | + map.put("username", p.getUsername()); | |
| 1731 | + map.put("phone", com.lyms.platform.common.utils.StringUtils.encryPhone(p.getPhone())); | |
| 1732 | + map.put("cardNo", com.lyms.platform.common.utils.StringUtils.encryCardNo(p.getCardNo())); | |
| 1733 | + map.put("week", DateUtil.getWeekDesc(p.getLastMenses(), new Date())); | |
| 1734 | + map.put("doctorName", couponMapper.getUserName(p.getBookbuildingDoctor())); | |
| 1735 | + map.put("hospitalName", couponMapper.findHospitalNameById(p.getHospitalId())); | |
| 1736 | + map.put("checkTime", checkTime); | |
| 1737 | + unUsedCoupons.add(map); | |
| 1738 | + } | |
| 1739 | + } | |
| 1740 | + } | |
| 1741 | + } | |
| 1742 | + } | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + temp.put("un_used_people", unUsedIds.size()); | |
| 1746 | + temp.put("unUsedIds", unUsedIds); | |
| 1747 | + temp.put("un_used_coupons", unUsedCoupons); | |
| 1748 | + temp.put("un_used_coupon_count", unUsedCouponCount); | |
| 1749 | + restList.add(temp); | |
| 1750 | + } | |
| 1751 | + } | |
| 1752 | + return RespBuilder.buildSuccess(new PageResult(restList.size(), page, limit, restList)); | |
| 1753 | + } | |
| 1754 | + return RespBuilder.buildSuccess(new PageResult(0, page, limit, null));*/ | |
| 1755 | + } | |
| 1756 | + | |
| 1757 | + | |
| 1758 | +// @Override | |
| 1759 | + public BaseObjectResponse unUsed2(Date startDate, Date endDate, String provinceId, String cityId, String areaId, String hospitalId, Integer page, Integer limit, Integer userId) { | |
| 1560 | 1760 | List<String> hospitalIds = getHospitalIds(userId, hospitalId); |
| 1561 | 1761 | List<Map<String, Object>> hospitals= couponMapper.findHospitalInfoByIds2(CollectionUtils.createMap("list", hospitalIds, "provinceId", provinceId, "cityId", cityId, "areaId", areaId)); |
| 1562 | 1762 |