<?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.system.mapper.InterestsNumberTableMapper">
    
    <resultMap type="InterestsNumberTable" id="InterestsNumberTableResult">
        <result property="id"    column="id"    />
        <result property="interestsId"    column="interests_id"    />
        <result property="rightsRank"    column="rights_rank"    />
        <result property="number"    column="number"    />
    </resultMap>

    <sql id="selectInterestsNumberTableVo">
        select id, interests_id, rights_rank, number from interests_number_table
    </sql>

    <select id="selectInterestsNumberTableList" parameterType="InterestsNumberTable" resultMap="InterestsNumberTableResult">
        <include refid="selectInterestsNumberTableVo"/>
        <where>  
            <if test="interestsId != null "> and interests_id = #{interestsId}</if>
            <if test="rightsRank != null  and rightsRank != ''"> and rights_rank = #{rightsRank}</if>
            <if test="number != null "> and number = #{number}</if>
        </where>
    </select>
    
    <select id="selectInterestsNumberTableById" parameterType="Long" resultMap="InterestsNumberTableResult">
        <include refid="selectInterestsNumberTableVo"/>
        where id = #{id}
    </select>

    <select id="selectInterestsNumberTable" parameterType="InterestsNumberTable" resultMap="InterestsNumberTableResult">
        <include refid="selectInterestsNumberTableVo"/>
        <where>
            <if test="interestsId != null "> and interests_id = #{interestsId}</if>
            <if test="rightsRank != null  and rightsRank != ''"> and rights_rank = #{rightsRank}</if>
            <if test="number != null "> and number = #{number}</if>
        </where>
        limit 1
    </select>
    <select id="selectInterestsNumberTableByPolicyId" resultMap="InterestsNumberTableResult" >
        select i.id, i.interests_id, i.rights_rank, i.number
        from interests_number_table i
        left join interests_table t on i.interests_id = t.id
        where t.interests_policy_id = #{menuId} and i.rights_rank = #{creditLevel}
        limit 1

    </select>

    <insert id="insertInterestsNumberTable" parameterType="InterestsNumberTable">
        insert into interests_number_table
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="interestsId != null">interests_id,</if>
            <if test="rightsRank != null">rights_rank,</if>
            <if test="number != null">number,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="interestsId != null">#{interestsId},</if>
            <if test="rightsRank != null">#{rightsRank},</if>
            <if test="number != null">#{number},</if>
         </trim>
    </insert>

    <update id="updateInterestsNumberTable" parameterType="InterestsNumberTable">
        update interests_number_table
        <trim prefix="SET" suffixOverrides=",">
            <if test="interestsId != null">interests_id = #{interestsId},</if>
            <if test="rightsRank != null">rights_rank = #{rightsRank},</if>
            <if test="number != null">number = #{number},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteInterestsNumberTableById" parameterType="Long">
        delete from interests_number_table where id = #{id}
    </delete>

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