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

    <resultMap type="TCheckCalibration" id="TCheckCalibrationResult">
        <result property="id"    column="id"    />
        <result property="calibrationTime"    column="calibration_time"    />
        <result property="calibrationUser"    column="calibration_user"    />
        <result property="instrumentId"    column="instrument_id"    />
        <result property="standardgasesId"    column="standardgases_id"    />
        <result property="zerogasConcentration"    column="zerogas_concentration"    />
        <result property="zerogasCalibration"    column="zerogas_calibration"    />
        <result property="standardgasesCalibration"    column="standardgases_calibration"    />
        <result property="driftCheck"    column="drift_check"    />
        <result property="filterCheck"    column="filter_check"    />
        <result property="airtightnessCheck"    column="airtightness_check"    />
        <result property="flowCheck"    column="flow_check"    />
        <result property="pressure"    column="pressure"    />
        <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="selectTCheckCalibrationVo">
        select id, calibration_time, calibration_user, instrument_id, standardgases_id, zerogas_concentration, zerogas_calibration, standardgases_calibration, drift_check, filter_check, airtightness_check, flow_check, pressure, remarks, dept_id, del_flag, creater_code, createdate, updater_code, updatedate from t_check_calibration
    </sql>

    <select id="selectTCheckCalibrationList" parameterType="TCheckCalibration" resultMap="TCheckCalibrationResult">
        select d.*,ci.name instrumentName,ci.code instrumentCode,ci.model instrumentType,cs.name standardgasesName,cs.concentration standardgasesConcentration,cs.lifespan standardgasesLifespan from t_check_calibration d
        left join t_check_instrument ci on ci.id= d.instrument_id
        left join t_check_standardgases cs on cs.id=d.standardgases_id
        <where>
            <if test="calibrationTime != null "> and calibration_time = #{calibrationTime}</if>
            <if test="calibrationUser != null  and calibrationUser != ''"> and calibration_user = #{calibrationUser}</if>
            <if test="instrumentId != null "> and instrument_id = #{instrumentId}</if>
            <if test="standardgasesId != null "> and standardgases_id = #{standardgasesId}</if>
            <if test="zerogasConcentration != null  and zerogasConcentration != ''"> and zerogas_concentration = #{zerogasConcentration}</if>
            <if test="zerogasCalibration != null  and zerogasCalibration != ''"> and zerogas_calibration = #{zerogasCalibration}</if>
            <if test="standardgasesCalibration != null  and standardgasesCalibration != ''"> and standardgases_calibration = #{standardgasesCalibration}</if>
            <if test="driftCheck != null  and driftCheck != ''"> and drift_check = #{driftCheck}</if>
            <if test="filterCheck != null  and filterCheck != ''"> and filter_check = #{filterCheck}</if>
            <if test="airtightnessCheck != null  and airtightnessCheck != ''"> and airtightness_check = #{airtightnessCheck}</if>
            <if test="flowCheck != null  and flowCheck != ''"> and flow_check = #{flowCheck}</if>
            <if test="pressure != null  and pressure != ''"> and pressure = #{pressure}</if>
            <if test="remarks != null  and remarks != ''"> and d.remarks = #{remarks}</if>
            <if test="instrumentName != null  and instrumentName != ''"> and ci.`name` like concat('%',#{instrumentName}, '%')</if>
            <if test="instrumentCode != null  and instrumentCode != ''"> and ci.`code` like concat('%',#{instrumentCode}, '%')</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="selectTCheckCalibrationById" parameterType="Long" resultMap="TCheckCalibrationResult">
        <include refid="selectTCheckCalibrationVo"/>
        where id = #{id}
    </select>

    <insert id="insertTCheckCalibration" parameterType="TCheckCalibration" useGeneratedKeys="true" keyProperty="id">
        insert into t_check_calibration
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="calibrationTime != null">calibration_time,</if>
            <if test="calibrationUser != null">calibration_user,</if>
            <if test="instrumentId != null">instrument_id,</if>
            <if test="standardgasesId != null">standardgases_id,</if>
            <if test="zerogasConcentration != null">zerogas_concentration,</if>
            <if test="zerogasCalibration != null">zerogas_calibration,</if>
            <if test="standardgasesCalibration != null">standardgases_calibration,</if>
            <if test="driftCheck != null">drift_check,</if>
            <if test="filterCheck != null">filter_check,</if>
            <if test="airtightnessCheck != null">airtightness_check,</if>
            <if test="flowCheck != null">flow_check,</if>
            <if test="pressure != null">pressure,</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="calibrationTime != null">#{calibrationTime},</if>
            <if test="calibrationUser != null">#{calibrationUser},</if>
            <if test="instrumentId != null">#{instrumentId},</if>
            <if test="standardgasesId != null">#{standardgasesId},</if>
            <if test="zerogasConcentration != null">#{zerogasConcentration},</if>
            <if test="zerogasCalibration != null">#{zerogasCalibration},</if>
            <if test="standardgasesCalibration != null">#{standardgasesCalibration},</if>
            <if test="driftCheck != null">#{driftCheck},</if>
            <if test="filterCheck != null">#{filterCheck},</if>
            <if test="airtightnessCheck != null">#{airtightnessCheck},</if>
            <if test="flowCheck != null">#{flowCheck},</if>
            <if test="pressure != null">#{pressure},</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="updateTCheckCalibration" parameterType="TCheckCalibration">
        update t_check_calibration
        <trim prefix="SET" suffixOverrides=",">
            <if test="calibrationTime != null">calibration_time = #{calibrationTime},</if>
            <if test="calibrationUser != null">calibration_user = #{calibrationUser},</if>
            <if test="instrumentId != null">instrument_id = #{instrumentId},</if>
            <if test="standardgasesId != null">standardgases_id = #{standardgasesId},</if>
            <if test="zerogasConcentration != null">zerogas_concentration = #{zerogasConcentration},</if>
            <if test="zerogasCalibration != null">zerogas_calibration = #{zerogasCalibration},</if>
            <if test="standardgasesCalibration != null">standardgases_calibration = #{standardgasesCalibration},</if>
            <if test="driftCheck != null">drift_check = #{driftCheck},</if>
            <if test="filterCheck != null">filter_check = #{filterCheck},</if>
            <if test="airtightnessCheck != null">airtightness_check = #{airtightnessCheck},</if>
            <if test="flowCheck != null">flow_check = #{flowCheck},</if>
            <if test="pressure != null">pressure = #{pressure},</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="deleteTCheckCalibrationById" parameterType="Long">
        update t_check_calibration set del_flag=1 where id = #{id}
    </delete>

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