<?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="cn.reghao.tnb.user.app.db.mapper.UserProfileMapper">
    <insert id="save">
        insert into user_profile
        (`user_id`,`gender`,`signature`,`following`,`follower`)
        values
        (#{userId},#{gender},#{signature},#{following},#{follower})
    </insert>
    <insert id="saveAll1" useGeneratedKeys="true" keyProperty="id">
        insert into user_measurements
        (`height`,`weight`,`bust`,`waist`,`hips`,`thigh`)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.height},#{item.weight},#{item.bust},#{item.waist},#{item.hips},#{item.thigh})
        </foreach>
    </insert>

    <update id="updateSetFollowingCountIncr">
        update user_profile
        set update_time=now(),following_count=following_count+1
        where user_id=#{userId}
    </update>
    <update id="updateSetFollowingCountDecr">
        update user_profile
        set update_time=now(),following_count=if(following_count &lt; 1, 0, following_count-1)
        where user_id=#{userId}
    </update>
    <update id="updateUserSignature">
        update user_profile
        set update_time=now(),signature=#{signature}
        where user_id=#{userId}
    </update>

    <select id="countAll" resultType="java.lang.Integer">
        select count(*)
        from user_profile
    </select>
    <select id="findAllById" resultType="cn.reghao.tnb.user.app.model.po.UserProfile">
        select *
        from user_profile
        where id > #{nextId}
        order by id asc
        limit #{pageSize}
    </select>
    <select id="findByUserId" resultType="cn.reghao.tnb.user.app.model.po.UserProfile">
        select *
        from user_profile
        where user_id=#{userId}
    </select>
</mapper>
