<?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.project.inspection.mapper.TInspectionRecordRegionMapper">

    <resultMap type="TInspectionRecordRegion" id="TInspectionRecordRegionResult">
        <result property="id"    column="id"    />
        <result property="devname"    column="devname"    />
        <result property="devno"    column="devno"    />
        <result property="deptId"    column="dept_id"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
        <result property="remarks"    column="remarks"    />
        <result property="region"    column="region"    />
        <result property="reason"    column="reason"    />
        <result property="inspectionTime"    column="inspection_time"    />
        <result property="pastTime"    column="past_time"    />
        <result property="pasterCode"    column="paster_code"    />
        <result property="treatment"    column="treatment"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTInspectionRecordRegionVo">
        select d.id, d.devname, d.devno, d.dept_id, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks, d.region, d.reason, d.inspection_time, d.past_time, d.paster_code, d.treatment ,s.dept_name from t_inspection_record_region d
                                                                                                                                                                                                                                            left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTInspectionRecordRegionList" parameterType="TInspectionRecordRegion" resultMap="TInspectionRecordRegionResult">
        <include refid="selectTInspectionRecordRegionVo"/>
        <where>
            <if test="devname != null  and devname != ''"> and devname like concat(concat('%', #{devname}), '%')</if>
            <if test="devno != null  and devno != ''"> and devno = #{devno}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="createrCode != null  and createrCode != ''"> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null "> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="region != null  and region != ''"> and region = #{region}</if>
            <if test="reason != null  and reason != ''"> and reason = #{reason}</if>
            <if test="inspectionTime != null "> and inspection_time = #{inspectionTime}</if>
            <if test="pastTime != null "> and past_time = #{pastTime}</if>
            <if test="pasterCode != null  and pasterCode != ''"> and paster_code = #{pasterCode}</if>
            <if test="treatment != null  and treatment != ''"> and treatment = #{treatment}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectTInspectionRecordRegionById" parameterType="Long" resultMap="TInspectionRecordRegionResult">
        <include refid="selectTInspectionRecordRegionVo"/>
        where id = #{id}
    </select>

    <insert id="insertTInspectionRecordRegion" parameterType="TInspectionRecordRegion">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_inspection_record_region.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_inspection_record_region
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="devname != null">devname,</if>
            <if test="devno != null">devno,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="remarks != null">remarks,</if>
            <if test="region != null">region,</if>
            <if test="reason != null">reason,</if>
            <if test="inspectionTime != null">inspection_time,</if>
            <if test="pastTime != null">past_time,</if>
            <if test="pasterCode != null">paster_code,</if>
            <if test="treatment != null">treatment,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="devname != null">#{devname},</if>
            <if test="devno != null">#{devno},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="region != null">#{region},</if>
            <if test="reason != null">#{reason},</if>
            <if test="inspectionTime != null">#{inspectionTime},</if>
            <if test="pastTime != null">#{pastTime},</if>
            <if test="pasterCode != null">#{pasterCode},</if>
            <if test="treatment != null">#{treatment},</if>
        </trim>
    </insert>

    <update id="updateTInspectionRecordRegion" parameterType="TInspectionRecordRegion">
        update t_inspection_record_region
        <trim prefix="SET" suffixOverrides=",">
            <if test="devname != null">devname = #{devname},</if>
            <if test="devno != null">devno = #{devno},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="region != null">region = #{region},</if>
            <if test="reason != null">reason = #{reason},</if>
            <if test="inspectionTime != null">inspection_time = #{inspectionTime},</if>
            <if test="pastTime != null">past_time = #{pastTime},</if>
            <if test="pasterCode != null">paster_code = #{pasterCode},</if>
            <if test="treatment != null">treatment = #{treatment},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteTInspectionRecordRegionById" parameterType="Long">
        update t_inspection_record_region set del_flag = -1 where id = #{id}
    </update>

    <update id="deleteTInspectionRecordRegionByIds" parameterType="String">
        update t_inspection_record_region set del_flag = -1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

</mapper>