<?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.UserInfoMapper">
    
    <resultMap type="UserInfo" id="UserInfoResult">
        <result property="userId"    column="user_id"    />
        <result property="authenticationStatus"    column="authentication_status"    />
        <result property="realName"    column="real_name"    />
        <result property="idCard"    column="id_card"    />
        <result property="sex"    column="sex"    />
        <result property="signature"    column="signature"    />
        <result property="avatar"    column="avatar"    />
        <result property="cardFront"    column="card_front"    />
        <result property="cardBack"    column="card_back"    />
        <result property="email"    column="email"    />
        <result property="receiveRockets"    column="receive_rockets"    />
        <result property="sendRockets"    column="send_rockets"    />
        <result property="shares"    column="shares"    />
        <result property="followers"    column="followers"    />
        <result property="followings"    column="followings"    />
        <result property="sOnlineTime"    column="s_online_time"    />
        <result property="sMrTime"    column="s_mr_time"    />
        <result property="sConsumption"    column="s_consumption"    />
        <result property="thConsumption"    column="th_consumption"    />
        <result property="phonenumber"    column="phonenumber"    />
        <result property="tMrTime"    column="t_mr_time"    />
        <result property="tOnlineTime"    column="t_online_time"    />
        <result property="tConsumption"    column="t_consumption"    />
        <result property="updateTime" column="update_time" />
        <result property="birth" column="date_of_birth"/>
        <result property="backGround" column="back_ground"/>
        <result property="calculationTime" column="calculation_time"/>
        <result property="idType" column="id_type"/>
    </resultMap>

    <resultMap id="AppUserInfoVoResult" type="appUserInfoVo">
        <result property="userId"    column="user_id"    />
        <result property="receiveRockets"    column="receive_rockets"    />
        <result property="sendRockets"    column="send_rockets"    />
        <result property="createTime"   column="create_time"  />
        <result property="nickName"     column="nick_name"    />
        <result property="status"       column="status"       />

        <result property="followers"    column="followers"    />
        <result property="followings"    column="followings"    />
        <result property="sOnlineTime"    column="s_online_time"    />
        <result property="sMrTime"    column="s_mr_time"    />
        <result property="sConsumption"    column="s_consumption"    />
        <result property="thConsumption"    column="th_consumption"    />
        <result property="phonenumber"    column="phonenumber"    />
        <result property="tMrTime"    column="t_mr_time"    />
        <result property="tOnlineTime"    column="t_online_time"    />
        <result property="tConsumption"    column="t_consumption"    />
<!--        <result property="idType" column="id_type"/>-->
    </resultMap>

    <resultMap id="HotAuthorDtoResult" type="HotAuthorDto">
        <id column="user_id" property="userId"/>
        <result column="nick_name" property="nickName"/>
        <result column="receive_rockets" property="receiveRockets"/>

    </resultMap>

    <resultMap id="UserAuthenticationInfoDtoResult" type="UserAuthenticationInfoDto">
        <result property="idCard"    column="id_card"    />
        <result property="idType"    column="id_type"    />
        <result property="realName"  column="real_name"    />
    </resultMap>



    <sql id="selectUserInfoVo">
        select user_id, authentication_status, real_name, id_card, sex, signature, avatar, card_front, card_back, email, receive_rockets, send_rockets, shares, followers, followings,s_online_time, s_mr_time, s_consumption, th_consumption, phonenumber, t_mr_time, t_online_time, t_consumption, update_time, date_of_birth, back_ground, calculation_time, id_type  from user_info
    </sql>

    <select id="selectUserInfoList" parameterType="UserInfo" resultMap="UserInfoResult">
        <include refid="selectUserInfoVo"/>
        <where>  
            <if test="authenticationStatus != null  and authenticationStatus != ''"> and authentication_status = #{authenticationStatus}</if>
            <if test="realName != null  and realName != ''"> and real_name like concat('%', #{realName}, '%')</if>
            <if test="idCard != null  and idCard != ''"> and id_card = #{idCard}</if>
            <if test="sex != null  and sex != ''"> and sex = #{sex}</if>
            <if test="signature != null  and signature != ''"> and signature = #{signature}</if>
            <if test="avatar != null  and avatar != ''"> and avatar = #{avatar}</if>
            <if test="cardFront != null  and cardFront != ''"> and card_front = #{cardFront}</if>
            <if test="cardBack != null  and cardBack != ''"> and card_back = #{cardBack}</if>
            <if test="email != null  and email != ''"> and email = #{email}</if>
            <if test="receiveRockets != null "> and receive_rockets = #{receiveRockets}</if>
            <if test="sendRockets != null "> and send_rockets = #{sendRockets}</if>
            <if test="shares != null "> and shares = #{shares}</if>
            <if test="followers != null "> and followers = #{followers}</if>
             <if test="followings != null "> and followings = #{followings}</if>
            <if test="sOnlineTime != null "> and s_online_time = #{sOnlineTime}</if>
            <if test="sMrTime != null "> and s_mr_time = #{sMrTime}</if>
            <if test="sConsumption != null "> and s_consumption = #{sConsumption}</if>
            <if test="thConsumption != null "> and th_consumption = #{thConsumption}</if>
            <if test="phonenumber != null  and phonenumber != ''"> and phonenumber = #{phonenumber}</if>
            <if test="tMrTime != null "> and t_mr_time = #{tMrTime}</if>
            <if test="tOnlineTime != null "> and t_online_time = #{tOnlineTime}</if>
            <if test="tConsumption != null "> and t_consumption = #{tConsumption}</if>
            <if test="updateTime != null"> and update_time = #{updateTime}</if>
            <if test="birth != null"> and date_of_birth = #{birth}</if>
            <if test="backGround != null"> and back_ground = #{backGround}</if>
            <if test="calculationTime != null"> and calculation_time = #{calculationTime}</if>
             <if test="idType != null">and id_type = #{idType}</if>
        </where>
    </select>
    
    <select id="selectUserInfoByUserId" parameterType="Long" resultMap="UserInfoResult">
        <include refid="selectUserInfoVo"/>
        where user_id = #{userId}
    </select>

    <select id="selectAllUserInfo" resultMap="UserInfoResult">
        select user_id, authentication_status, real_name, id_card, sex, signature, avatar, card_front, card_back, email, receive_rockets, send_rockets, shares, followers, s_online_time, s_mr_time, s_consumption, th_consumption, phonenumber, t_mr_time, t_online_time, t_consumption, update_time, date_of_birth, back_ground, calculation_time, id_type from user_info
    </select>
    <select id="getAllAppUserInfo" resultMap="AppUserInfoVoResult" parameterType="SysUser">
        select s.user_id, s.nick_name, s.status, s.create_time, u.receive_rockets, u.send_rockets, u.followers, u.followings, u.s_online_time, u.s_mr_time, u.s_consumption, u.th_consumption, u.phonenumber, u.t_mr_time, u.t_online_time, u.t_consumption
        from sys_user s
        left join user_info u
        on s.user_id = u.user_id
        where s.user_type = '0000000000'

            <if test="status != null and status != ''"> AND s.status = #{status} </if>
            <if test="nickName != null and  nickName != ''">AND s.nick_name like concat('%', #{nickName}, '%')</if>
        order by s.create_time desc

    </select>
    <select id="getAppUserInfo" resultMap="AppUserInfoVoResult">
        select s.user_id, s.nick_name, s.status, s.create_time, u.receive_rockets, u.send_rockets, u.followers, u.s_online_time, u.s_mr_time, u.s_consumption, u.th_consumption, u.phonenumber, u.t_mr_time, u.t_online_time, u.t_consumption
        from sys_user s
        left join user_info u
        on s.user_id = u.user_id
        where s.user_type = '0000000000' and s.user_id = #{userId}
    </select>
    <select id="getHotAuthor" resultMap="HotAuthorDtoResult">

        select u.user_id, s.nick_name, u.receive_rockets
        from user_info u
        left join sys_user s
        on u.user_id = s.user_id
        where s.status = 0
        order by receive_rockets desc
        limit 6
    </select>
    <select id="getUserAuthenticationInfo" resultMap="UserAuthenticationInfoDtoResult">
        select real_name, id_card, id_type
        from user_info
        where user_id = #{userId}

    </select>

    <insert id="insertUserInfo" parameterType="UserInfo">
        insert into user_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="authenticationStatus != null">authentication_status,</if>
            <if test="realName != null">real_name,</if>
            <if test="idCard != null">id_card,</if>
            <if test="sex != null">sex,</if>
            <if test="signature != null">signature,</if>
            <if test="avatar != null">avatar,</if>
            <if test="cardFront != null">card_front,</if>
            <if test="cardBack != null">card_back,</if>
            <if test="email != null">email,</if>
            <if test="receiveRockets != null">receive_rockets,</if>
            <if test="sendRockets != null">send_rockets,</if>
            <if test="shares != null">shares,</if>
            <if test="followers != null">followers,</if>
            <if test="followings != null">followings,</if>
            <if test="sOnlineTime != null">s_online_time,</if>
            <if test="sMrTime != null">s_mr_time,</if>
            <if test="sConsumption != null">s_consumption,</if>
            <if test="thConsumption != null">th_consumption,</if>
            <if test="phonenumber != null">phonenumber,</if>
            <if test="tMrTime != null">t_mr_time,</if>
            <if test="tOnlineTime != null">t_online_time,</if>
            <if test="tConsumption != null">t_consumption,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="birth != null">date_of_birth,</if>
            <if test="backGround != null">back_ground,</if>
            <if test="calculationTime != null">calculation_time,</if>
            <if test="idType != null">id_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="authenticationStatus != null">#{authenticationStatus},</if>
            <if test="realName != null">#{realName},</if>
            <if test="idCard != null">#{idCard},</if>
            <if test="sex != null">#{sex},</if>
            <if test="signature != null">#{signature},</if>
            <if test="avatar != null">#{avatar},</if>
            <if test="cardFront != null">#{cardFront},</if>
            <if test="cardBack != null">#{cardBack},</if>
            <if test="email != null">#{email},</if>
            <if test="receiveRockets != null">#{receiveRockets},</if>
            <if test="sendRockets != null">#{sendRockets},</if>
            <if test="shares != null">#{shares},</if>
            <if test="followers != null">#{followers},</if>
            <if test="followings != null">#{followings},</if>
            <if test="sOnlineTime != null">#{sOnlineTime},</if>
            <if test="sMrTime != null">#{sMrTime},</if>
            <if test="sConsumption != null">#{sConsumption},</if>
            <if test="thConsumption != null">#{thConsumption},</if>
            <if test="phonenumber != null">#{phonenumber},</if>
            <if test="tMrTime != null">#{tMrTime},</if>
            <if test="tOnlineTime != null">#{tOnlineTime},</if>
            <if test="tConsumption != null">#{tConsumption},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="birth != null">#{birth},</if>
            <if test="backGround != null">#{backGround},</if>
            <if test="calculationTime != null">#{calculationTime},</if>
            <if test="idType != null">#{idType},</if>
         </trim>
    </insert>

    <update id="updateUserInfo" parameterType="UserInfo">
        update user_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="authenticationStatus != null">authentication_status = #{authenticationStatus},</if>
            <if test="realName != null">real_name = #{realName},</if>
            <if test="idCard != null">id_card = #{idCard},</if>
            <if test="sex != null">sex = #{sex},</if>
            <if test="signature != null">signature = #{signature},</if>
            <if test="avatar != null">avatar = #{avatar},</if>
            <if test="cardFront != null">card_front = #{cardFront},</if>
            <if test="cardBack != null">card_back = #{cardBack},</if>
            <if test="email != null">email = #{email},</if>
            <if test="receiveRockets != null">receive_rockets = #{receiveRockets},</if>
            <if test="sendRockets != null">send_rockets = #{sendRockets},</if>
            <if test="shares != null">shares = #{shares},</if>
            <if test="followers != null">followers = #{followers},</if>
            <if test="followings != null">followings = #{followings},</if>
            <if test="sOnlineTime != null">s_online_time = #{sOnlineTime},</if>
            <if test="sMrTime != null">s_mr_time = #{sMrTime},</if>
            <if test="sConsumption != null">s_consumption = #{sConsumption},</if>
            <if test="thConsumption != null">th_consumption = #{thConsumption},</if>
            <if test="phonenumber != null">phonenumber = #{phonenumber},</if>
            <if test="tMrTime != null">t_mr_time = #{tMrTime},</if>
            <if test="tOnlineTime != null">t_online_time = #{tOnlineTime},</if>
            <if test="tConsumption != null">t_consumption = #{tConsumption},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="birth != null">date_of_birth = #{birth},</if>
            <if test="backGround != null">back_ground = #{backGround},</if>
            <if test="calculationTime != null">calculation_time = #{calculationTime},</if>
            <if test="idType != null">id_type = #{idType},</if>

        </trim>
        where user_id = #{userId}
    </update>



    <delete id="deleteUserInfoByUserId" parameterType="Long">
        delete from user_info where user_id = #{userId}
    </delete>

    <delete id="deleteUserInfoByUserIds" parameterType="String">
        delete from user_info where user_id in 
        <foreach item="userId" collection="array" open="(" separator="," close=")">
            #{userId}
        </foreach>
    </delete>

    <update id="updateSignature" parameterType="UserInfo">
        update user_info set signature = #{signature} where phonenumber = #{phonenumber}
    </update>

    <update id="updateAvatar" parameterType="UserInfo">
        update user_info set avatar = #{avatar} where phonenumber = #{phonenumber}
    </update>

    <update id="updateBackground" parameterType="UserInfo">
        update user_info set back_ground = #{background} where phonenumber = #{phonenumber}
    </update>
</mapper>