<?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.FormPermMapper">
    <sql id="formPermSql">
        select id, deployment_id, from_key, required, perm
        from wk_re_form_perm
    </sql>

    <insert id="batchInsert">
        insert into wk_re_form_perm
        (id,deployment_id,from_key,required,perm)
        values
        <foreach collection="list" separator="," item="item">
            (#{item.id},
            #{item.deploymentId},
            #{item.fromKey},
            #{item.required},
            #{item.perm})
        </foreach>
    </insert>

    <select id="selectListByFormKeyAndDeploymentId" resultType="cn.fateverse.workflow.entity.FormPerm">
        <include refid="formPermSql"/>
        <where>
            <if test="fromKey != null and fromKey != ''"> and from_key = #{fromKey}</if>
            <if test="deploymentId != null and deploymentId != ''"> and deployment_id = #{deploymentId}</if>
        </where>
    </select>
    <select id="selectListByFormKeyListAndDeploymentId"
            resultType="cn.fateverse.workflow.entity.FormPerm">
        <include refid="formPermSql"/>
        where deployment_id = #{deploymentId} and from_key in
        <foreach collection="fromKeys" item="fromKey" open="(" separator="," close=")" index="index">
            #{fromKey}
        </foreach>
    </select>

</mapper>
