diff --git a/platform-biz-service/src/main/java/com/lyms/platform/permission/dao/master/CouponMapper.java b/platform-biz-service/src/main/java/com/lyms/platform/permission/dao/master/CouponMapper.java index 2db269e..b546916 100644 --- a/platform-biz-service/src/main/java/com/lyms/platform/permission/dao/master/CouponMapper.java +++ b/platform-biz-service/src/main/java/com/lyms/platform/permission/dao/master/CouponMapper.java @@ -66,4 +66,12 @@ public interface CouponMapper { int findCouponInfoCount(Map param); List doHospitalFilter(Map param); + + Map findHospitalUsedInfo(Map param); + + String findHospitalNameById(String id); + + List> findHospitalNames(List ids); + + Map findHospitalSendInfo(Map param); } diff --git a/platform-biz-service/src/main/resources/mainOrm/master/CouponMapper.xml b/platform-biz-service/src/main/resources/mainOrm/master/CouponMapper.xml index 36c1b1d..d84bb74 100644 --- a/platform-biz-service/src/main/resources/mainOrm/master/CouponMapper.xml +++ b/platform-biz-service/src/main/resources/mainOrm/master/CouponMapper.xml @@ -229,10 +229,54 @@ #{type} ) b - where a.used_hospital_id = b.hospital_id and a.coupon_template_id = b.id and a.status = #{status} + where a.used_hospital_id = b.hospital_id and a.coupon_template_id = b.id and a.status = 2 group by b.coupon_order, b.type, a.used_hospital_id + + + + + + + + \ No newline at end of file diff --git a/platform-common/src/main/java/com/lyms/platform/common/result/ResponseCode.java b/platform-common/src/main/java/com/lyms/platform/common/result/ResponseCode.java index 6b28e76..7b1351f 100644 --- a/platform-common/src/main/java/com/lyms/platform/common/result/ResponseCode.java +++ b/platform-common/src/main/java/com/lyms/platform/common/result/ResponseCode.java @@ -9,6 +9,7 @@ public enum ResponseCode { SUCCESS(0, "成功"), ERROR(500, "系统错误,请联系管理员"), DATA_ERROR(3001, "数据错误"), + HOSPITAL_NOT_FOUND_ERROR(3002, "医院未找到"), PERSON_NOT_FOUND(2001, "用户未查询到或type为空"), PATIENT_NOT_FOUND(2002, "未查询到患者"), diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/ReportController.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/ReportController.java index 4c96941..1c861b5 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/ReportController.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/ReportController.java @@ -209,8 +209,9 @@ public class ReportController extends BaseController { public BaseObjectResponse coupon(HttpServletRequest request, Date startDate, Date endDate, String provinceId, String cityId, String areaId, String hospitalId, String tempId, String couponType) { Map param = CollectionUtils.createMap("userId", getUserId(request), "startDate", startDate, - "endDate", DateUtil.addDay(endDate, 1), "hospitalId", hospitalId, "provinceId", provinceId, "cityId", cityId, "areaId", - areaId, "tempId", tempId, "couponType", couponType); + "endDate", endDate != null ? DateUtil.addDay(endDate, 1) : endDate, + "hospitalId", hospitalId, "provinceId", provinceId, "cityId", cityId, "areaId", + areaId, "tempId", tempId, "couponType", CollectionUtils.asList(couponType)); return reportService.coupon(param); } @@ -235,7 +236,7 @@ public class ReportController extends BaseController { String provinceId, String cityId, String areaId, String hospitalId, String tempId, String couponType, Integer page, Integer limit) { Map param = CollectionUtils.createMap("userId", getUserId(request), "startDate", startDate, - "endDate", DateUtil.addDay(endDate, 1), "hospitalId", CollectionUtils.asList(hospitalId), "provinceId", provinceId, "cityId", cityId, "areaId", areaId, "type", type, + "endDate", endDate != null ? DateUtil.addDay(endDate, 1) : endDate, "hospitalId", CollectionUtils.asList(hospitalId), "provinceId", provinceId, "cityId", cityId, "areaId", areaId, "type", type, "tempId", tempId, "couponType", CollectionUtils.asList(couponType), "currentPage", page, "pageSize", limit); return reportService.couponInfo(param); } @@ -262,10 +263,8 @@ public class ReportController extends BaseController { String provinceId, String cityId, String areaId, String hospitalId, String tempId, String couponType, Integer page, Integer limit) { Map param = CollectionUtils.createMap("userId", getUserId(request), "startDate", startDate, - "endDate", DateUtil.addDay(endDate, 1), "hospitalId", hospitalId, "provinceId", provinceId, "cityId", cityId, "areaId", areaId, "type", type, + "endDate", endDate != null ? DateUtil.addDay(endDate, 1) : endDate, "hospitalId", hospitalId, "provinceId", provinceId, "cityId", cityId, "areaId", areaId, "type", type, "tempId", tempId, "couponType", CollectionUtils.asList(couponType), "currentPage", page, "pageSize", limit); - /*Map param = CollectionUtils.createMap("userId", "1000000185", "hospitalId", CollectionUtils.asList("216"), "type", type, - "tempId", tempId, "couponType", CollectionUtils.asList("1,2,3,4,5,6,7,8"), "currentPage", page, "pageSize", limit);*/ reportService.exportCouponInfo(param, response); } diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java index 05b47b1..8e72cd3 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/ReportServiceImpl.java @@ -443,42 +443,155 @@ public class ReportServiceImpl extends BaseServiceImpl implements IReportService } else { param.put("hospitalId", CollectionUtils.asList((String) param.get("hospitalId"))); } - doHospitalFilter(param); - - param.put("status", 2); - param.put("couponType", CollectionUtils.asList((String) param.get("couponType"))); - List> couponReport = couponMapper.findReport(param); /** 优惠券统计详情(发放人数、发放券数、使用人数、使用券数) */ - - List> usedInfo = couponMapper.findUsedInfo(param); /** 优惠券使用详情 */ - List xAxis = new ArrayList<>(); + List> couponReport = new ArrayList<>(); + List hospitalId = (List) param.get("hospitalId"); + if(CollectionUtils.isNotEmpty(hospitalId)) { + List> hospitalNames = couponMapper.findHospitalNames(hospitalId); + if(CollectionUtils.isNotEmpty(hospitalNames)) { + Map hNameMap = CollectionUtils.coverListToMap(hospitalNames, "id", "name"); + for (String hid : hospitalId) { + param.put("hid", hid); + Map usedInfo = couponMapper.findHospitalUsedInfo(param); + Map sendInfo = couponMapper.findHospitalSendInfo(param); + + Map tempMap = packCouponMap(sendInfo, usedInfo, hNameMap, hid); + if(MapUtils.isNotEmpty(tempMap)) { + couponReport.add(tempMap); + } + } + } - if(org.apache.commons.collections.CollectionUtils.isNotEmpty(couponReport) && - org.apache.commons.collections.CollectionUtils.isNotEmpty(usedInfo)) { - if(CollectionUtils.putAll(couponReport, usedInfo, "used_hospital_id", "used_hospital_id")) { - for (Map map : couponReport) { - map.put("province_name", findName(map.get("province_id"))); - map.put("city_name", findName(map.get("city_id"))); + } - String areaName = findName(map.get("area_id")); - map.put("area_name", areaName); - xAxis.add(areaName); + if(CollectionUtils.isNotEmpty(couponReport)) { + param.put("status", 2); + List> couponUsedTypeInfo = couponMapper.findUsedInfo(param); /** 优惠券使用详情 */ + for (Map m : couponReport) { + for (Map info : couponUsedTypeInfo) { + if(m.get("hospitalId").toString().equals(info.get("used_hospital_id"))) { + m.put(info.get("type") + "_" + info.get("coupon_order"), info.get("type_used_count")); + } } } + + List xAxis = new ArrayList<>(); } - ReportModel reportModel = new ReportModel(); - reportModel.setxAxis(xAxis); - reportModel.setData(Arrays.asList("发放券数", "使用券数")); - reportModel.setSeries(createSeries(couponReport)); - reportModel.doMerge(); + return RespBuilder.buildSuccess(couponReport); +// if(org.apache.commons.collections.CollectionUtils.isNotEmpty(couponReport) && +// org.apache.commons.collections.CollectionUtils.isNotEmpty(usedInfo)) { +// if(CollectionUtils.putAll(couponReport, usedInfo, "used_hospital_id", "used_hospital_id")) { +// for (Map map : couponReport) { +// map.put("province_name", findName(map.get("province_id"))); +// map.put("city_name", findName(map.get("city_id"))); +// +// String areaName = findName(map.get("area_id")); +// map.put("area_name", areaName); +// if(map.get("areaId") == null) { /** 没传区县 报表数据就为区域的 传了区县 报表数据就为市 */ +// xAxis.add(areaName); +// } else { +// Map m = couponMapper.findHospitalName(CollectionUtils.createMap("hospitalId", "")); +// if(m.get("name") != null) { +// xAxis.add(m.get("name").toString()); +// } +// } +// } +// } +// } +// +// ReportModel reportModel = new ReportModel(); +// reportModel.setxAxis(xAxis); +// reportModel.setData(Arrays.asList("发放券数", "使用券数")); +// reportModel.setSeries(createSeries(couponReport)); +// reportModel.doMerge(); +// +// Map titleMap = parseTitle(couponReport); +// transNullToZero(couponReport, titleMap); +// +// +// return RespBuilder.buildSuccess("couponReport", couponReport, "couponReportMap", titleMap, "reportModel", reportModel); + } + + private Map packCouponMap(Map sendInfo, Map usedInfo, Map hNameMap, String hid) { + if(MapUtils.isEmpty(sendInfo) && MapUtils.isEmpty(usedInfo)) return null; + + boolean flag = false; /** 本条数据是否有效 sendInfo和usedInfo其中一个有id就有效 */ + + if(MapUtils.isNotEmpty(sendInfo) && sendInfo.get("id") != null) { + flag = true; + } else if(MapUtils.isNotEmpty(usedInfo) && usedInfo.get("id") != null) { + flag = true; + } + + if(flag) { + String areaId = null; + String cityId = null; + String provinceId = null; + + Map tempMap = new HashMap<>(); + if (MapUtils.isNotEmpty(usedInfo)) { /** 因为如果按照条件没查出来数据 统计数据还是会有 但是id没有 需要过滤掉 */ + CollectionUtils.transNullToZero(usedInfo, "user_used_count", "coupon_used_count"); + tempMap.put("user_used_count", usedInfo.get("user_used_count")); + tempMap.put("coupon_used_count", usedInfo.get("coupon_used_count")); + areaId = (String) usedInfo.get("area_id"); + cityId = (String) usedInfo.get("city_id"); + provinceId = (String) usedInfo.get("province_id"); + } else { + tempMap.put("user_used_count", 0); + tempMap.put("coupon_used_count", 0); + } - Map titleMap = parseTitle(couponReport); - transNullToZero(couponReport, titleMap); + if (MapUtils.isNotEmpty(sendInfo)) { + CollectionUtils.transNullToZero(sendInfo, "people_send_count", "coupon_send_count"); + tempMap.put("people_send_count", sendInfo.get("people_send_count")); + tempMap.put("coupon_send_count", sendInfo.get("coupon_send_count")); + if(StringUtils.isEmpty(areaId)) { + areaId = (String) sendInfo.get("area_id"); + } + if(StringUtils.isEmpty(cityId)) { + cityId = (String) sendInfo.get("city_id"); + } + if(StringUtils.isEmpty(cityId)) { + provinceId = (String) sendInfo.get("province_id"); + } + } else { + tempMap.put("people_send_count", 0); + tempMap.put("coupon_send_count", 0); + } + tempMap.put("name", hNameMap.get(hid)); + tempMap.put("hospitalId", hid); + + tempMap.put("area_id", areaId); + tempMap.put("city_id", cityId); + tempMap.put("province_id", provinceId); + tempMap.put("province_name", findName(provinceId)); + tempMap.put("city_name", findName(cityId)); + tempMap.put("area_name", findName(areaId)); + return tempMap; + } + return null; + } - - return RespBuilder.buildSuccess("couponReport", couponReport, "couponReportMap", titleMap, "reportModel", reportModel); + // 把发放人数/发放券数/使用人数/使用券数为null的设置为0 + private void transNullToZero(List> couponReport) { + if(org.apache.commons.collections.CollectionUtils.isNotEmpty(couponReport)) { + for (Map coupon : couponReport) { + if(coupon.get("coupon_send_count") == null) { + coupon.put("coupon_send_count", 0); + } + if(coupon.get("coupon_used_count") == null) { + coupon.put("coupon_used_count", 0); + } + if(coupon.get("people_send_count") == null) { + coupon.put("people_send_count", 0); + } + if(coupon.get("user_used_count") == null) { + coupon.put("user_used_count", 0); + } + } + } } private void transNullToZero(List> couponReport, Map titleMap) { diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/CollectionUtils.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/CollectionUtils.java index 259c860..9b2d186 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/CollectionUtils.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/CollectionUtils.java @@ -1,6 +1,7 @@ package com.lyms.platform.operate.web.utils; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; +import org.eclipse.jetty.util.StringUtil; import org.springframework.util.Assert; import java.util.*; @@ -10,7 +11,7 @@ import java.util.*; * @Date: 2017/5/22 0022 10:44 * @Version: V1.0 */ -public class CollectionUtils { +public class CollectionUtils extends org.apache.commons.collections.CollectionUtils { private CollectionUtils(){} public static Map createMap(Object ... args){ @@ -21,7 +22,7 @@ public class CollectionUtils { for (int i = 0; i < args.length; i++) { String key = args[i++].toString(); Object value = args[i]; - if(value != null && StringUtils.isNotBlank(value.toString())) { + if(value != null && StringUtil.isNotBlank(value.toString())) { map.put(key, value); } } @@ -109,4 +110,33 @@ public class CollectionUtils { return restList; } + /** + * key所对应的值如果=null就设置为0 + * @param map + * @param keys + */ + public static void transNullToZero(Map map, String ... keys) { + Assert.notNull(map, "userinfo must not be null!"); + Assert.notNull(keys, "keys must not be null!"); + + for (String key : keys) { + if(map.get(key) == null) { + map.put(key, 0); + } + } + } + + public static Map coverListToMap(List> map, String key, String value) { + Assert.notNull(map, "map must not be null!"); + Assert.notNull(key, "key must not be null!"); + Assert.notNull(value, "value must not be null!"); + + Map restMap = new HashMap<>(); + for (Map m : map) { + restMap.put(m.get(key) + "", m.get(value)); + } + return restMap; + + } + }