Commit aa929905d6320da510db41cea8fe3577aad8d807

Authored by shiyang
1 parent d94a672663

秦皇岛-区域妇幼管理-区域妇幼统计-孕期优惠券使用统计: 年龄筛选 <35 岁

Showing 4 changed files with 305 additions and 4 deletions

platform-biz-service/src/main/java/com/lyms/platform/permission/dao/master/CouponMapper.java View file @ aa92990
... ... @@ -155,5 +155,12 @@
155 155  
156 156 Map<String,Object> findHospitalAllused(Map<String, Object> param);
157 157  
  158 + List<String> findHospitalUsedInfo2Ids(Map<String, Object> param);
  159 +
  160 + List<String> findHospitalSendInfo2Ids(Map<String, Object> param);
  161 +
  162 + List<String> findUsedInfo2ids(Map<String, Object> param);
  163 +
  164 + List<String> findCouponInfoCount2Ids(Map<String, Object> param);
158 165 }
platform-biz-service/src/main/resources/mainOrm/master/CouponMapper.xml View file @ aa92990
... ... @@ -356,6 +356,30 @@
356 356 group by b.coupon_order, b.type, a.used_hospital_id
357 357 </select>
358 358  
  359 + <select id="findUsedInfo2ids" parameterType="map" resultType="string">
  360 + select a.user_id as ids
  361 + from coupon_info a, (
  362 + select a.id, a.coupon_order, b.type, d.hospital_id
  363 + from coupon_template a, coupon_type b, hospital_coupon_template_group d
  364 + where a.group_id = d.coupon_template_group_id and b.id = a.type_id and d.hospital_id in
  365 + <foreach collection="hospitalId" open="(" close=")" separator="," item="hid">
  366 + #{hid}
  367 + </foreach>
  368 + and b.type in
  369 + <foreach collection="couponType" open="(" close=")" separator="," item="type">
  370 + #{type}
  371 + </foreach>
  372 + ) b
  373 + where a.used_hospital_id = b.hospital_id and a.coupon_template_id = b.id and a.status = 2
  374 + <if test="startDate != null">
  375 + and a.use_date >= #{startDate}
  376 + </if>
  377 + <if test="endDate != null">
  378 + and a.use_date <![CDATA[ < ]]> #{endDate}
  379 + </if>
  380 +
  381 + </select>
  382 +
359 383 <select id="findUsedUserIds" parameterType="map" resultType="string">
360 384 select distinct( user_id) from (select c.id from coupon_template c INNER JOIN (select id from coupon_type d where d.type in
361 385 <foreach collection="couponType" open="(" close=")" separator="," item="type">
... ... @@ -537,6 +561,48 @@
537 561 and b.use_date <![CDATA[ < ]]> #{endDate}
538 562 </if> -->
539 563 </select>
  564 + <select id="findHospitalUsedInfo2Ids" parameterType="map" resultType="string">
  565 + SELECT
  566 + distinct(user_id)
  567 + FROM
  568 + (
  569 + SELECT
  570 + c.id
  571 + FROM
  572 + coupon_template c
  573 + INNER JOIN (
  574 + SELECT
  575 + id
  576 + FROM
  577 + coupon_type d
  578 + WHERE
  579 + d.type IN
  580 + <foreach collection="couponType" open="(" close=")" separator="," item="type">
  581 + #{type}
  582 + </foreach>
  583 + ) t ON c.type_id = t.id
  584 + ) m
  585 + INNER JOIN (
  586 + SELECT
  587 + coupon_template_id,
  588 + STATUS,
  589 + use_date,
  590 + user_id,
  591 + used_hospital_id
  592 + FROM
  593 + coupon_info
  594 + WHERE
  595 + used_hospital_id = #{hid}
  596 + AND STATUS = 2
  597 + <if test="startDate != null">
  598 + and use_date >= #{startDate}
  599 + </if>
  600 + <if test="endDate != null">
  601 + and use_date <![CDATA[ < ]]> #{endDate}
  602 + </if>
  603 + ) a ON m.id = a.coupon_template_id
  604 + INNER JOIN organization o ON a.used_hospital_id = o.id
  605 + </select>
540 606  
541 607 <select id="findSendUserIds" parameterType="map" resultType="string">
542 608 select distinct(b.user_id)
543 609  
... ... @@ -699,7 +765,50 @@
699 765 and b.create_date <![CDATA[ < ]]> #{endDate}
700 766 </if>-->
701 767 </select>
  768 + <select id="findHospitalSendInfo2Ids" parameterType="map" resultType="string">
702 769  
  770 + SELECT
  771 + distinct(user_id)
  772 + FROM
  773 + (
  774 + SELECT
  775 + c.id
  776 + FROM
  777 + coupon_template c
  778 + INNER JOIN (
  779 + SELECT
  780 + id
  781 + FROM
  782 + coupon_type d
  783 + WHERE
  784 + d.type IN
  785 + <foreach collection="couponType" open="(" close=")" separator="," item="type">
  786 + #{type}
  787 + </foreach>
  788 + ) t ON c.type_id = t.id
  789 + ) m
  790 + INNER JOIN (
  791 + SELECT
  792 + coupon_template_id,
  793 + STATUS,
  794 + use_date,
  795 + user_id,
  796 + used_hospital_id,
  797 + create_hospital_id
  798 + FROM
  799 + coupon_info
  800 + WHERE
  801 + create_hospital_id = #{hid}
  802 + <if test="startDate != null">
  803 + and create_date >= #{startDate}
  804 + </if>
  805 + <if test="endDate != null">
  806 + and create_date <![CDATA[ < ]]> #{endDate}
  807 + </if>
  808 + ) a ON m.id = a.coupon_template_id
  809 + INNER JOIN organization o ON a.create_hospital_id = o.id
  810 + </select>
  811 +
703 812 <select id="findHospitalNameById" parameterType="string" resultType="string">
704 813 select name from organization where id = #{id}
705 814 </select>
... ... @@ -858,6 +967,44 @@
858 967 </if>
859 968  
860 969 ) a
  970 + </select>
  971 + <select id="findCouponInfoCount2Ids" parameterType="map" resultType="string">
  972 +
  973 + select
  974 + a.used_id
  975 + from coupon_info a, coupon_template b, coupon_type c, organization d
  976 + where a.coupon_template_id = b.id and b.type_id = c.id and a.create_hospital_id = d.id
  977 + and a.status = 2
  978 + and a.used_hospital_id in
  979 + <foreach collection="hospitalId" open="(" close=")" separator="," item="hid">
  980 + #{hid}
  981 + </foreach>
  982 + and c.type in
  983 + <foreach collection="couponType" open="(" close=")" separator="," item="type">
  984 + #{type}
  985 + </foreach>
  986 +
  987 + <if test="keys.size()>0">
  988 + and a.user_id in
  989 + <foreach collection="keys" open="(" close=")" separator="," item="key">
  990 + #{key}
  991 + </foreach>
  992 + </if>
  993 +
  994 + <if test="coupon_order != null">
  995 + and b.coupon_order = #{coupon_order}
  996 + </if>
  997 + <if test="startDate != null">
  998 + and a.use_date >= #{startDate}
  999 + </if>
  1000 + <if test="doctor != null">
  1001 + and a.operator_use_id = #{doctor}
  1002 + </if>
  1003 + <if test="endDate != null">
  1004 + and a.use_date <![CDATA[ < ]]> #{endDate}
  1005 + </if>
  1006 +
  1007 +
861 1008 </select>
862 1009  
863 1010 <select id="doHospitalFilter" parameterType="map" resultType="string">
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/ReportController.java View file @ aa92990
... ... @@ -413,11 +413,11 @@
413 413 @TokenRequired
414 414 @RequestMapping(value = "/coupon", method = RequestMethod.GET)
415 415 public BaseObjectResponse coupon(HttpServletRequest request, Date startDate, Date endDate,
416   - String provinceId, String cityId, String areaId, String hospitalId, String tempId, String couponType) {
  416 + String provinceId, String cityId, String areaId, String hospitalId, String tempId, String couponType,Integer age) {
417 417 Map<String, Object> param = CollectionUtils.createMap("userId", getUserId(request), "startDate", startDate,
418 418 "endDate", endDate != null ? DateUtil.addDay(endDate, 1) : endDate,
419 419 "hospitalId", hospitalId, "provinceId", provinceId, "cityId", cityId, "areaId",
420   - areaId, "tempId", tempId, "couponType", CollectionUtils.asList(couponType));
  420 + areaId, "tempId", tempId, "couponType", CollectionUtils.asList(couponType),"age",age);
421 421 return reportService.coupon(param);
422 422 }
423 423  
424 424  
... ... @@ -440,10 +440,10 @@
440 440 @RequestMapping(value = "/coupon/info", method = RequestMethod.GET)
441 441 public BaseObjectResponse couponInfo(HttpServletRequest request, Date startDate, Date endDate, Integer type,
442 442 String provinceId, String cityId, String areaId, String hospitalId, String tempId, String couponType,
443   - Integer page, Integer limit) {
  443 + Integer page, Integer limit,Integer age) {
444 444 Map<String, Object> param = CollectionUtils.createMap("userId", getUserId(request), "startDate", startDate,
445 445 "endDate", endDate != null ? DateUtil.addDay(endDate, 1) : endDate, "hospitalId", CollectionUtils.asList(hospitalId), "provinceId", provinceId, "cityId", cityId, "areaId", areaId, "type", type,
446   - "tempId", tempId, "couponType",couponType, "currentPage", page, "pageSize", limit, "currentPage2", page, "pageSize2", limit);
  446 + "tempId", tempId, "couponType",couponType, "currentPage", page, "pageSize", limit, "currentPage2", page, "pageSize2", limit,"age",age);
447 447 return reportService.couponInfo(param);
448 448 }
449 449  
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java View file @ aa92990
... ... @@ -2607,7 +2607,47 @@
2607 2607 for (String hid : hospitalIds) {
2608 2608 queryParam.put("hid", hid);
2609 2609 Map<String, Object> usedInfo = couponMapper.findHospitalUsedInfo2(queryParam);
  2610 +
  2611 + //秦皇岛年龄筛选 <35 岁(大于等于35需要减1次)
  2612 + if(null!=queryParam.get("age") && MapUtils.isNotEmpty(usedInfo) && usedInfo.get("id") != null) {
  2613 + List<String> usedInfoId = couponMapper.findHospitalUsedInfo2Ids(queryParam);
  2614 + for (String s : usedInfoId) {
  2615 + PersonModel personModel = mongoTemplate.findOne(Query.query(Criteria.where("id").is(s)), PersonModel.class);
  2616 + if (null != personModel) {
  2617 + Integer age = DateUtil.getAge(personModel.getBirth());
  2618 + if (age >= 35) {
  2619 + if (null != usedInfo.get("user_used_count") && 0 != (long) usedInfo.get("user_used_count")) {
  2620 + usedInfo.put("user_used_count", (long) usedInfo.get("user_used_count") - 1);
  2621 + }
  2622 + if (null != usedInfo.get("coupon_used_count") && 0 != (long) usedInfo.get("coupon_used_count")) {
  2623 + usedInfo.put("coupon_used_count", (long) usedInfo.get("coupon_used_count") - 1);
  2624 + }
  2625 + }
  2626 + }
  2627 + }
  2628 + }
  2629 +
2610 2630 Map<String, Object> sendInfo = couponMapper.findHospitalSendInfo2(queryParam);
  2631 +
  2632 + //秦皇岛年龄筛选 <35 岁(大于等于35需要减1次)
  2633 + if(null!=queryParam.get("age") && MapUtils.isNotEmpty(sendInfo) && sendInfo.get("id") != null) {
  2634 + List<String> sendInfoId = couponMapper.findHospitalSendInfo2Ids(queryParam);
  2635 + for (String s : sendInfoId) {
  2636 + PersonModel personModel = mongoTemplate.findOne(Query.query(Criteria.where("id").is(s)), PersonModel.class);
  2637 + if (null != personModel) {
  2638 + Integer age = DateUtil.getAge(personModel.getBirth());
  2639 + if (age >= 35) {
  2640 + if (null != sendInfo.get("people_send_count") && 0 != (long) sendInfo.get("people_send_count")) {
  2641 + sendInfo.put("people_send_count", (long) sendInfo.get("people_send_count") - 1);
  2642 + }
  2643 + if (null != sendInfo.get("coupon_send_count") && 0 != (long) sendInfo.get("coupon_send_count")) {
  2644 + sendInfo.put("coupon_send_count", (long) sendInfo.get("coupon_send_count") - 1);
  2645 + }
  2646 + }
  2647 + }
  2648 + }
  2649 + }
  2650 +
2611 2651 Map<String, Object> allusedInfo = couponMapper.findHospitalAllused(queryParam);
2612 2652  
2613 2653 Map<String, Object> tempMap = packCouponMap(sendInfo, usedInfo, hNameMap, hid, xAxis, queryParam);
... ... @@ -2618,6 +2658,31 @@
2618 2658 /** 方法/使用人数id */
2619 2659 List<String> sendUserIds = couponMapper.findSendUserIds2(queryParam);
2620 2660 List<String> usedUserIds = couponMapper.findUsedUserIds2(queryParam);
  2661 + //秦皇岛年龄筛选 <35 岁(大于等于35需要移除)
  2662 + if(null!=queryParam.get("age")) {
  2663 + Iterator<String> iterator = sendUserIds.iterator();
  2664 + while (iterator .hasNext()) {
  2665 + String id= iterator.next();
  2666 + PersonModel personModel = mongoTemplate.findOne(Query.query(Criteria.where("id").is(id)), PersonModel.class);
  2667 + if (null != personModel) {
  2668 + Integer age = DateUtil.getAge(personModel.getBirth());
  2669 + if (age >= 35) {
  2670 + iterator.remove();
  2671 + }
  2672 + }
  2673 + }
  2674 + Iterator<String> iterator2 = usedUserIds.iterator();
  2675 + while (iterator2 .hasNext()) {
  2676 + String id= iterator2.next();
  2677 + PersonModel personModel = mongoTemplate.findOne(Query.query(Criteria.where("id").is(id)), PersonModel.class);
  2678 + if (null != personModel) {
  2679 + Integer age = DateUtil.getAge(personModel.getBirth());
  2680 + if (age >= 35) {
  2681 + iterator2.remove();
  2682 + }
  2683 + }
  2684 + }
  2685 + }
2621 2686 tempMap.put("sendUserIds", sendUserIds);
2622 2687 tempMap.put("usedUserIds", usedUserIds);
2623 2688 couponReports.add(tempMap);
... ... @@ -2643,6 +2708,25 @@
2643 2708 for (Map<String, Object> m : couponReport) {
2644 2709 for (Map<String, Object> info : couponUsedTypeInfo) {
2645 2710 if (m.get("hospitalId").toString().equals(info.get("used_hospital_id"))) {
  2711 +
  2712 + //秦皇岛年龄筛选 <35 岁(大于等于35需要减1次)
  2713 + if(null!=param.get("age")) {
  2714 + Map<String,Object> map=param;
  2715 + map.put("hospitalId", Arrays.asList(info.get("used_hospital_id")));
  2716 + List<String> couponUsedTypeInfoIds = couponMapper.findUsedInfo2ids(map);
  2717 + for (String id : couponUsedTypeInfoIds) {
  2718 + PersonModel personModel = mongoTemplate.findOne(Query.query(Criteria.where("id").is(id)), PersonModel.class);
  2719 + if (null != personModel) {
  2720 + Integer age = DateUtil.getAge(personModel.getBirth());
  2721 + if (age >= 35) {
  2722 + if (null != info.get("type_used_count") && 0 != (long) info.get("type_used_count")) {
  2723 + info.put("type_used_count", (long) info.get("type_used_count") - 1);
  2724 + }
  2725 + }
  2726 + }
  2727 + }
  2728 + }
  2729 +
2646 2730 m.put(info.get("type") + "_" + info.get("coupon_order"), info.get("type_used_count"));
2647 2731 }
2648 2732 }
2649 2733  
... ... @@ -2683,7 +2767,22 @@
2683 2767 if (CollectionUtils.isNotEmpty(sendUserIds)) {
2684 2768 param.put("hospitalFlag", "create_hospital_id"); /** 医院是用create_hospital_id 还是用 used_hospital_id限制*/
2685 2769 List<Map<String, Object>> mulitPatienInfo = couponMapper.findMulitPatienInfoWithSend(param); /** 查询需要添加人数的总数, 例如A发了两次优惠券 那么这里返回需要加的值为1 */
  2770 + //秦皇岛年龄筛选 <35 岁(大于等于35需要移除)
  2771 + if(null!=param.get("age")) {
  2772 + Iterator<Map<String, Object>> iterator = mulitPatienInfo.iterator();
  2773 + while (iterator.hasNext()) {
  2774 + String id = iterator.next().get("user_id").toString();
  2775 + PersonModel personModel = mongoTemplate.findOne(Query.query(Criteria.where("id").is(id)), PersonModel.class);
  2776 + if (null != personModel) {
  2777 + Integer age = DateUtil.getAge(personModel.getBirth());
  2778 + if (age >= 35) {
  2779 + iterator.remove();
  2780 + }
  2781 + }
  2782 + }
  2783 + }
2686 2784 for (Map<String, Object> m : mulitPatienInfo) {
  2785 +
2687 2786 Long count = (Long) m.get("count");
2688 2787 sendUserIds2.add((String) m.get("user_id"));
2689 2788 if (count > 1) {
... ... @@ -3035,6 +3134,22 @@
3035 3134 if (type == 4) { /** 使用详情统计 */
3036 3135 // List<Map<String, Object>> couponInfos = couponMapper.couponInfo(param);
3037 3136 List<Map<String, Object>> couponInfos = couponMapper.couponInfo2(param);
  3137 + //秦皇岛年龄筛选 <35 岁(大于等于35需要移除)
  3138 + if(null!=param.get("age")) {
  3139 + Iterator<Map<String, Object>> iterator = couponInfos.iterator();
  3140 + while (iterator .hasNext()) {
  3141 + Map<String, Object> map= iterator.next();
  3142 + if(MapUtils.isNotEmpty(map) && null!=map.get("used_id")) {
  3143 + Patients patients = mongoTemplate.findOne(Query.query(Criteria.where("id").is(map.get("used_id").toString())), Patients.class);
  3144 + if (null != patients) {
  3145 + Integer age = DateUtil.getAge(patients.getBirth());
  3146 + if (age >= 35) {
  3147 + iterator.remove();
  3148 + }
  3149 + }
  3150 + }
  3151 + }
  3152 + }
3038 3153 String subTitle = null;
3039 3154 Set<String> subTitleTempSet = new HashSet<>();
3040 3155  
... ... @@ -3066,6 +3181,21 @@
3066 3181 }
3067 3182 // int count = couponMapper.findCouponInfoCount(param);
3068 3183 int count = couponMapper.findCouponInfoCount2(param);
  3184 + //秦皇岛年龄筛选 <35 岁(大于等于35需要减1)
  3185 + if(null!=param.get("age")) {
  3186 + List<String> countIds = couponMapper.findCouponInfoCount2Ids(param);
  3187 + for (String countId : countIds) {
  3188 + Patients patients = mongoTemplate.findOne(Query.query(Criteria.where("id").is(countId)), Patients.class);
  3189 + if (null != patients) {
  3190 + Integer age = DateUtil.getAge(patients.getBirth());
  3191 + if (age >= 35) {
  3192 + if(0!=count){
  3193 + --count;
  3194 + }
  3195 + }
  3196 + }
  3197 + }
  3198 + }
3069 3199 PageResult pageResult = new PageResult(count, currentPage, (Integer) param.get("pageSize"), CollectionUtils.createMap("couponInfos", couponInfos, "subTitle", subTitle));
3070 3200 return RespBuilder.buildSuccess(pageResult);
3071 3201 }
... ... @@ -3093,6 +3223,23 @@
3093 3223 return RespBuilder.buildSuccess(pg);
3094 3224 }
3095 3225 List<Map<String, Object>> userSendInfo = couponMapper.findUserSendInfoByUids(param2);
  3226 +
  3227 + //秦皇岛年龄筛选 <35 岁(大于等于35需要移除)
  3228 + if(null!=param.get("age")) {
  3229 + Iterator<Map<String, Object>> iterator = userSendInfo.iterator();
  3230 + while (iterator .hasNext()) {
  3231 + Map<String, Object> map= iterator.next();
  3232 + if(MapUtils.isNotEmpty(map) && null!=map.get("user_id")) {
  3233 + PersonModel personModel = mongoTemplate.findOne(Query.query(Criteria.where("id").is(map.get("user_id"))), PersonModel.class);
  3234 + if (null != personModel) {
  3235 + Integer age = DateUtil.getAge(personModel.getBirth());
  3236 + if (age >= 35) {
  3237 + iterator.remove();
  3238 + }
  3239 + }
  3240 + }
  3241 + }
  3242 + }
3096 3243 // System.out.println(userIds);
3097 3244 // Integer count = couponMapper.findUserSendInfoCount(param);
3098 3245 for (Map<String, Object> map : userSendInfo) {