<?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.yami.shop.distribution.comment.dao.DistributionUserWalletMapper">
  <resultMap id="BaseResultMap" type="com.yami.shop.distribution.comment.model.DistributionUserWallet">
    <id column="wallet_id" jdbcType="BIGINT" property="walletId" />
    <result column="distribution_user_id" jdbcType="BIGINT" property="distributionUserId" />
    <result column="unsettled_amount" jdbcType="DECIMAL" property="unsettledAmount" />
    <result column="settled_amount" jdbcType="DECIMAL" property="settledAmount" />
    <result column="addup_amount" jdbcType="DECIMAL" property="addupAmount" />
      <result column="invalid_amount" jdbcType="DECIMAL" property="invalidAmount" />
    <result column="version" jdbcType="INTEGER" property="version" />
      <result column="state" jdbcType="INTEGER" property="state" />
  </resultMap>

    <resultMap id="DistributionUserWallet_DistributionUserVO" type="com.yami.shop.distribution.comment.model.DistributionUserWallet">
        <id column="wallet_id" jdbcType="BIGINT" property="walletId" />
        <result column="distribution_user_id" jdbcType="BIGINT" property="distributionUserId" />
        <result column="unsettled_amount" jdbcType="DECIMAL" property="unsettledAmount" />
        <result column="settled_amount" jdbcType="DECIMAL" property="settledAmount" />
        <result column="addup_amount" jdbcType="DECIMAL" property="addupAmount" />
        <result column="invalid_amount" jdbcType="DECIMAL" property="invalidAmount" />
        <result column="version" jdbcType="INTEGER" property="version" />
        <result column="state" jdbcType="INTEGER" property="state" />
        <association property="distributionUser" javaType="com.yami.shop.distribution.comment.vo.DistributionUserVO">
            <result column="nick_name" jdbcType="VARCHAR" property="nickName" />
            <result column="user_mobile" jdbcType="VARCHAR" property="userMobile" />
        </association>
    </resultMap>

    <select id="getDistributionUserWalletAndDistributionUserVOPage" resultMap="DistributionUserWallet_DistributionUserVO">
        select
        duw.wallet_id,
        duw.distribution_user_id,
        duw.unsettled_amount,
        duw.settled_amount,
        duw.invalid_amount,
        duw.addup_amount,
        duw.version,
        duw.state,
        du.nick_name
        from tz_distribution_user_wallet duw
        left join tz_distribution_user du on du.distribution_user_id = duw.distribution_user_id
        <where>
            <if test="userMobile !=null and userMobile != ''">
               and du.user_mobile = #{userMobile}
            </if>
        </where>
    </select>



  <select id="getSettledAmountByDistributionUserId" resultType="double">
      select
      settled_amount
      from
      tz_distribution_user_wallet
      where distribution_user_id=#{distributionUserId}
  </select>

    <select id="getWalletIdByDistributionUserId" resultType="long">
      select
      wallet_id
      from
      tz_distribution_user_wallet
      where distribution_user_id=#{distributionUserId}
    </select>

    <select id="getDistributionUserWalletDtoByDistributionUserId" resultType="com.yami.shop.distribution.comment.dto.DistributionUserWalletDto">
        select
        unsettled_amount,
        settled_amount,
        invalid_amount,
        addup_amount
        from
        tz_distribution_user_wallet
        where distribution_user_id = #{distributionUserId}
    </select>

    <!--根据分销员id修改状态-->
    <update id="updateStateByDistributionUserId">
        update tz_distribution_user_wallet
        set state = #{state}
        where
        distribution_user_id = #{distributionUserId}
    </update>

</mapper>