<?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.unis.emergencySupportCenter.modular.planExecuteEnterprise.mapper.PlanExecuteEnterpriseMapper">
    <select id="getFourTypeList" resultType="com.unis.emergencySupportCenter.modular.planExecuteEnterprise.entity.PlanExecuteEnterprise">
        SELECT
            t1.id enterpriseId,
            t1.enterprise_name enterpriseName,
            t1.management_area_city sysOrgId,
            t1.enterprise_type enterpriseType,
            dd.DICT_LABEL sysOrgName
        FROM
            (
                SELECT
                    ne.id,
                    ne.enterprise_name,
                    ne.management_area_city,
                    '1' enterprise_type
                FROM
                    biz_es_network_entry ne
                UNION ALL
                    SELECT
                        pe.id,
                        pe.enterprise_name,
                        pe.management_area_city,
                        '2' enterprise_type
                    FROM
                        biz_es_process_enterprise pe
                    UNION ALL
                        SELECT
                            de.id,
                            de.enterprise_name,
                            de.management_area_city,
                            '3' enterprise_type
                        FROM
                            biz_es_delivery_enterprise de
                        UNION ALL
                            SELECT
                                se.id,
                                se.enterprise_name,
                                se.management_area_city,
                                '4' enterprise_type
                            FROM
                                biz_es_storage_enterprise se
            ) t1
        LEFT JOIN dev_dict dd ON t1.management_area_city = dd.ID
    </select>
    <select id="selectDetailList" parameterType="com.baomidou.mybatisplus.core.conditions.Wrapper" resultType="com.unis.emergencySupportCenter.modular.planExecuteEnterprise.entity.PlanExecuteEnterprise">
        SELECT
            ee.enterprise_id,
            ee.sys_org_id,
            (
                CASE
                WHEN ee.enterprise_type = 1 THEN
                    ne.enterprise_name
                WHEN ee.enterprise_type = 2 THEN
                    pe.enterprise_name
                WHEN ee.enterprise_type = 3 THEN
                    de.enterprise_name
                WHEN ee.enterprise_type = 4 THEN
                    se.enterprise_name
                ELSE
                    ''
                END
            ) enterpriseName,
            dd.DICT_LABEL sysOrgName,
            ee.grain_variety_id grainVarietyId,
            be.enumname grainVarietyName,
            ee.grain_grade_id,
            be1.enumname grainGradeName,
            ee.quantity
        FROM
            biz_es_ep_plan_execute_enterprise ee
        LEFT JOIN biz_es_network_entry ne ON ee.enterprise_id = ne.id
        LEFT JOIN biz_es_process_enterprise pe ON ee.enterprise_id = pe.id
        LEFT JOIN biz_es_delivery_enterprise de ON ee.enterprise_id = de.id
        LEFT JOIN biz_es_storage_enterprise se ON ee.enterprise_id = se.id
        LEFT JOIN dev_dict dd ON ee.sys_org_id = dd.ID
        LEFT JOIN depot_qh.basic_enum be ON ee.grain_variety_id = be.enumId
        LEFT JOIN depot_qh.basic_enum be1 ON ee.grain_grade_id = be1.enumId
        ${ew.customSqlSegment}
    </select>
</mapper>