<?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.planExecute.mapper.PlanExecuteMapper">
    <select id="pageList" parameterType="com.baomidou.mybatisplus.core.conditions.Wrapper" resultType="com.unis.emergencySupportCenter.modular.planExecute.entity.PlanExecute">
        SELECT
            t1.id,
            t1.planName,
            t1.emergencyLevel,
            t1.disasterLevel,
            t1.enterpriseCount,
            t1.grainCount,
            t1.create_time
        FROM
            (
                SELECT
                    pe.id,
                    pf.plan_name planName,
                    pf.emergency_level emergencyLevel,
                    pf.disaster_level disasterLevel,
                    CASE
                WHEN COUNT(ee.es_plan_execute_id) = 0 THEN
                    NULL
                END enterpriseCount,
                SUM(ee.quantity) grainCount,
                pe.create_time,
                ee.sys_org_id,
                pe.create_user,
                pe.es_online_plan_formulation_id
            FROM
                biz_es_ep_plan_execute pe
            LEFT JOIN biz_es_ep_online_plan_formulation pf ON pe.es_online_plan_formulation_id = pf.id
            LEFT JOIN biz_es_ep_plan_execute_enterprise ee ON pe.id = ee.es_plan_execute_id
            ) t1
        ${ew.customSqlSegment}
    </select>
</mapper>