<?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.pj.project.sys_user_acc.SysUserAccMapper">

	<!-- 增 -->
	<insert id="save">
		insert into 
		sys_user (username, avatar, phone, email, create_time) 
		values (#{username}, #{avatar}, #{phone}, #{email}, now()) 
	</insert>
	
    <!-- 通用映射 -->
    <resultMap id="model" type="com.pj.project.sys_user_acc.SysUserAcc">
        <result column="id" property="id"/>
        <result column="username" property="username"/>
        <result column="password" property="password"/>
        <result column="phone" property="phone"/>
        <result column="email" property="email"/>
        <result column="status" property="status"/>
    </resultMap>

    <!-- 公共查询sql片段 -->
    <sql id="select_sql">
		select * from sys_user
	</sql>

    <!-- 查 -->
    <select id="getById" resultMap="model">
        <include refid="select_sql"></include>
        where id = #{id}
    </select>

    <!-- 查 - 根据username -->
    <select id="getByUsername" resultMap="model">
        <include refid="select_sql"></include>
        where username = #{username}
    </select>

    <!-- 查 - 根据phone -->
    <select id="getByPhone" resultMap="model">
        <include refid="select_sql"></include>
        where phone = #{phone}
    </select>

    <!-- 查 - 根据email -->
    <select id="getByEmail" resultMap="model">
        <include refid="select_sql"></include>
        where email = #{email}
    </select>
    
    <!-- 指定id的账号成功登录一次 -->
    <update id="successLogin">
        update sys_user set
		login_ip = #{login_ip},
		login_time = NOW(),
		login_count = login_count + 1
		where id = #{id}
    </update>


</mapper>
