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

    <resultMap id="UUserResult" type="com.ruoyi.system.domain.UUser">
        <id property="userId" column="user_id"/>
        <result property="mobile" column="mobile"/>
        <result property="nickName" column="nick_name"/>
        <result property="avatar" column="avatar"/>
        <result property="passwordHash" column="password_hash"/>
        <result property="status" column="status"/>
        <result property="lastLoginIp" column="last_login_ip"/>
        <result property="lastLoginTime" column="last_login_time"/>
        <result property="delFlag" column="del_flag"/>
    </resultMap>

    <select id="selectByMobile" resultMap="UUserResult">
        select user_id, mobile, nick_name, avatar, password_hash, status,
               last_login_ip, last_login_time, del_flag
        from u_center.u_user
        where mobile = #{mobile}
          and del_flag = '0'
        limit 1
    </select>

    <insert id="insertUUser" parameterType="com.ruoyi.system.domain.UUser" useGeneratedKeys="true" keyProperty="userId">
        insert into u_center.u_user (
            mobile,
            nick_name,
            avatar,
            password_hash,
            status,
            create_by,
            create_time,
            update_by,
            update_time,
            remark,
            del_flag
        ) values (
            #{mobile},
            #{nickName},
            #{avatar},
            #{passwordHash},
            #{status},
            'system',
            sysdate(),
            'system',
            sysdate(),
            '',
            '0'
        )
    </insert>

    <update id="updateLoginInfo">
        update u_center.u_user
        set last_login_ip = #{lastLoginIp},
            last_login_time = sysdate(),
            update_by = 'system',
            update_time = sysdate()
        where user_id = #{userId}
    </update>

</mapper>
