报表功能查看

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