<?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.process.mapper.TSifOverviewMapper">
    
    <resultMap type="TSifOverview" id="TSifOverviewResult">
        <result property="id"    column="id"    />
        <result property="sifNo"    column="sif_no"    />
        <result property="plant"    column="plant"    />
        <result property="sifTag"    column="sif_tag"    />
        <result property="deviation"    column="deviation"    />
        <result property="riskAnalysis"    column="risk_analysis"    />
        <result property="causeConsequence"    column="cause_consequence"    />
        <result property="requiredSil"    column="required_sil"    />
        <result property="acheievedSil"    column="acheieved_sil"    />
        <result property="ver"    column="ver"    />
        <result property="pfdavg"    column="pfdavg"    />
        <result property="remarks"    column="remarks"    />
        <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"    />
    </resultMap>

    <resultMap type="TSifVo" id="TSifVoResult">
        <result property="id"    column="id"    />
        <result property="sifNo"    column="sif_no"    />
        <result property="plant"    column="plant"    />
        <result property="sifTag"    column="sif_tag"    />
        <result property="deviation"    column="deviation"    />
        <result property="riskAnalysis"    column="risk_analysis"    />
        <result property="causeConsequence"    column="cause_consequence"    />
        <result property="requiredSil"    column="required_sil"    />
        <result property="acheievedSil"    column="acheieved_sil"    />
        <result property="ver"    column="ver"    />
        <result property="pfdavg"    column="pfdavg"    />
        <result property="sensorTag"    column="sensor_tag"    />
        <result property="type"    column="type"    />
        <result property="service"    column="service"    />
        <result property="votingQ"    column="voting_q"    />
        <result property="condition"    column="condition"    />
        <result property="mainPti"    column="main_pti"    />
        <result property="finalElementTag"    column="final_element_tag"    />
        <result property="h"    column="h"    />
        <result property="hType"    column="h_type"    />
        <result property="hService"    column="h_service"    />
        <result property="votingH"    column="voting_h"    />
        <result property="action"    column="action"    />
        <result property="mainPtiH"    column="main_pti_h"    />
        <result property="filter"    column="filter"    />
        <result property="remarks"    column="remarks"    />
        <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"    />
    </resultMap>

    <sql id="selectTSifOverviewVo">
        select id, sif_no, plant, sif_tag, deviation, risk_analysis, cause_consequence, required_sil, acheieved_sil, ver, pfdavg, remarks, del_flag, creater_code, createdate, updater_code, updatedate, dept_id from t_sif_overview
    </sql>

    <sql id="selectTSifVoVo">
        SELECT a.id, a.sif_no, a.plant, a.sif_tag, a.deviation, a.risk_analysis, a.cause_consequence, a.required_sil, a.acheieved_sil, a.ver, a.pfdavg, a.remarks, a.del_flag, a.creater_code, a.createdate, a.updater_code, a.updatedate, a.dept_id, b.sensor_tag, b.type, b.service, b.voting_q, b.`condition`, b.main_pti, b.final_element_tag,b.h,b.h_type,b.h_service, b.voting_h, b.action,b.main_pti_h,b.`filter` FROM t_sif_overview a LEFT JOIN t_sis_record b on a.id=b.sis_id
    </sql>


    <select id="selectTSifOverviewList" parameterType="TSifOverview" resultMap="TSifVoResult">
        <include refid="selectTSifVoVo"/>
        <where>
            <if test="sifNo != null  and sifNo != ''"> and sif_no = #{sifNo}</if>
            <if test="plant != null  and plant != ''"> and plant = #{plant}</if>
            <if test="sifTag != null  and sifTag != ''"> and sif_tag = #{sifTag}</if>
            <if test="deviation != null  and deviation != ''"> and deviation = #{deviation}</if>
            <if test="riskAnalysis != null  and riskAnalysis != ''"> and risk_analysis = #{riskAnalysis}</if>
            <if test="causeConsequence != null  and causeConsequence != ''"> and cause_consequence = #{causeConsequence}</if>
            <if test="requiredSil != null  and requiredSil != ''"> and required_sil = #{requiredSil}</if>
            <if test="acheievedSil != null  and acheievedSil != ''"> and acheieved_sil = #{acheievedSil}</if>
            <if test="ver != null  and ver != ''"> and ver = #{ver}</if>
            <if test="pfdavg != null  and pfdavg != ''"> and pfdavg = #{pfdavg}</if>
        and a.del_flag=0
        </where>
        order by a.createdate desc
    </select>
    
    <select id="selectTSifOverviewById" parameterType="Long" resultMap="TSifOverviewResult">
        <include refid="selectTSifOverviewVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTSifOverview" parameterType="TSifOverview" useGeneratedKeys="true" keyProperty="id">
        insert into t_sif_overview
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sifNo != null">sif_no,</if>
            <if test="plant != null">plant,</if>
            <if test="sifTag != null">sif_tag,</if>
            <if test="deviation != null">deviation,</if>
            <if test="riskAnalysis != null">risk_analysis,</if>
            <if test="causeConsequence != null">cause_consequence,</if>
            <if test="requiredSil != null">required_sil,</if>
            <if test="acheievedSil != null">acheieved_sil,</if>
            <if test="ver != null">ver,</if>
            <if test="pfdavg != null">pfdavg,</if>
            <if test="remarks != null">remarks,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="sifNo != null">#{sifNo},</if>
            <if test="plant != null">#{plant},</if>
            <if test="sifTag != null">#{sifTag},</if>
            <if test="deviation != null">#{deviation},</if>
            <if test="riskAnalysis != null">#{riskAnalysis},</if>
            <if test="causeConsequence != null">#{causeConsequence},</if>
            <if test="requiredSil != null">#{requiredSil},</if>
            <if test="acheievedSil != null">#{acheievedSil},</if>
            <if test="ver != null">#{ver},</if>
            <if test="pfdavg != null">#{pfdavg},</if>
            <if test="remarks != null">#{remarks},</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>
         </trim>
    </insert>

    <update id="updateTSifOverview" parameterType="TSifOverview">
        update t_sif_overview
        <trim prefix="SET" suffixOverrides=",">
            <if test="sifNo != null">sif_no = #{sifNo},</if>
            <if test="plant != null">plant = #{plant},</if>
            <if test="sifTag != null">sif_tag = #{sifTag},</if>
            <if test="deviation != null">deviation = #{deviation},</if>
            <if test="riskAnalysis != null">risk_analysis = #{riskAnalysis},</if>
            <if test="causeConsequence != null">cause_consequence = #{causeConsequence},</if>
            <if test="requiredSil != null">required_sil = #{requiredSil},</if>
            <if test="acheievedSil != null">acheieved_sil = #{acheievedSil},</if>
            <if test="ver != null">ver = #{ver},</if>
            <if test="pfdavg != null">pfdavg = #{pfdavg},</if>
            <if test="remarks != null">remarks = #{remarks},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTSifOverviewById" parameterType="Long">
        delete from t_sif_overview where id = #{id}
    </delete>

    <delete id="deleteTSifOverviewByIds" parameterType="String">
        delete from t_sif_overview where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>