<?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.ForgetPasswordMapper">
    
    <resultMap type="ForgetPassword" id="ForgetPasswordResult">
        <result property="pId"    column="p_id"    />
        <result property="userName"    column="user_name"    />
        <result property="loginName"    column="login_name"    />
        <result property="expectPassword"    column="expect_password"    />
        <result property="applyTime"    column="apply_time"    />
        <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"    />

        <result property="confirmPassword"    column="confirm_password"    />



    </resultMap>

    <sql id="selectForgetPasswordVo">
         select p.p_id, u.user_name, p.login_name,p.confirm_password,
          p.expect_password,p.apply_time, p.status, p.create_by, p.create_time, p.update_by, p.update_time, p.remark
         from sys_forget_password p
         left join sys_user u on u.login_name = p.login_name
    </sql>

    <select id="selectForgetPasswordList" parameterType="ForgetPassword" resultMap="ForgetPasswordResult">
        <include refid="selectForgetPasswordVo"/>
        <where>
            <if test="userName != null  and userName != ''"> and u.user_name like concat('%', #{userName}, '%')</if>
            <if test="loginName != null  and loginName != ''"> and p.login_name like concat('%', #{loginName}, '%')</if>
            <if test="expectPassword != null  and expectPassword != ''"> and p.expect_password = #{expectPassword}</if>
            <if test="applyTime != null "> and p.apply_time = #{applyTime}</if>
            <if test="status != null  and status != ''"> and p.status = #{status}</if>
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                AND to_date(p.apply_time,'YY-MM-DD') &gt;= to_date(#{params.beginTime},'YY-MM-DD')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                AND to_date(p.apply_time,'YY-MM-DD') &lt;= to_date(#{params.endTime},'YY-MM-DD')
            </if>
        </where>
    </select>
    
    <select id="selectForgetPasswordById" parameterType="Long" resultMap="ForgetPasswordResult">
        <include refid="selectForgetPasswordVo"/>
        where p_id = #{pId}
    </select>
        
    <insert id="insertForgetPassword" parameterType="ForgetPassword" useGeneratedKeys="true" keyProperty="pId">
        insert into sys_forget_password
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userName != null">user_name,</if>
            <if test="loginName != null">login_name,</if>
            <if test="expectPassword != null">expect_password,</if>
            <if test="applyTime != null">apply_time,</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>
            <if test="confirmPassword != null">confirm_password,</if>

        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userName != null">#{userName},</if>
            <if test="loginName != null">#{loginName},</if>
            <if test="expectPassword != null">#{expectPassword},</if>
            <if test="applyTime != null">#{applyTime},</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>
            <if test="confirmPassword != null">#{confirmPassword},</if>

        </trim>
    </insert>

    <update id="updateForgetPassword" parameterType="ForgetPassword">
        update sys_forget_password
        <trim prefix="SET" suffixOverrides=",">
            <if test="userName != null">user_name = #{userName},</if>
            <if test="loginName != null">login_name = #{loginName},</if>
            <if test="expectPassword != null">expect_password = #{expectPassword},</if>
            <if test="applyTime != null">apply_time = #{applyTime},</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>
            <if test="confirmPassword != null">confirm_password = #{confirmPassword},</if>

        </trim>
        where p_id = #{pId}
    </update>

    <delete id="deleteForgetPasswordById" parameterType="Long">
        delete from sys_forget_password where p_id = #{pId}
    </delete>

    <delete id="deleteForgetPasswordByIds" parameterType="String">
        delete from sys_forget_password where p_id in 
        <foreach item="pId" collection="array" open="(" separator="," close=")">
            #{pId}
        </foreach>
    </delete>

</mapper>