<?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.check.mapper.TCheckInstrumentRecordMapper">

    <resultMap type="TCheckInstrumentRecord" id="TCheckInstrumentRecordResult">
        <result property="id"    column="id"    />
        <result property="instrumentId"    column="instrument_id"    />
        <result property="content"    column="content"    />
        <result property="unit"    column="unit"    />
        <result property="certificate"    column="certificate"    />
        <result property="remarks"    column="remarks"    />
        <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"    />
    </resultMap>

    <sql id="selectTCheckInstrumentRecordVo">
        select id, instrument_id, content, unit, certificate, remarks, dept_id, del_flag, creater_code, createdate, updater_code, updatedate from t_check_instrument_record
    </sql>

    <select id="selectTCheckInstrumentRecordList" parameterType="TCheckInstrumentRecord" resultMap="TCheckInstrumentRecordResult">
        select d.*,tci.code,tci.name,tci.model from t_check_instrument_record d
        left join t_check_instrument tci on d.instrument_id = tci.id
        <where>
            <if test="instrumentId != null "> and instrument_id = #{instrumentId}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="unit != null  and unit != ''"> and unit = #{unit}</if>
            <if test="certificate != null  and certificate != ''"> and certificate = #{certificate}</if>
            <if test="remarks != null  and remarks != ''"> and d.remarks = #{remarks}</if>
            <if test="deptId != null "> and d.dept_id = #{deptId}</if>
            <if test="createrCode != null "> and d.creater_code = #{createrCode}</if>
            <if test="createdate != null "> and d.createdate = #{createdate}</if>
            <if test="updaterCode != null "> and d.updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and d.updatedate = #{updatedate}</if>
        and d.del_flag = 0
        </where>
    </select>

    <select id="selectTCheckInstrumentRecordById" parameterType="Long" resultMap="TCheckInstrumentRecordResult">
        <include refid="selectTCheckInstrumentRecordVo"/>
        where id = #{id}
    </select>

    <insert id="insertTCheckInstrumentRecord" parameterType="TCheckInstrumentRecord" useGeneratedKeys="true" keyProperty="id">
        insert into t_check_instrument_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="instrumentId != null">instrument_id,</if>
            <if test="content != null">content,</if>
            <if test="unit != null">unit,</if>
            <if test="certificate != null">certificate,</if>
            <if test="remarks != null">remarks,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="instrumentId != null">#{instrumentId},</if>
            <if test="content != null">#{content},</if>
            <if test="unit != null">#{unit},</if>
            <if test="certificate != null">#{certificate},</if>
            <if test="remarks != null">#{remarks},</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>
         </trim>
    </insert>

    <update id="updateTCheckInstrumentRecord" parameterType="TCheckInstrumentRecord">
        update t_check_instrument_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="instrumentId != null">instrument_id = #{instrumentId},</if>
            <if test="content != null">content = #{content},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="certificate != null">certificate = #{certificate},</if>
            <if test="remarks != null">remarks = #{remarks},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTCheckInstrumentRecordById" parameterType="Long">
        update t_check_instrument_record set del_flag=1 where id = #{id}
    </delete>

    <delete id="deleteTCheckInstrumentRecordByIds" parameterType="String">
        update t_check_instrument_record set del_flag=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
