<?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="dName"    column="d_name"    />
        <result property="dCode"    column="d_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="dEmail"    column="d_email"    />
        <result property="dPhone"    column="d_phone"    />
        <result property="updateDate"    column="update_date"    />
        <result property="certContent"    column="cert_content"    />
    </resultMap>

    <sql id="selectContractTableVo">
        select id, cert_type, d_name, d_code, cert_id, cert_major, issue_date, valid_term, d_email, d_phone, update_date, cert_content 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="dName != null  and dName != ''"> and d_name like concat('%', #{dName}, '%')</if>
            <if test="dCode != null  and dCode != ''"> and d_code = #{dCode}</if>
            <if test="certId != null  and certId != ''"> and cert_id = #{certId}</if>
            <if test="certMajor != null "> and cert_major = #{certMajor}</if>
            <if test="dEmail != null  and dEmail != ''"> and d_email = #{dEmail}</if>
            <if test="dPhone != null  and dPhone != ''"> and d_phone = #{dPhone}</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 d_code = #{dCode}
    </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="dName != null and dName != ''">d_name,</if>
            <if test="dCode != null">d_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="dEmail != null">d_email,</if>
            <if test="dPhone != null">d_phone,</if>
            <if test="updateDate != null">update_date,</if>
            <if test="certContent != null">cert_content,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="certType != null">#{certType},</if>
            <if test="dName != null and dName != ''">#{dName},</if>
            <if test="dCode != null">#{dCode},</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="dEmail != null">#{dEmail},</if>
            <if test="dPhone != null">#{dPhone},</if>
            <if test="updateDate != null">#{updateDate},</if>
            <if test="certContent != null">#{certContent},</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="dName != null and dName != ''">d_name = #{dName},</if>
            <if test="dCode != null">d_code = #{dCode},</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="dEmail != null">d_email = #{dEmail},</if>
            <if test="dPhone != null">d_phone = #{dPhone},</if>
            <if test="updateDate != null">update_date = #{updateDate},</if>
            <if test="certContent != null">cert_content = #{certContent},</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>