From 3b0d223da5ab0dc504252009b4a3afa6ff937bfb Mon Sep 17 00:00:00 2001 From: Joshi <3040996759@qq.com> Date: Mon, 23 Jun 2025 11:36:14 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=96=B0=E4=BF=AE=E6=94=B9=E7=9B=88?= =?UTF-8?q?=E4=BA=8F=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/SysOaProjectServiceImpl.java | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/ruoyi-oa/src/main/java/com/ruoyi/oa/service/impl/SysOaProjectServiceImpl.java b/ruoyi-oa/src/main/java/com/ruoyi/oa/service/impl/SysOaProjectServiceImpl.java index cbc60bf..1e2e1cf 100644 --- a/ruoyi-oa/src/main/java/com/ruoyi/oa/service/impl/SysOaProjectServiceImpl.java +++ b/ruoyi-oa/src/main/java/com/ruoyi/oa/service/impl/SysOaProjectServiceImpl.java @@ -90,23 +90,29 @@ public class SysOaProjectServiceImpl implements ISysOaProjectService { wrapper.ge(StringUtils.isNotBlank(beginTimeStart), "p.begin_time", beginTimeStart); wrapper.le(StringUtils.isNotBlank(beginTimeEnd), "p.begin_time", beginTimeEnd); - // 3. 构建HAVING子句, 用于筛选计算后的盈亏值 - StringBuilder havingClause = new StringBuilder(); + // 先把 profit_loss 的 CASE 表达式完整地组装成一个字符串 + String profitLossExpr = "(" + + "CASE " + + " WHEN p.funds IS NOT NULL AND p.funds > 0 THEN " + + " CASE WHEN p.remark LIKE '%美元%' OR p.remark LIKE '%美金%' " + + " THEN p.funds * " + currentExchangeRate + + " ELSE p.funds END " + + " ELSE COALESCE(finance_details.total_income, 0) " + + "END " + + " - COALESCE(finance_details.total_expenditure, 0)" + + ")"; + +// 不用 wrapper.having(...) if ("profit".equals(profitType)) { - havingClause.append("profit_loss > 0"); + wrapper.apply(profitLossExpr + " > 0"); } else if ("loss".equals(profitType)) { - havingClause.append("profit_loss < 0"); + wrapper.apply(profitLossExpr + " < 0"); } if (minProfitLoss != null) { - if (havingClause.length() > 0) havingClause.append(" AND "); - havingClause.append("profit_loss >= ").append(minProfitLoss); + wrapper.apply(profitLossExpr + " >= {0}", minProfitLoss); } if (maxProfitLoss != null) { - if (havingClause.length() > 0) havingClause.append(" AND "); - havingClause.append("profit_loss <= ").append(maxProfitLoss); - } - if (havingClause.length() > 0) { - wrapper.having(havingClause.toString()); + wrapper.apply(profitLossExpr + " <= {0}", maxProfitLoss); } // 4. 构建分页对象 (排序由PageQuery自动处理)