<?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.ruoyi.frequency.withdrawalconfig.mapper.WithdrawalConfigMapper">
    
    <resultMap type="com.ruoyi.frequency.withdrawalconfig.entity.WithdrawalConfig" id="WithdrawalConfigResult">
        <result property="id"    column="id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="minPrice"    column="min_price"    />
        <result property="maxPrice"    column="max_price"    />
        <result property="dayMaxPrice"    column="day_max_price"    />
        <result property="monthMaxPrice"    column="month_max_price"    />
        <result property="yearMaxPrice"    column="year_max_price"    />
        <result property="dayMaxTimes"    column="day_max_times"    />
        <result property="monthMaxTimes"    column="month_max_times"    />
        <result property="yearMaxTimes"    column="year_max_times"    />
        <result property="monthRangeMin"    column="month_range_min"    />
        <result property="monthRangeMax"    column="month_range_max"    />
        <result property="userType"    column="user_type"    />
    </resultMap>

    <sql id="selectWithdrawalConfigVo">
        select id, create_by, create_time, update_by, update_time, del_flag, min_price, max_price, day_max_price, month_max_price, year_max_price, day_max_times, month_max_times, year_max_times, month_range_min, month_range_max, user_type from t_withdrawal_config
    </sql>

    <select id="selectWithdrawalConfigList" parameterType="com.ruoyi.frequency.withdrawalconfig.entity.WithdrawalConfig" resultMap="WithdrawalConfigResult">
        <include refid="selectWithdrawalConfigVo"/>
        <where>  
            <if test="createBy != null "> and create_by = #{createBy}</if>
            <if test="updateBy != null "> and update_by = #{updateBy}</if>
            <if test="minPrice != null "> and min_price = #{minPrice}</if>
            <if test="maxPrice != null "> and max_price = #{maxPrice}</if>
            <if test="dayMaxPrice != null "> and day_max_price = #{dayMaxPrice}</if>
            <if test="monthMaxPrice != null "> and month_max_price = #{monthMaxPrice}</if>
            <if test="yearMaxPrice != null "> and year_max_price = #{yearMaxPrice}</if>
            <if test="dayMaxTimes != null "> and day_max_times = #{dayMaxTimes}</if>
            <if test="monthMaxTimes != null "> and month_max_times = #{monthMaxTimes}</if>
            <if test="yearMaxTimes != null "> and year_max_times = #{yearMaxTimes}</if>
            <if test="monthRangeMin != null "> and month_range_min = #{monthRangeMin}</if>
            <if test="monthRangeMax != null "> and month_range_max = #{monthRangeMax}</if>
            <if test="userType != null "> and user_type = #{userType}</if>
        </where>
    </select>
    
    <select id="selectWithdrawalConfigById" parameterType="Long" resultMap="WithdrawalConfigResult">
        <include refid="selectWithdrawalConfigVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertWithdrawalConfig" parameterType="com.ruoyi.frequency.withdrawalconfig.entity.WithdrawalConfig">
        insert into t_withdrawal_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</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>
            <if test="minPrice != null">min_price,</if>
            <if test="maxPrice != null">max_price,</if>
            <if test="dayMaxPrice != null">day_max_price,</if>
            <if test="monthMaxPrice != null">month_max_price,</if>
            <if test="yearMaxPrice != null">year_max_price,</if>
            <if test="dayMaxTimes != null">day_max_times,</if>
            <if test="monthMaxTimes != null">month_max_times,</if>
            <if test="yearMaxTimes != null">year_max_times,</if>
            <if test="monthRangeMin != null">month_range_min,</if>
            <if test="monthRangeMax != null">month_range_max,</if>
            <if test="userType != null">user_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="minPrice != null">#{minPrice},</if>
            <if test="maxPrice != null">#{maxPrice},</if>
            <if test="dayMaxPrice != null">#{dayMaxPrice},</if>
            <if test="monthMaxPrice != null">#{monthMaxPrice},</if>
            <if test="yearMaxPrice != null">#{yearMaxPrice},</if>
            <if test="dayMaxTimes != null">#{dayMaxTimes},</if>
            <if test="monthMaxTimes != null">#{monthMaxTimes},</if>
            <if test="yearMaxTimes != null">#{yearMaxTimes},</if>
            <if test="monthRangeMin != null">#{monthRangeMin},</if>
            <if test="monthRangeMax != null">#{monthRangeMax},</if>
            <if test="userType != null">#{userType},</if>
         </trim>
    </insert>

    <update id="updateWithdrawalConfig" parameterType="com.ruoyi.frequency.withdrawalconfig.entity.WithdrawalConfig">
        update t_withdrawal_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="minPrice != null">min_price = #{minPrice},</if>
            <if test="maxPrice != null">max_price = #{maxPrice},</if>
            <if test="dayMaxPrice != null">day_max_price = #{dayMaxPrice},</if>
            <if test="monthMaxPrice != null">month_max_price = #{monthMaxPrice},</if>
            <if test="yearMaxPrice != null">year_max_price = #{yearMaxPrice},</if>
            <if test="dayMaxTimes != null">day_max_times = #{dayMaxTimes},</if>
            <if test="monthMaxTimes != null">month_max_times = #{monthMaxTimes},</if>
            <if test="yearMaxTimes != null">year_max_times = #{yearMaxTimes},</if>
            <if test="monthRangeMin != null">month_range_min = #{monthRangeMin},</if>
            <if test="monthRangeMax != null">month_range_max = #{monthRangeMax},</if>
            <if test="userType != null">user_type = #{userType},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWithdrawalConfigById" parameterType="Long">
        delete from t_withdrawal_config where id = #{id}
    </delete>

    <delete id="deleteWithdrawalConfigByIds" parameterType="String">
        delete from t_withdrawal_config where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>


    <select id="getWithdrawalData" resultType="com.ruoyi.frequency.withdrawalconfig.entity.WithdrawalConfig">
        SELECT
            (
                SELECT
                    IFNULL( SUM( t.price + t.service_charge ), 0 )
                FROM
                    t_withdrawal_record t
                WHERE
                    t.user_type = #{userVo.userType}
                  AND t.user_id = #{userVo.userId}
                  AND t.del_flag = 1
                  AND t.status != 3
                  AND DATE_FORMAT( t.create_time, '%Y-%m-%d' ) = DATE_FORMAT( NOW(), '%Y-%m-%d' )
            ) dayMaxPrice,
            (
                SELECT
                    IFNULL( SUM( t.price + t.service_charge ), 0 )
                FROM
                    t_withdrawal_record t
                WHERE
                    t.user_type = #{userVo.userType}
                  AND t.user_id = #{userVo.userId}
                  AND t.del_flag = 1
                  AND t.status != 3
                  AND DATE_FORMAT( t.create_time, '%Y-%m' ) = DATE_FORMAT( NOW(), '%Y-%m' )
            ) monthMaxPrice,
            (
                SELECT
                    IFNULL( SUM( t.price + t.service_charge ), 0 )
                FROM
                    t_withdrawal_record t
                WHERE
                    t.user_type = #{userVo.userType}
                  AND t.user_id = #{userVo.userId}
                  AND t.del_flag = 1
                  AND t.status != 3
                  AND DATE_FORMAT( t.create_time, '%Y' ) = DATE_FORMAT( NOW(), '%Y' )
            ) yearMaxPrice,
            (
                SELECT
                    COUNT( 1 )
                FROM
                    t_withdrawal_record t
                WHERE
                    t.user_type = #{userVo.userType}
                  AND t.user_id = #{userVo.userId}
                  AND t.del_flag = 1
                  AND t.status != 3
                  AND DATE_FORMAT( t.create_time, '%Y-%m-%d' ) = DATE_FORMAT( NOW(), '%Y-%m-%d' )
            ) dayMaxTimes,
            (
                SELECT
                    COUNT( 1 )
                FROM
                    t_withdrawal_record t
                WHERE
                    t.user_type = #{userVo.userType}
                  AND t.user_id = #{userVo.userId}
                  AND t.del_flag = 1
                  AND t.status != 3
                  AND DATE_FORMAT( t.create_time, '%Y-%m' ) = DATE_FORMAT( NOW(), '%Y-%m' )
            ) monthMaxTimes,
            (
                SELECT
                    COUNT( 1 )
                FROM
                    t_withdrawal_record t
                WHERE
                    t.user_type = #{userVo.userType}
                  AND t.user_id = #{userVo.userId}
                  AND t.del_flag = 1
                  AND t.status != 3
                  AND DATE_FORMAT( t.create_time, '%Y' ) = DATE_FORMAT( NOW(), '%Y' )
            ) yearMaxTimes
    </select>
</mapper>