<?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.generator.mapper.front.FrontUserMapper">

    <resultMap type="FrontUser" id="FrontUserResult">
        <id property="userId" column="user_id" />
        <result property="username" column="username" />
        <result property="password" column="password" />
        <result property="nickname" column="nickname" />
        <result property="email" column="email" />
        <result property="phone" column="phone" />
        <result property="status" column="status" />
        <result property="delFlag" column="del_flag" />
        <result property="lastLoginTime" column="last_login_time" />
        <result property="createTime" column="create_time" />
        <result property="updateTime" column="update_time" />
        <result property="remark" column="remark" />
    </resultMap>

    <sql id="selectFrontUserVo">
        select user_id, username, password, nickname, email, phone, status, del_flag, last_login_time, create_time, update_time, remark from front_user
    </sql>

    <select id="selectFrontUserById" parameterType="Long" resultMap="FrontUserResult">
        <include refid="selectFrontUserVo"/>
        where user_id = #{userId}
    </select>

    <select id="selectFrontUserByUsername" parameterType="String" resultMap="FrontUserResult">
        <include refid="selectFrontUserVo"/>
        where username = #{username} and del_flag = '0'
    </select>

    <select id="selectFrontUserList" parameterType="FrontUser" resultMap="FrontUserResult">
        <include refid="selectFrontUserVo"/>
        <where>
            <if test="username != null and username != ''"> and username like concat('%', #{username}, '%')</if>
            <if test="nickname != null and nickname != ''"> and nickname like concat('%', #{nickname}, '%')</if>
            <if test="email != null and email != ''"> and email = #{email}</if>
            <if test="phone != null and phone != ''"> and phone = #{phone}</if>
            <if test="status != null and status != ''"> and status = #{status}</if>
            <if test="delFlag != null and delFlag != ''"> and del_flag = #{delFlag}</if>
        </where>
    </select>

    <insert id="insertFrontUser" parameterType="FrontUser" useGeneratedKeys="true" keyProperty="userId">
        insert into front_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="username != null">username,</if>
            <if test="password != null">password,</if>
            <if test="nickname != null">nickname,</if>
            <if test="email != null">email,</if>
            <if test="phone != null">phone,</if>
            <if test="status != null">status,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="lastLoginTime != null">last_login_time,</if>
            create_time,
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="username != null">#{username},</if>
            <if test="password != null">#{password},</if>
            <if test="nickname != null">#{nickname},</if>
            <if test="email != null">#{email},</if>
            <if test="phone != null">#{phone},</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="lastLoginTime != null">#{lastLoginTime},</if>
            sysdate(),
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateFrontUser" parameterType="FrontUser">
        update front_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="password != null">password = #{password},</if>
            <if test="nickname != null">nickname = #{nickname},</if>
            <if test="email != null">email = #{email},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="status != null">status = #{status},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="lastLoginTime != null">last_login_time = #{lastLoginTime},</if>
            update_time = sysdate(),
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where user_id = #{userId}
    </update>

    <delete id="deleteFrontUserById" parameterType="Long">
        delete from front_user where user_id = #{userId}
    </delete>
</mapper>
