<?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.blocked.mapper.BlockedMissCheckStatisticsMapper">

    <resultMap type="BlockedMissCheckStatistics" id="BlockedMissCheckStatisticsResult">
        <result property="id" column="id"/>
        <result property="brigadeId" column="brigade_id"/>
        <result property="brigadeName" column="brigade_name"/>
        <result property="terminalId" column="terminal_id"/>
        <result property="terminalName" column="terminal_name"/>
        <result property="areaId" column="area_id"/>
        <result property="areaName" column="area_name"/>
        <result property="channelId" column="channel_id"/>
        <result property="channelName" column="channel_name"/>
        <result property="reviewedUserId" column="reviewed_user_id"/>
        <result property="reviewedUserName" column="reviewed_user_name"/>
        <result property="reviewUserId" column="review_user_id"/>
        <result property="reviewUserName" column="review_user_name"/>
        <result property="supervisorId" column="supervisor_id"/>
        <result property="supervisorName" column="supervisor_name"/>
        <result property="actingSupervisorId" column="acting_supervisor_id"/>
        <result property="actingSupervisorName" column="acting_supervisor_name"/>
        <result property="teamLeaderId" column="team_leader_id"/>
        <result property="teamLeaderName" column="team_leader_name"/>
        <result property="reviewDate" column="review_date"/>
        <result property="missCheckTime" column="miss_check_time"/>
        <result property="missCheckTimePeriod" column="miss_check_time_period"/>
        <result property="missCheckItem" column="miss_check_item"/>
        <result property="itemLocation" column="item_location"/>
        <result property="difficultyLevel" column="difficulty_level"/>
        <result property="discriminationType" column="discrimination_type"/>
        <result property="isRecovered" column="is_recovered"/>
        <result property="machineOperatingYears" column="machine_operating_years"/>
        <result property="certificateLevel" column="certificate_level"/>
        <result property="gender" column="gender"/>
        <result property="missCheckReasonCategory" column="miss_check_reason_category"/>
        <result property="monthlyAssessment" column="monthly_assessment"/>
        <result property="selfTestHasMissCheck" column="self_test_has_miss_check"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
        <result property="delFlag" column="del_flag"/>
    </resultMap>

    <sql id="selectBlockedMissCheckStatisticsVo">
        select id,
               brigade_id,
               brigade_name,
               terminal_id,
               terminal_name,
               area_id,
               area_name,
               channel_id,
               channel_name,
               reviewed_user_id,
               reviewed_user_name,
               review_user_id,
               review_user_name,
               supervisor_id,
               supervisor_name,
               acting_supervisor_id,
               acting_supervisor_name,
               team_leader_id,
               team_leader_name,
               review_date,
               miss_check_time,
               miss_check_time_period,
               miss_check_item,
               item_location,
               difficulty_level,
               discrimination_type,
               is_recovered,
               machine_operating_years,
               certificate_level,
               gender,
               miss_check_reason_category,
               monthly_assessment,
               self_test_has_miss_check,
               create_by,
               create_time,
               update_by,
               update_time,
               remark,
               del_flag
        from blocked_miss_check_statistics
    </sql>

    <select id="selectBlockedMissCheckStatisticsList" parameterType="BlockedMissCheckStatistics"
            resultMap="BlockedMissCheckStatisticsResult">
        <include refid="selectBlockedMissCheckStatisticsVo"/>
        <where>
            del_flag = '0'
            <if test="brigadeId != null ">and brigade_id = #{brigadeId}</if>
            <if test="brigadeName != null  and brigadeName != ''">and brigade_name like concat('%', #{brigadeName},
                '%')
            </if>
            <if test="terminalId != null ">and terminal_id = #{terminalId}</if>
            <if test="terminalName != null  and terminalName != ''">and terminal_name like
                concat('%', #{terminalName}, '%')
            </if>
            <if test="areaId != null ">and area_id = #{areaId}</if>
            <if test="areaName != null  and areaName != ''">and area_name like
                concat('%', #{areaName}, '%')
            </if>
            <if test="channelId != null ">and channel_id = #{channelId}</if>
            <if test="channelName != null  and channelName != ''">and channel_name like
                concat('%', #{channelName}, '%')
            </if>
            <if test="reviewedUserId != null ">and reviewed_user_id = #{reviewedUserId}</if>
            <if test="reviewedUserName != null  and reviewedUserName != ''">and reviewed_user_name like concat('%',
                #{reviewedUserName}, '%')
            </if>
            <if test="reviewUserId != null ">and review_user_id = #{reviewUserId}</if>
            <if test="reviewUserName != null  and reviewUserName != ''">and review_user_name like
                concat('%', #{reviewUserName}, '%')
            </if>
            <if test="reviewDate != null ">and review_date = #{reviewDate}</if>
            <if test="missCheckTime != null ">and DATE_FORMAT(miss_check_time, '%Y-%m-%d %H:%i') =
                DATE_FORMAT(#{missCheckTime}, '%Y-%m-%d %H:%i')
            </if>
            <if test="difficultyLevel != null  and difficultyLevel != ''">and difficulty_level = #{difficultyLevel}</if>
            <if test="gender != null  and gender != ''">and gender = #{gender}</if>
            <if test="actingSupervisorId != null ">and acting_supervisor_id = #{actingSupervisorId}</if>
            <if test="actingSupervisorName != null  and actingSupervisorName != ''">and acting_supervisor_name like
                concat('%', #{actingSupervisorName}, '%')
            </if>
            <if test="missCheckItem != null  and missCheckItem != ''">and miss_check_item like
                concat('%', #{missCheckItem}, '%')
            </if>
            <if test="supervisorId != null ">and supervisor_id = #{supervisorId}</if>
            <if test="supervisorName != null  and supervisorName != ''">and supervisor_name like
                concat('%', #{supervisorName}, '%')
            </if>
            <if test="teamLeaderId != null ">and team_leader_id = #{teamLeaderId}</if>
            <if test="teamLeaderName != null  and teamLeaderName != ''">and team_leader_name like
                concat('%', #{teamLeaderName}, '%')
            </if>
            <if test="startDate != null and endDate != null">
                and (review_date >= #{startDate}
                and review_date <![CDATA[ < ]]> date_add(#{endDate} , interval 1 day))
            </if>
        </where>
        order by review_date desc, miss_check_time desc
    </select>

    <select id="selectBlockedMissCheckStatisticsById" parameterType="Long" resultMap="BlockedMissCheckStatisticsResult">
        <include refid="selectBlockedMissCheckStatisticsVo"/>
        where id = #{id} and del_flag = '0'
    </select>

    <insert id="insertBlockedMissCheckStatistics" parameterType="BlockedMissCheckStatistics" useGeneratedKeys="true"
            keyProperty="id">
        insert into blocked_miss_check_statistics
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="brigadeId != null">brigade_id,</if>
            <if test="brigadeName != null and brigadeName != ''">brigade_name,</if>
            <if test="terminalId != null">terminal_id,</if>
            <if test="terminalName != null and terminalName != ''">terminal_name,</if>
            <if test="areaId != null">area_id,</if>
            <if test="areaName != null and areaName != ''">area_name,</if>
            <if test="channelId != null">channel_id,</if>
            <if test="channelName != null and channelName != ''">channel_name,</if>
            <if test="reviewedUserId != null">reviewed_user_id,</if>
            <if test="reviewedUserName != null and reviewedUserName != ''">reviewed_user_name,</if>
            <if test="reviewUserId != null">review_user_id,</if>
            <if test="reviewUserName != null and reviewUserName != ''">review_user_name,</if>
            <if test="supervisorId != null">supervisor_id,</if>
            <if test="supervisorName != null and supervisorName != ''">supervisor_name,</if>
            <if test="actingSupervisorId != null">acting_supervisor_id,</if>
            <if test="actingSupervisorName != null and actingSupervisorName != ''">acting_supervisor_name,</if>
            <if test="teamLeaderId != null">team_leader_id,</if>
            <if test="teamLeaderName != null and teamLeaderName != ''">team_leader_name,</if>
            <if test="reviewDate != null">review_date,</if>
            <if test="missCheckTime != null">miss_check_time,</if>
            <if test="missCheckTimePeriod != null and missCheckTimePeriod != ''">miss_check_time_period,</if>
            <if test="missCheckItem != null and missCheckItem != ''">miss_check_item,</if>
            <if test="itemLocation != null and itemLocation != ''">item_location,</if>
            <if test="difficultyLevel != null and difficultyLevel != ''">difficulty_level,</if>
            <if test="discriminationType != null and discriminationType != ''">discrimination_type,</if>
            <if test="isRecovered != null">is_recovered,</if>
            <if test="machineOperatingYears != null">machine_operating_years,</if>
            <if test="certificateLevel != null and certificateLevel != ''">certificate_level,</if>
            <if test="gender != null and gender != ''">gender,</if>
            <if test="missCheckReasonCategory != null and missCheckReasonCategory != ''">miss_check_reason_category,
            </if>
            <if test="monthlyAssessment != null and monthlyAssessment != ''">monthly_assessment,</if>
            <if test="selfTestHasMissCheck != null">self_test_has_miss_check,</if>
            <if test="createBy != null and createBy != ''">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null and updateBy != ''">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="delFlag != null and delFlag != ''">del_flag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="brigadeId != null">#{brigadeId},</if>
            <if test="brigadeName != null and brigadeName != ''">#{brigadeName},</if>
            <if test="terminalId != null">#{terminalId},</if>
            <if test="terminalName != null and terminalName != ''">#{terminalName},</if>
            <if test="areaId != null">#{areaId},</if>
            <if test="areaName != null and areaName != ''">#{areaName},</if>
            <if test="channelId != null">#{channelId},</if>
            <if test="channelName != null and channelName != ''">#{channelName},</if>
            <if test="reviewedUserId != null">#{reviewedUserId},</if>
            <if test="reviewedUserName != null and reviewedUserName != ''">#{reviewedUserName},</if>
            <if test="reviewUserId != null">#{reviewUserId},</if>
            <if test="reviewUserName != null and reviewUserName != ''">#{reviewUserName},</if>
            <if test="supervisorId != null">#{supervisorId},</if>
            <if test="supervisorName != null and supervisorName != ''">#{supervisorName},</if>
            <if test="actingSupervisorId != null">#{actingSupervisorId},</if>
            <if test="actingSupervisorName != null and actingSupervisorName != ''">#{actingSupervisorName},</if>
            <if test="teamLeaderId != null">#{teamLeaderId},</if>
            <if test="teamLeaderName != null and teamLeaderName != ''">#{teamLeaderName},</if>
            <if test="reviewDate != null">#{reviewDate},</if>
            <if test="missCheckTime != null">#{missCheckTime},</if>
            <if test="missCheckTimePeriod != null and missCheckTimePeriod != ''">#{missCheckTimePeriod},</if>
            <if test="missCheckItem != null and missCheckItem != ''">#{missCheckItem},</if>
            <if test="itemLocation != null and itemLocation != ''">#{itemLocation},</if>
            <if test="difficultyLevel != null and difficultyLevel != ''">#{difficultyLevel},</if>
            <if test="discriminationType != null and discriminationType != ''">#{discriminationType},</if>
            <if test="isRecovered != null">#{isRecovered},</if>
            <if test="machineOperatingYears != null">#{machineOperatingYears},</if>
            <if test="certificateLevel != null and certificateLevel != ''">#{certificateLevel},</if>
            <if test="gender != null and gender != ''">#{gender},</if>
            <if test="missCheckReasonCategory != null and missCheckReasonCategory != ''">#{missCheckReasonCategory},
            </if>
            <if test="monthlyAssessment != null and monthlyAssessment != ''">#{monthlyAssessment},</if>
            <if test="selfTestHasMissCheck != null">#{selfTestHasMissCheck},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null and updateBy != ''">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="delFlag != null and delFlag != ''">#{delFlag},</if>
        </trim>
    </insert>

    <update id="updateBlockedMissCheckStatistics" parameterType="BlockedMissCheckStatistics">
        update blocked_miss_check_statistics
        <trim prefix="SET" suffixOverrides=",">
            <if test="brigadeId != null">brigade_id = #{brigadeId},</if>
            <if test="brigadeName != null and brigadeName != ''">brigade_name = #{brigadeName},</if>
            <if test="terminalId != null">terminal_id = #{terminalId},</if>
            <if test="terminalName != null and terminalName != ''">terminal_name = #{terminalName},</if>
            <if test="areaId != null">area_id = #{areaId},</if>
            <if test="areaName != null and areaName != ''">area_name = #{areaName},</if>
            <if test="channelId != null">channel_id = #{channelId},</if>
            <if test="channelName != null and channelName != ''">channel_name = #{channelName},</if>
            <if test="reviewedUserId != null">reviewed_user_id = #{reviewedUserId},</if>
            <if test="reviewedUserName != null and reviewedUserName != ''">reviewed_user_name = #{reviewedUserName},
            </if>
            <if test="reviewUserId != null">review_user_id = #{reviewUserId},</if>
            <if test="reviewUserName != null and reviewUserName != ''">review_user_name = #{reviewUserName},</if>
            <if test="supervisorId != null">supervisor_id = #{supervisorId},</if>
            <if test="supervisorName != null and supervisorName != ''">supervisor_name = #{supervisorName},</if>
            <if test="actingSupervisorId != null">acting_supervisor_id = #{actingSupervisorId},</if>
            <if test="actingSupervisorName != null and actingSupervisorName != ''">acting_supervisor_name =
                #{actingSupervisorName},
            </if>
            <if test="teamLeaderId != null">team_leader_id = #{teamLeaderId},</if>
            <if test="teamLeaderName != null and teamLeaderName != ''">team_leader_name = #{teamLeaderName},</if>
            <if test="reviewDate != null">review_date = #{reviewDate},</if>
            <if test="missCheckTime != null">miss_check_time = #{missCheckTime},</if>
            <if test="missCheckTimePeriod != null and missCheckTimePeriod != ''">miss_check_time_period =
                #{missCheckTimePeriod},
            </if>
            <if test="missCheckItem != null and missCheckItem != ''">miss_check_item = #{missCheckItem},</if>
            <if test="itemLocation != null and itemLocation != ''">item_location = #{itemLocation},</if>
            <if test="difficultyLevel != null and difficultyLevel != ''">difficulty_level = #{difficultyLevel},</if>
            <if test="discriminationType != null and discriminationType != ''">discrimination_type =
                #{discriminationType},
            </if>
            <if test="isRecovered != null">is_recovered = #{isRecovered},</if>
            <if test="machineOperatingYears != null">machine_operating_years = #{machineOperatingYears},</if>
            <if test="certificateLevel != null and certificateLevel != ''">certificate_level = #{certificateLevel},</if>
            <if test="gender != null and gender != ''">gender = #{gender},</if>
            <if test="missCheckReasonCategory != null and missCheckReasonCategory != ''">miss_check_reason_category =
                #{missCheckReasonCategory},
            </if>
            <if test="monthlyAssessment != null and monthlyAssessment != ''">monthly_assessment =
                #{monthlyAssessment},
            </if>
            <if test="selfTestHasMissCheck != null">self_test_has_miss_check = #{selfTestHasMissCheck},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBlockedMissCheckStatisticsById" parameterType="Long">
        update blocked_miss_check_statistics
        set del_flag = '2'
        where id = #{id}
    </delete>

    <delete id="deleteBlockedMissCheckStatisticsByIds" parameterType="String">
        update blocked_miss_check_statistics set del_flag = '2' where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
