<?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.ozs.pm.mapper.PmFlowChartMapper">
    
    <resultMap type="com.ozs.pm.doman.PmFlowChart" id="PmFlowChartResult">
        <result property="flowChartId"    column="flow_chart_id"    />
        <result property="moduleName"    column="module_name"    />
        <result property="deptRole"    column="dept_role"    />
        <result property="promptWords"    column="prompt_words"    />
        <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="selectPmFlowChartVo">
        select flow_chart_id, module_name, dept_role, prompt_words, create_by, create_time, update_by, update_time from pm_flow_chart
    </sql>

    <select id="selectPmFlowChartList" parameterType="com.ozs.pm.doman.PmFlowChart" resultMap="PmFlowChartResult">
        <include refid="selectPmFlowChartVo"/>
        <where>  
            <if test="moduleName != null  and moduleName != ''"> and module_name like concat('%', #{moduleName}, '%')</if>
            <if test="deptRole != null  and deptRole != ''"> and dept_role = #{deptRole}</if>
            <if test="promptWords != null  and promptWords != ''"> and prompt_words = #{promptWords}</if>
        </where>
    </select>
    
    <select id="selectPmFlowChartByFlowChartId" parameterType="Long" resultMap="PmFlowChartResult">
        <include refid="selectPmFlowChartVo"/>
        where flow_chart_id = #{flowChartId}
    </select>
        
    <insert id="insertPmFlowChart" parameterType="com.ozs.pm.doman.PmFlowChart" useGeneratedKeys="true" keyProperty="flowChartId">
        insert into pm_flow_chart
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="moduleName != null and moduleName != ''">module_name,</if>
            <if test="deptRole != null">dept_role,</if>
            <if test="promptWords != null">prompt_words,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="moduleName != null and moduleName != ''">#{moduleName},</if>
            <if test="deptRole != null">#{deptRole},</if>
            <if test="promptWords != null">#{promptWords},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updatePmFlowChart" parameterType="com.ozs.pm.doman.PmFlowChart">
        update pm_flow_chart
        <trim prefix="SET" suffixOverrides=",">
            <if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if>
            <if test="deptRole != null">dept_role = #{deptRole},</if>
            <if test="promptWords != null">prompt_words = #{promptWords},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where flow_chart_id = #{flowChartId}
    </update>

    <delete id="deletePmFlowChartByFlowChartId" parameterType="Long">
        delete from pm_flow_chart where flow_chart_id = #{flowChartId}
    </delete>

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