<?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.SysRegisterRequestMapper">

    <resultMap type="SysRegisterRequest" id="SysRegisterRequestResult">
        <result property="requestId"    column="request_id"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"  column="user_name"   />
        <result property="nickName"  column="nick_name"   />
        <result property="company" column="company"   />
        <result property="position" column="position"   />
        <result property="email"  column="email"   />
        <result property="status"    column="status"    />
        <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="selectSysRegisterRequestVo">
        select r.request_id, r.user_id, r.status, r.create_by, r.create_time, r.update_by, r.update_time, r.remark,
        u.user_name, u.nick_name, u.company, u.position, u.email
        from sys_register_request r
        left join sys_user u on r.user_id = u.user_id
    </sql>

    <select id="selectSysRegisterRequestList" parameterType="SysRegisterRequest" resultMap="SysRegisterRequestResult">
        <include refid="selectSysRegisterRequestVo"/>
        <where>
            <if test="userId != null "> and r.user_id = #{userId}</if>
            <if test="userName != null and userName != ''"> and u.userName like concat('%', #{userName}, '%')</if>
            <if test="email != null and email != ''"> and u.email like concat('%', #{email}, '%')</if>
            <if test="status != null  and status != ''"> and r.status = #{status}</if>
        </where>
    </select>

    <select id="selectSysRegisterRequestByRequestId" parameterType="Long" resultMap="SysRegisterRequestResult">
        <include refid="selectSysRegisterRequestVo"/>
        where request_id = #{requestId}
    </select>

    <insert id="insertSysRegisterRequest" parameterType="SysRegisterRequest">
        insert into sys_register_request
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="requestId != null">request_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="status != null">status,</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="requestId != null">#{requestId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="status != null">#{status},</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="updateSysRegisterRequest" parameterType="SysRegisterRequest">
        update sys_register_request
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="status != null">status = #{status},</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 request_id = #{requestId}
    </update>

    <delete id="deleteSysRegisterRequestByRequestId" parameterType="Long">
        delete from sys_register_request where request_id = #{requestId}
    </delete>

    <delete id="deleteSysRegisterRequestByRequestIds" parameterType="String">
        delete from sys_register_request where request_id in
        <foreach item="requestId" collection="array" open="(" separator="," close=")">
            #{requestId}
        </foreach>
    </delete>
</mapper>
