<?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.ruoyi.system.mapper.InvestigateUserMapper">
    
    <resultMap type="InvestigateUser" id="InvestigateUserResult">
        <result property="id"    column="id"    />
        <result property="investigateId"    column="investigate_id"    />
        <result property="userName"    column="user_name"    />
        <result property="phonenumber"    column="phonenumber"    />
        <result property="idCard"    column="id_card"    />
        <result property="duty"    column="duty"    />
        <result property="loginDate"    column="login_date"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectInvestigateUserVo">
        select id, investigate_id, user_name, phonenumber, id_card, duty, login_date, create_by, create_time, update_by, update_time, remark from investigate_user
    </sql>

    <select id="selectInvestigateUserList" parameterType="InvestigateUser" resultMap="InvestigateUserResult">
        <include refid="selectInvestigateUserVo"/>
        <where>  
            <if test="investigateId != null "> and investigate_id = #{investigateId}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="phonenumber != null  and phonenumber != ''"> and phonenumber = #{phonenumber}</if>
            <if test="idCard != null  and idCard != ''"> and id_card = #{idCard}</if>
            <if test="duty != null  and duty != ''"> and duty = #{duty}</if>
            <if test="loginDate != null "> and login_date = #{loginDate}</if>
        </where>
    </select>
    
    <select id="selectInvestigateUserById" parameterType="Long" resultMap="InvestigateUserResult">
        <include refid="selectInvestigateUserVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertInvestigateUser" parameterType="InvestigateUser" useGeneratedKeys="true" keyProperty="id">
        insert into investigate_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="investigateId != null">investigate_id,</if>
            <if test="userName != null and userName != ''">user_name,</if>
            <if test="phonenumber != null">phonenumber,</if>
            <if test="idCard != null">id_card,</if>
            <if test="duty != null">duty,</if>
            <if test="loginDate != null">login_date,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="investigateId != null">#{investigateId},</if>
            <if test="userName != null and userName != ''">#{userName},</if>
            <if test="phonenumber != null">#{phonenumber},</if>
            <if test="idCard != null">#{idCard},</if>
            <if test="duty != null">#{duty},</if>
            <if test="loginDate != null">#{loginDate},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateInvestigateUser" parameterType="InvestigateUser">
        update investigate_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="investigateId != null">investigate_id = #{investigateId},</if>
            <if test="userName != null and userName != ''">user_name = #{userName},</if>
            <if test="phonenumber != null">phonenumber = #{phonenumber},</if>
            <if test="idCard != null">id_card = #{idCard},</if>
            <if test="duty != null">duty = #{duty},</if>
            <if test="loginDate != null">login_date = #{loginDate},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteInvestigateUserById" parameterType="Long">
        delete from investigate_user where id = #{id}
    </delete>

    <delete id="deleteInvestigateUserByIds" parameterType="String">
        delete from investigate_user where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <delete id="deleteInvestigateUserByInvestigateId">
        delete from investigate_user where investigate_id = #{investigateId}
    </delete>

    <insert id="batchDispositionUser">
        insert into investigate_user (  `investigate_id`, `user_name`, `phonenumber`, `id_card`, `duty`,  `create_time`) values
        <foreach item="item" index="index" collection="list" separator=",">
            (#{item.investigateId},#{item.userName},#{item.phonenumber},#{item.idCard},#{item.duty},sysdate())
        </foreach>
    </insert>
</mapper>