<?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.zcxk.dao.UserRoleMapper">

    <resultMap type="UserRoleEntity" id="UserRoleResult">
        <result property="id" column="id"/>
        <result property="userId" column="user_id"/>
        <result property="roleId" column="role_id"/>
        <result property="status" column="status"/>
        <result property="dateCreate" column="date_create"/>
        <result property="createBy" column="create_by"/>
        <result property="dateUpdate" column="date_update"/>
        <result property="updateBy" column="update_by"/>
    </resultMap>

    <!--  实体栏位  -->
    <sql id="userRoleColumns">
         a.id as "id" ,
         a.user_id as "userId" ,
         a.role_id as "roleId" ,
         a.status as "status" ,
         a.date_create as "dateCreate" ,
         a.create_by as "createBy" ,
         a.date_update as "dateUpdate" ,
         a.update_by as "updateBy" 
     </sql>


    <!--  根据主键获取实体   -->
    <select id="findUserRoleById" resultType="com.zcxk.entity.UserRoleEntity">
        SELECT
        <include refid="userRoleColumns"/>
        FROM uims_user_role a

        WHERE a.id = #{id} and  a.status=1
    </select>

    <!--  根据获取实体List   -->
    <select id="findList" resultType="com.zcxk.entity.UserRoleEntity">
        SELECT
        <include refid="userRoleColumns"/>
        FROM uims_user_role a

        <where>
            a.status=1
            <if test="userId != null ">and a.user_id = #{userId}</if>
            <if test="roleId != null ">and a.role_id = #{roleId}</if>
            <if test="status != null ">and a.status = #{status}</if>
            <if test="dateCreate != null ">and a.date_create = #{dateCreate}</if>
            <if test="dateUpdate != null ">and a.date_update = #{dateUpdate}</if>

        </where>
    </select>

    <!--  根据获取实体 page   -->
    <select id="findPage" resultType="com.zcxk.entity.UserRoleEntity">
        SELECT
        <include refid="userRoleColumns"/>
        FROM uims_user_role a
        <where>
            a.status=1
            <if test="userRole.userId != null ">and a.user_id = #{userRole.userId}</if>
            <if test="userRole.roleId != null ">and a.role_id = #{userRole.roleId}</if>
            <if test="userRole.status != null ">and a.status = #{userRole.status}</if>
            <if test="userRole.dateCreate != null ">and a.date_create = #{userRole.dateCreate}</if>
            <if test="userRole.dateUpdate != null ">and a.date_update = #{userRole.dateUpdate}</if>

        </where>
    </select>
</mapper>