| | |
| | | ORDER BY COALESCE(o.pay_time, o.create_time, o.end_time) DESC, o.create_time DESC, o.id DESC |
| | | |
| | | </select> |
| | | <select id="getRefundList" resultType="com.ruoyi.order.api.model.TChargingOrderRefund"> |
| | | select * from ( |
| | | SELECT |
| | | re.id, |
| | | re.`code`, |
| | | re.refund_code, |
| | | re.refund_title, |
| | | re.refund_reason, |
| | | re.refund_amount, |
| | | re.balance_refund_amount, |
| | | re.third_refund_amount, |
| | | re.refund_total_amount, |
| | | re.refund_time, |
| | | re.pay_type, |
| | | re.pay_amount, |
| | | re.refund_remark, |
| | | co.recharge_serial_number as serail_number, |
| | | co.payment_amount, |
| | | co.create_time as pay_time, |
| | | co.id as order_id, |
| | | co.app_user_id as user_id, |
| | | co.site_id as site_id, |
| | | co.pay_method as pay_method, |
| | | 1 as type |
| | | FROM t_charging_order_refund re |
| | | LEFT JOIN t_charging_order co ON re.charging_order_id = co.id |
| | | <if test="data.specialRefund != null and data.specialRefund"> |
| | | WHERE re.refund_title = '特殊退款处理' |
| | | </if> |
| | | <if test="data.specialRefund == null or !data.specialRefund"> |
| | | UNION ALL |
| | | SELECT |
| | | re.id, |
| | | re.`code`, |
| | | re.refund_code, |
| | | re.refund_title, |
| | | re.refund_reason, |
| | | re.refund_amount, |
| | | 0 as balance_refund_amount, |
| | | re.refund_amount as third_refund_amount, |
| | | re.refund_total_amount, |
| | | re.refund_time, |
| | | re.pay_type, |
| | | re.pay_amount, |
| | | re.refund_remark, |
| | | so.serial_number, |
| | | so.payment_amount, |
| | | so.create_time as pay_time, |
| | | so.id as order_id, |
| | | so.app_user_id as user_id, |
| | | null as site_id, |
| | | 3 as pay_method, |
| | | 2 as type |
| | | FROM t_shopping_order_refund re |
| | | LEFT JOIN t_shopping_order so on re.shopping_order_id = so.id |
| | | UNION ALL |
| | | SELECT |
| | | vr.id, |
| | | vr.`code`, |
| | | vr.refund_code, |
| | | vr.refund_title, |
| | | vr.refund_reason, |
| | | vr.refund_amount, |
| | | 0 as balance_refund_amount, |
| | | vr.refund_amount as third_refund_amount, |
| | | vr.refund_total_amount, |
| | | vr.refund_time, |
| | | vr.pay_type, |
| | | vr.pay_amount, |
| | | vr.refund_remark, |
| | | vo.serial_number, |
| | | vo.payment_amount, |
| | | vo.create_time as pay_time, |
| | | vo.id as order_id, |
| | | vo.app_user_id as user_id, |
| | | null as site_id, |
| | | 3 as pay_method, |
| | | 3 as type |
| | | FROM t_vip_order_refund vr |
| | | LEFT JOIN t_vip_order vo on vr.vip_order_id = vo.id |
| | | </if> |
| | | ) o |
| | | <where> |
| | | <if test="data.code != null and data.code != ''"> |
| | | AND o.code LIKE CONCAT('%',#{data.code},'%') |
| | | </if> |
| | | <if test="data.refundCode != null and data.refundCode != ''"> |
| | | AND o.refund_code LIKE CONCAT('%',#{data.refundCode},'%') |
| | | </if> |
| | | <if test="data.serialNumber != null and data.serialNumber != ''"> |
| | | AND o.serail_number LIKE CONCAT('%',#{data.serialNumber},'%') |
| | | </if> |
| | | <if test="data.specialRefund != null and data.specialRefund"> |
| | | AND o.refund_title = '特殊退款处理' |
| | | </if> |
| | | <if test="data.siteIds != null and data.siteIds.size() > 0"> |
| | | AND (o.type != 1 OR o.site_id IN |
| | | <foreach collection="data.siteIds" item="siteId" open="(" separator="," close=")"> |
| | | #{siteId} |
| | | </foreach> |
| | | ) |
| | | </if> |
| | | </where> |
| | | order by o.refund_time desc |
| | | |
| | | </select> |
| | | <select id="getRefundListWithoutOrderJoin" resultType="com.ruoyi.order.api.model.TChargingOrderRefund"> |
| | | <!-- |
| | | 退款列表(筛选逆反查版)。serialNumber/siteIds 筛选时,先由 Service 按条件查出订单 id 列表, |
| | | 再按各类型订单 id IN 过滤退款表(IN 为退款表分片键,MyCat 可路由),替代跨分片 LEFT JOIN。 |
| | | type1/type2/type3 订单 id:null = 不过滤;空列表 = 无匹配(AND 1=0)。 |
| | | 各分支同样内联 ORDER BY + LIMIT 下推。 |
| | | --> |
| | | <select id="getRefundListByOrderIds" resultType="com.ruoyi.order.api.model.TChargingOrderRefund"> |
| | | SELECT * FROM ( |
| | | SELECT |
| | | (SELECT |
| | | re.id, |
| | | re.`code`, |
| | | re.refund_code, |
| | |
| | | <if test="data.refundCode != null and data.refundCode != ''"> |
| | | AND re.refund_code LIKE CONCAT('%', #{data.refundCode}, '%') |
| | | </if> |
| | | <if test="data.refundTime1 != null and data.refundTime1 != ''"> |
| | | AND re.refund_time >= #{data.refundTime1} |
| | | </if> |
| | | <if test="data.refundTime2 != null and data.refundTime2 != ''"> |
| | | AND re.refund_time <= #{data.refundTime2} |
| | | </if> |
| | | <choose> |
| | | <when test="type1OrderIds != null and type1OrderIds.size() > 0"> |
| | | AND re.charging_order_id IN |
| | | <foreach collection="type1OrderIds" item="id" open="(" separator="," close=")"> |
| | | #{id} |
| | | </foreach> |
| | | </when> |
| | | <otherwise> |
| | | <if test="type1OrderIds != null"> |
| | | AND 1 = 0 |
| | | </if> |
| | | </otherwise> |
| | | </choose> |
| | | </where> |
| | | ORDER BY re.refund_time DESC |
| | | LIMIT #{branchLimit}) |
| | | <if test="data.specialRefund == null or !data.specialRefund"> |
| | | UNION ALL |
| | | SELECT |
| | | (SELECT |
| | | re.id, |
| | | re.`code`, |
| | | re.refund_code, |
| | |
| | | <if test="data.refundCode != null and data.refundCode != ''"> |
| | | AND re.refund_code LIKE CONCAT('%', #{data.refundCode}, '%') |
| | | </if> |
| | | <if test="data.refundTime1 != null and data.refundTime1 != ''"> |
| | | AND re.refund_time >= #{data.refundTime1} |
| | | </if> |
| | | <if test="data.refundTime2 != null and data.refundTime2 != ''"> |
| | | AND re.refund_time <= #{data.refundTime2} |
| | | </if> |
| | | <choose> |
| | | <when test="type2OrderIds != null and type2OrderIds.size() > 0"> |
| | | AND re.shopping_order_id IN |
| | | <foreach collection="type2OrderIds" item="id" open="(" separator="," close=")"> |
| | | #{id} |
| | | </foreach> |
| | | </when> |
| | | <otherwise> |
| | | <if test="type2OrderIds != null"> |
| | | AND 1 = 0 |
| | | </if> |
| | | </otherwise> |
| | | </choose> |
| | | </where> |
| | | ORDER BY re.refund_time DESC |
| | | LIMIT #{branchLimit}) |
| | | UNION ALL |
| | | SELECT |
| | | (SELECT |
| | | re.id, |
| | | re.`code`, |
| | | re.refund_code, |
| | |
| | | <if test="data.refundCode != null and data.refundCode != ''"> |
| | | AND re.refund_code LIKE CONCAT('%', #{data.refundCode}, '%') |
| | | </if> |
| | | <if test="data.refundTime1 != null and data.refundTime1 != ''"> |
| | | AND re.refund_time >= #{data.refundTime1} |
| | | </if> |
| | | <if test="data.refundTime2 != null and data.refundTime2 != ''"> |
| | | AND re.refund_time <= #{data.refundTime2} |
| | | </if> |
| | | <choose> |
| | | <when test="type3OrderIds != null and type3OrderIds.size() > 0"> |
| | | AND re.vip_order_id IN |
| | | <foreach collection="type3OrderIds" item="id" open="(" separator="," close=")"> |
| | | #{id} |
| | | </foreach> |
| | | </when> |
| | | <otherwise> |
| | | <if test="type3OrderIds != null"> |
| | | AND 1 = 0 |
| | | </if> |
| | | </otherwise> |
| | | </choose> |
| | | </where> |
| | | ORDER BY re.refund_time DESC |
| | | LIMIT #{branchLimit}) |
| | | </if> |
| | | ) o |
| | | ORDER BY o.refund_time DESC |
| | | LIMIT #{offset}, #{limit} |
| | | </select> |
| | | <!-- |
| | | 退款总数(筛选逆反查版),与 getRefundListByOrderIds 同构,三分支 COUNT 可下推。 |
| | | --> |
| | | <select id="countRefundListByOrderIds" resultType="long"> |
| | | SELECT SUM(cnt) FROM ( |
| | | (SELECT COUNT(*) AS cnt |
| | | FROM t_charging_order_refund re |
| | | <where> |
| | | <if test="data.specialRefund != null and data.specialRefund"> |
| | | AND re.refund_title = '特殊退款处理' |
| | | </if> |
| | | <if test="data.code != null and data.code != ''"> |
| | | AND re.code LIKE CONCAT('%', #{data.code}, '%') |
| | | </if> |
| | | <if test="data.refundCode != null and data.refundCode != ''"> |
| | | AND re.refund_code LIKE CONCAT('%', #{data.refundCode}, '%') |
| | | </if> |
| | | <if test="data.refundTime1 != null and data.refundTime1 != ''"> |
| | | AND re.refund_time >= #{data.refundTime1} |
| | | </if> |
| | | <if test="data.refundTime2 != null and data.refundTime2 != ''"> |
| | | AND re.refund_time <= #{data.refundTime2} |
| | | </if> |
| | | <choose> |
| | | <when test="type1OrderIds != null and type1OrderIds.size() > 0"> |
| | | AND re.charging_order_id IN |
| | | <foreach collection="type1OrderIds" item="id" open="(" separator="," close=")"> |
| | | #{id} |
| | | </foreach> |
| | | </when> |
| | | <otherwise> |
| | | <if test="type1OrderIds != null"> |
| | | AND 1 = 0 |
| | | </if> |
| | | </otherwise> |
| | | </choose> |
| | | </where>) |
| | | <if test="data.specialRefund == null or !data.specialRefund"> |
| | | UNION ALL |
| | | (SELECT COUNT(*) AS cnt |
| | | FROM t_shopping_order_refund re |
| | | <where> |
| | | <if test="data.code != null and data.code != ''"> |
| | | AND re.code LIKE CONCAT('%', #{data.code}, '%') |
| | | </if> |
| | | <if test="data.refundCode != null and data.refundCode != ''"> |
| | | AND re.refund_code LIKE CONCAT('%', #{data.refundCode}, '%') |
| | | </if> |
| | | <if test="data.refundTime1 != null and data.refundTime1 != ''"> |
| | | AND re.refund_time >= #{data.refundTime1} |
| | | </if> |
| | | <if test="data.refundTime2 != null and data.refundTime2 != ''"> |
| | | AND re.refund_time <= #{data.refundTime2} |
| | | </if> |
| | | <choose> |
| | | <when test="type2OrderIds != null and type2OrderIds.size() > 0"> |
| | | AND re.shopping_order_id IN |
| | | <foreach collection="type2OrderIds" item="id" open="(" separator="," close=")"> |
| | | #{id} |
| | | </foreach> |
| | | </when> |
| | | <otherwise> |
| | | <if test="type2OrderIds != null"> |
| | | AND 1 = 0 |
| | | </if> |
| | | </otherwise> |
| | | </choose> |
| | | </where>) |
| | | UNION ALL |
| | | (SELECT COUNT(*) AS cnt |
| | | FROM t_vip_order_refund re |
| | | <where> |
| | | <if test="data.code != null and data.code != ''"> |
| | | AND re.code LIKE CONCAT('%', #{data.code}, '%') |
| | | </if> |
| | | <if test="data.refundCode != null and data.refundCode != ''"> |
| | | AND re.refund_code LIKE CONCAT('%', #{data.refundCode}, '%') |
| | | </if> |
| | | <if test="data.refundTime1 != null and data.refundTime1 != ''"> |
| | | AND re.refund_time >= #{data.refundTime1} |
| | | </if> |
| | | <if test="data.refundTime2 != null and data.refundTime2 != ''"> |
| | | AND re.refund_time <= #{data.refundTime2} |
| | | </if> |
| | | <choose> |
| | | <when test="type3OrderIds != null and type3OrderIds.size() > 0"> |
| | | AND re.vip_order_id IN |
| | | <foreach collection="type3OrderIds" item="id" open="(" separator="," close=")"> |
| | | #{id} |
| | | </foreach> |
| | | </when> |
| | | <otherwise> |
| | | <if test="type3OrderIds != null"> |
| | | AND 1 = 0 |
| | | </if> |
| | | </otherwise> |
| | | </choose> |
| | | </where>) |
| | | </if> |
| | | ) t |
| | | </select> |
| | | <!-- |
| | | 按支付流水号模糊匹配充电订单 id(逆反查第一步)。 |
| | | 注意:前导通配符 LIKE '%x%' 无法走 recharge_serial_number 索引,MyCat 广播 50 张分片表全表扫描; |
| | | 匹配行一般极少(流水号近似唯一),结果集小,可接受。ORDER BY id 保证截断时结果确定性。 |
| | | --> |
| | | <select id="listChargingOrderIdsBySerialNumber" resultType="long"> |
| | | SELECT id FROM t_charging_order |
| | | WHERE recharge_serial_number LIKE CONCAT('%', #{serialNumber}, '%') |
| | | ORDER BY id DESC |
| | | LIMIT #{limit} |
| | | </select> |
| | | <!-- 按支付流水号模糊匹配商城订单 id(同前导通配符说明,广播 20 张分片表) --> |
| | | <select id="listShoppingOrderIdsBySerialNumber" resultType="long"> |
| | | SELECT id FROM t_shopping_order |
| | | WHERE serial_number LIKE CONCAT('%', #{serialNumber}, '%') |
| | | ORDER BY id DESC |
| | | LIMIT #{limit} |
| | | </select> |
| | | <!-- 按支付流水号模糊匹配会员订单 id(同前导通配符说明,广播 20 张分片表) --> |
| | | <select id="listVipOrderIdsBySerialNumber" resultType="long"> |
| | | SELECT id FROM t_vip_order |
| | | WHERE serial_number LIKE CONCAT('%', #{serialNumber}, '%') |
| | | ORDER BY id DESC |
| | | LIMIT #{limit} |
| | | </select> |
| | | <!-- 按站点匹配充电订单 id(逆反查第一步,site_id 走新增索引;ORDER BY id 保证截断时结果确定性) --> |
| | | <select id="listChargingOrderIdsBySiteIds" resultType="long"> |
| | | SELECT id FROM t_charging_order |
| | | WHERE site_id IN |
| | | <foreach collection="siteIds" item="siteId" open="(" separator="," close=")"> |
| | | #{siteId} |
| | | </foreach> |
| | | ORDER BY id DESC |
| | | LIMIT #{limit} |
| | | </select> |
| | | <!-- |
| | | 退款列表(分片下推版)。 |
| | | 三个 UNION 分支各自单表查询,分支内 ORDER BY + LIMIT 可被 MyCat 下推到每张分片表(每表最多取 offset+limit 行), |
| | | 代理层只归并三分支共 3×(offset+limit) 行再取页。相比旧版(90 张分片表全量拉回代理层排序)避免全量传输。 |
| | | --> |
| | | <select id="getRefundListPage" resultType="com.ruoyi.order.api.model.TChargingOrderRefund"> |
| | | SELECT * FROM ( |
| | | (SELECT |
| | | re.id, |
| | | re.`code`, |
| | | re.refund_code, |
| | | re.refund_title, |
| | | re.refund_reason, |
| | | re.refund_amount, |
| | | re.balance_refund_amount, |
| | | re.third_refund_amount, |
| | | re.refund_total_amount, |
| | | re.refund_time, |
| | | re.pay_type, |
| | | re.pay_amount, |
| | | re.refund_remark, |
| | | re.charging_order_id AS order_id, |
| | | 1 AS type |
| | | FROM t_charging_order_refund re |
| | | <where> |
| | | <if test="data.specialRefund != null and data.specialRefund"> |
| | | AND re.refund_title = '特殊退款处理' |
| | | </if> |
| | | <if test="data.code != null and data.code != ''"> |
| | | AND re.code LIKE CONCAT('%', #{data.code}, '%') |
| | | </if> |
| | | <if test="data.refundCode != null and data.refundCode != ''"> |
| | | AND re.refund_code LIKE CONCAT('%', #{data.refundCode}, '%') |
| | | </if> |
| | | <if test="data.refundTime1 != null and data.refundTime1 != ''"> |
| | | AND re.refund_time >= #{data.refundTime1} |
| | | </if> |
| | | <if test="data.refundTime2 != null and data.refundTime2 != ''"> |
| | | AND re.refund_time <= #{data.refundTime2} |
| | | </if> |
| | | </where> |
| | | ORDER BY re.refund_time DESC |
| | | LIMIT #{branchLimit}) |
| | | <if test="data.specialRefund == null or !data.specialRefund"> |
| | | UNION ALL |
| | | (SELECT |
| | | re.id, |
| | | re.`code`, |
| | | re.refund_code, |
| | | re.refund_title, |
| | | re.refund_reason, |
| | | re.refund_amount, |
| | | 0 AS balance_refund_amount, |
| | | re.refund_amount AS third_refund_amount, |
| | | re.refund_total_amount, |
| | | re.refund_time, |
| | | re.pay_type, |
| | | re.pay_amount, |
| | | re.refund_remark, |
| | | re.shopping_order_id AS order_id, |
| | | 2 AS type |
| | | FROM t_shopping_order_refund re |
| | | <where> |
| | | <if test="data.code != null and data.code != ''"> |
| | | AND re.code LIKE CONCAT('%', #{data.code}, '%') |
| | | </if> |
| | | <if test="data.refundCode != null and data.refundCode != ''"> |
| | | AND re.refund_code LIKE CONCAT('%', #{data.refundCode}, '%') |
| | | </if> |
| | | <if test="data.refundTime1 != null and data.refundTime1 != ''"> |
| | | AND re.refund_time >= #{data.refundTime1} |
| | | </if> |
| | | <if test="data.refundTime2 != null and data.refundTime2 != ''"> |
| | | AND re.refund_time <= #{data.refundTime2} |
| | | </if> |
| | | </where> |
| | | ORDER BY re.refund_time DESC |
| | | LIMIT #{branchLimit}) |
| | | UNION ALL |
| | | (SELECT |
| | | re.id, |
| | | re.`code`, |
| | | re.refund_code, |
| | | re.refund_title, |
| | | re.refund_reason, |
| | | re.refund_amount, |
| | | 0 AS balance_refund_amount, |
| | | re.refund_amount AS third_refund_amount, |
| | | re.refund_total_amount, |
| | | re.refund_time, |
| | | re.pay_type, |
| | | re.pay_amount, |
| | | re.refund_remark, |
| | | re.vip_order_id AS order_id, |
| | | 3 AS type |
| | | FROM t_vip_order_refund re |
| | | <where> |
| | | <if test="data.code != null and data.code != ''"> |
| | | AND re.code LIKE CONCAT('%', #{data.code}, '%') |
| | | </if> |
| | | <if test="data.refundCode != null and data.refundCode != ''"> |
| | | AND re.refund_code LIKE CONCAT('%', #{data.refundCode}, '%') |
| | | </if> |
| | | <if test="data.refundTime1 != null and data.refundTime1 != ''"> |
| | | AND re.refund_time >= #{data.refundTime1} |
| | | </if> |
| | | <if test="data.refundTime2 != null and data.refundTime2 != ''"> |
| | | AND re.refund_time <= #{data.refundTime2} |
| | | </if> |
| | | </where> |
| | | ORDER BY re.refund_time DESC |
| | | LIMIT #{branchLimit}) |
| | | </if> |
| | | ) o |
| | | ORDER BY o.refund_time DESC |
| | | LIMIT #{offset}, #{limit} |
| | | </select> |
| | | <!-- |
| | | 退款总数(分片下推版)。三分支各自 COUNT(可下推到每张分片表),代理层只 SUM 三个数。 |
| | | 旧版由分页拦截器生成 SELECT COUNT(*) FROM (90 表全量 UNION),MyCat 无法下推导致全量扫描。 |
| | | --> |
| | | <select id="countRefundList" resultType="long"> |
| | | SELECT SUM(cnt) FROM ( |
| | | (SELECT COUNT(*) AS cnt |
| | | FROM t_charging_order_refund re |
| | | <where> |
| | | <if test="data.specialRefund != null and data.specialRefund"> |
| | | AND re.refund_title = '特殊退款处理' |
| | | </if> |
| | | <if test="data.code != null and data.code != ''"> |
| | | AND re.code LIKE CONCAT('%', #{data.code}, '%') |
| | | </if> |
| | | <if test="data.refundCode != null and data.refundCode != ''"> |
| | | AND re.refund_code LIKE CONCAT('%', #{data.refundCode}, '%') |
| | | </if> |
| | | <if test="data.refundTime1 != null and data.refundTime1 != ''"> |
| | | AND re.refund_time >= #{data.refundTime1} |
| | | </if> |
| | | <if test="data.refundTime2 != null and data.refundTime2 != ''"> |
| | | AND re.refund_time <= #{data.refundTime2} |
| | | </if> |
| | | </where>) |
| | | <if test="data.specialRefund == null or !data.specialRefund"> |
| | | UNION ALL |
| | | (SELECT COUNT(*) AS cnt |
| | | FROM t_shopping_order_refund re |
| | | <where> |
| | | <if test="data.code != null and data.code != ''"> |
| | | AND re.code LIKE CONCAT('%', #{data.code}, '%') |
| | | </if> |
| | | <if test="data.refundCode != null and data.refundCode != ''"> |
| | | AND re.refund_code LIKE CONCAT('%', #{data.refundCode}, '%') |
| | | </if> |
| | | <if test="data.refundTime1 != null and data.refundTime1 != ''"> |
| | | AND re.refund_time >= #{data.refundTime1} |
| | | </if> |
| | | <if test="data.refundTime2 != null and data.refundTime2 != ''"> |
| | | AND re.refund_time <= #{data.refundTime2} |
| | | </if> |
| | | </where>) |
| | | UNION ALL |
| | | (SELECT COUNT(*) AS cnt |
| | | FROM t_vip_order_refund re |
| | | <where> |
| | | <if test="data.code != null and data.code != ''"> |
| | | AND re.code LIKE CONCAT('%', #{data.code}, '%') |
| | | </if> |
| | | <if test="data.refundCode != null and data.refundCode != ''"> |
| | | AND re.refund_code LIKE CONCAT('%', #{data.refundCode}, '%') |
| | | </if> |
| | | <if test="data.refundTime1 != null and data.refundTime1 != ''"> |
| | | AND re.refund_time >= #{data.refundTime1} |
| | | </if> |
| | | <if test="data.refundTime2 != null and data.refundTime2 != ''"> |
| | | AND re.refund_time <= #{data.refundTime2} |
| | | </if> |
| | | </where>) |
| | | </if> |
| | | ) t |
| | | </select> |
| | | <select id="chargingOrderGroup" resultType="com.ruoyi.common.core.dto.ChargingOrderGroup"> |
| | | SELECT SUM(tc.charging_capacity) as charging_capacity,tc.site_id |