<?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.dpc.mapper.DpcIntermediaryBlacklistMapper">

    <resultMap type="DpcIntermediaryBlacklist" id="DpcIntermediaryBlacklistResult">
        <id property="intermediaryId" column="intermediary_id"/>
        <result property="name" column="name"/>
        <result property="certificateNo" column="certificate_no"/>
        <result property="intermediaryType" column="intermediary_type"/>
        <result property="status" column="status"/>
        <result property="remark" column="remark"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectIntermediaryVo">
        select intermediary_id, name, certificate_no, intermediary_type, status, remark,
               create_by, create_time, update_by, update_time
        from dpc_intermediary_blacklist
    </sql>

    <select id="selectIntermediaryList" parameterType="DpcIntermediaryBlacklistQueryDTO"
            resultMap="DpcIntermediaryBlacklistResult">
        <include refid="selectIntermediaryVo"/>
        <where>
            <if test="name != null and name != ''">
                AND name like concat('%', #{name}, '%')
            </if>
            <if test="certificateNo != null and certificateNo != ''">
                AND certificate_no = #{certificateNo}
            </if>
            <if test="intermediaryType != null and intermediaryType != ''">
                AND intermediary_type = #{intermediaryType}
            </if>
            <if test="status != null and status != ''">
                AND status = #{status}
            </if>
        </where>
        order by create_time desc
    </select>

    <select id="selectIntermediaryById" parameterType="Long" resultMap="DpcIntermediaryBlacklistResult">
        <include refid="selectIntermediaryVo"/>
        where intermediary_id = #{intermediaryId}
    </select>

    <insert id="insertIntermediary" parameterType="DpcIntermediaryBlacklist" useGeneratedKeys="true"
            keyProperty="intermediaryId">
        insert into dpc_intermediary_blacklist
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="certificateNo != null and certificateNo != ''">certificate_no,</if>
            <if test="intermediaryType != null and intermediaryType != ''">intermediary_type,</if>
            <if test="status != null and status != ''">status,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null and createBy != ''">create_by,</if>
            create_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="certificateNo != null and certificateNo != ''">#{certificateNo},</if>
            <if test="intermediaryType != null and intermediaryType != ''">#{intermediaryType},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            sysdate()
        </trim>
    </insert>

    <update id="updateIntermediary" parameterType="DpcIntermediaryBlacklist">
        update dpc_intermediary_blacklist
        <set>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="certificateNo != null">certificate_no = #{certificateNo},</if>
            <if test="intermediaryType != null and intermediaryType != ''">intermediary_type = #{intermediaryType},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            update_time = sysdate()
        </set>
        where intermediary_id = #{intermediaryId}
    </update>

    <delete id="deleteIntermediaryById" parameterType="Long">
        delete from dpc_intermediary_blacklist where intermediary_id = #{intermediaryId}
    </delete>

    <delete id="deleteIntermediaryByIds" parameterType="Long">
        delete from dpc_intermediary_blacklist where intermediary_id in
        <foreach collection="array" item="intermediaryId" open="(" separator="," close=")">
            #{intermediaryId}
        </foreach>
    </delete>

</mapper>
