<?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.im.mapper.FriendMapper">

    <select id="getFriendListForConsumer_old" resultType="com.ruoyi.im.domain.Friend">
        select a.id,
               a.user_id,
               a.friend_id,
               CONCAT(a.friend_nick_name,'(',d.store_name,')') as friend_nick_name,
               b.avatar as friend_head_image,
               c.role_id,
               e.dept_id as store_id
        from im_friend a,
             yj_app_user b,
             sys_user_role c,
             yj_store d,
             sys_user e
        WHERE  a.friend_id=b.app_user_id
          and  b.manage_account_id=c.user_id
          and  b.manage_account_id=e.user_id
          and  e.dept_id=d.dept_id
          and a.user_id=#{userId}
    </select>

    <select id="getFriendListForConsumer" resultType="com.ruoyi.im.domain.Friend">
        select
                d.app_user_id as friend_id,
--                CONCAT(d.nick_name,'(',b.store_name,')') as friend_nick_name,
               d.nick_name as friend_nick_name,
               d.avatar as friend_head_image,
               e.role_id,
               b.dept_id as store_id
        from yj_store b
           ,sys_user c
           ,yj_app_user d
           ,sys_user_role e
        WHERE c.dept_id=b.dept_id
          and d.manage_account_id=c.user_id
          and c.user_id=e.user_id
          and b.dept_id=#{storeId}
    </select>

    <select id="getFriendListForManage" resultType="com.ruoyi.im.domain.Friend">
        select a.id,
               a.user_id,
               a.friend_id,
               a.friend_nick_name,
               b.avatar as friend_head_image
        from im_friend a,
             yj_app_user b
        WHERE  a.friend_id=b.app_user_id
          and a.user_id=#{userId}
    </select>

    <select id="getUserByDept" resultType="AppUser">
        select b.app_user_id ,b.nick_name
        from sys_user a,yj_app_user b
        WHERE a.user_id=b.manage_account_id
          and a.personnel_status='1'
          and  a.delete_flag='0'
          and  a.status='0'
          and a.dept_id=#{deptId}
    </select>

</mapper>
