<?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.ehs.mapper.TAutosprinklerMapper">
    
    <resultMap type="TAutosprinkler" id="TAutosprinklerResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="location"    column="location"    />
        <result property="sysname"    column="sysname"    />
        <result property="chkcontents"    column="chkcontents"    />
        <result property="manitenance"    column="manitenance"    />
        <result property="owner"    column="owner"    />
        <result property="inspector"    column="inspector"    />
        <result property="inspectdate"    column="inspectdate"    />
        <result property="inspectstatus"    column="inspectstatus"    />
        <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="deptId"    column="dept_id"    />
        <result property="remarks"    column="remarks"    />
        <result property="deptName" column="dept_name" />
        <result property="startDate"    column="inspectdate"    />
        <result property="endDate"    column="inspectdate"    />
    </resultMap>

    <sql id="selectTAutosprinklerVo">
        select d.id, d.plant_code, d.location, d.sysname, d.chkcontents, d.manitenance, d.owner, d.inspector, d.inspectdate, d.inspectstatus, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks ,s.dept_name from t_autosprinkler d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTAutosprinklerList" parameterType="TAutosprinkler" resultMap="TAutosprinklerResult">
        <include refid="selectTAutosprinklerVo"/>
        <where>
            <if test="chkcontents != null  and chkcontents != ''"> and chkcontents like concat(concat('%', #{chkcontents}), '%')</if>
            <if test="inspectstatus != null  and inspectstatus != ''"> and inspectstatus = #{inspectstatus}</if>
            <if test="startDate != null ">and inspectdate <![CDATA[>=]]> #{startDate}</if>
            <if test="endDate != null">and inspectdate <![CDATA[<=]]>#{endDate}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by d.inspectdate asc
    </select>

    <select id="selectList" parameterType="TAutosprinkler" resultMap="TAutosprinklerResult">
        <include refid="selectTAutosprinklerVo"/>
        <where>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectTAutosprinklerById" parameterType="Long" resultMap="TAutosprinklerResult">
        <include refid="selectTAutosprinklerVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTAutosprinkler" parameterType="TAutosprinkler">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_autosprinkler.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_autosprinkler
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="location != null">location,</if>
            <if test="sysname != null">sysname,</if>
            <if test="chkcontents != null">chkcontents,</if>
            <if test="manitenance != null">manitenance,</if>
            <if test="owner != null">owner,</if>
            <if test="inspector != null">inspector,</if>
            <if test="inspectdate != null">inspectdate,</if>
            <if test="inspectstatus != null">inspectstatus,</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="deptId != null">dept_id,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null and plantCode != ''">#{plantCode},</if>
            <if test="location != null">#{location},</if>
            <if test="sysname != null">#{sysname},</if>
            <if test="chkcontents != null">#{chkcontents},</if>
            <if test="manitenance != null">#{manitenance},</if>
            <if test="owner != null">#{owner},</if>
            <if test="inspector != null">#{inspector},</if>
            <if test="inspectdate != null">#{inspectdate},</if>
            <if test="inspectstatus != null">#{inspectstatus},</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="deptId != null">#{deptId},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTAutosprinkler" parameterType="TAutosprinkler">
        update t_autosprinkler
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="location != null">location = #{location},</if>
            <if test="sysname != null">sysname = #{sysname},</if>
            <if test="chkcontents != null">chkcontents = #{chkcontents},</if>
            <if test="manitenance != null">manitenance = #{manitenance},</if>
            <if test="owner != null">owner = #{owner},</if>
            <if test="inspector != null">inspector = #{inspector},</if>
            <if test="inspectdate != null">inspectdate = #{inspectdate},</if>
            <if test="inspectstatus != null">inspectstatus = #{inspectstatus},</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="deptId != null">dept_id = #{deptId},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteTAutosprinklerById" parameterType="Long">
        update t_autosprinkler set del_flag = 2 where id = #{id}
    </update>

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