<?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.system.mapper.ContractTableMapper">
    
    <resultMap type="ContractTable" id="ContractTableResult">
        <result property="id"    column="id"    />
        <result property="certType"    column="cert_type"    />
        <result property="name"    column="name"    />
        <result property="code"    column="code"    />
        <result property="certId"    column="cert_id"    />
        <result property="certMajor"    column="cert_major"    />
        <result property="issueDate"    column="issue_date"    />
        <result property="validTerm"    column="valid_term"    />
        <result property="email"    column="email"    />
        <result property="phone"    column="phone"    />
        <result property="updateDate"    column="update_date"    />
        <result property="certContent"    column="cert_content"    />
        <result property="templateId" column="template_id"/>
    </resultMap>

    <sql id="selectContractTableVo">
        select id, cert_type, name, code, cert_id, cert_major, issue_date, valid_term, email, phone, update_date, cert_content, template_id from contract_table
    </sql>

    <select id="selectContractTableList" parameterType="ContractTable" resultMap="ContractTableResult">
        <include refid="selectContractTableVo"/>
        <where>  
            <if test="certType != null "> and cert_type = #{certType}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="code != null  and code != ''"> and code = #{code}</if>
            <if test="certId != null  and certId != ''"> and cert_id = #{certId}</if>
            <if test="certMajor != null "> and cert_major = #{certMajor}</if>
            <if test="email != null  and email != ''"> and email = #{email}</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
        </where>
    </select>
    
    <select id="selectContractTableById" parameterType="Long" resultMap="ContractTableResult">
        <include refid="selectContractTableVo"/>
        where id = #{id}
    </select>

    <select id="selectContractTableByCode" parameterType="String" resultMap="ContractTableResult">
        <include refid="selectContractTableVo"/>
        where cert_id = #{certId}
    </select>
        
    <insert id="insertContractTable" parameterType="ContractTable" useGeneratedKeys="true" keyProperty="id">
        insert into contract_table
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="certType != null">cert_type,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="code != null">code,</if>
            <if test="certId != null and certId != ''">cert_id,</if>
            <if test="certMajor != null">cert_major,</if>
            <if test="issueDate != null">issue_date,</if>
            <if test="validTerm != null and validTerm != ''">valid_term,</if>
            <if test="email != null">email,</if>
            <if test="phone != null">phone,</if>
            <if test="updateDate != null">update_date,</if>
            <if test="certContent != null">cert_content,</if>
            <if test="templateId != null">template_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="certType != null">#{certType},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="code != null">#{code},</if>
            <if test="certId != null and certId != ''">#{certId},</if>
            <if test="certMajor != null">#{certMajor},</if>
            <if test="issueDate != null">#{issueDate},</if>
            <if test="validTerm != null and validTerm != ''">#{validTerm},</if>
            <if test="email != null">#{email},</if>
            <if test="phone != null">#{phone},</if>
            <if test="updateDate != null">#{updateDate},</if>
            <if test="certContent != null">#{certContent},</if>
            <if test="templateId != null">#{templateId},</if>
         </trim>
    </insert>

    <update id="updateContractTable" parameterType="ContractTable">
        update contract_table
        <trim prefix="SET" suffixOverrides=",">
            <if test="certType != null">cert_type = #{certType},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="code != null">code = #{code},</if>
            <if test="certId != null and certId != ''">cert_id = #{certId},</if>
            <if test="certMajor != null">cert_major = #{certMajor},</if>
            <if test="issueDate != null">issue_date = #{issueDate},</if>
            <if test="validTerm != null and validTerm != ''">valid_term = #{validTerm},</if>
            <if test="email != null">email = #{email},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="updateDate != null">update_date = #{updateDate},</if>
            <if test="certContent != null">cert_content = #{certContent},</if>
            <if test="templateId != null">template_id = #{templateId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteContractTableById" parameterType="Long">
        delete from contract_table where id = #{id}
    </delete>

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