2022-04-14 17:00:00 +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">
2022-04-21 10:22:28 +08:00
<mapper namespace= "com.xhpc.activity.mapper.XhpcClearingCheckoutMapper" >
<resultMap id= "BaseResultMap" type= "com.xhpc.activity.domain.XhpcClearingCheckoutDomain" >
2022-04-14 17:00:00 +08:00
<id column= "clearing_checkout_id" jdbcType= "BIGINT" property= "clearingCheckoutId" />
<result column= "clearing_bank_id" jdbcType= "BIGINT" property= "clearingBankId" />
<result column= "apply_amount" jdbcType= "DECIMAL" property= "applyAmount" />
2022-06-21 11:31:36 +08:00
<result column= "apply_power_amount" property= "applyPowerAmount" />
<result column= "apply_service_amount" property= "applyServiceAmount" />
2022-04-14 17:00:00 +08:00
<result column= "handling_fee" jdbcType= "DECIMAL" property= "handlingFee" />
<result column= "bank_fee" jdbcType= "DECIMAL" property= "bankFee" />
<result column= "received_amount" jdbcType= "DECIMAL" property= "receivedAmount" />
2022-06-21 11:31:36 +08:00
<result column= "received_power_amount" property= "receivedPowerAmount" />
<result column= "received_service_amount" property= "receivedServiceAmount" />
2022-04-14 17:00:00 +08:00
<result column= "status" jdbcType= "INTEGER" property= "status" />
<result column= "del_flag" jdbcType= "INTEGER" property= "delFlag" />
<result column= "operator_id" jdbcType= "BIGINT" property= "operatorId" />
<result column= "tenant_id" jdbcType= "VARCHAR" property= "tenantId" />
<result column= "create_by" jdbcType= "VARCHAR" property= "createBy" />
<result column= "create_time" jdbcType= "TIMESTAMP" property= "createTime" />
<result column= "update_by" jdbcType= "VARCHAR" property= "updateBy" />
<result column= "update_time" jdbcType= "TIMESTAMP" property= "updateTime" />
<result column= "check_by" jdbcType= "VARCHAR" property= "checkBy" />
<result column= "check_time" jdbcType= "TIMESTAMP" property= "checkTime" />
</resultMap>
<sql id= "Base_Column_List" >
2022-06-21 11:31:36 +08:00
cc.clearing_checkout_id, cc.clearing_bank_id, cc.apply_amount, cc.apply_power_amount, cc.apply_service_amount, cc.handling_fee,
2026-06-12 16:10:39 +08:00
cc.received_amount, cc.bank_fee, cc.del_flag, cc.received_power_amount, cc.received_service_amount,cc.clearing_price,
2022-04-14 17:00:00 +08:00
cc.`status`, cc.operator_id, cc.tenant_id, cc.create_by, cc.create_time, cc.update_by, cc.update_time, cc.check_by, cc.check_time
</sql>
2022-04-21 10:22:28 +08:00
<select id= "selectByPrimaryKey" parameterType= "java.lang.Long" resultType= "com.xhpc.activity.domain.XhpcClearingCheckoutDomain" >
2022-06-21 11:31:36 +08:00
select
2022-04-14 17:00:00 +08:00
<include refid= "Base_Column_List" /> , xo.name as 'operator_name'
from xhpc_clearing_checkout cc
left join xhpc_operator xo on xo.operator_id = cc.operator_id
where cc.clearing_checkout_id = #{clearingCheckoutId,jdbcType=BIGINT}
</select>
2022-04-21 10:22:28 +08:00
<select id= "selectByParams" resultType= "com.xhpc.activity.domain.XhpcClearingCheckoutDomain" >
2022-04-14 17:00:00 +08:00
select
2022-05-05 17:30:10 +08:00
<include refid= "Base_Column_List" /> ,
xo.name as 'operator_name',
xt.tenant_name
2022-04-14 17:00:00 +08:00
from xhpc_clearing_checkout cc
left join xhpc_operator xo on xo.operator_id = cc.operator_id
2022-05-05 17:30:10 +08:00
left join xhpc_tenant xt on xo.tenant_id=xt.tenant_id
2022-04-14 17:00:00 +08:00
where cc.del_flag =0
<if test= "params.status!=null and params.status!=''" >
and cc.status=#{params.status}
</if>
<if test= "params.tenantId!=null and params.tenantId!=''" >
and cc.tenant_id=#{params.tenantId}
</if>
<if test= "params.operatorId!=null and params.operatorId!='' " >
and cc.operator_id=#{params.operatorId}
</if>
<if test= "params.startTime!=null and params.startTime!=''" >
and cc.create_time <![CDATA[ >= ]]> #{params.startTime}
</if>
<if test= "params.endTime!=null and params.endTime!=''" >
and cc.create_time <![CDATA[ <= ]]> #{params.endTime}
</if>
2022-05-09 17:14:58 +08:00
<if test= "params.type==1" >
2022-05-13 09:54:53 +08:00
and cc.operator_id in (select operator_id from xhpc_charging_station where charging_station_id in(select charging_station_id from xhpc_charging_station where operator_id=#{params.logOperatorId}))
2022-05-09 17:14:58 +08:00
</if>
<if test= "params.type==2" >
2022-05-13 09:54:53 +08:00
and cc.operator_id in (select operator_id from xhpc_charging_station where charging_station_id in(select charging_station_id from xhpc_user_privilege where user_id=#{params.logOperatorId}))
2022-05-09 17:14:58 +08:00
</if>
2026-06-12 16:10:39 +08:00
order by cc.clearing_checkout_id desc,cc.status
2022-04-14 17:00:00 +08:00
</select>
2026-06-12 16:10:39 +08:00
<select id= "getXhpcOperatorParams" resultType= "map" >
SELECT
xt.tenant_id AS 'tenantId',
xt.tenant_name AS 'tenantName',
xo.operator_id AS 'operatorId',
xo.name AS 'operatorName'
FROM xhpc_operator xo
LEFT JOIN xhpc_tenant xt ON xo.tenant_id = xt.tenant_id
WHERE xo.del_flag = 0
<if test= "params.tenantId!=null and params.tenantId!=''" >
AND xo.tenant_id = #{params.tenantId}
</if>
<if test= "params.operatorId!=null and params.operatorId!='' " >
AND xo.operator_id = #{params.operatorId}
</if>
</select>
2022-05-05 17:30:10 +08:00
<select id= "selectCheckoutMapByParams" resultType= "map" >
2026-06-12 16:10:39 +08:00
SELECT
xt.tenant_id AS 'tenantId',
xt.tenant_name AS 'tenantName',
xo.operator_id AS 'operatorId',
xo.name AS 'operatorName',
IFNULL(ho.unClearingAmount, 0) AS 'unClearingAmount',
IFNULL(cho.cashAmount, 0) AS 'cashAmount',
IFNULL(cc1.applyAmount, 0) AS 'applyAmount',
IFNULL(cc2.cashedAmount, 0) AS 'cashedAmount'
FROM xhpc_operator xo
2022-05-05 17:30:10 +08:00
LEFT JOIN (
2026-06-12 16:10:39 +08:00
SELECT operator_id, SUM(received_amount) AS applyAmount
FROM xhpc_clearing_checkout
WHERE `status` = 1 AND del_flag = 0
GROUP BY operator_id
) cc1 ON xo.operator_id = cc1.operator_id
LEFT JOIN (
SELECT operator_id, SUM(received_amount) AS cashedAmount
FROM xhpc_clearing_checkout
WHERE `status` = 6 AND del_flag = 0
GROUP BY operator_id
) cc2 ON xo.operator_id = cc2.operator_id
LEFT JOIN xhpc_tenant xt ON xo.tenant_id = xt.tenant_id
LEFT JOIN (
SELECT
IFNULL(SUM(ho.act_power_price + ho.act_service_price), 0) AS unClearingAmount,
ct.operator_id AS operatorId
FROM xhpc_clearing_history_order ho
LEFT JOIN xhpc_charging_station ct ON ct.charging_station_id = ho.charging_station_id
WHERE ho.check_status NOT IN (1, 2)
AND ho.del_flag = 0
2024-03-07 11:19:20 +08:00
<if test= "params.startTime!=null and params.startTime!='' " >
2026-06-12 16:10:39 +08:00
AND ho.end_time > = #{params.startTime}
2024-03-07 11:19:20 +08:00
</if>
<if test= "params.endTime!=null and params.endTime!='' " >
2026-06-12 16:10:39 +08:00
AND ho.end_time < = #{params.endTime}
2024-03-07 11:19:20 +08:00
</if>
2022-05-05 17:30:10 +08:00
GROUP BY ct.operator_id
2026-06-12 16:10:39 +08:00
) ho ON ho.operatorId = xo.operator_id
2022-05-05 17:30:10 +08:00
LEFT JOIN (
2026-06-12 16:10:39 +08:00
SELECT
IFNULL(SUM(ho.act_power_price + ho.act_service_price), 0) AS cashAmount,
ho.operator_id AS operatorId
FROM xhpc_clearing_history_order ho
WHERE ho.check_status = 2
AND ho.del_flag = 0
AND ho.clearing_checkout_id IS NULL
<if test= "params.startTime!=null and params.startTime!='' " >
AND ho.end_time > = #{params.startTime}
</if>
<if test= "params.endTime!=null and params.endTime!='' " >
AND ho.end_time < = #{params.endTime}
</if>
2024-03-07 11:19:20 +08:00
GROUP BY ho.operator_id
2026-06-12 16:10:39 +08:00
) cho ON cho.operatorId = xo.operator_id
WHERE xo.del_flag = 0
2022-05-05 17:30:10 +08:00
<if test= "params.tenantId!=null and params.tenantId!=''" >
2026-06-12 16:10:39 +08:00
AND xo.tenant_id = #{params.tenantId}
2022-05-05 17:30:10 +08:00
</if>
<if test= "params.operatorId!=null and params.operatorId!='' " >
2026-06-12 16:10:39 +08:00
AND xo.operator_id = #{params.operatorId}
2022-05-05 17:30:10 +08:00
</if>
</select>
2022-04-14 17:00:00 +08:00
<select id= "selectAmountByStatus" resultType= "java.math.BigDecimal" >
2022-05-20 17:46:03 +08:00
select ifnull(sum(received_amount), 0) from xhpc_clearing_checkout where del_flag =0 and operator_id=#{operatorId} and status=#{status}
2022-04-14 17:00:00 +08:00
</select>
2026-06-12 16:10:39 +08:00
2022-04-21 10:22:28 +08:00
<select id= "selectOrderMapByCheckoutIds" resultType= "com.xhpc.activity.vo.CheckoutBankVo" >
2022-04-14 17:00:00 +08:00
select
'RMB' as 'curreyType',
date_format(now(), '%Y%m%d') as 'date',
'' as 'detailFlag',
cc.clearing_checkout_id as 'index',
'' as 'payBank',
'' as 'payBankAccount',
'' as 'payBankName',
cb.bank_name as 'receiveBank',
'' as 'receiveProvice',
'' as 'receiveCity',
'' as 'receiveCode',
cb.bank_no as 'receiveAccount',
cb.operator_account as 'receiveName',
sum(cc.received_amount) as 'amount',
'' as 'purposes',
'' as 'remark',
'0' as 'transType',
'' as 'mobile',
'' as 'customeIndex',
'' as 'applyCheckNo'
from xhpc_clearing_checkout cc
left join xhpc_clearing_bank cb on cb.clearing_bank_id=cc.clearing_bank_id
where find_in_set(cc.clearing_checkout_id, #{checkoutIds})
group by cc.clearing_bank_id, cc.operator_id
</select>
2022-05-20 16:25:42 +08:00
<select id= "selectMapGroupByStatus" resultType= "java.util.Map" >
SELECT `status`, GROUP_CONCAT(clearing_checkout_id) as 'ids' from xhpc_clearing_checkout
WHERE del_flag=0 and find_in_set(clearing_checkout_id, #{checkoutIds})
GROUP BY status
</select>
<select id= "selectIdsByStatusAndIds" resultType= "java.lang.String" >
SELECT GROUP_CONCAT(clearing_checkout_id) as 'ids' from xhpc_clearing_checkout
WHERE del_flag=0 and find_in_set(clearing_checkout_id, #{checkoutIds}) and status=#{status}
</select>
<update id= "deleteLogicByPrimaryKey" parameterType= "java.lang.Long" >
2022-04-14 17:00:00 +08:00
update xhpc_clearing_checkout set del_flag=2
where clearing_checkout_id = #{clearingCheckoutId,jdbcType=BIGINT}
</update>
<delete id= "deleteByPrimaryKey" parameterType= "java.lang.Long" >
delete from xhpc_clearing_checkout
where clearing_checkout_id = #{clearingCheckoutId,jdbcType=BIGINT}
</delete>
2022-04-21 10:22:28 +08:00
<insert id= "insert" keyColumn= "clearing_checkout_id" keyProperty= "clearingCheckoutId" parameterType= "com.xhpc.activity.domain.XhpcClearingCheckoutDomain" useGeneratedKeys= "true" >
2022-06-21 11:31:36 +08:00
insert into xhpc_clearing_checkout (clearing_bank_id, apply_amount, apply_power_amount, apply_service_amount,
handling_fee, bank_fee,
received_amount, received_power_amount, received_service_amount, del_flag, `status`, operator_id, tenant_id,
2022-04-14 17:00:00 +08:00
create_by, create_time,
2026-06-12 16:10:39 +08:00
update_by,update_time, check_by, check_time,clearing_price)
2022-06-21 11:31:36 +08:00
values (#{clearingBankId,jdbcType=BIGINT}, #{applyAmount,jdbcType=DECIMAL}, #{applyPowerAmount}, #{applyServiceAmount},
#{handlingFee,jdbcType=DECIMAL}, #{bankFee},
#{receivedAmount,jdbcType=DECIMAL}, #{receivedPowerAmount}, #{receivedServiceAmount}, 0, #{status}, #{operatorId}, #{tenantId,jdbcType=VARCHAR},
2022-04-14 17:00:00 +08:00
#{createBy,jdbcType=VARCHAR}, sysdate(), #{updateBy,jdbcType=VARCHAR},
2026-06-12 16:10:39 +08:00
sysdate(), #{checkBy}, sysdate(),#{clearingPrice})
2022-04-14 17:00:00 +08:00
</insert>
2022-04-21 10:22:28 +08:00
<update id= "updateByPrimaryKey" parameterType= "com.xhpc.activity.domain.XhpcClearingCheckoutDomain" >
2022-04-14 17:00:00 +08:00
update xhpc_clearing_checkout
set clearing_bank_id = #{clearingBankId,jdbcType=BIGINT},
apply_amount = #{applyAmount,jdbcType=DECIMAL},
2022-06-21 11:31:36 +08:00
apply_power_amount=#{applyPowerAmount},
apply_service_amount=#{applyServiceAmount},
2022-04-14 17:00:00 +08:00
handling_fee = #{handlingFee,jdbcType=DECIMAL},
bank_fee = #{bankFee},
received_amount = #{receivedAmount,jdbcType=DECIMAL},
2022-06-21 11:31:36 +08:00
received_power_amount=#{receivedPowerAmount},
received_service_amount=#{receivedServiceAmount}
2022-04-14 17:00:00 +08:00
`status` = #{status,jdbcType=INTEGER},
update_by = #{updateBy,jdbcType=VARCHAR},
update_time = sysdate()
where clearing_checkout_id = #{clearingCheckoutId,jdbcType=BIGINT}
</update>
<update id= "checkByPrimaryKey" >
update xhpc_clearing_checkout
set `status` = #{status,jdbcType=INTEGER},
check_by = #{updateBy,jdbcType=VARCHAR},
check_time = #{updateTime,jdbcType=TIMESTAMP}
where clearing_checkout_id = #{clearingCheckoutId,jdbcType=BIGINT}
</update>
<update id= "updateStatusByPrimaryKey" >
update xhpc_clearing_checkout
set `status` = #{status,jdbcType=INTEGER},
update_by = #{updateBy,jdbcType=VARCHAR},
update_time = sysdate()
where clearing_checkout_id = #{clearingCheckoutId,jdbcType=BIGINT}
</update>
<update id= "updateStatusByIds" >
update xhpc_clearing_checkout
set `status` = #{status}
where find_in_set(clearing_checkout_id, #{checkoutIds})
</update>
2026-06-12 16:10:39 +08:00
<select id= "selectUnclearingAmount" resultType= "java.math.BigDecimal" >
select
ifnull(sum(ho.act_total_price), 0)
from xhpc_clearing_history_order as ho
where ho.del_flag=0 and ho.check_status=0 and ho.operator_id=#{params.operatorId}
<if test= "params.startTime!=null and params.startTime!='' " >
AND ho.end_time > = #{params.startTime}
</if>
<if test= "params.endTime!=null and params.endTime!='' " >
AND ho.end_time < = #{params.endTime}
</if>
</select>
<select id= "selectClearingPrice" resultType= "map" >
select
ifnull(sum(ho.clearing_price), 0) as clearingPrice,
ifnull(sum(ho.act_service_price+ho.act_power_price), 0) as actTotalPrice
from xhpc_clearing_history_order as ho
where ho.check_status=2 and ho.del_flag=0 and ho.clearing_checkout_id is null and ho.operator_id=#{params.operatorId}
<if test= "params.startTime!=null and params.startTime!='' " >
AND ho.end_time > = #{params.startTime}
</if>
<if test= "params.endTime!=null and params.endTime!='' " >
AND ho.end_time < = #{params.endTime}
</if>
</select>
<select id= "selectCashedAmountOrCashingAmount" resultType= "map" >
SELECT
IFNULL(SUM(CASE WHEN status = 1 THEN received_amount ELSE 0 END), 0) AS cashingAmount,
IFNULL(SUM(CASE WHEN status = 6 THEN received_amount ELSE 0 END), 0) AS cashedAmount
FROM xhpc_clearing_checkout
WHERE del_flag = 0
AND operator_id = #{operatorId}
AND status IN (1, 6)
</select>
<select id= "selectUnclearingAmountBatch" resultType= "java.util.HashMap" >
SELECT
ho.operator_id as operatorId,
IFNULL(SUM(ho.act_total_price), 0) as unClearingAmount
FROM xhpc_clearing_history_order ho
WHERE ho.del_flag = 0
AND ho.check_status = 0
AND ho.operator_id IN
<foreach collection= "operatorIds" item= "operatorId" open= "(" separator= "," close= ")" >
#{operatorId}
</foreach>
<if test= "params.startTime != null and params.startTime != ''" >
AND ho.end_time > = #{params.startTime}
</if>
<if test= "params.endTime != null and params.endTime != ''" >
AND ho.end_time < = #{params.endTime}
</if>
GROUP BY ho.operator_id
</select>
<!-- 2. 批量查询已提现和提现中金额 -->
<select id= "selectCashedAmountOrCashingAmountBatch" resultType= "java.util.HashMap" >
SELECT
operator_id as operatorId,
IFNULL(SUM(CASE WHEN status = 1 THEN received_amount ELSE 0 END), 0) AS cashingAmount,
IFNULL(SUM(CASE WHEN status = 6 THEN received_amount ELSE 0 END), 0) AS cashedAmount
FROM xhpc_clearing_checkout
WHERE del_flag = 0
AND status IN (1, 6)
AND operator_id IN
<foreach collection= "operatorIds" item= "operatorId" open= "(" separator= "," close= ")" >
#{operatorId}
</foreach>
GROUP BY operator_id
</select>
<select id= "selectCashAmountYuBatch" resultType= "java.util.HashMap" >
SELECT
ho.operator_id as operatorId,
IFNULL(SUM(ho.act_power_price), 0) as powerAmount,
IFNULL(SUM(ho.act_service_price), 0) as serviceAmount
FROM xhpc_clearing_history_order ho
WHERE ho.check_status = 2
AND ho.del_flag = 0
AND ho.clearing_type = 0
AND ho.clearing_checkout_id IS NULL
AND ho.operator_id IN
<foreach collection= "operatorIds" item= "operatorId" open= "(" separator= "," close= ")" >
#{operatorId}
</foreach>
GROUP BY ho.operator_id
</select>
<select id= "selectClearingPriceBatch" resultType= "java.util.HashMap" >
SELECT
ho.operator_id as operatorId,
IFNULL(SUM(ho.clearing_price), 0) as clearingPrice,
IFNULL(SUM(ho.act_service_price + ho.act_power_price), 0) as actTotalPrice
FROM xhpc_clearing_history_order ho
WHERE ho.check_status = 2
AND ho.del_flag = 0
AND ho.clearing_checkout_id IS NULL
AND ho.operator_id IN
<foreach collection= "operatorIds" item= "operatorId" open= "(" separator= "," close= ")" >
#{operatorId}
</foreach>
<if test= "params.startTime != null and params.startTime != ''" >
AND ho.end_time > = #{params.startTime}
</if>
<if test= "params.endTime != null and params.endTime != ''" >
AND ho.end_time < = #{params.endTime}
</if>
GROUP BY ho.operator_id
</select>
</mapper>