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

    <resultMap type="com.ruoyi.ems.domain.InspectionReport" id="InspectionReportResult">
        <id property="id" column="id"/>
        <result property="reportCode" column="report_code"/>
        <result property="planCode" column="plan_code"/>
        <result property="planName" column="plan_name"/>
        <result property="planType" column="plan_type"/>
        <result property="areaCode" column="area_code"/>
        <result property="areaName" column="area_name"/>
        <result property="targetType" column="target_type"/>
        <result property="executeTime" column="execute_time"/>
        <result property="finishTime" column="finish_time"/>
        <result property="executor" column="executor"/>
        <result property="resultStatus" column="result_status"/>
        <result property="totalCount" column="total_count"/>
        <result property="normalCount" column="normal_count"/>
        <result property="abnormalCount" column="abnormal_count"/>
        <result property="resultSummary" column="result_summary"/>
        <result property="manualRemark" column="manual_remark"/>
        <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 r.id, r.report_code, r.plan_code, r.plan_name, r.plan_type,
               r.area_code, r.area_name, r.target_type, r.execute_time, r.finish_time,
               r.executor, r.result_status, r.total_count, r.normal_count, r.abnormal_count,
               r.result_summary, r.manual_remark, r.create_by, r.create_time, r.update_by, r.update_time
        FROM adm_op_inspection_report r
    </sql>

    <select id="selectById" parameterType="Long" resultMap="InspectionReportResult">
        <include refid="selectVo"/>
        WHERE r.id = #{id}
    </select>

    <select id="selectByReportCode" parameterType="String" resultMap="InspectionReportResult">
        <include refid="selectVo"/>
        WHERE r.report_code = #{reportCode}
    </select>

    <select id="selectList" parameterType="com.ruoyi.ems.domain.InspectionReport" resultMap="InspectionReportResult">
        <include refid="selectVo"/>
        <where>
            <if test="areaCode != null and areaCode != ''">AND r.area_code = #{areaCode}</if>
            <if test="planCode != null and planCode != ''">AND r.plan_code = #{planCode}</if>
            <if test="planName != null and planName != ''">AND r.plan_name LIKE CONCAT('%', #{planName}, '%')</if>
            <if test="planType != null">AND r.plan_type = #{planType}</if>
            <if test="resultStatus != null">AND r.result_status = #{resultStatus}</if>
            <if test="executor != null and executor != ''">AND r.executor LIKE CONCAT('%', #{executor}, '%')</if>
            <if test="params != null and params.beginTime != null and params.beginTime != ''">
                AND r.execute_time &gt;= #{params.beginTime}
            </if>
            <if test="params != null and params.endTime != null and params.endTime != ''">
                AND r.execute_time &lt;= #{params.endTime}
            </if>
        </where>
        ORDER BY r.execute_time DESC
    </select>

    <insert id="insert" parameterType="com.ruoyi.ems.domain.InspectionReport" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO adm_op_inspection_report (
            report_code, plan_code, plan_name, plan_type, area_code, area_name, target_type,
            execute_time, finish_time, executor, result_status, total_count, normal_count,
            abnormal_count, result_summary, manual_remark, create_by, create_time
        ) VALUES (
                     #{reportCode}, #{planCode}, #{planName}, #{planType}, #{areaCode}, #{areaName}, #{targetType},
                     #{executeTime}, #{finishTime}, #{executor}, #{resultStatus}, #{totalCount}, #{normalCount},
                     #{abnormalCount}, #{resultSummary}, #{manualRemark}, #{createBy}, NOW()
                 )
    </insert>

    <update id="update" parameterType="com.ruoyi.ems.domain.InspectionReport">
        UPDATE adm_op_inspection_report
        <set>
            <if test="planName != null and planName != ''">plan_name = #{planName},</if>
            <if test="areaCode != null and areaCode != ''">area_code = #{areaCode},</if>
            <if test="areaName != null and areaName != ''">area_name = #{areaName},</if>
            <if test="executeTime != null">execute_time = #{executeTime},</if>
            <if test="finishTime != null">finish_time = #{finishTime},</if>
            <if test="executor != null and executor != ''">executor = #{executor},</if>
            <if test="resultStatus != null">result_status = #{resultStatus},</if>
            <if test="totalCount != null">total_count = #{totalCount},</if>
            <if test="normalCount != null">normal_count = #{normalCount},</if>
            <if test="abnormalCount != null">abnormal_count = #{abnormalCount},</if>
            <if test="resultSummary != null">result_summary = #{resultSummary},</if>
            <if test="manualRemark != null">manual_remark = #{manualRemark},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            update_time = NOW()
        </set>
        WHERE id = #{id}
    </update>

    <delete id="deleteById" parameterType="Long">
        DELETE FROM adm_op_inspection_report WHERE id = #{id}
    </delete>

    <delete id="deleteByIds" parameterType="Long">
        DELETE FROM adm_op_inspection_report WHERE id IN
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>