<?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.production.mapper.TBlindMapper">
    
    <resultMap type="TBlind" id="TBlindResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="unit"    column="unit"    />
        <result property="system"    column="system"    />
        <result property="blindno"    column="blindno"    />
        <result property="sizes"    column="sizes"    />
        <result property="eightblind"    column="eightblind"    />
        <result property="pressure"    column="pressure"    />
        <result property="blindtype"    column="blindtype"    />
        <result property="pipeno"    column="pipeno"    />
        <result property="media"    column="media"    />
        <result property="pid"    column="pid"    />
        <result property="place"    column="place"    />
        <result property="ynblind"    column="ynblind"    />
        <result property="blinddate"    column="blinddate"    />
        <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="deptId"    column="dept_id"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTBlindVo">
        select d.id, d.plant_code, d.unit, d.system, d.blindno, d.sizes, d.eightblind, d.pressure, d.blindtype, d.pipeno, d.media, d.pid, d.place, d.ynblind, d.blinddate, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks, d.dept_id ,s.dept_name from t_blind d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTBlindList" parameterType="TBlind" resultMap="TBlindResult">
        <include refid="selectTBlindVo"/>
        <where>  
            <if test="unit != null  and unit != ''"> and unit like concat(concat('%', #{unit}), '%')</if>
            <if test="pipeno != null  and pipeno != ''"> and pipeno like concat(concat('%', #{pipeno}), '%')</if>
            <if test="media != null  and media != ''"> and media like concat(concat('%', #{media}), '%')</if>
            <if test="pid != null  and pid != ''"> and pid like concat(concat('%', #{pid}), '%')</if>
            <if test="ynblind != null  and ynblind != ''"> and ynblind = #{ynblind}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.id desc
    </select>
    
    <select id="selectTBlindById" parameterType="String" resultMap="TBlindResult">
        <include refid="selectTBlindVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTBlind" parameterType="TBlind">
        insert into t_blind
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null and id != ''">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="unit != null">unit,</if>
            <if test="system != null">system,</if>
            <if test="blindno != null">blindno,</if>
            <if test="sizes != null">sizes,</if>
            <if test="eightblind != null">eightblind,</if>
            <if test="pressure != null">pressure,</if>
            <if test="blindtype != null">blindtype,</if>
            <if test="pipeno != null">pipeno,</if>
            <if test="media != null">media,</if>
            <if test="pid != null">pid,</if>
            <if test="place != null">place,</if>
            <if test="ynblind != null">ynblind,</if>
            <if test="blinddate != null">blinddate,</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="deptId != null">dept_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null and id != ''">#{id},</if>
            <if test="plantCode != null and plantCode != ''">#{plantCode},</if>
            <if test="unit != null">#{unit},</if>
            <if test="system != null">#{system},</if>
            <if test="blindno != null">#{blindno},</if>
            <if test="sizes != null">#{sizes},</if>
            <if test="eightblind != null">#{eightblind},</if>
            <if test="pressure != null">#{pressure},</if>
            <if test="blindtype != null">#{blindtype},</if>
            <if test="pipeno != null">#{pipeno},</if>
            <if test="media != null">#{media},</if>
            <if test="pid != null">#{pid},</if>
            <if test="place != null">#{place},</if>
            <if test="ynblind != null">#{ynblind},</if>
            <if test="blinddate != null">#{blinddate},</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="deptId != null">#{deptId},</if>
         </trim>
    </insert>

    <update id="updateTBlind" parameterType="TBlind">
        update t_blind
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="system != null">system = #{system},</if>
            <if test="blindno != null">blindno = #{blindno},</if>
            <if test="sizes != null">sizes = #{sizes},</if>
            <if test="eightblind != null">eightblind = #{eightblind},</if>
            <if test="pressure != null">pressure = #{pressure},</if>
            <if test="blindtype != null">blindtype = #{blindtype},</if>
            <if test="pipeno != null">pipeno = #{pipeno},</if>
            <if test="media != null">media = #{media},</if>
            <if test="pid != null">pid = #{pid},</if>
            <if test="place != null">place = #{place},</if>
            <if test="ynblind != null">ynblind = #{ynblind},</if>
            <if test="blinddate != null">blinddate = #{blinddate},</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="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteTBlindById" parameterType="String">
        update t_blind set del_flag = 2 where id = #{id}
    </update>

    <update id="deleteTBlindByIds" parameterType="String">
        update t_blind set del_flag = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    
</mapper>