<?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 >= #{startTime}
|
AND receipt_time < #{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 >= #{startTime}
|
AND payment_time < #{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 >= #{startTime}
|
AND order_time < #{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 >= #{startTime}
|
AND order_time < #{endTime}
|
GROUP BY DATE_FORMAT(order_time, '%Y-%m')
|
) t
|
GROUP BY t.month
|
ORDER BY t.month
|
</select>
|
|
</mapper>
|