<?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.sundot.airport.check.mapper.CheckLargeScreenMapper">

    <select id="planOverview" resultType="com.sundot.airport.check.domain.CheckLargeScreenPlanOverviewDto">
        select date_format(ct.check_start_time, '%Y-%m-%d') date,
        ct.check_category type,
        ct.check_category_desc typeDesc,
        count(ct.id) total
        from check_task ct
        where 1 = 1
        <if test="isSelfCheck != null">
            and ct.is_self_check=#{isSelfCheck}
        </if>
        <if test="createId != null">
            and ct.create_id=#{createId}
        </if>
        <if test="deptId != null">
            and ct.self_check_dept_id=#{deptId}
        </if>
        <if test="startDate != null and endDate != null">
            and (ct.check_start_time >= #{startDate}
            and ct.check_start_time <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day))
        </if>
        group by date_format(ct.check_start_time, '%Y-%m-%d'), ct.check_category, ct.check_category_desc
    </select>

    <select id="planDistribution" resultType="com.sundot.airport.check.domain.CheckLargeScreenCommonDto">
        select cpi.category_code_one code, category_name_one name, count(cpi.id) total
        from check_task ct
        inner join check_project_item cpi on (cpi.source_id = ct.id and cpi.type = 'CHECK_TASK')
        where 1 = 1
        <if test="isSelfCheck != null">
            and ct.is_self_check=#{isSelfCheck}
        </if>
        <if test="createId != null">
            and ct.create_id=#{createId}
        </if>
        <if test="deptId != null">
            and ct.self_check_dept_id=#{deptId}
        </if>
        <if test="startDate != null and endDate != null">
            and (ct.check_start_time >= #{startDate}
            and ct.check_start_time <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day))
        </if>
        group by cpi.category_code_one, cpi.category_name_one
        order by total desc
    </select>

    <select id="planStatistics" resultType="com.sundot.airport.check.domain.CheckTask">
        select ct.*
        from check_task ct
        where 1 = 1
        <if test="isSelfCheck != null">
            and ct.is_self_check=#{isSelfCheck}
        </if>
        <if test="createId != null">
            and ct.create_id=#{createId}
        </if>
        <if test="deptId != null">
            and ct.self_check_dept_id=#{deptId}
        </if>
        <if test="startDate != null and endDate != null">
            and (ct.check_start_time >= #{startDate}
            and ct.check_start_time <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day))
        </if>
        order by ct.check_start_time desc
    </select>

    <select id="problemDistribution" resultType="com.sundot.airport.check.domain.CheckLargeScreenProblemDto">
        select cpi.category_code_one code, cpi.category_name_one name, count(cpi.id) total
        from check_correction cc
        inner join check_project_item cpi on (cpi.source_id = cc.id and cpi.type = 'CHECK_CORRECTION')
        where 1 = 1
        <if test="isSelfCheck != null">
            and cc.is_self_check=#{isSelfCheck}
        </if>
        <if test="checkedBrigadeId != null">
            and cc.checked_brigade_id=#{checkedBrigadeId}
        </if>
        <if test="checkedDepartmentId != null">
            and cc.checked_department_id=#{checkedDepartmentId}
        </if>
        <if test="checkedTeamId != null">
            and cc.checked_team_id=#{checkedTeamId}
        </if>
        <if test="startDate != null and endDate != null">
            and (cc.check_time >= #{startDate}
            and cc.check_time <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day))
        </if>
        group by cpi.category_code_one, cpi.category_name_one
        order by total desc
    </select>

    <select id="problemComparisonBrigade" resultType="com.sundot.airport.check.domain.CheckLargeScreenProblemDto">
        select cc.checked_brigade_id deptId,
        cc.checked_brigade_name deptName,
        cpi.category_code_one code,
        cpi.category_name_one name,
        count(cpi.id) total
        from check_correction cc
        inner join check_project_item cpi on (cpi.source_id = cc.id and cpi.type = 'CHECK_CORRECTION')
        where 1 = 1
        <if test="isSelfCheck != null">
            and cc.is_self_check=#{isSelfCheck}
        </if>
        <if test="checkedBrigadeId != null">
            and cc.checked_brigade_id=#{checkedBrigadeId}
        </if>
        <if test="checkedDepartmentId != null">
            and cc.checked_department_id=#{checkedDepartmentId}
        </if>
        <if test="checkedTeamId != null">
            and cc.checked_team_id=#{checkedTeamId}
        </if>
        <if test="startDate != null and endDate != null">
            and (cc.check_time >= #{startDate}
            and cc.check_time <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day))
        </if>
        group by cc.checked_brigade_id, cc.checked_brigade_name, cpi.category_code_one, cpi.category_name_one
        order by total desc
    </select>

    <select id="problemComparison" resultType="com.sundot.airport.check.domain.CheckLargeScreenProblemDto">
        select cc.checked_department_id deptId,
        cc.checked_department_name deptName,
        cpi.category_code_one code,
        cpi.category_name_one name,
        count(cpi.id) total
        from check_correction cc
        inner join check_project_item cpi on (cpi.source_id = cc.id and cpi.type = 'CHECK_CORRECTION')
        where 1 = 1
        <if test="isSelfCheck != null">
            and cc.is_self_check=#{isSelfCheck}
        </if>
        <if test="checkedBrigadeId != null">
            and cc.checked_brigade_id=#{checkedBrigadeId}
        </if>
        <if test="checkedDepartmentId != null">
            and cc.checked_department_id=#{checkedDepartmentId}
        </if>
        <if test="checkedTeamId != null">
            and cc.checked_team_id=#{checkedTeamId}
        </if>
        <if test="startDate != null and endDate != null">
            and (cc.check_time >= #{startDate}
            and cc.check_time <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day))
        </if>
        group by cc.checked_department_id, cc.checked_department_name, cpi.category_code_one, cpi.category_name_one
        order by total desc
    </select>

    <select id="problemComparisonTwoBrigade" resultType="com.sundot.airport.check.domain.CheckLargeScreenProblemDto">
        select cc.checked_brigade_id deptId,
        cc.checked_brigade_name deptName,
        cpi.category_code_two code,
        cpi.category_name_two name,
        count(cpi.id) total
        from check_correction cc
        inner join check_project_item cpi on (cpi.source_id = cc.id and cpi.type = 'CHECK_CORRECTION')
        where 1 = 1
        <if test="isSelfCheck != null">
            and cc.is_self_check=#{isSelfCheck}
        </if>
        <if test="checkedBrigadeId != null">
            and cc.checked_brigade_id=#{checkedBrigadeId}
        </if>
        <if test="checkedDepartmentId != null">
            and cc.checked_department_id=#{checkedDepartmentId}
        </if>
        <if test="checkedTeamId != null">
            and cc.checked_team_id=#{checkedTeamId}
        </if>
        <if test="categoryCodeOne != null and categoryCodeOne != ''">
            and cpi.category_code_one=#{categoryCodeOne}
        </if>
        <if test="startDate != null and endDate != null">
            and (cc.check_time >= #{startDate}
            and cc.check_time <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day))
        </if>
        group by cc.checked_brigade_id, cc.checked_brigade_name, cpi.category_code_two, cpi.category_name_two
        order by total desc
    </select>

    <select id="problemComparisonTwo" resultType="com.sundot.airport.check.domain.CheckLargeScreenProblemDto">
        select cc.checked_department_id deptId,
        cc.checked_department_name deptName,
        cpi.category_code_two code,
        cpi.category_name_two name,
        count(cpi.id) total
        from check_correction cc
        inner join check_project_item cpi on (cpi.source_id = cc.id and cpi.type = 'CHECK_CORRECTION')
        where 1 = 1
        <if test="isSelfCheck != null">
            and cc.is_self_check=#{isSelfCheck}
        </if>
        <if test="checkedBrigadeId != null">
            and cc.checked_brigade_id=#{checkedBrigadeId}
        </if>
        <if test="checkedDepartmentId != null">
            and cc.checked_department_id=#{checkedDepartmentId}
        </if>
        <if test="checkedTeamId != null">
            and cc.checked_team_id=#{checkedTeamId}
        </if>
        <if test="categoryCodeOne != null and categoryCodeOne != ''">
            and cpi.category_code_one=#{categoryCodeOne}
        </if>
        <if test="startDate != null and endDate != null">
            and (cc.check_time >= #{startDate}
            and cc.check_time <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day))
        </if>
        group by cc.checked_department_id, cc.checked_department_name, cpi.category_code_two, cpi.category_name_two
        order by total desc
    </select>

    <select id="problemComparisonBanZu" resultType="com.sundot.airport.check.domain.CheckLargeScreenProblemDto">
        select cc.checked_team_id deptId,
        cc.checked_team_name deptName,
        cpi.category_code_one code,
        cpi.category_name_one name,
        count(cpi.id) total
        from check_correction cc
        inner join check_project_item cpi on (cpi.source_id = cc.id and cpi.type = 'CHECK_CORRECTION')
        where 1 = 1
        <if test="isSelfCheck != null">
            and cc.is_self_check=#{isSelfCheck}
        </if>
        <if test="checkedBrigadeId != null">
            and cc.checked_brigade_id=#{checkedBrigadeId}
        </if>
        <if test="checkedDepartmentId != null">
            and cc.checked_department_id=#{checkedDepartmentId}
        </if>
        <if test="checkedTeamId != null">
            and cc.checked_team_id=#{checkedTeamId}
        </if>
        <if test="startDate != null and endDate != null">
            and (cc.check_time >= #{startDate}
            and cc.check_time <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day))
        </if>
        group by cc.checked_team_id, cc.checked_team_name, cpi.category_code_one, cpi.category_name_one
        order by total desc
    </select>

    <select id="problemComparisonTwoBanZu" resultType="com.sundot.airport.check.domain.CheckLargeScreenProblemDto">
        select cc.checked_team_id deptId,
        cc.checked_team_name deptName,
        cpi.category_code_two code,
        cpi.category_name_two name,
        count(cpi.id) total
        from check_correction cc
        inner join check_project_item cpi on (cpi.source_id = cc.id and cpi.type = 'CHECK_CORRECTION')
        where 1 = 1
        <if test="isSelfCheck != null">
            and cc.is_self_check=#{isSelfCheck}
        </if>
        <if test="checkedBrigadeId != null">
            and cc.checked_brigade_id=#{checkedBrigadeId}
        </if>
        <if test="checkedDepartmentId != null">
            and cc.checked_department_id=#{checkedDepartmentId}
        </if>
        <if test="checkedTeamId != null">
            and cc.checked_team_id=#{checkedTeamId}
        </if>
        <if test="categoryCodeOne != null and categoryCodeOne != ''">
            and cpi.category_code_one=#{categoryCodeOne}
        </if>
        <if test="startDate != null and endDate != null">
            and (cc.check_time >= #{startDate}
            and cc.check_time <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day))
        </if>
        group by cc.checked_team_id, cc.checked_team_name, cpi.category_code_two, cpi.category_name_two
        order by total desc
    </select>

    <select id="problemTrendBrigade" resultType="com.sundot.airport.check.domain.CheckLargeScreenProblemTrendDto">
        select date_format(cc.check_time, '%Y-%m-%d') date,
        cc.checked_brigade_id id,
        cc.checked_brigade_name name,
        count(cpi.id) total
        from check_correction cc
        inner join check_project_item cpi on (cpi.source_id = cc.id and cpi.type = 'CHECK_CORRECTION')
        where 1 = 1
        <if test="isSelfCheck != null">
            and cc.is_self_check=#{isSelfCheck}
        </if>
        <if test="checkedBrigadeId != null">
            and cc.checked_brigade_id=#{checkedBrigadeId}
        </if>
        <if test="checkedDepartmentId != null">
            and cc.checked_department_id=#{checkedDepartmentId}
        </if>
        <if test="checkedTeamId != null">
            and cc.checked_team_id=#{checkedTeamId}
        </if>
        <if test="categoryCodeOne != null and categoryCodeOne != ''">
            and cpi.category_code_one=#{categoryCodeOne}
        </if>
        <if test="startDate != null and endDate != null">
            and (cc.check_time >= #{startDate}
            and cc.check_time <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day))
        </if>
        group by date_format(cc.check_time, '%Y-%m-%d'), cc.checked_brigade_id, cc.checked_brigade_name
        order by total desc
    </select>

    <select id="problemTrend" resultType="com.sundot.airport.check.domain.CheckLargeScreenProblemTrendDto">
        select date_format(cc.check_time, '%Y-%m-%d') date,
        cc.checked_department_id id,
        cc.checked_department_name name,
        count(cpi.id) total
        from check_correction cc
        inner join check_project_item cpi on (cpi.source_id = cc.id and cpi.type = 'CHECK_CORRECTION')
        where 1 = 1
        <if test="isSelfCheck != null">
            and cc.is_self_check=#{isSelfCheck}
        </if>
        <if test="checkedBrigadeId != null">
            and cc.checked_brigade_id=#{checkedBrigadeId}
        </if>
        <if test="checkedDepartmentId != null">
            and cc.checked_department_id=#{checkedDepartmentId}
        </if>
        <if test="checkedTeamId != null">
            and cc.checked_team_id=#{checkedTeamId}
        </if>
        <if test="categoryCodeOne != null and categoryCodeOne != ''">
            and cpi.category_code_one=#{categoryCodeOne}
        </if>
        <if test="startDate != null and endDate != null">
            and (cc.check_time >= #{startDate}
            and cc.check_time <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day))
        </if>
        group by date_format(cc.check_time, '%Y-%m-%d'), cc.checked_department_id, cc.checked_department_name
        order by total desc
    </select>

    <select id="problemTrendBanZu" resultType="com.sundot.airport.check.domain.CheckLargeScreenProblemTrendDto">
        select date_format(cc.check_time, '%Y-%m-%d') date,
        cc.checked_team_id id,
        cc.checked_team_name name,
        count(cpi.id) total
        from check_correction cc
        inner join check_project_item cpi on (cpi.source_id = cc.id and cpi.type = 'CHECK_CORRECTION')
        where 1 = 1
        <if test="isSelfCheck != null">
            and cc.is_self_check=#{isSelfCheck}
        </if>
        <if test="checkedBrigadeId != null">
            and cc.checked_brigade_id=#{checkedBrigadeId}
        </if>
        <if test="checkedDepartmentId != null">
            and cc.checked_department_id=#{checkedDepartmentId}
        </if>
        <if test="checkedTeamId != null">
            and cc.checked_team_id=#{checkedTeamId}
        </if>
        <if test="categoryCodeOne != null and categoryCodeOne != ''">
            and cpi.category_code_one=#{categoryCodeOne}
        </if>
        <if test="startDate != null and endDate != null">
            and (cc.check_time >= #{startDate}
            and cc.check_time <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day))
        </if>
        group by date_format(cc.check_time, '%Y-%m-%d'), cc.checked_team_id, cc.checked_team_name
        order by total desc
    </select>

    <select id="correction" resultType="com.sundot.airport.check.domain.CheckLargeScreenCorrectionAssistDto">
        select cc.checked_brigade_id brigadeId,
        cc.checked_brigade_name brigadeName,
        cc.checked_department_id departmentId,
        cc.checked_department_name departmentName,
        cc.checked_team_id teamId,
        cc.checked_team_name teamName,
        case
        when cc.status = 'RECTIFIED' and cc.rectification_deadline >= cc.completion_time
        then 'ON_TIME_COMPLETED'
        when cc.status = 'RECTIFIED' and cc.rectification_deadline <![CDATA[ < ]]> cc.completion_time
        then 'OVER_TIME_COMPLETED'
        when cc.status = 'UNDER_RECTIFICATION' and CURRENT_DATE() <![CDATA[ <= ]]> cc.rectification_deadline
        then 'ON_TIME_UNFINISHED'
        when cc.status = 'UNDER_RECTIFICATION' and CURRENT_DATE() > cc.rectification_deadline
        then 'OVER_TIME_UNFINISHED'
        else 'OTHER' end type
        from check_correction cc
        where 1 = 1
        <if test="isSelfCheck != null">
            and cc.is_self_check=#{isSelfCheck}
        </if>
        <if test="startDate != null and endDate != null">
            and (cc.check_time >= #{startDate}
            and cc.check_time <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day))
        </if>
        <if test="checkedBrigadeId != null">
            and cc.checked_brigade_id=#{checkedBrigadeId}
        </if>
        <if test="checkedDepartmentId != null">
            and cc.checked_department_id=#{checkedDepartmentId}
        </if>
        <if test="checkedTeamId != null">
            and cc.checked_team_id=#{checkedTeamId}
        </if>
    </select>

    <select id="correctionDistributionBrigade"
            resultType="com.sundot.airport.check.domain.CheckLargeScreenCorrectionDto">
        select temp.deptId deptId,
        temp.deptName deptName,
        ifnull(sum(case when temp.type = 'ON_TIME_COMPLETED' then 1 else 0 end), 0) onTimeCompletedCount,
        ifnull(sum(case when temp.type = 'OVER_TIME_COMPLETED' then 1 else 0 end), 0) overTimeCompletedCount,
        ifnull(sum(case when temp.type = 'ON_TIME_UNFINISHED' then 1 else 0 end), 0) onTimeUnfinishedCount,
        ifnull(sum(case when temp.type = 'OVER_TIME_UNFINISHED' then 1 else 0 end), 0) overTimeUnfinishedCount,
        ifnull(sum(case when temp.type = 'OTHER' then 1 else 0 end), 0) otherCount
        from (select cc.checked_brigade_id deptId,
        cc.checked_brigade_name deptName,
        case
        when cc.status = 'RECTIFIED' and cc.rectification_deadline >= cc.completion_time
        then 'ON_TIME_COMPLETED'
        when cc.status = 'RECTIFIED' and cc.rectification_deadline <![CDATA[ < ]]> cc.completion_time
        then 'OVER_TIME_COMPLETED'
        when cc.status = 'UNDER_RECTIFICATION' and CURRENT_DATE() <![CDATA[ <= ]]> cc.rectification_deadline
        then 'ON_TIME_UNFINISHED'
        when cc.status = 'UNDER_RECTIFICATION' and CURRENT_DATE() > cc.rectification_deadline
        then 'OVER_TIME_UNFINISHED'
        else 'OTHER' end type
        from check_correction cc
        where 1 = 1
        <if test="isSelfCheck != null">
            and cc.is_self_check=#{isSelfCheck}
        </if>
        <if test="checkedBrigadeId != null">
            and cc.checked_brigade_id=#{checkedBrigadeId}
        </if>
        <if test="checkedDepartmentId != null">
            and cc.checked_department_id=#{checkedDepartmentId}
        </if>
        <if test="checkedTeamId != null">
            and cc.checked_team_id=#{checkedTeamId}
        </if>
        <if test="startDate != null and endDate != null">
            and (cc.check_time >= #{startDate}
            and cc.check_time <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day))
        </if>) temp
        group by temp.deptId, temp.deptName
    </select>

    <select id="correctionDistribution" resultType="com.sundot.airport.check.domain.CheckLargeScreenCorrectionDto">
        select temp.deptId deptId,
        temp.deptName deptName,
        ifnull(sum(case when temp.type = 'ON_TIME_COMPLETED' then 1 else 0 end), 0) onTimeCompletedCount,
        ifnull(sum(case when temp.type = 'OVER_TIME_COMPLETED' then 1 else 0 end), 0) overTimeCompletedCount,
        ifnull(sum(case when temp.type = 'ON_TIME_UNFINISHED' then 1 else 0 end), 0) onTimeUnfinishedCount,
        ifnull(sum(case when temp.type = 'OVER_TIME_UNFINISHED' then 1 else 0 end), 0) overTimeUnfinishedCount,
        ifnull(sum(case when temp.type = 'OTHER' then 1 else 0 end), 0) otherCount
        from (select cc.checked_department_id deptId,
        cc.checked_department_name deptName,
        case
        when cc.status = 'RECTIFIED' and cc.rectification_deadline >= cc.completion_time
        then 'ON_TIME_COMPLETED'
        when cc.status = 'RECTIFIED' and cc.rectification_deadline <![CDATA[ < ]]> cc.completion_time
        then 'OVER_TIME_COMPLETED'
        when cc.status = 'UNDER_RECTIFICATION' and CURRENT_DATE() <![CDATA[ <= ]]> cc.rectification_deadline
        then 'ON_TIME_UNFINISHED'
        when cc.status = 'UNDER_RECTIFICATION' and CURRENT_DATE() > cc.rectification_deadline
        then 'OVER_TIME_UNFINISHED'
        else 'OTHER' end type
        from check_correction cc
        where 1 = 1
        <if test="isSelfCheck != null">
            and cc.is_self_check=#{isSelfCheck}
        </if>
        <if test="checkedBrigadeId != null">
            and cc.checked_brigade_id=#{checkedBrigadeId}
        </if>
        <if test="checkedDepartmentId != null">
            and cc.checked_department_id=#{checkedDepartmentId}
        </if>
        <if test="checkedTeamId != null">
            and cc.checked_team_id=#{checkedTeamId}
        </if>
        <if test="startDate != null and endDate != null">
            and (cc.check_time >= #{startDate}
            and cc.check_time <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day))
        </if>) temp
        group by temp.deptId, temp.deptName
    </select>

    <select id="correctionDistributionBanZu" resultType="com.sundot.airport.check.domain.CheckLargeScreenCorrectionDto">
        select temp.deptId deptId,
        temp.deptName deptName,
        ifnull(sum(case when temp.type = 'ON_TIME_COMPLETED' then 1 else 0 end), 0) onTimeCompletedCount,
        ifnull(sum(case when temp.type = 'OVER_TIME_COMPLETED' then 1 else 0 end), 0) overTimeCompletedCount,
        ifnull(sum(case when temp.type = 'ON_TIME_UNFINISHED' then 1 else 0 end), 0) onTimeUnfinishedCount,
        ifnull(sum(case when temp.type = 'OVER_TIME_UNFINISHED' then 1 else 0 end), 0) overTimeUnfinishedCount,
        ifnull(sum(case when temp.type = 'OTHER' then 1 else 0 end), 0) otherCount
        from (select cc.checked_team_id deptId,
        cc.checked_team_name deptName,
        case
        when cc.status = 'RECTIFIED' and cc.rectification_deadline >= cc.completion_time
        then 'ON_TIME_COMPLETED'
        when cc.status = 'RECTIFIED' and cc.rectification_deadline <![CDATA[ < ]]> cc.completion_time
        then 'OVER_TIME_COMPLETED'
        when cc.status = 'UNDER_RECTIFICATION' and CURRENT_DATE() <![CDATA[ <= ]]> cc.rectification_deadline
        then 'ON_TIME_UNFINISHED'
        when cc.status = 'UNDER_RECTIFICATION' and CURRENT_DATE() > cc.rectification_deadline
        then 'OVER_TIME_UNFINISHED'
        else 'OTHER' end type
        from check_correction cc
        where 1 = 1
        <if test="isSelfCheck != null">
            and cc.is_self_check=#{isSelfCheck}
        </if>
        <if test="checkedBrigadeId != null">
            and cc.checked_brigade_id=#{checkedBrigadeId}
        </if>
        <if test="checkedDepartmentId != null">
            and cc.checked_department_id=#{checkedDepartmentId}
        </if>
        <if test="checkedTeamId != null">
            and cc.checked_team_id=#{checkedTeamId}
        </if>
        <if test="startDate != null and endDate != null">
            and (cc.check_time >= #{startDate}
            and cc.check_time <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day))
        </if>) temp
        group by temp.deptId, temp.deptName
    </select>

    <select id="inspectionExecute" resultType="com.sundot.airport.check.domain.CheckLargeScreenInspectionExecuteDto">
        select ct.id               taskId,
               ct.task_code        taskCode,
               ct.task_name        taskName,
               ct.check_level      checkLevel,
               ct.check_level_desc checkLevelDesc,
               ct.rule_type_num    ruleTypeNum,
               ct.check_start_time checkStartTime,
               ct.check_end_time   checkEndTime
        from check_task ct
        where 1 = 1
          and current_date() between ct.check_start_time and ct.check_end_time
    </select>

    <select id="inspectionExecuteItem"
            resultType="com.sundot.airport.check.domain.CheckLargeScreenInspectionExecuteItemDto">
        select cr.task_code taskCode,
        cr.checker_id userId,
        cr.checker_name userName,
        count(distinct cr.id) checkOrderCount,
        count(distinct cc.id) rectificationOrderCount,
        count(distinct cpi.id) unqualifiedProjectCount
        from check_record cr
        left join check_correction cc on cc.check_record_id = cr.id
        left join check_project_item cpi on (cpi.source_id = cc.id and cpi.type = 'CHECK_CORRECTION')
        where 1 = 1
        and cr.task_code in
        <foreach item="item" collection="list" open="(" separator="," close=")">
            #{item}
        </foreach>
        and (cr.check_time
        between concat(curdate(), ' 00:00:00') and concat(date_add(curdate(), interval 1 day), ' 00:00:00'))
        group by cr.task_code, cr.checker_id, cr.checker_name
    </select>

    <select id="inspectionExecuteUser"
            resultType="com.sundot.airport.check.domain.CheckLargeScreenInspectionExecuteUserDto">
        select su.user_id,
        su.user_name,
        su.nick_name,
        su.dept_id,
        sr.role_id,
        sr.role_name,
        sr.role_key
        from sys_user su
        inner join sys_user_role sur on su.user_id = sur.user_id
        inner join sys_role sr on sr.role_id = sur.role_id
        where 1 = 1
        and su.del_flag = '0'
        and sr.del_flag = '0'
        and su.user_id in
        <foreach item="item" collection="list" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

    <select id="getProblemBrigade" resultType="com.sundot.airport.check.domain.CheckLargeScreenProblemDto">
        select distinct cc.checked_brigade_id deptId,
        cc.checked_brigade_name deptName
        from check_correction cc
        inner join check_project_item cpi on (cpi.source_id = cc.id and cpi.type = 'CHECK_CORRECTION')
        where 1 = 1
        <if test="isSelfCheck != null">
            and cc.is_self_check=#{isSelfCheck}
        </if>
        <if test="checkedBrigadeId != null">
            and cc.checked_brigade_id=#{checkedBrigadeId}
        </if>
        <if test="checkedDepartmentId != null">
            and cc.checked_department_id=#{checkedDepartmentId}
        </if>
        <if test="checkedTeamId != null">
            and cc.checked_team_id=#{checkedTeamId}
        </if>
        <if test="startDate != null and endDate != null">
            and (cc.check_time >= #{startDate}
            and cc.check_time <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day))
        </if>
    </select>

    <select id="getProblemDepartment" resultType="com.sundot.airport.check.domain.CheckLargeScreenProblemDto">
        select distinct cc.checked_department_id deptId,
        cc.checked_department_name deptName
        from check_correction cc
        inner join check_project_item cpi on (cpi.source_id = cc.id and cpi.type = 'CHECK_CORRECTION')
        where 1 = 1
        <if test="isSelfCheck != null">
            and cc.is_self_check=#{isSelfCheck}
        </if>
        <if test="checkedBrigadeId != null">
            and cc.checked_brigade_id=#{checkedBrigadeId}
        </if>
        <if test="checkedDepartmentId != null">
            and cc.checked_department_id=#{checkedDepartmentId}
        </if>
        <if test="checkedTeamId != null">
            and cc.checked_team_id=#{checkedTeamId}
        </if>
        <if test="startDate != null and endDate != null">
            and (cc.check_time >= #{startDate}
            and cc.check_time <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day))
        </if>
    </select>

    <select id="getProblemTeam" resultType="com.sundot.airport.check.domain.CheckLargeScreenProblemDto">
        select distinct cc.checked_team_id deptId,
        cc.checked_team_name deptName
        from check_correction cc
        inner join check_project_item cpi on (cpi.source_id = cc.id and cpi.type = 'CHECK_CORRECTION')
        where 1 = 1
        <if test="isSelfCheck != null">
            and cc.is_self_check=#{isSelfCheck}
        </if>
        <if test="checkedBrigadeId != null">
            and cc.checked_brigade_id=#{checkedBrigadeId}
        </if>
        <if test="checkedDepartmentId != null">
            and cc.checked_department_id=#{checkedDepartmentId}
        </if>
        <if test="checkedTeamId != null">
            and cc.checked_team_id=#{checkedTeamId}
        </if>
        <if test="startDate != null and endDate != null">
            and (cc.check_time >= #{startDate}
            and cc.check_time <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day))
        </if>
    </select>

    <select id="portrait" resultType="com.sundot.airport.check.domain.CheckLargeScreenCorrectionPortraitSqlDto">
        select cc.id id,
        cc.checked_brigade_id checkedBrigadeId,
        cc.checked_brigade_name checkedBrigadeName,
        cc.checked_department_id checkedDepartmentId,
        cc.checked_department_name checkedDepartmentName,
        cc.checked_team_id checkedTeamId,
        cc.checked_team_name checkedTeamName,
        cpi.category_code_one categoryCodeOne,
        cpi.category_name_one categoryNameOne,
        cpi.category_code_two categoryCodeTwo,
        cpi.category_name_two categoryNameTwo,
        cu.user_id userId,
        cu.user_name userName,
        case
        when cc.status = 'RECTIFIED' and cc.rectification_deadline >= cc.completion_time
        then 'ON_TIME_COMPLETED'
        when cc.status = 'RECTIFIED' and cc.rectification_deadline <![CDATA[ < ]]> cc.completion_time
        then 'OVER_TIME_COMPLETED'
        when cc.status = 'UNDER_RECTIFICATION' and CURRENT_DATE() <![CDATA[ <= ]]> cc.rectification_deadline
        then 'ON_TIME_UNFINISHED'
        when cc.status = 'UNDER_RECTIFICATION' and CURRENT_DATE() > cc.rectification_deadline
        then 'OVER_TIME_UNFINISHED'
        else 'OTHER' end correctionType
        from check_correction cc
        inner join check_project_item cpi on (cpi.source_id = cc.id and cpi.type = 'CHECK_CORRECTION')
        inner join check_user cu
        on (cu.source_id = cpi.id and cu.type = 'PROBLEM_RECTIFICATION_INSPECTION_ITEM_DETAILS')
        where 1 = 1
        <if test="isSelfCheck != null">
            and cc.is_self_check=#{isSelfCheck}
        </if>
        <if test="processStatus != null">
            and cc.process_status=#{processStatus}
        </if>
        <if test="checkedBrigadeId != null">
            and cc.checked_brigade_id=#{checkedBrigadeId}
        </if>
        <if test="checkedDepartmentId != null">
            and cc.checked_department_id=#{checkedDepartmentId}
        </if>
        <if test="checkedTeamId != null">
            and cc.checked_team_id=#{checkedTeamId}
        </if>
        <if test="checkedUserId != null">
            and cu.user_id=#{checkedUserId}
        </if>
        <if test="specifiedDate != null and specifiedDate != null">
            and DATE(cc.check_time) = DATE(#{specifiedDate})
        </if>
        <if test="startDate != null and endDate != null">
            and (cc.check_time >= #{startDate}
            and cc.check_time <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day))
        </if>
    </select>

    <select id="managementPromotionRecord" resultType="com.sundot.airport.check.domain.CheckLargeScreenPlanOverviewDto">
        select date_format(cr.check_time, '%Y-%m-%d') date,
        ct.check_category type,
        ct.check_category_desc typeDesc,
        count(cr.id) total
        from check_task ct
        inner join check_record cr on cr.task_code = ct.task_code
        where 1 = 1
        <if test="isSelfCheck != null">
            and ct.is_self_check=#{isSelfCheck}
        </if>
        <if test="checkedBrigadeId != null">
            and cr.checked_brigade_id=#{checkedBrigadeId}
        </if>
        <if test="checkedDepartmentId != null">
            and cr.checked_department_id=#{checkedDepartmentId}
        </if>
        <if test="checkedTeamId != null">
            and cr.checked_team_id=#{checkedTeamId}
        </if>
        <if test="startDate != null and endDate != null">
            and (cr.check_time >= #{startDate}
            and cr.check_time <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day))
        </if>
        group by date_format(cr.check_time, '%Y-%m-%d'), ct.check_category, ct.check_category_desc
        order by date desc
    </select>

    <select id="managementPromotionCorrection"
            resultType="com.sundot.airport.check.domain.CheckLargeScreenCorrectionDto">
        select ifnull(sum(case when temp.type = 'ON_TIME_COMPLETED' then 1 else 0 end), 0) onTimeCompletedCount,
        ifnull(sum(case when temp.type = 'OVER_TIME_COMPLETED' then 1 else 0 end), 0) overTimeCompletedCount,
        ifnull(sum(case when temp.type = 'ON_TIME_UNFINISHED' then 1 else 0 end), 0) onTimeUnfinishedCount,
        ifnull(sum(case when temp.type = 'OVER_TIME_UNFINISHED' then 1 else 0 end), 0) overTimeUnfinishedCount,
        ifnull(sum(case when temp.type = 'OTHER' then 1 else 0 end), 0) otherCount
        from (select
        case
        when cc.status = 'RECTIFIED' and cc.rectification_deadline >= cc.completion_time
        then 'ON_TIME_COMPLETED'
        when cc.status = 'RECTIFIED' and cc.rectification_deadline <![CDATA[ < ]]> cc.completion_time
        then 'OVER_TIME_COMPLETED'
        when cc.status = 'UNDER_RECTIFICATION' and CURRENT_DATE() <![CDATA[ <= ]]> cc.rectification_deadline
        then 'ON_TIME_UNFINISHED'
        when cc.status = 'UNDER_RECTIFICATION' and CURRENT_DATE() > cc.rectification_deadline
        then 'OVER_TIME_UNFINISHED'
        else 'OTHER' end type
        from check_correction cc
        where 1 = 1
        <if test="isSelfCheck != null">
            and cc.is_self_check=#{isSelfCheck}
        </if>
        <if test="processStatus != null">
            and cc.process_status=#{processStatus}
        </if>
        <if test="checkedBrigadeId != null">
            and cc.checked_brigade_id=#{checkedBrigadeId}
        </if>
        <if test="checkedDepartmentId != null">
            and cc.checked_department_id=#{checkedDepartmentId}
        </if>
        <if test="checkedTeamId != null">
            and cc.checked_team_id=#{checkedTeamId}
        </if>
        <if test="startDate != null and endDate != null">
            and (cc.check_time >= #{startDate}
            and cc.check_time <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day))
        </if>) temp
    </select>

</mapper>