Browse Source

fix(statistics):优化财务统计查询逻辑并修复金额显示问题

- 调整SQL格式,增强可读性- 修复金额计算未除以100导致的数据错误- 增加负数金额过滤逻辑
- 完善订单状态与分账状态判断条件
-优化动态SQL查询结构
- 确保分账记录筛选条件正确应用
SheepHy 1 day ago
parent
commit
745a08ec63

+ 66 - 33
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/mapper/xml/StatisticsMapper.xml

@@ -305,53 +305,79 @@
         SELECT
         b.id,
         CASE
-        WHEN a.order_status IN (0, 1, 2) THEN '收入'
-        WHEN a.order_status IN (3, 5, 6) THEN '支出'
-        ELSE '其他'
+        WHEN a.order_status IN (0, 1, 2) THEN
+        '收入'
+        WHEN a.order_status IN (3, 5, 6) THEN
+        '支出'
+        ELSE
+        '其他'
         END AS income_expense_type,
         CASE
-        WHEN b.order_id IS NULL THEN '待结算'
-        WHEN c.profit_sharing_status = 0 THEN '待结算'
-        WHEN c.profit_sharing_status = 1 THEN '已到账'
-        ELSE '其他'
+        WHEN b.order_id IS NULL THEN
+        '待结算'
+        WHEN c.profit_sharing_status = 0 THEN
+        '待结算'
+        WHEN c.profit_sharing_status = 1 THEN
+        '已到账'
+        ELSE
+        '其他'
         END AS amount_type,
         CASE
-        WHEN a.order_status IN (5, 6) THEN '用户退款'
-        WHEN a.order_status IN (0, 1, 2) THEN '用户支付'
-        WHEN c.profit_sharing_status = 0 THEN '分账'
-        WHEN c.profit_sharing_status = 1 THEN '银行卡到账'
-        ELSE '其他原因'
+        WHEN a.order_status IN (5, 6) THEN
+        '用户退款'
+        WHEN a.order_status IN (0, 1, 2) THEN
+        '用户支付'
+        WHEN c.profit_sharing_status = 0 THEN
+        '分账'
+        WHEN c.profit_sharing_status = 1 THEN
+        '银行卡到账'
+        ELSE
+        '其他原因'
         END AS change_reason,
         CASE
-        WHEN b.id IS NOT NULL THEN b.cumulative - b.pre_amount
-        WHEN b.order_id IS NULL THEN a.price
-        ELSE 0
+        WHEN b.id IS NOT NULL THEN
+        (b.cumulative - b.pre_amount) / 100
+        WHEN b.order_id IS NULL THEN
+        a.price / 100
+        ELSE
+        0
         END AS amount_before,
         CASE
-        WHEN b.id IS NOT NULL THEN b.cumulative + b.pre_amount
-        ELSE 0
+        WHEN b.id IS NOT NULL THEN
+        (b.cumulative + b.pre_amount) / 100
+        ELSE
+        0
         END AS amount_after,
         CASE
-        WHEN b.id IS NOT NULL THEN b.pre_amount
-        WHEN b.order_id IS NULL THEN a.price
-        ELSE 0
+        WHEN b.id IS NOT NULL THEN
+        b.pre_amount / 100
+        WHEN b.order_id IS NULL THEN
+        a.price / 100
+        ELSE
+        0
         END AS change_amount,
         a.create_time,
         ROW_NUMBER() OVER (
-        PARTITION BY
-        COALESCE(b.id, a.order_id)
+        PARTITION BY COALESCE(b.id, a.order_id)
         ORDER BY
-        CASE WHEN b.id IS NULL THEN 1 ELSE 0 END,
+        CASE
+        WHEN b.id IS NULL THEN
+        1
+        ELSE
+        0
+        END,
         b.id DESC,
         a.order_id
-        ) as rn
-        FROM nm_order_pro_info a
+        ) AS rn
+        FROM
+        nm_order_pro_info a
         LEFT JOIN nm_profit_sharing_info b ON a.order_id = b.order_id
         LEFT JOIN nm_order c ON a.order_id = c.id
-        WHERE a.price > 0
+        WHERE
+        a.price > 0
         AND a.type NOT IN (3, 4, 6)
-        AND c.org_code = #{orgCode}
         AND b.pre_amount > 0
+        AND c.org_code = #{orgCode}
         <!-- 动态条件 -->
         <if test="incomeExpenseType != null and incomeExpenseType != '' and incomeExpenseType != '全部'">
             AND (
@@ -383,18 +409,25 @@
             END
             ) = #{changeReason}
         </if>
-        )
-        SELECT
+        ) SELECT
         id,
         income_expense_type,
         amount_type,
         change_reason,
-        amount_before,
+        CASE
+        WHEN amount_before &lt; 0 THEN
+        0
+        ELSE
+        amount_before
+        END AS amount_before,
         amount_after,
         change_amount,
         create_time
-        FROM RankedData
-        WHERE rn = 1
-        ORDER BY create_time DESC
+        FROM
+        RankedData
+        WHERE
+        rn = 1
+        ORDER BY
+        create_time DESC
     </select>
 </mapper>