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

    <resultMap type="TSafetyRecord" id="TSafetyRecordResult">
        <result property="id"    column="id"    />
        <result property="washerId"    column="washer_id"    />
        <result property="status"    column="status"    />
        <result property="faultDesc"    column="fault_desc"    />
        <result property="faultSloveSign"    column="fault_slove_sign"    />
        <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="fileIds"    column="file_ids"    />
        <result property="fireId"    column="fire_id"    />
        <result property="measure"    column="measure"    />
        <result property="devId"    column="dev_id"    />
        <result property="devType"    column="dev_type"    />
        <result property="fillingDate"    column="filling_date"    />
        <result property="location"    column="location"    />
    </resultMap>

    <sql id="selectTSafetyRecordVo">
        select id, washer_id, status, fault_desc, fault_slove_sign, inspector, inspectdate, inspectstatus, del_flag, creater_code, createdate, updater_code, updatedate, dept_id, remarks, file_ids,fire_id,measure,filling_date,dev_type,dev_id,location from t_safety_record
    </sql>

    <select id="selectTSafetyRecordList" parameterType="TSafetyRecord" resultMap="TSafetyRecordResult">
        <include refid="selectTSafetyRecordVo"/>
        <where>
            <if test="washerId != null  and washerId != ''"> and washer_id = #{washerId}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="faultDesc != null  and faultDesc != ''"> and fault_desc = #{faultDesc}</if>
            <if test="faultSloveSign != null  and faultSloveSign != ''"> and fault_slove_sign = #{faultSloveSign}</if>
            <if test="inspector != null  and inspector != ''"> and inspector = #{inspector}</if>
            <if test="inspectdate != null "> and inspectdate = #{inspectdate}</if>
            <if test="inspectstatus != null  and inspectstatus != ''"> and inspectstatus = #{inspectstatus}</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>
            <if test="fileIds != null  and fileIds != ''"> and file_ids = #{fileIds}</if>
            <if test="fireId != null  and fireId != ''"> and fire_id = #{fireId}</if>
            <if test="measure != null  and measure != ''"> and measure = #{measure}</if>
            <if test="devType != null  and devType != ''"> and dev_type = #{devType}</if>
            <if test="fillingDate != null  and fillingDate != ''"> and filling_date = #{fillingDate}</if>
            <if test="devId != null  and devId != ''"> and dev_id = #{devId}</if>
        and del_flag = 0
        </where>
        order by createdate desc
    </select>

    <select id="selectTSafetyRecordById" parameterType="Long" resultMap="TSafetyRecordResult">
        <include refid="selectTSafetyRecordVo"/>
        where id=#{id}
    </select>

    <insert id="insertTSafetyRecord" parameterType="TSafetyRecord" useGeneratedKeys="true" keyProperty="id">
        insert into t_safety_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="washerId != null and washerId != ''">washer_id,</if>
            <if test="status != null">status,</if>
            <if test="faultDesc != null">fault_desc,</if>
            <if test="faultSloveSign != null">fault_slove_sign,</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>
            <if test="fileIds != null">file_ids,</if>
            <if test="fireId != null">fire_id,</if>
            <if test="measure != null">measure,</if>
            <if test="fillingDate != null">filling_date,</if>
            <if test="devType != null">dev_type,</if>
            <if test="devId != null">dev_id,</if>
            <if test="location != null">location,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="washerId != null and washerId != ''">#{washerId},</if>
            <if test="status != null">#{status},</if>
            <if test="faultDesc != null">#{faultDesc},</if>
            <if test="faultSloveSign != null">#{faultSloveSign},</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>
            <if test="fileIds != null">#{fileIds},</if>
            <if test="fireId != null">#{fireId},</if>
            <if test="measure != null">#{measure},</if>
            <if test="fillingDate != null">#{fillingDate},</if>
            <if test="devType != null">#{devType},</if>
            <if test="devId != null">#{devId},</if>
            <if test="location != null">#{location},</if>
         </trim>
    </insert>

    <update id="updateTSafetyRecord" parameterType="TSafetyRecord">
        update t_safety_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="washerId != null and washerId != ''">washer_id = #{washerId},</if>
            <if test="status != null">status = #{status},</if>
            <if test="faultDesc != null">fault_desc = #{faultDesc},</if>
            <if test="faultSloveSign != null">fault_slove_sign = #{faultSloveSign},</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>
            <if test="fileIds != null">file_ids = #{fileIds},</if>
            <if test="fireId != null">fire_id = #{fireId},</if>
            <if test="measure != null">measure = #{measure},</if>
            <if test="fillingDate != null">filling_date = #{fillingDate},</if>
            <if test="devType != null">dev_type = #{devType},</if>
            <if test="devId != null">dev_id = #{devId},</if>
            <if test="location != null">location = #{location},</if>
        </trim>
        where id = #{id}
    </update>

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

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