<?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.dxhy.admin.sys.dao.SellerUserDao">

    <select id="getAllUser" resultType="com.dxhy.admin.sys.entity.SysUserEntity">
        select * from sys_user where company=#{company}
        <if test='map.userName!="null" and map.userName!=""'>
            and username =#{map.userName}
        </if>
    </select>


    <select id="queryNoBindCompany" resultType="com.dxhy.admin.sys.entity.SysDeptEntity">
        select taxname,company from sys_dept t where t.company not in (select company from sys_user_company t1 where
        t1.user_id=#{userId} ) and t.org_type='1'
        <if test='company!="null" and company!=""'>
            and t.company =#{company}
        </if>
        limit #{map.currIndex} , #{map.pageSize}
    </select>

    <select id="queryBindCompany" resultType="com.dxhy.admin.sys.entity.SysDeptEntity">
        select t.taxname,t.company from sys_dept t left join sys_user_company t1 on t.company=t1.company where
        t1.user_id=#{userId} and t.org_type='1' and t1.id is not null
        <if test='company!="null" and company!=""'>
            and t.company =#{company}
        </if>
        limit #{map.currIndex} , #{map.pageSize}
    </select>

    <select id="queryNoBindCompanyCount" resultType="int">
        select count(1) from sys_dept t where t.company not in (select company from sys_user_company t1 where
        t1.user_id=#{userId} ) and t.org_type='1'
        <if test='company!="null" and company!=""'>
            and t.company =#{company}
        </if>

    </select>

    <select id="queryBindCompanyCount" resultType="int">
        select count(1) from sys_dept t left join sys_user_company t1 on t.company=t1.company where t1.user_id=#{userId}
        and t.org_type='1' and t1.id is not null
        <if test='company!="null" and company!=""'>
            and t.company =#{company}
        </if>

    </select>


    <insert id="addUserBindCompany">
        insert into sys_user_company (user_id,company) values
        <foreach item="item" index="index" collection="list" separator=",">
            (#{userId},#{item})
        </foreach>
    </insert>


    <delete id="deleteCompany">
        delete from sys_user_company where user_id=#{userId} and company in
        <foreach item="item" index="index" collection="list" separator="," open="(" close=")">
            #{item}
        </foreach>
    </delete>


</mapper>
