<?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.ho.flow.mapper.ProcessTemplateMapper">

    <resultMap id="BaseResultMap" type="com.ho.flow.entity.ProcessTemplate">
        <id property="id" column="id" jdbcType="INTEGER"/>
        <result property="serialNum" column="serial_num" jdbcType="VARCHAR"/>
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <result property="type" column="type" jdbcType="INTEGER"/>
        <result property="remark" column="remark" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="status" column="status" jdbcType="TINYINT"/>
    </resultMap>

    <sql id="Base_Column_List">
        id
        ,serial_num,name,
        type,remark,create_time,
        status
    </sql>
    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.ho.flow.entity.ProcessTemplate"
            useGeneratedKeys="true">
        insert into process_template
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="serialNum != null and serialNum != ''">serial_num,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="type != null">type,</if>
            <if test="remark != null and remark != ''">remark,</if>
            <if test="createTime != null">create_time,</if>
            <if test="status != null ">status,</if>
            <if test="processBpmn != null ">process_bpmn,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="serialNum != null and serialNum != ''">#{serialNum},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="type != null">#{type},</if>
            <if test="remark != null and remark != ''">#{remark},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="status != null ">#{status},</if>
            <if test="processBpmn != null ">#{processBpmn},</if>
        </trim>
    </insert>
    <update id="update">
        update process_template
        <set>
            <if test="serialNum != null and serialNum != ''">serial_num =  #{serialNum},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="type != null">type = #{type},</if>
            <if test="remark != null and remark != ''">remark = #{remark},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="status != null ">status = #{status},</if>
            <if test="processBpmn != null ">process_bpmn = #{processBpmn},</if>
        </set>
        where id = #{id}
    </update>

    <delete id="delete">
        delete
        from process_template
        where id = #{id,jdbcType=INTEGER}
    </delete>

    <select id="selectList" resultType="com.ho.flow.entity.ProcessTemplate">
        select
        <include refid="Base_Column_List"/>
        from process_template
        <where>
            <if test="serialNum != null">and serial_num LIKE concat('%',#{serialNum},'%')</if>
            <if test="name != null and name != ''">and `name`  LIKE concat('%',#{name},'%')</if>
            <if test="type != null">and type = #{type}</if>
            <if test="remark != null and remark != ''">and remark = #{remark}</if>
            <if test="createTime != null">and create_time = #{createTime}</if>
            <if test="status != null ">and status = #{status}</if>
        </where>
    </select>

    <select id="selectById" resultType="com.ho.flow.entity.ProcessTemplate">
        select
        <include refid="Base_Column_List"/>
        from process_template
        where id = #{id}
    </select>
    <select id="selectBpmnById" resultType="java.lang.String">
        select
        process_bpmn
        from process_template
        where id = #{id}
    </select>
</mapper>
