<?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.UserGroupRoleMapper">
    <!-- 结果集 -->
    <resultMap type="com.zcxk.entity.UserGroupRole" id="UserGroupRoleMap">
        <result property="id" column="ID" jdbcType="INTEGER"/>
        <result property="userGroupId" column="USER_GROUP_ID" jdbcType="INTEGER"/>
        <result property="roleId" column="ROLE_ID" jdbcType="INTEGER"/>
        <result property="status" column="STATUS" jdbcType="INTEGER"/>
        <result property="dateCreate" column="DATE_CREATE" jdbcType="TIMESTAMP"/>
        <result property="createBy" column="CREATE_BY" jdbcType="VARCHAR"/>
        <result property="dateUpdate" column="DATE_UPDATE" jdbcType="TIMESTAMP"/>
        <result property="updateBy" column="UPDATE_BY" jdbcType="VARCHAR"/>
    </resultMap>

    <!-- 基本字段 -->
    <sql id="Base_Column_List">
        ID, USER_GROUP_ID, ROLE_ID, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY    </sql>

    <!-- 查询单个 -->
    <select id="selectById" resultMap="UserGroupRoleMap">
        select
        <include refid="Base_Column_List"/>
        from uims_user_group_role
        where ID = #{id}
    </select>


    <!-- 查询全部 -->
    <select id="selectAll" resultMap="UserGroupRoleMap">
        select
        <include refid="Base_Column_List"/>
        from uims_user_group_role
    </select>

    <!--通过实体作为筛选条件查询-->
    <select id="selectList" resultMap="UserGroupRoleMap">
        select
        <include refid="Base_Column_List"/>
        from uims_user_group_role
        <where>
            <if test="id != null">
                and ID = #{id}
            </if>
            <if test="userGroupId != null">
                and USER_GROUP_ID = #{userGroupId}
            </if>
            <if test="roleId != null">
                and ROLE_ID = #{roleId}
            </if>
            <if test="status != null">
                and STATUS = #{status}
            </if>
            <if test="dateCreate != null">
                and DATE_CREATE = #{dateCreate}
            </if>
            <if test="createBy != null and createBy != ''">
                and CREATE_BY = #{createBy}
            </if>
            <if test="dateUpdate != null">
                and DATE_UPDATE = #{dateUpdate}
            </if>
            <if test="updateBy != null and updateBy != ''">
                and UPDATE_BY = #{updateBy}
            </if>
        </where>
    </select>

    <!-- 新增所有列 -->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into uims_user_group_role(ID, USER_GROUP_ID, ROLE_ID, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY)
        values ( #{id}, #{userGroupId}, #{roleId}, #{status}, #{dateCreate}, #{createBy}, #{dateUpdate}, #{updateBy})
    </insert>

    <!-- 批量新增 -->
    <insert id="batchInsert">
        insert into uims_user_group_role(ID, USER_GROUP_ID, ROLE_ID, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE,
        UPDATE_BY)
        values
        <foreach collection="userGroupRoles" item="item" index="index" separator=",">
            (
            #{item.id}, #{item.userGroupId}, #{item.roleId}, #{item.status}, #{item.dateCreate}, #{item.createBy},
            #{item.dateUpdate}, #{item.updateBy} )
        </foreach>
    </insert>

    <!-- 通过主键修改数据 -->
    <update id="update">
        update uims.uims_user_group_role
        <set>
            <if test="userGroupId != null">
                USER_GROUP_ID = #{userGroupId},
            </if>
            <if test="roleId != null">
                ROLE_ID = #{roleId},
            </if>
            <if test="status != null">
                STATUS = #{status},
            </if>
            <if test="dateCreate != null">
                DATE_CREATE = #{dateCreate},
            </if>
            <if test="createBy != null and createBy != ''">
                CREATE_BY = #{createBy},
            </if>
            <if test="dateUpdate != null">
                DATE_UPDATE = #{dateUpdate},
            </if>
            <if test="updateBy != null and updateBy != ''">
                UPDATE_BY = #{updateBy},
            </if>
        </set>
        where ID = #{id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete from uims_user_group_role where ID = #{id}
    </delete>

    <!-- 总数 -->
    <select id="count" resultType="int">
        select count(*) from uims_user_group_role
    </select>
    <select id="selectPage" resultMap="UserGroupRoleMap">
        select
        <include refid="Base_Column_List"/>
        from uims_user_group_role
        <where>
            <if test="userGroupRole.id != null">
                and ID = #{userGroupRole.id}
            </if>
            <if test="userGroupRole.userGroupId != null">
                and USER_GROUP_ID = #{userGroupRole.userGroupId}
            </if>
            <if test="userGroupRole.roleId != null">
                and ROLE_ID = #{userGroupRole.roleId}
            </if>
            <if test="userGroupRole.status != null">
                and STATUS = #{userGroupRole.status}
            </if>
            <if test="userGroupRole.dateCreate != null">
                and DATE_CREATE = #{userGroupRole.dateCreate}
            </if>
            <if test="userGroupRole.createBy != null and userGroupRole.createBy != ''">
                and CREATE_BY = #{userGroupRole.createBy}
            </if>
            <if test="userGroupRole.dateUpdate != null">
                and DATE_UPDATE = #{userGroupRole.dateUpdate}
            </if>
            <if test="userGroupRole.updateBy != null and userGroupRole.updateBy != ''">
                and UPDATE_BY = #{userGroupRole.updateBy}
            </if>
        </where>
    </select>
</mapper>