Commit 8666f81299fb8c6ebc332ce14d25391ff92301bb
Exists in
master
and in
6 other branches
Merge remote-tracking branch 'origin/master'
Showing 6 changed files
- 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-common/src/main/java/com/lyms/platform/common/result/ResponseCode.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/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 @
8666f81
... | ... | @@ -66,5 +66,13 @@ |
66 | 66 | int findCouponInfoCount(Map<String, Object> param); |
67 | 67 | |
68 | 68 | List<String> doHospitalFilter(Map<String, Object> param); |
69 | + | |
70 | + Map<String, Object> findHospitalUsedInfo(Map<String, Object> param); | |
71 | + | |
72 | + String findHospitalNameById(String id); | |
73 | + | |
74 | + List<Map<String, Object>> findHospitalNames(List<String> ids); | |
75 | + | |
76 | + Map<String,Object> findHospitalSendInfo(Map<String, Object> param); | |
69 | 77 | } |
platform-biz-service/src/main/resources/mainOrm/master/CouponMapper.xml
View file @
8666f81
... | ... | @@ -229,10 +229,54 @@ |
229 | 229 | #{type} |
230 | 230 | </foreach> |
231 | 231 | ) b |
232 | - where a.used_hospital_id = b.hospital_id and a.coupon_template_id = b.id and a.status = #{status} | |
232 | + where a.used_hospital_id = b.hospital_id and a.coupon_template_id = b.id and a.status = 2 | |
233 | 233 | group by b.coupon_order, b.type, a.used_hospital_id |
234 | 234 | </select> |
235 | 235 | |
236 | + <select id="findHospitalUsedInfo" parameterType="map" resultType="map"> | |
237 | + select a.id, count(distinct(b.user_id)) as user_used_count, count(1) as coupon_used_count, a.area_id, a.city_id, a.province_id | |
238 | + from organization a, coupon_info b, coupon_template c, coupon_type d, hospital_coupon_template_group e, coupon_template_group f | |
239 | + where a.id = b.used_hospital_id and b.coupon_template_id = c.id and c.type_id = d.id and e.coupon_template_group_id = f.id and e.hospital_id = 1000000095 | |
240 | + and a.id = #{hid} | |
241 | + and d.type in | |
242 | + <foreach collection="couponType" open="(" close=")" separator="," item="type"> | |
243 | + #{type} | |
244 | + </foreach> | |
245 | + <if test="tempId != null and tempId != ''"> | |
246 | + and f.id = #{tempId} | |
247 | + </if> | |
248 | + <if test="startDate != null"> | |
249 | + and b.use_date >= #{startDate} | |
250 | + </if> | |
251 | + <if test="endDate != null"> | |
252 | + and b.use_date <![CDATA[ < ]]> #{endDate} | |
253 | + </if> | |
254 | + </select> | |
255 | + | |
256 | + <select id="findHospitalSendInfo" parameterType="map" resultType="map"> | |
257 | + select a.id, count(distinct(b.user_id)) as people_send_count, count(1) as coupon_send_count, a.area_id, a.city_id, a.province_id | |
258 | + from organization a, coupon_info b, coupon_template c, coupon_type d, hospital_coupon_template_group e, coupon_template_group f | |
259 | + where a.id = b.create_hospital_id and b.coupon_template_id = c.id and c.type_id = d.id and e.coupon_template_group_id = f.id and e.hospital_id = 1000000095 | |
260 | + and a.id = #{hid} | |
261 | + and d.type in | |
262 | + <foreach collection="couponType" open="(" close=")" separator="," item="type"> | |
263 | + #{type} | |
264 | + </foreach> | |
265 | + <if test="tempId != null and tempId != ''"> | |
266 | + and f.id = #{tempId} | |
267 | + </if> | |
268 | + <if test="startDate != null"> | |
269 | + and b.create_date >= #{startDate} | |
270 | + </if> | |
271 | + <if test="endDate != null"> | |
272 | + and b.create_date <![CDATA[ < ]]> #{endDate} | |
273 | + </if> | |
274 | + </select> | |
275 | + | |
276 | + <select id="findHospitalNameById" parameterType="string" resultType="string"> | |
277 | + select name from organization where id = #{id} | |
278 | + </select> | |
279 | + | |
236 | 280 | <select id="findHospitals" parameterType="map" resultType="map"> |
237 | 281 | select a.coupon_template_group_id as id, b.name |
238 | 282 | from hospital_coupon_template_group a, coupon_template_group b |
... | ... | @@ -314,6 +358,13 @@ |
314 | 358 | <if test="areaId != null and areaId != ''"> |
315 | 359 | and area_id = #{areaId} |
316 | 360 | </if> |
361 | + </select> | |
362 | + | |
363 | + <select id="findHospitalNames" parameterType="list" resultType="map"> | |
364 | + select id, name from organization where id in | |
365 | + <foreach collection="list" open="(" close=")" separator="," item="hid"> | |
366 | + #{hid} | |
367 | + </foreach> | |
317 | 368 | </select> |
318 | 369 | </mapper> |
platform-common/src/main/java/com/lyms/platform/common/result/ResponseCode.java
View file @
8666f81
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/ReportController.java
View file @
8666f81
... | ... | @@ -209,8 +209,9 @@ |
209 | 209 | public BaseObjectResponse coupon(HttpServletRequest request, Date startDate, Date endDate, |
210 | 210 | String provinceId, String cityId, String areaId, String hospitalId, String tempId, String couponType) { |
211 | 211 | Map<String, Object> param = CollectionUtils.createMap("userId", getUserId(request), "startDate", startDate, |
212 | - "endDate", DateUtil.addDay(endDate, 1), "hospitalId", hospitalId, "provinceId", provinceId, "cityId", cityId, "areaId", | |
213 | - areaId, "tempId", tempId, "couponType", couponType); | |
212 | + "endDate", endDate != null ? DateUtil.addDay(endDate, 1) : endDate, | |
213 | + "hospitalId", hospitalId, "provinceId", provinceId, "cityId", cityId, "areaId", | |
214 | + areaId, "tempId", tempId, "couponType", CollectionUtils.asList(couponType)); | |
214 | 215 | return reportService.coupon(param); |
215 | 216 | } |
216 | 217 | |
... | ... | @@ -235,7 +236,7 @@ |
235 | 236 | String provinceId, String cityId, String areaId, String hospitalId, String tempId, String couponType, |
236 | 237 | Integer page, Integer limit) { |
237 | 238 | Map<String, Object> param = CollectionUtils.createMap("userId", getUserId(request), "startDate", startDate, |
238 | - "endDate", DateUtil.addDay(endDate, 1), "hospitalId", CollectionUtils.asList(hospitalId), "provinceId", provinceId, "cityId", cityId, "areaId", areaId, "type", type, | |
239 | + "endDate", endDate != null ? DateUtil.addDay(endDate, 1) : endDate, "hospitalId", CollectionUtils.asList(hospitalId), "provinceId", provinceId, "cityId", cityId, "areaId", areaId, "type", type, | |
239 | 240 | "tempId", tempId, "couponType", CollectionUtils.asList(couponType), "currentPage", page, "pageSize", limit); |
240 | 241 | return reportService.couponInfo(param); |
241 | 242 | } |
242 | 243 | |
... | ... | @@ -262,10 +263,8 @@ |
262 | 263 | String provinceId, String cityId, String areaId, String hospitalId, String tempId, String couponType, |
263 | 264 | Integer page, Integer limit) { |
264 | 265 | Map<String, Object> param = CollectionUtils.createMap("userId", getUserId(request), "startDate", startDate, |
265 | - "endDate", DateUtil.addDay(endDate, 1), "hospitalId", hospitalId, "provinceId", provinceId, "cityId", cityId, "areaId", areaId, "type", type, | |
266 | + "endDate", endDate != null ? DateUtil.addDay(endDate, 1) : endDate, "hospitalId", hospitalId, "provinceId", provinceId, "cityId", cityId, "areaId", areaId, "type", type, | |
266 | 267 | "tempId", tempId, "couponType", CollectionUtils.asList(couponType), "currentPage", page, "pageSize", limit); |
267 | - /*Map<String, Object> param = CollectionUtils.createMap("userId", "1000000185", "hospitalId", CollectionUtils.asList("216"), "type", type, | |
268 | - "tempId", tempId, "couponType", CollectionUtils.asList("1,2,3,4,5,6,7,8"), "currentPage", page, "pageSize", limit);*/ | |
269 | 268 | reportService.exportCouponInfo(param, response); |
270 | 269 | } |
271 | 270 |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java
View file @
8666f81
... | ... | @@ -443,31 +443,42 @@ |
443 | 443 | } else { |
444 | 444 | param.put("hospitalId", CollectionUtils.asList((String) param.get("hospitalId"))); |
445 | 445 | } |
446 | - | |
447 | 446 | doHospitalFilter(param); |
448 | - | |
449 | - param.put("status", 2); | |
450 | - param.put("couponType", CollectionUtils.asList((String) param.get("couponType"))); | |
451 | 447 | |
452 | - List<Map<String, Object>> couponReport = couponMapper.findReport(param); /** 优惠券统计详情(发放人数、发放券数、使用人数、使用券数) */ | |
453 | - | |
454 | - List<Map<String, Object>> usedInfo = couponMapper.findUsedInfo(param); /** 优惠券使用详情 */ | |
448 | + List<Map<String, Object>> couponReport = new ArrayList<>(); | |
449 | + List<String> hospitalId = (List<String>) param.get("hospitalId"); | |
455 | 450 | List<String> xAxis = new ArrayList<>(); |
456 | 451 | |
457 | - if(org.apache.commons.collections.CollectionUtils.isNotEmpty(couponReport) && | |
458 | - org.apache.commons.collections.CollectionUtils.isNotEmpty(usedInfo)) { | |
459 | - if(CollectionUtils.putAll(couponReport, usedInfo, "used_hospital_id", "used_hospital_id")) { | |
460 | - for (Map<String, Object> map : couponReport) { | |
461 | - map.put("province_name", findName(map.get("province_id"))); | |
462 | - map.put("city_name", findName(map.get("city_id"))); | |
452 | + if(CollectionUtils.isNotEmpty(hospitalId)) { | |
453 | + List<Map<String, Object>> hospitalNames = couponMapper.findHospitalNames(hospitalId); | |
454 | + if(CollectionUtils.isNotEmpty(hospitalNames)) { | |
455 | + Map<String, Object> hNameMap = CollectionUtils.coverListToMap(hospitalNames, "id", "name"); | |
456 | + for (String hid : hospitalId) { | |
457 | + param.put("hid", hid); | |
458 | + Map<String, Object> usedInfo = couponMapper.findHospitalUsedInfo(param); | |
459 | + Map<String, Object> sendInfo = couponMapper.findHospitalSendInfo(param); | |
463 | 460 | |
464 | - String areaName = findName(map.get("area_id")); | |
465 | - map.put("area_name", areaName); | |
466 | - xAxis.add(areaName); | |
461 | + Map<String, Object> tempMap = packCouponMap(sendInfo, usedInfo, hNameMap, hid, xAxis, param); | |
462 | + if(MapUtils.isNotEmpty(tempMap)) { | |
463 | + couponReport.add(tempMap); | |
464 | + } | |
467 | 465 | } |
468 | 466 | } |
467 | + | |
469 | 468 | } |
470 | 469 | |
470 | + if(CollectionUtils.isNotEmpty(couponReport)) { | |
471 | + param.put("status", 2); | |
472 | + List<Map<String, Object>> couponUsedTypeInfo = couponMapper.findUsedInfo(param); /** 优惠券使用详情 */ | |
473 | + for (Map<String, Object> m : couponReport) { | |
474 | + for (Map<String, Object> info : couponUsedTypeInfo) { | |
475 | + if(m.get("hospitalId").toString().equals(info.get("used_hospital_id"))) { | |
476 | + m.put(info.get("type") + "_" + info.get("coupon_order"), info.get("type_used_count")); | |
477 | + } | |
478 | + } | |
479 | + } | |
480 | + } | |
481 | + | |
471 | 482 | ReportModel reportModel = new ReportModel(); |
472 | 483 | reportModel.setxAxis(xAxis); |
473 | 484 | reportModel.setData(Arrays.asList("发放券数", "使用券数")); |
474 | 485 | |
475 | 486 | |
476 | 487 | |
477 | 488 | |
478 | 489 | |
479 | 490 | |
480 | 491 | |
... | ... | @@ -477,25 +488,118 @@ |
477 | 488 | Map<String, Object> titleMap = parseTitle(couponReport); |
478 | 489 | transNullToZero(couponReport, titleMap); |
479 | 490 | |
480 | - | |
481 | 491 | return RespBuilder.buildSuccess("couponReport", couponReport, "couponReportMap", titleMap, "reportModel", reportModel); |
492 | + // return RespBuilder.buildSuccess(couponReport); | |
493 | +// if(org.apache.commons.collections.CollectionUtils.isNotEmpty(couponReport) && | |
494 | +// org.apache.commons.collections.CollectionUtils.isNotEmpty(usedInfo)) { | |
495 | +// if(CollectionUtils.putAll(couponReport, usedInfo, "used_hospital_id", "used_hospital_id")) { | |
496 | +// for (Map<String, Object> map : couponReport) { | |
497 | +// map.put("province_name", findName(map.get("province_id"))); | |
498 | +// map.put("city_name", findName(map.get("city_id"))); | |
499 | +// | |
500 | +// String areaName = findName(map.get("area_id")); | |
501 | +// map.put("area_name", areaName); | |
502 | +// if(map.get("areaId") == null) { /** 没传区县 报表数据就为区域的 传了区县 报表数据就为市 */ | |
503 | +// xAxis.add(areaName); | |
504 | +// } else { | |
505 | +// Map<String, Object> m = couponMapper.findHospitalName(CollectionUtils.createMap("hospitalId", "")); | |
506 | +// if(m.get("name") != null) { | |
507 | +// xAxis.add(m.get("name").toString()); | |
508 | +// } | |
509 | +// } | |
510 | +// } | |
511 | +// } | |
512 | +// } | |
513 | +// | |
514 | +// ReportModel reportModel = new ReportModel(); | |
515 | +// reportModel.setxAxis(xAxis); | |
516 | +// reportModel.setData(Arrays.asList("发放券数", "使用券数")); | |
517 | +// reportModel.setSeries(createSeries(couponReport)); | |
518 | +// reportModel.doMerge(); | |
519 | +// | |
520 | +// Map<String, Object> titleMap = parseTitle(couponReport); | |
521 | +// transNullToZero(couponReport, titleMap); | |
522 | +// | |
523 | +// | |
524 | +// return RespBuilder.buildSuccess("couponReport", couponReport, "couponReportMap", titleMap, "reportModel", reportModel); | |
482 | 525 | } |
483 | 526 | |
484 | - private void transNullToZero(List<Map<String, Object>> couponReport, Map<String, Object> titleMap) { | |
485 | - if(org.apache.commons.collections.CollectionUtils.isNotEmpty(couponReport) | |
486 | - && org.apache.commons.collections.MapUtils.isNotEmpty(titleMap)) | |
487 | - for (Map<String, Object> coupon : couponReport) { | |
488 | - Set<String> set = titleMap.keySet(); | |
489 | - for (String s : set) { | |
490 | - if(coupon.get(s) == null) { | |
491 | - coupon.put(s, 0); | |
527 | + private Map<String, Object> packCouponMap(Map<String, Object> sendInfo, Map<String, Object> usedInfo, Map<String, Object> hNameMap, String hid, List<String> xAxis, Map<String, Object> param) { | |
528 | + if(MapUtils.isEmpty(sendInfo) && MapUtils.isEmpty(usedInfo)) return null; | |
529 | + | |
530 | + boolean flag = false; /** 本条数据是否有效 sendInfo和usedInfo其中一个有id就有效 */ | |
531 | + | |
532 | + if(MapUtils.isNotEmpty(sendInfo) && sendInfo.get("id") != null) { | |
533 | + flag = true; | |
534 | + } else if(MapUtils.isNotEmpty(usedInfo) && usedInfo.get("id") != null) { | |
535 | + flag = true; | |
536 | + } | |
537 | + | |
538 | + if(flag) { | |
539 | + String areaId = null; | |
540 | + String cityId = null; | |
541 | + String provinceId = null; | |
542 | + | |
543 | + Map<String, Object> tempMap = new HashMap<>(); | |
544 | + if (MapUtils.isNotEmpty(usedInfo)) { /** 因为如果按照条件没查出来数据 统计数据还是会有 但是id没有 需要过滤掉 */ | |
545 | + CollectionUtils.transNullToZero(usedInfo, "user_used_count", "coupon_used_count"); | |
546 | + tempMap.put("user_used_count", usedInfo.get("user_used_count")); | |
547 | + tempMap.put("coupon_used_count", usedInfo.get("coupon_used_count")); | |
548 | + areaId = (String) usedInfo.get("area_id"); | |
549 | + cityId = (String) usedInfo.get("city_id"); | |
550 | + provinceId = (String) usedInfo.get("province_id"); | |
551 | + } else { | |
552 | + tempMap.put("user_used_count", 0); | |
553 | + tempMap.put("coupon_used_count", 0); | |
554 | + } | |
555 | + | |
556 | + if (MapUtils.isNotEmpty(sendInfo)) { | |
557 | + CollectionUtils.transNullToZero(sendInfo, "people_send_count", "coupon_send_count"); | |
558 | + tempMap.put("people_send_count", sendInfo.get("people_send_count")); | |
559 | + tempMap.put("coupon_send_count", sendInfo.get("coupon_send_count")); | |
560 | + if(StringUtils.isEmpty(areaId)) { | |
561 | + areaId = (String) sendInfo.get("area_id"); | |
492 | 562 | } |
563 | + if(StringUtils.isEmpty(cityId)) { | |
564 | + cityId = (String) sendInfo.get("city_id"); | |
565 | + } | |
566 | + if(StringUtils.isEmpty(cityId)) { | |
567 | + provinceId = (String) sendInfo.get("province_id"); | |
568 | + } | |
569 | + } else { | |
570 | + tempMap.put("people_send_count", 0); | |
571 | + tempMap.put("coupon_send_count", 0); | |
493 | 572 | } |
494 | - } | |
495 | - } | |
496 | 573 | |
574 | + if("0".equals(tempMap.get("people_send_count").toString()) && | |
575 | + "0".equals(tempMap.get("coupon_send_count").toString())&& | |
576 | + "0".equals(tempMap.get("user_used_count").toString())&& | |
577 | + "0".equals(tempMap.get("coupon_used_count").toString())){ | |
578 | + return null; | |
579 | + } | |
497 | 580 | |
581 | + tempMap.put("name", hNameMap.get(hid)); | |
582 | + tempMap.put("hospitalId", hid); | |
498 | 583 | |
584 | + tempMap.put("area_id", areaId); | |
585 | + tempMap.put("city_id", cityId); | |
586 | + tempMap.put("province_id", provinceId); | |
587 | + tempMap.put("province_name", findName(provinceId)); | |
588 | + tempMap.put("city_name", findName(cityId)); | |
589 | + String areaName = findName(areaId); | |
590 | + tempMap.put("area_name", areaName); | |
591 | + | |
592 | + /** 没传区县 报表数据就为区域的 */ | |
593 | + if(param.get("areaId") == null) { | |
594 | + xAxis.add(areaName); | |
595 | + } else { /** 传了区县 报表数据就为医院 */ | |
596 | + xAxis.add((String) hNameMap.get(hid)); | |
597 | + } | |
598 | + return tempMap; | |
599 | + } | |
600 | + return null; | |
601 | + } | |
602 | + | |
499 | 603 | /** |
500 | 604 | * 根据省市区县过滤医院 |
501 | 605 | * @param param |
... | ... | @@ -504,6 +608,20 @@ |
504 | 608 | List<String> hospitalIds = couponMapper.doHospitalFilter(param); |
505 | 609 | param.put("hospitalId", hospitalIds); |
506 | 610 | } |
611 | + | |
612 | + private void transNullToZero(List<Map<String, Object>> couponReport, Map<String, Object> titleMap) { | |
613 | + if(org.apache.commons.collections.CollectionUtils.isNotEmpty(couponReport) | |
614 | + && org.apache.commons.collections.MapUtils.isNotEmpty(titleMap)) | |
615 | + for (Map<String, Object> coupon : couponReport) { | |
616 | + Set<String> set = titleMap.keySet(); | |
617 | + for (String s : set) { | |
618 | + if(coupon.get(s) == null) { | |
619 | + coupon.put(s, 0); | |
620 | + } | |
621 | + } | |
622 | + } | |
623 | + } | |
624 | + | |
507 | 625 | |
508 | 626 | private Map<String,Object> parseTitle(List<Map<String, Object>> couponReport) { |
509 | 627 | Map<String, Object> titleMap = new HashMap<>(); |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/CollectionUtils.java
View file @
8666f81
1 | 1 | package com.lyms.platform.operate.web.utils; |
2 | 2 | |
3 | -import org.apache.commons.lang.StringUtils; | |
3 | +import org.apache.commons.lang3.StringUtils; | |
4 | +import org.eclipse.jetty.util.StringUtil; | |
4 | 5 | import org.springframework.util.Assert; |
5 | 6 | |
6 | 7 | import java.util.*; |
... | ... | @@ -10,7 +11,7 @@ |
10 | 11 | * @Date: 2017/5/22 0022 10:44 |
11 | 12 | * @Version: V1.0 |
12 | 13 | */ |
13 | -public class CollectionUtils { | |
14 | +public class CollectionUtils extends org.apache.commons.collections.CollectionUtils { | |
14 | 15 | private CollectionUtils(){} |
15 | 16 | |
16 | 17 | public static Map<String,Object> createMap(Object ... args){ |
... | ... | @@ -21,7 +22,7 @@ |
21 | 22 | for (int i = 0; i < args.length; i++) { |
22 | 23 | String key = args[i++].toString(); |
23 | 24 | Object value = args[i]; |
24 | - if(value != null && StringUtils.isNotBlank(value.toString())) { | |
25 | + if(value != null && StringUtil.isNotBlank(value.toString())) { | |
25 | 26 | map.put(key, value); |
26 | 27 | } |
27 | 28 | } |
... | ... | @@ -107,6 +108,35 @@ |
107 | 108 | restList.add(map.get(s)); |
108 | 109 | } |
109 | 110 | return restList; |
111 | + } | |
112 | + | |
113 | + /** | |
114 | + * key所对应的值如果=null就设置为0 | |
115 | + * @param map | |
116 | + * @param keys | |
117 | + */ | |
118 | + public static void transNullToZero(Map<String, Object> map, String ... keys) { | |
119 | + Assert.notNull(map, "userinfo must not be null!"); | |
120 | + Assert.notNull(keys, "keys must not be null!"); | |
121 | + | |
122 | + for (String key : keys) { | |
123 | + if(map.get(key) == null) { | |
124 | + map.put(key, 0); | |
125 | + } | |
126 | + } | |
127 | + } | |
128 | + | |
129 | + public static Map<String, Object> coverListToMap(List<Map<String, Object>> map, String key, String value) { | |
130 | + Assert.notNull(map, "map must not be null!"); | |
131 | + Assert.notNull(key, "key must not be null!"); | |
132 | + Assert.notNull(value, "value must not be null!"); | |
133 | + | |
134 | + Map<String, Object> restMap = new HashMap<>(); | |
135 | + for (Map<String, Object> m : map) { | |
136 | + restMap.put(m.get(key) + "", m.get(value)); | |
137 | + } | |
138 | + return restMap; | |
139 | + | |
110 | 140 | } |
111 | 141 | |
112 | 142 | } |