<?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.GroupUserMapper">
    <!-- 结果集 -->
    <resultMap type="com.zcxk.entity.GroupUser" id="GroupUserMap">
        <result property="id" column="ID" jdbcType="INTEGER"/>
        <result property="groupId" column="GROUP_ID" jdbcType="INTEGER"/>
        <result property="userId" column="USER_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, GROUP_ID, USER_ID, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY    </sql>

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


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

    <!--通过实体作为筛选条件查询-->
    <select id="selectList" resultMap="GroupUserMap">
        select
        <include refid="Base_Column_List"/>
        from uims_group_user
        <where>
            <if test="id != null">
                and ID = #{id}
            </if>
            <if test="groupId != null">
                and GROUP_ID = #{groupId}
            </if>
            <if test="userId != null">
                and USER_ID = #{userId}
            </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_group_user(ID, GROUP_ID, USER_ID, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY)
        values ( #{id}, #{groupId}, #{userId}, #{status}, #{dateCreate}, #{createBy}, #{dateUpdate}, #{updateBy})
    </insert>

    <!-- 批量新增 -->
    <insert id="batchInsert">
        insert into uims_group_user(ID, GROUP_ID, USER_ID, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY)
        values
        <foreach collection="groupUsers" item="item" index="index" separator=",">
            (
            #{item.id}, #{item.groupId}, #{item.userId}, #{item.status}, #{item.dateCreate}, #{item.createBy},
            #{item.dateUpdate}, #{item.updateBy} )
        </foreach>
    </insert>

    <!-- 通过主键修改数据 -->
    <update id="update">
        update uims.uims_group_user
        <set>
            <if test="groupId != null">
                GROUP_ID = #{groupId},
            </if>
            <if test="userId != null">
                USER_ID = #{userId},
            </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_group_user where ID = #{id}
    </delete>

    <!-- 总数 -->
    <select id="count" resultType="int">
        select count(*) from uims_group_user
    </select>
    <select id="selectPage" resultMap="GroupUserMap">
        select
        <include refid="Base_Column_List"/>
        from uims_group_user
        <where>
            <if test="groupUser.id != null">
                and ID = #{groupUser.id}
            </if>
            <if test="groupUser.groupId != null">
                and GROUP_ID = #{groupUser.groupId}
            </if>
            <if test="groupUser.userId != null">
                and USER_ID = #{groupUser.userId}
            </if>
            <if test="groupUser.status != null">
                and STATUS = #{groupUser.status}
            </if>
            <if test="groupUser.dateCreate != null">
                and DATE_CREATE = #{groupUser.dateCreate}
            </if>
            <if test="groupUser.createBy != null and groupUser.createBy != ''">
                and CREATE_BY = #{groupUser.createBy}
            </if>
            <if test="groupUser.dateUpdate != null">
                and DATE_UPDATE = #{groupUser.dateUpdate}
            </if>
            <if test="groupUser.updateBy != null and groupUser.updateBy != ''">
                and UPDATE_BY = #{groupUser.updateBy}
            </if>
        </where>
    </select>
</mapper>