<?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.tuoheng.admin.mapper.AccidentMapper">

    <resultMap type="com.tuoheng.admin.entity.Accident" id="AccidentResult">
        <result property="id"    column="id"    />
        <result property="tenantId"    column="tenant_id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="inspectionId"    column="inspection_id"    />
        <result property="inspectionFileId"    column="inspection_file_id"    />
        <result property="accidentInspectionId"    column="accident_inspection_id"    />
        <result property="roadId"    column="road_id"    />
        <result property="roadCode"    column="road_code"    />
        <result property="sectionId"    column="section_id"    />
        <result property="sectionName"    column="section_name"    />
        <result property="questionId"    column="question_id"    />
        <result property="questionCode"    column="question_code"    />
        <result property="questionName"    column="question_name"    />
        <result property="isCasualties"    column="is_casualties"    />
        <result property="isDrivingSafety"    column="is_driving_safety"    />
        <result property="isFire"    column="is_fire"    />
        <result property="record"    column="record"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="uavReturn"    column="uav_return"    />
        <result property="status"    column="status"    />
        <result property="createUser"    column="create_user"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateUser"    column="update_user"    />
        <result property="updateTime"    column="update_time"    />
        <result property="checkUser"    column="check_user"    />
        <result property="checkTime"    column="check_time"    />
        <result property="checkResult"    column="check_result"    />
        <result property="verificationTime"    column="verification_time"    />
        <result property="reportTime"    column="report_time"    />
        <result property="noAccidentTime"    column="no_accident_time"    />
        <result property="ignoreTime"    column="ignore_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="flag"    column="flag"    />
        <result property="mark"    column="mark"    />
    </resultMap>


    <sql id="Base_Column_List">
        id, tenant_id, dept_id, inspection_id, inspection_file_id, accident_inspection_id, road_id, road_code, section_id, section_name, question_id, question_code, question_name,
        is_casualties, is_driving_safety, is_fire, record, longitude, latitude, uav_return, status, create_user, create_time, update_user, update_time,
        check_user, check_time, check_result, verification_time, report_time, no_accident_time, ignore_time, end_time, flag, mark
    </sql>

    <sql id="selectThAccidentVo">
        select id, tenant_id, dept_id, inspection_id, inspection_file_id, accident_inspection_id, road_id, road_code, section_id, section_name, question_id, question_code, question_name,
        is_casualties, is_driving_safety, is_fire, record, longitude, latitude, uav_return, status, create_user, create_time, update_user, update_time,
        check_user, check_time, check_result, verification_time, report_time, no_accident_time, ignore_time, end_time, flag, mark
        from th_accident
    </sql>

    <select id="selectPageList" parameterType="com.tuoheng.admin.request.accident.QueryAccidentCardPageListRequest" resultMap="AccidentResult">
        select <include refid="Base_Column_List"/>
        from th_accident
        <where>
            <if test="1 == 1"> and mark = 1 </if>
            <if test="request.tenantId != null and request.tenantId != ''"> and tenant_id = #{request.tenantId} </if>
            <if test="request.sectionName != null and request.sectionName != ''"> and section_name = #{request.sectionName} </if>
            <if test="request.statusList != null and request.statusList.size() > 0">
                and status in
                <foreach item="status" collection="request.statusList" open="(" separator="," close=")">
                    #{status}
                </foreach>
            </if>
            <if test="request.deptIdList != null and request.deptIdList.size() > 0">
                and dept_id in
                <foreach item="deptId" collection="request.deptIdList" open="(" separator="," close=")">
                    #{deptId}
                </foreach>
            </if>
            <if test="request.beginTime != null">
                and create_time &gt;= #{request.beginTime}
            </if>
            <if test="request.endTime != null">
                and create_time &lt;= #{request.endTime}
            </if>
        </where>
        order by create_time desc
    </select>

    <select id="selectAccidentCardList" parameterType="com.tuoheng.admin.request.accident.QueryAccidentCardListRequest" resultMap="AccidentResult">
        select <include refid="Base_Column_List"/>
        from th_accident
        <where>
            <if test="1 == 1"> and mark = 1 </if>
            <if test="1 == 1"> and flag = 0 </if>
            <if test="request.tenantId != null and request.tenantId != ''"> and tenant_id = #{request.tenantId} </if>
            <if test="request.statusList != null and request.statusList.size() > 0">
                and status in
                <foreach item="status" collection="request.statusList" open="(" separator="," close=")">
                    #{status}
                </foreach>
            </if>
            <if test="request.deptIdList != null and request.deptIdList.size() > 0">
                and dept_id in
                <foreach item="deptId" collection="request.deptIdList" open="(" separator="," close=")">
                    #{deptId}
                </foreach>
            </if>
        </where>
        order by create_time desc
    </select>

</mapper>