gaoluyang
3 天以前 90b3ad820eea45d021835197eac5bc3ad55b12ed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.erp.dal.mysql.finance.ErpFinanceStatisticsMapper">
 
    <select id="selectMonthlyStatistics"
            resultType="cn.iocoder.yudao.module.erp.api.finance.dto.ErpFinanceMonthlyStatisticsRespDTO">
        SELECT t.month                                                    AS month,
               IFNULL(SUM(t.receiptPrice), 0)                             AS receiptPrice,
               IFNULL(SUM(t.paymentPrice), 0)                             AS paymentPrice,
               IFNULL(SUM(t.saleOrderPrice), 0)                           AS saleOrderPrice,
               IFNULL(SUM(t.purchaseOrderPrice), 0)                       AS purchaseOrderPrice
        FROM (
            SELECT DATE_FORMAT(receipt_time, '%Y-%m')  AS month,
                   IFNULL(SUM(receipt_price), 0)       AS receiptPrice,
                   0                                   AS paymentPrice,
                   0                                   AS saleOrderPrice,
                   0                                   AS purchaseOrderPrice
            FROM erp_finance_receipt
            WHERE deleted = 0
              AND status = #{approveStatus}
              AND receipt_time &gt;= #{startTime}
              AND receipt_time &lt; #{endTime}
            GROUP BY DATE_FORMAT(receipt_time, '%Y-%m')
            UNION ALL
            SELECT DATE_FORMAT(payment_time, '%Y-%m'),
                   IFNULL(SUM(payment_price), 0),
                   0,
                   0,
                   0
            FROM erp_finance_payment
            WHERE deleted = 0
              AND status = #{approveStatus}
              AND payment_time &gt;= #{startTime}
              AND payment_time &lt; #{endTime}
            GROUP BY DATE_FORMAT(payment_time, '%Y-%m')
            UNION ALL
            SELECT DATE_FORMAT(order_time, '%Y-%m'),
                   IFNULL(SUM(total_price), 0),
                   0,
                   0,
                   0
            FROM erp_sale_order
            WHERE deleted = 0
              AND status = #{approveStatus}
              AND order_time &gt;= #{startTime}
              AND order_time &lt; #{endTime}
            GROUP BY DATE_FORMAT(order_time, '%Y-%m')
            UNION ALL
            SELECT DATE_FORMAT(order_time, '%Y-%m'),
                   IFNULL(SUM(total_price), 0),
                   0,
                   0,
                   0
            FROM erp_purchase_order
            WHERE deleted = 0
              AND status = #{approveStatus}
              AND order_time &gt;= #{startTime}
              AND order_time &lt; #{endTime}
            GROUP BY DATE_FORMAT(order_time, '%Y-%m')
        ) t
        GROUP BY t.month
        ORDER BY t.month
    </select>
 
</mapper>