<?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.bonus.system.mapper.PasswordValidatorMapper">
    <!-- 插入密码历史记录 -->
    <insert id="addPasswordExpiry">
        INSERT INTO sys_user_password_history (user_id,
                                               old_password,
                                               new_password,
                                               change_timestamp,
                                               change_user)
        VALUES (#{userId},
                #{oldPassword},
                #{newPassword},
                NOW(),
                #{changeUser});
    </insert>
    <select id="checkPasswordExpiry" resultType="com.bonus.system.domain.UserPasswordHistory">
        SELECT id               AS id,
               old_password     AS oldPassword,
               new_password     AS newPassword,
               change_timestamp AS changeTimestamp,
               change_user      AS changeUser
        FROM sys_user_password_history
        WHERE user_id = #{userId}
        ORDER BY change_timestamp DESC
        LIMIT 5;
    </select>
</mapper>