440 lines
21 KiB
XML
440 lines
21 KiB
XML
<?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="com.handong.smartservice.mapper.TransactionMapper">
|
|
|
|
<!--
|
|
<select id="selectTransaction" resultType="map">
|
|
SELECT
|
|
<choose>
|
|
<when test='isCount == true'>
|
|
COUNT(*)
|
|
</when>
|
|
<otherwise>
|
|
T.reg_time, T.order_time, T.amount, T.type, T.approval, T.uid1, T.pay_name, T.pay_vendor, T.column_no, T.code, T.goods_name, T.pay_unique_num, T.order_time
|
|
</otherwise>
|
|
</choose>
|
|
FROM transactions AS T
|
|
JOIN terminal T2 ON T.uid1 = T2.uid1 AND T.uid1_type = T2.type
|
|
JOIN terminal_biz_group TBG ON TBG.terminal_id = T2.terminal_id
|
|
JOIN biz_group AS BG ON BG.biz_group_id = TBG.biz_group_id
|
|
WHERE ( TBG.biz_group_id = #{biz_group_id}
|
|
<if test='is_group_access == false'>
|
|
OR BG.top_group_id = #{biz_group_id}
|
|
</if>
|
|
)
|
|
<if test='date_end != null and date_end != ""'>
|
|
AND DATE(T.reg_time) <= #{date_end}
|
|
</if>
|
|
<if test='uid1 != null and uid1 != ""'>
|
|
AND T.uid1 = #{uid1}
|
|
</if>
|
|
<if test='isCount == false'>
|
|
ORDER BY T.transaction_id DESC LIMIT #{limit} OFFSET #{offset}
|
|
</if>
|
|
</select>
|
|
-->
|
|
<select id="selectTransaction" resultType="map">
|
|
<if test='is_group_access == false'>
|
|
WITH target_group AS (
|
|
WITH RECURSIVE group_tree AS (
|
|
SELECT
|
|
BG1.biz_group_id,
|
|
1 AS depth
|
|
FROM biz_group BG1
|
|
WHERE BG1.state != 2 AND BG1.biz_group_id = #{biz_group_id}
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
BG2.biz_group_id,
|
|
GT.depth + 1
|
|
FROM biz_group BG2
|
|
INNER JOIN group_tree GT ON BG2.pid = GT.biz_group_id
|
|
WHERE BG2.state != 2 AND GT.depth < 10
|
|
)
|
|
SELECT biz_group_id
|
|
FROM group_tree
|
|
)
|
|
</if>
|
|
SELECT
|
|
<choose>
|
|
<when test='isCount == true'>
|
|
COUNT(*)
|
|
</when>
|
|
<otherwise>
|
|
T.reg_time, T.order_time, D.name AS device_name, T.amount, T.type, T.approval, T.uid1, T.pay_name, T.pay_vendor, T.column_no, T.code, T.goods_name, T.pay_unique_num, T.order_time,
|
|
T.card_num, T.rtid,
|
|
/* the original approval, used for the cancel column and the cancel receipt of a credit cancel row */
|
|
ORG.order_time AS org_order_time, ORG.goods_name AS org_goods_name
|
|
</otherwise>
|
|
</choose>
|
|
FROM transactions AS T
|
|
JOIN device D ON T.device_id = D.device_id
|
|
LEFT JOIN transactions ORG ON ORG.transaction_id = T.rtid
|
|
WHERE
|
|
<choose>
|
|
<when test='is_group_access == false'>
|
|
T.biz_group_id IN ( SELECT biz_group_id FROM target_group )
|
|
</when>
|
|
<otherwise>
|
|
T.biz_group_id = #{biz_group_id}
|
|
</otherwise>
|
|
</choose>
|
|
<if test='date_start != null and date_start != ""'>AND #{date_start} <= DATE(T.reg_time)</if>
|
|
<if test='date_end != null and date_end != ""'>AND DATE(T.reg_time) <= #{date_end}</if>
|
|
<if test='device_name != null and device_name != ""'>AND D.name like CONCAT('%', #{device_name}, '%')</if>
|
|
<if test='uid1 != null and uid1 != ""'>AND T.uid1 = #{uid1}</if>
|
|
<if test='uid1_type != null and uid1_type != 0'>AND T.uid1_type = #{uid1_type}</if>
|
|
<if test='type != null and type != ""'>AND T.type = #{type}</if>
|
|
<if test='amount != null and amount != 0'>AND T.amount = #{amount}</if>
|
|
<if test='approval != null and approval != ""'>AND T.approval = #{approval}</if>
|
|
<if test='column_no != null and column_no != ""'>AND T.column_no = #{column_no}</if>
|
|
<if test='code != null and code != ""'>AND T.code = #{code}</if>
|
|
<if test='goods_name != null and goods_name != ""'>AND T.goods_name like CONCAT('%', #{goods_name}, '%')</if>
|
|
<if test='pay_name != null and pay_name != ""'>AND T.pay_name like CONCAT('%', #{pay_name}, '%')</if>
|
|
<if test='pay_vendor != null and pay_vendor != ""'>AND T.pay_vendor like CONCAT('%', #{pay_vendor}, '%')</if>
|
|
<if test='isCount == false and is_excel == false'>
|
|
ORDER BY T.transaction_id DESC LIMIT #{limit} OFFSET #{offset}
|
|
</if>
|
|
</select>
|
|
|
|
<select id="selectTransactionBizGroup0" resultType="map">
|
|
SELECT
|
|
<choose>
|
|
<when test='isCount == true'>
|
|
COUNT(*)
|
|
</when>
|
|
<otherwise>
|
|
T.reg_time, T.order_time, T.amount, T.type, T.approval, T.uid1, T.pay_name, T.pay_vendor, T.column_no, T.code, T.goods_name, T.pay_unique_num, T.order_time
|
|
</otherwise>
|
|
</choose>
|
|
FROM transactions AS T
|
|
WHERE biz_group_id = 0
|
|
<if test='date_end != null and date_end != ""'>
|
|
AND DATE(T.reg_time) <= #{date_end}
|
|
</if>
|
|
<if test='date_start != null and date_start != ""'>AND #{date_start} <= DATE(T.reg_time)</if>
|
|
<if test='date_end != null and date_end != ""'>AND DATE(T.reg_time) <= #{date_end}</if>
|
|
<if test='uid1 != null and uid1 != ""'>AND T.uid1 = #{uid1}</if>
|
|
<if test='uid1_type != null and uid1_type != 0'>AND T.uid1_type = #{uid1_type}</if>
|
|
<if test='type != null and type != ""'>AND T.type = #{type}</if>
|
|
<if test='amount != null and amount != 0'>AND T.amount = #{amount}</if>
|
|
<if test='approval != null and approval != ""'>AND T.approval = #{approval}</if>
|
|
<if test='column_no != null and column_no != ""'>AND T.column_no = #{column_no}</if>
|
|
<if test='code != null and code != ""'>AND T.code = #{code}</if>
|
|
<if test='goods_name != null and goods_name != ""'>AND T.goods_name like CONCAT('%', #{goods_name}, '%')</if>
|
|
<if test='pay_name != null and pay_name != ""'>AND T.pay_name like CONCAT('%', #{pay_name}, '%')</if>
|
|
<if test='pay_vendor != null and pay_vendor != ""'>AND T.pay_vendor like CONCAT('%', #{pay_vendor}, '%')</if>
|
|
<if test='isCount == false and is_excel == false'>
|
|
ORDER BY T.transaction_id DESC LIMIT #{limit} OFFSET #{offset}
|
|
</if>
|
|
</select>
|
|
|
|
<!--
|
|
<select id="selectTransaction3" resultType="map">
|
|
SELECT
|
|
<choose>
|
|
<when test='isCount == true'>
|
|
COUNT(*)
|
|
</when>
|
|
<otherwise>
|
|
DATE_FORMAT(STR_TO_DATE(T.order_time, '%y%m%d%H%i%s'), '%Y-%m-%d') AS date,
|
|
D.name AS device_name,
|
|
TER.uid1,
|
|
|
|
SUM(CASE WHEN T.type = 'D1' THEN 1 ELSE 0 END) AS card_count,
|
|
SUM(CASE WHEN T.type = 'D1' THEN T.amount ELSE 0 END) AS card_amount,
|
|
SUM(CASE WHEN T.type = 'I1' THEN 1 ELSE 0 END) AS cash_count,
|
|
SUM(CASE WHEN T.type = 'I1' THEN T.amount ELSE 0 END) AS cash_amount,
|
|
SUM(CASE WHEN T.type = 'TM1' THEN 1 ELSE 0 END) AS tmoney_count,
|
|
SUM(CASE WHEN T.type = 'TM1' THEN T.amount ELSE 0 END) AS tmoney_amount,
|
|
SUM(CASE WHEN T.type = 'EB1' THEN 1 ELSE 0 END) AS cashb_count,
|
|
SUM(CASE WHEN T.type = 'EB1' THEN T.amount ELSE 0 END) AS cashb_amount,
|
|
SUM(T.amount) AS total
|
|
</otherwise>
|
|
</choose>
|
|
FROM transactions AS T
|
|
JOIN device D ON T.device_id = D.device_id
|
|
JOIN terminal TER ON TER.device_id = D.device_id
|
|
JOIN device_biz_group DBG ON DBG.device_id = D.device_id
|
|
JOIN biz_group AS BG ON BG.biz_group_id = DBG.biz_group_id
|
|
WHERE ( DBG.biz_group_id = #{biz_group_id}
|
|
<if test='is_group_access == false'>
|
|
OR BG.top_group_id = #{biz_group_id}
|
|
</if>
|
|
)
|
|
<if test='date_end != null and date_end != ""'>
|
|
AND DATE(T.reg_time) <= #{date_end}
|
|
</if>
|
|
<if test='uid1 != null and uid1 != ""'>
|
|
AND TER.uid1 = #{uid1}
|
|
</if>
|
|
GROUP BY DATE_FORMAT(STR_TO_DATE(T.order_time, '%y%m%d%H%i%s'), '%Y-%m-%d'), D.name, TER.uid1
|
|
<if test='isCount == false'>
|
|
ORDER BY date, D.name;
|
|
</if>
|
|
</select>
|
|
-->
|
|
<select id="selectTransaction3" resultType="map">
|
|
<if test='is_group_access == false'>
|
|
WITH target_group AS (
|
|
WITH RECURSIVE group_tree AS (
|
|
SELECT
|
|
BG1.biz_group_id,
|
|
1 AS depth
|
|
FROM biz_group BG1
|
|
WHERE BG1.state != 2 AND BG1.biz_group_id = #{biz_group_id}
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
BG2.biz_group_id,
|
|
GT.depth + 1
|
|
FROM biz_group BG2
|
|
INNER JOIN group_tree GT ON BG2.pid = GT.biz_group_id
|
|
WHERE BG2.state != 2 AND GT.depth < 10
|
|
)
|
|
SELECT biz_group_id
|
|
FROM group_tree
|
|
)
|
|
</if>
|
|
|
|
<choose>
|
|
<when test='isCount == true'>
|
|
SELECT COUNT(*) AS total_count
|
|
FROM (
|
|
SELECT 1
|
|
</when>
|
|
<otherwise>
|
|
SELECT
|
|
<choose>
|
|
<when test='date_type == 2'>DATE_FORMAT(T.reg_time, '%Y-%m')</when>
|
|
<otherwise>DATE_FORMAT(T.reg_time, '%Y-%m-%d')</otherwise>
|
|
</choose> AS date,
|
|
<if test='query_uid1 == true'>
|
|
D.name AS device_name, T.uid1 AS uid1,
|
|
</if>
|
|
/* 카드 */
|
|
COUNT(CASE WHEN
|
|
<choose>
|
|
<when test='approval_type == 0'>T.type IN ('D1','D4','I1','I4')</when>
|
|
<when test='approval_type == 1'>T.type IN ('D1','I1')</when>
|
|
<when test='approval_type == 2'>T.type IN ('D4','I4')</when>
|
|
</choose>
|
|
THEN 1 END) AS card_count,
|
|
SUM(CASE WHEN
|
|
<choose>
|
|
<when test='approval_type == 0'>T.type IN ('D1','D4','I1','I4')</when>
|
|
<when test='approval_type == 1'>T.type IN ('D1','I1')</when>
|
|
<when test='approval_type == 2'>T.type IN ('D4','I4')</when>
|
|
</choose>
|
|
THEN T.amount ELSE 0 END) AS card_amount,
|
|
/* 현금 */
|
|
COUNT(CASE WHEN
|
|
<choose>
|
|
<when test='approval_type == 0'>T.type IN ('B1','B4')</when>
|
|
<when test='approval_type == 1'>T.type IN ('B1')</when>
|
|
<when test='approval_type == 2'>T.type IN ('B4')</when>
|
|
</choose>
|
|
THEN 1 END) AS cash_count,
|
|
SUM(CASE WHEN
|
|
<choose>
|
|
<when test='approval_type == 0'>T.type IN ('B1','B4')</when>
|
|
<when test='approval_type == 1'>T.type IN ('B1')</when>
|
|
<when test='approval_type == 2'>T.type IN ('B4')</when>
|
|
</choose>
|
|
THEN T.amount ELSE 0 END) AS cash_amount,
|
|
/* T머니 */
|
|
COUNT(CASE WHEN
|
|
<choose>
|
|
<when test='approval_type == 0'>T.type IN ('TM1','TM4')</when>
|
|
<when test='approval_type == 1'>T.type IN ('TM1')</when>
|
|
<when test='approval_type == 2'>T.type IN ('TM4')</when>
|
|
</choose>
|
|
THEN 1 END) AS tmoney_count,
|
|
SUM(CASE WHEN
|
|
<choose>
|
|
<when test='approval_type == 0'>T.type IN ('TM1','TM4')</when>
|
|
<when test='approval_type == 1'>T.type IN ('TM1')</when>
|
|
<when test='approval_type == 2'>T.type IN ('TM4')</when>
|
|
</choose>
|
|
THEN T.amount ELSE 0 END) AS tmoney_amount,
|
|
/* 캐시비 */
|
|
COUNT(CASE WHEN
|
|
<choose>
|
|
<when test='approval_type == 0'>T.type IN ('EB1','EB4')</when>
|
|
<when test='approval_type == 1'>T.type IN ('EB1')</when>
|
|
<when test='approval_type == 2'>T.type IN ('EB4')</when>
|
|
</choose>
|
|
THEN 1 END) AS cbee_count,
|
|
SUM(CASE WHEN
|
|
<choose>
|
|
<when test='approval_type == 0'>T.type IN ('EB1','EB4')</when>
|
|
<when test='approval_type == 1'>T.type IN ('EB1')</when>
|
|
<when test='approval_type == 2'>T.type IN ('EB4')</when>
|
|
</choose>
|
|
THEN T.amount ELSE 0 END) AS cbee_amount,
|
|
/* 합계 */
|
|
(
|
|
SUM(CASE WHEN T.type IN ('D1','D4','I1','I4') THEN T.amount ELSE 0 END) +
|
|
SUM(CASE WHEN T.type IN ('B1','B4') THEN T.amount ELSE 0 END) +
|
|
SUM(CASE WHEN T.type IN ('TM1','TM4') THEN T.amount ELSE 0 END) +
|
|
SUM(CASE WHEN T.type IN ('EB1','EB4') THEN T.amount ELSE 0 END)
|
|
) AS total
|
|
</otherwise>
|
|
</choose>
|
|
|
|
FROM transactions AS T
|
|
JOIN device D ON D.device_id = T.device_id
|
|
WHERE
|
|
<choose>
|
|
<when test='is_group_access == false'>
|
|
T.biz_group_id IN ( SELECT biz_group_id FROM target_group )
|
|
</when>
|
|
<otherwise>
|
|
T.biz_group_id = #{biz_group_id}
|
|
</otherwise>
|
|
</choose>
|
|
<if test='date_start != null and date_start != ""'>AND #{date_start} <= DATE(T.reg_time)</if>
|
|
<if test='date_end != null and date_end != ""'>AND DATE(T.reg_time) <= #{date_end}</if>
|
|
<if test='device_name != null and device_name != ""'>AND D.name like CONCAT('%', #{device_name}, '%')</if>
|
|
<if test='uid1 != null and uid1 != ""'>AND T.uid1 = #{uid1}</if>
|
|
|
|
GROUP BY
|
|
<choose>
|
|
<when test='date_type == 2'>DATE_FORMAT(T.reg_time, '%Y-%m')</when>
|
|
<otherwise>DATE_FORMAT(T.reg_time, '%Y-%m-%d')</otherwise>
|
|
</choose>
|
|
<if test='query_uid1 == true'>, D.name, T.uid1</if>
|
|
|
|
<choose>
|
|
<when test='isCount == true'>
|
|
HAVING COUNT(CASE WHEN T.type IN ('D1','D4','I1','I4','B1','B4','TM1','TM4','EB1','EB4') THEN 1 END) != 0
|
|
) AS counted
|
|
</when>
|
|
<otherwise>
|
|
<if test='isCount == false and is_excel == false'>
|
|
HAVING card_count != 0 OR cash_count != 0 OR tmoney_count != 0 OR cbee_count != 0
|
|
ORDER BY date DESC LIMIT #{limit} OFFSET #{offset}
|
|
</if>
|
|
</otherwise>
|
|
</choose>
|
|
</select>
|
|
|
|
<select id="selectTransactionSum" resultType="map">
|
|
<if test='is_group_access == false'>
|
|
WITH target_group AS (
|
|
WITH RECURSIVE group_tree AS (
|
|
SELECT
|
|
BG1.biz_group_id,
|
|
1 AS depth
|
|
FROM biz_group BG1
|
|
WHERE BG1.state != 2 AND BG1.biz_group_id = #{biz_group_id}
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
BG2.biz_group_id,
|
|
GT.depth + 1
|
|
FROM biz_group BG2
|
|
INNER JOIN group_tree GT ON BG2.pid = GT.biz_group_id
|
|
WHERE BG2.state != 2 AND GT.depth < 10
|
|
)
|
|
SELECT biz_group_id
|
|
FROM group_tree
|
|
)
|
|
</if>
|
|
SELECT
|
|
/* 카드 */
|
|
SUM(T.type IN ('D1','D4','I1','I4')) AS card_count,
|
|
IFNULL(SUM(CASE WHEN T.type IN ('D1','D4','I1','I4') THEN T.amount ELSE 0 END), 0) AS card_amount,
|
|
|
|
/* 현금 */
|
|
SUM(T.type IN ('B1','B4')) AS cash_count,
|
|
IFNULL(SUM(CASE WHEN T.type IN ('B1','B4') THEN T.amount ELSE 0 END), 0) AS cash_amount,
|
|
|
|
/* T머니 */
|
|
SUM(T.type IN ('TM1','TM4')) AS tmoney_count,
|
|
IFNULL(SUM(CASE WHEN T.type IN ('TM1','TM4') THEN T.amount ELSE 0 END), 0) AS tmoney_amount,
|
|
|
|
/* 캐시비 */
|
|
SUM(T.type IN ('EB1','EB4')) AS cbee_count,
|
|
IFNULL(SUM(CASE WHEN T.type IN ('EB1','EB4') THEN T.amount ELSE 0 END), 0) AS cbee_amount,
|
|
|
|
/* 합계 */
|
|
(
|
|
IFNULL(SUM(CASE WHEN T.type IN ('D1','D4','I1','I4') THEN T.amount ELSE 0 END), 0) +
|
|
IFNULL(SUM(CASE WHEN T.type IN ('B1','B4') THEN T.amount ELSE 0 END), 0) +
|
|
IFNULL(SUM(CASE WHEN T.type IN ('TM1','TM4') THEN T.amount ELSE 0 END), 0) +
|
|
IFNULL(SUM(CASE WHEN T.type IN ('EB1','EB4') THEN T.amount ELSE 0 END), 0)
|
|
) AS total
|
|
FROM transactions AS T
|
|
JOIN device D ON D.device_id = T.device_id
|
|
WHERE
|
|
<choose>
|
|
<when test='is_group_access == false'>
|
|
T.biz_group_id IN ( SELECT biz_group_id FROM target_group )
|
|
</when>
|
|
<otherwise>
|
|
T.biz_group_id = #{biz_group_id}
|
|
</otherwise>
|
|
</choose>
|
|
<if test='date_start != null and date_start != ""'>AND #{date_start} <= DATE(T.reg_time)</if>
|
|
<if test='date_end != null and date_end != ""'>AND DATE(T.reg_time) <= #{date_end}</if>
|
|
|
|
HAVING card_count != 0 OR cash_count != 0 OR tmoney_count != 0 OR cbee_count != 0
|
|
</select>
|
|
|
|
<!-- The original credit approval of a cancel: same terminal and same approval number, latest one first -->
|
|
<select id="selectOrgTransactionId" resultType="java.lang.Long">
|
|
SELECT transaction_id
|
|
FROM transactions
|
|
WHERE type = 'D1' AND uid1 = #{uid1} AND approval = #{approval}
|
|
ORDER BY transaction_id DESC
|
|
LIMIT 1
|
|
</select>
|
|
|
|
<insert id="insertTransaction">
|
|
INSERT INTO transactions
|
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
|
reg_time, process,
|
|
<if test='biz_group_id != null'>biz_group_id,</if>
|
|
<if test='device_id != null'>device_id,</if>
|
|
<if test='uid1 != null and uid1 != ""'>uid1,</if>
|
|
<if test='uid1_type != null and uid1_type != 0'>uid1_type,</if>
|
|
<if test='order_time != null and order_time != ""'>order_time,</if>
|
|
<if test='type != null and type != ""'>type,</if>
|
|
<if test='amount != null and amount != 0'>amount,</if>
|
|
<if test='approval != null and approval != ""'>approval,</if>
|
|
<if test='pay_unique_num != null and pay_unique_num != ""'>pay_unique_num,</if>
|
|
<if test='column_no != null and column_no != ""'>column_no,</if>
|
|
<if test='code != null and code != ""'>code,</if>
|
|
<if test='goods_name != null and goods_name != ""'>goods_name,</if>
|
|
<if test='price != null and price != 0'>price,</if>
|
|
<if test='pay_name != null and pay_name != ""'>pay_name,</if>
|
|
<if test='rtid != null'>rtid,</if>
|
|
<if test='pay_vendor != null and pay_vendor != ""'>pay_vendor</if>
|
|
</trim>
|
|
VALUES
|
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
|
NOW(), 1,
|
|
<if test='biz_group_id != null'>#{biz_group_id},</if>
|
|
<if test='device_id != null'>#{device_id},</if>
|
|
<if test='uid1 != null and uid1 != ""'>#{uid1},</if>
|
|
<if test='uid1_type != null and uid1_type != 0'>#{uid1_type},</if>
|
|
<if test='order_time != null and order_time != ""'>#{order_time},</if>
|
|
<if test='type != null and type != ""'>#{type},</if>
|
|
<if test='amount != null and amount != 0'>#{amount},</if>
|
|
<if test='approval != null and approval != ""'>#{approval},</if>
|
|
<if test='pay_unique_num != null and pay_unique_num != ""'>#{pay_unique_num},</if>
|
|
<if test='column_no != null and column_no != ""'>#{column_no},</if>
|
|
<if test='code != null and code != ""'>#{code},</if>
|
|
<if test='goods_name != null and goods_name != ""'>#{goods_name},</if>
|
|
<if test='price != null and price != 0'>#{price},</if>
|
|
<if test='pay_name != null and pay_name != ""'>#{pay_name},</if>
|
|
<if test='rtid != null'>#{rtid},</if>
|
|
<if test='pay_vendor != null and pay_vendor != ""'>#{pay_vendor}</if>
|
|
</trim>
|
|
</insert>
|
|
</mapper> |