Commit cd7fb77d9739e0565affd5f019b7689c8abb863d
1 parent
a5c5845b8f
Exists in
master
and in
1 other branch
改bug
Showing 4 changed files with 155 additions and 32 deletions
- platform-biz-service/src/main/java/com/lyms/platform/permission/dao/master/CouponMapper.java
- platform-biz-service/src/main/resources/mainOrm/master/CouponMapper.xml
- 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-biz-service/src/main/java/com/lyms/platform/permission/dao/master/CouponMapper.java
View file @
cd7fb77
| ... | ... | @@ -118,5 +118,11 @@ |
| 118 | 118 | List<Map<String, Object>> findMulitPatienInfo(List<String> sendUserIds); |
| 119 | 119 | |
| 120 | 120 | List<Map<String,Object>> findUserSendInfoByUids(Map<String, Object> uids); |
| 121 | + | |
| 122 | + List<Map<String,Object>> findUnUsed2(Map<String, Object> param); | |
| 123 | + | |
| 124 | + List<Map<String,Object>> findUserTypeInfo(Map<String, Object> map); | |
| 125 | + | |
| 126 | + List<Map<String,Object>> findHospitalInfoByIds2(Map<String, Object> map); | |
| 121 | 127 | } |
platform-biz-service/src/main/resources/mainOrm/master/CouponMapper.xml
View file @
cd7fb77
| ... | ... | @@ -533,6 +533,22 @@ |
| 533 | 533 | </foreach> and yn = 1 |
| 534 | 534 | </select> |
| 535 | 535 | |
| 536 | + <select id="findHospitalInfoByIds2" parameterType="map" resultType="map"> | |
| 537 | + SELECT id, name, province_id, city_id, area_id FROM `organization` where id in | |
| 538 | + <foreach collection="list" item="id" open="(" separator="," close=")"> | |
| 539 | + #{id} | |
| 540 | + </foreach> and yn = 1 | |
| 541 | + <if test="provinceId != null and provinceId != ''"> | |
| 542 | + and province_id = #{provinceId} | |
| 543 | + </if> | |
| 544 | + <if test="cityId != null and cityId != '' "> | |
| 545 | + and city_id = #{cityId} | |
| 546 | + </if> | |
| 547 | + <if test="areaId != null and areaId != ''"> | |
| 548 | + and area_id = #{areaId} | |
| 549 | + </if> | |
| 550 | + </select> | |
| 551 | + | |
| 536 | 552 | <select id="findUnUsed" parameterType="map" resultType="map"> |
| 537 | 553 | select count(distinct(user_id)) as un_used_people, count(1) as un_used_coupon_count, b.province_id, b.city_id, b.area_id, b.name as hospitalName, a.create_hospital_id as hospitalId |
| 538 | 554 | from coupon_info a, organization b |
| 539 | 555 | |
| ... | ... | @@ -624,9 +640,9 @@ |
| 624 | 640 | <if test="areaId != null and areaId != ''"> |
| 625 | 641 | and b.area_id = #{areaId} |
| 626 | 642 | </if> |
| 627 | - <if test="page != null and limit != null"> | |
| 643 | + <!-- <if test="page != null and limit != null"> | |
| 628 | 644 | limit #{page}, #{limit} |
| 629 | - </if> | |
| 645 | + </if>--> | |
| 630 | 646 | </select> |
| 631 | 647 | |
| 632 | 648 | <select id="findUnUsedPeopleInfoCount" resultType="integer"> |
| ... | ... | @@ -691,6 +707,30 @@ |
| 691 | 707 | <foreach collection="uids" open="(" close=")" separator="," item="uid"> |
| 692 | 708 | #{uid} |
| 693 | 709 | </foreach>--> |
| 710 | + </select> | |
| 711 | + | |
| 712 | + | |
| 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 | |
| 715 | + from coupon_info a, coupon_template b, coupon_type c, organization d | |
| 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 | + and a.create_hospital_id = #{hid} and a.user_id in | |
| 718 | + <foreach collection="userIds" open="(" close=")" separator="," item="uid"> | |
| 719 | + #{uid} | |
| 720 | + </foreach> | |
| 721 | + order by a.create_date desc, a.user_id | |
| 722 | + </select> | |
| 723 | + | |
| 724 | + <select id="findUserTypeInfo" parameterType="map" resultType="map"> | |
| 725 | + select a.user_id, a.create_date, c.type, a.create_hospital_id as hospitalId | |
| 726 | + from coupon_info a, coupon_template b, coupon_type c | |
| 727 | + where a.coupon_template_id = b.id and b.type_id = c.id and a.status = 1 | |
| 728 | + and a.create_hospital_id = #{hospitalId} | |
| 729 | + and a.user_id in | |
| 730 | + <foreach collection="userIds" open="(" close=")" separator="," item="uid"> | |
| 731 | + #{uid} | |
| 732 | + </foreach> | |
| 733 | + order by a.user_id | |
| 694 | 734 | </select> |
| 695 | 735 | </mapper> |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java
View file @
cd7fb77
| ... | ... | @@ -30,6 +30,7 @@ |
| 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; | |
| 33 | 34 | |
| 34 | 35 | import javax.servlet.http.HttpServletResponse; |
| 35 | 36 | import java.sql.PreparedStatement; |
| 36 | 37 | |
| 37 | 38 | |
| 38 | 39 | |
| 39 | 40 | |
| 40 | 41 | |
| 41 | 42 | |
| 42 | 43 | |
| 43 | 44 | |
| 44 | 45 | |
| 45 | 46 | |
| ... | ... | @@ -615,48 +616,55 @@ |
| 615 | 616 | * 6=产妇产后复查 lyms_postreview |
| 616 | 617 | * 7=儿童建档 lyms_baby |
| 617 | 618 | * 8=儿童保健 lyms_babycheck |
| 619 | + * 9=新生儿访视 lyms_newborn_visit | |
| 620 | + * 10=血红蛋白检查 lyms_babycheck | |
| 618 | 621 | */ |
| 619 | 622 | private String getCheckTime(Integer type, String userId) { |
| 620 | 623 | if(type != null && StringUtils.isNotEmpty(userId)) { |
| 621 | 624 | if(type == 1 || type == 3) { |
| 622 | 625 | Patients patients = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)).with(new Sort(Sort.Direction.DESC, "created")), Patients.class); |
| 623 | 626 | if(patients != null) { |
| 624 | - return DateUtil.getyyyy_MM_dd(patients.getCreated()); | |
| 627 | + return DateUtil.getyyyy_MM_dd(patients.getBookbuildingDate()); | |
| 625 | 628 | } |
| 626 | 629 | } else if(type == 2) { |
| 627 | 630 | AntExChuModel exChuModel = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)).with(new Sort(Sort.Direction.DESC, "created")), AntExChuModel.class); |
| 628 | 631 | if(exChuModel != null) { |
| 629 | - return DateUtil.getyyyy_MM_dd(exChuModel.getCreated()); | |
| 632 | + return DateUtil.getyyyy_MM_dd(exChuModel.getCheckTime()); | |
| 630 | 633 | } |
| 631 | 634 | AntenatalExaminationModel antenatalExaminationModel = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)).with(new Sort(Sort.Direction.DESC, "created")), AntenatalExaminationModel.class); |
| 632 | 635 | if(antenatalExaminationModel != null) { |
| 633 | - return DateUtil.getyyyy_MM_dd(antenatalExaminationModel.getCreated()); | |
| 636 | + return DateUtil.getyyyy_MM_dd(antenatalExaminationModel.getCheckDate()); | |
| 634 | 637 | } |
| 635 | 638 | } else if(type == 4) { |
| 636 | 639 | MaternalDeliverModel md = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)).with(new Sort(Sort.Direction.DESC, "created")), MaternalDeliverModel.class); |
| 637 | - if(md != null && md.getCreated() != null) { | |
| 638 | - return DateUtil.getyyyy_MM_dd(md.getCreated()); | |
| 640 | + if(md != null) { | |
| 641 | + return md.getDueDate(); | |
| 639 | 642 | } |
| 640 | 643 | } else if(type == 5) { |
| 641 | 644 | DischargeAbstractMotherModel dischargeAbstractMotherModel = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)).with(new Sort(Sort.Direction.DESC, "created")), DischargeAbstractMotherModel.class); |
| 642 | 645 | if(dischargeAbstractMotherModel != null) { |
| 643 | - return DateUtil.getyyyy_MM_dd(dischargeAbstractMotherModel.getCreateDate()); | |
| 646 | + return DateUtil.getyyyy_MM_dd(dischargeAbstractMotherModel.getLeaveHospitalDate()); | |
| 644 | 647 | } |
| 645 | 648 | } else if(type == 6) { |
| 646 | 649 | PostReviewModel p = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)).with(new Sort(Sort.Direction.DESC, "created")), PostReviewModel.class); |
| 647 | - if(p != null && p.getCreated() != null) { | |
| 648 | - return DateUtil.getyyyy_MM_dd(p.getCreated()); | |
| 650 | + if(p != null) { | |
| 651 | + return DateUtil.getyyyy_MM_dd(p.getCheckTime()); | |
| 649 | 652 | } |
| 650 | 653 | } else if(type == 7) { |
| 651 | 654 | BabyModel b = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)).with(new Sort(Sort.Direction.DESC, "created")), BabyModel.class); |
| 652 | - if(b != null && b.getCreated() != null) { | |
| 653 | - return DateUtil.getyyyy_MM_dd(b.getCreated()); | |
| 655 | + if(b != null) { | |
| 656 | + return DateUtil.getyyyy_MM_dd(b.getBuildDate()); | |
| 654 | 657 | } |
| 655 | - } else if(type == 8) { | |
| 658 | + } else if(type == 8 || type == 10) { | |
| 656 | 659 | BabyCheckModel b = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(userId)).with(new Sort(Sort.Direction.DESC, "created")), BabyCheckModel.class); |
| 657 | - if(b != null && b.getCreated() != null) { | |
| 658 | - return DateUtil.getyyyy_MM_dd(b.getCreated()); | |
| 660 | + if(b != null) { | |
| 661 | + return DateUtil.getyyyy_MM_dd(b.getCheckDate()); | |
| 659 | 662 | } |
| 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 | + } | |
| 660 | 668 | } |
| 661 | 669 | } |
| 662 | 670 | |
| 663 | 671 | |
| 664 | 672 | |
| 665 | 673 | |
| ... | ... | @@ -666,27 +674,53 @@ |
| 666 | 674 | @Override |
| 667 | 675 | public BaseObjectResponse unUsed(Date startDate, Date endDate, String provinceId, String cityId, String areaId, String hospitalId, Integer page, Integer limit, Integer userId) { |
| 668 | 676 | List<String> hospitalIds = getHospitalIds(userId, hospitalId); |
| 669 | - if(CollectionUtils.isNotEmpty(hospitalIds)) { | |
| 670 | - List<Map<String, Object>> datas = couponMapper.findHospitalInfoByIds(hospitalIds); | |
| 671 | - List<Patients> patients = getPatients(hospitalIds, datas, startDate, endDate, provinceId, cityId, areaId, true); | |
| 672 | - if(CollectionUtils.isNotEmpty(patients)) { | |
| 673 | - Set<String> userIds = new HashSet<>(); | |
| 674 | - for (Patients patient : patients) { | |
| 675 | - userIds.add(patient.getPid()); | |
| 677 | + List<Map<String, Object>> hospitals= couponMapper.findHospitalInfoByIds2(CollectionUtils.createMap("list", hospitalIds, "provinceId", provinceId, "cityId", cityId, "areaId", areaId)); | |
| 678 | + | |
| 679 | + Criteria c = new Criteria(); | |
| 680 | + List<String> hids = CollectionUtils.getListByKey(hospitals, "id"); | |
| 681 | + c.and("hospitalId").in(hids).and("yn").ne(0).and("enable").ne("2").and("buildType").ne(1).and("isSendCoupon").is(true); | |
| 682 | + if(startDate != null && endDate != null) { | |
| 683 | + c.and("bookbuildingDate").gte(startDate).lt(DateUtil.addDay(endDate, 1)); | |
| 684 | + } | |
| 685 | + List<Patients> patients = mongoTemplate.find(Query.query(c).with(new Sort(Sort.Direction.DESC, "bookbuildingDate")), Patients.class); | |
| 686 | + | |
| 687 | + Set<String> userIds = new HashSet<>(); | |
| 688 | + for (Patients patient : patients) { | |
| 689 | + userIds.add(patient.getPid()); | |
| 690 | + } | |
| 691 | +// Map<String, Object> param = CollectionUtils.createMap("hospitalIds", hospitalIds, "userIds", userIds, "provinceId", provinceId, "cityId", cityId, "areaId", areaId, "page", (page - 1) * limit, "limit", limit); | |
| 692 | + if(CollectionUtils.isNotEmpty(userIds)) { | |
| 693 | + Map<String, Object> param = CollectionUtils.createMap("hospitalIds", hospitalIds, "userIds", userIds, "provinceId", provinceId, "cityId", cityId, "areaId", areaId, "page", (page - 1) * limit, "limit", limit); | |
| 694 | + List<Map<String, Object>> restList = new ArrayList<>(); | |
| 695 | + for (String hid : hids) { | |
| 696 | + param.put("hid", hid); | |
| 697 | + List<Map<String, Object>> list = couponMapper.findUnUsed2(param); | |
| 698 | + if(CollectionUtils.isNotEmpty(list)) { | |
| 699 | + Map<String, Object> temp = new HashMap<>(); | |
| 700 | + Set<String> unUsedUids = new HashSet<>(); | |
| 701 | + Integer unUsedCouponCount = 0; | |
| 702 | + temp.putAll(list.get(0)); | |
| 703 | + temp.put("cityName", findName(list.get(0).get("city_id"))); | |
| 704 | + temp.put("areaName", findName(list.get(0).get("area_id"))); | |
| 705 | + 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++; | |
| 711 | + } | |
| 712 | + } | |
| 713 | + temp.put("un_used_people", unUsedUids.size()); | |
| 714 | + temp.put("un_used_coupon_count", unUsedCouponCount); | |
| 715 | + restList.add(temp); | |
| 676 | 716 | } |
| 677 | - Map<String, Object> param = CollectionUtils.createMap("hospitalIds", hospitalIds, "userIds", userIds, "provinceId", provinceId, "cityId", cityId, "areaId", areaId, "page", (page - 1) * limit, "limit", limit); | |
| 678 | - List<Map<String, Object>> restList = couponMapper.findUnUsed(param); | |
| 679 | - for (Map<String, Object> map : restList) { | |
| 680 | - map.put("cityName", findName(map.get("city_id"))); | |
| 681 | - map.put("areaName", findName(map.get("area_id"))); | |
| 682 | - } | |
| 683 | - Integer count = couponMapper.findUnUsedCount(param); | |
| 684 | - return RespBuilder.buildSuccess(new PageResult(count, page, limit, restList)); | |
| 685 | 717 | } |
| 718 | + return RespBuilder.buildSuccess(new PageResult(restList.size(), page, limit, restList)); | |
| 686 | 719 | } |
| 687 | 720 | return RespBuilder.buildSuccess(new PageResult(0, page, limit, null)); |
| 688 | 721 | } |
| 689 | 722 | |
| 723 | + | |
| 690 | 724 | @Override |
| 691 | 725 | public void unUsedExport(Date startDate, Date endDate, String provinceId, String cityId, String areaId, String hospitalId, Integer userId, HttpServletResponse response) { |
| 692 | 726 | BaseObjectResponse rest = unUsed(startDate, endDate, provinceId, cityId, areaId, hospitalId, 1, Integer.MAX_VALUE, userId); |
| 693 | 727 | |
| ... | ... | @@ -730,8 +764,11 @@ |
| 730 | 764 | } |
| 731 | 765 | Map<String, Object> param = CollectionUtils.createMap("hospitalId", hospitalId, "userIds", userIds, "provinceId", provinceId, "cityId", cityId, "areaId", areaId, "page", (page - 1) * limit, "limit", limit); |
| 732 | 766 | List<String> pids = couponMapper.findUnUsedPeopleInfo(param); |
| 767 | + doFilter(pids, hospitalId); | |
| 733 | 768 | if(CollectionUtils.isNotEmpty(pids)) { |
| 734 | - Integer count = couponMapper.findUnUsedPeopleInfoCount(param); | |
| 769 | +// Integer count = couponMapper.findUnUsedPeopleInfoCount(param); | |
| 770 | + Integer count = pids.size(); | |
| 771 | + pids = CollectionUtils.getPageIds(pids, page, limit); | |
| 735 | 772 | List<Map<String, Object>> restList = new ArrayList<>(); |
| 736 | 773 | for (String pid : pids) { |
| 737 | 774 | Map<String, Object> temp = new HashMap<>(); |
| ... | ... | @@ -756,6 +793,36 @@ |
| 756 | 793 | } |
| 757 | 794 | } |
| 758 | 795 | return RespBuilder.buildSuccess(new PageResult(0, page, limit, null)); |
| 796 | + } | |
| 797 | + | |
| 798 | + /** | |
| 799 | + * 过滤掉全部优惠券所对应的项目都没做的userid | |
| 800 | + * @param userIds | |
| 801 | + */ | |
| 802 | + private void doFilter(List<String> userIds, String hospitalId) { | |
| 803 | + if(CollectionUtils.isNotEmpty(userIds) && StringUtils.isNotEmpty(hospitalId)) { | |
| 804 | + List<Map<String, Object>> lists = couponMapper.findUserTypeInfo(CollectionUtils.createMap("userIds", userIds, "hospitalId", hospitalId)); | |
| 805 | + if(CollectionUtils.isNotEmpty(lists)) { | |
| 806 | + // key = user_id, value = isRemove 默认true | |
| 807 | + Map<String, Boolean> temp = new HashMap<>(); | |
| 808 | + for (String userId : userIds) { | |
| 809 | + temp.put(userId, true); | |
| 810 | + } | |
| 811 | + for (Map<String, Object> map : lists) { | |
| 812 | + Integer type = (Integer) map.get("type"); | |
| 813 | + String userId = (String) map.get("user_id"); | |
| 814 | + String checkTime = getCheckTime(type, userId); | |
| 815 | + if(!"".equals(checkTime)) { // 找到对应信息 | |
| 816 | + temp.put(userId, false); | |
| 817 | + } | |
| 818 | + } | |
| 819 | + for (Map.Entry<String, Boolean> entry : temp.entrySet()) { | |
| 820 | + if(entry.getValue()) { | |
| 821 | + userIds.remove(entry.getKey()); | |
| 822 | + } | |
| 823 | + } | |
| 824 | + } | |
| 825 | + } | |
| 759 | 826 | } |
| 760 | 827 | |
| 761 | 828 |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/CollectionUtils.java
View file @
cd7fb77
| 1 | 1 | package com.lyms.platform.operate.web.utils; |
| 2 | 2 | |
| 3 | 3 | import org.apache.commons.collections.MapUtils; |
| 4 | -import org.apache.commons.collections.map.HashedMap; | |
| 5 | 4 | import org.apache.commons.lang3.StringUtils; |
| 6 | 5 | import org.springframework.util.Assert; |
| 7 | 6 | |
| ... | ... | @@ -14,6 +13,17 @@ |
| 14 | 13 | */ |
| 15 | 14 | public class CollectionUtils extends org.apache.commons.collections.CollectionUtils { |
| 16 | 15 | private CollectionUtils(){} |
| 16 | + | |
| 17 | + public static List<String> getListByKey(List<Map<String, Object>> datas, String key) { | |
| 18 | + List<String> rest = new ArrayList<>(); | |
| 19 | + if(isNotEmpty(datas)) { | |
| 20 | + for (Map<String, Object> data : datas) { | |
| 21 | + Object value = data.get(key); | |
| 22 | + rest.add(value == null ? null : value + ""); | |
| 23 | + } | |
| 24 | + } | |
| 25 | + return rest; | |
| 26 | + } | |
| 17 | 27 | |
| 18 | 28 | public static Map<String,Object> createMap(Object ... args){ |
| 19 | 29 | Assert.notNull(args, "参数不能为null"); |