Files
jsowell-charger-web/jsowell-pile/src/main/resources/mapper/pile/MemberWalletInfoMapper.xml
2025-07-24 15:26:55 +08:00

578 lines
22 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.jsowell.pile.mapper.MemberWalletInfoMapper">
<resultMap id="BaseResultMap" type="com.jsowell.pile.domain.MemberWalletInfo">
<!--@mbg.generated-->
<!--@Table member_wallet_info-->
<id column="id" jdbcType="INTEGER" property="id" />
<result column="member_id" jdbcType="VARCHAR" property="memberId" />
<result column="merchant_id" jdbcType="VARCHAR" property="merchantId" />
<result column="wallet_code" jdbcType="VARCHAR" property="walletCode" />
<result column="principal_balance" jdbcType="DECIMAL" property="principalBalance" />
<result column="gift_balance" jdbcType="DECIMAL" property="giftBalance" />
<result column="version" jdbcType="INTEGER" property="version" />
<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="del_flag" jdbcType="CHAR" property="delFlag" />
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated-->
id, member_id, merchant_id, wallet_code, principal_balance, gift_balance, version,
create_by, create_time, update_by, update_time, del_flag
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
<!--@mbg.generated-->
select
<include refid="Base_Column_List" />
from member_wallet_info
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
<!--@mbg.generated-->
delete from member_wallet_info
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.jsowell.pile.domain.MemberWalletInfo" useGeneratedKeys="true">
<!--@mbg.generated-->
insert into member_wallet_info (member_id, merchant_id, wallet_code,
principal_balance, gift_balance, version,
create_by, create_time, update_by,
update_time, del_flag)
values (#{memberId,jdbcType=VARCHAR}, #{merchantId,jdbcType=VARCHAR}, #{walletCode,jdbcType=VARCHAR},
#{principalBalance,jdbcType=DECIMAL}, #{giftBalance,jdbcType=DECIMAL}, #{version,jdbcType=INTEGER},
#{createBy,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateBy,jdbcType=VARCHAR},
#{updateTime,jdbcType=TIMESTAMP}, #{delFlag,jdbcType=CHAR})
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.jsowell.pile.domain.MemberWalletInfo" useGeneratedKeys="true">
<!--@mbg.generated-->
insert into member_wallet_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="memberId != null">
member_id,
</if>
<if test="merchantId != null">
merchant_id,
</if>
<if test="walletCode != null">
wallet_code,
</if>
<if test="principalBalance != null">
principal_balance,
</if>
<if test="giftBalance != null">
gift_balance,
</if>
<if test="version != null">
version,
</if>
<if test="createBy != null">
create_by,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateBy != null">
update_by,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="delFlag != null">
del_flag,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="memberId != null">
#{memberId,jdbcType=VARCHAR},
</if>
<if test="merchantId != null">
#{merchantId,jdbcType=VARCHAR},
</if>
<if test="walletCode != null">
#{walletCode,jdbcType=VARCHAR},
</if>
<if test="principalBalance != null">
#{principalBalance,jdbcType=DECIMAL},
</if>
<if test="giftBalance != null">
#{giftBalance,jdbcType=DECIMAL},
</if>
<if test="version != null">
#{version,jdbcType=INTEGER},
</if>
<if test="createBy != null">
#{createBy,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateBy != null">
#{updateBy,jdbcType=VARCHAR},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="delFlag != null">
#{delFlag,jdbcType=CHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.jsowell.pile.domain.MemberWalletInfo">
<!--@mbg.generated-->
update member_wallet_info
<set>
<if test="memberId != null">
member_id = #{memberId,jdbcType=VARCHAR},
</if>
<if test="merchantId != null">
merchant_id = #{merchantId,jdbcType=VARCHAR},
</if>
<if test="walletCode != null">
wallet_code = #{walletCode,jdbcType=VARCHAR},
</if>
<if test="principalBalance != null">
principal_balance = #{principalBalance,jdbcType=DECIMAL},
</if>
<if test="giftBalance != null">
gift_balance = #{giftBalance,jdbcType=DECIMAL},
</if>
<if test="version != null">
version = #{version,jdbcType=INTEGER},
</if>
<if test="createBy != null">
create_by = #{createBy,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateBy != null">
update_by = #{updateBy,jdbcType=VARCHAR},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="delFlag != null">
del_flag = #{delFlag,jdbcType=CHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.jsowell.pile.domain.MemberWalletInfo">
<!--@mbg.generated-->
update member_wallet_info
set member_id = #{memberId,jdbcType=VARCHAR},
merchant_id = #{merchantId,jdbcType=VARCHAR},
wallet_code = #{walletCode,jdbcType=VARCHAR},
principal_balance = #{principalBalance,jdbcType=DECIMAL},
gift_balance = #{giftBalance,jdbcType=DECIMAL},
version = #{version,jdbcType=INTEGER},
create_by = #{createBy,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_by = #{updateBy,jdbcType=VARCHAR},
update_time = #{updateTime,jdbcType=TIMESTAMP},
del_flag = #{delFlag,jdbcType=CHAR}
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateBatch" parameterType="java.util.List">
<!--@mbg.generated-->
update member_wallet_info
<trim prefix="set" suffixOverrides=",">
<trim prefix="member_id = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id,jdbcType=INTEGER} then #{item.memberId,jdbcType=VARCHAR}
</foreach>
</trim>
<trim prefix="merchant_id = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id,jdbcType=INTEGER} then #{item.merchantId,jdbcType=VARCHAR}
</foreach>
</trim>
<trim prefix="wallet_code = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id,jdbcType=INTEGER} then #{item.walletCode,jdbcType=VARCHAR}
</foreach>
</trim>
<trim prefix="principal_balance = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id,jdbcType=INTEGER} then #{item.principalBalance,jdbcType=DECIMAL}
</foreach>
</trim>
<trim prefix="gift_balance = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id,jdbcType=INTEGER} then #{item.giftBalance,jdbcType=DECIMAL}
</foreach>
</trim>
<trim prefix="version = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id,jdbcType=INTEGER} then #{item.version,jdbcType=INTEGER}
</foreach>
</trim>
<trim prefix="create_by = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id,jdbcType=INTEGER} then #{item.createBy,jdbcType=VARCHAR}
</foreach>
</trim>
<trim prefix="create_time = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id,jdbcType=INTEGER} then #{item.createTime,jdbcType=TIMESTAMP}
</foreach>
</trim>
<trim prefix="update_by = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id,jdbcType=INTEGER} then #{item.updateBy,jdbcType=VARCHAR}
</foreach>
</trim>
<trim prefix="update_time = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id,jdbcType=INTEGER} then #{item.updateTime,jdbcType=TIMESTAMP}
</foreach>
</trim>
<trim prefix="del_flag = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id,jdbcType=INTEGER} then #{item.delFlag,jdbcType=CHAR}
</foreach>
</trim>
</trim>
where id in
<foreach close=")" collection="list" item="item" open="(" separator=", ">
#{item.id,jdbcType=INTEGER}
</foreach>
</update>
<update id="updateBatchSelective" parameterType="java.util.List">
<!--@mbg.generated-->
update member_wallet_info
<trim prefix="set" suffixOverrides=",">
<trim prefix="member_id = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.memberId != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.memberId,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim prefix="merchant_id = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.merchantId != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.merchantId,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim prefix="wallet_code = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.walletCode != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.walletCode,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim prefix="principal_balance = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.principalBalance != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.principalBalance,jdbcType=DECIMAL}
</if>
</foreach>
</trim>
<trim prefix="gift_balance = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.giftBalance != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.giftBalance,jdbcType=DECIMAL}
</if>
</foreach>
</trim>
<trim prefix="version = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.version != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.version,jdbcType=INTEGER}
</if>
</foreach>
</trim>
<trim prefix="create_by = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.createBy != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.createBy,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim prefix="create_time = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.createTime != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.createTime,jdbcType=TIMESTAMP}
</if>
</foreach>
</trim>
<trim prefix="update_by = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.updateBy != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.updateBy,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim prefix="update_time = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.updateTime != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.updateTime,jdbcType=TIMESTAMP}
</if>
</foreach>
</trim>
<trim prefix="del_flag = case" suffix="end,">
<foreach collection="list" index="index" item="item">
<if test="item.delFlag != null">
when id = #{item.id,jdbcType=INTEGER} then #{item.delFlag,jdbcType=CHAR}
</if>
</foreach>
</trim>
</trim>
where id in
<foreach close=")" collection="list" item="item" open="(" separator=", ">
#{item.id,jdbcType=INTEGER}
</foreach>
</update>
<insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map" useGeneratedKeys="true">
<!--@mbg.generated-->
insert into member_wallet_info
(member_id, merchant_id, wallet_code, principal_balance, gift_balance, version, create_by,
create_time, update_by, update_time, del_flag)
values
<foreach collection="list" item="item" separator=",">
(#{item.memberId,jdbcType=VARCHAR}, #{item.merchantId,jdbcType=VARCHAR}, #{item.walletCode,jdbcType=VARCHAR},
#{item.principalBalance,jdbcType=DECIMAL}, #{item.giftBalance,jdbcType=DECIMAL},
#{item.version,jdbcType=INTEGER}, #{item.createBy,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP},
#{item.updateBy,jdbcType=VARCHAR}, #{item.updateTime,jdbcType=TIMESTAMP}, #{item.delFlag,jdbcType=CHAR}
)
</foreach>
</insert>
<insert id="insertOrUpdate" keyColumn="id" keyProperty="id" parameterType="com.jsowell.pile.domain.MemberWalletInfo" useGeneratedKeys="true">
<!--@mbg.generated-->
insert into member_wallet_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
member_id,
merchant_id,
wallet_code,
principal_balance,
gift_balance,
version,
create_by,
create_time,
update_by,
update_time,
del_flag,
</trim>
values
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
#{memberId,jdbcType=VARCHAR},
#{merchantId,jdbcType=VARCHAR},
#{walletCode,jdbcType=VARCHAR},
#{principalBalance,jdbcType=DECIMAL},
#{giftBalance,jdbcType=DECIMAL},
#{version,jdbcType=INTEGER},
#{createBy,jdbcType=VARCHAR},
#{createTime,jdbcType=TIMESTAMP},
#{updateBy,jdbcType=VARCHAR},
#{updateTime,jdbcType=TIMESTAMP},
#{delFlag,jdbcType=CHAR},
</trim>
on duplicate key update
<trim suffixOverrides=",">
<if test="id != null">
id = #{id,jdbcType=INTEGER},
</if>
member_id = #{memberId,jdbcType=VARCHAR},
merchant_id = #{merchantId,jdbcType=VARCHAR},
wallet_code = #{walletCode,jdbcType=VARCHAR},
principal_balance = #{principalBalance,jdbcType=DECIMAL},
gift_balance = #{giftBalance,jdbcType=DECIMAL},
version = #{version,jdbcType=INTEGER},
create_by = #{createBy,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_by = #{updateBy,jdbcType=VARCHAR},
update_time = #{updateTime,jdbcType=TIMESTAMP},
del_flag = #{delFlag,jdbcType=CHAR},
</trim>
</insert>
<insert id="insertOrUpdateSelective" keyColumn="id" keyProperty="id" parameterType="com.jsowell.pile.domain.MemberWalletInfo" useGeneratedKeys="true">
<!--@mbg.generated-->
insert into member_wallet_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="memberId != null">
member_id,
</if>
<if test="merchantId != null">
merchant_id,
</if>
<if test="walletCode != null">
wallet_code,
</if>
<if test="principalBalance != null">
principal_balance,
</if>
<if test="giftBalance != null">
gift_balance,
</if>
<if test="version != null">
version,
</if>
<if test="createBy != null">
create_by,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateBy != null">
update_by,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="delFlag != null">
del_flag,
</if>
</trim>
values
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="memberId != null">
#{memberId,jdbcType=VARCHAR},
</if>
<if test="merchantId != null">
#{merchantId,jdbcType=VARCHAR},
</if>
<if test="walletCode != null">
#{walletCode,jdbcType=VARCHAR},
</if>
<if test="principalBalance != null">
#{principalBalance,jdbcType=DECIMAL},
</if>
<if test="giftBalance != null">
#{giftBalance,jdbcType=DECIMAL},
</if>
<if test="version != null">
#{version,jdbcType=INTEGER},
</if>
<if test="createBy != null">
#{createBy,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateBy != null">
#{updateBy,jdbcType=VARCHAR},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="delFlag != null">
#{delFlag,jdbcType=CHAR},
</if>
</trim>
on duplicate key update
<trim suffixOverrides=",">
<if test="id != null">
id = #{id,jdbcType=INTEGER},
</if>
<if test="memberId != null">
member_id = #{memberId,jdbcType=VARCHAR},
</if>
<if test="merchantId != null">
merchant_id = #{merchantId,jdbcType=VARCHAR},
</if>
<if test="walletCode != null">
wallet_code = #{walletCode,jdbcType=VARCHAR},
</if>
<if test="principalBalance != null">
principal_balance = #{principalBalance,jdbcType=DECIMAL},
</if>
<if test="giftBalance != null">
gift_balance = #{giftBalance,jdbcType=DECIMAL},
</if>
<if test="version != null">
version = #{version,jdbcType=INTEGER},
</if>
<if test="createBy != null">
create_by = #{createBy,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateBy != null">
update_by = #{updateBy,jdbcType=VARCHAR},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="delFlag != null">
del_flag = #{delFlag,jdbcType=CHAR},
</if>
</trim>
</insert>
<select id="selectByMemberId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from member_wallet_info
where del_flag = '0'
and member_id = #{memberId,jdbcType=INTEGER}
<if test="merchantId != null">
and merchant_id = #{merchantId,jdbcType=VARCHAR}
</if>
</select>
<select id="selectByMemberWalletList" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from member_wallet_info
where del_flag = '0'
and member_id = #{memberId,jdbcType=INTEGER}
and merchant_id is not null
</select>
<select id="selectByWalletCode" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from member_wallet_info
where del_flag = '0'
and wallet_code = #{walletCode,jdbcType=VARCHAR}
</select>
<select id="selectMemberWalletInfo" resultType="com.jsowell.pile.vo.base.MemberWalletVO">
SELECT t1.member_id as memberId,
t1.wallet_code as walletCode,
t1.merchant_id as merchantId,
ifnull(t1.principal_balance, 0) as principalBalance,
ifnull(t1.gift_balance, 0) as giftBalance,
ifnull(t2.accumulatedRechargePrincipal, 0) as accumulatedRechargePrincipal,
ifnull(t3.accumulatedRechargeGift, 0) as accumulatedRechargeGift
from member_wallet_info t1
left join (select wallet_code, sum(amount) as accumulatedRechargePrincipal
from `member_wallet_log`
WHERE `wallet_code` = #{walletCode,jdbcType=VARCHAR}
and type = '1'
and sub_type = '10') t2 on t2.wallet_code = t1.wallet_code
left join (select wallet_code, sum(amount) as accumulatedRechargeGift
from `member_wallet_log`
WHERE `wallet_code` = #{walletCode,jdbcType=VARCHAR}
and type = '1'
and sub_type = '11') t3 on t3.wallet_code = t1.wallet_code
where t1.wallet_code = #{walletCode,jdbcType=VARCHAR}
</select>
<select id="queryWalletIsNull" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from member_wallet_info
where del_flag = '0'
and wallet_code is null
</select>
</mapper>