<?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.item.mapper.ItemLargeScreenMapper">

    <!--查获总数-->
    <select id="getTotalSum" resultType="java.math.BigDecimal">
        select ifnull(sum(isi.quantity), 0) totalSum
        from item_seizure_record isr
        left join item_seizure_items isi on isr.id = isi.record_id
        where isr.process_status=3
        <if test="specifiedDate != null">and date(isr.seizure_time) = #{specifiedDate}</if>
        <if test="startDate != null and endDate != null">
            and (isr.seizure_time >= #{startDate}
            and isr.seizure_time <![CDATA[ < ]]> date_add(#{endDate}, interval 1 day))
        </if>
        <if test="inspectBrigadeId != null">and isr.inspect_brigade_id = #{inspectBrigadeId}</if>
        <if test="inspectDepartmentId != null">and isr.inspect_department_id = #{inspectDepartmentId}</if>
        <if test="inspectTeamId != null">and isr.inspect_team_id = #{inspectTeamId}</if>
        <if test="isPolice == '1' or isPolice == 1 ">and isi.handling_method = 'TRANSFER_TO_AIRPORT_POLICE'</if>
        <if test="isConceal=='1' or isConceal == 1">and isi.is_active_concealment = 1</if>
    </select>

    <!--移交公安情况-->
    <select id="police" resultType="com.sundot.airport.item.domain.ItemLargeScreenInfoDto">
        select isr.id mId,
        isi.id dId,
        isr.inspect_user_id inspectUserId,
        isr.inspect_user_name inspectUserName,
        isr.seizure_time seizureTime,
        isr.terminl_code terminlCode,
        isr.terminl_name terminlName,
        isr.regional_code regionalCode,
        isr.regional_name regionalName,
        isr.channel_code channelCode,
        isr.channel_name channelName,
        isr.check_method checkMethod,
        isr.check_method_desc checkMethodDesc,
        isr.inspect_brigade_id inspectBrigadeId,
        isr.inspect_brigade_name inspectBrigadeName,
        isr.inspect_department_id inspectDepartmentId,
        isr.inspect_department_name inspectDepartmentName,
        isr.inspect_team_id inspectTeamId,
        isr.inspect_team_name inspectTeamName,
        isi.category_code_one categoryCodeOne,
        isi.category_name_one categoryNameOne,
        isi.category_code_two categoryCodeTwo,
        isi.category_name_two categoryNameTwo,
        isi.item_code itemCode,
        isi.item_name itemName,
        isi.quantity quantity,
        isi.unit unit,
        isi.unit_desc unitDesc,
        isi.handling_method handlingMethod,
        isi.handling_method_desc handlingMethodDesc,
        isi.is_active_concealment isActiveConcealment,
        isi.check_position_code_one checkPositionCodeOne,
        isi.check_position_name_one checkPositionNameOne,
        isi.check_position_code_two checkPositionCodeOne,
        isi.check_position_name_two checkPositionNameTwo,
        isi.check_position_specific checkPositionSpecific,
        su.nick_name nackName
        from item_seizure_record isr
        left join item_seizure_items isi on isr.id = isi.record_id
        left join sys_user su on isr.inspect_user_id = su.user_id
        where 1 = 1
        and isi.handling_method = 'TRANSFER_TO_AIRPORT_POLICE'
        <if test="specifiedDate != null">and date(isr.seizure_time) = #{specifiedDate}</if>
        <if test="startDate != null and endDate != null">
            and (isr.seizure_time >= #{startDate}
            and isr.seizure_time <![CDATA[ < ]]> date_add(#{endDate}, interval 1 day))
        </if>
        <if test="inspectBrigadeId != null">and isr.inspect_brigade_id = #{inspectBrigadeId}</if>
        <if test="inspectDepartmentId != null">and isr.inspect_department_id = #{inspectDepartmentId}</if>
        <if test="inspectTeamId != null">and isr.inspect_team_id = #{inspectTeamId}</if>
        <if test="userId != null">and isr.inspect_user_id = #{userId}</if>
        and isr.process_status=3
        order by isr.seizure_time desc
    </select>

    <!--故意隐匿情况-->
    <select id="conceal" resultType="com.sundot.airport.item.domain.ItemLargeScreenInfoDto">
        select isr.id mId,
        isi.id dId,
        isr.inspect_user_id inspectUserId,
        isr.inspect_user_name inspectUserName,
        isr.seizure_time seizureTime,
        isr.terminl_code terminlCode,
        isr.terminl_name terminlName,
        isr.regional_code regionalCode,
        isr.regional_name regionalName,
        isr.channel_code channelCode,
        isr.channel_name channelName,
        isr.check_method checkMethod,
        isr.check_method_desc checkMethodDesc,
        isi.category_code_one categoryCodeOne,
        isi.category_name_one categoryNameOne,
        isi.category_code_two categoryCodeTwo,
        isi.category_name_two categoryNameTwo,
        isi.item_code itemCode,
        isi.item_name itemName,
        isi.quantity quantity,
        isi.unit unit,
        isi.unit_desc unitDesc,
        isi.handling_method handlingMethod,
        isi.handling_method_desc handlingMethodDesc,
        isi.is_active_concealment isActiveConcealment,
        isi.check_position_code_one checkPositionCodeOne,
        isi.check_position_name_one checkPositionNameOne,
        isi.check_position_code_two checkPositionCodeOne,
        isi.check_position_name_two checkPositionNameTwo,
        isi.check_position_specific checkPositionSpecific
        from item_seizure_record isr
        left join item_seizure_items isi on isr.id = isi.record_id
        where 1 = 1
        and isi.is_active_concealment = 1
        and isr.process_status=3
        <if test="specifiedDate != null">and date(isr.seizure_time) = #{specifiedDate}</if>
        <if test="startDate != null and endDate != null">
            and (isr.seizure_time >= #{startDate}
            and isr.seizure_time <![CDATA[ < ]]> date_add(#{endDate}, interval 1 day))
        </if>
        <if test="inspectBrigadeId != null">and isr.inspect_brigade_id = #{inspectBrigadeId}</if>
        <if test="inspectDepartmentId != null">and isr.inspect_department_id = #{inspectDepartmentId}</if>
        <if test="inspectTeamId != null">and isr.inspect_team_id = #{inspectTeamId}</if>
        order by isr.seizure_time desc
    </select>

    <!--查获类别分布-->
    <select id="category" resultType="com.sundot.airport.item.domain.ItemLargeScreenCommonDto">
        select
        <!--判断参数里的级别类型，根据级别类型，查询对应级别-->
        <if test="levelType == 1">
            isi.category_code_one code,
            isi.category_name_one name,
            sum(isi.quantity) total
        </if>
        <if test="levelType == 2">
            isi.category_code_two code,
            isi.category_name_two name,
            sum(isi.quantity) total
        </if>
        from item_seizure_record isr
        left join item_seizure_items isi on isr.id = isi.record_id
        where isr.process_status=3
        <if test="specifiedDate != null">and date(isr.seizure_time) = #{specifiedDate}</if>
        <if test="startDate != null and endDate != null">
            and (isr.seizure_time >= #{startDate}
            and isr.seizure_time <![CDATA[ < ]]> date_add(#{endDate}, interval 1 day))
        </if>
        <if test="levelType == 2  and categoryCode != null and  categoryCode != ''">
            and isi.category_code_one = #{categoryCode}
        </if>
        <if test="inspectBrigadeId != null">and isr.inspect_brigade_id = #{inspectBrigadeId}</if>
        <if test="inspectDepartmentId != null">and isr.inspect_department_id = #{inspectDepartmentId}</if>
        <if test="inspectTeamId != null">and isr.inspect_team_id = #{inspectTeamId}</if>
        <if test="isPolice=='1' or isPolice==1">and isi.handling_method = 'TRANSFER_TO_AIRPORT_POLICE'</if>
        <if test="isConceal=='1' or isConceal==1">and isi.is_active_concealment = 1</if>
        group by
        <if test="levelType == 1">
            isi.category_code_one,
            isi.category_name_one
        </if>
        <if test="levelType == 2">
            isi.category_code_two,
            isi.category_name_two
        </if>
        order by total desc
    </select>

    <!--查获岗位分布-->
    <select id="post" resultType="com.sundot.airport.item.domain.ItemLargeScreenCommonDto">
        select isr.check_method code,
        isr.check_method_desc name,
        sum(isi.quantity) total
        from item_seizure_record isr
        left join item_seizure_items isi on isr.id = isi.record_id
        where isr.process_status=3
        <if test="specifiedDate != null">and date(isr.seizure_time) = #{specifiedDate}</if>
        <if test="startDate != null and endDate != null">
            and (isr.seizure_time >= #{startDate}
            and isr.seizure_time <![CDATA[ < ]]> date_add(#{endDate}, interval 1 day))
        </if>
        <if test="inspectBrigadeId != null">and isr.inspect_brigade_id = #{inspectBrigadeId}</if>
        <if test="inspectDepartmentId != null">and isr.inspect_department_id = #{inspectDepartmentId}</if>
        <if test="inspectTeamId != null">and isr.inspect_team_id = #{inspectTeamId}</if>
        <if test="isPolice=='1' or isPolice==1">and isi.handling_method = 'TRANSFER_TO_AIRPORT_POLICE'</if>
        <if test="isConceal=='1' or isConceal==1">and isi.is_active_concealment = 1</if>
        group by isr.check_method,
        isr.check_method_desc
        order by total desc
    </select>

    <!--查获总数量+移交公安数量+故意隐匿数量-->
    <select id="getTotalSome" resultType="com.sundot.airport.item.domain.ItemLargeScreenTotalSomeDto">
        select ifnull(sum(isi.quantity), 0) total,
        ifnull(sum(case when isi.handling_method = 'TRANSFER_TO_AIRPORT_POLICE' then isi.quantity else 0 end),
        0) as policeTotal,
        ifnull(sum(case when isi.is_active_concealment = 1 then isi.quantity else 0 end), 0) as concealTotal
        from item_seizure_record isr
        left join item_seizure_items isi on isr.id = isi.record_id
        where isr.process_status=3
        <if test="specifiedDate != null">and date(isr.seizure_time) = #{specifiedDate}</if>
        <if test="startDate != null and endDate != null">
            and (isr.seizure_time >= #{startDate}
            and isr.seizure_time <![CDATA[ < ]]> date_add(#{endDate}, interval 1 day))
        </if>
        <if test="inspectBrigadeId != null">and isr.inspect_brigade_id = #{inspectBrigadeId}</if>
        <if test="inspectDepartmentId != null">and isr.inspect_department_id = #{inspectDepartmentId}</if>
        <if test="inspectTeamId != null">and isr.inspect_team_id = #{inspectTeamId}</if>
    </select>

    <!--查获总数量+移交公安数量+故意隐匿数量 不只查审批通过的-->
    <select id="getPcTotalSome" resultType="com.sundot.airport.item.domain.ItemLargeScreenTotalSomeDto">
        select ifnull(sum(isi.quantity), 0) total,
        ifnull(sum(case when isi.handling_method = 'TRANSFER_TO_AIRPORT_POLICE' then isi.quantity else 0 end),
        0) as policeTotal,
        ifnull(sum(case when isi.is_active_concealment = 1 then isi.quantity else 0 end), 0) as concealTotal
        from item_seizure_record isr
        left join item_seizure_items isi on isr.id = isi.record_id
        where 1=1
        <if test="specifiedDate != null">and date(isr.seizure_time) = #{specifiedDate}</if>
        <if test="startDate != null and endDate != null">
            and (isr.seizure_time >= #{startDate}
            and isr.seizure_time <![CDATA[ < ]]> date_add(#{endDate}, interval 1 day))
        </if>
        <if test="inspectStationId != null">and isr.inspect_station_id = #{inspectStationId}</if>
        <if test="inspectBrigadeId != null">and isr.inspect_brigade_id = #{inspectBrigadeId}</if>
        <if test="inspectDepartmentId != null">and isr.inspect_department_id = #{inspectDepartmentId}</if>
        <if test="inspectTeamId != null">and isr.inspect_team_id = #{inspectTeamId}</if>
    </select>

    <!--查获排名-按大队-->
    <select id="rankByBrigade" resultType="com.sundot.airport.item.domain.ItemLargeScreenCommonDto">
        select isr.inspect_brigade_id id,
        isr.inspect_brigade_name name,
        sum(isi.quantity) total
        from item_seizure_record isr
        left join item_seizure_items isi on isr.id = isi.record_id
        where isr.process_status=3
        <if test="specifiedDate != null">and date(isr.seizure_time) = #{specifiedDate}</if>
        <if test="startDate != null and endDate != null">
            and (isr.seizure_time >= #{startDate}
            and isr.seizure_time <![CDATA[ < ]]> date_add(#{endDate}, interval 1 day))
        </if>
        <if test="inspectBrigadeId != null">and isr.inspect_brigade_id = #{inspectBrigadeId}</if>
        <if test="inspectDepartmentId != null">and isr.inspect_department_id = #{inspectDepartmentId}</if>
        <if test="inspectTeamId != null">and isr.inspect_team_id = #{inspectTeamId}</if>
        <if test="categoryCodeOne != null and  categoryCodeOne != ''">
            and isi.category_code_one = #{categoryCodeOne}
        </if>
        <if test="categoryCodeTwo != null and  categoryCodeTwo != ''">
            and isi.category_code_two = #{categoryCodeTwo}
        </if>
        <if test="isPolice=='1' or isPolice==1 ">and isi.handling_method = 'TRANSFER_TO_AIRPORT_POLICE'</if>
        <if test="isConceal=='1' or isConceal==1 ">and isi.is_active_concealment = 1</if>
        group by isr.inspect_brigade_id,
        isr.inspect_brigade_name
        order by total desc
    </select>

    <!--查获排名-按科室-->
    <select id="rankByDepartment" resultType="com.sundot.airport.item.domain.ItemLargeScreenCommonDto">
        select isr.inspect_department_id id,
        isr.inspect_department_name name,
        sum(isi.quantity) total
        from item_seizure_record isr
        left join item_seizure_items isi on isr.id = isi.record_id
        where isr.process_status=3
        <if test="specifiedDate != null">and date(isr.seizure_time) = #{specifiedDate}</if>
        <if test="startDate != null and endDate != null">
            and (isr.seizure_time >= #{startDate}
            and isr.seizure_time <![CDATA[ < ]]> date_add(#{endDate}, interval 1 day))
        </if>
        <if test="inspectBrigadeId != null">and isr.inspect_brigade_id = #{inspectBrigadeId}</if>
        <if test="inspectDepartmentId != null">and isr.inspect_department_id = #{inspectDepartmentId}</if>
        <if test="inspectTeamId != null">and isr.inspect_team_id = #{inspectTeamId}</if>
        <if test="categoryCodeOne != null and  categoryCodeOne != ''">
            and isi.category_code_one = #{categoryCodeOne}
        </if>
        <if test="categoryCodeTwo != null and  categoryCodeTwo != ''">
            and isi.category_code_two = #{categoryCodeTwo}
        </if>
        <if test="isPolice=='1' or isPolice==1 ">and isi.handling_method = 'TRANSFER_TO_AIRPORT_POLICE'</if>
        <if test="isConceal=='1' or isConceal==1 ">and isi.is_active_concealment = 1</if>
        group by isr.inspect_department_id,
        isr.inspect_department_name
        order by total desc
    </select>

    <!--查获排名-按班组-->
    <select id="rankByTeam" resultType="com.sundot.airport.item.domain.ItemLargeScreenCommonDto">
        select isr.inspect_team_id id,
        isr.inspect_team_name name,
        sum(isi.quantity) total
        from item_seizure_record isr
        left join item_seizure_items isi on isr.id = isi.record_id
        where isr.process_status=3
        <if test="specifiedDate != null">and date(isr.seizure_time) = #{specifiedDate}</if>
        <if test="startDate != null and endDate != null">
            and (isr.seizure_time >= #{startDate}
            and isr.seizure_time <![CDATA[ < ]]> date_add(#{endDate}, interval 1 day))
        </if>
        <if test="inspectBrigadeId != null">and isr.inspect_brigade_id = #{inspectBrigadeId}</if>
        <if test="inspectDepartmentId != null">and isr.inspect_department_id = #{inspectDepartmentId}</if>
        <if test="inspectTeamId != null">and isr.inspect_team_id = #{inspectTeamId}</if>
        <if test="categoryCodeOne != null and  categoryCodeOne != ''">
            and isi.category_code_one = #{categoryCodeOne}
        </if>
        <if test="categoryCodeTwo != null and  categoryCodeTwo != ''">
            and isi.category_code_two = #{categoryCodeTwo}
        </if>
        <if test="isPolice=='1' or isPolice==1">and isi.handling_method = 'TRANSFER_TO_AIRPORT_POLICE'</if>
        <if test="isConceal=='1' or  isConceal==1">and isi.is_active_concealment = 1</if>
        group by isr.inspect_team_id,
        isr.inspect_team_name
        order by total desc
    </select>

    <!--查获排名-按个人-->
    <select id="rankByIndividual" resultType="com.sundot.airport.item.domain.ItemLargeScreenCommonDto">
        select isr.inspect_user_id id,
        isr.inspect_user_name name,
        sum(isi.quantity) total
        from item_seizure_record isr
        left join item_seizure_items isi on isr.id = isi.record_id
        where isr.process_status=3
        <if test="specifiedDate != null">and date(isr.seizure_time) = #{specifiedDate}</if>
        <if test="startDate != null and endDate != null">
            and (isr.seizure_time >= #{startDate}
            and isr.seizure_time <![CDATA[ < ]]> date_add(#{endDate}, interval 1 day))
        </if>
        <if test="inspectBrigadeId != null">and isr.inspect_brigade_id = #{inspectBrigadeId}</if>
        <if test="inspectDepartmentId != null">and isr.inspect_department_id = #{inspectDepartmentId}</if>
        <if test="inspectTeamId != null">and isr.inspect_team_id = #{inspectTeamId}</if>
        <if test="categoryCodeOne != null and  categoryCodeOne != ''">
            and isi.category_code_one = #{categoryCodeOne}
        </if>
        <if test="categoryCodeTwo != null and  categoryCodeTwo != ''">
            and isi.category_code_two = #{categoryCodeTwo}
        </if>
        <if test="isPolice=='1' or isPolice==1 ">and isi.handling_method = 'TRANSFER_TO_AIRPORT_POLICE'</if>
        <if test="isConceal=='1' or isConceal==1 ">and isi.is_active_concealment = 1</if>
        group by isr.inspect_user_id,
        isr.inspect_user_name
        order by total desc
    </select>

    <!--查获时段分布-->
    <select id="timeSpan" resultType="com.sundot.airport.item.domain.ItemLargeScreenTimeSpanDto">
        select hours.hour as hourOfDay,
        ifnull(sum(isi.quantity), 0) as total
        from (select 0 as hour
        union
        select 1
        union
        select 2
        union
        select 3
        union
        select 4
        union
        select 5
        union
        select 6
        union
        select 7
        union
        select 8
        union
        select 9
        union
        select 10
        union
        select 11
        union
        select 12
        union
        select 13
        union
        select 14
        union
        select 15
        union
        select 16
        union
        select 17
        union
        select 18
        union
        select 19
        union
        select 20
        union
        select 21
        union
        select 22
        union
        select 23) as hours
        left join item_seizure_record isr
        on hours.hour = hour (isr.seizure_time)
        <if test="specifiedDate != null and specifiedDate != null">
            and date (isr.seizure_time) = #{specifiedDate}
        </if>
        left join item_seizure_items isi
        on isr.id = isi.record_id
        where isr.process_status=3
        <if test="startDate != null and endDate != null">
            and (isr.seizure_time >= #{startDate}
            and isr.seizure_time <![CDATA[ < ]]> date_add(#{endDate}, interval 1 day))
        </if>
        <if test="categoryCodeOne != null and  categoryCodeOne != ''">
            and isi.category_code_one = #{categoryCodeOne}
        </if>
        <if test="categoryCodeTwo != null and  categoryCodeTwo != ''">
            and isi.category_code_two = #{categoryCodeTwo}
        </if>
        <if test="inspectBrigadeId != null">and isr.inspect_brigade_id = #{inspectBrigadeId}</if>
        <if test="inspectDepartmentId != null">and isr.inspect_department_id = #{inspectDepartmentId}</if>
        <if test="inspectTeamId != null">and isr.inspect_team_id = #{inspectTeamId}</if>
        <if test="userId != null">and isr.inspect_user_id = #{userId}</if>
        <if test="isPolice=='1' or isPolice==1 ">and isi.handling_method = 'TRANSFER_TO_AIRPORT_POLICE'</if>
        <if test="isConceal=='1' or  isConceal==1 ">and isi.is_active_concealment = 1</if>
        group by hours.hour
        order by hours.hour
    </select>

    <!--按天统计趋势数据-->
    <select id="dailyTrend" resultType="com.sundot.airport.item.domain.ItemLargeScreenDailyTrendDto">
        select DATE(isr.seizure_time) as date,
        ifnull(sum(isi.quantity), 0) as total
        from item_seizure_record isr
        left join item_seizure_items isi on isr.id = isi.record_id
        where isr.process_status = 3
        <if test="startDate != null and endDate != null">
            and (isr.seizure_time >= #{startDate}
            and isr.seizure_time <![CDATA[ < ]]> date_add(#{endDate}, interval 1 day))
        </if>
        <if test="inspectBrigadeId != null">and isr.inspect_brigade_id = #{inspectBrigadeId}</if>
        <if test="inspectDepartmentId != null">and isr.inspect_department_id = #{inspectDepartmentId}</if>
        <if test="inspectTeamId != null">and isr.inspect_team_id = #{inspectTeamId}</if>
        <if test="categoryCodeOne != null and categoryCodeOne != ''">
            and isi.category_code_one = #{categoryCodeOne}
        </if>
        <if test="categoryCodeTwo != null and categoryCodeTwo != ''">
            and isi.category_code_two = #{categoryCodeTwo}
        </if>
        <if test="isPolice=='1' or isPolice==1 ">and isi.handling_method = 'TRANSFER_TO_AIRPORT_POLICE'</if>
        <if test="isConceal=='1' or isConceal==1 ">and isi.is_active_concealment = 1</if>
        group by DATE(isr.seizure_time)
        order by date
    </select>

    <!--查获位置分布-->
    <select id="position" resultType="com.sundot.airport.item.domain.ItemLargeScreenPositionDto">
        select isi.check_position_code_one checkPositionCodeOne,
        isi.check_position_name_one checkPositionNameOne,
        isi.check_position_code_two checkPositionCodeTwo,
        isi.check_position_name_two checkPositionNameTwo,
        sum(isi.quantity) total
        from item_seizure_record isr
        left join item_seizure_items isi on isr.id = isi.record_id
        where isr.process_status=3
        <if test="specifiedDate != null">and date(isr.seizure_time) = #{specifiedDate}</if>
        <if test="startDate != null and endDate != null">
            and (isr.seizure_time >= #{startDate}
            and isr.seizure_time <![CDATA[ < ]]> date_add(#{endDate}, interval 1 day))
        </if>
        <if test="inspectBrigadeId != null">and isr.inspect_brigade_id = #{inspectBrigadeId}</if>
        <if test="inspectDepartmentId != null">and isr.inspect_department_id = #{inspectDepartmentId}</if>
        <if test="inspectTeamId != null">and isr.inspect_team_id = #{inspectTeamId}</if>
        <if test="isPolice=='1' or isPolice==1">and isi.handling_method = 'TRANSFER_TO_AIRPORT_POLICE'</if>
        <if test="isConceal=='1' or isConceal==1">and isi.is_active_concealment = 1</if>
        group by isi.check_position_code_one,
        isi.check_position_name_one,
        isi.check_position_code_two,
        isi.check_position_name_two
        order by checkPositionCodeOne, checkPositionCodeTwo, total desc
    </select>

    <!--查获通道分布-->
    <select id="channel" resultType="com.sundot.airport.item.domain.ItemLargeScreenChannelDto">
        select isr.regional_code channelCode,
        isr.regional_name channelName,
        isi.category_code_one categoryCode,
        isi.category_name_one categoryName,
        sum(isi.quantity) total
        from item_seizure_record isr
        left join item_seizure_items isi on isr.id = isi.record_id
        where isr.process_status=3
        <if test="specifiedDate != null">and date(isr.seizure_time) = #{specifiedDate}</if>
        <if test="startDate != null and endDate != null">
            and (isr.seizure_time >= #{startDate}
            and isr.seizure_time <![CDATA[ < ]]> date_add(#{endDate}, interval 1 day))
        </if>
        <if test="inspectBrigadeId != null">and isr.inspect_brigade_id = #{inspectBrigadeId}</if>
        <if test="inspectDepartmentId != null">and isr.inspect_department_id = #{inspectDepartmentId}</if>
        <if test="inspectTeamId != null">and isr.inspect_team_id = #{inspectTeamId}</if>
        group by isr.regional_code,
        isr.regional_name,
        isi.category_code_one,
        isi.category_name_one
        order by channelCode, categoryCode, total desc
    </select>

    <select id="appPosition" resultType="com.sundot.airport.item.domain.ItemLargeScreenPositionAppDto">
        select
        <if test="levelType == 1">
            isi.check_position_code_one code,
            isi.check_position_name_one name,
        </if>
        <if test="levelType == 2">
            isi.check_position_code_two code,
            isi.check_position_name_two name,
        </if>
        sum(isi.quantity) total
        from item_seizure_record isr
        left join item_seizure_items isi on isr.id = isi.record_id
        where isr.process_status=3
        <if test="specifiedDate != null">and date(isr.seizure_time) = #{specifiedDate}</if>
        <if test="startDate != null and endDate != null">
            and (isr.seizure_time >= #{startDate}
            and isr.seizure_time <![CDATA[ < ]]> date_add(#{endDate}, interval 1 day))
        </if>
        <if test="inspectBrigadeId != null">and isr.inspect_brigade_id = #{inspectBrigadeId}</if>
        <if test="inspectDepartmentId != null">and isr.inspect_department_id = #{inspectDepartmentId}</if>
        <if test="inspectTeamId != null">and isr.inspect_team_id = #{inspectTeamId}</if>
        <if test="isPolice=='1' or isPolice==1">and isi.handling_method = 'TRANSFER_TO_AIRPORT_POLICE'</if>
        <if test="isConceal=='1' or isConceal==1">and isi.is_active_concealment = 1</if>
        <if test="levelType == 2 and positionCode!=null and positionCode!=''">and isi.check_position_code_one =
            #{positionCode}
        </if>
        group by
        <if test="levelType == 1">
            isi.check_position_code_one,
            isi.check_position_name_one
        </if>
        <if test="levelType == 2">
            isi.check_position_code_two,
            isi.check_position_name_two
        </if>
        order by total desc
    </select>

    <!--批量获取个人在岗时长-->
    <select id="getBatchIndividualWorkDuration"
            resultType="com.sundot.airport.item.domain.ItemLargeScreenWorkDurationDto">
        select apr.user_id as id,
        ifnull(sum(apr.work_duration), 0) as workDuration
        from attendance_post_record apr
        where apr.user_id in
        <foreach collection="userIds" item="userId" open="(" separator="," close=")">
            #{userId}
        </foreach>
        and apr.work_duration > 0
        <if test="startDate != null and endDate != null">
            and apr.check_in_time <![CDATA[ < ]]> date_add(#{endDate}, interval 1 day)
            and apr.check_out_time >= #{startDate}
        </if>
        group by apr.user_id
    </select>

    <!--批量获取班组在岗时长-->
    <select id="getBatchTeamWorkDuration" resultType="com.sundot.airport.item.domain.ItemLargeScreenWorkDurationDto">
        select apr.attendance_team_id as id,
        ifnull(sum(apr.work_duration), 0) as workDuration
        from attendance_post_record apr
        where apr.attendance_team_id in
        <foreach collection="teamIds" item="teamId" open="(" separator="," close=")">
            #{teamId}
        </foreach>
        and apr.work_duration > 0
        <if test="startDate != null and endDate != null">
            and apr.check_in_time <![CDATA[ < ]]> date_add(#{endDate}, interval 1 day)
            and apr.check_out_time >= #{startDate}
        </if>
        group by apr.attendance_team_id
    </select>

    <!--获取科室在岗时长-->
    <select id="getDepartmentWorkDuration" resultType="java.math.BigDecimal">
        select ifnull(sum(apr.work_duration), 0) as workDuration
        from attendance_post_record apr
        where 1 = 1
        and apr.work_duration > 0
        <if test="startDate != null and endDate != null">
            and apr.check_in_time <![CDATA[ < ]]> date_add(#{endDate}, interval 1 day)
            and apr.check_out_time >= #{startDate}
        </if>
        <if test="inspectDepartmentId != null">
            and apr.attendance_department_id = #{inspectDepartmentId}
        </if>
    </select>

    <!--获取大队在岗时长-->
    <select id="getBrigadeWorkDuration" resultType="java.math.BigDecimal">
        select ifnull(sum(apr.work_duration), 0) as workDuration
        from attendance_post_record apr
        where 1 = 1
        and apr.work_duration > 0
        <if test="startDate != null and endDate != null">
            and apr.check_in_time <![CDATA[ < ]]> date_add(#{endDate}, interval 1 day)
            and apr.check_out_time >= #{startDate}
        </if>
        <if test="inspectBrigadeId != null">
            and apr.attendance_brigade_id = #{inspectBrigadeId}
        </if>
    </select>

    <!--获取在岗时长-->
    <select id="getWorkDuration" resultType="java.math.BigDecimal">
        select ifnull(sum(apr.work_duration), 0) as workDuration
        from attendance_post_record apr
        where 1 = 1
        and apr.work_duration > 0
        <if test="startDate != null and endDate != null">
            and apr.check_in_time <![CDATA[ < ]]> date_add(#{endDate}, interval 1 day)
            and apr.check_out_time >= #{startDate}
        </if>
        <if test="inspectBrigadeId != null">
            and apr.attendance_brigade_id = #{inspectBrigadeId}
        </if>
        <if test="inspectDepartmentId != null">
            and apr.attendance_department_id = #{inspectDepartmentId}
        </if>
        <if test="inspectTeamId != null">
            and apr.attendance_team_id = #{inspectTeamId}
        </if>
    </select>

    <!-- 查询全站查获违禁品 -->
    <select id="selectProhibitedItemsTop3" resultType="com.sundot.airport.item.domain.dto.ProhibitedItemsTop3DTO">
        SELECT
        isi.category_code_two AS categoryCode,
        isi.category_name_two AS categoryName,
        SUM(isi.quantity) AS quantity,
        0 AS percentage,
        0 AS rank
        FROM item_seizure_record isr
        LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
        WHERE isr.process_status = 3 and isr.inspect_station_id = #{inspectStationId}
        <if test="startDate != null and endDate != null">
            AND isr.seizure_time >= #{startDate}
            AND isr.seizure_time <![CDATA[ < ]]> date_add(#{endDate}, interval 1 day)
        </if>
        GROUP BY isi.category_code_two, isi.category_name_two
        ORDER BY quantity DESC
        LIMIT 3
    </select>

    <!-- 查询隐匿重点部位 Top1 -->
    <select id="selectConcealmentPositionTop1"
            resultType="com.sundot.airport.item.domain.dto.ConcealmentPositionTop1DTO">
        SELECT
        isi.check_position_code_one AS checkPositionCodeOne,
        isi.check_position_name_one AS checkPositionNameOne,
        isi.check_position_code_two AS checkPositionCodeTwo,
        isi.check_position_name_two AS checkPositionNameTwo,
        SUM(isi.quantity) AS quantity
        FROM item_seizure_record isr
        LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
        WHERE isr.process_status = 3
        AND isr.inspect_station_id = #{inspectStationId}
        AND isi.is_active_concealment = 1
        <if test="startDate != null and endDate != null">
            AND isr.seizure_time >= #{startDate}
            AND isr.seizure_time <![CDATA[ < ]]> date_add(#{endDate}, interval 1 day)
        </if>
        GROUP BY isi.check_position_code_one, isi.check_position_name_one,
        isi.check_position_code_two, isi.check_position_name_two
        ORDER BY quantity DESC
        LIMIT 1
    </select>

    <!-- 使用报表-运行情况-查获模块 -->
    <select id="getSeizureModule" resultType="com.sundot.airport.common.core.domain.SysUsageReportSeizureDto">
        select isr.id id,
        isi.quantity total,
        isr.check_method positionCode,
        isr.check_method_desc positionName,
        isi.category_code_one categoryCode,
        isi.category_name_one categoryName,
        isi.check_position_code_one partCode,
        isi.check_position_name_one partName,
        isi.is_active_concealment hidden,
        isr.process_status processStatus
        from item_seizure_record isr
        inner join item_seizure_items isi on isi.record_id = isr.id
        where 1 = 1
        <if test="startDate != null and endDate != null">
            AND isr.seizure_time >= #{startDate}
            AND isr.seizure_time <![CDATA[ < ]]> date_add(#{endDate}, interval 1 day)
        </if>
    </select>

    <!-- X 光机漏检数据 -->
    <select id="xRayMissCheck" resultType="com.sundot.airport.item.domain.ItemXRayMissCheckDto">
        select
        isr.inspect_brigade_name brigadeName,
        isr.inspect_department_name departmentName,
        isr.inspect_team_name teamName,
        isr.xray_operator_name userName,
        isi.category_name_two missItemName,
        isi.quantity missQuantity,
        concat(
        ifnull(isi.check_position_name_one, ''),
        if(isi.check_position_name_two is null or isi.check_position_name_two = '', '', concat('/',
        isi.check_position_name_two)),
        if(isi.check_position_specific is null or isi.check_position_specific = '', '', concat('/',
        isi.check_position_specific))
        ) missPosition,
        isr.channel_name channelName,
        isr.seizure_time missTime
        from item_seizure_record isr
        inner join item_seizure_items isi on isi.record_id = isr.id
        where isr.power_on_instruction=1
        <if test="specifiedDate != null">
            and date(isr.seizure_time) = #{specifiedDate}
        </if>
        <if test="startDate != null and endDate != null">
            and (isr.seizure_time >= #{startDate}
            AND isr.seizure_time <![CDATA[ < ]]> date_add(#{endDate}, interval 1 day))
        </if>
        <if test="inspectStationId != null">
            and isr.inspect_station_id = #{inspectStationId}
        </if>
        <if test="inspectBrigadeId != null">
            and isr.inspect_brigade_id = #{inspectBrigadeId}
        </if>
        <if test="inspectDepartmentId != null">
            and isr.inspect_department_id = #{inspectDepartmentId}
        </if>
        <if test="inspectTeamId != null">
            and isr.inspect_team_id = #{inspectTeamId}
        </if>
        and isr.process_status = 3
        order by isr.seizure_time desc
    </select>

    <!-- X 光机漏检人员统计 TOP3 -->
    <select id="xRayMissCheckUserStatsTop3" resultType="com.sundot.airport.item.domain.ItemXRayMissCheckUserStatsDto">
        select
        isr.xray_operator_id xrayOperatorId,
        isr.xray_operator_name xrayOperatorName,
        sum(isi.quantity) totalMissQuantity
        from item_seizure_record isr
        inner join item_seizure_items isi on isi.record_id = isr.id
        where isr.power_on_instruction=1
        <if test="specifiedDate != null">
            and date(isr.seizure_time) = #{specifiedDate}
        </if>
        <if test="startDate != null and endDate != null">
            and (isr.seizure_time >= #{startDate}
            AND isr.seizure_time <![CDATA[ < ]]> date_add(#{endDate}, interval 1 day))
        </if>
        <if test="inspectStationId != null">
            and isr.inspect_station_id = #{inspectStationId}
        </if>
        <if test="inspectBrigadeId != null">
            and isr.inspect_brigade_id = #{inspectBrigadeId}
        </if>
        <if test="inspectDepartmentId != null">
            and isr.inspect_department_id = #{inspectDepartmentId}
        </if>
        <if test="inspectTeamId != null">
            and isr.inspect_team_id = #{inspectTeamId}
        </if>
        and isr.process_status = 3
        and isr.xray_operator_id is not null
        group by isr.xray_operator_id, isr.xray_operator_name
        order by totalMissQuantity desc
        limit 3
    </select>

    <!-- 查询移交公安违禁品 TOP3(用于消息推送) -->
    <select id="selectProhibitedItemsTop3ForPush"
            resultType="com.sundot.airport.item.domain.push.SeizureMessagePushDTO$ProhibitedItemTop3">
        SELECT
        isi.category_code_one AS categoryCodeOne,
        isi.category_name_one AS categoryNameOne,
        isi.category_code_two AS categoryCodeTwo,
        isi.category_name_two AS categoryNameTwo,
        SUM(isi.quantity) AS seizureCount,
        0 AS rank
        FROM item_seizure_record isr
        LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
        WHERE isr.process_status = 3
        <if test="inspectStationId != null">
            AND isr.inspect_station_id = #{inspectStationId}
        </if>
        <if test="inspectBrigadeId != null">
            and isr.inspect_brigade_id = #{inspectBrigadeId}
        </if>
        <if test="inspectDepartmentId != null">
            and isr.inspect_department_id = #{inspectDepartmentId}
        </if>
        <if test="inspectTeamId != null">
            and isr.inspect_team_id = #{inspectTeamId}
        </if>
        <if test="startDate != null and endDate != null">
            AND isr.seizure_time &gt;= #{startDate}
            AND isr.seizure_time &lt; date_add(#{endDate}, interval 1 day)
        </if>
        AND isi.handling_method = 'TRANSFER_TO_AIRPORT_POLICE'
        GROUP BY isi.category_code_one, isi.category_name_one, isi.category_code_two, isi.category_name_two
        ORDER BY seizureCount DESC
        LIMIT 3
    </select>

    <!-- 查询故意隐匿物品藏匿部位 TOP3(用于消息推送) -->
    <select id="selectConcealmentPositionsTop3ForPush"
            resultType="com.sundot.airport.item.domain.push.SeizureMessagePushDTO$ConcealmentPositionTop3">
        SELECT
        isi.check_position_code_one AS positionCodeOne,
        isi.check_position_name_one AS positionNameOne,
        isi.check_position_code_two AS positionCodeTwo,
        isi.check_position_name_two AS positionNameTwo,
        SUM(isi.quantity) AS concealmentCount,
        0 AS rank
        FROM item_seizure_record isr
        LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
        WHERE isr.process_status = 3
        <if test="inspectStationId != null">
            AND isr.inspect_station_id = #{inspectStationId}
        </if>
        <if test="inspectBrigadeId != null">
            and isr.inspect_brigade_id = #{inspectBrigadeId}
        </if>
        <if test="inspectDepartmentId != null">
            and isr.inspect_department_id = #{inspectDepartmentId}
        </if>
        <if test="inspectTeamId != null">
            and isr.inspect_team_id = #{inspectTeamId}
        </if>
        <if test="startDate != null and endDate != null">
            AND isr.seizure_time &gt;= #{startDate}
            AND isr.seizure_time &lt; date_add(#{endDate}, interval 1 day)
        </if>
        AND isi.is_active_concealment = 1
        GROUP BY isi.check_position_code_one, isi.check_position_name_one, isi.check_position_code_two,
        isi.check_position_name_two
        ORDER BY concealmentCount DESC
        LIMIT 3
    </select>

    <!-- 查询移交公安违禁品高发通道 TOP3(用于消息推送) -->
    <select id="selectHighRiskChannelsTop3ForPush"
            resultType="com.sundot.airport.item.domain.push.SeizureMessagePushDTO$HighRiskChannelTop3">
        SELECT
        isr.terminl_name AS terminalName,
        isr.regional_name AS areaName,
        isr.channel_name AS channelName,
        SUM(isi.quantity) AS transferToPoliceCount,
        0 AS rank
        FROM item_seizure_record isr
        LEFT JOIN item_seizure_items isi ON isr.id = isi.record_id
        WHERE isr.process_status = 3
        <if test="inspectStationId != null">
            AND isr.inspect_station_id = #{inspectStationId}
        </if>
        <if test="inspectBrigadeId != null">
            and isr.inspect_brigade_id = #{inspectBrigadeId}
        </if>
        <if test="inspectDepartmentId != null">
            and isr.inspect_department_id = #{inspectDepartmentId}
        </if>
        <if test="inspectTeamId != null">
            and isr.inspect_team_id = #{inspectTeamId}
        </if>
        <if test="startDate != null and endDate != null">
            AND isr.seizure_time &gt;= #{startDate}
            AND isr.seizure_time &lt; date_add(#{endDate}, interval 1 day)
        </if>
        AND isi.handling_method = 'TRANSFER_TO_AIRPORT_POLICE'
        AND isr.terminl_name IS NOT NULL
        AND isr.regional_name IS NOT NULL
        AND isr.channel_name IS NOT NULL
        GROUP BY isr.terminl_name, isr.regional_name, isr.channel_name
        ORDER BY transferToPoliceCount DESC
        LIMIT 3
    </select>

</mapper>