From 83671834ca4eab3bd296024eec817e0882962279 Mon Sep 17 00:00:00 2001 From: chenqi Date: Sun, 21 Jun 2026 05:19:38 +0800 Subject: [PATCH] refactor: split IChargeBillServiceImpl into focused services --- .../impl/ChargeBillCalculationService.java | 1786 +++++++++++ .../impl/ChargeBillQueryService.java | 611 ++++ .../impl/ChargeBillStatisticsService.java | 88 + .../impl/IChargeBillServiceImpl.java | 2727 +---------------- 4 files changed, 2504 insertions(+), 2708 deletions(-) create mode 100644 healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/paymentmanage/appservice/impl/ChargeBillCalculationService.java create mode 100644 healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/paymentmanage/appservice/impl/ChargeBillQueryService.java create mode 100644 healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/paymentmanage/appservice/impl/ChargeBillStatisticsService.java diff --git a/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/paymentmanage/appservice/impl/ChargeBillCalculationService.java b/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/paymentmanage/appservice/impl/ChargeBillCalculationService.java new file mode 100644 index 000000000..d1f2b86e4 --- /dev/null +++ b/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/paymentmanage/appservice/impl/ChargeBillCalculationService.java @@ -0,0 +1,1786 @@ +package com.healthlink.his.web.paymentmanage.appservice.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.core.common.enums.DelFlag; +import com.core.common.exception.ServiceException; +import com.core.common.utils.*; +import com.healthlink.his.administration.domain.*; +import com.healthlink.his.administration.dto.ChargeItemDefInfo; +import com.healthlink.his.administration.dto.EncounterAccountDto; +import com.healthlink.his.administration.service.*; +import com.healthlink.his.common.constant.CommonConstants; +import com.healthlink.his.common.enums.*; +import com.healthlink.his.yb.enums.YbMedChrgItmType; +import com.healthlink.his.yb.enums.YbPayment; +import com.healthlink.his.financial.domain.Contract; +import com.healthlink.his.financial.domain.PaymentRecDetail; +import com.healthlink.his.financial.domain.PaymentReconciliation; +import com.healthlink.his.financial.model.PaymentRecDetailAccountResult; +import com.healthlink.his.financial.model.PaymentReconciliationAccountDel; +import com.healthlink.his.financial.service.IContractService; +import com.healthlink.his.financial.service.IPaymentRecDetailService; +import com.healthlink.his.financial.service.IPaymentReconciliationService; +import com.healthlink.his.web.paymentmanage.dto.*; +import com.healthlink.his.web.paymentmanage.mapper.ChargeBillMapper; +import com.healthlink.his.yb.domain.ClinicSettle; +import com.healthlink.his.yb.domain.ClinicUnSettle; +import com.healthlink.his.yb.service.*; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.stream.Collectors; + +/** + * 收费票据计算服务 - 处理计算/统计相关方法 + */ +@Component +@Slf4j +public class ChargeBillCalculationService { + + @Autowired + private IAccountService iAccountService; + @Autowired + private IEncounterService iEncounterService; + @Autowired + private IContractService iContractService; + @Autowired + private IInvoiceService iInvoiceService; + @Autowired + private IPaymentReconciliationService paymentReconciliationService; + @Autowired + private IPaymentRecDetailService paymentRecDetailService; + @Autowired + private IChargeItemService chargeItemService; + @Autowired + private IPatientService iPatientService; + @Autowired + private IChargeItemDefinitionService iChargeItemDefinitionService; + @Autowired + private IOrganizationService iOrganizationService; + @Autowired + private ChargeBillMapper chargeBillMapper; + @Autowired + private IClinicSettleService iClinicSettleService; + @Autowired + private IClinicUnSettleService iClinicUnSettleService; + @Autowired + private IPractitionerService iPractitionerService; + + /** + * 农大版本 + */ + public Map getTotal(String startTime, String endTime, Long entererId, String contractNo) { + Map map = new HashMap<>(); + + Date startDate = DateUtils.parseDate(startTime); + Date endDate = DateUtils.parseDate(endTime); + + 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); + } + + 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()).notIn(PaymentRecDetail::getPayEnum, + YbPayment.SUPPLEMENTARY_INSURANCE.getValue(), YbPayment.SUPPLEMENTARY_INSURANCE.getValue(), + YbPayment.FULAMT_OWNPAY_AMT.getValue(), YbPayment.OVERLMT_SELFPAY.getValue(), + YbPayment.PRESELFPAY_AMT.getValue(), YbPayment.INSCP_SCP_AMT.getValue(), + YbPayment.ACT_PAY_DEDC.getValue(), YbPayment.POOL_PROP_SELFPAY.getValue(), + YbPayment.BALC.getValue(), YbPayment.BIRTH_FUND.getValue(), YbPayment.RETIREE_MEDICAL.getValue(), + YbPayment.MEDICAL_ASSISTANCE.getValue(), YbPayment.URBAN_SERIOUS_ILLNESS.getValue(), + YbPayment.URBAN_BASIC_MEDICAL.getValue(), YbPayment.GOVERNMENT_SUBSIDY.getValue(), + YbPayment.ACCIDENT_INSURANCE.getValue(), YbPayment.CARE_INSURANCE.getValue(), + YbPayment.FINANCIAL_FUND.getValue(), YbPayment.HOSPITAL_ADVANCE.getValue(), + YbPayment.SUPPLEMENTARY_INSURANCE.getValue(), + YbPayment.BASIC_MEDICAL_INSURANCE_FOR_URBAN_EMPLOYEES.getValue(), YbPayment.E_WALLET.getValue(), + YbPayment.HEALTHCARE_PREPAYMENT.getValue())); + if (paymentDetails.isEmpty()) { + return getMap(map); + } + Map> paymentDetailsKV + = paymentDetails.stream().collect(Collectors.groupingBy(PaymentRecDetail::getReconciliationId)); + Collection PaymentReconciliationList; + List accountList = new ArrayList<>(); + if (!StringUtils.isEmpty(contractNo)) { + List accountIds + = paymentDetails.stream().map(PaymentRecDetail::getAccountId).collect(Collectors.toList()); + if (accountIds.isEmpty()) { + throw new ServiceException("查询账户信息为空"); + } + accountList = iAccountService.list(new LambdaQueryWrapper().in(Account::getId, accountIds)); + + Map paymentMap = new HashMap<>(); + for (PaymentRecDetail paymentDetail : paymentDetails) { + + Optional first + = accountList.stream().filter(x -> x.getId().equals(paymentDetail.getAccountId())).findFirst(); + if (first.isEmpty() || !first.get().getContractNo().equals(contractNo)) { + continue; + } + Optional first1 = paymentReconciliationList.stream() + .filter(x -> x.getId().equals(paymentDetail.getReconciliationId())).findFirst(); + if (first1.isEmpty()) { + continue; + } + + paymentMap.put(paymentDetail.getReconciliationId(), first1.get()); + } + PaymentReconciliationList = paymentMap.values(); + } else { + PaymentReconciliationList = paymentReconciliationList; + } + if (PaymentReconciliationList.isEmpty()) { + return getMap(map); + } + 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 (paymentDetails.isEmpty()) { + throw new ServiceException("数据异常,该时间段内未查询到收费项"); + } + + 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)); + + List settleIds = new ArrayList<>(); + for (PaymentReconciliation paymentReconciliation : paymentReconciliationList) { + if (!StringUtils.isEmpty(paymentReconciliation.getYbSettleIds())) { + List strings = Arrays.asList(paymentReconciliation.getYbSettleIds().split(",")); + settleIds.addAll(strings); + } + } + List clinicSettle = new ArrayList<>(); + if (!settleIds.isEmpty()) { + clinicSettle = iClinicSettleService.getBySettleIds(settleIds); + } + + BigDecimal cashSum = BigDecimal.ZERO; + 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; + for (PaymentRecDetail paymentDetail : paymentDetails) { + + if (!StringUtils.isEmpty(contractNo)) { + Optional first + = accountList.stream().filter(x -> x.getId().equals(paymentDetail.getAccountId())).findFirst(); + if (first.isEmpty() || !first.get().getContractNo().equals(contractNo)) { + continue; + } + } + + if (YbPayment.SELF_CASH_PAY.getValue().equals(paymentDetail.getPayEnum())) { + cashSum = cashSum.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()); + } + } + + 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); + } + } + if (!returnPaymentList.isEmpty()) { + List returnIds + = returnPaymentList.stream().map(PaymentReconciliation::getId).collect(Collectors.toList()); + + 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()); + 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 (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); + + var loginUser = SecurityUtils.getLoginUser(); + String fixmedinsName = loginUser.getOptionJsonValue(CommonConstants.Option.FIXMEDINS_NAME); + String fixmedinsCode = loginUser.getOptionJsonValue(CommonConstants.Option.FIXMEDINS_CODE); + + map.put("fixmedinsName", fixmedinsName); + map.put("fixmedinsCode", fixmedinsCode); + + 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版 + */ + public Map getTotalCcu(String startTime, String endTime, Long entererId) { + Map map = new HashMap<>(); + + Date startDate = DateUtils.parseDate(startTime); + Date endDate = DateUtils.parseDate(endTime); + + 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); + } + + List paymentIdList + = paymentReconciliationList.stream().map(PaymentReconciliation::getId).collect(Collectors.toList()); + + List PaymentRecDetailAccountResultList + = paymentRecDetailService.getListByReconciliationIds(paymentIdList, PaymentKind.OUTPATIENT_CLINIC.getValue()); + if (PaymentRecDetailAccountResultList.isEmpty()) { + return getMap(map); + } + + Map> paymentDetailsKV = PaymentRecDetailAccountResultList.stream() + .collect(Collectors.groupingBy(PaymentRecDetailAccountResult::getReconciliationId)); + + Map> paymentDetailsMapByContract = PaymentRecDetailAccountResultList + .stream() + .filter(e -> e.getContractNo() != null && !e.getContractNo().isEmpty()) + .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("数据异常,该时间段内未查询到收费项"); + } + + 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)); + + 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); + } + + BigDecimal cashSum = BigDecimal.ZERO; + 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 SelfCashSum = BigDecimal.ZERO; + BigDecimal YbCashSum = BigDecimal.ZERO; + List redisContractList = iContractService.getRedisContractList(); + Map> contractMapByBusNo + = redisContractList.stream() + .filter(e -> e.getBusNo() != null && !e.getBusNo().isEmpty()) + .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()); + } + 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); + } + } + + 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()) { + 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(); + + 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()); + List paymentRecDetails + = paymentDetailsKV.get(paymentReconciliation.getId()); + for (PaymentRecDetailAccountResult 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("ybCashSum", YbCashSum); + map.put("selfCashSum", SelfCashSum); + + 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); + + var loginUser = SecurityUtils.getLoginUser(); + String fixmedinsName = loginUser.getOptionJsonValue(CommonConstants.Option.FIXMEDINS_NAME); + String fixmedinsCode = loginUser.getOptionJsonValue(CommonConstants.Option.FIXMEDINS_CODE); + + map.put("fixmedinsName", fixmedinsName); + map.put("fixmedinsCode", fixmedinsCode); + + 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); + } + + if (!beforeChargeItemDefinitions.isEmpty() && !beforeChargeItemList.isEmpty()) { + Map> beforeChargeItemDefMapByTypeCode + = beforeChargeItemDefinitions.stream().collect(Collectors.groupingBy(ChargeItemDefinition::getTypeCode)); + Map> beforeChargeItemMapByDefinitionId + = beforeChargeItemList.stream().collect(Collectors.groupingBy(ChargeItem::getDefinitionId)); + for (Map.Entry> longListEntry : beforeChargeItemDefMapByTypeCode + .entrySet()) { + BigDecimal bigDecimal = map.get(longListEntry.getKey()) == null ? BigDecimal.ZERO + : new BigDecimal(String.valueOf(map.get(longListEntry.getKey()))); + for (ChargeItemDefinition chargeItemDefinition : longListEntry.getValue()) { + List chargeItems = beforeChargeItemMapByDefinitionId.get(chargeItemDefinition.getId()); + for (ChargeItem chargeItem : chargeItems) { + if (!chargeItem.getStatusEnum().equals(ChargeItemStatus.REFUNDED.getValue())) { + continue; + } + bigDecimal = bigDecimal.add(chargeItem.getTotalPrice()); + } + } + map.put(longListEntry.getKey(), bigDecimal); + } + } + + List list = iEncounterService.getEncounterInfoByTime(startDate, endDate); + Map> encounterAccountDtoMapByContract + = list.stream() + .filter(e -> e.getContractNo() != null && !e.getContractNo().isEmpty()) + .collect(Collectors.groupingBy(EncounterAccountDto::getContractNo)); + for (Map.Entry> stringListEntry : encounterAccountDtoMapByContract + .entrySet()) { + String key = stringListEntry.getKey(); + map.put(key + "reg", stringListEntry.getValue().size()); + } + + return map; + } + + /** + * 长大门诊日结单(最终版) + */ + public Map getTotalCommen(String startTime, String endTime, Long entererId, String contractNo) { + + Map map = new HashMap<>(); + Date startDate = DateUtils.parseDate(startTime); + Date endDate = DateUtils.parseDate(endTime); + + 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 + .getPaymentAccountContract(startTime, endTime, entererId, contractNo, PaymentStatus.SUCCESS.getValue(), + PaymentStatus.REFUND_ALL.getValue(), PaymentKind.OUTPATIENT_CLINIC.getValue()); + + if (paymentReconciliationList.isEmpty()) { + return getMap(map); + } + + BigDecimal amount = BigDecimal.ZERO; + for (PaymentReconciliationAccountDel paymentReconciliationAccountDel : paymentReconciliationList) { + amount = amount.add(paymentReconciliationAccountDel.getTenderedAmount()); + } + map.put("amount", amount); + + List paymentIdList + = paymentReconciliationList.stream().map(PaymentReconciliationAccountDel::getId).collect(Collectors.toList()); + List PaymentRecDetailAccountResultList + = paymentRecDetailService.getListByReconciliationIds(paymentIdList, PaymentKind.OUTPATIENT_CLINIC.getValue()); + + if (PaymentRecDetailAccountResultList.isEmpty()) { + return getMap(map); + } + + Map> paymentDetailsKV = PaymentRecDetailAccountResultList.stream() + .collect(Collectors.groupingBy(PaymentRecDetailAccountResult::getReconciliationId)); + + Map> paymentDetailsMapByContract = PaymentRecDetailAccountResultList + .stream() + .filter(e -> e.getContractNo() != null && !e.getContractNo().isEmpty()) + .collect(Collectors.groupingBy(PaymentRecDetailAccountResult::getContractNo)); + + BigDecimal cashSum = BigDecimal.ZERO; + 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 SelfCashSum = BigDecimal.ZERO; + BigDecimal YbCashSum = BigDecimal.ZERO; + BigDecimal discountSum = BigDecimal.ZERO; + List redisContractList = iContractService.getRedisContractList(); + Map> contractMapByBusNo + = redisContractList.stream() + .filter(e -> e.getBusNo() != null && !e.getBusNo().isEmpty()) + .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 (YbPayment.DISCOUNT_PAY.getValue().equals(paymentRecDetailAccountResult.getPayEnum())) { + discountSum = discountSum.add(paymentRecDetailAccountResult.getAmount()); + } + 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); + } + } + map.put("ybCashSum", YbCashSum); + map.put("rmbCashSum", rmbCashSum); + map.put("vxCashSum", vxCashSum); + map.put("uniCashSum", uniCashSum); + map.put("aliCashSum", aliCashSum); + map.put("discountSum", discountSum); + + List paymentList = new ArrayList<>(); + List returnList = new ArrayList<>(); + + for (PaymentReconciliationAccountDel paymentReconciliation : paymentReconciliationList) { + if (PaymentStatus.REFUND_ALL.getValue().equals(paymentReconciliation.getStatusEnum())) { + returnList.add(paymentReconciliation); + } else if (PaymentStatus.REFUND_PART.getValue().equals(paymentReconciliation.getStatusEnum())) { + paymentList.add(paymentReconciliation); + } else { + paymentList.add(paymentReconciliation); + } + } + + Map> returnPaymentMapByRelationId = new HashMap<>(); + if (!returnList.isEmpty()) { + returnPaymentMapByRelationId + = returnList.stream().collect(Collectors.groupingBy(PaymentReconciliationAccountDel::getRelationId)); + } + + List addChargeItemIds = new ArrayList<>(); + List subChargeItemIds = new ArrayList<>(); + for (PaymentReconciliationAccountDel paymentReconciliation : paymentList) { + List paymentReconciliations + = returnPaymentMapByRelationId.get(paymentReconciliation.getId()); + if (paymentReconciliations != null && !paymentReconciliations.isEmpty()) { + if (PaymentStatus.SUCCESS.getValue().equals(paymentReconciliation.getStatusEnum())) { + returnPaymentMapByRelationId.remove(paymentReconciliation.getId()); + continue; + } + List strings = Arrays.asList(paymentReconciliation.getChargeItemIds().split(",")); + List split = new ArrayList<>(); + for (PaymentReconciliationAccountDel reconciliation : paymentReconciliations) { + split.addAll(Arrays.asList(reconciliation.getChargeItemIds().split(","))); + } + strings.removeAll(split); + addChargeItemIds.addAll(strings); + returnPaymentMapByRelationId.remove(paymentReconciliation.getId()); + } else { + addChargeItemIds.addAll(Arrays.asList(paymentReconciliation.getChargeItemIds().split(","))); + } + } + + for (Map.Entry> longListEntry : returnPaymentMapByRelationId + .entrySet()) { + for (PaymentReconciliationAccountDel paymentReconciliation : longListEntry.getValue()) { + subChargeItemIds.addAll(Arrays.asList(paymentReconciliation.getChargeItemIds().split(","))); + } + } + + List chargeItemIdStrs = new ArrayList<>(); + chargeItemIdStrs.addAll(addChargeItemIds); + chargeItemIdStrs.addAll(subChargeItemIds); + List chargeItemIds = new ArrayList<>(); + for (String chargeItemIdStr : chargeItemIdStrs) { + String[] strings = chargeItemIdStr.split(","); + for (String string : strings) { + Long id = Long.parseLong(string); + chargeItemIds.add(id); + } + } + + if (chargeItemIds.isEmpty()) { + return getMap(map); + } + List chargeItemDefInfoByIds = chargeItemService.getChargeItemDefInfoByIds(chargeItemIds); + if (chargeItemDefInfoByIds.isEmpty()) { + throw new ServiceException("数据异常,该时间段内未查询到收费项"); + } + Map> chargeItemDefInfoKVById + = chargeItemDefInfoByIds.stream().collect(Collectors.groupingBy(ChargeItemDefInfo::getId)); + + BigDecimal bedFee = BigDecimal.ZERO; + BigDecimal diagnosticFee = BigDecimal.ZERO; + BigDecimal checkFee = BigDecimal.ZERO; + BigDecimal diagnosticTestFee = BigDecimal.ZERO; + BigDecimal outDiagnosticTestFee = BigDecimal.ZERO; + BigDecimal medicalExpenseFee = BigDecimal.ZERO; + BigDecimal operationFee = BigDecimal.ZERO; + BigDecimal nursingFee = BigDecimal.ZERO; + BigDecimal sanitaryMaterialsFee = BigDecimal.ZERO; + BigDecimal westMedicine = BigDecimal.ZERO; + BigDecimal chineseMedicineSlicesFee = BigDecimal.ZERO; + BigDecimal chineseMedicineFee = BigDecimal.ZERO; + BigDecimal generalConsultationFee = BigDecimal.ZERO; + BigDecimal registrationFee = BigDecimal.ZERO; + BigDecimal otherFee = BigDecimal.ZERO; + BigDecimal sum = BigDecimal.ZERO; + + ChargeItemDefInfo chargeItem; + for (String addChargeItemId : addChargeItemIds) { + List chargeItems = chargeItemDefInfoKVById.get(Long.parseLong(addChargeItemId)); + if (chargeItems == null || chargeItems.isEmpty()) { + continue; + } + chargeItem = chargeItems.get(0); + YbMedChrgItmType medChrgItmType = YbMedChrgItmType.getByCode(Integer.parseInt(chargeItem.getYbType())); + + switch (medChrgItmType) { + case BED_FEE: + bedFee = bedFee.add(chargeItem.getTotalPrice()); + break; + case DIAGNOSTIC_FEE: + diagnosticFee = diagnosticFee.add(chargeItem.getTotalPrice()); + break; + case CHECK_FEE: + checkFee = checkFee.add(chargeItem.getTotalPrice()); + break; + case DIAGNOSTIC_TEST_FEE: + if (DictUtils.getDictValue("fin_type_code", "化验").equals(chargeItem.getTypeCode())) { + diagnosticTestFee = diagnosticTestFee.add(chargeItem.getTotalPrice()); + } else if (DictUtils.getDictValue("fin_type_code", "外送化验费").equals(chargeItem.getTypeCode())) { + outDiagnosticTestFee = outDiagnosticTestFee.add(chargeItem.getTotalPrice()); + } else { + diagnosticTestFee = diagnosticTestFee.add(chargeItem.getTotalPrice()); + } + break; + case MEDICAL_EXPENSE_FEE: + medicalExpenseFee = medicalExpenseFee.add(chargeItem.getTotalPrice()); + break; + case OPERATION_FEE: + operationFee = operationFee.add(chargeItem.getTotalPrice()); + break; + case NURSING_FEE: + nursingFee = nursingFee.add(chargeItem.getTotalPrice()); + break; + case SANITARY_MATERIALS_FEE: + sanitaryMaterialsFee = sanitaryMaterialsFee.add(chargeItem.getTotalPrice()); + break; + case WEST_MEDICINE: + westMedicine = westMedicine.add(chargeItem.getTotalPrice()); + break; + case CHINESE_MEDICINE_SLICES_FEE: + chineseMedicineSlicesFee = chineseMedicineSlicesFee.add(chargeItem.getTotalPrice()); + break; + case CHINESE_MEDICINE_FEE: + chineseMedicineFee = chineseMedicineFee.add(chargeItem.getTotalPrice()); + break; + case GENERAL_CONSULTATION_FEE: + generalConsultationFee = generalConsultationFee.add(chargeItem.getTotalPrice()); + break; + case REGISTRATION_FEE: + registrationFee = registrationFee.add(chargeItem.getTotalPrice()); + break; + default: + otherFee = otherFee.add(chargeItem.getTotalPrice()); + break; + } + } + + for (String subChargeItemId : subChargeItemIds) { + List chargeItems = chargeItemDefInfoKVById.get(Long.parseLong(subChargeItemId)); + if (chargeItems == null || chargeItems.isEmpty()) { + continue; + } + chargeItem = chargeItems.get(0); + + YbMedChrgItmType medChrgItmType = YbMedChrgItmType.getByCode(Integer.parseInt(chargeItem.getYbType())); + + switch (medChrgItmType) { + case BED_FEE: + bedFee = bedFee.subtract(chargeItem.getTotalPrice()); + break; + case DIAGNOSTIC_FEE: + diagnosticFee = diagnosticFee.subtract(chargeItem.getTotalPrice()); + break; + case CHECK_FEE: + checkFee = checkFee.subtract(chargeItem.getTotalPrice()); + break; + case DIAGNOSTIC_TEST_FEE: + if (DictUtils.getDictValue("fin_type_code", "化验").equals(chargeItem.getTypeCode())) { + diagnosticTestFee = diagnosticTestFee.add(chargeItem.getTotalPrice()); + } else if (DictUtils.getDictValue("fin_type_code", "外送化验费").equals(chargeItem.getTypeCode())) { + outDiagnosticTestFee = outDiagnosticTestFee.add(chargeItem.getTotalPrice()); + } else { + diagnosticTestFee = diagnosticTestFee.add(chargeItem.getTotalPrice()); + } + break; + case MEDICAL_EXPENSE_FEE: + medicalExpenseFee = medicalExpenseFee.subtract(chargeItem.getTotalPrice()); + break; + case OPERATION_FEE: + operationFee = operationFee.subtract(chargeItem.getTotalPrice()); + break; + case NURSING_FEE: + nursingFee = nursingFee.subtract(chargeItem.getTotalPrice()); + break; + case SANITARY_MATERIALS_FEE: + sanitaryMaterialsFee = sanitaryMaterialsFee.subtract(chargeItem.getTotalPrice()); + break; + case WEST_MEDICINE: + westMedicine = westMedicine.subtract(chargeItem.getTotalPrice()); + break; + case CHINESE_MEDICINE_SLICES_FEE: + chineseMedicineSlicesFee = chineseMedicineSlicesFee.subtract(chargeItem.getTotalPrice()); + break; + case CHINESE_MEDICINE_FEE: + chineseMedicineFee = chineseMedicineFee.subtract(chargeItem.getTotalPrice()); + break; + case GENERAL_CONSULTATION_FEE: + generalConsultationFee = generalConsultationFee.subtract(chargeItem.getTotalPrice()); + break; + case REGISTRATION_FEE: + registrationFee = registrationFee.subtract(chargeItem.getTotalPrice()); + break; + default: + otherFee = otherFee.subtract(chargeItem.getTotalPrice()); + break; + } + } + + map.put("BED_FEE", bedFee); + map.put("DIAGNOSTIC_FEE", diagnosticFee); + map.put("CHECK_FEE", checkFee); + map.put("DIAGNOSTIC_TEST_FEE", diagnosticTestFee); + map.put("OUT_DIAGNOSTIC_TEST_FEE", outDiagnosticTestFee); + map.put("MEDICAL_EXPENSE_FEE", medicalExpenseFee); + map.put("OPERATION_FEE", operationFee); + map.put("NURSING_FEE", nursingFee); + map.put("SANITARY_MATERIALS_FEE", sanitaryMaterialsFee); + map.put("WEST_MEDICINE", westMedicine); + map.put("CHINESE_MEDICINE_SLICES_FEE", chineseMedicineSlicesFee); + map.put("CHINESE_MEDICINE_FEE", chineseMedicineFee); + map.put("GENERAL_CONSULTATION_FEE", generalConsultationFee); + map.put("REGISTRATION_FEE", registrationFee); + map.put("OTHER_FEE", otherFee); + sum = bedFee.add(diagnosticFee).add(checkFee).add(diagnosticTestFee).add(outDiagnosticTestFee).add(medicalExpenseFee).add(operationFee) + .add(nursingFee).add(sanitaryMaterialsFee).add(westMedicine).add(chineseMedicineFee).add( + chineseMedicineSlicesFee).add(generalConsultationFee).add(registrationFee).add(otherFee); + map.put("SUM", sum); + + Map> chargeItemDefKVByTypeCode = chargeItemDefInfoByIds.stream() + .collect(Collectors.groupingBy( + item -> item.getTypeCode() != null ? item.getTypeCode() : "UNKNOWN" + )); + for (Map.Entry> longListEntry : chargeItemDefKVByTypeCode.entrySet()) { + String key = longListEntry.getKey(); + BigDecimal bigDecimal = BigDecimal.ZERO; + for (ChargeItemDefInfo itemDefinition : longListEntry.getValue()) { + if (subChargeItemIds.contains(itemDefinition.getId().toString())) { + bigDecimal = bigDecimal.subtract(itemDefinition.getTotalPrice()); + } else { + bigDecimal = bigDecimal.add(itemDefinition.getTotalPrice()); + } + } + map.put(key, bigDecimal); + } + + List chargeItemDefInfos = chargeItemDefKVByTypeCode.get("9999"); + BigDecimal peisCnt = BigDecimal.ZERO; + if (chargeItemDefInfos != null) { + for (ChargeItemDefInfo chargeItemDefInfo : chargeItemDefInfos) { + peisCnt = peisCnt.add(chargeItemDefInfo.getQuantityValue()); + } + } + map.put("peisCnt", peisCnt); + + List returnBillVOList = new ArrayList<>(); + ReturnBillVO returnBillVO; + + if (!returnList.isEmpty()) { + List returnIds + = returnList.stream().map(PaymentReconciliationAccountDel::getId).collect(Collectors.toList()); + List relationIdList + = returnList.stream().map(PaymentReconciliationAccountDel::getRelationId).collect(Collectors.toList()); + if (relationIdList.isEmpty() || returnList.size() != relationIdList.size()) { + throw new ServiceException("数据异常,存在无法关联到原单的退款单,请联系工程师"); + } + + 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 (PaymentReconciliationAccountDel paymentReconciliation : returnList) { + returnBillVO = new ReturnBillVO(); + returnBillVO.setTotalAmount(paymentReconciliation.getTenderedAmount()); + List paymentRecDetails + = paymentDetailsKV.get(paymentReconciliation.getId()); + for (PaymentRecDetailAccountResult 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()); + returnBillVOList.add(returnBillVO); + } + map.put("returnList", returnBillVOList); + } + } + + List encounterList = iEncounterService.getEncounterInfoByTime(startDate, endDate); + Map> encounterAccountDtoMapByContract + = encounterList.stream() + .filter(e -> e.getContractNo() != null && !e.getContractNo().isEmpty()) + .collect(Collectors.groupingBy(EncounterAccountDto::getContractNo)); + for (Map.Entry> stringListEntry : encounterAccountDtoMapByContract + .entrySet()) { + String key = stringListEntry.getKey(); + map.put(key + "reg", stringListEntry.getValue().size()); + } + + BigDecimal tyBedFee = BigDecimal.ZERO; + BigDecimal tyDiagnosticFee = BigDecimal.ZERO; + BigDecimal tyCheckFee = BigDecimal.ZERO; + BigDecimal tyDiagnosticTestFee = BigDecimal.ZERO; + BigDecimal tyOutDiagnosticTestFee = BigDecimal.ZERO; + BigDecimal tyMedicalExpenseFee = BigDecimal.ZERO; + BigDecimal tyOperationFee = BigDecimal.ZERO; + BigDecimal tyNursingFee = BigDecimal.ZERO; + BigDecimal tySanitaryMaterialsFee = BigDecimal.ZERO; + BigDecimal tyWestMedicine = BigDecimal.ZERO; + BigDecimal tyChineseMedicineSlicesFee = BigDecimal.ZERO; + BigDecimal tyChineseMedicineFee = BigDecimal.ZERO; + BigDecimal tyGeneralConsultationFee = BigDecimal.ZERO; + BigDecimal tyRegistrationFee = BigDecimal.ZERO; + BigDecimal tyOtherFee = BigDecimal.ZERO; + BigDecimal tySum = BigDecimal.ZERO; + + for (String addChargeItemId : addChargeItemIds) { + List chargeItems = chargeItemDefInfoKVById.get(Long.parseLong(addChargeItemId)); + if (chargeItems == null || chargeItems.isEmpty()) { + continue; + } + chargeItem = chargeItems.get(0); + YbMedChrgItmType medChrgItmType = YbMedChrgItmType.getByCode(Integer.parseInt(chargeItem.getYbType())); + + switch (medChrgItmType) { + case BED_FEE: + tyBedFee = tyBedFee.add(chargeItem.getSystemDiscountPrice() == null ? chargeItem.getTotalPrice() + : chargeItem.getSystemDiscountPrice()); + break; + case DIAGNOSTIC_FEE: + tyDiagnosticFee = tyDiagnosticFee.add(chargeItem.getSystemDiscountPrice() == null + ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); + break; + case CHECK_FEE: + tyCheckFee = tyCheckFee.add(chargeItem.getSystemDiscountPrice() == null ? chargeItem.getTotalPrice() + : chargeItem.getSystemDiscountPrice()); + break; + case DIAGNOSTIC_TEST_FEE: + BigDecimal discountPrice = chargeItem.getSystemDiscountPrice() == null ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice(); + if (DictUtils.getDictValue("fin_type_code", "化验").equals(chargeItem.getTypeCode())) { + tyDiagnosticTestFee = tyDiagnosticTestFee.add(discountPrice); + } else if (DictUtils.getDictValue("fin_type_code", "外送化验费").equals(chargeItem.getTypeCode())) { + tyOutDiagnosticTestFee = tyOutDiagnosticTestFee.add(discountPrice); + } else { + tyDiagnosticTestFee = tyDiagnosticTestFee.add(discountPrice); + } + break; + case MEDICAL_EXPENSE_FEE: + tyMedicalExpenseFee = tyMedicalExpenseFee.add(chargeItem.getSystemDiscountPrice() == null + ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); + break; + case OPERATION_FEE: + tyOperationFee = tyOperationFee.add(chargeItem.getSystemDiscountPrice() == null + ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); + break; + case NURSING_FEE: + tyNursingFee = tyNursingFee.add(chargeItem.getSystemDiscountPrice() == null + ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); + break; + case SANITARY_MATERIALS_FEE: + tySanitaryMaterialsFee = tySanitaryMaterialsFee.add(chargeItem.getSystemDiscountPrice() == null + ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); + break; + case WEST_MEDICINE: + tyWestMedicine = tyWestMedicine.add(chargeItem.getSystemDiscountPrice() == null + ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); + break; + case CHINESE_MEDICINE_SLICES_FEE: + tyChineseMedicineSlicesFee + = tyChineseMedicineSlicesFee.add(chargeItem.getSystemDiscountPrice() == null + ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); + break; + case CHINESE_MEDICINE_FEE: + tyChineseMedicineFee = tyChineseMedicineFee.add(chargeItem.getSystemDiscountPrice() == null + ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); + break; + case GENERAL_CONSULTATION_FEE: + tyGeneralConsultationFee = tyGeneralConsultationFee.add(chargeItem.getSystemDiscountPrice() == null + ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); + break; + case REGISTRATION_FEE: + tyRegistrationFee = tyRegistrationFee.add(chargeItem.getSystemDiscountPrice() == null + ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); + break; + default: + tyOtherFee = tyOtherFee.add(chargeItem.getSystemDiscountPrice() == null ? chargeItem.getTotalPrice() + : chargeItem.getSystemDiscountPrice()); + break; + } + } + + for (String subChargeItemId : subChargeItemIds) { + List chargeItems = chargeItemDefInfoKVById.get(Long.parseLong(subChargeItemId)); + if (chargeItems == null || chargeItems.isEmpty()) { + continue; + } + chargeItem = chargeItems.get(0); + + YbMedChrgItmType medChrgItmType = YbMedChrgItmType.getByCode(Integer.parseInt(chargeItem.getYbType())); + + switch (medChrgItmType) { + case BED_FEE: + tyBedFee = tyBedFee.subtract(chargeItem.getSystemDiscountPrice() == null + ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); + break; + case DIAGNOSTIC_FEE: + tyDiagnosticFee = tyDiagnosticFee.subtract(chargeItem.getSystemDiscountPrice() == null + ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); + break; + case CHECK_FEE: + tyCheckFee = tyCheckFee.subtract(chargeItem.getSystemDiscountPrice() == null + ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); + break; + case DIAGNOSTIC_TEST_FEE: + BigDecimal discountPriceSub = chargeItem.getSystemDiscountPrice() == null ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice(); + if (DictUtils.getDictValue("fin_type_code", "化验").equals(chargeItem.getTypeCode())) { + tyDiagnosticTestFee = tyDiagnosticTestFee.subtract(discountPriceSub); + } else if (DictUtils.getDictValue("fin_type_code", "外送化验费").equals(chargeItem.getTypeCode())) { + tyOutDiagnosticTestFee = tyOutDiagnosticTestFee.subtract(discountPriceSub); + } else { + tyDiagnosticTestFee = tyDiagnosticTestFee.subtract(discountPriceSub); + } + break; + case MEDICAL_EXPENSE_FEE: + tyMedicalExpenseFee = tyMedicalExpenseFee.subtract(chargeItem.getSystemDiscountPrice() == null + ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); + break; + case OPERATION_FEE: + tyOperationFee = tyOperationFee.subtract(chargeItem.getSystemDiscountPrice() == null + ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); + break; + case NURSING_FEE: + tyNursingFee = tyNursingFee.subtract(chargeItem.getSystemDiscountPrice() == null + ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); + break; + case SANITARY_MATERIALS_FEE: + tySanitaryMaterialsFee = tySanitaryMaterialsFee.subtract(chargeItem.getSystemDiscountPrice() == null + ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); + break; + case WEST_MEDICINE: + tyWestMedicine = tyWestMedicine.subtract(chargeItem.getSystemDiscountPrice() == null + ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); + break; + case CHINESE_MEDICINE_SLICES_FEE: + tyChineseMedicineSlicesFee + = tyChineseMedicineSlicesFee.subtract(chargeItem.getSystemDiscountPrice() == null + ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); + break; + case CHINESE_MEDICINE_FEE: + tyChineseMedicineFee = tyChineseMedicineFee.subtract(chargeItem.getSystemDiscountPrice() == null + ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); + break; + case GENERAL_CONSULTATION_FEE: + tyGeneralConsultationFee + = tyGeneralConsultationFee.subtract(chargeItem.getSystemDiscountPrice() == null + ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); + break; + case REGISTRATION_FEE: + tyRegistrationFee = tyRegistrationFee.subtract(chargeItem.getSystemDiscountPrice() == null + ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); + break; + default: + tyOtherFee = tyOtherFee.subtract(chargeItem.getSystemDiscountPrice() == null + ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); + break; + } + } + + map.put("TY_BED_FEE", tyBedFee); + map.put("TY_DIAGNOSTIC_FEE", tyDiagnosticFee); + map.put("TY_CHECK_FEE", tyCheckFee); + map.put("TY_DIAGNOSTIC_TEST_FEE", tyDiagnosticTestFee); + map.put("TY_OUT_DIAGNOSTIC_TEST_FEE", tyOutDiagnosticTestFee); + map.put("TY_MEDICAL_EXPENSE_FEE", tyMedicalExpenseFee); + map.put("TY_OPERATION_FEE", tyOperationFee); + map.put("TY_NURSING_FEE", tyNursingFee); + map.put("TY_SANITARY_MATERIALS_FEE", tySanitaryMaterialsFee); + map.put("TY_WEST_MEDICINE", tyWestMedicine); + map.put("TY_CHINESE_MEDICINE_SLICES_FEE", tyChineseMedicineSlicesFee); + map.put("TY_CHINESE_MEDICINE_FEE", tyChineseMedicineFee); + map.put("TY_GENERAL_CONSULTATION_FEE", tyGeneralConsultationFee); + map.put("TY_REGISTRATION_FEE", tyRegistrationFee); + map.put("TY_OTHER_FEE", tyOtherFee); + tySum = tyBedFee.add(tyDiagnosticFee).add(tyCheckFee).add(tyDiagnosticTestFee).add(tyOutDiagnosticTestFee).add(tyMedicalExpenseFee).add( + tyOperationFee).add(tyNursingFee).add(tySanitaryMaterialsFee).add(tyWestMedicine).add( + tyChineseMedicineSlicesFee).add(tyChineseMedicineFee).add(tyGeneralConsultationFee).add(tyRegistrationFee) + .add(tyOtherFee); + map.put("TY_SUM", tySum); + + return map; + } + + public Map getMedicalExpenseCoverageSummary(Long paymentId) { + return null; + } + + public Map getChargeItemByOrg(ChargeSummaryDto chargeSummaryDto) { + Map map = new HashMap<>(); + + Date startDate = DateUtils.parseDate(chargeSummaryDto.getStartTime()); + Date endDate = DateUtils.parseDate(chargeSummaryDto.getEndTime()); + + 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()); + + List paymentReconciliationList = paymentReconciliationService.list(queryWrapper); + if (paymentReconciliationList.isEmpty()) { + return null; + } + + List chargeItemIds = paymentReconciliationList.stream().map(PaymentReconciliation::getChargeItemIds) + .flatMap(str -> Arrays.stream(str.split(","))) + .map(String::trim) + .filter(s -> !s.isEmpty()) + .map(Long::valueOf) + .collect(Collectors.toList()); + + List ChargeItemExtendInfoDtoList + = chargeBillMapper.selectChargeItemExtendInfoList(chargeItemIds, chargeSummaryDto.getOrgIdList()); + + Map> chargeItemExtendInfoDtoListGroupByOrgIdMap + = 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); + if (chargeSummaryDto.getOrgIdList() != null && !chargeSummaryDto.getOrgIdList().isEmpty()) { + organizationLambdaQueryWrapper.in(Organization::getId, chargeSummaryDto.getOrgIdList()); + } + List organizationList = iOrganizationService.list(organizationLambdaQueryWrapper); + if (organizationList.isEmpty()) { + throw new ServiceException("未查询到科室信息"); + } + List orgIncomeList = new ArrayList(); + OrgIncomeDto orgIncomeDto; + for (Organization organization : organizationList) { + orgIncomeDto = new OrgIncomeDto(); + orgIncomeDto.setOrgName(organization.getName()); + List chargeItemExtendInfoDtos + = chargeItemExtendInfoDtoListGroupByOrgIdMap.get(organization.getId()); + if (chargeItemExtendInfoDtos == null) { + orgIncomeList.add(orgIncomeDto); + continue; + } + for (ChargeItemExtendInfoDto chargeItemExtendInfoDto : chargeItemExtendInfoDtos) { + switch (YbMedChrgItmType.getByValue(chargeItemExtendInfoDto.getYbType())) { + case WEST_MEDICINE: + case CHINESE_MEDICINE_SLICES_FEE: + case CHINESE_MEDICINE_FEE: + orgIncomeDto.setAmount(orgIncomeDto.getAmount().add(chargeItemExtendInfoDto.getTotalPrice())); + orgIncomeDto.setMedFee(orgIncomeDto.getMedFee().add(chargeItemExtendInfoDto.getTotalPrice())); + break; + case REGISTRATION_FEE: + orgIncomeDto.setAmount(orgIncomeDto.getAmount().add(chargeItemExtendInfoDto.getTotalPrice())); + orgIncomeDto.setPersonCnt(orgIncomeDto.getPersonCnt() + 1); + orgIncomeDto.setRegistrationFee( + orgIncomeDto.getRegistrationFee().add(chargeItemExtendInfoDto.getTotalPrice())); + break; + case SANITARY_MATERIALS_FEE: + orgIncomeDto.setAmount(orgIncomeDto.getAmount().add(chargeItemExtendInfoDto.getTotalPrice())); + orgIncomeDto + .setDeviceFee(orgIncomeDto.getDeviceFee().add(chargeItemExtendInfoDto.getTotalPrice())); + break; + default: + orgIncomeDto.setAmount(orgIncomeDto.getAmount().add(chargeItemExtendInfoDto.getTotalPrice())); + orgIncomeDto + .setServiceFee(orgIncomeDto.getServiceFee().add(chargeItemExtendInfoDto.getTotalPrice())); + } + } + + orgIncomeList.add(orgIncomeDto); + } + + map.put("clinic", orgIncomeList); + + return map; + } + + public Map updateChargeItemTotalPrice() { + + List paymentRecDetails = paymentRecDetailService.list( + new LambdaQueryWrapper().eq(PaymentRecDetail::getDeleteFlag, DelFlag.NO.getCode()) + .eq(PaymentRecDetail::getPayEnum, 220500)); + + List paymentIdList = paymentRecDetails.stream().map(PaymentRecDetail::getReconciliationId).collect( + Collectors.toList()); + + HashMap hashMap = new HashMap<>(); + List paymentList1 = new ArrayList<>(); + List paymentList2 = new ArrayList<>(); + List paymentList3 = new ArrayList<>(); + + List list = paymentReconciliationService.list( + new LambdaQueryWrapper().eq(PaymentReconciliation::getDeleteFlag, + DelFlag.NO.getCode()).eq(PaymentReconciliation::getStatusEnum, PaymentStatus.SUCCESS.getValue()) + .between(PaymentReconciliation::getBillDate, Date.from(LocalDateTime.parse("2025-12-01 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")).atZone(ZoneId.systemDefault()).toInstant()), + Date.from(LocalDateTime.parse("2025-12-31 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")).atZone(ZoneId.systemDefault()).toInstant()))); + + for (PaymentReconciliation paymentReconciliation : list) { + + BigDecimal a = BigDecimal.ZERO; + BigDecimal b = BigDecimal.ZERO; + BigDecimal c = BigDecimal.ZERO; + BigDecimal d = BigDecimal.ZERO; + BigDecimal e = BigDecimal.ZERO; + BigDecimal f = BigDecimal.ZERO; + + List paymentRecDetailList = paymentRecDetailService.list( + new LambdaQueryWrapper().eq(PaymentRecDetail::getReconciliationId, + paymentReconciliation.getId())); + + PaymentRecDetail paymentRecDetail = null; + for (PaymentRecDetail item : paymentRecDetailList) { + if (item.getPayEnum() == 220500) { + e = e.add(item.getAmount()); + paymentRecDetail = item; + } + if (item.getPayEnum() == 220100) { + d = d.add(item.getAmount()); + } + if (item.getPayEnum() == 220200) { + d = d.add(item.getAmount()); + } + if (item.getPayEnum() == 220300) { + d = d.add(item.getAmount()); + } + if (item.getPayEnum() == 220400) { + d = d.add(item.getAmount()); + } + } + ChargeItem chargeItem; + if (paymentRecDetail == null) { + + List collect = Arrays.stream(paymentReconciliation.getChargeItemIds().split(",")).collect( + Collectors.toList()); + List chargeItemIds = collect.stream().map(Long::parseLong).collect(Collectors.toList()); + + List chargeItemDefInfoByIdList = chargeItemService.getChargeItemDefInfoByIdList( + chargeItemIds); + + for (ChargeItemDefInfo chargeItemDefInfo : chargeItemDefInfoByIdList) { + + chargeItem = new ChargeItem(); + + chargeItem.setId(chargeItemDefInfo.getId()); + chargeItem.setSystemDiscountPrice(chargeItemDefInfo.getTotalPrice()); + + chargeItemService.updateById(chargeItem); + } + + paymentList1.add(paymentReconciliation.getId()); + continue; + } + + List collect = Arrays.stream(paymentReconciliation.getChargeItemIds().split(",")).collect( + Collectors.toList()); + List chargeItemIds = collect.stream().map(Long::parseLong).collect(Collectors.toList()); + + List chargeItemDefInfoByIdList = chargeItemService.getChargeItemDefInfoByIdList( + chargeItemIds); + + List newChargeItemList = new ArrayList<>(); + + for (ChargeItemDefInfo chargeItemDefInfo : chargeItemDefInfoByIdList) { + + chargeItem = new ChargeItem(); + + if (chargeItemDefInfo.getYbType().equals(YbMedChrgItmType.WEST_MEDICINE.getValue()) + || chargeItemDefInfo.getYbType().equals(YbMedChrgItmType.CHINESE_MEDICINE_SLICES_FEE.getValue()) + || chargeItemDefInfo.getYbType().equals(YbMedChrgItmType.CHINESE_MEDICINE_FEE.getValue()) + || chargeItemDefInfo.getYbType().equals(YbMedChrgItmType.SANITARY_MATERIALS_FEE.getValue())) { + + chargeItem.setId(chargeItemDefInfo.getId()); + chargeItem.setSystemDiscountPrice(chargeItemDefInfo.getTotalPrice()); + + a = a.add(chargeItemDefInfo.getTotalPrice()); + + chargeItemService.updateById(chargeItem); + + } else { + + c = c.add(chargeItemDefInfo.getTotalPrice()); + + chargeItem.setId(chargeItemDefInfo.getId()); + chargeItem.setTotalPrice(chargeItemDefInfo.getTotalPrice()); + + newChargeItemList.add(chargeItem); + + } + } + + b = d.subtract(a); + f = paymentReconciliation.getTenderedAmount().subtract(a); + + for (ChargeItem item : newChargeItemList) { + if (item.getTotalPrice() == null) { + log.info("这个收费项没有定义总价:" + item.getId()); + } + } + + Long paymentReconciliationId = paymentReconciliation.getId(); + if (paymentReconciliationId == 1987152585230508034L || paymentReconciliationId == 1987153070121410561L + || paymentReconciliationId == 1984438852329246721L || paymentReconciliationId == 1984902967625117698L + || paymentReconciliationId == 1984778667126493186L || paymentReconciliationId == 1984780710054531074L) { + log.info("主键id如下:" + paymentReconciliationId); + log.info("待分配诊疗项目如下:" + JsonUtils.toJson(newChargeItemList)); + } + if (b.compareTo(BigDecimal.ZERO) > 0) { + + for (ChargeItem item : newChargeItemList) { + item.setSystemDiscountPrice(item.getTotalPrice().divide(f, 6, RoundingMode.HALF_UP).multiply(b)); + chargeItemService.updateById(item); + } + + } + } + + return new HashMap<>(); + } + + private Map getMap(Map map) { + + var loginUser = SecurityUtils.getLoginUser(); + String fixmedinsName = loginUser.getOptionJsonValue(CommonConstants.Option.FIXMEDINS_NAME); + String fixmedinsCode = loginUser.getOptionJsonValue(CommonConstants.Option.FIXMEDINS_CODE); + + map.put("fixmedinsName", fixmedinsName); + map.put("fixmedinsCode", fixmedinsCode); + + map.put("BED_FEE", BigDecimal.ZERO); + map.put("DIAGNOSTIC_FEE", BigDecimal.ZERO); + map.put("CHECK_FEE", BigDecimal.ZERO); + map.put("DIAGNOSTIC_TEST_FEE", BigDecimal.ZERO); + map.put("OUT_DIAGNOSTIC_TEST_FEE", BigDecimal.ZERO); + map.put("MEDICAL_EXPENSE_FEE", BigDecimal.ZERO); + map.put("OPERATION_FEE", BigDecimal.ZERO); + map.put("NURSING_FEE", BigDecimal.ZERO); + map.put("SANITARY_MATERIALS_FEE", BigDecimal.ZERO); + map.put("WEST_MEDICINE", BigDecimal.ZERO); + map.put("CHINESE_MEDICINE_SLICES_FEE", BigDecimal.ZERO); + map.put("CHINESE_MEDICINE_FEE", BigDecimal.ZERO); + map.put("GENERAL_CONSULTATION_FEE", BigDecimal.ZERO); + map.put("REGISTRATION_FEE", BigDecimal.ZERO); + map.put("OTHER_FEE", BigDecimal.ZERO); + map.put("SUM", BigDecimal.ZERO); + map.put("ybCashSum", BigDecimal.ZERO); + map.put("selfCashSum", BigDecimal.ZERO); + map.put("selfReg", 0); + map.put("ybReg", 0); + + map.put("cashSum", BigDecimal.ZERO); + map.put("rmbCashSum", BigDecimal.ZERO); + map.put("vxCashSum", BigDecimal.ZERO); + map.put("aliCashSum", BigDecimal.ZERO); + map.put("uniCashSum", BigDecimal.ZERO); + map.put("tcSum", BigDecimal.ZERO); + map.put("zhSum", BigDecimal.ZERO); + map.put("fundSum", BigDecimal.ZERO); + + return map; + } +} diff --git a/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/paymentmanage/appservice/impl/ChargeBillQueryService.java b/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/paymentmanage/appservice/impl/ChargeBillQueryService.java new file mode 100644 index 000000000..2b289feae --- /dev/null +++ b/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/paymentmanage/appservice/impl/ChargeBillQueryService.java @@ -0,0 +1,611 @@ +package com.healthlink.his.web.paymentmanage.appservice.impl; + +import com.core.common.utils.JsonUtils; +import tools.jackson.databind.JsonNode; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.core.common.enums.DelFlag; +import com.core.common.exception.ServiceException; +import com.core.common.utils.*; +import com.healthlink.his.administration.domain.*; +import com.healthlink.his.administration.dto.ChargeItemBaseInfoDto; +import com.healthlink.his.administration.service.*; +import com.healthlink.his.clinical.domain.Condition; +import com.healthlink.his.clinical.domain.ConditionDefinition; +import com.healthlink.his.clinical.service.IConditionDefinitionService; +import com.healthlink.his.clinical.service.IConditionService; +import com.healthlink.his.common.constant.CommonConstants; +import com.healthlink.his.common.constant.YbCommonConstants; +import com.healthlink.his.common.enums.*; +import com.healthlink.his.yb.enums.YbPayment; +import com.healthlink.his.financial.domain.PaymentRecDetail; +import com.healthlink.his.financial.domain.PaymentReconciliation; +import com.healthlink.his.financial.service.IContractService; +import com.healthlink.his.financial.service.IPaymentRecDetailService; +import com.healthlink.his.financial.service.IPaymentReconciliationService; +import com.healthlink.his.medication.domain.Medication; +import com.healthlink.his.medication.domain.MedicationDefinition; +import com.healthlink.his.medication.service.IMedicationDefinitionService; +import com.healthlink.his.medication.service.IMedicationService; +import com.healthlink.his.web.paymentmanage.dto.*; +import com.healthlink.his.web.paymentmanage.mapper.ChargeBillMapper; +import com.healthlink.his.workflow.domain.ActivityDefinition; +import com.healthlink.his.workflow.domain.ServiceRequest; +import com.healthlink.his.workflow.service.IActivityDefinitionService; +import com.healthlink.his.workflow.service.IServiceRequestService; +import com.healthlink.his.yb.domain.InfoPerson; +import com.healthlink.his.yb.service.*; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.util.*; +import java.util.stream.Collectors; + +/** + * 收费票据查询服务 - 处理票据查询/搜索相关方法 + */ +@Component +@Slf4j +public class ChargeBillQueryService { + + @Autowired + private IAccountService iAccountService; + @Autowired + private IEncounterService iEncounterService; + @Autowired + private IEncounterParticipantService iEncounterParticipantService; + @Autowired + private IInvoiceService iInvoiceService; + @Autowired + private IPaymentReconciliationService paymentReconciliationService; + @Autowired + private IPaymentRecDetailService paymentRecDetailService; + @Autowired + private IChargeItemService chargeItemService; + @Autowired + private IPatientService iPatientService; + @Autowired + private IChargeItemDefinitionService iChargeItemDefinitionService; + @Autowired + private IPerinfoService iPerinfoService; + @Autowired + private IEncounterDiagnosisService iEncounterDiagnosisService; + @Autowired + private IOrganizationService iOrganizationService; + @Autowired + private IConditionDefinitionService iConditionDefinitionService; + @Autowired + private IConditionService iConditionService; + @Autowired + private ChargeBillMapper chargeBillMapper; + @Autowired + private IMedicationService iMedicationService; + @Autowired + private IMedicationDefinitionService iMedicationDefinitionService; + @Autowired + private IDeviceDefinitionService iDeviceDefinitionService; + @Autowired + private IActivityDefinitionService iActivityDefinitionService; + @Autowired + private IServiceRequestService iServiceRequestService; + @Autowired + private IPractitionerService iPractitionerService; + @Autowired + private IHealthcareServiceService iHealthcareServiceService; + @Autowired + private IContractService iContractService; + + public Map getDetail(Long paymentId) { + + Map map = new HashMap<>(); + PaymentReconciliation paymentReconciliation = paymentReconciliationService.getById(paymentId); + if (paymentReconciliation == null) { + throw new ServiceException("未查询到付款信息"); + } + map.put("paymentId", paymentReconciliation.getPaymentNo()); + map.put("paymentAmount", paymentReconciliation.getTenderedAmount()); + + Practitioner practitioner = iPractitionerService.getById(paymentReconciliation.getEntererId()); + map.put("paymentEmployee", practitioner == null ? "" : practitioner.getName()); + map.put("chargeTime", paymentReconciliation.getBillDate()); + + Patient patient = iPatientService.getById(paymentReconciliation.getPatientId()); + if (patient == null) { + throw new ServiceException("未查询到患者信息"); + } + map.put("patientName", patient.getName()); + + map.put("sex", patient.getGenderEnum()); + map.put("idCardNo", patient.getIdCard()); + map.put("birthDay", patient.getBirthDate()); + map.put("age", AgeCalculatorUtil.calculateAge(patient.getBirthDate())); + + Encounter encounter = iEncounterService.getById(paymentReconciliation.getEncounterId()); + if (patient == null) { + throw new ServiceException("未查询到就诊信息"); + } + map.put("classEnum", encounter.getYbClassEnum()); + map.put("regNo", encounter.getBusNo()); + + List encounterParticipantListByTypeCode = iEncounterParticipantService.getEncounterParticipantListByTypeCode(encounter.getId(), ParticipantType.ADMITTER); + if (!encounterParticipantListByTypeCode.isEmpty()) { + Practitioner doctor = iPractitionerService.getById(encounterParticipantListByTypeCode.get(0).getPractitionerId()); + map.put("doctor", doctor == null ? "" : doctor.getName()); + } + + List paymentRecDetails = paymentRecDetailService + .list(new LambdaQueryWrapper().eq(PaymentRecDetail::getReconciliationId, paymentId)); + + if (paymentRecDetails.isEmpty()) { + throw new ServiceException("未查询到付款信息"); + } + map.put("detail", paymentRecDetails); + + BigDecimal amount = BigDecimal.ZERO; + for (PaymentRecDetail paymentRecDetail : paymentRecDetails) { + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.SELF_YB_ZH_PAY.getValue())) { + map.put("ybAccountPay", paymentRecDetail.getAmount()); + amount = amount.add(paymentRecDetail.getAmount()); + } + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.BALC.getValue())) { + map.put("ybAccountBalc", paymentRecDetail.getAmount()); + } + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.YB_FUND_PAY.getValue())) { + map.put("ybFundPay", paymentRecDetail.getAmount()); + } + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.YB_TC_FUND_AMOUNT.getValue())) { + map.put("ybTcPay", paymentRecDetail.getAmount()); + } + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.YB_BC_GWY_BZ_VALUE.getValue())) { + map.put("ybGWYPay", paymentRecDetail.getAmount()); + } + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.OTHER_PAY.getValue())) { + map.put("ybOtherPay", paymentRecDetail.getAmount()); + } + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.YB_BC_DE_BZ_VALUE.getValue())) { + map.put("ybDELPPay", paymentRecDetail.getAmount()); + } + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.YB_BC_ZG_DE_BZ_VALUE.getValue())) { + map.put("ybDELPPay", paymentRecDetail.getAmount()); + } + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.E_WALLET.getValue())) { + map.put("ybWallet", paymentRecDetail.getAmount()); + } + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.SUPPLEMENTARY_INSURANCE.getValue())) { + map.put("ybWallet", paymentRecDetail.getAmount()); + } + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.SELF_CASH_VALUE.getValue())) { + map.put("cash", paymentRecDetail.getAmount()); + amount = amount.add(paymentRecDetail.getAmount()); + } + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.SELF_CASH_VX_VALUE.getValue())) { + map.put("wxCash", paymentRecDetail.getAmount()); + amount = amount.add(paymentRecDetail.getAmount()); + } + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.SELF_CASH_ALI_VALUE.getValue())) { + map.put("aliCash", paymentRecDetail.getAmount()); + amount = amount.add(paymentRecDetail.getAmount()); + } + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.INSCP_SCP_AMT.getValue())) { + map.put("FHZCAmount", paymentRecDetail.getAmount()); + } + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.INSCP_SCP_AMT.getValue())) { + map.put("FHZCAmount", paymentRecDetail.getAmount()); + } + } + map.put("realAmount", amount); + + Invoice invoice = iInvoiceService.getOne(new LambdaQueryWrapper() + .eq(Invoice::getReconciliationId, paymentId).eq(Invoice::getStatusEnum, InvoiceStatus.ISSUED.getValue()) + .orderByDesc(Invoice::getCreateTime).last(YbCommonConstants.sqlConst.LIMIT1)); + if (invoice != null) { + map.put("invoiceNo", invoice.getBillNo()); + map.put("pictureUrl", invoice.getPictureUrl()); + } + + List chargeItemIdList = Arrays.stream(paymentReconciliation.getChargeItemIds().split(",")) + .map(Long::parseLong).collect(Collectors.toList()); + + List chargeItemList = chargeItemService.list(new LambdaQueryWrapper() + .in(ChargeItem::getId, chargeItemIdList).eq(ChargeItem::getDeleteFlag, DelFlag.NO.getCode())); + List chargeItemDetailList = new ArrayList<>(); + ChargeItemDetailVO chargeItemDetailVO; + for (ChargeItem chargeItem : chargeItemList) { + chargeItemDetailVO = new ChargeItemDetailVO(); + BeanUtils.copyProperties(chargeItem, chargeItemDetailVO); + if (CommonConstants.TableName.MED_MEDICATION_DEFINITION.equals(chargeItem.getProductTable())) { + MedicationDefinition medication = iMedicationDefinitionService.getById(chargeItem.getProductId()); + + Medication medicationDef = iMedicationService + .list(new LambdaQueryWrapper().eq(Medication::getMedicationDefId, medication.getId())) + .get(0); + chargeItemDetailVO.setDirClass(medication.getChrgitmLv() + "").setChargeItemName(medication.getName()) + .setTotalPrice(chargeItem.getTotalPrice()).setQuantityUnit(chargeItem.getQuantityUnit()) + .setTotalVolume(medicationDef.getTotalVolume()).setQuantityValue(chargeItem.getQuantityValue()); + } else if (CommonConstants.TableName.ADM_DEVICE_DEFINITION.equals(chargeItem.getProductTable())) { + DeviceDefinition device = iDeviceDefinitionService.getById(chargeItem.getProductId()); + chargeItemDetailVO.setDirClass(device.getChrgitmLv() + "").setChargeItemName(device.getName()) + .setTotalPrice(chargeItem.getTotalPrice()).setQuantityUnit(chargeItem.getQuantityUnit()) + .setTotalVolume(device.getSize()).setQuantityValue(chargeItem.getQuantityValue()); + } else if (CommonConstants.TableName.WOR_ACTIVITY_DEFINITION.equals(chargeItem.getProductTable())) { + if (chargeItem.getProductId() != null && chargeItem.getProductId() > 0) { + ActivityDefinition activity = iActivityDefinitionService.getById(chargeItem.getProductId()); + chargeItemDetailVO.setDirClass(activity.getChrgitmLv() + "").setChargeItemName(activity.getName()) + .setTotalPrice(chargeItem.getTotalPrice()).setQuantityUnit(chargeItem.getQuantityUnit()) + .setTotalVolume("").setQuantityValue(chargeItem.getQuantityValue()); + } else { + ServiceRequest serviceRequest = iServiceRequestService.getById(chargeItem.getServiceId()); + String itemName = "未知项目"; + String dirClass = "3"; + if (serviceRequest != null && serviceRequest.getContentJson() != null) { + try { + JsonNode json = JsonUtils.parse(serviceRequest.getContentJson()); + if (json.has("adviceName")) { + itemName = json.path("adviceName").asText(); + } + } catch (Exception e) { + log.warn("解析ServiceRequest.contentJson失败: {}", e.getMessage()); + } + } + chargeItemDetailVO.setDirClass(dirClass).setChargeItemName(itemName) + .setTotalPrice(chargeItem.getTotalPrice()).setQuantityUnit(chargeItem.getQuantityUnit()) + .setTotalVolume("").setQuantityValue(chargeItem.getQuantityValue()); + } + } else { + HealthcareService healthcareService = iHealthcareServiceService.getById(chargeItem.getServiceId()); + chargeItemDetailVO.setDirClass("3").setChargeItemName(healthcareService.getName()) + .setTotalPrice(chargeItem.getTotalPrice()).setQuantityUnit(chargeItem.getQuantityUnit()) + .setTotalVolume("").setQuantityValue(chargeItem.getQuantityValue()); + } + chargeItemDetailList.add(chargeItemDetailVO); + } + map.put("chargeItem", chargeItemDetailList); + + if (chargeItemList.isEmpty()) { + throw new ServiceException("未查询到收费项"); + } + if (encounter == null) { + throw new ServiceException("未查询到就诊信息"); + } + map.put("classEnum", encounter.getYbClassEnum()); + map.put("regNo", encounter.getBusNo()); + + Account account = iAccountService.getOne(new LambdaQueryWrapper() + .eq(Account::getEncounterId, encounter.getId()).eq(Account::getEncounterFlag, Whether.YES.getValue())); + if (account == null) { + throw new ServiceException("未查询到就诊信息"); + } + + InfoPerson perinfo = iPerinfoService.getOne(new LambdaQueryWrapper() + .eq(InfoPerson::getCertno, patient.getIdCard()).eq(InfoPerson::getTenantId, patient.getTenantId()) + .orderByDesc(InfoPerson::getCreateTime).last(YbCommonConstants.sqlConst.LIMIT1)); + if (perinfo != null) { + map.put("personType", perinfo.getInsutype()); + map.put("insuplcAdmdvs", perinfo.getInsuplcAdmdvs()); + } + + com.healthlink.his.financial.domain.Contract contract + = iContractService.getOne(new LambdaQueryWrapper() + .eq(com.healthlink.his.financial.domain.Contract::getBusNo, account.getContractNo())); + if (contract == null) { + throw new ServiceException("未查询到合同信息"); + } + map.put("contractName", contract.getContractName()); + EncounterDiagnosis encounterDiagnosis = iEncounterDiagnosisService.getOne( + new LambdaQueryWrapper().eq(EncounterDiagnosis::getEncounterId, encounter.getId()) + .eq(EncounterDiagnosis::getMaindiseFlag, Whether.YES.getValue()) + .eq(EncounterDiagnosis::getDeleteFlag, DelFlag.NO.getCode()) + .orderByDesc(EncounterDiagnosis::getDiagSrtNo).last(YbCommonConstants.sqlConst.LIMIT1)); + + if (encounterDiagnosis != null) { + Condition condition = iConditionService.getById(encounterDiagnosis.getConditionId()); + if (condition != null) { + ConditionDefinition conditionDefinition + = iConditionDefinitionService.getOne(new LambdaQueryWrapper() + .eq(ConditionDefinition::getId, condition.getDefinitionId())); + if (conditionDefinition != null) { + map.put("conditionDefinition", conditionDefinition.getName()); + } + } + } + + 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; + + for (ChargeItem chargeItem : chargeItemList) { + + Long definitionId = chargeItem.getDefinitionId(); + + ChargeItemDefinition chargeItemDefinition = null; + if (definitionId != null && definitionId > 0) { + chargeItemDefinition = iChargeItemDefinitionService.getById(definitionId); + } + + if (chargeItemDefinition == null) { + sum03 = sum03.add(chargeItem.getTotalPrice()); + continue; + } + + com.healthlink.his.yb.enums.YbMedChrgItmType medChrgItmType + = com.healthlink.his.yb.enums.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); + + var loginUser = SecurityUtils.getLoginUser(); + String fixmedinsName = loginUser.getOptionJsonValue(CommonConstants.Option.FIXMEDINS_NAME); + String fixmedinsCode = loginUser.getOptionJsonValue(CommonConstants.Option.FIXMEDINS_CODE); + + map.put("fixmedinsName", fixmedinsName); + map.put("fixmedinsCode", fixmedinsCode); + + return map; + } + + public Map getReceiptDetailsND(Long paymentId) { + + Map map = new HashMap<>(); + PaymentReconciliation paymentReconciliation = paymentReconciliationService.getById(paymentId); + if (paymentReconciliation == null) { + throw new ServiceException("未查询到付款信息"); + } + map.put("paymentId", paymentReconciliation.getPaymentNo()); + map.put("paymentAmount", paymentReconciliation.getTenderedAmount()); + Practitioner practitioner = iPractitionerService.getById(paymentReconciliation.getEntererId()); + map.put("paymentEmployee", practitioner == null ? "" : practitioner.getName()); + map.put("chargeTime", paymentReconciliation.getBillDate()); + Patient patient = iPatientService.getById(paymentReconciliation.getPatientId()); + if (patient == null) { + throw new ServiceException("未查询到患者信息"); + } + map.put("patientName", patient.getName()); + + map.put("sex", patient.getGenderEnum()); + map.put("idCardNo", patient.getIdCard()); + map.put("birthDay", patient.getBirthDate()); + + List paymentRecDetails = paymentRecDetailService.list( + new LambdaQueryWrapper().eq(PaymentRecDetail::getReconciliationId, paymentId)); + + if (paymentRecDetails.isEmpty()) { + throw new ServiceException("未查询到付款信息"); + } + map.put("detail", paymentRecDetails); + + for (PaymentRecDetail paymentRecDetail : paymentRecDetails) { + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.SELF_YB_ZH_PAY.getValue())) { + map.put("ybAccountPay", paymentRecDetail.getAmount()); + } + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.BALC.getValue())) { + map.put("ybAccountBalc", paymentRecDetail.getAmount()); + } + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.YB_FUND_PAY.getValue())) { + map.put("ybFundPay", paymentRecDetail.getAmount()); + } + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.YB_TC_FUND_AMOUNT.getValue())) { + map.put("ybTcPay", paymentRecDetail.getAmount()); + } + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.YB_BC_GWY_BZ_VALUE.getValue())) { + map.put("ybGWYPay", paymentRecDetail.getAmount()); + } + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.OTHER_PAY.getValue())) { + map.put("ybOtherPay", paymentRecDetail.getAmount()); + } + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.YB_BC_DE_BZ_VALUE.getValue())) { + map.put("ybDELPPay", paymentRecDetail.getAmount()); + } + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.YB_BC_ZG_DE_BZ_VALUE.getValue())) { + map.put("ybDELPPay", paymentRecDetail.getAmount()); + } + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.E_WALLET.getValue())) { + map.put("ybWallet", paymentRecDetail.getAmount()); + } + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.SUPPLEMENTARY_INSURANCE.getValue())) { + map.put("ybWallet", paymentRecDetail.getAmount()); + } + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.SELF_CASH_VALUE.getValue())) { + map.put("cash", paymentRecDetail.getAmount()); + } + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.SELF_CASH_VX_VALUE.getValue())) { + map.put("wxCash", paymentRecDetail.getAmount()); + } + if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.SELF_CASH_ALI_VALUE.getValue())) { + map.put("aliCash", paymentRecDetail.getAmount()); + } + } + + Invoice invoice = iInvoiceService.getOne(new LambdaQueryWrapper().eq(Invoice::getReconciliationId, + paymentId).eq(Invoice::getStatusEnum, InvoiceStatus.ISSUED.getValue()).orderByDesc(Invoice::getCreateTime) + .last(YbCommonConstants.sqlConst.LIMIT1)); + if (invoice != null) { + map.put("invoiceNo", invoice.getBillNo()); + map.put("pictureUrl", invoice.getPictureUrl()); + } + + List chargeItemIds = Arrays.stream(paymentReconciliation.getChargeItemIds().split(",")).map( + Long::parseLong) + .collect(Collectors.toList()); + List chargeItemBaseInfoByIds = chargeItemService.getChargeItemBaseInfoByIds( + chargeItemIds); + + for (ChargeItemBaseInfoDto chargeItemBaseInfoById : chargeItemBaseInfoByIds) { + if (chargeItemBaseInfoById.getDeptName() == null) { + throw new ServiceException("收费项" + chargeItemBaseInfoById.getName() + "无开单科室"); + } + if (chargeItemBaseInfoById.getTypeCode() == null) { + throw new ServiceException("收费项" + chargeItemBaseInfoById.getName() + "无财务分类"); + } + if (!CommonConstants.BusinessName.DEFAULT_CONTRACT_NO.equals(chargeItemBaseInfoById.getContractNo())) { + Object o = map.get(chargeItemBaseInfoById.getContractNo() + "-" + chargeItemBaseInfoById.getTypeCode()); + if (o == null) { + map.put(chargeItemBaseInfoById.getContractNo() + "-" + chargeItemBaseInfoById.getTypeCode(), + chargeItemBaseInfoById.getTotalPrice()); + } else { + BigDecimal bigDecimal = new BigDecimal(String.valueOf(o)); + bigDecimal = bigDecimal.add(chargeItemBaseInfoById.getTotalPrice()); + map.put(chargeItemBaseInfoById.getContractNo() + "-" + chargeItemBaseInfoById.getTypeCode(), + bigDecimal); + } + } else { + Object o = map.get(chargeItemBaseInfoById.getDeptName() + "-" + chargeItemBaseInfoById.getTypeCode()); + if (o == null) { + map.put(chargeItemBaseInfoById.getDeptName() + "-" + chargeItemBaseInfoById.getTypeCode(), + chargeItemBaseInfoById.getTotalPrice()); + } else { + BigDecimal bigDecimal = new BigDecimal(String.valueOf(o)); + bigDecimal = bigDecimal.add(chargeItemBaseInfoById.getTotalPrice()); + map.put(chargeItemBaseInfoById.getDeptName() + "-" + chargeItemBaseInfoById.getTypeCode(), + bigDecimal); + } + } + } + + Encounter encounter = iEncounterService.getById(paymentReconciliation.getEncounterId()); + if (encounter == null) { + throw new ServiceException("未查询到就诊信息"); + } + map.put("classEnum", encounter.getYbClassEnum()); + map.put("regNo", encounter.getBusNo()); + + InfoPerson perinfo = iPerinfoService.getOne(new LambdaQueryWrapper().eq(InfoPerson::getCertno, + patient.getIdCard()).eq(InfoPerson::getTenantId, patient.getTenantId()) + .orderByDesc(InfoPerson::getCreateTime).last(YbCommonConstants.sqlConst.LIMIT1)); + if (perinfo != null) { + map.put("personType", perinfo.getInsutype()); + map.put("insuplcAdmdvs", perinfo.getInsuplcAdmdvs()); + } + + EncounterDiagnosis encounterDiagnosis = iEncounterDiagnosisService.getOne( + new LambdaQueryWrapper().eq(EncounterDiagnosis::getEncounterId, encounter.getId()).eq( + EncounterDiagnosis::getMaindiseFlag, Whether.YES.getValue()).eq(EncounterDiagnosis::getDeleteFlag, + DelFlag.NO.getCode()).orderByDesc(EncounterDiagnosis::getDiagSrtNo) + .last(YbCommonConstants.sqlConst.LIMIT1)); + + if (encounterDiagnosis != null) { + Condition condition = iConditionService.getById(encounterDiagnosis.getConditionId()); + if (condition != null) { + ConditionDefinition conditionDefinition = iConditionDefinitionService.getOne( + new LambdaQueryWrapper().eq(ConditionDefinition::getId, + condition.getDefinitionId())); + if (conditionDefinition != null) { + map.put("conditionDefinition", conditionDefinition.getName()); + } + } + } + + var loginUser = SecurityUtils.getLoginUser(); + String fixmedinsName = loginUser.getOptionJsonValue(CommonConstants.Option.FIXMEDINS_NAME); + String fixmedinsCode = loginUser.getOptionJsonValue(CommonConstants.Option.FIXMEDINS_CODE); + + map.put("fixmedinsName", fixmedinsName); + map.put("fixmedinsCode", fixmedinsCode); + + return map; + } + + public Map getYbEncounterType(Long encounterId) { + HashMap map = new HashMap<>(); + Encounter encounter = iEncounterService.getById(encounterId); + if (encounter == null) { + throw new ServiceException("未查询到就诊信息"); + } + + Patient patient = iPatientService.getById(encounter.getPatientId()); + if (patient == null) { + throw new ServiceException("未查询到患者信息"); + } + + Account ybAccount = iAccountService.getYbAccount(encounter.getId()); + if (ybAccount == null) { + map.put("insutype", "自费"); + return map; + } + + com.healthlink.his.financial.domain.Contract contract = iContractService.getContract(ybAccount.getContractNo()); + if (contract == null) { + throw new ServiceException("未查询到合同信息"); + } + + InfoPerson perinfo = iPerinfoService.getOne(new LambdaQueryWrapper().eq(InfoPerson::getCertno, + patient.getIdCard()).eq(InfoPerson::getTenantId, patient.getTenantId()) + .orderByDesc(InfoPerson::getCreateTime).last(YbCommonConstants.sqlConst.LIMIT1)); + if (perinfo != null) { + com.healthlink.his.yb.enums.YbMdcsType byCode = com.healthlink.his.yb.enums.YbMdcsType.getByCode(perinfo.getInsutype()); + map.put("insutype", contract.getBusNo() + "-" + byCode.getInfo()); + return map; + } + map.put("insutype", "自费"); + return map; + } +} diff --git a/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/paymentmanage/appservice/impl/ChargeBillStatisticsService.java b/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/paymentmanage/appservice/impl/ChargeBillStatisticsService.java new file mode 100644 index 000000000..14b14f21a --- /dev/null +++ b/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/paymentmanage/appservice/impl/ChargeBillStatisticsService.java @@ -0,0 +1,88 @@ +package com.healthlink.his.web.paymentmanage.appservice.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.core.common.core.domain.R; +import com.core.common.enums.DelFlag; +import com.core.common.exception.ServiceException; +import com.core.common.utils.*; +import com.healthlink.his.workflow.domain.ActivityDefinition; +import com.healthlink.his.workflow.service.IActivityDefinitionService; +import com.healthlink.his.common.constant.CommonConstants; +import com.healthlink.his.yb.dto.Catalogue1312Output; +import com.healthlink.his.yb.dto.Catalogue1312QueryParam; +import com.healthlink.his.yb.service.IYbHttpUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.time.LocalDate; +import java.time.ZoneId; +import java.util.*; + +/** + * 收费票据统计服务 - 处理报表/统计相关方法 + */ +@Component +@Slf4j +public class ChargeBillStatisticsService { + + @Autowired + private IActivityDefinitionService iActivityDefinitionService; + @Autowired + private IYbHttpUtils ybHttpUtils; + + public R checkYbNo() { + + List list = iActivityDefinitionService.list( + new LambdaQueryWrapper().isNotNull(ActivityDefinition::getYbNo) + .eq(ActivityDefinition::getDeleteFlag, DelFlag.NO.getCode())); + + List outList = new ArrayList<>(); + List voicList = new ArrayList<>(); + + if (list.isEmpty()) { + throw new ServiceException("没查到有医保码的诊疗定义"); + } + + for (ActivityDefinition activityDefinition : list) { + + Date nowTime = new Date(); + + Catalogue1312QueryParam catalogue1312QueryParam = new Catalogue1312QueryParam(); + catalogue1312QueryParam.setHilistCode(activityDefinition.getYbNo()); + catalogue1312QueryParam.setInsuplcAdmdvs( + SecurityUtils.getLoginUser().getOptionJsonValue(CommonConstants.Option.INSUPLC_ADMDVS)); + LocalDate localDate = LocalDate.parse("2025-01-01"); + Date date = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + catalogue1312QueryParam.setUpdtTime(date); + catalogue1312QueryParam.setPageNum(1); + catalogue1312QueryParam.setPageSize(10); + catalogue1312QueryParam.setDecryptFlag("0"); + List outputList = ybHttpUtils.queryYbCatalogue(catalogue1312QueryParam); + + if (outputList != null && !outputList.isEmpty() && outputList.get(0) != null) { + Catalogue1312Output catalogue1312Output = outputList.get(0); + if (catalogue1312Output.getValiFlag() != null && catalogue1312Output.getValiFlag().equals("1")) { + Date enddate = catalogue1312Output.getEnddate(); + if (enddate == null) { + // OK + } else { + if (!DateUtils.isFuture(enddate)) { + outList.add(activityDefinition); + } + } + + } else { + voicList.add(activityDefinition); + } + } + + } + + HashMap hashMap = new HashMap<>(); + hashMap.put("失效列表", voicList); + hashMap.put("过期列表", outList); + + return R.ok(hashMap); + } +} diff --git a/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/paymentmanage/appservice/impl/IChargeBillServiceImpl.java b/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/paymentmanage/appservice/impl/IChargeBillServiceImpl.java index 6f37f9c27..6519736c2 100755 --- a/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/paymentmanage/appservice/impl/IChargeBillServiceImpl.java +++ b/healthlink-his-server/healthlink-his-application/src/main/java/com/healthlink/his/web/paymentmanage/appservice/impl/IChargeBillServiceImpl.java @@ -1,2764 +1,75 @@ package com.healthlink.his.web.paymentmanage.appservice.impl; -import com.core.common.utils.JsonUtils; -import tools.jackson.databind.JsonNode; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.core.common.core.domain.R; -import com.core.common.enums.DelFlag; -import com.core.common.exception.ServiceException; -import com.core.common.utils.*; -import com.healthlink.his.administration.domain.*; -import com.healthlink.his.administration.dto.ChargeItemBaseInfoDto; -import com.healthlink.his.administration.dto.ChargeItemDefInfo; -import com.healthlink.his.administration.dto.EncounterAccountDto; -import com.healthlink.his.administration.service.*; -import com.healthlink.his.clinical.domain.Condition; -import com.healthlink.his.clinical.domain.ConditionDefinition; -import com.healthlink.his.clinical.service.IConditionDefinitionService; -import com.healthlink.his.clinical.service.IConditionService; -import com.healthlink.his.clinical.service.IProcedureService; -import com.healthlink.his.common.constant.CommonConstants; -import com.healthlink.his.common.constant.YbCommonConstants; -import com.healthlink.his.common.enums.*; -import com.healthlink.his.yb.enums.YbMdcsType; -import com.healthlink.his.yb.enums.YbMedChrgItmType; -import com.healthlink.his.yb.enums.YbPayment; -import com.healthlink.his.financial.domain.Contract; -import com.healthlink.his.financial.domain.PaymentRecDetail; -import com.healthlink.his.financial.domain.PaymentReconciliation; -import com.healthlink.his.financial.model.PaymentRecDetailAccountResult; -import com.healthlink.his.financial.model.PaymentReconciliationAccountDel; -import com.healthlink.his.financial.service.IContractService; -import com.healthlink.his.financial.service.IPaymentRecDetailService; -import com.healthlink.his.financial.service.IPaymentReconciliationService; -import com.healthlink.his.medication.domain.Medication; -import com.healthlink.his.medication.domain.MedicationDefinition; -import com.healthlink.his.medication.service.IMedicationDefinitionService; -import com.healthlink.his.medication.service.IMedicationService; -import com.healthlink.his.web.outpatientmanage.mapper.OutpatientTreatmentAppMapper; import com.healthlink.his.web.paymentmanage.appservice.IChargeBillService; -import com.healthlink.his.web.paymentmanage.dto.*; -import com.healthlink.his.web.paymentmanage.mapper.ChargeBillMapper; -import com.healthlink.his.workflow.domain.ActivityDefinition; -import com.healthlink.his.workflow.domain.ServiceRequest; -import com.healthlink.his.workflow.service.IActivityDefinitionService; -import com.healthlink.his.workflow.service.IServiceRequestService; -import com.healthlink.his.yb.domain.ClinicSettle; -import com.healthlink.his.yb.domain.ClinicUnSettle; -import com.healthlink.his.yb.domain.InfoPerson; -import com.healthlink.his.yb.dto.Catalogue1312Output; -import com.healthlink.his.yb.dto.Catalogue1312QueryParam; -import com.healthlink.his.yb.service.*; -import com.healthlink.his.ybcatalog.service.ICatalogMedicalServiceService; +import com.healthlink.his.web.paymentmanage.dto.ChargeSummaryDto; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import jakarta.annotation.Resource; -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.time.format.DateTimeFormatter; -import java.util.*; -import java.util.stream.Collectors; +import java.util.Map; +/** + * 收费票据应用服务 - 委托到专注服务类 + */ @Component @Slf4j public class IChargeBillServiceImpl implements IChargeBillService { - @Resource - private IAccountService iAccountService; - @Resource - private IEncounterService iEncounterService; - @Resource - private IEncounterParticipantService iEncounterParticipantService; - @Resource - private IContractService iContractService; - @Resource - private IInvoiceService iInvoiceService; - @Resource - private IPaymentReconciliationService paymentReconciliationService; - @Resource - private IPaymentRecDetailService paymentRecDetailService; - @Resource - private IContractService contractService; - @Resource - private IChargeItemService chargeItemService; - @Resource - private IPatientService iPatientService; @Autowired - private IChargeItemDefinitionService iChargeItemDefinitionService; + private ChargeBillQueryService chargeBillQueryService; @Autowired - private IPerinfoService iPerinfoService; + private ChargeBillCalculationService chargeBillCalculationService; @Autowired - private IEncounterDiagnosisService iEncounterDiagnosisService; - @Autowired - private IOrganizationService iOrganizationService; - @Autowired - private IConditionDefinitionService iConditionDefinitionService; - @Autowired - private IConditionService iConditionService; - @Autowired - private ChargeBillMapper chargeBillMapper; - @Autowired - private IMedicationService iMedicationService; - @Autowired - private IMedicationDefinitionService iMedicationDefinitionService; - @Autowired - private IDeviceDefinitionService iDeviceDefinitionService; - @Autowired - private IActivityDefinitionService iActivityDefinitionService; - @Autowired - private IServiceRequestService iServiceRequestService; - @Autowired - private IPractitionerService iPractitionerService; - @Autowired - private IHealthcareServiceService iHealthcareServiceService; - @Autowired - private IClinicSettleService iClinicSettleService; - @Autowired - private IClinicUnRegService iClinicUnRegService; - @Autowired - private IRegService iRegService; - @Autowired - private IClinicUnSettleService iClinicUnSettleService; - @Autowired - private ICatalogMedicalServiceService iCatalogMedicalServiceService; - @Autowired - private IProcedureService procedureService; - @Autowired - private OutpatientTreatmentAppMapper outpatientTreatmentAppMapper; + private ChargeBillStatisticsService chargeBillStatisticsService; @Override public Map getDetail(Long paymentId) { - - Map map = new HashMap<>(); - // 查询 - PaymentReconciliation paymentReconciliation = paymentReconciliationService.getById(paymentId); - if (paymentReconciliation == null) { - throw new ServiceException("未查询到付款信息"); - } - map.put("paymentId", paymentReconciliation.getPaymentNo());// 结算id - map.put("paymentAmount", paymentReconciliation.getTenderedAmount());// 应收金额 - - Practitioner practitioner = iPractitionerService.getById(paymentReconciliation.getEntererId()); - map.put("paymentEmployee", practitioner == null ? "" : practitioner.getName());// 收费员 - map.put("chargeTime", paymentReconciliation.getBillDate());// 收费时间 - - Patient patient = iPatientService.getById(paymentReconciliation.getPatientId()); - if (patient == null) { - throw new ServiceException("未查询到患者信息"); - } - map.put("patientName", patient.getName());// 患者姓名 - - map.put("sex", patient.getGenderEnum());// 性别 - map.put("idCardNo", patient.getIdCard());// 身份证号 - map.put("birthDay", patient.getBirthDate());// 出生日期 - map.put("age", AgeCalculatorUtil.calculateAge(patient.getBirthDate()));// 出生日期 - - Encounter encounter = iEncounterService.getById(paymentReconciliation.getEncounterId()); - if (patient == null) { - throw new ServiceException("未查询到就诊信息"); - } - map.put("classEnum", encounter.getYbClassEnum());// 门诊/住院 - map.put("regNo", encounter.getBusNo());// 门诊号 - - List encounterParticipantListByTypeCode = iEncounterParticipantService.getEncounterParticipantListByTypeCode(encounter.getId(), ParticipantType.ADMITTER); - if (!encounterParticipantListByTypeCode.isEmpty()) { - Practitioner doctor = iPractitionerService.getById(encounterParticipantListByTypeCode.get(0).getPractitionerId()); - map.put("doctor", doctor == null ? "" : doctor.getName());// 接诊医生 - } - - List paymentRecDetails = paymentRecDetailService - .list(new LambdaQueryWrapper().eq(PaymentRecDetail::getReconciliationId, paymentId)); - - if (paymentRecDetails.isEmpty()) { - throw new ServiceException("未查询到付款信息"); - } - map.put("detail", paymentRecDetails);// 支付详细 - - BigDecimal amount = BigDecimal.ZERO; - for (PaymentRecDetail paymentRecDetail : paymentRecDetails) { - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.SELF_YB_ZH_PAY.getValue())) { - map.put("ybAccountPay", paymentRecDetail.getAmount());// 医保账户支付 - amount = amount.add(paymentRecDetail.getAmount()); - } - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.BALC.getValue())) { - map.put("ybAccountBalc", paymentRecDetail.getAmount());// 医保账户余额(现) - } - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.YB_FUND_PAY.getValue())) { - map.put("ybFundPay", paymentRecDetail.getAmount());// 基金支付总额 - } - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.YB_TC_FUND_AMOUNT.getValue())) { - map.put("ybTcPay", paymentRecDetail.getAmount());// 统筹支付金额 - } - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.YB_BC_GWY_BZ_VALUE.getValue())) { - map.put("ybGWYPay", paymentRecDetail.getAmount());// 公务员补助 - } - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.OTHER_PAY.getValue())) { - map.put("ybOtherPay", paymentRecDetail.getAmount());// 其他支付 - } - // 下面两个大额理赔有哪个用哪个,无所谓的 - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.YB_BC_DE_BZ_VALUE.getValue())) { - map.put("ybDELPPay", paymentRecDetail.getAmount());// 大额理赔(常规) - } - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.YB_BC_ZG_DE_BZ_VALUE.getValue())) { - map.put("ybDELPPay", paymentRecDetail.getAmount());// 大额理赔(企业) - } - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.E_WALLET.getValue())) { - map.put("ybWallet", paymentRecDetail.getAmount());// 电子钱包 - } - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.SUPPLEMENTARY_INSURANCE.getValue())) { - map.put("ybWallet", paymentRecDetail.getAmount());// 居民大病报销 - } - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.SELF_CASH_VALUE.getValue())) { - map.put("cash", paymentRecDetail.getAmount());// 现金 - amount = amount.add(paymentRecDetail.getAmount()); - } - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.SELF_CASH_VX_VALUE.getValue())) { - map.put("wxCash", paymentRecDetail.getAmount());// 现金(微信) - amount = amount.add(paymentRecDetail.getAmount()); - } - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.SELF_CASH_ALI_VALUE.getValue())) { - map.put("aliCash", paymentRecDetail.getAmount());// 现金(支付宝) - amount = amount.add(paymentRecDetail.getAmount()); - } - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.INSCP_SCP_AMT.getValue())) { - map.put("FHZCAmount", paymentRecDetail.getAmount());// 符合政策金额 - } - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.INSCP_SCP_AMT.getValue())) { - map.put("FHZCAmount", paymentRecDetail.getAmount());// 符合政策金额 - } - } - map.put("realAmount", amount);// 实收金额 - - Invoice invoice = iInvoiceService.getOne(new LambdaQueryWrapper() - .eq(Invoice::getReconciliationId, paymentId).eq(Invoice::getStatusEnum, InvoiceStatus.ISSUED.getValue()) - .orderByDesc(Invoice::getCreateTime).last(YbCommonConstants.sqlConst.LIMIT1)); - if (invoice != null) { - map.put("invoiceNo", invoice.getBillNo());// 支付详细 - map.put("pictureUrl", invoice.getPictureUrl());// 图片 - } - - List chargeItemIdList = Arrays.stream(paymentReconciliation.getChargeItemIds().split(",")) - .map(Long::parseLong).collect(Collectors.toList()); - - List chargeItemList = chargeItemService.list(new LambdaQueryWrapper() - .in(ChargeItem::getId, chargeItemIdList).eq(ChargeItem::getDeleteFlag, DelFlag.NO.getCode())); - List chargeItemDetailList = new ArrayList<>(); - ChargeItemDetailVO chargeItemDetailVO; - for (ChargeItem chargeItem : chargeItemList) { - chargeItemDetailVO = new ChargeItemDetailVO(); - BeanUtils.copyProperties(chargeItem, chargeItemDetailVO); - if (CommonConstants.TableName.MED_MEDICATION_DEFINITION.equals(chargeItem.getProductTable())) { - MedicationDefinition medication = iMedicationDefinitionService.getById(chargeItem.getProductId()); - - Medication medicationDef = iMedicationService - .list(new LambdaQueryWrapper().eq(Medication::getMedicationDefId, medication.getId())) - .get(0); - chargeItemDetailVO.setDirClass(medication.getChrgitmLv() + "").setChargeItemName(medication.getName()) - .setTotalPrice(chargeItem.getTotalPrice()).setQuantityUnit(chargeItem.getQuantityUnit()) - .setTotalVolume(medicationDef.getTotalVolume()).setQuantityValue(chargeItem.getQuantityValue()); - } else if (CommonConstants.TableName.ADM_DEVICE_DEFINITION.equals(chargeItem.getProductTable())) { - DeviceDefinition device = iDeviceDefinitionService.getById(chargeItem.getProductId()); - chargeItemDetailVO.setDirClass(device.getChrgitmLv() + "").setChargeItemName(device.getName()) - .setTotalPrice(chargeItem.getTotalPrice()).setQuantityUnit(chargeItem.getQuantityUnit()) - .setTotalVolume(device.getSize()).setQuantityValue(chargeItem.getQuantityValue()); - } else if (CommonConstants.TableName.WOR_ACTIVITY_DEFINITION.equals(chargeItem.getProductTable())) { - // 🔧 BugFix#385: 检查申请创建的收费项 productId=0,需从 ServiceRequest.contentJson 获取项目名称 - if (chargeItem.getProductId() != null && chargeItem.getProductId() > 0) { - ActivityDefinition activity = iActivityDefinitionService.getById(chargeItem.getProductId()); - chargeItemDetailVO.setDirClass(activity.getChrgitmLv() + "").setChargeItemName(activity.getName()) - .setTotalPrice(chargeItem.getTotalPrice()).setQuantityUnit(chargeItem.getQuantityUnit()) - .setTotalVolume("").setQuantityValue(chargeItem.getQuantityValue()); - } else { - // productId=0 时,从关联的 ServiceRequest 获取项目名称 - ServiceRequest serviceRequest = iServiceRequestService.getById(chargeItem.getServiceId()); - String itemName = "未知项目"; - String dirClass = "3"; // 默认诊疗类 - if (serviceRequest != null && serviceRequest.getContentJson() != null) { - try { - JsonNode json = JsonUtils.parse(serviceRequest.getContentJson()); - if (json.has("adviceName")) { - itemName = json.path("adviceName").asText(); - } - } catch (Exception e) { - log.warn("解析ServiceRequest.contentJson失败: {}", e.getMessage()); - } - } - chargeItemDetailVO.setDirClass(dirClass).setChargeItemName(itemName) - .setTotalPrice(chargeItem.getTotalPrice()).setQuantityUnit(chargeItem.getQuantityUnit()) - .setTotalVolume("").setQuantityValue(chargeItem.getQuantityValue()); - } - } else { - HealthcareService healthcareService = iHealthcareServiceService.getById(chargeItem.getServiceId()); - chargeItemDetailVO.setDirClass("3").setChargeItemName(healthcareService.getName()) - .setTotalPrice(chargeItem.getTotalPrice()).setQuantityUnit(chargeItem.getQuantityUnit()) - .setTotalVolume("").setQuantityValue(chargeItem.getQuantityValue()); - } - chargeItemDetailList.add(chargeItemDetailVO); - } - map.put("chargeItem", chargeItemDetailList);// 收费项 - - if (chargeItemList.isEmpty()) { - throw new ServiceException("未查询到收费项"); - } -// Encounter encounter = iEncounterService.getById(paymentReconciliation.getEncounterId()); - if (encounter == null) { - throw new ServiceException("未查询到就诊信息"); - } - map.put("classEnum", encounter.getYbClassEnum());// 门诊/住院 - map.put("regNo", encounter.getBusNo());// 门诊号 - - Account account = iAccountService.getOne(new LambdaQueryWrapper() - .eq(Account::getEncounterId, encounter.getId()).eq(Account::getEncounterFlag, Whether.YES.getValue())); - if (account == null) { - throw new ServiceException("未查询到就诊信息"); - } - - InfoPerson perinfo = iPerinfoService.getOne(new LambdaQueryWrapper() - .eq(InfoPerson::getCertno, patient.getIdCard()).eq(InfoPerson::getTenantId, patient.getTenantId()) - .orderByDesc(InfoPerson::getCreateTime).last(YbCommonConstants.sqlConst.LIMIT1)); - if (perinfo != null) { - map.put("personType", perinfo.getInsutype());// 人员类别:职工医保,居民医保等;如果为空显示自费或其他 - map.put("insuplcAdmdvs", perinfo.getInsuplcAdmdvs());// 患者参保地区划 - } - - Contract contract - = contractService.getOne(new LambdaQueryWrapper().eq(Contract::getBusNo, account.getContractNo())); - if (contract == null) { - throw new ServiceException("未查询到合同信息"); - } - map.put("contractName", contract.getContractName()); - // 查询主诊断信息 - EncounterDiagnosis encounterDiagnosis = iEncounterDiagnosisService.getOne( - new LambdaQueryWrapper().eq(EncounterDiagnosis::getEncounterId, encounter.getId()) - .eq(EncounterDiagnosis::getMaindiseFlag, Whether.YES.getValue()) - .eq(EncounterDiagnosis::getDeleteFlag, DelFlag.NO.getCode()) - .orderByDesc(EncounterDiagnosis::getDiagSrtNo).last(YbCommonConstants.sqlConst.LIMIT1)); - - if (encounterDiagnosis != null) { - Condition condition = iConditionService.getById(encounterDiagnosis.getConditionId()); - if (condition != null) { - ConditionDefinition conditionDefinition - = iConditionDefinitionService.getOne(new LambdaQueryWrapper() - .eq(ConditionDefinition::getId, condition.getDefinitionId())); - if (conditionDefinition != null) { - map.put("conditionDefinition", conditionDefinition.getName());// 诊断名 - } - } - } - - 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; - - for (ChargeItem chargeItem : chargeItemList) { - - Long definitionId = chargeItem.getDefinitionId(); - - // 🔧 BugFix#385: 检查申请创建的收费项 definition_id=0,chargeItemDefinition 会为 null - ChargeItemDefinition chargeItemDefinition = null; - if (definitionId != null && definitionId > 0) { - chargeItemDefinition = iChargeItemDefinitionService.getById(definitionId); - } - - // 当 definitionId=0 或 chargeItemDefinition 为 null 时,跳过医保分类统计 - // 检查类项目默认归类为"检查费" - if (chargeItemDefinition == null) { - // 检查申请的收费项,归类为检查费(03) - sum03 = sum03.add(chargeItem.getTotalPrice()); - continue; - } - - 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);// 其他费用 - - // String ybSwitch = SecurityUtils.getLoginUser().getOptionJsonValue(CommonConstants.Option.YB_SWITCH); - var loginUser = SecurityUtils.getLoginUser(); - String fixmedinsName = loginUser.getOptionJsonValue(CommonConstants.Option.FIXMEDINS_NAME); - String fixmedinsCode = loginUser.getOptionJsonValue(CommonConstants.Option.FIXMEDINS_CODE); - - map.put("fixmedinsName", fixmedinsName);// 医院名称 - map.put("fixmedinsCode", fixmedinsCode);// 医院编号 - - return map; + return chargeBillQueryService.getDetail(paymentId); } - /** - * 农大版本 - * - * @param - * @return - */ @Override public Map getTotal(String startTime, String endTime, Long entererId, String contractNo) { - // 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); - - // 查询所有的支付 - 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())) { - // log.info("//****************************"); - // log.info(JsonUtils.toJson(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()).notIn(PaymentRecDetail::getPayEnum, - YbPayment.SUPPLEMENTARY_INSURANCE.getValue(), YbPayment.SUPPLEMENTARY_INSURANCE.getValue(), - YbPayment.FULAMT_OWNPAY_AMT.getValue(), YbPayment.OVERLMT_SELFPAY.getValue(), - YbPayment.PRESELFPAY_AMT.getValue(), YbPayment.INSCP_SCP_AMT.getValue(), - YbPayment.ACT_PAY_DEDC.getValue(), YbPayment.POOL_PROP_SELFPAY.getValue(), - YbPayment.BALC.getValue(), YbPayment.BIRTH_FUND.getValue(), YbPayment.RETIREE_MEDICAL.getValue(), - YbPayment.MEDICAL_ASSISTANCE.getValue(), YbPayment.URBAN_SERIOUS_ILLNESS.getValue(), - YbPayment.URBAN_BASIC_MEDICAL.getValue(), YbPayment.GOVERNMENT_SUBSIDY.getValue(), - YbPayment.ACCIDENT_INSURANCE.getValue(), YbPayment.CARE_INSURANCE.getValue(), - YbPayment.FINANCIAL_FUND.getValue(), YbPayment.HOSPITAL_ADVANCE.getValue(), - YbPayment.SUPPLEMENTARY_INSURANCE.getValue(), - YbPayment.BASIC_MEDICAL_INSURANCE_FOR_URBAN_EMPLOYEES.getValue(), YbPayment.E_WALLET.getValue(), - YbPayment.HEALTHCARE_PREPAYMENT.getValue())); - if (paymentDetails.isEmpty()) { - return getMap(map); - } - Map> paymentDetailsKV - = paymentDetails.stream().collect(Collectors.groupingBy(PaymentRecDetail::getReconciliationId)); - // 声明变量,符合要求的付款记录 - Collection PaymentReconciliationList; - List accountList = new ArrayList<>(); - if (!StringUtils.isEmpty(contractNo)) { - // 查询账户信息用来区分省市医保 - List accountIds - = paymentDetails.stream().map(PaymentRecDetail::getAccountId).collect(Collectors.toList()); - if (accountIds.isEmpty()) { - throw new ServiceException("查询账户信息为空"); - } - accountList = iAccountService.list(new LambdaQueryWrapper().in(Account::getId, accountIds)); - - // 留下符合条件的付款记录 - Map paymentMap = new HashMap<>(); - for (PaymentRecDetail paymentDetail : paymentDetails) { - - Optional first - = accountList.stream().filter(x -> x.getId().equals(paymentDetail.getAccountId())).findFirst(); - // 账户不符合要求的筛出掉 - if (first.isEmpty() || !first.get().getContractNo().equals(contractNo)) { - continue; - } - // 付款记录里匹配不上筛出掉 - Optional first1 = paymentReconciliationList.stream() - .filter(x -> x.getId().equals(paymentDetail.getReconciliationId())).findFirst(); - if (first1.isEmpty()) { - continue; - } - - paymentMap.put(paymentDetail.getReconciliationId(), first1.get()); - } - // 符合省市医保或自费要求的付款实体集合 - PaymentReconciliationList = paymentMap.values(); - } else { - // 时间段内的全部付款记录 - PaymentReconciliationList = paymentReconciliationList; - } - if (PaymentReconciliationList.isEmpty()) { - return getMap(map); - } - // 查询所有的收费项 - 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); - } - } - - // for (Long chargeItemId : chargeItemIds) { - // log.info(chargeItemId); - // log.info(","); - // } - List chargeItemList = chargeItemService.list(new LambdaQueryWrapper() - .in(ChargeItem::getId, chargeItemIds).eq(ChargeItem::getDeleteFlag, DelFlag.NO.getCode())); - if (paymentDetails.isEmpty()) { - throw new ServiceException("数据异常,该时间段内未查询到收费项"); - } - - // for (ChargeItem chargeItem : chargeItemList) { - // if("adm_healthcare_service".equals(chargeItem.getServiceTable())){ - // log.info("//****************************"); - // log.info(JsonUtils.toJson(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 clinicSettle = new ArrayList<>(); - if (!settleIds.isEmpty()) { - clinicSettle = iClinicSettleService.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;// 基金支总额 - // 农大版本只查询收款员,日期,现金多少钱,挂号费多少钱 - for (PaymentRecDetail paymentDetail : paymentDetails) { - - if (!StringUtils.isEmpty(contractNo)) { - Optional first - = accountList.stream().filter(x -> x.getId().equals(paymentDetail.getAccountId())).findFirst(); - if (first.isEmpty() || !first.get().getContractNo().equals(contractNo)) { - continue; - } - } - - if (YbPayment.SELF_CASH_PAY.getValue().equals(paymentDetail.getPayEnum())) { - cashSum = cashSum.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 - } - - // 处理退费单 - 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); - } - } - if (!returnPaymentList.isEmpty()) { - List returnIds - = returnPaymentList.stream().map(PaymentReconciliation::getId).collect(Collectors.toList()); - - 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()); - 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().getOptionJsonValue(CommonConstants.Option.YB_SWITCH); - var loginUser = SecurityUtils.getLoginUser(); - String fixmedinsName = loginUser.getOptionJsonValue(CommonConstants.Option.FIXMEDINS_NAME); - String fixmedinsCode = loginUser.getOptionJsonValue(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; + return chargeBillCalculationService.getTotal(startTime, endTime, entererId, contractNo); } - /** - * 长大版本(门诊) 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())) { - // log.info("//****************************"); - // log.info(JsonUtils.toJson(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) { - // log.info("//////**********************///////"); - // log.info("payment:" + paymentReconciliation.getId()); - // log.info("paymentAmount:" + paymentReconciliation.getTenderedAmount()); - // log.info("payment应收:" + paymentReconciliation.getDisplayAmount()); - // log.info("//////**********************///////"); - // } - // 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()); - // log.info("收费项:" + chargeItemBaseInfoById.getTotalPrice()); - // } - // log.info("付款:" + paymentReconciliation.getTenderedAmount()); - // if (bigDecimal1.compareTo(paymentReconciliation.getTenderedAmount()) != 0) { - // log.info("//////**********************///////"); - // log.info("payment:" + paymentReconciliation.getId()); - // log.info("paymentAmount:" + paymentReconciliation.getTenderedAmount()); - // log.info("payment应收:" + paymentReconciliation.getDisplayAmount()); - // log.info("//////**********************///////"); - // } - // } - // 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() - .filter(e -> e.getContractNo() != null && !e.getContractNo().isEmpty()) - .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())){ - // log.info("//****************************"); - // log.info(JsonUtils.toJson(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() - .filter(e -> e.getBusNo() != null && !e.getBusNo().isEmpty()) - .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){ - // log.info(chargeItem.getId()); - // log.info(JsonUtils.toJson(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()); - List paymentRecDetails - = paymentDetailsKV.get(paymentReconciliation.getId()); - for (PaymentRecDetailAccountResult 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("tcSum", tcSum);// 基本统筹 - // map.put("zhSum", zhSum);// 账户支付 - // map.put("fundSum", fundSum);// 基金支付总额 - map.put("ybCashSum", YbCashSum);// 医保现金 - map.put("selfCashSum", SelfCashSum);// 自费现金 - - // 不同医院收费项统计内容不定,下面统计分两个for循环部分统计,一部分按照医保分类统计,一个是按照财务类型的字典去分类 - for (ChargeItem chargeItem : chargeItemList) { - - if (!chargeItem.getStatusEnum().equals(ChargeItemStatus.BILLED.getValue()) - && !chargeItem.getStatusEnum().equals(ChargeItemStatus.REFUNDING.getValue())) { - continue; - } - - Long definitionId = chargeItem.getDefinitionId(); - // if(chargeItemDefKV.get(definitionId)==null){ - // log.info(chargeItem.getId()); - // log.info(JsonUtils.toJson(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; - } - } - 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().getOptionJsonValue(CommonConstants.Option.YB_SWITCH); - var loginUser = SecurityUtils.getLoginUser(); - String fixmedinsName = loginUser.getOptionJsonValue(CommonConstants.Option.FIXMEDINS_NAME); - String fixmedinsCode = loginUser.getOptionJsonValue(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); - } - - // 超本时间段的退费单统计 - if (!beforeChargeItemDefinitions.isEmpty() && !beforeChargeItemList.isEmpty()) { - Map> beforeChargeItemDefMapByTypeCode - = beforeChargeItemDefinitions.stream().collect(Collectors.groupingBy(ChargeItemDefinition::getTypeCode)); - Map> beforeChargeItemMapByDefinitionId - = beforeChargeItemList.stream().collect(Collectors.groupingBy(ChargeItem::getDefinitionId)); - for (Map.Entry> longListEntry : beforeChargeItemDefMapByTypeCode - .entrySet()) { - BigDecimal bigDecimal = map.get(longListEntry.getKey()) == null ? BigDecimal.ZERO - : new BigDecimal(String.valueOf(map.get(longListEntry.getKey()))); - for (ChargeItemDefinition chargeItemDefinition : longListEntry.getValue()) { - List chargeItems = beforeChargeItemMapByDefinitionId.get(chargeItemDefinition.getId()); - for (ChargeItem chargeItem : chargeItems) { - if (!chargeItem.getStatusEnum().equals(ChargeItemStatus.REFUNDED.getValue())) { - continue; - } - // chargeItem.setTotalPrice(new BigDecimal("-1").multiply(chargeItem.getTotalPrice())); - bigDecimal = bigDecimal.add(chargeItem.getTotalPrice()); - } - } - map.put(longListEntry.getKey(), bigDecimal); - } - } - - // 医保人次自费人次计算 - List list = iEncounterService.getEncounterInfoByTime(startDate, endDate); - Map> encounterAccountDtoMapByContract - = list.stream() - .filter(e -> e.getContractNo() != null && !e.getContractNo().isEmpty()) - .collect(Collectors.groupingBy(EncounterAccountDto::getContractNo)); - for (Map.Entry> stringListEntry : encounterAccountDtoMapByContract - .entrySet()) { - String key = stringListEntry.getKey(); - map.put(key + "reg", stringListEntry.getValue().size()); - } - - return map; + return chargeBillCalculationService.getTotalCcu(startTime, endTime, entererId); } - /** - * 长大门诊日结单(最终版) ps:小范围区间内通用版本,需要时间检验 - * - * @param startTime 开始时间 - * @param endTime 结束时间 - * @param entererId 参与人id - * @return 参数 - */ + @Override public Map getTotalCommen(String startTime, String endTime, Long entererId, String contractNo) { - - // 声明变量 处理时间 - Map map = new HashMap<>(); - Date startDate = DateUtils.parseDate(startTime); - Date endDate = DateUtils.parseDate(endTime); - - // 查询所有的门诊支付记录 ,大概的情况如下 - // startDate endDate - // | æ­£ è´Ÿ | a.该情况下的chargeItem 状态为8 不用统计 - // | æ­£ | b.该情况的chargeItem 状态为5 计入统计 做加法 - // æ­£ | è´Ÿ | c.该情况的chargeItem 状态为8 计入统计 做减法 - // | æ­£ | è´Ÿ d.该情况的chargeItem 状态为8 计入统计 做加法 - // | æ­£ è´Ÿ | è´Ÿ e.该情况的chargeItem 状态8或5 区间内正负的chargeItem差值状态为5 计入统计 做加法 - // | æ­£ | è´Ÿ è´Ÿ f.该情况下的chargeItem 状态为8或5 全部计入统计 做加法 - // æ­£ è´Ÿ | è´Ÿ | g.该情况的chargeItem 状态8或5 è´Ÿçš„chargeItem状态为8 计入统计 做减法 - 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); - List paymentReconciliationList = paymentReconciliationService - .getPaymentAccountContract(startTime, endTime, entererId, contractNo, PaymentStatus.SUCCESS.getValue(), - PaymentStatus.REFUND_ALL.getValue(), PaymentKind.OUTPATIENT_CLINIC.getValue()); - - if (paymentReconciliationList.isEmpty()) { - return getMap(map); - } - - BigDecimal amount = BigDecimal.ZERO;// 应收金额 - for (PaymentReconciliationAccountDel paymentReconciliationAccountDel : paymentReconciliationList) { - amount = amount.add(paymentReconciliationAccountDel.getTenderedAmount()); - } - map.put("amount", amount);// 应收金额 - - // 查询所有的支付详情(业务注释:收集并统计不同支付渠道支付的费用) - List paymentIdList - = paymentReconciliationList.stream().map(PaymentReconciliationAccountDel::getId).collect(Collectors.toList()); - List PaymentRecDetailAccountResultList - = paymentRecDetailService.getListByReconciliationIds(paymentIdList, PaymentKind.OUTPATIENT_CLINIC.getValue()); - - if (PaymentRecDetailAccountResultList.isEmpty()) { - return getMap(map); - } - - // 支付详情根据主键分组 - Map> paymentDetailsKV = PaymentRecDetailAccountResultList.stream() - .collect(Collectors.groupingBy(PaymentRecDetailAccountResult::getReconciliationId)); - - // 根据省市医保分组 - Map> paymentDetailsMapByContract = PaymentRecDetailAccountResultList - .stream() - .filter(e -> e.getContractNo() != null && !e.getContractNo().isEmpty()) - .collect(Collectors.groupingBy(PaymentRecDetailAccountResult::getContractNo)); - - 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 SelfCashSum = BigDecimal.ZERO;// 自费现金总额 - BigDecimal YbCashSum = BigDecimal.ZERO;// 医保现金总额 - BigDecimal discountSum = BigDecimal.ZERO;// 优惠金额 - // 长大版本要显示出来省市医保的区别 - List redisContractList = iContractService.getRedisContractList(); - Map> contractMapByBusNo - = redisContractList.stream() - .filter(e -> e.getBusNo() != null && !e.getBusNo().isEmpty()) - .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 (YbPayment.DISCOUNT_PAY.getValue().equals(paymentRecDetailAccountResult.getPayEnum())) { - discountSum = discountSum.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); - } - } - map.put("ybCashSum", YbCashSum);// 医保现金 - // map.put("selfCashSum", SelfCashSum);// 自费现金 - map.put("rmbCashSum", rmbCashSum);// 自费现金纯现金 - map.put("vxCashSum", vxCashSum);// 自费现金vx - map.put("uniCashSum", uniCashSum);// 自费现金银联 - map.put("aliCashSum", aliCashSum);// 自费现金ali - map.put("discountSum", discountSum);// 优惠金额 - - // 将所有的payment分组进行单独处理(业务注释:处理不同财务分类的金额,如西药费中药费等) - List paymentList = new ArrayList<>(); - List returnList = new ArrayList<>(); - // List partReturnList = new ArrayList<>(); - - for (PaymentReconciliationAccountDel paymentReconciliation : paymentReconciliationList) { - if (PaymentStatus.REFUND_ALL.getValue().equals(paymentReconciliation.getStatusEnum())) { - returnList.add(paymentReconciliation); - } else if (PaymentStatus.REFUND_PART.getValue().equals(paymentReconciliation.getStatusEnum())) { - // partReturnList.add(paymentReconciliation); - paymentList.add(paymentReconciliation); - } else { - paymentList.add(paymentReconciliation); - } - } - - Map> returnPaymentMapByRelationId = new HashMap<>(); - if (!returnList.isEmpty()) { - returnPaymentMapByRelationId - = returnList.stream().collect(Collectors.groupingBy(PaymentReconciliationAccountDel::getRelationId)); - } - - List addChargeItemIds = new ArrayList<>(); - List subChargeItemIds = new ArrayList<>(); - for (PaymentReconciliationAccountDel paymentReconciliation : paymentList) { - List paymentReconciliations - = returnPaymentMapByRelationId.get(paymentReconciliation.getId()); - if (paymentReconciliations != null && !paymentReconciliations.isEmpty()) { - // 情况a - if (PaymentStatus.SUCCESS.getValue().equals(paymentReconciliation.getStatusEnum())) { - returnPaymentMapByRelationId.remove(paymentReconciliation.getId()); - continue; - } - // 情况 e - List strings = Arrays.asList(paymentReconciliation.getChargeItemIds().split(",")); - List split = new ArrayList<>(); - for (PaymentReconciliationAccountDel reconciliation : paymentReconciliations) { - split.addAll(Arrays.asList(reconciliation.getChargeItemIds().split(","))); - } - strings.removeAll(split); - addChargeItemIds.addAll(strings); - returnPaymentMapByRelationId.remove(paymentReconciliation.getId()); - } else { - // 情况 b - // 情况 d - // 情况 f - addChargeItemIds.addAll(Arrays.asList(paymentReconciliation.getChargeItemIds().split(","))); - } - } - - // 情况 c - // 情况 g - for (Map.Entry> longListEntry : returnPaymentMapByRelationId - .entrySet()) { - for (PaymentReconciliationAccountDel paymentReconciliation : longListEntry.getValue()) { - subChargeItemIds.addAll(Arrays.asList(paymentReconciliation.getChargeItemIds().split(","))); - } - } - - // 查询所有的收费项 - List chargeItemIdStrs = new ArrayList<>(); - chargeItemIdStrs.addAll(addChargeItemIds); - chargeItemIdStrs.addAll(subChargeItemIds); - List chargeItemIds = new ArrayList<>(); - for (String chargeItemIdStr : chargeItemIdStrs) { - String[] strings = chargeItemIdStr.split(","); - for (String string : strings) { - Long id = Long.parseLong(string); - chargeItemIds.add(id); - } - } - - // 查不到收费项的情况下不统计了 - if (chargeItemIds.isEmpty()) { - return getMap(map); - } - List chargeItemDefInfoByIds = chargeItemService.getChargeItemDefInfoByIds(chargeItemIds); - if (chargeItemDefInfoByIds.isEmpty()) { - throw new ServiceException("数据异常,该时间段内未查询到收费项"); - } - Map> chargeItemDefInfoKVById - = chargeItemDefInfoByIds.stream().collect(Collectors.groupingBy(ChargeItemDefInfo::getId)); - - // 省名变量 - BigDecimal bedFee = BigDecimal.ZERO;// 床位费 - BigDecimal diagnosticFee = BigDecimal.ZERO;// 诊察费 - BigDecimal checkFee = BigDecimal.ZERO;// 检查费 - BigDecimal diagnosticTestFee = BigDecimal.ZERO;// 化验费 - BigDecimal outDiagnosticTestFee = BigDecimal.ZERO;// 外送化验费 同一新增 - BigDecimal medicalExpenseFee = BigDecimal.ZERO;// 治疗费 - BigDecimal operationFee = BigDecimal.ZERO;// 手术费 - BigDecimal nursingFee = BigDecimal.ZERO;// 护理费 - BigDecimal sanitaryMaterialsFee = BigDecimal.ZERO;// 卫生材料费 - BigDecimal westMedicine = BigDecimal.ZERO;// 西药费 - BigDecimal chineseMedicineSlicesFee = BigDecimal.ZERO;// 中药饮片费 - BigDecimal chineseMedicineFee = BigDecimal.ZERO;// 中成药费 - BigDecimal generalConsultationFee = BigDecimal.ZERO;// 一般诊疗费 - BigDecimal registrationFee = BigDecimal.ZERO;// 挂号费 - BigDecimal otherFee = BigDecimal.ZERO;// 其他费用 - BigDecimal sum = BigDecimal.ZERO;// 合计费用 - - ChargeItemDefInfo chargeItem; - for (String addChargeItemId : addChargeItemIds) { - List chargeItems = chargeItemDefInfoKVById.get(Long.parseLong(addChargeItemId)); - if (chargeItems == null || chargeItems.isEmpty()) { - continue; - } - chargeItem = chargeItems.get(0); - YbMedChrgItmType medChrgItmType = YbMedChrgItmType.getByCode(Integer.parseInt(chargeItem.getYbType())); - - switch (medChrgItmType) { - case BED_FEE: - bedFee = bedFee.add(chargeItem.getTotalPrice()); - break; - case DIAGNOSTIC_FEE: - diagnosticFee = diagnosticFee.add(chargeItem.getTotalPrice()); - break; - case CHECK_FEE: - checkFee = checkFee.add(chargeItem.getTotalPrice()); - break; - case DIAGNOSTIC_TEST_FEE: - if (DictUtils.getDictValue("fin_type_code", "化验").equals(chargeItem.getTypeCode())) { - diagnosticTestFee = diagnosticTestFee.add(chargeItem.getTotalPrice()); - } else if (DictUtils.getDictValue("fin_type_code", "外送化验费").equals(chargeItem.getTypeCode())) { - outDiagnosticTestFee = outDiagnosticTestFee.add(chargeItem.getTotalPrice()); - } else { - diagnosticTestFee = diagnosticTestFee.add(chargeItem.getTotalPrice()); - } - break; - case MEDICAL_EXPENSE_FEE: - medicalExpenseFee = medicalExpenseFee.add(chargeItem.getTotalPrice()); - break; - case OPERATION_FEE: - operationFee = operationFee.add(chargeItem.getTotalPrice()); - break; - case NURSING_FEE: - nursingFee = nursingFee.add(chargeItem.getTotalPrice()); - break; - case SANITARY_MATERIALS_FEE: - sanitaryMaterialsFee = sanitaryMaterialsFee.add(chargeItem.getTotalPrice()); - break; - case WEST_MEDICINE: - westMedicine = westMedicine.add(chargeItem.getTotalPrice()); - break; - case CHINESE_MEDICINE_SLICES_FEE: - chineseMedicineSlicesFee = chineseMedicineSlicesFee.add(chargeItem.getTotalPrice()); - break; - case CHINESE_MEDICINE_FEE: - chineseMedicineFee = chineseMedicineFee.add(chargeItem.getTotalPrice()); - break; - case GENERAL_CONSULTATION_FEE: - generalConsultationFee = generalConsultationFee.add(chargeItem.getTotalPrice()); - break; - case REGISTRATION_FEE: - registrationFee = registrationFee.add(chargeItem.getTotalPrice()); - break; - default: - otherFee = otherFee.add(chargeItem.getTotalPrice()); - break; - } - } - - for (String subChargeItemId : subChargeItemIds) { - List chargeItems = chargeItemDefInfoKVById.get(Long.parseLong(subChargeItemId)); - if (chargeItems == null || chargeItems.isEmpty()) { - continue; - } - chargeItem = chargeItems.get(0); - - YbMedChrgItmType medChrgItmType = YbMedChrgItmType.getByCode(Integer.parseInt(chargeItem.getYbType())); - - switch (medChrgItmType) { - case BED_FEE: - bedFee = bedFee.subtract(chargeItem.getTotalPrice()); - break; - case DIAGNOSTIC_FEE: - diagnosticFee = diagnosticFee.subtract(chargeItem.getTotalPrice()); - break; - case CHECK_FEE: - checkFee = checkFee.subtract(chargeItem.getTotalPrice()); - break; - case DIAGNOSTIC_TEST_FEE: - if (DictUtils.getDictValue("fin_type_code", "化验").equals(chargeItem.getTypeCode())) { - diagnosticTestFee = diagnosticTestFee.add(chargeItem.getTotalPrice()); - } else if (DictUtils.getDictValue("fin_type_code", "外送化验费").equals(chargeItem.getTypeCode())) { - outDiagnosticTestFee = outDiagnosticTestFee.add(chargeItem.getTotalPrice()); - } else { - // å…¶ä»–typeCode默认归为普通化验费 - diagnosticTestFee = diagnosticTestFee.add(chargeItem.getTotalPrice()); - } - break; - case MEDICAL_EXPENSE_FEE: - medicalExpenseFee = medicalExpenseFee.subtract(chargeItem.getTotalPrice()); - break; - case OPERATION_FEE: - operationFee = operationFee.subtract(chargeItem.getTotalPrice()); - break; - case NURSING_FEE: - nursingFee = nursingFee.subtract(chargeItem.getTotalPrice()); - break; - case SANITARY_MATERIALS_FEE: - sanitaryMaterialsFee = sanitaryMaterialsFee.subtract(chargeItem.getTotalPrice()); - break; - case WEST_MEDICINE: - westMedicine = westMedicine.subtract(chargeItem.getTotalPrice()); - break; - case CHINESE_MEDICINE_SLICES_FEE: - chineseMedicineSlicesFee = chineseMedicineSlicesFee.subtract(chargeItem.getTotalPrice()); - break; - case CHINESE_MEDICINE_FEE: - chineseMedicineFee = chineseMedicineFee.subtract(chargeItem.getTotalPrice()); - break; - case GENERAL_CONSULTATION_FEE: - generalConsultationFee = generalConsultationFee.subtract(chargeItem.getTotalPrice()); - break; - case REGISTRATION_FEE: - registrationFee = registrationFee.subtract(chargeItem.getTotalPrice()); - break; - default: - otherFee = otherFee.subtract(chargeItem.getTotalPrice()); - break; - } - } - - map.put("BED_FEE", bedFee);// 床位费 - map.put("DIAGNOSTIC_FEE", diagnosticFee);// 诊察费 - map.put("CHECK_FEE", checkFee);// 检查费 - map.put("DIAGNOSTIC_TEST_FEE", diagnosticTestFee);// 化验费 - map.put("OUT_DIAGNOSTIC_TEST_FEE", outDiagnosticTestFee); - map.put("MEDICAL_EXPENSE_FEE", medicalExpenseFee);// 治疗费 - map.put("OPERATION_FEE", operationFee);// 手术费 - map.put("NURSING_FEE", nursingFee);// 护理费 - map.put("SANITARY_MATERIALS_FEE", sanitaryMaterialsFee);// 卫生材料费 - map.put("WEST_MEDICINE", westMedicine);// 西药费 - map.put("CHINESE_MEDICINE_SLICES_FEE", chineseMedicineSlicesFee);// 中药饮片费 - map.put("CHINESE_MEDICINE_FEE", chineseMedicineFee);// 中成药费 - map.put("GENERAL_CONSULTATION_FEE", generalConsultationFee);// 一般诊疗费 - map.put("REGISTRATION_FEE", registrationFee);// 挂号费 - map.put("OTHER_FEE", otherFee);// 其他费用 - sum = bedFee.add(diagnosticFee).add(checkFee).add(diagnosticTestFee).add(outDiagnosticTestFee).add(medicalExpenseFee).add(operationFee) - .add(nursingFee).add(sanitaryMaterialsFee).add(westMedicine).add(chineseMedicineFee).add( - chineseMedicineSlicesFee).add(generalConsultationFee).add(registrationFee).add(otherFee); - map.put("SUM", sum);// 合计费用 - - Map> chargeItemDefKVByTypeCode = chargeItemDefInfoByIds.stream() - .collect(Collectors.groupingBy( - item -> item.getTypeCode() != null ? item.getTypeCode() : "UNKNOWN" - )); - for (Map.Entry> longListEntry : chargeItemDefKVByTypeCode.entrySet()) { - String key = longListEntry.getKey(); - BigDecimal bigDecimal = BigDecimal.ZERO; - for (ChargeItemDefInfo itemDefinition : longListEntry.getValue()) { - if (subChargeItemIds.contains(itemDefinition.getId().toString())) { - bigDecimal = bigDecimal.subtract(itemDefinition.getTotalPrice()); - } else { - bigDecimal = bigDecimal.add(itemDefinition.getTotalPrice()); - } - } - map.put(key, bigDecimal); - } - - // 体检人次(长大专用) - List chargeItemDefInfos = chargeItemDefKVByTypeCode.get("9999"); - BigDecimal peisCnt = BigDecimal.ZERO; - if (chargeItemDefInfos != null) { - for (ChargeItemDefInfo chargeItemDefInfo : chargeItemDefInfos) { - peisCnt = peisCnt.add(chargeItemDefInfo.getQuantityValue()); - } - } - map.put("peisCnt", peisCnt);// 体检人次 - - // 处理退费单 - List returnBillVOList = new ArrayList<>(); - ReturnBillVO returnBillVO; - - if (!returnList.isEmpty()) { - List returnIds - = returnList.stream().map(PaymentReconciliationAccountDel::getId).collect(Collectors.toList()); - // 查原付款单子 - List relationIdList - = returnList.stream().map(PaymentReconciliationAccountDel::getRelationId).collect(Collectors.toList()); - if (relationIdList.isEmpty() || returnList.size() != relationIdList.size()) { - throw new ServiceException("数据异常,存在无法关联到原单的退款单,请联系工程师"); - } - - 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 (PaymentReconciliationAccountDel paymentReconciliation : returnList) { - returnBillVO = new ReturnBillVO(); - returnBillVO.setTotalAmount(paymentReconciliation.getTenderedAmount()); - List paymentRecDetails - = paymentDetailsKV.get(paymentReconciliation.getId()); - for (PaymentRecDetailAccountResult 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()); - returnBillVOList.add(returnBillVO); - } - map.put("returnList", returnBillVOList);// 退费单 - } - } - - // map.put("tcSum", tcSum);// 基本统筹 - // map.put("zhSum", zhSum);// 账户支付 - // map.put("fundSum", fundSum);// 基金支付总额 - // 医保人次自费人次计算 - List list = iEncounterService.getEncounterInfoByTime(startDate, endDate); - Map> encounterAccountDtoMapByContract - = list.stream() - .filter(e -> e.getContractNo() != null && !e.getContractNo().isEmpty()) - .collect(Collectors.groupingBy(EncounterAccountDto::getContractNo)); - for (Map.Entry> stringListEntry : encounterAccountDtoMapByContract - .entrySet()) { - String key = stringListEntry.getKey(); - map.put(key + "reg", stringListEntry.getValue().size()); - } -// -// //2025.12.9 调试对账用代码 -// //测试代码 -// for (PaymentReconciliationAccountDel paymentReconciliationAccountDel : paymentReconciliationList) { -// //查询到所有的paymentDetail -// List paymentRecDetailAccountResults = paymentDetailsKV.get(paymentReconciliationAccountDel.getId()); -// //求值 -// BigDecimal paymentAmount = BigDecimal.ZERO; -// BigDecimal discountAmount = BigDecimal.ZERO; -// BigDecimal chargeAmount = BigDecimal.ZERO; -// BigDecimal chargeDiscountAmount = BigDecimal.ZERO; -// -// for (PaymentRecDetailAccountResult paymentRecDetailAccountResult : paymentRecDetailAccountResults) { -// -// if (paymentRecDetailAccountResult.getPayEnum().equals(YbPayment.SELF_CASH_VX_VALUE.getValue())) { -// paymentAmount = paymentAmount.add(paymentRecDetailAccountResult.getAmount()); -// } -// if (paymentRecDetailAccountResult.getPayEnum().equals(YbPayment.SELF_CASH_ALI_VALUE.getValue())) { -// paymentAmount = paymentAmount.add(paymentRecDetailAccountResult.getAmount()); -// } -// if (paymentRecDetailAccountResult.getPayEnum().equals(YbPayment.SELF_CASH_UNION_VALUE.getValue())) { -// paymentAmount = paymentAmount.add(paymentRecDetailAccountResult.getAmount()); -// } -// if (paymentRecDetailAccountResult.getPayEnum().equals(YbPayment.SELF_CASH_VALUE.getValue())) { -// paymentAmount = paymentAmount.add(paymentRecDetailAccountResult.getAmount()); -// } -// if (paymentRecDetailAccountResult.getPayEnum().equals(YbPayment.DISCOUNT_PAY.getValue())) { -// discountAmount = discountAmount.add(paymentRecDetailAccountResult.getAmount()); -// } -// -// } -// -// List collect = Arrays.stream(paymentReconciliationAccountDel.getChargeItemIds().split(",")).map(Long::parseLong) // å°†String转为Long -// .collect(Collectors.toList()); -// -// List chargeItems = chargeItemService.list( -// new LambdaUpdateWrapper().in(ChargeItem::getId, collect) -// .eq(ChargeItem::getDeleteFlag, DelFlag.NO.getCode())); -// -// for (ChargeItem item : chargeItems) { -// -// chargeAmount = chargeAmount.add(item.getTotalPrice()); -// chargeDiscountAmount = chargeDiscountAmount.add(item.getSystemDiscountPrice()==null?item.getTotalPrice():item.getSystemDiscountPrice()); -// -// } -// -// //payment维度的值大于收费项的值 -// if(paymentAmount.add(discountAmount).compareTo(chargeAmount)>0||chargeAmount.compareTo(paymentAmount.add(discountAmount))>0){ -// log.info("总价不对等,提示信息:paymentId:"+paymentReconciliationAccountDel.getId()); -// } -// -// //chargeItem维度折后价格的值大于payment维度的实收 或者 chargeItem维度折后价格的值小于payment维度的实收 -// if(chargeDiscountAmount.compareTo(paymentAmount)>0||paymentAmount.compareTo(chargeDiscountAmount)>0){ -// log.info("折后价格不对等,提示信息:paymentId:"+paymentReconciliationAccountDel.getId()); -// } -// } - - // 同一打折专用处理 - BigDecimal tyBedFee = BigDecimal.ZERO;// 床位费 - BigDecimal tyDiagnosticFee = BigDecimal.ZERO;// 诊察费 - BigDecimal tyCheckFee = BigDecimal.ZERO;// 检查费 - BigDecimal tyDiagnosticTestFee = BigDecimal.ZERO;// 化验费 - BigDecimal tyOutDiagnosticTestFee = BigDecimal.ZERO; // 外送化验费 同一新增 - BigDecimal tyMedicalExpenseFee = BigDecimal.ZERO;// 治疗费 - BigDecimal tyOperationFee = BigDecimal.ZERO;// 手术费 - BigDecimal tyNursingFee = BigDecimal.ZERO;// 护理费 - BigDecimal tySanitaryMaterialsFee = BigDecimal.ZERO;// 卫生材料费 - BigDecimal tyWestMedicine = BigDecimal.ZERO;// 西药费 - BigDecimal tyChineseMedicineSlicesFee = BigDecimal.ZERO;// 中药饮片费 - BigDecimal tyChineseMedicineFee = BigDecimal.ZERO;// 中成药费 - BigDecimal tyGeneralConsultationFee = BigDecimal.ZERO;// 一般诊疗费 - BigDecimal tyRegistrationFee = BigDecimal.ZERO;// 挂号费 - BigDecimal tyOtherFee = BigDecimal.ZERO;// 其他费用 - BigDecimal tySum = BigDecimal.ZERO;// 合计费用 - - for (String addChargeItemId : addChargeItemIds) { - List chargeItems = chargeItemDefInfoKVById.get(Long.parseLong(addChargeItemId)); - if (chargeItems == null || chargeItems.isEmpty()) { - continue; - } - chargeItem = chargeItems.get(0); - YbMedChrgItmType medChrgItmType = YbMedChrgItmType.getByCode(Integer.parseInt(chargeItem.getYbType())); - - switch (medChrgItmType) { - case BED_FEE: - tyBedFee = tyBedFee.add(chargeItem.getSystemDiscountPrice() == null ? chargeItem.getTotalPrice() - : chargeItem.getSystemDiscountPrice()); - break; - case DIAGNOSTIC_FEE: - tyDiagnosticFee = tyDiagnosticFee.add(chargeItem.getSystemDiscountPrice() == null - ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); - break; - case CHECK_FEE: - tyCheckFee = tyCheckFee.add(chargeItem.getSystemDiscountPrice() == null ? chargeItem.getTotalPrice() - : chargeItem.getSystemDiscountPrice()); - break; - case DIAGNOSTIC_TEST_FEE: - BigDecimal discountPrice = chargeItem.getSystemDiscountPrice() == null ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice(); - if (DictUtils.getDictValue("fin_type_code", "化验").equals(chargeItem.getTypeCode())) { - tyDiagnosticTestFee = tyDiagnosticTestFee.add(discountPrice); - } else if (DictUtils.getDictValue("fin_type_code", "外送化验费").equals(chargeItem.getTypeCode())) { - tyOutDiagnosticTestFee = tyOutDiagnosticTestFee.add(discountPrice); - } else { - // å…¶ä»–typeCode默认归为普通化验费 - tyDiagnosticTestFee = tyDiagnosticTestFee.add(discountPrice); - } - break; - case MEDICAL_EXPENSE_FEE: - tyMedicalExpenseFee = tyMedicalExpenseFee.add(chargeItem.getSystemDiscountPrice() == null - ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); - break; - case OPERATION_FEE: - tyOperationFee = tyOperationFee.add(chargeItem.getSystemDiscountPrice() == null - ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); - break; - case NURSING_FEE: - tyNursingFee = tyNursingFee.add(chargeItem.getSystemDiscountPrice() == null - ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); - break; - case SANITARY_MATERIALS_FEE: - tySanitaryMaterialsFee = tySanitaryMaterialsFee.add(chargeItem.getSystemDiscountPrice() == null - ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); - break; - case WEST_MEDICINE: - tyWestMedicine = tyWestMedicine.add(chargeItem.getSystemDiscountPrice() == null - ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); - break; - case CHINESE_MEDICINE_SLICES_FEE: - tyChineseMedicineSlicesFee - = tyChineseMedicineSlicesFee.add(chargeItem.getSystemDiscountPrice() == null - ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); - break; - case CHINESE_MEDICINE_FEE: - tyChineseMedicineFee = tyChineseMedicineFee.add(chargeItem.getSystemDiscountPrice() == null - ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); - break; - case GENERAL_CONSULTATION_FEE: - tyGeneralConsultationFee = tyGeneralConsultationFee.add(chargeItem.getSystemDiscountPrice() == null - ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); - break; - case REGISTRATION_FEE: - tyRegistrationFee = tyRegistrationFee.add(chargeItem.getSystemDiscountPrice() == null - ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); - break; - default: - tyOtherFee = tyOtherFee.add(chargeItem.getSystemDiscountPrice() == null ? chargeItem.getTotalPrice() - : chargeItem.getSystemDiscountPrice()); - break; - } - } - - for (String subChargeItemId : subChargeItemIds) { - List chargeItems = chargeItemDefInfoKVById.get(Long.parseLong(subChargeItemId)); - if (chargeItems == null || chargeItems.isEmpty()) { - continue; - } - chargeItem = chargeItems.get(0); - - YbMedChrgItmType medChrgItmType = YbMedChrgItmType.getByCode(Integer.parseInt(chargeItem.getYbType())); - - switch (medChrgItmType) { - case BED_FEE: - tyBedFee = tyBedFee.subtract(chargeItem.getSystemDiscountPrice() == null - ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); - break; - case DIAGNOSTIC_FEE: - tyDiagnosticFee = tyDiagnosticFee.subtract(chargeItem.getSystemDiscountPrice() == null - ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); - break; - case CHECK_FEE: - tyCheckFee = tyCheckFee.subtract(chargeItem.getSystemDiscountPrice() == null - ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); - break; - case DIAGNOSTIC_TEST_FEE: - BigDecimal discountPriceSub = chargeItem.getSystemDiscountPrice() == null ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice(); - if (DictUtils.getDictValue("fin_type_code", "化验").equals(chargeItem.getTypeCode())) { - tyDiagnosticTestFee = tyDiagnosticTestFee.subtract(discountPriceSub); - } else if (DictUtils.getDictValue("fin_type_code", "外送化验费").equals(chargeItem.getTypeCode())) { - tyOutDiagnosticTestFee = tyOutDiagnosticTestFee.subtract(discountPriceSub); - } else { - // å…¶ä»–typeCode默认归为普通化验费 - tyDiagnosticTestFee = tyDiagnosticTestFee.subtract(discountPriceSub); - } - break; - case MEDICAL_EXPENSE_FEE: - tyMedicalExpenseFee = tyMedicalExpenseFee.subtract(chargeItem.getSystemDiscountPrice() == null - ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); - break; - case OPERATION_FEE: - tyOperationFee = tyOperationFee.subtract(chargeItem.getSystemDiscountPrice() == null - ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); - break; - case NURSING_FEE: - tyNursingFee = tyNursingFee.subtract(chargeItem.getSystemDiscountPrice() == null - ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); - break; - case SANITARY_MATERIALS_FEE: - tySanitaryMaterialsFee = tySanitaryMaterialsFee.subtract(chargeItem.getSystemDiscountPrice() == null - ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); - break; - case WEST_MEDICINE: - tyWestMedicine = tyWestMedicine.subtract(chargeItem.getSystemDiscountPrice() == null - ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); - break; - case CHINESE_MEDICINE_SLICES_FEE: - tyChineseMedicineSlicesFee - = tyChineseMedicineSlicesFee.subtract(chargeItem.getSystemDiscountPrice() == null - ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); - break; - case CHINESE_MEDICINE_FEE: - tyChineseMedicineFee = tyChineseMedicineFee.subtract(chargeItem.getSystemDiscountPrice() == null - ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); - break; - case GENERAL_CONSULTATION_FEE: - tyGeneralConsultationFee - = tyGeneralConsultationFee.subtract(chargeItem.getSystemDiscountPrice() == null - ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); - break; - case REGISTRATION_FEE: - tyRegistrationFee = tyRegistrationFee.subtract(chargeItem.getSystemDiscountPrice() == null - ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); - break; - default: - tyOtherFee = tyOtherFee.subtract(chargeItem.getSystemDiscountPrice() == null - ? chargeItem.getTotalPrice() : chargeItem.getSystemDiscountPrice()); - break; - } - } - - map.put("TY_BED_FEE", tyBedFee);// 床位费 - map.put("TY_DIAGNOSTIC_FEE", tyDiagnosticFee);// 诊察费 - map.put("TY_CHECK_FEE", tyCheckFee);// 检查费 - map.put("TY_DIAGNOSTIC_TEST_FEE", tyDiagnosticTestFee);// 化验费 - map.put("TY_OUT_DIAGNOSTIC_TEST_FEE", tyOutDiagnosticTestFee); - map.put("TY_MEDICAL_EXPENSE_FEE", tyMedicalExpenseFee);// 治疗费 - map.put("TY_OPERATION_FEE", tyOperationFee);// 手术费 - map.put("TY_NURSING_FEE", tyNursingFee);// 护理费 - map.put("TY_SANITARY_MATERIALS_FEE", tySanitaryMaterialsFee);// 卫生材料费 - map.put("TY_WEST_MEDICINE", tyWestMedicine);// 西药费 - map.put("TY_CHINESE_MEDICINE_SLICES_FEE", tyChineseMedicineSlicesFee);// 中药饮片费 - map.put("TY_CHINESE_MEDICINE_FEE", tyChineseMedicineFee);// 中成药费 - map.put("TY_GENERAL_CONSULTATION_FEE", tyGeneralConsultationFee);// 一般诊疗费 - map.put("TY_REGISTRATION_FEE", tyRegistrationFee);// 挂号费 - map.put("TY_OTHER_FEE", tyOtherFee);// 其他费用 - tySum = tyBedFee.add(tyDiagnosticFee).add(tyCheckFee).add(tyDiagnosticTestFee).add(tyOutDiagnosticTestFee).add(tyMedicalExpenseFee).add( - tyOperationFee).add(tyNursingFee).add(tySanitaryMaterialsFee).add(tyWestMedicine).add( - tyChineseMedicineSlicesFee).add(tyChineseMedicineFee).add(tyGeneralConsultationFee).add(tyRegistrationFee) - .add(tyOtherFee); - map.put("TY_SUM", tySum);// 合计费用 - - return map; + return chargeBillCalculationService.getTotalCommen(startTime, endTime, entererId, contractNo); } - private Map getMap(Map map) { - - var loginUser = SecurityUtils.getLoginUser(); - String fixmedinsName = loginUser.getOptionJsonValue(CommonConstants.Option.FIXMEDINS_NAME); - String fixmedinsCode = loginUser.getOptionJsonValue(CommonConstants.Option.FIXMEDINS_CODE); - - map.put("fixmedinsName", fixmedinsName); - map.put("fixmedinsCode", fixmedinsCode); - - map.put("BED_FEE", BigDecimal.ZERO);// 床位费 - map.put("DIAGNOSTIC_FEE", BigDecimal.ZERO);// 诊察费 - map.put("CHECK_FEE", BigDecimal.ZERO);// 检查费 - map.put("DIAGNOSTIC_TEST_FEE", BigDecimal.ZERO);// 化验费 - map.put("OUT_DIAGNOSTIC_TEST_FEE", BigDecimal.ZERO); - map.put("MEDICAL_EXPENSE_FEE", BigDecimal.ZERO);// 治疗费 - map.put("OPERATION_FEE", BigDecimal.ZERO);// 手术费 - map.put("NURSING_FEE", BigDecimal.ZERO);// 护理费 - map.put("SANITARY_MATERIALS_FEE", BigDecimal.ZERO);// 卫生材料费 - map.put("WEST_MEDICINE", BigDecimal.ZERO);// 西药费 - map.put("CHINESE_MEDICINE_SLICES_FEE", BigDecimal.ZERO);// 中药饮片费 - map.put("CHINESE_MEDICINE_FEE", BigDecimal.ZERO);// 中成药费 - map.put("GENERAL_CONSULTATION_FEE", BigDecimal.ZERO);// 一般诊疗费 - map.put("REGISTRATION_FEE", BigDecimal.ZERO);// 挂号费 - map.put("OTHER_FEE", BigDecimal.ZERO);// 其他费用 - map.put("SUM", BigDecimal.ZERO);// 合计费用 - map.put("ybCashSum", BigDecimal.ZERO);// 医保现金 - map.put("selfCashSum", BigDecimal.ZERO);// 自费现金 - map.put("selfReg", 0); - map.put("ybReg", 0); - - map.put("cashSum", BigDecimal.ZERO);// 现金支付 - map.put("rmbCashSum", BigDecimal.ZERO);// 现金支付 - map.put("vxCashSum", BigDecimal.ZERO);// 现金支付() - map.put("aliCashSum", BigDecimal.ZERO);// 现金支付() - map.put("uniCashSum", BigDecimal.ZERO);// 现金支付() - map.put("tcSum", BigDecimal.ZERO);// 基本统筹 - map.put("zhSum", BigDecimal.ZERO);// 账户支付 - map.put("fundSum", BigDecimal.ZERO);// 基金支付总额 - - return map; - } - - /** - * @param paymentId - * @return - */ @Override public Map getMedicalExpenseCoverageSummary(Long paymentId) { - return null; + return chargeBillCalculationService.getMedicalExpenseCoverageSummary(paymentId); } @Override public Map getChargeItemByOrg(ChargeSummaryDto chargeSummaryDto) { - Map map = new HashMap<>(); - - // SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS"); - Date startDate = DateUtils.parseDate(chargeSummaryDto.getStartTime()); - Date endDate = DateUtils.parseDate(chargeSummaryDto.getEndTime()); - - // 查询所有的支付 - 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()); - - List paymentReconciliationList = paymentReconciliationService.list(queryWrapper); - if (paymentReconciliationList.isEmpty()) { - return null; - } - - List chargeItemIds = paymentReconciliationList.stream().map(PaymentReconciliation::getChargeItemIds) // 获取逗号分隔的字符串字段 - .flatMap(str -> Arrays.stream(str.split(","))) // 拆分字符串并扁平化 - .map(String::trim) // 去除前后空格 - .filter(s -> !s.isEmpty()) // 过滤空字符串 - .map(Long::valueOf) // 转换为Long - .collect(Collectors.toList()); - - List ChargeItemExtendInfoDtoList - = chargeBillMapper.selectChargeItemExtendInfoList(chargeItemIds, chargeSummaryDto.getOrgIdList()); - - Map> chargeItemExtendInfoDtoListGroupByOrgIdMap - = 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); - if (chargeSummaryDto.getOrgIdList() != null && !chargeSummaryDto.getOrgIdList().isEmpty()) { - organizationLambdaQueryWrapper.in(Organization::getId, chargeSummaryDto.getOrgIdList()); - } - List organizationList = iOrganizationService.list(organizationLambdaQueryWrapper); - if (organizationList.isEmpty()) { - throw new ServiceException("未查询到科室信息"); - } - List orgIncomeList = new ArrayList(); - OrgIncomeDto orgIncomeDto; - for (Organization organization : organizationList) { - orgIncomeDto = new OrgIncomeDto(); - orgIncomeDto.setOrgName(organization.getName()); - List chargeItemExtendInfoDtos - = chargeItemExtendInfoDtoListGroupByOrgIdMap.get(organization.getId()); - if (chargeItemExtendInfoDtos == null) { - orgIncomeList.add(orgIncomeDto); - continue; - } - for (ChargeItemExtendInfoDto chargeItemExtendInfoDto : chargeItemExtendInfoDtos) { - // 挂号费单独 未计入应收 - switch (YbMedChrgItmType.getByValue(chargeItemExtendInfoDto.getYbType())) { - case WEST_MEDICINE: - case CHINESE_MEDICINE_SLICES_FEE: - case CHINESE_MEDICINE_FEE: - orgIncomeDto.setAmount(orgIncomeDto.getAmount().add(chargeItemExtendInfoDto.getTotalPrice())); - orgIncomeDto.setMedFee(orgIncomeDto.getMedFee().add(chargeItemExtendInfoDto.getTotalPrice())); - break; - case REGISTRATION_FEE: - orgIncomeDto.setAmount(orgIncomeDto.getAmount().add(chargeItemExtendInfoDto.getTotalPrice())); - orgIncomeDto.setPersonCnt(orgIncomeDto.getPersonCnt() + 1); - orgIncomeDto.setRegistrationFee( - orgIncomeDto.getRegistrationFee().add(chargeItemExtendInfoDto.getTotalPrice())); - break; - case SANITARY_MATERIALS_FEE: - orgIncomeDto.setAmount(orgIncomeDto.getAmount().add(chargeItemExtendInfoDto.getTotalPrice())); - orgIncomeDto - .setDeviceFee(orgIncomeDto.getDeviceFee().add(chargeItemExtendInfoDto.getTotalPrice())); - break; - default: - orgIncomeDto.setAmount(orgIncomeDto.getAmount().add(chargeItemExtendInfoDto.getTotalPrice())); - orgIncomeDto - .setServiceFee(orgIncomeDto.getServiceFee().add(chargeItemExtendInfoDto.getTotalPrice())); - } - } - - orgIncomeList.add(orgIncomeDto); - } - // 住院部分数据tbd - - map.put("clinic", orgIncomeList); - - return map; + return chargeBillCalculationService.getChargeItemByOrg(chargeSummaryDto); } - /** - * 小票信息(农大) - * - * @param paymentId 付款id - * @return 结果 - */ @Override public Map getReceiptDetailsND(Long paymentId) { - - Map map = new HashMap<>(); - // 查询 - PaymentReconciliation paymentReconciliation = paymentReconciliationService.getById(paymentId); - if (paymentReconciliation == null) { - throw new ServiceException("未查询到付款信息"); - } - map.put("paymentId", paymentReconciliation.getPaymentNo());// 结算id - map.put("paymentAmount", paymentReconciliation.getTenderedAmount());// 应收金额 - Practitioner practitioner = iPractitionerService.getById(paymentReconciliation.getEntererId()); - map.put("paymentEmployee", practitioner == null ? "" : practitioner.getName());// 收费员 - map.put("chargeTime", paymentReconciliation.getBillDate());// 收费时间 - Patient patient = iPatientService.getById(paymentReconciliation.getPatientId()); - if (patient == null) { - throw new ServiceException("未查询到患者信息"); - } - map.put("patientName", patient.getName());// 患者姓名 - - map.put("sex", patient.getGenderEnum());// 性别 - map.put("idCardNo", patient.getIdCard());// 身份证号 - map.put("birthDay", patient.getBirthDate());// 出生日期 - - List paymentRecDetails = paymentRecDetailService.list( - new LambdaQueryWrapper().eq(PaymentRecDetail::getReconciliationId, paymentId)); - - if (paymentRecDetails.isEmpty()) { - throw new ServiceException("未查询到付款信息"); - } - map.put("detail", paymentRecDetails);// 支付详细 - - for (PaymentRecDetail paymentRecDetail : paymentRecDetails) { - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.SELF_YB_ZH_PAY.getValue())) { - map.put("ybAccountPay", paymentRecDetail.getAmount());// 医保账户支付 - } - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.BALC.getValue())) { - map.put("ybAccountBalc", paymentRecDetail.getAmount());// 医保账户余额(现) - } - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.YB_FUND_PAY.getValue())) { - map.put("ybFundPay", paymentRecDetail.getAmount());// 基金支付总额 - } - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.YB_TC_FUND_AMOUNT.getValue())) { - map.put("ybTcPay", paymentRecDetail.getAmount());// 统筹支付金额 - } - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.YB_BC_GWY_BZ_VALUE.getValue())) { - map.put("ybGWYPay", paymentRecDetail.getAmount());// 公务员补助 - } - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.OTHER_PAY.getValue())) { - map.put("ybOtherPay", paymentRecDetail.getAmount());// 其他支付 - } - // 下面两个大额理赔有哪个用哪个,无所谓的 - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.YB_BC_DE_BZ_VALUE.getValue())) { - map.put("ybDELPPay", paymentRecDetail.getAmount());// 大额理赔(常规) - } - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.YB_BC_ZG_DE_BZ_VALUE.getValue())) { - map.put("ybDELPPay", paymentRecDetail.getAmount());// 大额理赔(企业) - } - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.E_WALLET.getValue())) { - map.put("ybWallet", paymentRecDetail.getAmount());// 电子钱包 - } - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.SUPPLEMENTARY_INSURANCE.getValue())) { - map.put("ybWallet", paymentRecDetail.getAmount());// 居民大病报销 - } - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.SELF_CASH_VALUE.getValue())) { - map.put("cash", paymentRecDetail.getAmount());// 现金 - } - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.SELF_CASH_VX_VALUE.getValue())) { - map.put("wxCash", paymentRecDetail.getAmount());// 现金(微信) - } - if (Objects.equals(paymentRecDetail.getPayEnum(), YbPayment.SELF_CASH_ALI_VALUE.getValue())) { - map.put("aliCash", paymentRecDetail.getAmount());// 现金(支付宝) - } - } - - Invoice invoice = iInvoiceService.getOne(new LambdaQueryWrapper().eq(Invoice::getReconciliationId, - paymentId).eq(Invoice::getStatusEnum, InvoiceStatus.ISSUED.getValue()).orderByDesc(Invoice::getCreateTime) - .last(YbCommonConstants.sqlConst.LIMIT1)); - if (invoice != null) { - map.put("invoiceNo", invoice.getBillNo());// 支付详细 - map.put("pictureUrl", invoice.getPictureUrl());// 图片 - } - - List chargeItemIds = Arrays.stream(paymentReconciliation.getChargeItemIds().split(",")).map( - Long::parseLong) // 将字符串转换为 Long - .collect(Collectors.toList()); - List chargeItemBaseInfoByIds = chargeItemService.getChargeItemBaseInfoByIds( - chargeItemIds); - - for (ChargeItemBaseInfoDto chargeItemBaseInfoById : chargeItemBaseInfoByIds) { - if (chargeItemBaseInfoById.getDeptName() == null) { - throw new ServiceException("收费项" + chargeItemBaseInfoById.getName() + "无开单科室"); - } - if (chargeItemBaseInfoById.getTypeCode() == null) { - throw new ServiceException("收费项" + chargeItemBaseInfoById.getName() + "无财务分类"); - } - if (!CommonConstants.BusinessName.DEFAULT_CONTRACT_NO.equals(chargeItemBaseInfoById.getContractNo())) { - Object o = map.get(chargeItemBaseInfoById.getContractNo() + "-" + chargeItemBaseInfoById.getTypeCode()); - if (o == null) { - map.put(chargeItemBaseInfoById.getContractNo() + "-" + chargeItemBaseInfoById.getTypeCode(), - chargeItemBaseInfoById.getTotalPrice()); - } else { - BigDecimal bigDecimal = new BigDecimal(String.valueOf(o)); - bigDecimal = bigDecimal.add(chargeItemBaseInfoById.getTotalPrice()); - map.put(chargeItemBaseInfoById.getContractNo() + "-" + chargeItemBaseInfoById.getTypeCode(), - bigDecimal); - } - } else { - // 根据科室的分类来 - Object o = map.get(chargeItemBaseInfoById.getDeptName() + "-" + chargeItemBaseInfoById.getTypeCode()); - if (o == null) { - map.put(chargeItemBaseInfoById.getDeptName() + "-" + chargeItemBaseInfoById.getTypeCode(), - chargeItemBaseInfoById.getTotalPrice()); - } else { - BigDecimal bigDecimal = new BigDecimal(String.valueOf(o)); - bigDecimal = bigDecimal.add(chargeItemBaseInfoById.getTotalPrice()); - map.put(chargeItemBaseInfoById.getDeptName() + "-" + chargeItemBaseInfoById.getTypeCode(), - bigDecimal); - } - } - } - - Encounter encounter = iEncounterService.getById(paymentReconciliation.getEncounterId()); - if (encounter == null) { - throw new ServiceException("未查询到就诊信息"); - } - map.put("classEnum", encounter.getYbClassEnum());// 门诊/住院 - map.put("regNo", encounter.getBusNo());// 门诊号 - - InfoPerson perinfo = iPerinfoService.getOne(new LambdaQueryWrapper().eq(InfoPerson::getCertno, - patient.getIdCard()).eq(InfoPerson::getTenantId, patient.getTenantId()) - .orderByDesc(InfoPerson::getCreateTime).last(YbCommonConstants.sqlConst.LIMIT1)); - if (perinfo != null) { - map.put("personType", perinfo.getInsutype());// 人员类别:职工医保,居民医保等;如果为空显示自费或其他 - map.put("insuplcAdmdvs", perinfo.getInsuplcAdmdvs());// 患者参保地区划 - } - - // 查询主诊断信息 - EncounterDiagnosis encounterDiagnosis = iEncounterDiagnosisService.getOne( - new LambdaQueryWrapper().eq(EncounterDiagnosis::getEncounterId, encounter.getId()).eq( - EncounterDiagnosis::getMaindiseFlag, Whether.YES.getValue()).eq(EncounterDiagnosis::getDeleteFlag, - DelFlag.NO.getCode()).orderByDesc(EncounterDiagnosis::getDiagSrtNo) - .last(YbCommonConstants.sqlConst.LIMIT1)); - - if (encounterDiagnosis != null) { - Condition condition = iConditionService.getById(encounterDiagnosis.getConditionId()); - if (condition != null) { - ConditionDefinition conditionDefinition = iConditionDefinitionService.getOne( - new LambdaQueryWrapper().eq(ConditionDefinition::getId, - condition.getDefinitionId())); - if (conditionDefinition != null) { - map.put("conditionDefinition", conditionDefinition.getName());// 诊断名 - } - } - } - - var loginUser = SecurityUtils.getLoginUser(); - String fixmedinsName = loginUser.getOptionJsonValue(CommonConstants.Option.FIXMEDINS_NAME); - String fixmedinsCode = loginUser.getOptionJsonValue(CommonConstants.Option.FIXMEDINS_CODE); - - map.put("fixmedinsName", fixmedinsName);// 医院名称 - map.put("fixmedinsCode", fixmedinsCode);// 医院编号 - - return map; + return chargeBillQueryService.getReceiptDetailsND(paymentId); } @Override public Map getYbEncounterType(Long encounterId) { - HashMap map = new HashMap<>(); - Encounter encounter = iEncounterService.getById(encounterId); - if (encounter == null) { - throw new ServiceException("未查询到就诊信息"); - } - - Patient patient = iPatientService.getById(encounter.getPatientId()); - if (patient == null) { - throw new ServiceException("未查询到患者信息"); - } - - Account ybAccount = iAccountService.getYbAccount(encounter.getId()); - if (ybAccount == null) { - map.put("insutype", "自费"); - return map; - } - - Contract contract = contractService.getContract(ybAccount.getContractNo()); - if (contract == null) { - throw new ServiceException("未查询到合同信息"); - } - - InfoPerson perinfo = iPerinfoService.getOne(new LambdaQueryWrapper().eq(InfoPerson::getCertno, - patient.getIdCard()).eq(InfoPerson::getTenantId, patient.getTenantId()) - .orderByDesc(InfoPerson::getCreateTime).last(YbCommonConstants.sqlConst.LIMIT1)); - if (perinfo != null) { - YbMdcsType byCode = YbMdcsType.getByCode(perinfo.getInsutype()); - map.put("insutype", contract.getBusNo() + "-" + byCode.getInfo()); - return map; - } - map.put("insutype", "自费"); - return map; + return chargeBillQueryService.getYbEncounterType(encounterId); } @Override public Map updateChargeItemTotalPrice() { - - List paymentRecDetails = paymentRecDetailService.list( - new LambdaQueryWrapper().eq(PaymentRecDetail::getDeleteFlag, DelFlag.NO.getCode()) - .eq(PaymentRecDetail::getPayEnum, 220500)); - - List paymentIdList = paymentRecDetails.stream().map(PaymentRecDetail::getReconciliationId).collect( - Collectors.toList()); - - HashMap hashMap = new HashMap<>(); - List paymentList1 = new ArrayList<>(); - List paymentList2 = new ArrayList<>(); - List paymentList3 = new ArrayList<>(); - - // List list = paymentReconciliationService.list(new - // LambdaQueryWrapper().eq(PaymentReconciliation::getDeleteFlag, - // DelFlag.NO.getCode()).eq(PaymentReconciliation::getStatusEnum, - // PaymentStatus.SUCCESS.getValue()).in(PaymentReconciliation::getId,paymentIdList)); - List list = paymentReconciliationService.list( - new LambdaQueryWrapper().eq(PaymentReconciliation::getDeleteFlag, - DelFlag.NO.getCode()).eq(PaymentReconciliation::getStatusEnum, PaymentStatus.SUCCESS.getValue()) - .between(PaymentReconciliation::getBillDate, Date.from(LocalDateTime.parse("2025-12-01 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")).atZone(ZoneId.systemDefault()).toInstant()), - Date.from(LocalDateTime.parse("2025-12-31 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")).atZone(ZoneId.systemDefault()).toInstant()))); - - for (PaymentReconciliation paymentReconciliation : list) { - - BigDecimal a = BigDecimal.ZERO;// 药品固定价格 - BigDecimal b = BigDecimal.ZERO;// 实付金额与药品金额差值即待分配金额 - BigDecimal c = BigDecimal.ZERO;// 诊疗检查等项目的合计金额 - BigDecimal d = BigDecimal.ZERO;// 实际交款金额 - BigDecimal e = BigDecimal.ZERO;// 折扣金额 - BigDecimal f = BigDecimal.ZERO;// 应收金额与药品金额差值即应收待分配金额 - - List paymentRecDetailList = paymentRecDetailService.list( - new LambdaQueryWrapper().eq(PaymentRecDetail::getReconciliationId, - paymentReconciliation.getId())); - - PaymentRecDetail paymentRecDetail = null; - for (PaymentRecDetail item : paymentRecDetailList) { - if (item.getPayEnum() == 220500) { - e = e.add(item.getAmount()); - paymentRecDetail = item; - } - if (item.getPayEnum() == 220100) { - d = d.add(item.getAmount()); - } - if (item.getPayEnum() == 220200) { - d = d.add(item.getAmount()); - } - if (item.getPayEnum() == 220300) { - d = d.add(item.getAmount()); - } - if (item.getPayEnum() == 220400) { - d = d.add(item.getAmount()); - } - } - ChargeItem chargeItem; - if (paymentRecDetail == null) { - - List collect = Arrays.stream(paymentReconciliation.getChargeItemIds().split(",")).collect( - Collectors.toList()); - List chargeItemIds = collect.stream().map(Long::parseLong).collect(Collectors.toList()); - - List chargeItemDefInfoByIdList = chargeItemService.getChargeItemDefInfoByIdList( - chargeItemIds); - - for (ChargeItemDefInfo chargeItemDefInfo : chargeItemDefInfoByIdList) { - - chargeItem = new ChargeItem(); - - chargeItem.setId(chargeItemDefInfo.getId()); - chargeItem.setSystemDiscountPrice(chargeItemDefInfo.getTotalPrice()); - - chargeItemService.updateById(chargeItem); - } - - paymentList1.add(paymentReconciliation.getId()); - continue; - } - - List collect = Arrays.stream(paymentReconciliation.getChargeItemIds().split(",")).collect( - Collectors.toList()); - List chargeItemIds = collect.stream().map(Long::parseLong).collect(Collectors.toList()); - - List chargeItemDefInfoByIdList = chargeItemService.getChargeItemDefInfoByIdList( - chargeItemIds); - -// BigDecimal a = BigDecimal.ZERO;// 药品固定价格 -// BigDecimal b = BigDecimal.ZERO;// 实付金额与药品金额差值即待分配金额 -// BigDecimal c = BigDecimal.ZERO;// 诊疗检查等项目的合计金额 -// BigDecimal d = paymentReconciliation.getTenderedAmount().subtract(paymentRecDetail.getAmount());// 实际交款金额 - List newChargeItemList = new ArrayList<>(); - - for (ChargeItemDefInfo chargeItemDefInfo : chargeItemDefInfoByIdList) { - - chargeItem = new ChargeItem(); - - if (chargeItemDefInfo.getYbType().equals(YbMedChrgItmType.WEST_MEDICINE.getValue()) - || chargeItemDefInfo.getYbType().equals(YbMedChrgItmType.CHINESE_MEDICINE_SLICES_FEE.getValue()) - || chargeItemDefInfo.getYbType().equals(YbMedChrgItmType.CHINESE_MEDICINE_FEE.getValue()) - || chargeItemDefInfo.getYbType().equals(YbMedChrgItmType.SANITARY_MATERIALS_FEE.getValue())) { - - // 药品耗材固定价格(中西药中成药耗材) - chargeItem.setId(chargeItemDefInfo.getId()); - chargeItem.setSystemDiscountPrice(chargeItemDefInfo.getTotalPrice()); - // newChargeItemList.add(chargeItem); - - a = a.add(chargeItemDefInfo.getTotalPrice());//药品固定金额 - - chargeItemService.updateById(chargeItem); - - } else { - - // 其他项目统计金额 - c = c.add(chargeItemDefInfo.getTotalPrice()); - - chargeItem.setId(chargeItemDefInfo.getId()); - chargeItem.setTotalPrice(chargeItemDefInfo.getTotalPrice()); - // chargeItem.setSystemDiscountPrice(chargeItemDefInfo.getTotalPrice()); - - newChargeItemList.add(chargeItem); - - } - } - - b = d.subtract(a);//实付的待分配金额 - f = paymentReconciliation.getTenderedAmount().subtract(a);//应收的待分配金额 - - for (ChargeItem item : newChargeItemList) { - if (item.getTotalPrice() == null) { - log.info("这个收费项没有定义总价:" + item.getId()); - } - } - - Long paymentReconciliationId = paymentReconciliation.getId(); - if (paymentReconciliationId == 1987152585230508034L || paymentReconciliationId == 1987153070121410561L - || paymentReconciliationId == 1984438852329246721L || paymentReconciliationId == 1984902967625117698L - || paymentReconciliationId == 1984778667126493186L || paymentReconciliationId == 1984780710054531074L) { - log.info("主键id如下:" + paymentReconciliationId); - log.info("待分配诊疗项目如下:" + JsonUtils.toJson(newChargeItemList)); - } - if (b.compareTo(BigDecimal.ZERO) > 0) { - - // 存在待分配金额的情况下,对诊疗检查检验项目进行分配 - for (ChargeItem item : newChargeItemList) { - item.setSystemDiscountPrice(item.getTotalPrice().divide(f, 6, RoundingMode.HALF_UP).multiply(b)); - chargeItemService.updateById(item); - } - - } - } - - return new HashMap<>(); + return chargeBillCalculationService.updateChargeItemTotalPrice(); } - @Autowired - private IYbHttpUtils ybHttpUtils; - @Override public R checkYbNo() { - - List list = iActivityDefinitionService.list( - new LambdaQueryWrapper().isNotNull(ActivityDefinition::getYbNo) - .eq(ActivityDefinition::getDeleteFlag, DelFlag.NO.getCode())); - - List outList = new ArrayList<>(); - List voicList = new ArrayList<>(); - - if (list.isEmpty()) { - throw new ServiceException("没查到有医保码的诊疗定义"); - } - - for (ActivityDefinition activityDefinition : list) { - - Date nowTime = new Date(); - - Catalogue1312QueryParam catalogue1312QueryParam = new Catalogue1312QueryParam(); - catalogue1312QueryParam.setHilistCode(activityDefinition.getYbNo()); - catalogue1312QueryParam.setInsuplcAdmdvs( - SecurityUtils.getLoginUser().getOptionJsonValue(CommonConstants.Option.INSUPLC_ADMDVS)); - // 直接解析(默认 ISO 格式) - LocalDate localDate = LocalDate.parse("2025-01-01"); - // 转换为 Date - Date date = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); - catalogue1312QueryParam.setUpdtTime(date); - catalogue1312QueryParam.setPageNum(1); - catalogue1312QueryParam.setPageSize(10); - catalogue1312QueryParam.setDecryptFlag("0"); // 不需要解密 - List outputList = ybHttpUtils.queryYbCatalogue(catalogue1312QueryParam); - - if (outputList != null && !outputList.isEmpty() && outputList.get(0) != null) { - Catalogue1312Output catalogue1312Output = outputList.get(0); - if (catalogue1312Output.getValiFlag() != null && catalogue1312Output.getValiFlag().equals("1")) { - // 有效标志 - Date enddate = catalogue1312Output.getEnddate(); - if (enddate == null) { - // OK - } else { - if (!DateUtils.isFuture(enddate)) { - // 已过期 - outList.add(activityDefinition); - } - } - - } else { - voicList.add(activityDefinition); - } - } - - } - - HashMap hashMap = new HashMap<>(); - hashMap.put("失效列表", voicList); - hashMap.put("过期列表", outList); - - return R.ok(hashMap); + return chargeBillStatisticsService.checkYbNo(); } - }