<?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.UserRegisterMapper">
    <!-- 结果集 -->
    <resultMap type="com.zcxk.entity.UserRegister" id="UserRegisterMap">
        <result property="id" column="ID" jdbcType="INTEGER"/>
        <result property="username" column="USERNAME" jdbcType="VARCHAR"/>
        <result property="phone" column="PHONE" jdbcType="VARCHAR"/>
        <result property="userType" column="USER_TYPE" jdbcType="VARCHAR"/>
        <result property="remark" column="REMARK" jdbcType="VARCHAR"/>
        <result property="status" column="STATUS" jdbcType="INTEGER"/>
        <result property="createBy" column="CREATE_BY" jdbcType="VARCHAR"/>
        <result property="dateCreate" column="DATE_CREATE" jdbcType="TIMESTAMP"/>
        <result property="updateBy" column="UPDATE_BY" jdbcType="VARCHAR"/>
        <result property="dateUpdate" column="DATE_UPDATE" jdbcType="TIMESTAMP"/>
    </resultMap>
    <sql id="Base_Column_List">
         ID, USERNAME, PHONE, USER_TYPE,REMARK,	STATUS,	DATE_CREATE,CREATE_BY,DATE_UPDATE,UPDATE_BY</sql>

    <!-- 新增所有列 -->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into uims_user_register( ID, USERNAME, PHONE, USER_TYPE,	REMARK,	STATUS,	CREATE_BY,DATE_CREATE,UPDATE_BY,DATE_UPDATE)
        values ( #{id}, #{username}, #{phone}, #{userType}, #{remark}, 1, #{createBy}, #{dateCreate}, #{updateBy}, #{dateUpdate})
    </insert>

    <!--通过主键删除-逻辑删除-->
    <update id="deleteById" parameterType="java.util.List">
        update uims.uims_user_register
        set STATUS=0
        where ID in
        <foreach item="item" index="index" collection="ids" open="("
                 separator="," close=")">
            #{item}
        </foreach>
    </update>

    <select id="selectPage" resultMap="UserRegisterMap">
        select
        <include refid="Base_Column_List"/>
        from uims_user_register
        <where>
            <if test="userRegister.id != null">
                and ID = #{userRegister.id}
            </if>
            <if test="userRegister.username != null and userRegister.username != ''">
                and (USERNAME LIKE CONCAT('%',#{userRegister.username},'%')
                or PHONE LIKE CONCAT('%',#{userRegister.username},'%'))
            </if>
            <if test="userRegister.dateCreate != null">
                and DATE_CREATE >= #{userRegister.dateCreate}
            </if>
            <if test="userRegister.dateUpdate != null">
                and DATE_CREATE &lt; DATE_ADD(#{userRegister.dateUpdate},INTERVAL 1 DAY)
            </if>
            and STATUS =1
        </where>
        order by DATE_CREATE desc
    </select>
    <select id="selectListByCondition" resultMap="UserRegisterMap">
        select
        <include refid="Base_Column_List"/>
        from uims_user_register
        <where>
            <if test="ids != null">
                ID in
                <foreach item="item" index="index" collection="ids" open="("
                         separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="keywords != null and keywords != '' ">
                and (USERNAME LIKE CONCAT('%',#{keywords},'%')
                or PHONE LIKE CONCAT('%',#{keywords},'%'))
            </if>
            <if test="beginTime != null and beginTime != '' ">
                and DATE_CREATE >= #{beginTime}
            </if>
            <if test="endTime != null and endTime != '' ">
                and DATE_CREATE &lt; DATE_ADD(#{endTime},INTERVAL 1 DAY)
            </if>
            and STATUS =1
        </where>
        order by DATE_CREATE desc
    </select>
</mapper>