<?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.zhongzheng.modules.recruit.mapper.RecruitCompanyTradeMapper">

    <resultMap type="com.zhongzheng.modules.recruit.domain.RecruitCompanyTrade" id="RecruitCompanyTradeResult">
        <result property="tradeId" column="trade_id"/>
        <result property="tradeName" column="trade_name"/>
        <result property="father" column="father"/>
        <result property="fatherId" column="father_id"/>
        <result property="tenantId" column="tenant_id"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.recruit.vo.RecruitCompanyTradeVo" id="CompanyTradeResultVo">
        <result property="tradeId" column="trade_id"/>
        <result property="tradeName" column="trade_name"/>
        <result property="father" column="father"/>
        <result property="fatherId" column="father_id"/>
        <result property="tenantId" column="tenant_id"/>
        <collection property="companyTradeSonVo" javaType="java.util.List" resultMap="CompanyTradeResultSonVo"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.recruit.vo.RecruitCompanyTradeSonVo" id="CompanyTradeResultSonVo">
        <result property="tradeId" column="son_id"/>
        <result property="tradeName" column="son_name"/>
        <result property="tenantId" column="son_tenant_id"/>
    </resultMap>

    <select id="queryCompanyTradeVo" parameterType="com.zhongzheng.modules.recruit.bo.RecruitCompanyTradeQueryBo" resultMap="CompanyTradeResultVo">
        SELECT
            c.trade_id,
            c.trade_name,
            m.trade_id AS son_id,
            m.trade_name AS son_name,
            m.tenant_id AS son_tenant_id
        FROM
                ( SELECT * FROM recruit_company_trade WHERE father = 0 ) c
                    LEFT JOIN ( SELECT * FROM recruit_company_trade WHERE father = 1 ) m ON c.trade_id = m.father_id
    </select>

</mapper>