<?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="cn.fateverse.workflow.mapper.ProcessListenerMapper">

    <resultMap id="ProcessListenerResult" type="cn.fateverse.workflow.entity.ProcessListener">
        <id column="id" property="id"/>
        <result column="listener_type" property="listenerType"/>
        <result column="event_type" property="eventType"/>
        <result column="listener_name" property="listenerName"/>
        <result column="listener_value" property="listenerValue"/>
        <result column="listener_value_type" property="listenerValueType"/>
        <result column="create_by" property="createBy"/>
        <result column="create_time" property="createTime"/>
        <result column="update_by" property="updateBy"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <sql id="selectProcessListenerVo">
        select id,
               listener_type,
               event_type,
               listener_name,
               listener_value,
               listener_value_type,
               create_by,
               create_time,
               update_by,
               update_time
        from wk_re_process_listener
    </sql>


    <select id="selectList" resultMap="ProcessListenerResult">
        <include refid="selectProcessListenerVo"/>
        <where>
            <if test="listenerType != null  and listenerType != ''">and listener_type = #{listenerType}</if>
            <if test="eventType != null  and eventType != ''">and event_type like concat('%', #{eventType}, '%')</if>
            <if test="listenerName != null  and listenerName != ''">and listener_name like concat('%', #{listenerName},'%')
            </if>
            <if test="listenerValueType != null  and listenerValueType != ''">and listener_value_type = #{listenerValueType}
            </if>
        </where>
    </select>

    <select id="selectById" resultMap="ProcessListenerResult">
        <include refid="selectProcessListenerVo"/>
        where id = #{id}
    </select>

    <select id="selectIds" resultType="cn.fateverse.workflow.entity.ProcessListener">
        <include refid="selectProcessListenerVo"/>
        where id in
        <foreach collection="list" open="(" separator="," close=")" item="id">
            #{id}
        </foreach>
    </select>

    <insert id="insert">
        insert into wk_re_process_listener
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="listenerType != null">listener_type,</if>
            <if test="eventType != null">event_type,</if>
            <if test="listenerName != null">listener_name,</if>
            <if test="listenerValue != null">listener_value,</if>
            <if test="listenerValueType != null">listener_value_type,</if>
            <if test="createBy != null and createBy != ''">create_by,</if>
            <if test="createTime != null ">create_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="listenerType != null">#{listenerType},</if>
            <if test="eventType != null">#{eventType},</if>
            <if test="listenerName != null">#{listenerName},</if>
            <if test="listenerValue != null">#{listenerValue},</if>
            <if test="listenerValueType != null">#{listenerValueType},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            <if test="createTime != null ">#{createTime},</if>
        </trim>
    </insert>

    <update id="update">
        update wk_re_process_listener
        <set>
            <if test="listenerType != null">listener_type = #{listenerType},</if>
            <if test="eventType != null">event_type = #{eventType},</if>
            <if test="listenerName != null">listener_name = #{listenerName},</if>
            <if test="listenerValue != null">listener_value = #{listenerValue},</if>
            <if test="listenerValueType != null">listener_value_type = #{listenerValueType},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </set>
        where id = #{id}
    </update>

    <delete id="deleteById">
        delete
        from wk_re_process_listener
        where id = #{id}
    </delete>

    <delete id="deleteBatchByIdList" parameterType="String">
        delete from wk_re_process_listener
        where id in
        <foreach collection="list" open="(" close=")" separator="," item="id">
            #{id}
        </foreach>
    </delete>

</mapper>