<?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.yeejoin.amos.boot.module.jxiop.api.mapper.HouseholdPvDistrictMapper">

    <select id="getList" resultType="com.yeejoin.amos.boot.module.jxiop.api.dto.CompanyTreeDto">
        select hpd.sequence_nbr as id, hpd.name, hpd.parent_id as parentId, hpd.parent_type as type
        from household_pv_district hpd
        where is_delete = 0
    </select>
    <select id="countTreeNodesById" resultType="java.lang.Integer">
        SELECT
            COUNT( 1 )
        FROM
            household_pv_district hpd
        WHERE
            hpd.parent_id = #{id}
    </select>
    <select id="countHouseholdById" resultType="java.lang.Integer">
        SELECT
            COUNT( 1 )
        FROM
            household_pv hp
                LEFT JOIN household_pv_install hpi ON hp.sequence_nbr = hpi.household_pv_id
        WHERE
             hp.district_id = #{id}
    </select>

    <select id="selectIds" resultType="java.lang.Long">
        select  hp.sequence_nbr from  household_pv_district hp where  hp.biz_org_code like concat(#{bizOrgCode}, '%')
    </select>
    <select id="getListByParentId" resultType="com.yeejoin.amos.boot.module.jxiop.api.dto.CompanyTreeDto">
        SELECT
            hpd.sequence_nbr AS id,
            hpd.NAME,
            hpd.parent_id AS parentId,
            hpd.parent_type AS type
        FROM
            household_pv_district hpd
        WHERE
            hpd.is_delete = 0
        <if test="parentId != null and parentId != ''">
            AND hpd.sequence_nbr != #{parentId}
        </if>
        <if test="bizOrgCode != null and bizOrgCode != ''">
            AND  hpd.biz_org_code LIKE CONCAT(#{bizOrgCode}, '%' )
        </if>

    </select>
</mapper>
