wujianwei
2025-12-23 298a6477b6220f651062080264750dcb04573eca
service/src/main/java/com/ruoyi/cwgl/service/impl/PayableFeeManagementServiceImpl.java
@@ -2,6 +2,8 @@
import java.math.RoundingMode;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import java.math.BigDecimal;
import com.ruoyi.common.utils.DateUtils;
@@ -134,6 +136,12 @@
    {
        payableFeeManagement.setCreateTime(DateUtils.getNowDate());
        
        // 计算应付金额字符串描述
        if (payableFeeManagement.getPayableFeeDetailList() != null && !payableFeeManagement.getPayableFeeDetailList().isEmpty()) {
            String payableAmountStr = calculatePayableAmountStr(payableFeeManagement.getPayableFeeDetailList());
            payableFeeManagement.setPayableAmountStr(payableAmountStr);
        }
        // 保存主实体
        int result = payableFeeManagementMapper.insertPayableFeeManagement(payableFeeManagement);
        Integer payableFeeId = payableFeeManagement.getId();
@@ -173,6 +181,13 @@
    public int updatePayableFeeManagement(PayableFeeManagement payableFeeManagement)
    {
        payableFeeManagement.setUpdateTime(DateUtils.getNowDate());
        // 计算应付金额字符串描述
        if (payableFeeManagement.getPayableFeeDetailList() != null && !payableFeeManagement.getPayableFeeDetailList().isEmpty()) {
            String payableAmountStr = calculatePayableAmountStr(payableFeeManagement.getPayableFeeDetailList());
            payableFeeManagement.setPayableAmountStr(payableAmountStr);
        }
        return payableFeeManagementMapper.updatePayableFeeManagement(payableFeeManagement);
    }
@@ -249,34 +264,45 @@
                throw new RuntimeException("所选记录的供应商名称不一致,无法进行统计");
            }
        }
        // 计算单据数量
        int documentCount = feeList.size();
        // 获取汇率配置
        SysConfig sysConfig = sysConfigMapper.selectConfig(new SysConfig() {{
            setConfigKey("sys.hk.rmb.rate");
        }});
        BigDecimal exchangeRate = new BigDecimal(sysConfig.getConfigValue());
        statisticsVo.setRate(exchangeRate);
        // 设置单据数量
        statisticsVo.setDocumentCount(feeList.size());
        // 设置汇率(默认汇率)
        statisticsVo.setRate(new BigDecimal("0.90"));
        // 计算总应收金额
        BigDecimal totalPayableAmount = feeList.stream()
                .map(PayableFeeManagement::getPayableAmount)
                .reduce(BigDecimal.ZERO, BigDecimal::add);
        BigDecimal exchangeRate = new BigDecimal(sysConfig.getConfigValue());
        BigDecimal totalAmountHkd = totalPayableAmount.divide(exchangeRate, 2, RoundingMode.HALF_UP);
        statisticsVo.setDocumentCount(documentCount);
        statisticsVo.setTotalPayableAmount(totalPayableAmount);
        statisticsVo.setTotalAmountRmb(totalPayableAmount);
        statisticsVo.setTotalAmountHkd(totalAmountHkd);
        statisticsVo.setIds(ids);
        // 获取所有应付费用明细,按币种分别计算金额
        List<PayableFeeDetail> detailList = payableFeeDetailService.selectPayableFeeDetailByPayableFeeIds(ids);
        // 按币种汇总金额
        BigDecimal totalAmountRmb = BigDecimal.ZERO;
        BigDecimal totalAmountHkd = BigDecimal.ZERO;
        for (PayableFeeDetail detail : detailList) {
            if ("CNY".equals(detail.getCurrency())) {
                totalAmountRmb = totalAmountRmb.add(detail.getBillingAmount());
            } else if ("HKD".equals(detail.getCurrency())) {
                totalAmountHkd = totalAmountHkd.add(detail.getBillingAmount());
            }
        }
        // 计算转换后的总金额
        BigDecimal totalAmountRmbWithConversion = totalAmountRmb.add(
            totalAmountHkd.multiply(exchangeRate).setScale(2, RoundingMode.HALF_UP)
        );
        BigDecimal totalAmountHkdWithConversion = totalAmountHkd.add(
            totalAmountRmb.divide(exchangeRate, 2, RoundingMode.HALF_UP)
        );
        // 设置统计结果
        statisticsVo.setTotalPayableAmount(totalAmountRmbWithConversion);
        statisticsVo.setTotalAmountRmb(totalAmountRmbWithConversion);
        statisticsVo.setTotalAmountHkd(totalAmountHkdWithConversion);
        return statisticsVo;
    }
@@ -323,7 +349,7 @@
        // 根据账单类型设置币种和总金额
        if (billCreateVo.getBillType() == 0) {
            // 人民币账单
            bill.setCurrency("CNY");
            bill.setCurrency("RMB");
            bill.setTotalAmount(statisticsVo.getTotalAmountRmb());
            bill.setCnyAmount(statisticsVo.getTotalAmountRmb());
        } else {
@@ -397,6 +423,53 @@
        
        return result;
    }
    /**
     * 计算应付金额字符串描述
     * 根据明细列表按币种汇总金额,格式如:"200港币100人民币"
     *
     * @param detailList 应付费用明细列表
     * @return 应付金额字符串描述
     */
    private String calculatePayableAmountStr(List<PayableFeeDetail> detailList) {
        if (detailList == null || detailList.isEmpty()) {
            return "";
        }
        // 按币种汇总金额
        Map<String, BigDecimal> currencyAmountMap = new HashMap<>();
        for (PayableFeeDetail detail : detailList) {
            String currency = detail.getCurrency();
            BigDecimal billingAmount = detail.getBillingAmount();
            if (currency != null && billingAmount != null) {
                currencyAmountMap.merge(currency, billingAmount, BigDecimal::add);
            }
        }
        // 构建字符串描述
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, BigDecimal> entry : currencyAmountMap.entrySet()) {
            if (sb.length() > 0) {
                sb.append(" ");
            }
            sb.append(entry.getValue().stripTrailingZeros().toPlainString());
            // 根据币种显示对应的货币名称
            String currency = entry.getKey();
            if ("CNY".equals(currency)) {
                sb.append("人民币");
            } else if ("HKD".equals(currency)) {
                sb.append("港币");
            } else if ("USD".equals(currency)) {
                sb.append("美元");
            } else {
                sb.append(currency);
            }
        }
        return sb.toString();
    }
}