<?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.siwei.system.mapper.SysRoleAuditflowMapper">
    
    <resultMap type="SysRoleAuditflow" id="SysRoleAuditflowResult">
        <result property="roleId"    column="role_id"    />
        <result property="auditflowId"    column="auditflow_id"    />
    </resultMap>

    <sql id="selectSysRoleAuditflowVo">
        select role_id, auditflow_id from sys_role_auditflow
    </sql>

    <select id="selectSysRoleAuditflowList" parameterType="SysRoleAuditflow" resultMap="SysRoleAuditflowResult">
        <include refid="selectSysRoleAuditflowVo"/>
        <where>  
            <if test="roleId != null "> and role_id = #{roleId}</if>
            <if test="auditflowId != null  and auditflowId != ''"> and auditflow_id = #{auditflowId}</if>
        </where>
    </select>
    
    <select id="selectSysRoleAuditflowByRoleId" parameterType="Long" resultMap="SysRoleAuditflowResult">
        <include refid="selectSysRoleAuditflowVo"/>
        where role_id = #{roleId}
    </select>

    <insert id="insertSysRoleAuditflow" parameterType="SysRoleAuditflow">
        insert into sys_role_auditflow
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="roleId != null">role_id,</if>
            <if test="auditflowId != null and auditflowId != ''">auditflow_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="roleId != null">#{roleId},</if>
            <if test="auditflowId != null and auditflowId != ''">#{auditflowId},</if>
         </trim>
    </insert>

    <update id="updateSysRoleAuditflow" parameterType="SysRoleAuditflow">
        update sys_role_auditflow
        <trim prefix="SET" suffixOverrides=",">
            <if test="auditflowId != null and auditflowId != ''">auditflow_id = #{auditflowId},</if>
        </trim>
        where role_id = #{roleId}
    </update>

    <delete id="deleteSysRoleAuditflowByRoleId" parameterType="Long">
        delete from sys_role_auditflow where role_id = #{roleId}
    </delete>

    <delete id="deleteSysRoleAuditflowByRoleIds" parameterType="String">
        delete from sys_role_auditflow where role_id in 
        <foreach item="roleId" collection="array" open="(" separator="," close=")">
            #{roleId}
        </foreach>
    </delete>

    <delete id="deleteRoleAuditflowByRoleId" parameterType="Long">
        delete from sys_role_auditflow where role_id=#{roleId}
    </delete>

    <delete id="deleteRoleAuditflow" parameterType="Long">
        delete from sys_role_auditflow where role_id in
        <foreach collection="array" item="roleId" open="(" separator="," close=")">
            #{roleId}
        </foreach>
    </delete>

    <insert id="batchRoleAuditflow">
        insert into sys_role_auditflow(role_id, auditflow_id) values
        <foreach item="item" index="index" collection="list" separator=",">
            (#{item.roleId},#{item.auditflowId})
        </foreach>
    </insert>
</mapper>