<?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.com.ctop.common.module.mapper.UserCompanyMapper">

    <select id="allCompany" resultType="com.alibaba.fastjson.JSONObject">
        SELECT company_id as 'companyId', company_name as 'companyName'
        FROM user_company
        GROUP BY company_id
    </select>
    <select id="getCompanyInfoByAccountId" resultType="com.alibaba.fastjson.JSONObject">
        SELECT company_id AS 'companyId', company_name AS 'companyName'
        FROM user_company
        WHERE user_id = (
            SELECT user_id
            FROM ctop_user_allocation
            WHERE account_id = #{accountId}
            LIMIT 1
            )

    </select>
    <select id="getCompanyInfoByUserId" resultType="com.alibaba.fastjson.JSONObject">
        SELECT company_id AS 'companyId', company_name AS 'companyName'
        FROM user_company
        WHERE user_id = #{userId}
    </select>

    <select id="getUserIdListByCompanyId" resultType="String">
        SELECT user_id
        FROM user_company
        WHERE company_id = #{companyId}
    </select>


</mapper>
