<?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.ruoyi.ems.mapper.InspectionReportDetailMapper">

    <resultMap type="com.ruoyi.ems.domain.InspectionReportDetail" id="DetailResult">
        <id property="id" column="id"/>
        <result property="reportCode" column="report_code"/>
        <result property="deviceCode" column="device_code"/>
        <result property="deviceName" column="device_name"/>
        <result property="deviceModel" column="device_model"/>
        <result property="deviceModelName" column="device_model_name"/>
        <result property="location" column="location"/>
        <result property="areaPath" column="area_path"/>
        <result property="resultStatus" column="result_status"/>
        <result property="checkItems" column="check_items"/>
        <result property="checkTime" column="check_time"/>
        <result property="createTime" column="create_time"/>
    </resultMap>

    <select id="selectByReportCode" parameterType="String" resultMap="DetailResult">
        SELECT id, report_code, device_code, device_name, device_model, device_model_name,
               location, area_path, result_status, check_items, check_time, create_time
        FROM adm_op_inspection_report_detail
        WHERE report_code = #{reportCode}
        ORDER BY result_status DESC, id
    </select>

    <insert id="insert" parameterType="com.ruoyi.ems.domain.InspectionReportDetail" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO adm_op_inspection_report_detail (
            report_code, device_code, device_name, device_model, device_model_name,
            location, area_path, result_status, check_items, check_time, create_time
        ) VALUES (
                     #{reportCode}, #{deviceCode}, #{deviceName}, #{deviceModel}, #{deviceModelName},
                     #{location}, #{areaPath}, #{resultStatus}, #{checkItems}, #{checkTime}, NOW()
                 )
    </insert>

    <insert id="insertBatch" parameterType="java.util.List">
        INSERT INTO adm_op_inspection_report_detail (
        report_code, device_code, device_name, device_model, device_model_name,
        location, area_path, result_status, check_items, check_time, create_time
        ) VALUES
        <foreach collection="list" item="item" separator=",">
            (#{item.reportCode}, #{item.deviceCode}, #{item.deviceName}, #{item.deviceModel},
            #{item.deviceModelName}, #{item.location}, #{item.areaPath}, #{item.resultStatus},
            #{item.checkItems}, #{item.checkTime}, NOW())
        </foreach>
    </insert>

    <delete id="deleteByReportCode" parameterType="String">
        DELETE FROM adm_op_inspection_report_detail WHERE report_code = #{reportCode}
    </delete>
</mapper>