<?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.goafanti.common.dao.RolePermissionMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.RolePermission">
    <result column="rid" jdbcType="VARCHAR" property="rid" />
    <result column="pid" jdbcType="VARCHAR" property="pid" />
  </resultMap>
  <insert id="insert" parameterType="com.goafanti.common.model.RolePermission">
    insert into role_permission (rid, pid)
    values (#{rid,jdbcType=VARCHAR}, #{pid,jdbcType=VARCHAR})
    ON DUPLICATE KEY UPDATE
    pid = values(pid)
  </insert>
  <delete id="deleteByPermissionId" parameterType="java.lang.String">
    delete from role_permission
    where pid in 
    <foreach item="item" index="index" collection="list" open="(" separator="," close=")">  
	  #{item,jdbcType=VARCHAR}  
    </foreach>
  </delete>
  <delete id="deleteByRoleId" parameterType="java.lang.String">
    delete from role_permission
    where rid in 
    <foreach item="item" index="index" collection="list" open="(" separator="," close=")">  
	  #{item,jdbcType=VARCHAR}  
    </foreach>
  </delete>
  <delete id="deleteByRid" parameterType="java.lang.String">
    delete from role_permission
    where rid = #{roleId, jdbcType=VARCHAR}
  </delete>
  <delete id="deleteByPrimaryKey">
    delete from role_permission
    where rid = #{rid,jdbcType=VARCHAR} and pid = #{pid,jdbcType=VARCHAR}
  </delete>
  
  <insert id="insertBatch" parameterType="com.goafanti.common.model.RolePermission">
    insert into role_permission (rid, pid)
    values 
    <foreach item="item" index="index" collection="list" separator=",">
      (#{item.rid,jdbcType=VARCHAR}, #{item.pid,jdbcType=VARCHAR})
    </foreach>
    ON DUPLICATE KEY UPDATE
	    pid = values(pid)
  </insert>
</mapper>