<?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="deptName"    column="dept_name"    />
        <result property="inspectionId"    column="inspection_id"    />
        <result property="inspectionFileId"    column="inspection_file_id"    />
        <result property="channelId"    column="channel_id"    />
        <result property="channelCode"    column="channel_code"    />
        <result property="channelName"    column="channel_came"    />
        <result property="legId"    column="leg_id"    />
        <result property="legName"    column="leg_name"    />
        <result property="questionId"    column="question_id"    />
        <result property="questionCode"    column="question_code"    />
        <result property="questionName"    column="question_name"    />
        <result property="longitude"    column="longitude"    />
        <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="endTime"    column="end_time"    />
        <result property="mark"    column="mark"    />
    </resultMap>

    <sql id="Base_Column_List">
        id, tenant_id, dept_id, dept_name, inspection_id, inspection_file_id, channel_id, channel_code, leg_id, leg_name, question_id, question_code, question_name,
        longitude, latitude, source, status, create_user, create_time, update_user, update_time, check_user, check_time, check_result, end_time, mark
    </sql>

    <sql id="selectThAccidentVo">
        select id, tenant_id, dept_id, inspection_id, inspection_file_id, channel_id, channel_code, leg_id, leg_name, question_id, question_code, question_name,
        longitude, latitude, source, status, create_user, create_time, update_user, update_time, check_user, check_time, check_result, end_time, mark
        from th_accident
    </sql>

    <select id="selectAccidentList" parameterType="com.tuoheng.admin.request.accident.QueryAccidentListRequest" resultMap="AccidentResult">
        select <include refid="Base_Column_List"/>
        from th_accident
        <where>
            <if test="1 == 1"> and mark = 1 </if>
            <if test="request.sourceList != null and request.sourceList.size() > 0">
                and source in
                <foreach item="source" collection="request.sourceList" open="(" separator="," close=")">
                    #{source}
                </foreach>
            </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 status desc, create_time desc
    </select>

</mapper>