Commit 0d5feb48cd91ee070050bd75ef1a5f50e8e9f44f

Authored by litao
1 parent f6e2ade56b

bug修复

Showing 6 changed files with 238 additions and 36 deletions

platform-biz-service/src/main/java/com/lyms/platform/permission/dao/master/CouponMapper.java View file @ 0d5feb4
... ... @@ -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 @ 0d5feb4
... ... @@ -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.create_date >= #{startDate}
  250 + </if>
  251 + <if test="endDate != null">
  252 + and b.create_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.used_hospital_id >= #{startDate}
  270 + </if>
  271 + <if test="endDate != null">
  272 + and b.used_hospital_id <![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 @ 0d5feb4
... ... @@ -9,6 +9,7 @@
9 9 SUCCESS(0, "成功"),
10 10 ERROR(500, "系统错误,请联系管理员"),
11 11 DATA_ERROR(3001, "数据错误"),
  12 + HOSPITAL_NOT_FOUND_ERROR(3002, "医院未找到"),
12 13  
13 14 PERSON_NOT_FOUND(2001, "用户未查询到或type为空"),
14 15 PATIENT_NOT_FOUND(2002, "未查询到患者"),
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/ReportController.java View file @ 0d5feb4
... ... @@ -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 @ 0d5feb4
... ... @@ -443,42 +443,155 @@
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); /** 优惠券统计详情(发放人数、发放券数、使用人数、使用券数) */
  448 + List<Map<String, Object>> couponReport = new ArrayList<>();
  449 + List<String> hospitalId = (List<String>) param.get("hospitalId");
  450 + if(CollectionUtils.isNotEmpty(hospitalId)) {
  451 + List<Map<String, Object>> hospitalNames = couponMapper.findHospitalNames(hospitalId);
  452 + if(CollectionUtils.isNotEmpty(hospitalNames)) {
  453 + Map<String, Object> hNameMap = CollectionUtils.coverListToMap(hospitalNames, "id", "name");
  454 + for (String hid : hospitalId) {
  455 + param.put("hid", hid);
  456 + Map<String, Object> usedInfo = couponMapper.findHospitalUsedInfo(param);
  457 + Map<String, Object> sendInfo = couponMapper.findHospitalSendInfo(param);
453 458  
454   - List<Map<String, Object>> usedInfo = couponMapper.findUsedInfo(param); /** 优惠券使用详情 */
455   - List<String> xAxis = new ArrayList<>();
  459 + Map<String, Object> tempMap = packCouponMap(sendInfo, usedInfo, hNameMap, hid);
  460 + if(MapUtils.isNotEmpty(tempMap)) {
  461 + couponReport.add(tempMap);
  462 + }
  463 + }
  464 + }
456 465  
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")));
  466 + }
463 467  
464   - String areaName = findName(map.get("area_id"));
465   - map.put("area_name", areaName);
466   - xAxis.add(areaName);
  468 + if(CollectionUtils.isNotEmpty(couponReport)) {
  469 + param.put("status", 2);
  470 + List<Map<String, Object>> couponUsedTypeInfo = couponMapper.findUsedInfo(param); /** 优惠券使用详情 */
  471 + for (Map<String, Object> m : couponReport) {
  472 + for (Map<String, Object> info : couponUsedTypeInfo) {
  473 + if(m.get("hospitalId").toString().equals(info.get("used_hospital_id"))) {
  474 + m.put(info.get("type") + "_" + info.get("coupon_order"), info.get("type_used_count"));
  475 + }
467 476 }
468 477 }
  478 +
  479 + List<String> xAxis = new ArrayList<>();
469 480 }
470 481  
471   - ReportModel reportModel = new ReportModel();
472   - reportModel.setxAxis(xAxis);
473   - reportModel.setData(Arrays.asList("发放券数", "使用券数"));
474   - reportModel.setSeries(createSeries(couponReport));
475   - reportModel.doMerge();
  482 + return RespBuilder.buildSuccess(couponReport);
  483 +// if(org.apache.commons.collections.CollectionUtils.isNotEmpty(couponReport) &&
  484 +// org.apache.commons.collections.CollectionUtils.isNotEmpty(usedInfo)) {
  485 +// if(CollectionUtils.putAll(couponReport, usedInfo, "used_hospital_id", "used_hospital_id")) {
  486 +// for (Map<String, Object> map : couponReport) {
  487 +// map.put("province_name", findName(map.get("province_id")));
  488 +// map.put("city_name", findName(map.get("city_id")));
  489 +//
  490 +// String areaName = findName(map.get("area_id"));
  491 +// map.put("area_name", areaName);
  492 +// if(map.get("areaId") == null) { /** 没传区县 报表数据就为区域的 传了区县 报表数据就为市 */
  493 +// xAxis.add(areaName);
  494 +// } else {
  495 +// Map<String, Object> m = couponMapper.findHospitalName(CollectionUtils.createMap("hospitalId", ""));
  496 +// if(m.get("name") != null) {
  497 +// xAxis.add(m.get("name").toString());
  498 +// }
  499 +// }
  500 +// }
  501 +// }
  502 +// }
  503 +//
  504 +// ReportModel reportModel = new ReportModel();
  505 +// reportModel.setxAxis(xAxis);
  506 +// reportModel.setData(Arrays.asList("发放券数", "使用券数"));
  507 +// reportModel.setSeries(createSeries(couponReport));
  508 +// reportModel.doMerge();
  509 +//
  510 +// Map<String, Object> titleMap = parseTitle(couponReport);
  511 +// transNullToZero(couponReport, titleMap);
  512 +//
  513 +//
  514 +// return RespBuilder.buildSuccess("couponReport", couponReport, "couponReportMap", titleMap, "reportModel", reportModel);
  515 + }
476 516  
477   - Map<String, Object> titleMap = parseTitle(couponReport);
478   - transNullToZero(couponReport, titleMap);
  517 + private Map<String, Object> packCouponMap(Map<String, Object> sendInfo, Map<String, Object> usedInfo, Map<String, Object> hNameMap, String hid) {
  518 + if(MapUtils.isEmpty(sendInfo) && MapUtils.isEmpty(usedInfo)) return null;
479 519  
480   -
481   - return RespBuilder.buildSuccess("couponReport", couponReport, "couponReportMap", titleMap, "reportModel", reportModel);
  520 + boolean flag = false; /** 本条数据是否有效 sendInfo和usedInfo其中一个有id就有效 */
  521 +
  522 + if(MapUtils.isNotEmpty(sendInfo) && sendInfo.get("id") != null) {
  523 + flag = true;
  524 + } else if(MapUtils.isNotEmpty(usedInfo) && usedInfo.get("id") != null) {
  525 + flag = true;
  526 + }
  527 +
  528 + if(flag) {
  529 + String areaId = null;
  530 + String cityId = null;
  531 + String provinceId = null;
  532 +
  533 + Map<String, Object> tempMap = new HashMap<>();
  534 + if (MapUtils.isNotEmpty(usedInfo)) { /** 因为如果按照条件没查出来数据 统计数据还是会有 但是id没有 需要过滤掉 */
  535 + CollectionUtils.transNullToZero(usedInfo, "user_used_count", "coupon_used_count");
  536 + tempMap.put("user_used_count", usedInfo.get("user_used_count"));
  537 + tempMap.put("coupon_used_count", usedInfo.get("coupon_used_count"));
  538 + areaId = (String) usedInfo.get("area_id");
  539 + cityId = (String) usedInfo.get("city_id");
  540 + provinceId = (String) usedInfo.get("province_id");
  541 + } else {
  542 + tempMap.put("user_used_count", 0);
  543 + tempMap.put("coupon_used_count", 0);
  544 + }
  545 +
  546 + if (MapUtils.isNotEmpty(sendInfo)) {
  547 + CollectionUtils.transNullToZero(sendInfo, "people_send_count", "coupon_send_count");
  548 + tempMap.put("people_send_count", sendInfo.get("people_send_count"));
  549 + tempMap.put("coupon_send_count", sendInfo.get("coupon_send_count"));
  550 + if(StringUtils.isEmpty(areaId)) {
  551 + areaId = (String) sendInfo.get("area_id");
  552 + }
  553 + if(StringUtils.isEmpty(cityId)) {
  554 + cityId = (String) sendInfo.get("city_id");
  555 + }
  556 + if(StringUtils.isEmpty(cityId)) {
  557 + provinceId = (String) sendInfo.get("province_id");
  558 + }
  559 + } else {
  560 + tempMap.put("people_send_count", 0);
  561 + tempMap.put("coupon_send_count", 0);
  562 + }
  563 + tempMap.put("name", hNameMap.get(hid));
  564 + tempMap.put("hospitalId", hid);
  565 +
  566 + tempMap.put("area_id", areaId);
  567 + tempMap.put("city_id", cityId);
  568 + tempMap.put("province_id", provinceId);
  569 + tempMap.put("province_name", findName(provinceId));
  570 + tempMap.put("city_name", findName(cityId));
  571 + tempMap.put("area_name", findName(areaId));
  572 + return tempMap;
  573 + }
  574 + return null;
  575 + }
  576 +
  577 + // 把发放人数/发放券数/使用人数/使用券数为null的设置为0
  578 + private void transNullToZero(List<Map<String, Object>> couponReport) {
  579 + if(org.apache.commons.collections.CollectionUtils.isNotEmpty(couponReport)) {
  580 + for (Map<String, Object> coupon : couponReport) {
  581 + if(coupon.get("coupon_send_count") == null) {
  582 + coupon.put("coupon_send_count", 0);
  583 + }
  584 + if(coupon.get("coupon_used_count") == null) {
  585 + coupon.put("coupon_used_count", 0);
  586 + }
  587 + if(coupon.get("people_send_count") == null) {
  588 + coupon.put("people_send_count", 0);
  589 + }
  590 + if(coupon.get("user_used_count") == null) {
  591 + coupon.put("user_used_count", 0);
  592 + }
  593 + }
  594 + }
482 595 }
483 596  
484 597 private void transNullToZero(List<Map<String, Object>> couponReport, Map<String, Object> titleMap) {
platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/CollectionUtils.java View file @ 0d5feb4
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 }