<?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.ledger.mapper.LedgerWarningMapper">

    <select id="selectLedgerSupervisionProblem"
            parameterType="com.sundot.airport.common.dto.LedgerCommonQueryReqVO"
            resultType="java.lang.Integer">
        select count(1)
        from ledger_supervision_problem
        where 1 = 1
        <if test="deptId != null">and dept_id = #{deptId}</if>
        <if test="teamId != null">and team_id = #{teamId}</if>
        <if test="groupId != null">and group_id = #{groupId}</if>
        <if test="userId != null">and inspected_id = #{userId}</if>
        <if test="startDate != null">
            and record_date >= #{startDate}
        </if>
        <if test="endDate != null">
            and record_date <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day)
        </if>
    </select>

    <select id="selectLedgerRealtimeInterception"
            parameterType="com.sundot.airport.common.dto.LedgerCommonQueryReqVO"
            resultType="java.lang.Integer">
        select count(1)
        from ledger_realtime_interception
        where 1 = 1
        <if test="deptId != null">and dept_id = #{deptId}</if>
        <if test="teamId != null">and team_id = #{teamId}</if>
        <if test="groupId != null">and group_id = #{groupId}</if>
        <if test="userId != null">and inspector_id = #{userId}</if>
        <if test="startDate != null">
            and record_date >= #{startDate}
        </if>
        <if test="endDate != null">
            and record_date <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day)
        </if>
    </select>

    <select id="selectLedgerUnsafeEvent"
            parameterType="com.sundot.airport.common.dto.LedgerCommonQueryReqVO"
            resultType="java.lang.Integer">
        select count(1)
        from ledger_unsafe_event
        where 1 = 1
        <if test="deptId != null">and dept_id = #{deptId}</if>
        <if test="teamId != null">and team_id = #{teamId}</if>
        <if test="groupId != null">and group_id = #{groupId}</if>
        <if test="userId != null">and responsible_id = #{userId}</if>
        <if test="startDate != null">
            and record_date >= #{startDate}
        </if>
        <if test="endDate != null">
            and record_date <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day)
        </if>
    </select>

    <select id="selectLedgerSecurityTest"
            parameterType="com.sundot.airport.common.dto.LedgerCommonQueryReqVO"
            resultType="java.lang.Integer">
        select count(1)
        from ledger_security_test
        where 1 = 1
        <if test="deptId != null">and dept_id = #{deptId}</if>
        <if test="teamId != null">and team_id = #{teamId}</if>
        <if test="groupId != null">and group_id = #{groupId}</if>
        <if test="userId != null">and tested_id = #{userId}</if>
        <if test="startDate != null">
            and record_date >= #{startDate}
        </if>
        <if test="endDate != null">
            and record_date <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day)
        </if>
    </select>

    <select id="selectLedgerComplaint"
            parameterType="com.sundot.airport.common.dto.LedgerCommonQueryReqVO"
            resultType="java.lang.Integer">
        select count(1)
        from ledger_complaint
        where 1 = 1
        <if test="deptId != null">and dept_id = #{deptId}</if>
        <if test="teamId != null">and team_id = #{teamId}</if>
        <if test="groupId != null">and group_id = #{groupId}</if>
        <if test="userId != null">and responsible_id = #{userId}</if>
        <if test="startDate != null">
            and record_date >= #{startDate}
        </if>
        <if test="endDate != null">
            and record_date <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day)
        </if>
    </select>

    <select id="selectLedgerServicePatrol"
            parameterType="com.sundot.airport.common.dto.LedgerCommonQueryReqVO"
            resultType="java.lang.Integer">
        select count(1)
        from ledger_service_patrol
        where 1 = 1
        <if test="deptId != null">and dept_id = #{deptId}</if>
        <if test="teamId != null">and team_id = #{teamId}</if>
        <if test="groupId != null">and group_id = #{groupId}</if>
        <if test="userId != null">and inspected_id = #{userId}</if>
        <if test="startDate != null">
            and record_date >= #{startDate}
        </if>
        <if test="endDate != null">
            and record_date <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day)
        </if>
    </select>

    <select id="selectLedgerTerminalBonus"
            parameterType="com.sundot.airport.common.dto.LedgerCommonQueryReqVO"
            resultType="java.lang.Integer">
        select count(1)
        from ledger_terminal_bonus
        where 1 = 1
        <if test="deptId != null">and dept_id = #{deptId}</if>
        <if test="teamId != null">and team_id = #{teamId}</if>
        <if test="groupId != null">and group_id = #{groupId}</if>
        <if test="userId != null">and person_id = #{userId}</if>
        <if test="startDate != null">
            and score_date >= #{startDate}
        </if>
        <if test="endDate != null">
            and score_date <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day)
        </if>
    </select>

    <select id="selectLedgerRewardApproval"
            parameterType="com.sundot.airport.common.dto.LedgerCommonQueryReqVO"
            resultType="java.lang.Integer">
        select count(1)
        from ledger_reward_approval
        where 1 = 1
        <if test="deptId != null">and dept_id = #{deptId}</if>
        <if test="teamId != null">and team_id = #{teamId}</if>
        <if test="groupId != null">and group_id = #{groupId}</if>
        <if test="userId != null">and person_id = #{userId}</if>
        <if test="startDate != null">
            and approve_date >= #{startDate}
        </if>
        <if test="endDate != null">
            and approve_date <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day)
        </if>
    </select>

    <select id="selectLedgerExamScore"
            parameterType="com.sundot.airport.common.dto.LedgerCommonQueryReqVO"
            resultType="java.lang.Integer">
        select count(1)
        from ledger_exam_score
        where 1 = 1
        <if test="deptId != null">and dept_id = #{deptId}</if>
        <if test="teamId != null">and team_id = #{teamId}</if>
        <if test="groupId != null">and group_id = #{groupId}</if>
        <if test="userId != null">and person_id = #{userId}</if>
        <if test="startDate != null">
            and exam_date >= #{startDate}
        </if>
        <if test="endDate != null">
            and exam_date <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day)
        </if>
    </select>

    <select id="selectScoreEventList"
            resultType="com.sundot.airport.ledger.domain.ScoreEvent">
        select person_id personId,
        person_name personName,
        dept_id deptId,
        dept_name deptName,
        dimension_id dimensionId,
        dimension_name dimensionName,
        level2_id level2Id,
        level2_name level2Name,
        event_time eventTime
        from score_event
        where 1 = 1
        and org = '4'
        <if test="startDate != null">
            and event_time >= #{startDate}
        </if>
        <if test="endDate != null">
            and event_time <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day)
        </if>
        <if test="scoreIndicatorIdList != null and scoreIndicatorIdList.size() > 0">
            and level2_id in
            <foreach collection="scoreIndicatorIdList" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <!--        由于person_name存在多用户时person_id为空,因此不能根据person_id进行查询-->
        <!--        <if test="userIdList != null and userIdList.size() > 0">-->
        <!--            and person_id in-->
        <!--            <foreach collection="userIdList" item="item" open="(" separator="," close=")">-->
        <!--                #{item}-->
        <!--            </foreach>-->
        <!--        </if>-->
    </select>

</mapper>