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

    <resultMap type="PostUser" id="PostUserResult">
        <result property="id"    column="id"    />
        <result property="realname"    column="realname"    />
        <result property="username"    column="username"    />
        <result property="mobile"    column="mobile"    />
        <result property="registerAt"    column="register_at"    />
        <result property="lastIp"    column="last_ip"    />
        <result property="email"    column="email"    />
        <result property="password"    column="password"    />
        <result property="updateAt"    column="update_at"    />
        <result property="state"    column="state"    />
        <result property="loginCount"    column="login_count"    />
        <result property="avatar"    column="avatar"    />
    </resultMap>

    <sql id="selectPostUserVo">
        select id, realname, username, mobile, register_at, last_ip, email, password, update_at, state, login_count, avatar from post_user
    </sql>

    <select id="selectPostUserList" parameterType="PostUser" resultMap="PostUserResult">
        <include refid="selectPostUserVo"/>
        <where>
            <if test="realname != null  and realname != ''"> and realname like concat('%', #{realname}, '%')</if>
            <if test="username != null  and username != ''"> and username like concat('%', #{username}, '%')</if>
            <if test="mobile != null  and mobile != ''"> and mobile = #{mobile}</if>
            <if test="registerAt != null "> and register_at = #{registerAt}</if>
            <if test="lastIp != null  and lastIp != ''"> and last_ip = #{lastIp}</if>
            <if test="email != null  and email != ''"> and email = #{email}</if>
            <if test="password != null  and password != ''"> and password = #{password}</if>
            <if test="updateAt != null "> and update_at = #{updateAt}</if>
            <if test="state != null "> and state = #{state}</if>
            <if test="loginCount != null "> and login_count = #{loginCount}</if>
            <if test="avatar != null  and avatar != ''"> and avatar = #{avatar}</if>
        </where>
    </select>

    <select id="selectPostUserById" parameterType="Long" resultMap="PostUserResult">
        <include refid="selectPostUserVo"/>
        where id = #{id}
    </select>

    <insert id="insertPostUser" parameterType="PostUser" useGeneratedKeys="true" keyProperty="id">
        insert into post_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="realname != null">realname,</if>
            <if test="username != null">username,</if>
            <if test="mobile != null">mobile,</if>
            <if test="registerAt != null">register_at,</if>
            <if test="lastIp != null">last_ip,</if>
            <if test="email != null">email,</if>
            <if test="password != null">password,</if>
            <if test="updateAt != null">update_at,</if>
            <if test="state != null">state,</if>
            <if test="loginCount != null">login_count,</if>
            <if test="avatar != null">avatar,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="realname != null">#{realname},</if>
            <if test="username != null">#{username},</if>
            <if test="mobile != null">#{mobile},</if>
            <if test="registerAt != null">#{registerAt},</if>
            <if test="lastIp != null">#{lastIp},</if>
            <if test="email != null">#{email},</if>
            <if test="password != null">#{password},</if>
            <if test="updateAt != null">#{updateAt},</if>
            <if test="state != null">#{state},</if>
            <if test="loginCount != null">#{loginCount},</if>
            <if test="avatar != null">#{avatar},</if>
        </trim>
    </insert>

    <update id="updatePostUser" parameterType="PostUser">
        update post_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="realname != null">realname = #{realname},</if>
            <if test="username != null">username = #{username},</if>
            <if test="mobile != null">mobile = #{mobile},</if>
            <if test="registerAt != null">register_at = #{registerAt},</if>
            <if test="lastIp != null">last_ip = #{lastIp},</if>
            <if test="email != null">email = #{email},</if>
            <if test="password != null">password = #{password},</if>
            <if test="updateAt != null">update_at = #{updateAt},</if>
            <if test="state != null">state = #{state},</if>
            <if test="loginCount != null">login_count = #{loginCount},</if>
            <if test="avatar != null">avatar = #{avatar},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePostUserById" parameterType="Long">
        delete from post_user where id = #{id}
    </delete>

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