<?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.UserRelationMapper">
    <insert id="save">
        insert into user_relation
        (`user_id`,`following_id`,`id`,`deleted`,`create_time`,`update_time`)
        values
        (#{userId},#{followingId},#{id},#{deleted},#{createTime},#{updateTime})
    </insert>

    <delete id="deleteByUserRelation">
        delete from user_relation where user_id=#{userId} and following_id=#{followingId}
    </delete>

    <select id="findFollowingUsers" resultType="java.lang.Long">
        select following_id from user_relation where user_id=#{userId}
    </select>
    <select id="findRelation" resultType="cn.reghao.tnb.user.app.model.po.UserRelation">
        select * from user_relation
        where user_id=#{loginUserId} and following_id=#{userId}
    </select>

    <select id="countUserFollower" resultType="java.lang.Integer">
        select count(*)
        from user_relation
        where following_id=#{userId}
    </select>
    <select id="findUserFollowers" resultType="java.lang.Long">
        select user_id
        from user_relation
        where following_id=#{userId}
    </select>

    <select id="countUserFollowing" resultType="java.lang.Integer">
        select count(*)
        from user_relation
        where user_id=#{userId}
    </select>
    <select id="findUserFollowings" resultType="java.lang.Long">
        select following_id
        from user_relation
        where user_id=#{userId}
    </select>
</mapper>
