<?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.dayou.mapper.CustomerCompanyMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.dayou.entity.CustomerCompany">
        <result column="id" property="id" />
        <result column="deleted" property="deleted" />
        <result column="created" property="created" />
        <result column="modified" property="modified" />
        <result column="parent_id" property="parentId" />
        <result column="level" property="level" />
        <result column="name" property="name" />
        <result column="terminal" property="terminal" />
        <result column="company_type" property="companyType" />
        <result column="org_type" property="orgType" />
        <result column="address" property="address" />
        <result column="phone" property="phone" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,
        deleted,
        created,
        modified,
        parent_id, level, name, terminal, company_type, org_type, address, phone
    </sql>

    <select id="avoidWareHouseApplyByTargetId" parameterType="java.lang.Long" resultType="java.lang.Long">
        SELECT
            id
        FROM
            customer_company
        WHERE
                id = (
                SELECT
                    clientele_id
                FROM
                    personal
                WHERE
                    id = ( SELECT personal_id FROM personal_target WHERE id = #{targetId} AND deleted = 0 ))
          and terminal = 0 and company_type = '银行及金融机构' and parent_id is null
    </select>
</mapper>
