스마트서비스 최종완료보고 버전
This commit is contained in:
@@ -0,0 +1,353 @@
|
||||
<?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.slot, 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, T.amount, T.type, T.approval, T.uid1, T.pay_name, T.pay_vendor, T.slot, T.code, T.goods_name, T.pay_unique_num, T.order_time
|
||||
</otherwise>
|
||||
</choose>
|
||||
FROM transactions AS T
|
||||
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="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="slot != null and slot != ''">AND T.slot = #{slot}</if>
|
||||
<if test="code != null and code != ''">AND T.code = #{code}</if>
|
||||
<if test="goods_name != null and goods_name != ''">AND T.goods_name = #{goods_name}</if>
|
||||
<if test="pay_vendor != null and pay_vendor != ''">AND T.pay_vendor = #{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.slot, 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="slot != null and slot != ''">AND T.slot = #{slot}</if>
|
||||
<if test="code != null and code != ''">AND T.code = #{code}</if>
|
||||
<if test="goods_name != null and goods_name != ''">AND T.goods_name = #{goods_name}</if>
|
||||
<if test="pay_vendor != null and pay_vendor != ''">AND T.pay_vendor = #{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>
|
||||
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,
|
||||
D.name AS device_name,
|
||||
T.uid1 AS uid1,
|
||||
|
||||
/* 카드 */
|
||||
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
|
||||
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>
|
||||
|
||||
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>,
|
||||
D.name,
|
||||
T.uid1
|
||||
|
||||
HAVING card_count != 0 OR cash_count != 0 OR tmoney_count != 0 OR cbee_count != 0
|
||||
|
||||
ORDER BY
|
||||
date DESC
|
||||
</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="slot != null and slot != ''">slot,</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="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="slot != null and slot != ''">#{slot},</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="pay_vendor != null and pay_vendor != ''">#{pay_vendor}</if>
|
||||
</trim>
|
||||
</insert>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user