<?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.zehong.system.mapper.TEnterpriseCertificateMapper">
    
    <resultMap type="TEnterpriseCertificate" id="TEnterpriseCertificateResult">
        <result property="id"    column="id"    />
        <result property="enterpriseId"    column="enterprise_id"    />
        <result property="certificateName"    column="certificate_name"    />
        <result property="certificateType"    column="certificate_type"    />
        <result property="certificateUrl"    column="certificate_url"    />
        <result property="effectiveDate"    column="effective_date"    />
        <result property="status"    column="status"    />
        <result property="isDel"    column="is_del"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectTEnterpriseCertificateVo">
        select id, enterprise_id, certificate_name, certificate_type, certificate_url, effective_date, status, is_del, create_time, update_time from t_enterprise_certificate
    </sql>

    <select id="selectTEnterpriseCertificateList" parameterType="TEnterpriseCertificate" resultMap="TEnterpriseCertificateResult">
        <include refid="selectTEnterpriseCertificateVo"/>
        <where>  is_del = '0'
            <if test="enterpriseId != null "> and enterprise_id = #{enterpriseId}</if>
            <if test="certificateName != null  and certificateName != ''"> and certificate_name like concat('%', #{certificateName}, '%')</if>
            <if test="certificateType != null  and certificateType != ''"> and certificate_type = #{certificateType}</if>
            <if test="certificateUrl != null  and certificateUrl != ''"> and certificate_url = #{certificateUrl}</if>
            <if test="effectiveDate != null "> and effective_date = #{effectiveDate}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                AND date_format(effective_date,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                AND date_format(effective_date,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
            </if>
        </where>
    </select>
    
    <select id="selectTEnterpriseCertificateById" parameterType="Long" resultMap="TEnterpriseCertificateResult">
        <include refid="selectTEnterpriseCertificateVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTEnterpriseCertificate" parameterType="TEnterpriseCertificate">
        insert into t_enterprise_certificate
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="enterpriseId != null">enterprise_id,</if>
            <if test="certificateName != null">certificate_name,</if>
            <if test="certificateType != null">certificate_type,</if>
            <if test="certificateUrl != null">certificate_url,</if>
            <if test="effectiveDate != null">effective_date,</if>
            <if test="status != null">status,</if>
            <if test="isDel != null">is_del,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="enterpriseId != null">#{enterpriseId},</if>
            <if test="certificateName != null">#{certificateName},</if>
            <if test="certificateType != null">#{certificateType},</if>
            <if test="certificateUrl != null">#{certificateUrl},</if>
            <if test="effectiveDate != null">#{effectiveDate},</if>
            <if test="status != null">#{status},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateTEnterpriseCertificate" parameterType="TEnterpriseCertificate">
        update t_enterprise_certificate
        <trim prefix="SET" suffixOverrides=",">
            <if test="enterpriseId != null">enterprise_id = #{enterpriseId},</if>
            <if test="certificateName != null">certificate_name = #{certificateName},</if>
            <if test="certificateType != null">certificate_type = #{certificateType},</if>
            <if test="certificateUrl != null">certificate_url = #{certificateUrl},</if>
            <if test="effectiveDate != null">effective_date = #{effectiveDate},</if>
            <if test="status != null">status = #{status},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTEnterpriseCertificateById" parameterType="Long">
        delete from t_enterprise_certificate where id = #{id}
    </delete>

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