Bonus-Cloud-Houqin/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/v3/AccTradeMapper.xml

765 lines
31 KiB
XML
Raw Normal View History

2025-02-27 13:36:55 +08:00
<?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">
2025-02-27 13:46:27 +08:00
<mapper namespace="com.bonus.canteen.core.account.v3.mapper.AccTradeMapper">
2025-02-27 13:36:55 +08:00
<!-- 移动端分页查询充值记录 -->
2025-02-27 13:46:27 +08:00
<select id="queryTradeAppPage" resultType="com.bonus.canteen.core.account.v3.app.vo.AppAccTradePageVO">
2025-02-27 13:36:55 +08:00
SELECT
id AS tradeId,
amount,
acc_all_bal as walletBalTotal,
trade_type,
trade_time,
pay_state,
pay_type,
remark,
fail_reason
FROM acc_trade
<where>
cust_id = #{infoParam.custId}
<if test="infoParam.startDateTime != null">
and trade_time <![CDATA[ >= ]]> #{infoParam.startDateTime}
</if>
<if test="infoParam.endDateTime != null">
and trade_time <![CDATA[ <= ]]> #{infoParam.endDateTime}
</if>
<if test="infoParam.tradeTypeList != null and infoParam.tradeTypeList.size()>0 ">
and trade_type in
<foreach collection="infoParam.tradeTypeList" item="tradeType" separator="," open="(" close=")">
#{tradeType}
</foreach>
</if>
<if test="infoParam.payStateList != null and infoParam.payStateList.size()>0 ">
and pay_state in
<foreach collection="infoParam.payStateList" item="payState" separator="," open="(" close=")">
#{payState}
</foreach>
</if>
</where>
ORDER BY trade_time DESC
</select>
<!-- * 查询交易记录 场景发送mq-->
2025-02-27 13:46:27 +08:00
<select id="listAccTradeForSend" resultType="com.bonus.canteen.core.account.v3.mq.send.model.RepAccMqModel">
2025-02-27 13:36:55 +08:00
SELECT
atr.id AS flowId,
atr.cust_id,
ci.cust_num,
2025-03-12 16:22:41 +08:00
ci.nick_name as cust_name,
2025-02-27 13:36:55 +08:00
atr.org_id,
2025-03-12 16:22:41 +08:00
co.dept_name as org_name,
2025-03-14 16:46:49 +08:00
<!-- co.org_full_name, -->
2025-02-27 13:36:55 +08:00
atr.psn_type,
cpt.psn_type_name,
atr.amount AS flowAmount,
atr.actual_amount AS flowRealAmount,
atr.manage_cost AS manageCost,
atr.wallet_bal_total AS accTotalBal,
atr.acc_all_bal AS accAllBal,
atr.trade_time AS payTime,
atr.trade_type AS flowType,
atr.remark,
atr.crby AS optname,
atr.recharge_source AS rechargeSource,
atr.machine_type AS machineType,
atr.pay_channel AS payChannel,
atr.pay_type AS payType,
atr.batch_num AS batchNum,
atr.recharge_operate AS rechargeOperate,
atr.machine_sn As mchSn,
atr.machine_sn,
atr.withdraw_source,
atr.operate_source,
atr.origin_trade_id
FROM
acc_trade AS atr
2025-03-12 16:22:41 +08:00
LEFT JOIN sys_user AS ci ON atr.cust_id = ci.cust_id
LEFT JOIN sys_dept AS co ON atr.org_id = co.dept_id
2025-02-27 13:36:55 +08:00
LEFT JOIN cust_psn_type AS cpt ON atr.psn_type = cpt.psn_type
WHERE atr.id IN
<foreach collection="tradeIdList" item="tradeId" separator="," open="(" close=")">
#{tradeId}
</foreach>
ORDER BY atr.trade_time,atr.id
</select>
2025-03-12 16:22:41 +08:00
<!-- <select id="listAccTradeForSend" resultType="net.xnzn.core.account.v3.mq.send.model.RepAccMqModel">-->
<!-- SELECT-->
<!-- atr.id AS flowId,-->
<!-- atr.cust_id,-->
<!-- ci.cust_num,-->
<!-- ci.cust_name,-->
<!-- atr.org_id,-->
<!-- co.org_name,-->
<!-- co.org_full_name,-->
<!-- atr.psn_type,-->
<!-- cpt.psn_type_name,-->
<!-- atr.amount AS flowAmount,-->
<!-- atr.actual_amount AS flowRealAmount,-->
<!-- atr.manage_cost AS manageCost,-->
<!-- atr.wallet_bal_total AS accTotalBal,-->
<!-- atr.acc_all_bal AS accAllBal,-->
<!-- atr.trade_time AS payTime,-->
<!-- atr.trade_type AS flowType,-->
<!-- atr.remark,-->
<!-- atr.crby AS optname,-->
<!-- atr.recharge_source AS rechargeSource,-->
<!-- atr.machine_type AS machineType,-->
<!-- atr.pay_channel AS payChannel,-->
<!-- atr.pay_type AS payType,-->
<!-- atr.batch_num AS batchNum,-->
<!-- atr.recharge_operate AS rechargeOperate,-->
<!-- atr.machine_sn As mchSn,-->
<!-- atr.machine_sn,-->
<!-- atr.withdraw_source,-->
<!-- atr.operate_source,-->
<!-- atr.origin_trade_id-->
<!-- FROM-->
<!-- acc_trade AS atr-->
<!-- LEFT JOIN cust_info AS ci ON atr.cust_id = ci.cust_id-->
<!-- LEFT JOIN cust_org AS co ON atr.org_id = co.org_id-->
<!-- LEFT JOIN cust_psn_type AS cpt ON atr.psn_type = cpt.psn_type-->
<!-- WHERE atr.id IN-->
<!-- <foreach collection="tradeIdList" item="tradeId" separator="," open="(" close=")">-->
<!-- #{tradeId}-->
<!-- </foreach>-->
<!-- ORDER BY atr.trade_time,atr.id-->
<!-- </select>-->
2025-02-27 13:36:55 +08:00
<!-- 获取个人钱包充值汇总-->
2025-02-27 13:46:27 +08:00
<select id="getAccRechargeSum" resultType="com.bonus.canteen.core.account.v3.api.vo.AccRechargeSumApiVO">
2025-02-27 13:36:55 +08:00
SELECT
count(*) AS sumCount,
SUM( amount ) AS sumAmount
FROM
acc_trade t1
<where>
t1.trade_type = 10 and t1.pay_state = 3 and t1.trade_state = 2
<if test="param.custId != null">
and t1.cust_id = #{param.custId}
</if>
<if test="param.startDateTime != null">
and t1.trade_time <![CDATA[ >= ]]> #{param.startDateTime}
</if>
<if test="param.endDateTime != null">
and t1.trade_time <![CDATA[ <= ]]> #{param.endDateTime}
</if>
<if test="param.payChannellList != null and param.payChannellList.size() > 0">
and t1.pay_channel in
<foreach collection="param.payChannellList" item="payChannel" separator="," open="(" close=")">
#{payChannel}
</foreach>
</if>
</where>
</select>
<!-- 移动端根据交易id获取交易记录-->
2025-02-27 13:46:27 +08:00
<select id="getOneTradeApp" resultType="com.bonus.canteen.core.account.v3.app.vo.AppAccTradePageVO">
2025-02-27 13:36:55 +08:00
SELECT
id AS tradeId,
amount,
acc_all_bal as walletBalTotal,
trade_type,
trade_time,
pay_state,
pay_type,
remark
FROM acc_trade
WHERE id = #{tradeId}
</select>
<!-- 查询用户补贴交易明细-->
2025-02-27 13:46:27 +08:00
<select id="listAccSubsidyTrade" resultType="com.bonus.canteen.core.account.v3.model.AccTradeWalletDetail">
2025-02-27 13:36:55 +08:00
SELECT *
FROM
acc_trade_wallet_detail
<where>
wallet_id = 2
and cust_id = #{custId}
<if test="tradeTypeList != null and tradeTypeList.size() > 0">
and trade_type in
<foreach collection="tradeTypeList" item="tradeType" separator="," open="(" close=")">
#{tradeType}
</foreach>
</if>
</where>
ORDER BY trade_time DESC,trade_id DESC
</select>
2025-03-20 18:34:05 +08:00
<!-- 分页查询补贴充值记录-->
<select id="queryAccSubRechargeList" resultType="com.bonus.canteen.core.account.v3.web.vo.AccSubRechargePageVO">
<include refid="query_sub_recharge_detail_sql">
</include>
</select>
<!-- 查询补贴充值记录sql -->
<sql id="query_sub_recharge_detail_sql">
SELECT atr.trade_time,
atr.cust_id,
ci.cust_num,
ci.nick_name as cust_name,
ci.phonenumber as mobile,
<!-- co.org_full_name, -->
atr.psn_type,
cpt.psn_type_name,
atr.crby,
atr.id as tradeId,
atr.trade_state,
atr.batch_num,
atr.remark,
atr.amount as rechargeAmount,
atwd.wallet_bal as rechargeAfterWalletBal,
atwd.validate_time
FROM
acc_trade atr
LEFT JOIN sys_user ci ON ci.cust_id = atr.cust_id
LEFT JOIN cust_psn_type cpt ON cpt.psn_type = atr.psn_type
LEFT JOIN sys_dept co ON co.dept_id = atr.org_id
LEFT JOIN acc_trade_wallet_detail atwd ON atr.id = atwd.trade_id
<include refid="acc_recharge_sub_page_where_sql">
</include>
ORDER BY atr.trade_time desc,atr.id desc
</sql>
<!-- 补贴充值记录where条件-->
<sql id="acc_recharge_sub_page_where_sql">
<where>
atr.trade_type = 20 and atr.pay_state = 3
<if test="param.accTradeId != null">
and atr.id = #{param.accTradeId}
</if>
<if test="param.startDateTime != null">
and atr.trade_time <![CDATA[ >= ]]> #{param.startDateTime}
</if>
<if test="param.endDateTime != null">
and atr.trade_time <![CDATA[ <= ]]> #{param.endDateTime}
</if>
<if test="param.crBy != null and param.crBy != ''">
and atr.crby like #{param.crBy}
</if>
<if test="param.batchNum != null and param.batchNum != ''">
and atr.batch_num = #{param.batchNum}
</if>
<if test="param.orgIdList != null and param.orgIdList.size() > 0">
and atr.org_id in
<foreach collection="param.orgIdList" item="orgId" separator="," open="(" close=")">
#{orgId}
</foreach>
</if>
<if test="param.keyword != null and param.keyword != ''">
<include refid="cust_fuzzy_query"></include>
</if>
<if test="param.custId != null">
and atr.cust_id = #{param.custId}
</if>
</where>
</sql>
<!-- 关联用户模糊查询-->
<sql id="cust_fuzzy_query">
and (ci.cust_num LIKE CONCAT('%', #{param.keyword},'%')
or ci.nick_name = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
or ci.phonenumber = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler}
<!-- or ci.mobile_suffix = #{param.keyword,typeHandler=net.xnzn.core.common.encrypt.SM4EncDecHandler} -->
or ci.nick_name_like LIKE CONCAT('%',#{param.keyword,typeHandler=net.xnzn.core.common.encrypt.CipherQueryLikeHandler},'%')
)
</sql>
<!-- 查询补贴充值记录-合计金额-->
<select id="getTotalAccSubRechargePage" resultType="com.bonus.canteen.core.account.v3.web.vo.AccSubRechargePageVO">
SELECT sum(atr.amount) rechargeAmount
FROM
acc_trade atr
LEFT JOIN sys_user ci ON ci.cust_id = atr.cust_id
<include refid="acc_recharge_sub_page_where_sql">
</include>
</select>
<!-- 查询补贴清空记录-->
<select id="queryAccSubClearList" resultType="com.bonus.canteen.core.account.v3.web.vo.AccSubClearPageVO">
<include refid="query_sub_clear_detail_sql">
</include>
</select>
<!-- 补贴清空记录sql-->
<sql id="query_sub_clear_detail_sql">
SELECT atr.trade_time,
atr.cust_id,
ci.cust_num,
ci.nick_name AS cust_name,
ci.phonenumber AS mobile,
<!-- co.org_full_name, -->
atr.psn_type,
cpt.psn_type_name,
atr.amount as clearAmount,
atwd.wallet_bal as clearAfterWalletBal,
atr.crby,
atr.id as tradeId
FROM
acc_trade atr
LEFT JOIN sys_user ci ON ci.cust_id = atr.cust_id
LEFT JOIN sys_dept co ON co.dept_id = atr.org_id
LEFT JOIN cust_psn_type cpt ON cpt.psn_type = atr.psn_type
LEFT JOIN acc_trade_wallet_detail atwd ON atr.id = atwd.trade_id
<include refid="acc_recharge_sub_clear_page_where_sql">
</include>
ORDER BY atr.trade_time desc,atr.id desc
</sql>
<!-- 补贴清空记录where条件-->
<sql id="acc_recharge_sub_clear_page_where_sql">
<where>
atr.trade_type = 100 and atr.pay_state = 3
<if test="param.startDateTime != null">
and atr.trade_time <![CDATA[ >= ]]> #{param.startDateTime}
</if>
<if test="param.endDateTime != null">
and atr.trade_time <![CDATA[ <= ]]> #{param.endDateTime}
</if>
<if test="param.crBy != null and param.crBy != ''">
and atr.crby like #{param.crBy}
</if>
<if test="param.batchNum != null and param.batchNum != ''">
and atr.batch_num = #{param.batchNum}
</if>
<if test="param.orgIdList != null and param.orgIdList.size() > 0">
and atr.org_id in
<foreach collection="param.orgIdList" item="orgId" separator="," open="(" close=")">
#{orgId}
</foreach>
</if>
<if test="param.keyword != null and param.keyword != ''">
<include refid="cust_fuzzy_query"></include>
</if>
<if test="param.custId != null">
and atr.cust_id = #{param.custId}
</if>
<if test="param.accTradeId != null">
and atr.id = #{param.accTradeId}
</if>
</where>
</sql>
<!-- 查询补贴清空记录 - 合计金额-->
<select id="getTotalAccSubClearPage" resultType="com.bonus.canteen.core.account.v3.web.vo.AccSubClearPageVO">
SELECT SUM(atr.amount) clearAmount
FROM
acc_trade atr
LEFT JOIN sys_user ci ON ci.cust_id = atr.cust_id
<include refid="acc_recharge_sub_clear_page_where_sql">
</include>
</select>
<!-- 补贴汇总-用户个人补贴汇总-导出-->
<select id="listAccSubRechargeCollectPageForCust"
resultType="com.bonus.canteen.core.account.v3.web.vo.AccSubCollectVO">
<include refid="query_acc_sub_recharge_collect_cust_sql"></include>
</select>
<!-- 补贴汇总-用户个人补贴汇总-sql-->
<sql id="query_acc_sub_recharge_collect_cust_sql">
SELECT
ci.cust_id,
ci.cust_num,
ci.nick_name as cust_name,
ci.phonenumber as mobile,
<!-- co.org_full_name AS custOrgFullName, -->
IFNULL(t3.count,0) AS `times`,
IFNULL(t3.amount,0) AS `amount`,
IFNULL(t3.clearTimes,0) AS clearTimes,
IFNULL(t3.clearAmount,0) AS clearAmount,
IFNULL(t3.revocationTimes,0) AS revocationTimes,
IFNULL(t3.revocationAmount,0) AS revocationAmount,
IFNULL(t3.amount,0) + IFNULL(t3.clearAmount,0) + IFNULL(t3.revocationAmount,0) AS totalAmount,
t3.change_flag
FROM
sys_user ci
INNER JOIN acc_info ai on ci.cust_id = ai.cust_id
LEFT JOIN sys_dept co ON ci.dept_id = co.dept_id
LEFT JOIN
(
SELECT
t1.cust_id,
SUM( CASE WHEN t1.trade_type = 20 THEN 1 ELSE 0 END ) AS `count`,
SUM( CASE WHEN t1.trade_type = 20 THEN t1.amount ELSE 0 END ) AS `amount`,
SUM( CASE WHEN t1.trade_type = 50 THEN 1 ELSE 0 END ) AS revocationTimes,
SUM( CASE WHEN t1.trade_type = 50 THEN - t1.amount ELSE 0 END ) AS revocationAmount,
SUM( CASE WHEN t1.trade_type = 100 THEN 1 ELSE 0 END ) AS clearTimes,
SUM( CASE WHEN t1.trade_type = 100 THEN - t1.amount ELSE 0 END ) AS clearAmount,
1 AS change_flag
FROM
acc_trade t1
<where>
t1.trade_type IN (20,50,100)
<if test="param.startDateTime != null">
and t1.trade_time <![CDATA[ >= ]]> #{param.startDateTime}
</if>
<if test="param.endDateTime != null">
and t1.trade_time <![CDATA[ <= ]]> #{param.endDateTime}
</if>
</where>
GROUP BY t1.cust_id
) t3 ON t3.cust_id = ci.cust_id
<where>
<if test="param.orgIdList != null and param.orgIdList.size() != 0">
and ci.dept_id in
<foreach collection="param.orgIdList" item="orgId" separator="," open="(" close=")">
#{orgId}
</foreach>
</if>
<if test="param.keyword != null and param.keyword != ''">
<include refid="cust_fuzzy_query"></include>
</if>
</where>
ORDER BY change_flag IS NULL,amount DESC,ci.cust_id
</sql>
<!-- 补贴汇总 - 人员类别汇总 集合-->
<select id="listAccSubRechargeCollectForCustPsn"
resultType="com.bonus.canteen.core.account.v3.web.vo.AccSubCollectVO">
<include refid="query_acc_recharge_sum_psn_base_sql">
</include>
</select>
<!-- 补贴汇总-人员类别汇总 sql -->
<sql id="query_acc_recharge_sum_psn_base_sql">
SELECT
cpt.psn_type,
cpt.psn_type_name,
IFNULL(t3.count,0) AS `times`,
IFNULL(t3.amount,0) AS `amount`,
IFNULL(t3.clearTimes,0) AS clearTimes,
IFNULL(t3.clearAmount,0) AS clearAmount,
IFNULL(t3.revocationTimes,0) AS revocationTimes,
IFNULL(t3.revocationAmount,0) AS revocationAmount,
IFNULL(t3.amount,0) + IFNULL(t3.clearAmount,0) + IFNULL(t3.revocationAmount,0) AS totalAmount,
t3.change_flag
FROM
(SELECT psn_type_name, psn_type FROM cust_psn_type UNION ALL SELECT '—' AS psn_type_name, - 1 AS psn_type) cpt
LEFT JOIN
(
SELECT
IFNULL( t1.psn_type, - 1 ) AS psn_type,
SUM( CASE WHEN t1.trade_type = 20 THEN 1 ELSE 0 END ) AS `count`,
SUM( CASE WHEN t1.trade_type = 20 THEN t1.amount ELSE 0 END ) AS `amount`,
SUM( CASE WHEN t1.trade_type = 50 THEN 1 ELSE 0 END ) AS revocationTimes,
SUM( CASE WHEN t1.trade_type = 50 THEN - t1.amount ELSE 0 END ) AS revocationAmount,
SUM( CASE WHEN t1.trade_type = 100 THEN 1 ELSE 0 END ) AS clearTimes,
SUM( CASE WHEN t1.trade_type = 100 THEN - t1.amount ELSE 0 END ) AS clearAmount,
1 AS change_flag
FROM
acc_trade t1
<where>
t1.trade_type IN (20,50,100)
<if test="param.startDateTime != null">
and t1.trade_time <![CDATA[ >= ]]> #{param.startDateTime}
</if>
<if test="param.endDateTime != null">
and t1.trade_time <![CDATA[ <= ]]> #{param.endDateTime}
</if>
</where>
GROUP BY t1.psn_type
) t3 ON t3.psn_type = cpt.psn_type
<where>
<if test="param.psnTypeList != null and param.psnTypeList.size() != 0">
and cpt.psn_type in
<foreach collection="param.psnTypeList" item="psnType" separator="," open="(" close=")">
#{psnType}
</foreach>
</if>
</where>
ORDER BY change_flag IS NULL, amount DESC, cpt.psn_type
</sql>
<!-- 补贴汇总 - 组织汇总 集合-->
<select id="listAccSubRechargeCollectPageCustOrg"
resultType="com.bonus.canteen.core.account.v3.web.vo.AccSubCollectVO">
<include refid="query_acc_recharge_sum_org_base_sql">
</include>
</select>
<!-- 补贴汇总组织汇总sql-->
<sql id="query_acc_recharge_sum_org_base_sql">
SELECT
g.dept_id as org_id,
<!-- g.org_num, -->
<!-- g.org_full_name, -->
IFNULL(t3.count,0) AS `times`,
IFNULL(t3.amount,0) AS `amount`,
IFNULL(t3.clearTimes,0) AS clearTimes,
IFNULL(t3.clearAmount,0) AS clearAmount,
IFNULL(t3.revocationTimes,0) AS revocationTimes,
IFNULL(t3.revocationAmount,0) AS revocationAmount,
IFNULL(t3.amount,0) + IFNULL(t3.clearAmount,0) + IFNULL(t3.revocationAmount,0) AS totalAmount,
t3.change_flag
FROM
sys_dept g
LEFT JOIN (
SELECT
IFNULL( t1.org_id, - 1 ) AS org_id,
SUM( CASE WHEN t1.trade_type = 20 THEN 1 ELSE 0 END ) AS `count`,
SUM( CASE WHEN t1.trade_type = 20 THEN t1.amount ELSE 0 END ) AS `amount`,
SUM( CASE WHEN t1.trade_type = 50 THEN 1 ELSE 0 END ) AS revocationTimes,
SUM( CASE WHEN t1.trade_type = 50 THEN - t1.amount ELSE 0 END ) AS revocationAmount,
SUM( CASE WHEN t1.trade_type = 100 THEN 1 ELSE 0 END ) AS clearTimes,
SUM( CASE WHEN t1.trade_type = 100 THEN - t1.amount ELSE 0 END ) AS clearAmount,
1 AS change_flag
FROM
acc_trade t1
<where>
t1.trade_type IN ( 20, 50, 100 )
<if test="param.startDateTime != null">
and t1.trade_time <![CDATA[ >= ]]> #{param.startDateTime}
</if>
<if test="param.endDateTime != null">
and t1.trade_time <![CDATA[ <= ]]> #{param.endDateTime}
</if>
</where>
GROUP BY t1.org_id
) t3 ON t3.org_id = g.dept_id
<where>
<if test="param.orgIdList != null and param.orgIdList.size() != 0">
and g.dept_id in
<foreach collection="param.orgIdList" item="orgId" separator="," open="(" close=")">
#{orgId}
</foreach>
</if>
</where>
ORDER BY change_flag IS NULL,amount DESC,g.ancestors
</sql>
<!-- 补贴汇总-用户个人补贴汇总-->
<select id="getTotalAccSubRechargeCollectAmountForCust"
resultType="com.bonus.canteen.core.account.v3.web.vo.AccSubCollectVO">
SELECT
IFNULL( a.times, 0 ) AS `times`,
IFNULL( a.amount, 0 ) AS `amount`,
IFNULL( a.clearTimes, 0 ) AS clearTimes,
IFNULL( a.clearAmount, 0 ) AS clearAmount,
IFNULL( a.revocationTimes, 0 ) AS revocationTimes,
IFNULL( a.revocationAmount, 0 ) AS revocationAmount,
IFNULL( a.amount, 0 ) + IFNULL( a.clearAmount, 0 ) + IFNULL( a.revocationAmount, 0 ) AS totalAmount
FROM
(
SELECT
SUM( CASE WHEN atr.trade_type = 20 THEN 1 ELSE 0 END ) AS `times`,
SUM( CASE WHEN atr.trade_type = 20 THEN atr.amount ELSE 0 END ) AS `amount`,
SUM( CASE WHEN atr.trade_type = 50 THEN 1 ELSE 0 END ) AS revocationTimes,
SUM( CASE WHEN atr.trade_type = 50 THEN - atr.amount ELSE 0 END ) AS revocationAmount,
SUM( CASE WHEN atr.trade_type = 100 THEN 1 ELSE 0 END ) AS clearTimes,
SUM( CASE WHEN atr.trade_type = 100 THEN - atr.amount ELSE 0 END ) AS clearAmount
FROM sys_user ci
LEFT JOIN acc_trade atr ON ci.cust_id = atr.cust_id
<where>
atr.trade_type IN ( 20, 50, 100 )
<if test="param.startDateTime != null">
AND atr.trade_time <![CDATA[ >= ]]> #{param.startDateTime}
</if>
<if test="param.endDateTime != null">
AND atr.trade_time <![CDATA[ <= ]]> #{param.endDateTime}
</if>
<if test="param.psnTypeList != null and param.psnTypeList.size() != 0">
AND atr.psn_type in
<foreach collection="param.psnTypeList" item="psnType" separator="," open="(" close=")">
#{psnType}
</foreach>
</if>
<if test="param.orgIdList != null and param.orgIdList.size() != 0">
AND ci.dept_id in
<foreach collection="param.orgIdList" item="orgId" separator="," open="(" close=")">
#{orgId}
</foreach>
</if>
<if test="param.keyword != null and param.keyword != ''">
<include refid="cust_fuzzy_query"></include>
</if>
<if test="'2'.toString() == authPO.roleType.toString()">
and EXISTS (
SELECT null
FROM sys_role_dept it1
LEFT JOIN sys_role it2 ON it2.role_id = it1.role_id
LEFT JOIN sys_user_role it3 ON it1.role_id = it3.role_id
WHERE it2.del_flag = 0
AND it2.role_key = #{authPO.roleCode}
<!-- AND it1.half_select = 1 -->
AND it3.user_id = #{authPO.userId}
AND it1.dept_id = ci.dept_id
)
</if>
</where>
) as a
</select>
<!-- 补贴汇总 - 合计金额-->
<select id="getTotalAccSubRechargeCollectAmount"
resultType="com.bonus.canteen.core.account.v3.web.vo.AccSubCollectVO">
SELECT
IFNULL( a.times, 0 ) AS `times`,
IFNULL( a.amount, 0 ) AS `amount`,
IFNULL( a.clearTimes, 0 ) AS clearTimes,
IFNULL( a.clearAmount, 0 ) AS clearAmount,
IFNULL( a.revocationTimes, 0 ) AS revocationTimes,
IFNULL( a.revocationAmount, 0 ) AS revocationAmount,
IFNULL( a.amount, 0 ) + IFNULL( a.clearAmount, 0 ) + IFNULL( a.revocationAmount, 0 ) AS totalAmount
FROM
(
SELECT
SUM( CASE WHEN atr.trade_type = 20 THEN 1 ELSE 0 END ) AS `times`,
SUM( CASE WHEN atr.trade_type = 20 THEN atr.amount ELSE 0 END ) AS `amount`,
SUM( CASE WHEN atr.trade_type = 50 THEN 1 ELSE 0 END ) AS revocationTimes,
SUM( CASE WHEN atr.trade_type = 50 THEN - atr.amount ELSE 0 END ) AS revocationAmount,
SUM( CASE WHEN atr.trade_type = 100 THEN 1 ELSE 0 END ) AS clearTimes,
SUM( CASE WHEN atr.trade_type = 100 THEN - atr.amount ELSE 0 END ) AS clearAmount
FROM acc_trade atr
LEFT JOIN sys_user ci ON ci.cust_id = atr.cust_id
<where>
atr.trade_type IN ( 20, 50, 100 )
<if test="param.startDateTime != null">
AND atr.trade_time <![CDATA[ >= ]]> #{param.startDateTime}
</if>
<if test="param.endDateTime != null">
AND atr.trade_time <![CDATA[ <= ]]> #{param.endDateTime}
</if>
<if test="param.psnTypeList != null and param.psnTypeList.size() != 0">
AND atr.psn_type in
<foreach collection="param.psnTypeList" item="psnType" separator="," open="(" close=")">
#{psnType}
</foreach>
</if>
<if test="param.orgIdList != null and param.orgIdList.size() != 0">
AND atr.org_id in
<foreach collection="param.orgIdList" item="orgId" separator="," open="(" close=")">
#{orgId}
</foreach>
</if>
<if test="param.keyword != null and param.keyword != ''">
<include refid="cust_fuzzy_query"></include>
</if>
<if test="'2'.toString() == authPO.roleType.toString()">
and EXISTS (
SELECT null
FROM sys_role_dept it1
LEFT JOIN sys_role it2 ON it2.role_id = it1.role_id
LEFT JOIN sys_user_role it3 ON it1.role_id = it3.role_id
WHERE it2.del_flag = 0
AND it2.role_key = #{authPO.roleCode}
<!-- AND it1.half_select = 1 -->
AND it3.user_id = #{authPO.userId}
AND it1.dept_id = atr.org_id
)
</if>
</where>
) as a
</select>
<select id="getCustTimeForAdvanceReceiveSub" resultType="int">
SELECT COUNT(id)
FROM acc_trade
WHERE sub_time_rule_id = #{timeId}
AND trade_type = #{tradeType}
AND cust_id = #{custId}
AND trade_time <![CDATA[ >= ]]> #{firstDateTime}
AND trade_time <![CDATA[ <= ]]> #{nowTime}
</select>
<!-- 根据交易记录id和批次号查询交易记录-->
<select id="listAccTrade" resultType="com.bonus.canteen.core.account.v3.web.vo.AccTradeAndDetailVO">
SELECT *
FROM acc_trade
<where>
trade_type = #{tradeType}
<if test="tradeIdList != null and tradeIdList.size() != 0">
and id in
<foreach collection="tradeIdList" item="tradeId" separator="," open="(" close=")">
#{tradeId}
</foreach>
</if>
<if test="batchNum != null">
and batch_num = #{batchNum}
</if>
</where>
ORDER BY trade_time DESC
</select>
<!-- 查询补贴撤销记录-导出-->
<select id="listRepealAccSubTrade" resultType="com.bonus.canteen.core.account.v3.web.vo.AccSubRepealPageVO">
<include refid="query_sub_repeal_detail_sql">
</include>
</select>
<!-- 查询个人钱包充值撤销记录sql-->
<sql id="query_sub_repeal_detail_sql">
SELECT atr.trade_time,
atr.cust_id,
ci.cust_num,
ci.nick_name AS cust_name,
ci.phonenumber AS mobile,
<!-- co.org_full_name, -->
atr.psn_type,
cpt.psn_type_name,
atwd.amount as repealAmount,
atwd.wallet_bal as repealAfterWalletBal,
atr.crby,
atr.id as tradeId
FROM
acc_trade atr
LEFT JOIN sys_user ci ON ci.cust_id = atr.cust_id
LEFT JOIN sys_dept co ON co.dept_id = atr.org_id
LEFT JOIN cust_psn_type cpt ON cpt.psn_type = atr.psn_type
LEFT JOIN acc_trade_wallet_detail atwd ON atr.id = atwd.trade_id
<include refid="query_recharge_repeal_detail_where_sql">
</include>
ORDER BY atr.trade_time desc,atr.id desc
</sql>
<!-- 充值撤销补贴撤销where条件-->
<sql id="query_recharge_repeal_detail_where_sql">
<where>
atr.pay_state = 3
<if test="param.walletId != null">
and atwd.wallet_id = #{param.walletId}
</if>
<if test="param.tradeType != null">
and atr.trade_type = #{param.tradeType}
</if>
<if test="param.startDateTime != null">
and atr.trade_time <![CDATA[ >= ]]> #{param.startDateTime}
</if>
<if test="param.endDateTime != null">
and atr.trade_time <![CDATA[ <= ]]> #{param.endDateTime}
</if>
<if test="param.crBy != null and param.crBy != ''">
and atr.crby like #{param.crBy}
</if>
<if test="param.orgIdList != null and param.orgIdList.size() > 0">
and atr.org_id in
<foreach collection="param.orgIdList" item="orgId" separator="," open="(" close=")">
#{orgId}
</foreach>
</if>
<if test="param.custId != null">
and atr.cust_id = #{param.custId}
</if>
<if test="param.accTradeId != null and param.accTradeId != ''">
and atr.id = #{param.accTradeId}
</if>
<if test="param.keyword != null and param.keyword != ''">
<include refid="cust_fuzzy_query"></include>
</if>
</where>
</sql>
<!-- 查询个人钱包充值撤销记录 - 合计金额-->
<select id="getTotalRepealAccSubTradePage" resultType="java.math.BigDecimal">
SELECT SUM(atwd.amount)
FROM
acc_trade atr
LEFT JOIN sys_user ci ON ci.cust_id = atr.cust_id
LEFT JOIN acc_trade_wallet_detail atwd ON atr.id = atwd.trade_id
<include refid="query_recharge_repeal_detail_where_sql">
</include>
</select>
2025-02-27 13:36:55 +08:00
</mapper>