diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/paymentmanage/appservice/impl/IChargeBillServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/paymentmanage/appservice/impl/IChargeBillServiceImpl.java index d9ae3ef1..cac8a2bb 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/paymentmanage/appservice/impl/IChargeBillServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/paymentmanage/appservice/impl/IChargeBillServiceImpl.java @@ -487,9 +487,7 @@ public class IChargeBillServiceImpl implements IChargeBillService { return getMap(map); } Map> paymentDetailsKV - = paymentDetails.stream() - .filter(detail -> detail.getReconciliationId() != null) - .collect(Collectors.groupingBy(PaymentRecDetail::getReconciliationId)); + = paymentDetails.stream().collect(Collectors.groupingBy(PaymentRecDetail::getReconciliationId)); // 声明变量,符合要求的付款记录 Collection PaymentReconciliationList; List accountList = new ArrayList<>(); @@ -570,9 +568,7 @@ public class IChargeBillServiceImpl implements IChargeBillService { throw new ServiceException("未查询到收费记录,无收费项信息"); } Map> chargeItemDefKV - = chargeItemDefinitions.stream() - .filter(def -> def.getId() != null) - .collect(Collectors.groupingBy(ChargeItemDefinition::getId)); + = chargeItemDefinitions.stream().collect(Collectors.groupingBy(ChargeItemDefinition::getId)); // 查询医保结算id List settleIds = new ArrayList<>(); @@ -654,9 +650,585 @@ public class IChargeBillServiceImpl implements IChargeBillService { .in(Invoice::getReconciliationId, returnIds).eq(Invoice::getDeleteFlag, DelFlag.NO.getCode())); if (!invoiceList.isEmpty()) { Map> invoiceKV - = invoiceList.stream() - .filter(inv -> inv.getReconciliationId() != null) - .collect(Collectors.groupingBy(Invoice::getReconciliationId)); + = invoiceList.stream().collect(Collectors.groupingBy(Invoice::getReconciliationId)); + for (PaymentReconciliation paymentReconciliation : returnPaymentList) { + returnBillVO = new ReturnBillVO(); + returnBillVO.setTotalAmount(paymentReconciliation.getTenderedAmount()); + List paymentRecDetails = paymentDetailsKV.get(paymentReconciliation.getId()); + for (PaymentRecDetail paymentRecDetail : paymentRecDetails) { + if (YbPayment.SELF_CASH_PAY.getValue().equals(paymentRecDetail.getPayEnum())) { + returnBillVO.setPaidAmount(paymentRecDetail.getAmount()); + } + } + + if (invoiceKV.get(paymentReconciliation.getId()) == null) { + returnBillVO.setInvoiceNo(""); + } else { + Optional max = invoiceKV.get(paymentReconciliation.getId()).stream() + .max(Comparator.comparing(Invoice::getCreateTime)); + if (max.isPresent()) { + returnBillVO.setInvoiceNo(max.get().getBillNo()); + } else { + returnBillVO.setInvoiceNo(""); + } + } + returnBillVO.setPaymentNo(paymentReconciliation.getPaymentNo()); + returnList.add(returnBillVO); + } + map.put("returnList", returnList);// 退费单 + } + } + + map.put("cashSum", cashSum);// 现金支付 + map.put("rmbCashSum", rmbCashSum);// 现金支付 + map.put("vxCashSum", vxCashSum);// 现金支付() + map.put("aliCashSum", aliCashSum);// 现金支付() + map.put("uniCashSum", uniCashSum);// 现金支付() + map.put("tcSum", tcSum);// 基本统筹 + map.put("zhSum", zhSum);// 账户支付 + map.put("fundSum", fundSum);// 基金支付总额 + + BigDecimal sum01 = BigDecimal.ZERO; + BigDecimal sum02 = BigDecimal.ZERO; + BigDecimal sum03 = BigDecimal.ZERO; + BigDecimal sum04 = BigDecimal.ZERO; + BigDecimal sum05 = BigDecimal.ZERO; + BigDecimal sum06 = BigDecimal.ZERO; + BigDecimal sum07 = BigDecimal.ZERO; + BigDecimal sum08 = BigDecimal.ZERO; + BigDecimal sum09 = BigDecimal.ZERO; + BigDecimal sum10 = BigDecimal.ZERO; + BigDecimal sum11 = BigDecimal.ZERO; + BigDecimal sum12 = BigDecimal.ZERO; + BigDecimal sum13 = BigDecimal.ZERO; + BigDecimal sum14 = BigDecimal.ZERO; + BigDecimal sum15 = BigDecimal.ZERO; + + // 不同医院收费项统计内容不定,下面统计分两个for循环部分统计,一部分按照医保分类统计,一个是按照财务类型的字典去分类 + for (ChargeItem chargeItem : chargeItemList) { + + if (!chargeItem.getStatusEnum().equals(ChargeItemStatus.BILLED.getValue()) + && !chargeItem.getStatusEnum().equals(ChargeItemStatus.REFUNDING.getValue())) { + continue; + } + + Long definitionId = chargeItem.getDefinitionId(); + + ChargeItemDefinition chargeItemDefinition = chargeItemDefKV.get(definitionId).get(0); + + YbMedChrgItmType medChrgItmType + = YbMedChrgItmType.getByCode(Integer.parseInt(chargeItemDefinition.getYbType())); + + switch (medChrgItmType) { + case BED_FEE: + sum01 = sum01.add(chargeItem.getTotalPrice()); + break; + case DIAGNOSTIC_FEE: + sum02 = sum02.add(chargeItem.getTotalPrice()); + break; + case CHECK_FEE: + sum03 = sum03.add(chargeItem.getTotalPrice()); + break; + case DIAGNOSTIC_TEST_FEE: + sum04 = sum04.add(chargeItem.getTotalPrice()); + break; + case MEDICAL_EXPENSE_FEE: + sum05 = sum05.add(chargeItem.getTotalPrice()); + break; + case OPERATION_FEE: + sum06 = sum06.add(chargeItem.getTotalPrice()); + break; + case NURSING_FEE: + sum07 = sum07.add(chargeItem.getTotalPrice()); + break; + case SANITARY_MATERIALS_FEE: + sum08 = sum08.add(chargeItem.getTotalPrice()); + break; + case WEST_MEDICINE: + sum09 = sum09.add(chargeItem.getTotalPrice()); + break; + case CHINESE_MEDICINE_SLICES_FEE: + sum10 = sum10.add(chargeItem.getTotalPrice()); + break; + case CHINESE_MEDICINE_FEE: + sum11 = sum11.add(chargeItem.getTotalPrice()); + break; + case GENERAL_CONSULTATION_FEE: + sum12 = sum12.add(chargeItem.getTotalPrice()); + break; + case REGISTRATION_FEE: + sum13 = sum13.add(chargeItem.getTotalPrice()); + break; + default: + sum14 = sum14.add(chargeItem.getTotalPrice()); + break; + } + } + map.put("BED_FEE", sum01);// 床位费 + map.put("DIAGNOSTIC_FEE", sum02);// 诊察费 + map.put("CHECK_FEE", sum03);// 检查费 + map.put("DIAGNOSTIC_TEST_FEE", sum04);// 化验费 + map.put("MEDICAL_EXPENSE_FEE", sum05);// 治疗费 + map.put("OPERATION_FEE", sum06);// 手术费 + map.put("NURSING_FEE", sum07);// 护理费 + map.put("SANITARY_MATERIALS_FEE", sum08);// 卫生材料费 + map.put("WEST_MEDICINE", sum09);// 西药费 + map.put("CHINESE_MEDICINE_SLICES_FEE", sum10);// 中药饮片费 + map.put("CHINESE_MEDICINE_FEE", sum11);// 中成药费 + map.put("GENERAL_CONSULTATION_FEE", sum12);// 一般诊疗费 + map.put("REGISTRATION_FEE", sum13);// 挂号费 + map.put("OTHER_FEE", sum14);// 其他费用 + sum15 = sum01.add(sum02).add(sum03).add(sum04).add(sum05).add(sum06).add(sum07).add(sum08).add(sum09).add(sum10) + .add(sum11).add(sum12).add(sum13).add(sum14); + map.put("SUM", sum15);// 合计费用 + + // String ybSwitch = SecurityUtils.getLoginUser().getOptionJson().getString(CommonConstants.Option.YB_SWITCH); + JSONObject optionJson = SecurityUtils.getLoginUser().getOptionJson(); + String fixmedinsName = optionJson.getString(CommonConstants.Option.FIXMEDINS_NAME); + String fixmedinsCode = optionJson.getString(CommonConstants.Option.FIXMEDINS_CODE); + + map.put("fixmedinsName", fixmedinsName); + map.put("fixmedinsCode", fixmedinsCode); + + // 以chargeItem 的def为循环分类依据 + for (ChargeItemDefinition chargeItemDefinition : chargeItemDefinitions) { + if (chargeItemDefinition.getTypeCode() == null) { + throw new ServiceException("收费定义未设置财务分类,提示信息chargeItemDefinitionId:" + chargeItemDefinition.getId()); + } + } + Map> chargeItemDefMapByTypeCode + = chargeItemDefinitions.stream().collect(Collectors.groupingBy(ChargeItemDefinition::getTypeCode)); + Map> chargeItemMapByDefinitionId + = chargeItemList.stream().collect(Collectors.groupingBy(ChargeItem::getDefinitionId)); + + for (Map.Entry> stringListEntry : chargeItemDefMapByTypeCode.entrySet()) { + String key = stringListEntry.getKey(); + BigDecimal bigDecimal = BigDecimal.ZERO; + for (ChargeItemDefinition chargeItemDefinition : stringListEntry.getValue()) { + List chargeItems = chargeItemMapByDefinitionId.get(chargeItemDefinition.getId()); + for (ChargeItem chargeItem : chargeItems) { + if (chargeItem.getStatusEnum() != ChargeItemStatus.BILLED.getValue()) { + continue; + } + bigDecimal = bigDecimal.add(chargeItem.getTotalPrice()); + } + } + map.put(key, bigDecimal); + } + + return map; + } + + /** + * 长大版本(门诊) 2025/08/06版 + * + * @param + * @return + */ + @Override + public Map getTotalCcu(String startTime, String endTime, Long entererId) { + // String contractNo="220100"; + Map map = new HashMap<>(); + + // SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS"); + Date startDate = DateUtils.parseDate(startTime); + Date endDate = DateUtils.parseDate(endTime); + + // 查询所有的门诊支付记录(包含4种类型单据:a:该时间内的正向交易记录;b:该时间内的反向交易记录,但关联的正向单在该时间内;c:该时间内的反向交易记录,但是关联正向单在该时间之前;d:该时间内的正向交易记录,但是关联反向单在该时间之后;) + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() + .between(PaymentReconciliation::getBillDate, startDate, endDate) + .eq(PaymentReconciliation::getDeleteFlag, DelFlag.NO.getCode()) + .in(PaymentReconciliation::getStatusEnum, PaymentStatus.SUCCESS.getValue(), + PaymentStatus.REFUND_ALL.getValue()) + .eq(PaymentReconciliation::getKindEnum, PaymentKind.OUTPATIENT_CLINIC.getValue()); + if (entererId != null) { + queryWrapper.eq(PaymentReconciliation::getEntererId, entererId); + } + List paymentReconciliationList = paymentReconciliationService.list(queryWrapper); + if (paymentReconciliationList.isEmpty()) { + return getMap(map); + } + + // for (PaymentReconciliation paymentReconciliation : paymentReconciliationList) { + // String[] split = paymentReconciliation.getChargeItemIds().split(","); + // List strings = Arrays.asList(split); + // for (String string : strings) { + // ChargeItem byId = chargeItemService.getById(Long.parseLong(string)); + // if ("adm_healthcare_service".equals(byId.getServiceTable())) { + // System.out.println("//****************************"); + // System.out.println(JSON.toJSONString(byId)); + // } + // } + // } + // 查询所有的支付详情 + List paymentIdList + = paymentReconciliationList.stream().map(PaymentReconciliation::getId).collect(Collectors.toList()); + // List paymentDetails = paymentRecDetailService + // .list(new LambdaQueryWrapper().in(PaymentRecDetail::getReconciliationId, paymentIdList) + // .eq(PaymentRecDetail::getDeleteFlag, DelFlag.NO.getCode())); + + List PaymentRecDetailAccountResultList + = paymentRecDetailService.getListByReconciliationIds(paymentIdList, PaymentKind.OUTPATIENT_CLINIC.getValue()); + if (PaymentRecDetailAccountResultList.isEmpty()) { + return getMap(map); + } + + // 根据主键分组 + Map> paymentDetailsKV = PaymentRecDetailAccountResultList.stream() + .collect(Collectors.groupingBy(PaymentRecDetailAccountResult::getReconciliationId)); + + // 调试使用代码 + // for (PaymentReconciliation paymentReconciliation : paymentReconciliationList) { + // List paymentRecDetailAccountResults = + // paymentDetailsKV.get(paymentReconciliation.getId()); + // BigDecimal bigDecimal = BigDecimal.ZERO; + // for (PaymentRecDetailAccountResult paymentRecDetailAccountResult : paymentRecDetailAccountResults) { + // if (YbPayment.SELF_YB_ZH_PAY.getValue().equals(paymentRecDetailAccountResult.getPayEnum())) { + // bigDecimal = bigDecimal.add(paymentRecDetailAccountResult.getAmount()); + // } + // if (YbPayment.YB_FUND_PAY.getValue().equals(paymentRecDetailAccountResult.getPayEnum())) { + // bigDecimal = bigDecimal.add(paymentRecDetailAccountResult.getAmount()); + // } + // if (YbPayment.SELF_CASH_PAY.getValue().equals(paymentRecDetailAccountResult.getPayEnum())) { + // bigDecimal = bigDecimal.add(paymentRecDetailAccountResult.getAmount()); + // } + // } + // if (bigDecimal.compareTo(paymentReconciliation.getTenderedAmount()) != 0) { + // System.out.println("//////**********************///////"); + // System.out.println("payment:" + paymentReconciliation.getId()); + // System.out.println("paymentAmount:" + paymentReconciliation.getTenderedAmount()); + // System.out.println("payment应收:" + paymentReconciliation.getDisplayAmount()); + // System.out.println("//////**********************///////"); + // } + // if (paymentReconciliation.getStatusEnum() == 3) { + // continue; + // } + // List collect = Arrays.stream(paymentReconciliation.getChargeItemIds().split(",")) + // .map(e -> Long.parseLong(e)).collect(Collectors.toList()); + // List chargeItemBaseInfoByIds = chargeItemService.getChargeItemBaseInfoByIds(collect); + // BigDecimal bigDecimal1 = BigDecimal.ZERO; + // for (ChargeItemBaseInfoDto chargeItemBaseInfoById : chargeItemBaseInfoByIds) { + // bigDecimal1 = bigDecimal1.add(chargeItemBaseInfoById.getTotalPrice()); + // System.out.println("收费项:" + chargeItemBaseInfoById.getTotalPrice()); + // } + // System.out.println("付款:" + paymentReconciliation.getTenderedAmount()); + // if (bigDecimal1.compareTo(paymentReconciliation.getTenderedAmount()) != 0) { + // System.out.println("//////**********************///////"); + // System.out.println("payment:" + paymentReconciliation.getId()); + // System.out.println("paymentAmount:" + paymentReconciliation.getTenderedAmount()); + // System.out.println("payment应收:" + paymentReconciliation.getDisplayAmount()); + // System.out.println("//////**********************///////"); + // } + // } + // List list1 = chargeItemService.list(new LambdaQueryWrapper() + // .eq(ChargeItem::getStatusEnum, 5).between(ChargeItem::getCreateTime, startDate, endDate)); + // for (ChargeItem chargeItem : list1) { + // PaymentReconciliation one = + // paymentReconciliationService.getOne(new LambdaQueryWrapper() + // .like(PaymentReconciliation::getChargeItemIds, chargeItem.getId()) + // .eq(PaymentReconciliation::getStatusEnum, 1)); + // if (one == null) { + // throw new ServiceException("收费项:" + chargeItem.getId()); + // } + // } + // 根据省市医保分组 + Map> paymentDetailsMapByContract = PaymentRecDetailAccountResultList + .stream().collect(Collectors.groupingBy(PaymentRecDetailAccountResult::getContractNo)); + + // 查询所有的收费项 + List chargeItemIdStrs = paymentReconciliationList.stream().map(PaymentReconciliation::getChargeItemIds) + .collect(Collectors.toList()); + List chargeItemIds = new ArrayList<>(); + for (String chargeItemIdStr : chargeItemIdStrs) { + List strings = Arrays.asList(chargeItemIdStr.split(",")); + for (String string : strings) { + Long id = Long.parseLong(string); + chargeItemIds.add(id); + } + } + + List chargeItemList = chargeItemService.list(new LambdaQueryWrapper() + .in(ChargeItem::getId, chargeItemIds).eq(ChargeItem::getDeleteFlag, DelFlag.NO.getCode())); + if (chargeItemList.isEmpty()) { + throw new ServiceException("数据异常,该时间段内未查询到收费项"); + } + + // for (ChargeItem chargeItem : chargeItemList) { + // if("adm_healthcare_service".equals(chargeItem.getServiceTable())){ + // System.out.println("//****************************"); + // System.out.println(JSON.toJSONString(chargeItem)); + // } + // } + // 查询收费定义列表 + List chargeItemDefinitionIdList + = chargeItemList.stream().map(ChargeItem::getDefinitionId).collect(Collectors.toList()); + if (chargeItemDefinitionIdList.isEmpty()) { + throw new ServiceException("未查询到收费记录,无收费项信息"); + } + List chargeItemDefinitions + = iChargeItemDefinitionService.listByIds(chargeItemDefinitionIdList); + if (chargeItemDefinitions.isEmpty()) { + throw new ServiceException("未查询到收费记录,无收费项信息"); + } + Map> chargeItemDefKV + = chargeItemDefinitions.stream().collect(Collectors.groupingBy(ChargeItemDefinition::getId)); + + // 查询医保结算id + List settleIds = new ArrayList<>(); + for (PaymentReconciliation paymentReconciliation : paymentReconciliationList) { + if (!StringUtils.isEmpty(paymentReconciliation.getYbSettleIds())) { + List strings = Arrays.asList(paymentReconciliation.getYbSettleIds().split(",")); + settleIds.addAll(strings); + } + } + + List clinicSettleList = new ArrayList<>(); + List clinicUnSettleList = new ArrayList<>(); + if (!settleIds.isEmpty()) { + clinicSettleList = iClinicSettleService.getBySettleIds(settleIds); + clinicUnSettleList = iClinicUnSettleService.getBySettleIds(settleIds); + // List collect = clinicSettle.stream().map(ClinicSettle::getInsutype).collect(Collectors.toList()); + } + + BigDecimal cashSum = BigDecimal.ZERO;// 现金总数 = rmbCashSum + vxCashSum + aliCashSum + uniCashSum + BigDecimal rmbCashSum = BigDecimal.ZERO;// 现金总数 + BigDecimal vxCashSum = BigDecimal.ZERO;// 现金总数() + BigDecimal aliCashSum = BigDecimal.ZERO;// 现金总数() + BigDecimal uniCashSum = BigDecimal.ZERO;// 现金总数() + BigDecimal vxSum = BigDecimal.ZERO;// 微信总数 + BigDecimal aliSum = BigDecimal.ZERO;// 支付宝总数 + BigDecimal uniSum = BigDecimal.ZERO;// 银行卡总数 + // BigDecimal tcSum = BigDecimal.ZERO;// 基本统筹 + // BigDecimal zhSum = BigDecimal.ZERO;// 医保账户 + // BigDecimal fundSum = BigDecimal.ZERO;// 基金支总额 + BigDecimal SelfCashSum = BigDecimal.ZERO;// 自费现金总额 + BigDecimal YbCashSum = BigDecimal.ZERO;// 医保现金总额 + // 长大版本要显示出来省市医保的区别 + List redisContractList = iContractService.getRedisContractList(); + Map> contractMapByBusNo + = redisContractList.stream().collect(Collectors.groupingBy(Contract::getBusNo)); + for (Map.Entry> stringListEntry : paymentDetailsMapByContract + .entrySet()) { + String key = stringListEntry.getKey(); + List value = stringListEntry.getValue(); + BigDecimal tcSum = BigDecimal.ZERO;// 基本统筹 + BigDecimal cash = BigDecimal.ZERO;// 现金 + BigDecimal zhSum = BigDecimal.ZERO;// 医保账户 + BigDecimal fundSum = BigDecimal.ZERO;// 基金支总额 + for (PaymentRecDetailAccountResult paymentRecDetailAccountResult : value) { + if (YbPayment.SELF_CASH_PAY.getValue().equals(paymentRecDetailAccountResult.getPayEnum())) { + cash = cash.add(paymentRecDetailAccountResult.getAmount()); + } + if (YbPayment.SELF_CASH_VALUE.getValue().equals(paymentRecDetailAccountResult.getPayEnum())) { + rmbCashSum = rmbCashSum.add(paymentRecDetailAccountResult.getAmount()); + } + if (YbPayment.SELF_CASH_VX_VALUE.getValue().equals(paymentRecDetailAccountResult.getPayEnum())) { + vxCashSum = vxCashSum.add(paymentRecDetailAccountResult.getAmount()); + } + if (YbPayment.SELF_CASH_ALI_VALUE.getValue().equals(paymentRecDetailAccountResult.getPayEnum())) { + aliCashSum = aliCashSum.add(paymentRecDetailAccountResult.getAmount()); + } + if (YbPayment.SELF_CASH_UNION_VALUE.getValue().equals(paymentRecDetailAccountResult.getPayEnum())) { + uniCashSum = uniCashSum.add(paymentRecDetailAccountResult.getAmount()); + } + if (YbPayment.YB_TC_FUND_AMOUNT.getValue().equals(paymentRecDetailAccountResult.getPayEnum())) { + tcSum = tcSum.add(paymentRecDetailAccountResult.getAmount()); + } + if (YbPayment.YB_FUND_PAY.getValue().equals(paymentRecDetailAccountResult.getPayEnum())) { + fundSum = fundSum.add(paymentRecDetailAccountResult.getAmount()); + } + if (YbPayment.SELF_YB_ZH_PAY.getValue().equals(paymentRecDetailAccountResult.getPayEnum())) { + zhSum = zhSum.add(paymentRecDetailAccountResult.getAmount()); + } + // 其他的大病支付或者慢病特病支付往下接if + map.put( + contractMapByBusNo.get(key) == null ? key : contractMapByBusNo.get(key).get(0).getBusNo() + "cash", + cash); + map.put( + contractMapByBusNo.get(key) == null ? key : contractMapByBusNo.get(key).get(0).getBusNo() + "tcSum", + tcSum); + map.put( + contractMapByBusNo.get(key) == null ? key : contractMapByBusNo.get(key).get(0).getBusNo() + "zhSum", + zhSum); + map.put(contractMapByBusNo.get(key) == null ? key + : contractMapByBusNo.get(key).get(0).getBusNo() + "fundSum", fundSum); + } + } + // for (PaymentRecDetail paymentDetail : paymentDetails) { + // if (YbPayment.SELF_CASH_PAY.getValue().equals(paymentDetail.getPayEnum())) { + // cashSum = cashSum.add(paymentDetail.getAmount()); + // if (paymentDetail.getPayTransText() != null && paymentDetail.getPayTransText().length() > 10) { + // YbCashSum = YbCashSum.add(paymentDetail.getAmount()); + // } else { + // SelfCashSum = SelfCashSum.add(paymentDetail.getAmount()); + // } + // } + // if (YbPayment.SELF_CASH_VALUE.getValue().equals(paymentDetail.getPayEnum())) { + // rmbCashSum = rmbCashSum.add(paymentDetail.getAmount()); + // } + // if (YbPayment.SELF_CASH_VX_VALUE.getValue().equals(paymentDetail.getPayEnum())) { + // vxCashSum = vxCashSum.add(paymentDetail.getAmount()); + // } + // if (YbPayment.SELF_CASH_ALI_VALUE.getValue().equals(paymentDetail.getPayEnum())) { + // aliCashSum = aliCashSum.add(paymentDetail.getAmount()); + // } + // if (YbPayment.SELF_CASH_UNION_VALUE.getValue().equals(paymentDetail.getPayEnum())) { + // uniCashSum = uniCashSum.add(paymentDetail.getAmount()); + // } + // if (YbPayment.YB_TC_FUND_AMOUNT.getValue().equals(paymentDetail.getPayEnum())) { + // tcSum = tcSum.add(paymentDetail.getAmount()); + // } + // if (YbPayment.YB_FUND_PAY.getValue().equals(paymentDetail.getPayEnum())) { + // fundSum = fundSum.add(paymentDetail.getAmount()); + // } + // if (YbPayment.SELF_YB_ZH_PAY.getValue().equals(paymentDetail.getPayEnum())) { + // zhSum = zhSum.add(paymentDetail.getAmount()); + // } + // // 其他的大病支付或者慢病特病支付往下接if + // } + + BigDecimal sum01 = BigDecimal.ZERO; + BigDecimal sum02 = BigDecimal.ZERO; + BigDecimal sum03 = BigDecimal.ZERO; + BigDecimal sum04 = BigDecimal.ZERO; + BigDecimal sum05 = BigDecimal.ZERO; + BigDecimal sum06 = BigDecimal.ZERO; + BigDecimal sum07 = BigDecimal.ZERO; + BigDecimal sum08 = BigDecimal.ZERO; + BigDecimal sum09 = BigDecimal.ZERO; + BigDecimal sum10 = BigDecimal.ZERO; + BigDecimal sum11 = BigDecimal.ZERO; + BigDecimal sum12 = BigDecimal.ZERO; + BigDecimal sum13 = BigDecimal.ZERO; + BigDecimal sum14 = BigDecimal.ZERO; + BigDecimal sum15 = BigDecimal.ZERO; + + // 处理退费单 + List returnList = new ArrayList<>(); + List returnPaymentList = new ArrayList<>(); + ReturnBillVO returnBillVO; + for (PaymentReconciliation paymentReconciliation : paymentReconciliationList) { + if (PaymentType.UN_PAY.getValue().equals(paymentReconciliation.getPaymentEnum())) { + returnPaymentList.add(paymentReconciliation); + } + } + // 按照字典取值时使用的变量 + List beforeChargeItemDefinitions = new ArrayList<>(); + List beforeChargeItemList = new ArrayList<>(); + if (!returnPaymentList.isEmpty()) { + List returnIds + = returnPaymentList.stream().map(PaymentReconciliation::getId).collect(Collectors.toList()); + // 查原付款单子 + List relationIdList + = returnPaymentList.stream().map(PaymentReconciliation::getRelationId).collect(Collectors.toList()); + if (relationIdList.isEmpty() || returnPaymentList.size() != relationIdList.size()) { + throw new ServiceException("数据异常,存在无法关联到原单的退款单,请联系工程师"); + } + // 原单是该时间段前付款的 + List beforeList = new ArrayList<>(); + List paymentReconciliations = paymentReconciliationService + .list(new LambdaQueryWrapper().in(PaymentReconciliation::getId, relationIdList) + .eq(PaymentReconciliation::getDeleteFlag, DelFlag.NO.getCode())); + for (PaymentReconciliation paymentReconciliation : paymentReconciliations) { + if (startDate.compareTo(paymentReconciliation.getBillDate()) > 0) { + beforeList.add(paymentReconciliation); + } + } + if (!beforeList.isEmpty()) { + // 拆解所有的chargeItemId,拼装成一个集合 + List chargeItemIdList + = beforeList.stream().map(PaymentReconciliation::getChargeItemIds).collect(Collectors.toList()); + List beforeChargeItemIds = new ArrayList<>(); + for (String chargeItemId : chargeItemIdList) { + if (StringUtils.isNotEmpty(chargeItemId)) { + beforeChargeItemIds.addAll(Arrays + .stream(chargeItemId.replaceAll("\\[", "").replaceAll("\\]", "") + .split(CommonConstants.Common.COMMA)) + .map(Long::parseLong).collect(Collectors.toList())); + } + } + beforeChargeItemList = chargeItemService.list(new LambdaQueryWrapper() + .in(ChargeItem::getId, beforeChargeItemIds).eq(ChargeItem::getDeleteFlag, DelFlag.NO.getCode())); + if (beforeChargeItemList.isEmpty()) { + throw new ServiceException("数据异常,查找不到退费收费项信息"); + } + List beforeChargeItemDefinitionIdList + = beforeChargeItemList.stream().map(ChargeItem::getDefinitionId).collect(Collectors.toList()); + if (beforeChargeItemDefinitionIdList.isEmpty()) { + throw new ServiceException("数据异常,查找不到收费项的定义信息"); + } + beforeChargeItemDefinitions = iChargeItemDefinitionService.listByIds(beforeChargeItemDefinitionIdList); + for (ChargeItem chargeItem : beforeChargeItemList) { + + if (!chargeItem.getStatusEnum().equals(ChargeItemStatus.REFUNDED.getValue())) { + continue; + } + + chargeItem.setTotalPrice(new BigDecimal("-1").multiply(chargeItem.getTotalPrice())); + + Long definitionId = chargeItem.getDefinitionId(); + // if(chargeItemDefKV.get(definitionId)==null){ + // System.out.println(chargeItem.getId()); + // System.out.println(JSON.toJSONString(chargeItem)); + // } + + ChargeItemDefinition chargeItemDefinition = chargeItemDefKV.get(definitionId).get(0); + + YbMedChrgItmType medChrgItmType + = YbMedChrgItmType.getByCode(Integer.parseInt(chargeItemDefinition.getYbType())); + + switch (medChrgItmType) { + case BED_FEE: + sum01 = sum01.add(chargeItem.getTotalPrice()); + break; + case DIAGNOSTIC_FEE: + sum02 = sum02.add(chargeItem.getTotalPrice()); + break; + case CHECK_FEE: + sum03 = sum03.add(chargeItem.getTotalPrice()); + break; + case DIAGNOSTIC_TEST_FEE: + sum04 = sum04.add(chargeItem.getTotalPrice()); + break; + case MEDICAL_EXPENSE_FEE: + sum05 = sum05.add(chargeItem.getTotalPrice()); + break; + case OPERATION_FEE: + sum06 = sum06.add(chargeItem.getTotalPrice()); + break; + case NURSING_FEE: + sum07 = sum07.add(chargeItem.getTotalPrice()); + break; + case SANITARY_MATERIALS_FEE: + sum08 = sum08.add(chargeItem.getTotalPrice()); + break; + case WEST_MEDICINE: + sum09 = sum09.add(chargeItem.getTotalPrice()); + break; + case CHINESE_MEDICINE_SLICES_FEE: + sum10 = sum10.add(chargeItem.getTotalPrice()); + break; + case CHINESE_MEDICINE_FEE: + sum11 = sum11.add(chargeItem.getTotalPrice()); + break; + case GENERAL_CONSULTATION_FEE: + sum12 = sum12.add(chargeItem.getTotalPrice()); + break; + case REGISTRATION_FEE: + sum13 = sum13.add(chargeItem.getTotalPrice()); + break; + default: + sum14 = sum14.add(chargeItem.getTotalPrice()); + break; + } + } + } + + List invoiceList = iInvoiceService.list(new LambdaUpdateWrapper() + .in(Invoice::getReconciliationId, returnIds).eq(Invoice::getDeleteFlag, DelFlag.NO.getCode())); + if (!invoiceList.isEmpty()) { + Map> invoiceKV + = invoiceList.stream().collect(Collectors.groupingBy(Invoice::getReconciliationId)); for (PaymentReconciliation paymentReconciliation : returnPaymentList) { returnBillVO = new ReturnBillVO(); returnBillVO.setTotalAmount(paymentReconciliation.getTenderedAmount()); @@ -790,13 +1362,9 @@ public class IChargeBillServiceImpl implements IChargeBillService { } Map> chargeItemDefMapByTypeCode - = chargeItemDefinitions.stream() - .filter(def -> def.getTypeCode() != null && !def.getTypeCode().isEmpty()) - .collect(Collectors.groupingBy(ChargeItemDefinition::getTypeCode)); + = chargeItemDefinitions.stream().collect(Collectors.groupingBy(ChargeItemDefinition::getTypeCode)); Map> chargeItemMapByDefinitionId - = chargeItemList.stream() - .filter(item -> item.getDefinitionId() != null) - .collect(Collectors.groupingBy(ChargeItem::getDefinitionId)); + = chargeItemList.stream().collect(Collectors.groupingBy(ChargeItem::getDefinitionId)); for (Map.Entry> stringListEntry : chargeItemDefMapByTypeCode.entrySet()) { String key = stringListEntry.getKey(); @@ -816,13 +1384,9 @@ public class IChargeBillServiceImpl implements IChargeBillService { // 超本时间段的退费单统计 if (!beforeChargeItemDefinitions.isEmpty() && !beforeChargeItemList.isEmpty()) { Map> beforeChargeItemDefMapByTypeCode - = beforeChargeItemDefinitions.stream() - .filter(def -> def.getTypeCode() != null && !def.getTypeCode().isEmpty()) - .collect(Collectors.groupingBy(ChargeItemDefinition::getTypeCode)); + = beforeChargeItemDefinitions.stream().collect(Collectors.groupingBy(ChargeItemDefinition::getTypeCode)); Map> beforeChargeItemMapByDefinitionId - = beforeChargeItemList.stream() - .filter(item -> item.getDefinitionId() != null) - .collect(Collectors.groupingBy(ChargeItem::getDefinitionId)); + = beforeChargeItemList.stream().collect(Collectors.groupingBy(ChargeItem::getDefinitionId)); for (Map.Entry> longListEntry : beforeChargeItemDefMapByTypeCode .entrySet()) { BigDecimal bigDecimal = map.get(longListEntry.getKey()) == null ? BigDecimal.ZERO @@ -844,9 +1408,7 @@ public class IChargeBillServiceImpl implements IChargeBillService { // 医保人次自费人次计算 List list = iEncounterService.getEncounterInfoByTime(startDate, endDate); Map> encounterAccountDtoMapByContract - = list.stream() - .filter(dto -> dto.getContractNo() != null && !dto.getContractNo().isEmpty()) - .collect(Collectors.groupingBy(EncounterAccountDto::getContractNo)); + = list.stream().collect(Collectors.groupingBy(EncounterAccountDto::getContractNo)); for (Map.Entry> stringListEntry : encounterAccountDtoMapByContract .entrySet()) { String key = stringListEntry.getKey(); @@ -916,14 +1478,11 @@ public class IChargeBillServiceImpl implements IChargeBillService { // 支付详情根据主键分组 Map> paymentDetailsKV = PaymentRecDetailAccountResultList.stream() - .filter(detail -> detail.getReconciliationId() != null) - .collect(Collectors.groupingBy(PaymentRecDetailAccountResult::getReconciliationId)); + .collect(Collectors.groupingBy(PaymentRecDetailAccountResult::getReconciliationId)); // 根据省市医保分组 Map> paymentDetailsMapByContract = PaymentRecDetailAccountResultList - .stream() - .filter(dto -> dto.getContractNo() != null && !dto.getContractNo().isEmpty()) - .collect(Collectors.groupingBy(PaymentRecDetailAccountResult::getContractNo)); + .stream().collect(Collectors.groupingBy(PaymentRecDetailAccountResult::getContractNo)); BigDecimal cashSum = BigDecimal.ZERO;// 现金总数 = rmbCashSum + vxCashSum + aliCashSum + uniCashSum BigDecimal rmbCashSum = BigDecimal.ZERO;// 现金总数 @@ -939,9 +1498,7 @@ public class IChargeBillServiceImpl implements IChargeBillService { // 长大版本要显示出来省市医保的区别 List redisContractList = iContractService.getRedisContractList(); Map> contractMapByBusNo - = redisContractList.stream() - .filter(c -> c.getBusNo() != null && !c.getBusNo().isEmpty()) - .collect(Collectors.groupingBy(Contract::getBusNo)); + = redisContractList.stream().collect(Collectors.groupingBy(Contract::getBusNo)); for (Map.Entry> stringListEntry : paymentDetailsMapByContract .entrySet()) { @@ -1022,9 +1579,7 @@ public class IChargeBillServiceImpl implements IChargeBillService { Map> returnPaymentMapByRelationId = new HashMap<>(); if (!returnList.isEmpty()) { returnPaymentMapByRelationId - = returnList.stream() - .filter(item -> item.getRelationId() != null) - .collect(Collectors.groupingBy(PaymentReconciliationAccountDel::getRelationId)); + = returnList.stream().collect(Collectors.groupingBy(PaymentReconciliationAccountDel::getRelationId)); } List addChargeItemIds = new ArrayList<>(); @@ -1086,9 +1641,7 @@ public class IChargeBillServiceImpl implements IChargeBillService { throw new ServiceException("数据异常,该时间段内未查询到收费项"); } Map> chargeItemDefInfoKVById - = chargeItemDefInfoByIds.stream() - .filter(info -> info.getId() != null) - .collect(Collectors.groupingBy(ChargeItemDefInfo::getId)); + = chargeItemDefInfoByIds.stream().collect(Collectors.groupingBy(ChargeItemDefInfo::getId)); // 省名变量 BigDecimal bedFee = BigDecimal.ZERO;// 床位费 @@ -1296,9 +1849,7 @@ public class IChargeBillServiceImpl implements IChargeBillService { .in(Invoice::getReconciliationId, returnIds).eq(Invoice::getDeleteFlag, DelFlag.NO.getCode())); if (!invoiceList.isEmpty()) { Map> invoiceKV - = invoiceList.stream() - .filter(inv -> inv.getReconciliationId() != null) - .collect(Collectors.groupingBy(Invoice::getReconciliationId)); + = invoiceList.stream().collect(Collectors.groupingBy(Invoice::getReconciliationId)); for (PaymentReconciliationAccountDel paymentReconciliation : returnList) { returnBillVO = new ReturnBillVO(); returnBillVO.setTotalAmount(paymentReconciliation.getTenderedAmount()); @@ -1334,9 +1885,7 @@ public class IChargeBillServiceImpl implements IChargeBillService { // 医保人次自费人次计算 List list = iEncounterService.getEncounterInfoByTime(startDate, endDate); Map> encounterAccountDtoMapByContract - = list.stream() - .filter(dto -> dto.getContractNo() != null && !dto.getContractNo().isEmpty()) - .collect(Collectors.groupingBy(EncounterAccountDto::getContractNo)); + = list.stream().collect(Collectors.groupingBy(EncounterAccountDto::getContractNo)); for (Map.Entry> stringListEntry : encounterAccountDtoMapByContract .entrySet()) { String key = stringListEntry.getKey(); @@ -1678,9 +2227,7 @@ public class IChargeBillServiceImpl implements IChargeBillService { = chargeBillMapper.selectChargeItemExtendInfoList(chargeItemIds, chargeSummaryDto.getOrgIdList()); Map> chargeItemExtendInfoDtoListGroupByOrgIdMap - = ChargeItemExtendInfoDtoList.stream() - .filter(dto -> dto.getOrgId() != null) - .collect(Collectors.groupingBy(ChargeItemExtendInfoDto::getOrgId)); + = ChargeItemExtendInfoDtoList.stream().collect(Collectors.groupingBy(ChargeItemExtendInfoDto::getOrgId)); LambdaQueryWrapper organizationLambdaQueryWrapper = new LambdaQueryWrapper().eq(Organization::getTypeEnum, OrganizationType.DEPARTMENT.getValue()) .eq(Organization::getDeleteFlag, DelFlag.NO.getCode()).orderByDesc(Organization::getDisplayOrder);