<?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.LedgerRealtimeInterceptionMapper">

    <resultMap id="BaseResultMap" type="com.sundot.airport.ledger.domain.LedgerRealtimeInterception">
        <id property="id" column="id" />
        <result property="recordDate" column="record_date" />
        <result property="recordTime" column="record_time" />
        <result property="deptName" column="dept_name" />
        <result property="deptId" column="dept_id" />
        <result property="teamName" column="team_name" />
        <result property="teamId" column="team_id" />
        <result property="groupName" column="group_name" />
        <result property="groupId" column="group_id" />
        <result property="areaId" column="area_id" />
        <result property="location" column="location" />
        <result property="position" column="position" />
        <result property="positionId" column="position_id" />
        <result property="inspectorName" column="inspector_name" />
        <result property="inspectorId" column="inspector_id" />
        <result property="channelNo" column="channel_no" />
        <result property="passengerName" column="passenger_name" />
        <result property="idCardNo" column="id_card_no" />
        <result property="flightNo" column="flight_no" />
        <result property="itemCategory" column="item_category" />
        <result property="itemName" column="item_name" />
        <result property="itemQuantity" column="item_quantity" />
        <result property="itemWeight" column="item_weight" />
        <result property="handlingMethod" column="handling_method" />
        <result property="resultHandling" column="result_handling" />
        <result property="problemType" column="problem_type" />
        <result property="rectificationMeasures" column="rectification_measures" />
        <result property="problemLevel" column="problem_level" />
        <result property="attachment" column="attachment" />
        <result property="problemCategory" column="problem_category" />
        <result property="personalReview" column="personal_review" />
        <result property="teamReview" column="team_review" />
        <result property="qualityOfficer" column="quality_officer" />
        <result property="qualityPushLeader" column="quality_push_leader" />
        <result property="operationYears" column="operation_years" />
        <result property="responsibleOperationAge" column="responsible_operation_age" />
        <result property="sendToRelevant" column="send_to_relevant" />
        <result property="monthlyProblemCount" column="monthly_problem_count" />
        <result property="lastMonthProblemCount" column="last_month_problem_count" />
        <result property="imageMissDifficulty" column="image_miss_difficulty" />
        <result property="checkPersonnel" column="check_personnel" />
        <result property="deptTrainingInstructor" column="dept_training_instructor" />
        <result property="manageQcManager" column="manage_qc_manager" />
        <result property="teamInternalDuty" column="team_internal_duty" />
        <result property="remark" column="remark" />
        <result property="teamLeader" column="team_leader" />
        <result property="deductScore" column="deduct_score" />
        <result property="addScore" column="add_score" />
        <result property="scoreDimension" column="score_dimension" />
        <result property="scoreIndicator" column="score_indicator" />
        <result property="evidenceFile" column="evidence_file" />
        <result property="importBatch" column="import_batch" />
        <result property="sourceType" column="source_type" />
        <result property="createBy"   column="create_by"   />
        <result property="createTime" column="create_time" />
        <result property="updateBy"   column="update_by"   />
        <result property="updateTime" column="update_time" />
    </resultMap>

    <sql id="selectVo">
        SELECT id, record_date, record_time, dept_name, dept_id, team_name, team_id, group_name, group_id, area_id,
               location, position, position_id,
               inspector_name, inspector_id, channel_no, passenger_name, id_card_no, flight_no, item_category, item_name,
               item_quantity, item_weight, handling_method, result_handling, problem_type, rectification_measures,
               problem_level, attachment, problem_category, personal_review, team_review, quality_officer,
               quality_push_leader, operation_years, responsible_operation_age, send_to_relevant,
               monthly_problem_count, last_month_problem_count, image_miss_difficulty, check_personnel,
               dept_training_instructor, manage_qc_manager, team_internal_duty, remark, team_leader,
               deduct_score, add_score, score_dimension, score_indicator, evidence_file, import_batch, source_type,
               create_by, create_time, update_by, update_time
        FROM ledger_realtime_interception
        WHERE del_flag = '0'
    </sql>

    <select id="selectList" parameterType="com.sundot.airport.ledger.domain.LedgerRealtimeInterception" resultMap="BaseResultMap">
        <include refid="selectVo"/>
        <if test="deptName != null and deptName != ''">AND dept_name LIKE CONCAT('%', #{deptName}, '%')</if>
        <if test="teamName != null and teamName != ''">AND team_name LIKE CONCAT('%', #{teamName}, '%')</if>
        <if test="inspectorName != null and inspectorName != ''">AND inspector_name LIKE CONCAT('%', #{inspectorName}, '%')</if>
        <if test="params != null and params.beginTime != null and params.beginTime != ''">
            AND (record_date &gt;= #{params.beginTime} OR approve_date &gt;= #{params.beginTime} OR exam_date &gt;= #{params.beginTime})
        </if>
        <if test="params != null and params.endTime != null and params.endTime != ''">
            AND (record_date &lt;= #{params.endTime} OR approve_date &lt;= #{params.endTime} OR exam_date &lt;= #{params.endTime})
        </if>
        ORDER BY id DESC
    </select>

    <select id="realtimeInterceptionItem"
            parameterType="com.sundot.airport.common.dto.LedgerCommonQueryReqVO"
            resultType="com.sundot.airport.common.dto.LedgerCommonResVO">
        select item_name name,
        count(1) total
        from ledger_realtime_interception
        where del_flag = '0'
        <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 endDate != null">
            and (record_date >= #{startDate}
            and record_date <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day))
        </if>
        group by item_name
        order by total desc
    </select>

</mapper>
