报表功能查看

This commit is contained in:
lizhenhua 2025-09-08 09:14:39 +08:00
parent 98d2cf5f3b
commit 324c53294f
2 changed files with 158 additions and 173 deletions

View File

@ -43,4 +43,8 @@ public interface OrgConsumeMapper {
List<CanteenOrg> selectAllOrgs();
List<OrgConsume> getDeductionlist(OrgConsume orgConsume);
List<Map<String, Object>> selectReserveRecordsFromDatabase(OrgConsume orgConsume);
List<OrgConsume> getlistForH5Special(OrgConsume orgConsume);
}

View File

@ -9,102 +9,70 @@
WHEN t.flow_type = 120 THEN 'deduction'
WHEN t.source_type = 7 THEN 'H5'
WHEN t.source_type = 53 THEN 'super'
WHEN (t.source_type IS NULL OR t.source_type = '' OR t.source_type = 0) AND t.remark LIKE '%支付%' THEN 'station'
WHEN (t.source_type IS NULL OR t.source_type = 0 OR t.source_type = '')
AND t.remark LIKE '%支付%' THEN 'station'
ELSE 'canteen'
END AS conSource,
ROUND(SUM(t.flow_real_amount) / 100, 2) AS amount
FROM
(
-- 第一段正常消费flow_type = 110
SELECT DISTINCT
aa.canteen_name,
ROUND(SUM(t.amount) / 100, 2) AS amount
FROM (
<!-- 正常消费 flow_type = 110 -->
SELECT
aac.area_name,
f.flow_type,
f.source_type,
f.remark,
f.flow_id,
f.flow_real_amount,
f.flow_type,
f.ord_time
f.flow_real_amount AS amount,
f.flow_id
FROM report_account_flow f
LEFT JOIN device_info di ON f.mch_sn = di.device_sn
LEFT JOIN device_bind bd ON di.device_id = bd.device_id
LEFT JOIN alloc_canteen aa ON aa.canteen_id = bd.canteen_id
LEFT JOIN alloc_area aac ON aac.area_id = aa.area_id
WHERE 1 = 1
<if test="startPayTime != null">
AND f.pay_time &gt;= #{startPayTime}
</if>
<if test="endPayTime != null">
AND f.pay_time &lt; #{endPayTime}
</if>
WHERE f.pay_time <![CDATA[ >= ]]> #{startPayTime}
AND f.pay_time <![CDATA[ < ]]> #{endPayTime}
AND f.flow_type = 110
UNION ALL
-- 第二段补充没有设备号的消费flow_type = 130
<!-- 退款 flow_type = 130 -->
SELECT
bo.canteen_name,
bo.area_name,
aac.area_name,
130 AS flow_type,
f.source_type,
f.remark,
f.flow_id,
f.flow_real_amount,
f.flow_type,
f.ord_time
FROM report_account_flow f
INNER JOIN (
SELECT
aa.canteen_name,
aac.area_name,
f.ord_time
FROM report_account_flow f
AT.actual_amount AS amount,
f.flow_id AS origin_flow_id
FROM acc_trade AT
INNER JOIN report_account_flow f
ON AT.origin_trade_id = f.flow_id
AND f.flow_type = 110
LEFT JOIN device_info di ON f.mch_sn = di.device_sn
LEFT JOIN device_bind bd ON di.device_id = bd.device_id
LEFT JOIN alloc_canteen aa ON aa.canteen_id = bd.canteen_id
LEFT JOIN alloc_area aac ON aac.area_id = aa.area_id
WHERE 1 = 1
<if test="startPayTime != null">
AND f.pay_time &gt;= #{startPayTime}
</if>
<if test="endPayTime != null">
AND f.pay_time &lt; #{endPayTime}
</if>
AND f.flow_type = 110
) bo ON f.ord_time = bo.ord_time
WHERE 1 = 1
<if test="startPayTime != null">
AND f.pay_time &gt;= #{startPayTime}
</if>
<if test="endPayTime != null">
AND f.pay_time &lt; #{endPayTime}
</if>
AND f.flow_type = 130
AND (f.mch_sn IS NULL OR f.mch_sn = '')
WHERE AT.trade_time <![CDATA[ >= ]]> #{startPayTime}
AND AT.trade_time <![CDATA[ < ]]> #{endPayTime}
AND AT.trade_type = 130
AND AT.trade_state = 2
AND (AT.machine_sn IS NULL OR AT.machine_sn = '')
UNION ALL
-- 第三段补扣金额flow_type = 120
<!-- 补扣 flow_type = 120 -->
SELECT
aa.canteen_name,
aac.area_name,
f.flow_type,
f.source_type,
f.remark,
f.flow_id,
f.flow_real_amount,
f.flow_type,
f.ord_time
f.flow_real_amount AS amount,
f.flow_id
FROM report_account_flow f
LEFT JOIN device_info di ON f.mch_sn = di.device_sn
LEFT JOIN device_bind bd ON di.device_id = bd.device_id
LEFT JOIN alloc_canteen aa ON aa.canteen_id = bd.canteen_id
LEFT JOIN alloc_area aac ON aac.area_id = aa.area_id
WHERE 1 = 1
<if test="startPayTime != null">
AND f.pay_time &gt;= #{startPayTime}
</if>
<if test="endPayTime != null">
AND f.pay_time &lt; #{endPayTime}
</if>
WHERE f.pay_time <![CDATA[ >= ]]> #{startPayTime}
AND f.pay_time <![CDATA[ < ]]> #{endPayTime}
AND f.flow_type = 120
) t
GROUP BY
@ -113,13 +81,11 @@
WHEN t.flow_type = 120 THEN 'deduction'
WHEN t.source_type = 7 THEN 'H5'
WHEN t.source_type = 53 THEN 'super'
WHEN (t.source_type IS NULL OR t.source_type = '' OR t.source_type = 0) AND t.remark LIKE '%支付%' THEN 'station'
WHEN (t.source_type IS NULL OR t.source_type = 0 OR t.source_type = '')
AND t.remark LIKE '%支付%' THEN 'station'
ELSE 'canteen'
END
ORDER BY
t.area_name
ORDER BY t.area_name
</select>
<select id="selectReserveRecords" resultType="java.util.Map">
@ -179,122 +145,135 @@
GROUP BY oh.org_id, oh.org_name
HAVING COALESCE(SUM(ct.amount), 0) != 0
ORDER BY oh.org_id
</select>
<select id="selectAreaOrgMap" resultType="java.util.Map">
SELECT area_name, org_name FROM area_org_map
</select>
<select id="getlistByArealist" resultType="com.bonus.canteen.core.reportforms.beans.OrgConsume">
SELECT distinct
co.org_full_name as orgFullName,
t.remark,
u.cust_name,
u.cust_name_like,
t.canteen_name,
t.area_name,
t.consume_source,
t.flow_id,
t.flow_type,
CASE
WHEN t.flow_type = 110 THEN '消费'
WHEN t.flow_type = 130 THEN '退款'
ELSE '其他'
END AS flow_type_name,
t.flow_real_amount / 100 AS amount,
t.ord_time,
t.pay_time
FROM
(
SELECT
aa.canteen_name,
aac.area_name,
CASE
WHEN f.source_type = 7 THEN 'H5'
WHEN f.source_type = 53 THEN 'super'
ELSE 'canteen'
END AS consume_source,
f.flow_id,
d.flow_type,
f.flow_real_amount,
f.ord_time,
d.pay_time,
f.cust_id,
f.remark
FROM report_account_flow f
INNER JOIN report_account_flow_detail d ON f.flow_id = d.flow_id
INNER JOIN device_info di ON f.mch_sn = di.device_sn
INNER JOIN device_bind bd ON di.device_id = bd.device_id
INNER JOIN alloc_canteen aa ON aa.canteen_id = bd.canteen_id
INNER JOIN alloc_area aac ON aac.area_id = aa.area_id
WHERE 1=1
<if test="startPayTime != null">
AND d.pay_time &gt;= #{startPayTime}
</if>
<if test="endPayTime != null">
<!-- Mapper XML -->
SELECT DISTINCT
co.org_full_name AS orgFullName,
t.remark,
u.cust_name,
u.cust_name_like,
t.canteen_name,
t.area_name,
t.consume_source,
t.flow_id,
t.flow_type,
CASE
WHEN t.flow_type = 110 THEN '消费'
WHEN t.flow_type = 130 THEN '退款'
ELSE '其他'
END AS flow_type_name,
t.flow_real_amount / 100 AS amount,
t.ord_time,
t.pay_time
FROM (
<!-- 1. 原消费逻辑 -->
SELECT
aa.canteen_name,
aac.area_name,
CASE
WHEN f.source_type = 7 THEN 'H5'
WHEN f.source_type = 53 THEN 'super'
ELSE 'canteen'
END AS consume_source,
f.flow_id,
d.flow_type,
f.flow_real_amount,
f.ord_time,
d.pay_time,
f.cust_id,
f.remark
FROM report_account_flow f
INNER JOIN report_account_flow_detail d ON f.flow_id = d.flow_id
INNER JOIN device_info di ON f.mch_sn = di.device_sn
INNER JOIN device_bind bd ON di.device_id = bd.device_id
INNER JOIN alloc_canteen aa ON aa.canteen_id = bd.canteen_id
INNER JOIN alloc_area aac ON aac.area_id = aa.area_id
WHERE d.pay_time &gt;= #{startPayTime}
AND d.pay_time &lt; #{endPayTime}
</if>
AND d.flow_type = 110
AND (f.source_type NOT IN (7, 53) OR f.source_type IS NULL)
AND d.flow_type = 110
AND f.source_type IS NOT NULL
AND f.source_type NOT IN (7,53)
UNION ALL
UNION ALL
SELECT
bo.canteen_name,
bo.area_name,
bo.consume_source,
f.flow_id,
d.flow_type,
f.flow_real_amount,
f.ord_time,
d.pay_time,
f.cust_id,
f.remark
FROM report_account_flow f
INNER JOIN report_account_flow_detail d ON f.flow_id = d.flow_id
INNER JOIN (
SELECT
aa.canteen_name,
aac.area_name,
CASE
WHEN f.source_type = 7 THEN 'H5'
WHEN f.source_type = 53 THEN 'super'
ELSE 'canteen'
END AS consume_source,
f.ord_time
FROM report_account_flow f
INNER JOIN report_account_flow_detail d ON f.flow_id = d.flow_id
INNER JOIN device_info di ON f.mch_sn = di.device_sn
INNER JOIN device_bind bd ON di.device_id = bd.device_id
INNER JOIN alloc_canteen aa ON aa.canteen_id = bd.canteen_id
INNER JOIN alloc_area aac ON aac.area_id = aa.area_id
WHERE 1=1
<if test="startPayTime != null">
AND d.pay_time &gt;= #{startPayTime}
</if>
<if test="endPayTime != null">
<!-- 2. 补充消费逻辑 -->
SELECT
bo.canteen_name,
bo.area_name,
bo.consume_source,
f.flow_id,
d.flow_type,
f.flow_real_amount,
f.ord_time,
d.pay_time,
f.cust_id,
f.remark
FROM report_account_flow f
INNER JOIN report_account_flow_detail d ON f.flow_id = d.flow_id
INNER JOIN (
SELECT
aa.canteen_name,
aac.area_name,
CASE
WHEN f.source_type = 7 THEN 'H5'
WHEN f.source_type = 53 THEN 'super'
ELSE 'canteen'
END AS consume_source,
f.ord_time
FROM report_account_flow f
INNER JOIN report_account_flow_detail d ON f.flow_id = d.flow_id
INNER JOIN device_info di ON f.mch_sn = di.device_sn
INNER JOIN device_bind bd ON di.device_id = bd.device_id
INNER JOIN alloc_canteen aa ON aa.canteen_id = bd.canteen_id
INNER JOIN alloc_area aac ON aac.area_id = aa.area_id
WHERE d.pay_time &gt;= #{startPayTime}
AND d.pay_time &lt; #{endPayTime}
</if>
AND d.flow_type = 110
) bo ON f.ord_time = bo.ord_time
WHERE 1=1
<if test="startPayTime != null">
AND d.pay_time &gt;= #{startPayTime}
</if>
<if test="endPayTime != null">
AND d.flow_type = 110
) bo ON f.ord_time = bo.ord_time
WHERE d.pay_time &gt;= #{startPayTime}
AND d.pay_time &lt; #{endPayTime}
</if>
AND d.flow_type = 130
AND (f.mch_sn IS NULL OR f.mch_sn = '')
) t
LEFT JOIN cust_info u ON t.cust_id = u.cust_id
LEFT JOIN cust_org co ON u.org_id = co.org_id
WHERE 1=1
AND t.area_name LIKE CONCAT('%', #{orgName}, '%')
AND d.flow_type = 130
AND (f.mch_sn IS NULL OR f.mch_sn = '')
AND f.source_type IS NOT NULL
UNION ALL
<!-- 3. 退款逻辑 -->
SELECT
aa.canteen_name,
aac.area_name,
'canteen' AS consume_source,
f.flow_id AS flow_id,
130 AS flow_type,
AT.actual_amount AS flow_real_amount,
f.ord_time,
AT.trade_time AS pay_time,
AT.cust_id,
f.remark
FROM report_account_flow f
INNER JOIN acc_trade AT
ON AT.origin_trade_id = f.flow_id
AND f.flow_type = 110
LEFT JOIN device_info di ON f.mch_sn = di.device_sn
LEFT JOIN device_bind bd ON di.device_id = bd.device_id
LEFT JOIN alloc_canteen aa ON aa.canteen_id = bd.canteen_id
LEFT JOIN alloc_area aac ON aac.area_id = aa.area_id
WHERE AT.trade_type = 130
AND AT.trade_state = 2
AND f.source_type IS NOT NULL
AND (AT.machine_sn IS NULL OR AT.machine_sn = '')
AND AT.trade_time &gt;= #{startPayTime}
AND AT.trade_time &lt; #{endPayTime}
) t
LEFT JOIN cust_info u ON t.cust_id = u.cust_id
LEFT JOIN cust_org co ON u.org_id = co.org_id
WHERE t.area_name LIKE CONCAT('%', #{orgName}, '%')
ORDER BY t.pay_time DESC
ORDER BY t.pay_time DESC
</select>
<select id="getlistBySuperlist" resultType="com.bonus.canteen.core.reportforms.beans.OrgConsume">
SELECT DISTINCT
@ -569,6 +548,8 @@
LEFT JOIN cust_org co ON u.org_id = co.org_id
WHERE t.area_name LIKE CONCAT('%', #{orgName}, '%')
ORDER BY t.pay_time DESC
</select>
<select id="getlistConsmerlist" resultType="com.bonus.canteen.core.reportforms.beans.OrgConsume">
SELECT