zainali5120
2020-11-12 c8bbb87364e02f3ffe538173f98b2a2192e9f974
src/main/resources/mapper/member/MemberWalletCoinDao.xml
@@ -1,7 +1,65 @@
<?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.xcong.excoin.modules.member.dao.MemberWalletCoinDao">
<?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.xcong.excoin.modules.member.dao.MemberWalletCoinDao">
   <select id="selectMemberWalletCoinsByMemberId" resultType="com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity">
        select * from member_wallet_coin where member_id = #{memberId}
    </select>
    <select id="selectWalletCoinBymIdAndCode" resultType="com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity">
        select * from member_wallet_coin where member_id = #{memberId} and wallet_code = #{walletCode}
    </select>
    <update id="updateFrozenBalance" parameterType="map">
      UPDATE member_wallet_coin
      SET available_balance = available_balance - #{amount},
          frozen_balance = frozen_balance + #{amount}
      WHERE
         id = #{id}
      AND member_id = #{memberId}
   </update>
   <update id="subFrozenBalance" parameterType="map">
      UPDATE member_wallet_coin
      SET available_balance = available_balance + #{amount},
          frozen_balance = frozen_balance - #{amount}
      WHERE
         id = #{id}
      AND member_id = #{memberId}
   </update>
   <update id="updateBlockBalance">
      update member_wallet_coin
      set
      available_balance = IFNULL(available_balance, 0) + #{availableBalance},
      total_balance = IFNULL(total_balance, 0) + #{availableBalance},
      early_balance = IFNULL(early_balance, 0) + #{earlyBalance},
      block_number  = IFNULL(block_number, 0) + #{blockNumber}
      where id=#{id}
   </update>
   <update id="updateWalletBalance" parameterType="map">
      update member_wallet_coin
      <set>
         <if test="availableBalance != null">
            available_balance = (
            case when  IFNULL(available_balance, 0) + #{availableBalance}>0 then  IFNULL(available_balance, 0) + #{availableBalance} else 0 end
            ),
         </if>
         <if test="totalBalance != null">
            total_balance = (
            case when  IFNULL(total_balance, 0) + #{totalBalance}>0 then  IFNULL(total_balance, 0) + #{totalBalance} else 0 end
            ),
         </if>
         <if test="frozenBalance != null">
            frozen_balance = (
            case when  IFNULL(frozen_balance, 0) + #{frozenBalance}>0 then  IFNULL(frozen_balance, 0) + #{frozenBalance} else 0 end
            ),
         </if>
      </set>
      where id=#{id}
   </update>
</mapper>