<?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.dcs.dcs.mapper.DcsFlowMapper">
    
    <resultMap type="DcsFlow" id="DcsFlowResult">
        <result property="flowId"    column="flow_id"    />
        <result property="flowName"    column="flow_name"    />
        <result property="sort"    column="sort"    />
    </resultMap>

    <sql id="selectDcsFlowVo">
        select flow_id, flow_name, sort from dcs_flow
    </sql>

    <select id="selectDcsFlowList" parameterType="DcsFlow" resultMap="DcsFlowResult">
        <include refid="selectDcsFlowVo"/>
        <where>  
            <if test="flowName != null  and flowName != ''"> and flow_name like concat('%', #{flowName}, '%')</if>
        </where>
        ORDER BY sort
    </select>
    
    <select id="selectDcsFlowByFlowId" parameterType="Long" resultMap="DcsFlowResult">
        <include refid="selectDcsFlowVo"/>
        where flow_id = #{flowId}
    </select>
    <select id="selectFlowNameByFlowId" resultType="java.lang.String">
        select flow_name from dcs_flow where flow_id = #{flowId}
    </select>

    <insert id="insertDcsFlow" parameterType="DcsFlow">
        insert into dcs_flow
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="flowId != null">flow_id,</if>
            <if test="flowName != null">flow_name,</if>
            <if test="sort != null">sort,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="flowId != null">#{flowId},</if>
            <if test="flowName != null">#{flowName},</if>
            <if test="sort != null">#{sort},</if>
         </trim>
    </insert>

    <update id="updateDcsFlow" parameterType="DcsFlow">
        update dcs_flow
        <trim prefix="SET" suffixOverrides=",">
            <if test="flowName != null">flow_name = #{flowName},</if>
            <if test="sort != null">sort = #{sort},</if>
        </trim>
        where flow_id = #{flowId}
    </update>

    <delete id="deleteDcsFlowByFlowId" parameterType="Long">
        delete from dcs_flow where flow_id = #{flowId}
    </delete>

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