<?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.lyms.platform.permission.intf.IUserRoleMapsDao">

    <resultMap id="UserRoleMapsResultMap" type="com.lyms.platform.permission.model.UserRoleMaps">
        <result column="user_id" property="userId" jdbcType="INTEGER"/>
        <result column="role_id" property="roleId" jdbcType="INTEGER"/>
        <result column="yn" property="yn" jdbcType="INTEGER"/>
    </resultMap>


    <insert id="addUserRoleMaps" parameterType="com.lyms.platform.permission.model.UserRoleMaps">
insert into user_role_maps (user_id,role_id,yn) values (#{userId},#{roleId},#{yn})
</insert>


    <update id="updateUserRoleMaps" parameterType="com.lyms.platform.permission.model.UserRoleMaps">
        update user_role_maps
        <set>
            <if test="userId != null">
                user_id = #{userId,jdbcType=INTEGER},
            </if>
            <if test="roleId != null">
                role_id = #{roleId,jdbcType=INTEGER},
            </if>
            <if test="yn != null">
                yn = #{yn,jdbcType=INTEGER},
            </if>
        </set>
        where user_id = #{userId,jdbcType=INTEGER} and role_id = #{roleId,jdbcType=INTEGER}
    </update>


    <delete id="deleteUserRoleMaps" parameterType="java.lang.Integer">
    </delete>


    <select id="getUserRoleMaps" resultMap="UserRoleMapsResultMap" parameterType="java.lang.Integer">
select user_id,role_id,yn
</select>


    <sql id="orderAndLimit">
        <if test="sort != null and sort != '' ">
            order by ${sort}
            <if test="need != null">
                limit #{offset, jdbcType=INTEGER} , #{limit, jdbcType=INTEGER}
            </if>
        </if>
    </sql>


    <sql id="UserRoleMapsCondition">
        <where>
            1 = 1
            <if test="userId != null">
                and user_id = #{userId,jdbcType=INTEGER}
            </if>
            <if test="roleId != null">
                and role_id = #{roleId,jdbcType=INTEGER}
            </if>
            <if test="yn != null">
                and yn = #{yn,jdbcType=INTEGER}
            </if>
        </where>
    </sql>


    <select id="queryUserRoleMaps" resultMap="UserRoleMapsResultMap" parameterType="com.lyms.platform.permission.model.UserRoleMapsQuery">
        select user_id,role_id,yn
        from user_role_maps
        <include refid="UserRoleMapsCondition"/>
        <include refid="orderAndLimit"/>
    </select>


    <select id="queryUserRoleMapsCount" resultType="int" parameterType="com.lyms.platform.permission.model.UserRoleMapsQuery">
        select count(1) from user_role_maps
        <include refid="UserRoleMapsCondition"/>
    </select>


</mapper>