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 b8f79fa..4fdfb3c 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 @@ -7,9 +7,11 @@ import com.lyms.platform.biz.service.CommonService; import com.lyms.platform.common.enums.CouponEnums; import com.lyms.platform.common.enums.FetalEnums; import com.lyms.platform.common.enums.FuZhongEnums; +import com.lyms.platform.common.enums.YnEnums; import com.lyms.platform.common.result.BaseObjectResponse; import com.lyms.platform.common.result.PageResult; import com.lyms.platform.common.result.RespBuilder; +import com.lyms.platform.common.result.ResponseCode; import com.lyms.platform.common.utils.DateUtil; import com.lyms.platform.common.utils.EnumUtil; import com.lyms.platform.common.utils.PingYinUtil; @@ -43,6 +45,9 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.*; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; /** * @Author: litao @@ -1555,8 +1560,203 @@ public class ReportServiceImpl extends BaseServiceImpl implements IReportService return ""; } + static class MongoDataCallable implements Callable { + + private MongoTemplate mongoTemplate; + + private List parentIds; + + private Class clazz; + + public MongoDataCallable(MongoTemplate mongoTemplate, List parentIds, Class clazz) { + this.mongoTemplate = mongoTemplate; + this.parentIds = parentIds; + this.clazz = clazz; + } + + @Override + public List call() throws Exception { + return mongoTemplate.find(Query.query(Criteria.where("yn").is(YnEnums.YES.getId()).and("parentId").in(parentIds)), clazz); + } + + } + @Override public BaseObjectResponse unUsed(Date startDate, Date endDate, String provinceId, String cityId, String areaId, String hospitalId, Integer page, Integer limit, Integer userId) { + try { + List hospitalIds = getHospitalIds(userId, hospitalId); + List> hospitals= couponMapper.findHospitalInfoByIds2(CollectionUtils.createMap("list", hospitalIds, "provinceId", provinceId, "cityId", cityId, "areaId", areaId)); + + Criteria c = new Criteria(); + List hids = CollectionUtils.getListByKey(hospitals, "id"); + c.and("hospitalId").in(hids).and("yn").ne(0).and("enable").ne("2").and("buildType").ne(1).and("isSendCoupon").is(true); + if(startDate != null && endDate != null) { + c.and("bookbuildingDate").gte(startDate).lt(DateUtil.addDay(endDate, 1)); + } + + /** 建档自动被使用 所以不统计 */ + List patients = mongoTemplate.find(Query.query(c).with(new Sort(Sort.Direction.DESC, "created")), Patients.class); + List parentIds = new ArrayList<>(); + for (Patients patient : patients) { + parentIds.add(patient.getId()); + } + + ExecutorService executorService = Executors.newFixedThreadPool(5); + List antExChuModels = executorService.submit(new MongoDataCallable(mongoTemplate, parentIds, AntExChuModel.class)).get(); + List antenatalExaminationModels = executorService.submit(new MongoDataCallable(mongoTemplate, parentIds, AntenatalExaminationModel.class)).get(); + List maternalDeliverModels = executorService.submit(new MongoDataCallable(mongoTemplate, parentIds, MaternalDeliverModel.class)).get(); + List deliverModels = executorService.submit(new MongoDataCallable(mongoTemplate, parentIds, DischargeAbstractMotherModel.class)).get(); + List postReviewModels = executorService.submit(new MongoDataCallable(mongoTemplate, parentIds, PostReviewModel.class)).get(); + executorService.shutdown(); + + List usedIds = getNeedUsedIds(patients, antExChuModels, antenatalExaminationModels, maternalDeliverModels, deliverModels, postReviewModels); + List> restList = new ArrayList<>(); + if(CollectionUtils.isNotEmpty(usedIds)) { + List list = couponMapper.findUsededId(usedIds); + usedIds.removeAll(list); + + Map hospitalNameCache = new HashMap<>(); + for (String hid : hids) { + boolean flag = false; + Set unUsedIds = new HashSet<>(); // 未使用优惠券patientid + List> un_used_coupons = new ArrayList<>(); // 未使用优惠券详情 + for (String usedId : usedIds) { + if(checkHospital(patients, antExChuModels, antenatalExaminationModels, maternalDeliverModels, deliverModels, postReviewModels, hid, usedId)) { + flag = true; + Patients p = getParentByUsedId(patients, antExChuModels, antenatalExaminationModels, maternalDeliverModels, deliverModels, postReviewModels, usedId); + if(p != null) { + unUsedIds.add(p.getId()); + Map map = new HashMap<>(); + + map.put("username", p.getUsername()); + map.put("phone", com.lyms.platform.common.utils.StringUtils.encryPhone(p.getPhone())); + map.put("cardNo", com.lyms.platform.common.utils.StringUtils.encryCardNo(p.getCardNo())); + if(p.getType() == 3 || p.getBuildType() == 2) { + map.put("week", "已分娩"); + } else { + map.put("week", DateUtil.getWeekDesc(p.getLastMenses(), new Date())); + } + Map doctorNameCacheMap = new HashMap<>(); + String doctorName = doctorNameCacheMap.get(p.getBookbuildingDoctor()); + if(StringUtils.isEmpty(doctorName)) { + doctorName = couponMapper.getUserName(p.getBookbuildingDoctor()); + doctorNameCacheMap.put(p.getBookbuildingDoctor(), doctorName); + } + map.put("doctorName", doctorName); + String hName = hospitalNameCache.get(p.getHospitalId()); + if(StringUtils.isEmpty(hName)) { + hName = couponMapper.findHospitalNameById(p.getHospitalId()); + hospitalNameCache.put(p.getHospitalId(), hName); + } + map.put("hospitalName", hName); + map.put("checkTime", getCheckTimeByUsedId(patients, antExChuModels, antenatalExaminationModels, maternalDeliverModels, deliverModels, postReviewModels, usedId)); + un_used_coupons.add(map); + } + } + + } + if(flag) { + Map hospitalInfo = couponMapper.findHospitalInfoById(hid); + hospitalInfo.put("cityName", findName(hospitalInfo.get("city_id"))); + hospitalInfo.put("areaName", findName(hospitalInfo.get("area_id"))); + hospitalInfo.put("un_used_coupons", un_used_coupons); + hospitalInfo.put("un_used_coupon_count", un_used_coupons.size()); + hospitalInfo.put("unUsedIds", unUsedIds); + hospitalInfo.put("un_used_people", unUsedIds.size()); + hospitalInfo.put("hospitalId", hid); + hospitalInfo.put("hospitalName", hospitalInfo.get("name")); + restList.add(hospitalInfo); + } + } + } + return RespBuilder.buildSuccess(new PageResult(restList.size(), page, limit, restList)); + } catch (Exception e) { + e.printStackTrace(); + return RespBuilder.buildErro(ResponseCode.ERROR); + } + /*List userIds = new ArrayList<>(); // 存储patientId + for (Patients patient : patients) { + userIds.add(patient.getPid()); + } + System.out.println(userIds); +// Map param = CollectionUtils.createMap("hospitalIds", hospitalIds, "userIds", userIds, "provinceId", provinceId, "cityId", cityId, "areaId", areaId, "page", (page - 1) * limit, "limit", limit); + if(CollectionUtils.isNotEmpty(userIds)) { + Map param = CollectionUtils.createMap("hospitalIds", hospitalIds, "userIds", userIds, "provinceId", provinceId, "cityId", cityId, "areaId", areaId, "page", (page - 1) * limit, "limit", limit); + List> restList = new ArrayList<>(); + for (String hid : hids) { + param.put("hid", hid); + List> list = couponMapper.findUnUsed2(param); + if(CollectionUtils.isNotEmpty(list)) { + Map temp = new HashMap<>(); + Set unUsedIds = new HashSet<>(); // 存储patientId或者是babyId + List> unUsedCoupons = new ArrayList<>(); + Integer unUsedCouponCount = 0; + temp.putAll(list.get(0)); + temp.put("cityName", findName(list.get(0).get("city_id"))); + temp.put("areaName", findName(list.get(0).get("area_id"))); + temp.remove("user_id"); + + Map>> infos = new HashMap<>(); // key = patientId, value = 该patient所对应的所有优惠券 + for (Patients p : patients) { + for (Map coupon : list) { + if(p.getPid().equals(coupon.get("user_id").toString())) { + List> coupons = infos.containsKey(p.getId()) ? infos.get(p.getId()) : new ArrayList>(); + coupons.add(coupon); + infos.put(p.getId(), coupons); + } + } + } + for (Map.Entry>> entry : infos.entrySet()) { + String patientId = entry.getKey(); + for (Patients p : patients) { + if(p.getId().equals(patientId)) { + for (Map map : entry.getValue()) { + System.out.println(DateUtil.getyyyy_MM_dd_hms(p.getCreated()) + " >> " + DateUtil.getyyyy_MM_dd_hms(((Date) map.get("create_date")))); + if(p.getFmDate() != null && p.getFmDate().getTime() < ((Date) map.get("create_date")).getTime()) { // 如果手动终止妊娠了, 那么fmDate应该小于优惠券发放的时间 + continue; + } + if(p.getCreated().getTime() > ((Date) map.get("create_date")).getTime()) { // 同一个产程中 patient的创建时间肯定小于优惠券的创建时间 + continue; + } + String checkTime = getCheckTime((Integer) map.get("type"), (String) map.get("user_id"), patientId); + if(StringUtils.isNotEmpty(checkTime)) { * 如果没有做检查 那么返回的时间就是空字符串 这里等于做了检查但是没用券 + unUsedIds.add(p.getId()); + unUsedCouponCount ++; + map.put("couponName", (couponReportMap.get(map.get("type") + "_" + map.get("coupon_order"))).toString() + .replaceAll("使用人次", "") + .replaceAll("
", "") + .replaceAll("
", "") + .replaceAll("
", "")); + map.put("username", p.getUsername()); + map.put("phone", com.lyms.platform.common.utils.StringUtils.encryPhone(p.getPhone())); + map.put("cardNo", com.lyms.platform.common.utils.StringUtils.encryCardNo(p.getCardNo())); + map.put("week", DateUtil.getWeekDesc(p.getLastMenses(), new Date())); + map.put("doctorName", couponMapper.getUserName(p.getBookbuildingDoctor())); + map.put("hospitalName", couponMapper.findHospitalNameById(p.getHospitalId())); + map.put("checkTime", checkTime); + unUsedCoupons.add(map); + } + } + } + } + } + + + temp.put("un_used_people", unUsedIds.size()); + temp.put("unUsedIds", unUsedIds); + temp.put("un_used_coupons", unUsedCoupons); + temp.put("un_used_coupon_count", unUsedCouponCount); + restList.add(temp); + } + } + return RespBuilder.buildSuccess(new PageResult(restList.size(), page, limit, restList)); + } + return RespBuilder.buildSuccess(new PageResult(0, page, limit, null));*/ + } + + +// @Override + public BaseObjectResponse unUsed2(Date startDate, Date endDate, String provinceId, String cityId, String areaId, String hospitalId, Integer page, Integer limit, Integer userId) { List hospitalIds = getHospitalIds(userId, hospitalId); List> hospitals= couponMapper.findHospitalInfoByIds2(CollectionUtils.createMap("list", hospitalIds, "provinceId", provinceId, "cityId", cityId, "areaId", areaId));