<?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.cpms.project.safety.mapper.TSafetyFireExtinguisherMapper">

    <resultMap type="TSafetyFireExtinguisher" id="TSafetyFireExtinguisherResult">
        <result property="id"    column="id"    />
        <result property="plantName"    column="plant_name"    />
        <result property="devNo"    column="dev_no"    />
        <result property="location"    column="location"    />
        <result property="devNum"    column="dev_num"    />
        <result property="extinguisherType"    column="extinguisher_type"    />
        <result property="inspector"    column="inspector"    />
        <result property="fillingDate"    column="filling_date"    />
        <result property="inspectdate"    column="inspectdate"    />
        <result property="status"    column="status"    />
        <result property="measure"    column="measure"    />
        <result property="inspectstatus"    column="inspectstatus"    />
        <result property="fileIds"    column="file_ids"    />
        <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"    />
    </resultMap>

    <sql id="selectTSafetyFireExtinguisherVo">
        select id, plant_name, dev_no, location, dev_num, extinguisher_type, inspector, filling_date, inspectdate, status, measure, inspectstatus, file_ids, del_flag, creater_code, createdate, updater_code, updatedate, dept_id, remarks from t_safety_fire_extinguisher
    </sql>

    <select id="selectTSafetyFireExtinguisherList" parameterType="TSafetyFireExtinguisher" resultMap="TSafetyFireExtinguisherResult">
        <include refid="selectTSafetyFireExtinguisherVo"/>
        <where>
            <if test="plantName != null  and plantName != ''"> and plant_name like concat('%', #{plantName}, '%')</if>
            <if test="devNo != null  and devNo != ''"> and dev_no = #{devNo}</if>
            <if test="location != null  and location != ''"> and location = #{location}</if>
            <if test="devNum != null  and devNum != ''"> and dev_num = #{devNum}</if>
            <if test="extinguisherType != null  and extinguisherType != ''"> and extinguisher_type = #{extinguisherType}</if>
            <if test="inspector != null  and inspector != ''"> and inspector = #{inspector}</if>
            <if test="fillingDate != null  and fillingDate != ''"> and filling_date = #{fillingDate}</if>
            <if test="inspectdate != null "> and inspectdate = #{inspectdate}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="measure != null  and measure != ''"> and measure = #{measure}</if>
            <if test="inspectstatus != null  and inspectstatus != ''"> and inspectstatus = #{inspectstatus}</if>
            <if test="fileIds != null  and fileIds != ''"> and file_ids = #{fileIds}</if>
            <if test="createrCode != null  and createrCode != ''"> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null  and updaterCode != ''"> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
        and del_flag = 0
        </where>
    </select>

    <select id="selectTSafetyFireExtinguisherById" parameterType="Long" resultMap="TSafetyFireExtinguisherResult">
        <include refid="selectTSafetyFireExtinguisherVo"/>
        where id = #{id}
    </select>

    <insert id="insertTSafetyFireExtinguisher" parameterType="TSafetyFireExtinguisher" useGeneratedKeys="true" keyProperty="id">
        insert into t_safety_fire_extinguisher
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="plantName != null and plantName != ''">plant_name,</if>
            <if test="devNo != null and devNo != ''">dev_no,</if>
            <if test="location != null and location != ''">location,</if>
            <if test="devNum != null and devNum != ''">dev_num,</if>
            <if test="extinguisherType != null and extinguisherType != ''">extinguisher_type,</if>
            <if test="inspector != null">inspector,</if>
            <if test="fillingDate != null">filling_date,</if>
            <if test="inspectdate != null">inspectdate,</if>
            <if test="status != null">status,</if>
            <if test="measure != null">measure,</if>
            <if test="inspectstatus != null">inspectstatus,</if>
            <if test="fileIds != null">file_ids,</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="plantName != null and plantName != ''">#{plantName},</if>
            <if test="devNo != null and devNo != ''">#{devNo},</if>
            <if test="location != null and location != ''">#{location},</if>
            <if test="devNum != null and devNum != ''">#{devNum},</if>
            <if test="extinguisherType != null and extinguisherType != ''">#{extinguisherType},</if>
            <if test="inspector != null">#{inspector},</if>
            <if test="fillingDate != null">#{fillingDate},</if>
            <if test="inspectdate != null">#{inspectdate},</if>
            <if test="status != null">#{status},</if>
            <if test="measure != null">#{measure},</if>
            <if test="inspectstatus != null">#{inspectstatus},</if>
            <if test="fileIds != null">#{fileIds},</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="updateTSafetyFireExtinguisher" parameterType="TSafetyFireExtinguisher">
        update t_safety_fire_extinguisher
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantName != null and plantName != ''">plant_name = #{plantName},</if>
            <if test="devNo != null and devNo != ''">dev_no = #{devNo},</if>
            <if test="location != null and location != ''">location = #{location},</if>
            <if test="devNum != null and devNum != ''">dev_num = #{devNum},</if>
            <if test="extinguisherType != null and extinguisherType != ''">extinguisher_type = #{extinguisherType},</if>
            <if test="inspector != null">inspector = #{inspector},</if>
            <if test="fillingDate != null">filling_date = #{fillingDate},</if>
            <if test="inspectdate != null">inspectdate = #{inspectdate},</if>
            <if test="status != null">status = #{status},</if>
            <if test="measure != null">measure = #{measure},</if>
            <if test="inspectstatus != null">inspectstatus = #{inspectstatus},</if>
            <if test="fileIds != null">file_ids = #{fileIds},</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>

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

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