<?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.approval.mapper.TApprovalMapper">
    
    <resultMap type="TApproval" id="TApprovalResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="division"    column="division"    />
        <result property="effetivedate"    column="effetivedate"    />
        <result property="itemName"    column="item_name"    />
        <result property="itemOverview"    column="item_overview"    />
        <result property="approvalAttibutes"    column="approval_attibutes"    />
        <result property="approvalname"    column="approvalname"    />
        <result property="fileno"    column="fileno"    />
        <result property="responsauth"    column="responsauth"    />
        <result property="contentFile"    column="content_file"    />
        <result property="content"    column="content"    />
        <result property="scope"    column="scope"    />
        <result property="relatedlaw"    column="relatedlaw"    />
        <result property="validityBefore"    column="validity_before"    />
        <result property="validityAfter"    column="validity_after"    />
        <result property="isPermanent"    column="is_permanent"    />
        <result property="follow"    column="follow"    />
        <result property="owner"    column="owner"    />
        <result property="reviewer"    column="reviewer"    />
        <result property="reviewdate"    column="reviewdate"    />
        <result property="isCompliance"    column="is_compliance"    />
        <result property="nextreviewdate"    column="nextreviewdate"    />
        <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="selectTApprovalVo">
        select id, plant_code, division, effetivedate, item_name, item_overview, approval_attibutes, approvalname, fileno, responsauth, content_file, content, scope, relatedlaw, validity_before, validity_after, is_permanent, follow, owner, reviewer, reviewdate, is_compliance, nextreviewdate, remarks, del_flag, creater_code, createdate, updater_code, updatedate, dept_id from t_approval
    </sql>

    <select id="selectTApprovalList" parameterType="TApproval" resultMap="TApprovalResult">
        <include refid="selectTApprovalVo"/>
        <where>  
            <if test="plantCode != null  and plantCode != ''"> and plant_code = #{plantCode}</if>
            <if test="division != null  and division != ''"> and division = #{division}</if>
            <if test="effetivedate != null "> and effetivedate = #{effetivedate}</if>
            <if test="itemName != null  and itemName != ''"> and item_name like concat('%', #{itemName}, '%')</if>
            <if test="itemOverview != null  and itemOverview != ''"> and item_overview = #{itemOverview}</if>
            <if test="approvalAttibutes != null  and approvalAttibutes != ''"> and approval_attibutes = #{approvalAttibutes}</if>
            <if test="approvalname != null  and approvalname != ''"> and approvalname like concat('%', #{approvalname}, '%')</if>
            <if test="fileno != null  and fileno != ''"> and fileno = #{fileno}</if>
            <if test="responsauth != null  and responsauth != ''"> and responsauth = #{responsauth}</if>
            <if test="contentFile != null  and contentFile != ''"> and content_file = #{contentFile}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="scope != null  and scope != ''"> and scope = #{scope}</if>
            <if test="relatedlaw != null  and relatedlaw != ''"> and relatedlaw = #{relatedlaw}</if>
            <if test="validityBefore != null "> and validity_before = #{validityBefore}</if>
            <if test="validityAfter != null "> and validity_after = #{validityAfter}</if>
            <if test="isPermanent != null  and isPermanent != ''"> and is_permanent = #{isPermanent}</if>
            <if test="follow != null  and follow != ''"> and follow = #{follow}</if>
            <if test="owner != null  and owner != ''"> and owner = #{owner}</if>
            <if test="reviewer != null  and reviewer != ''"> and reviewer = #{reviewer}</if>
            <if test="reviewdate != null "> and reviewdate = #{reviewdate}</if>
            <if test="isCompliance != null  and isCompliance != ''"> and is_compliance = #{isCompliance}</if>
            <if test="nextreviewdate != null "> and nextreviewdate = #{nextreviewdate}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</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>
        </where>
    </select>
    
    <select id="selectTApprovalById" parameterType="Long" resultMap="TApprovalResult">
        <include refid="selectTApprovalVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTApproval" parameterType="TApproval" useGeneratedKeys="true" keyProperty="id">
        insert into t_approval
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="plantCode != null">plant_code,</if>
            <if test="division != null">division,</if>
            <if test="effetivedate != null">effetivedate,</if>
            <if test="itemName != null">item_name,</if>
            <if test="itemOverview != null">item_overview,</if>
            <if test="approvalAttibutes != null">approval_attibutes,</if>
            <if test="approvalname != null and approvalname != ''">approvalname,</if>
            <if test="fileno != null and fileno != ''">fileno,</if>
            <if test="responsauth != null">responsauth,</if>
            <if test="contentFile != null">content_file,</if>
            <if test="content != null">content,</if>
            <if test="scope != null">scope,</if>
            <if test="relatedlaw != null">relatedlaw,</if>
            <if test="validityBefore != null">validity_before,</if>
            <if test="validityAfter != null">validity_after,</if>
            <if test="isPermanent != null">is_permanent,</if>
            <if test="follow != null">follow,</if>
            <if test="owner != null">owner,</if>
            <if test="reviewer != null">reviewer,</if>
            <if test="reviewdate != null">reviewdate,</if>
            <if test="isCompliance != null">is_compliance,</if>
            <if test="nextreviewdate != null">nextreviewdate,</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="plantCode != null">#{plantCode},</if>
            <if test="division != null">#{division},</if>
            <if test="effetivedate != null">#{effetivedate},</if>
            <if test="itemName != null">#{itemName},</if>
            <if test="itemOverview != null">#{itemOverview},</if>
            <if test="approvalAttibutes != null">#{approvalAttibutes},</if>
            <if test="approvalname != null and approvalname != ''">#{approvalname},</if>
            <if test="fileno != null and fileno != ''">#{fileno},</if>
            <if test="responsauth != null">#{responsauth},</if>
            <if test="contentFile != null">#{contentFile},</if>
            <if test="content != null">#{content},</if>
            <if test="scope != null">#{scope},</if>
            <if test="relatedlaw != null">#{relatedlaw},</if>
            <if test="validityBefore != null">#{validityBefore},</if>
            <if test="validityAfter != null">#{validityAfter},</if>
            <if test="isPermanent != null">#{isPermanent},</if>
            <if test="follow != null">#{follow},</if>
            <if test="owner != null">#{owner},</if>
            <if test="reviewer != null">#{reviewer},</if>
            <if test="reviewdate != null">#{reviewdate},</if>
            <if test="isCompliance != null">#{isCompliance},</if>
            <if test="nextreviewdate != null">#{nextreviewdate},</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="updateTApproval" parameterType="TApproval">
        update t_approval
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null">plant_code = #{plantCode},</if>
            <if test="division != null">division = #{division},</if>
            <if test="effetivedate != null">effetivedate = #{effetivedate},</if>
            <if test="itemName != null">item_name = #{itemName},</if>
            <if test="itemOverview != null">item_overview = #{itemOverview},</if>
            <if test="approvalAttibutes != null">approval_attibutes = #{approvalAttibutes},</if>
            <if test="approvalname != null and approvalname != ''">approvalname = #{approvalname},</if>
            <if test="fileno != null and fileno != ''">fileno = #{fileno},</if>
            <if test="responsauth != null">responsauth = #{responsauth},</if>
            <if test="contentFile != null">content_file = #{contentFile},</if>
            <if test="content != null">content = #{content},</if>
            <if test="scope != null">scope = #{scope},</if>
            <if test="relatedlaw != null">relatedlaw = #{relatedlaw},</if>
            <if test="validityBefore != null">validity_before = #{validityBefore},</if>
            <if test="validityAfter != null">validity_after = #{validityAfter},</if>
            <if test="isPermanent != null">is_permanent = #{isPermanent},</if>
            <if test="follow != null">follow = #{follow},</if>
            <if test="owner != null">owner = #{owner},</if>
            <if test="reviewer != null">reviewer = #{reviewer},</if>
            <if test="reviewdate != null">reviewdate = #{reviewdate},</if>
            <if test="isCompliance != null">is_compliance = #{isCompliance},</if>
            <if test="nextreviewdate != null">nextreviewdate = #{nextreviewdate},</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="deleteTApprovalById" parameterType="Long">
        delete from t_approval where id = #{id}
    </delete>

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