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

    <resultMap type="TCheckInstrument" id="TCheckInstrumentResult">
        <result property="id"    column="id"    />
        <result property="code"    column="code"    />
        <result property="name"    column="name"    />
        <result property="model"    column="model"    />
        <result property="principle"    column="principle"    />
        <result property="linearRange"    column="linear_range"    />
        <result property="range"    column="range"    />
        <result property="factory"    column="factory"    />
        <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="updater"    column="updater"    />
        <result property="updatedate"    column="updatedate"    />
    </resultMap>

    <sql id="selectTCheckInstrumentVo">
        select id, code, name, model, principle, linear_range, `range`, factory, remarks, dept_id, del_flag, creater_code, createdate, updater_code, updatedate from t_check_instrument
    </sql>

    <select id="selectTCheckInstrumentList" parameterType="TCheckInstrument" resultMap="TCheckInstrumentResult">
        select d.*,su.user_name updater from t_check_instrument d
        left join sys_user su on su.user_id=d.updater_code
        <where>
            <if test="code != null  and code != ''"> and d.`code` = #{code}</if>
            <if test="name != null  and name != ''"> and d.`name` like concat('%', #{name}, '%')</if>
            <if test="model != null  and model != ''"> and d.`model` = #{model}</if>
            <if test="principle != null  and principle != ''"> and d.principle = #{principle}</if>
            <if test="linearRange != null  and linearRange != ''"> and d.linear_range = #{linearRange}</if>
            <if test="range != null  and range != ''"> and d.`range` = #{range}</if>
            <if test="factory != null  and factory != ''"> and d.factory = #{factory}</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="selectTCheckInstrumentById" parameterType="Long" resultMap="TCheckInstrumentResult">
        <include refid="selectTCheckInstrumentVo"/>
        where id = #{id}
    </select>
    <select id="selectAllInstrument" parameterType="Long" resultMap="TCheckInstrumentResult">
        select d.id, d.`code`, concat(d.`code`, '_' ,d.`name`) `name`, d.model, d.principle, d.linear_range, d.`range`, d.factory, d.remarks, d.dept_id, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate
        from t_check_instrument d
                 left join sys_dept s on d.dept_id = s.dept_id
        <where>AND d.del_flag = 0
        </where>
        order by createdate desc
    </select>

    <insert id="insertTCheckInstrument" parameterType="TCheckInstrument" useGeneratedKeys="true" keyProperty="id">
        insert into t_check_instrument
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="code != null">code,</if>
            <if test="name != null">`name`,</if>
            <if test="model != null">model,</if>
            <if test="principle != null">principle,</if>
            <if test="linearRange != null">linear_range,</if>
            <if test="range != null">`range`,</if>
            <if test="factory != null">factory,</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="code != null">#{code},</if>
            <if test="name != null">#{name},</if>
            <if test="model != null">#{model},</if>
            <if test="principle != null">#{principle},</if>
            <if test="linearRange != null">#{linearRange},</if>
            <if test="range != null">#{range},</if>
            <if test="factory != null">#{factory},</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="updateTCheckInstrument" parameterType="TCheckInstrument">
        update t_check_instrument
        <trim prefix="SET" suffixOverrides=",">
            <if test="code != null">code = #{code},</if>
            <if test="name != null">`name` = #{name},</if>
            <if test="model != null">model = #{model},</if>
            <if test="principle != null">principle = #{principle},</if>
            <if test="linearRange != null">linear_range = #{linearRange},</if>
            <if test="range != null">`range` = #{range},</if>
            <if test="factory != null">factory = #{factory},</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="deleteTCheckInstrumentById" parameterType="Long">
        update t_check_instrument set del_flag=1 where id = #{id}
    </delete>

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