<?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.ydd.oms.mapper.sys.AdminRoleMapper">
  <resultMap id="BaseResultMap" type="com.ydd.oms.entity.sys.AdminRole">
    <id column="admin_id" jdbcType="INTEGER" property="adminId" />
    <id column="role_id" jdbcType="INTEGER" property="roleId" />
  </resultMap>
  <delete id="deleteByPrimaryKey" parameterType="com.ydd.oms.entity.sys.AdminRole">
    delete from sys_admin_role
    where admin_id = #{adminId,jdbcType=INTEGER}
      and role_id = #{roleId,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.ydd.oms.entity.sys.AdminRole">
    insert into sys_admin_role (admin_id, role_id)
    values (#{adminId,jdbcType=INTEGER}, #{roleId,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="com.ydd.oms.entity.sys.AdminRole">
    insert into sys_admin_role
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="adminId != null">
        admin_id,
      </if>
      <if test="roleId != null">
        role_id,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="adminId != null">
        #{adminId,jdbcType=INTEGER},
      </if>
      <if test="roleId != null">
        #{roleId,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>

  <!--根据管理员编号删除-->
  <delete id="deleteByAdminId">
    DELETE FROM
      sys_admin_role
    WHERE
      admin_id = #{adminId, jdbcType=INTEGER}
  </delete>

  <!--保存角色-->
  <insert id="saveRoles">
    INSERT INTO
      sys_admin_role (admin_id, role_id)
    VALUES
    <foreach collection="roleIds" item="roleId" separator=",">
      (#{adminId, jdbcType=INTEGER}, #{roleId, jdbcType=INTEGER})
    </foreach>
  </insert>

</mapper>