<?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.emr.dao.emrRoleReader.Emr_Role_ReaderMapper" >
  <resultMap id="BaseResultMap" type="com.emr.entity.emrRoleReader.Emr_Role_Reader" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="role_id" property="roleId" jdbcType="INTEGER" />
    <result column="record_id" property="recordId" jdbcType="NVARCHAR" />
    <result column="creater" property="creater" jdbcType="NVARCHAR" />
    <result column="create_time" property="createTime" jdbcType="NCHAR" />
    <result column="upater" property="upater" jdbcType="NVARCHAR" />
    <result column="update_time" property="updateTime" jdbcType="NCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, role_id, record_id, creater, create_time, upater, update_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from emr_role_reader
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from emr_role_reader
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.emr.entity.emrRoleReader.Emr_Role_Reader" >
    insert into emr_role_reader (role_id, record_id,
      creater, create_time, upater, 
      update_time)
    values (#{roleId,jdbcType=INTEGER}, #{recordId,jdbcType=NVARCHAR},
      #{creater,jdbcType=NVARCHAR}, #{createTime,jdbcType=NCHAR}, #{upater,jdbcType=NVARCHAR}, 
      #{updateTime,jdbcType=NCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.emr.entity.emrRoleReader.Emr_Role_Reader" >
    insert into emr_role_reader
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="roleId != null" >
        role_id,
      </if>
      <if test="recordId != null" >
        record_id,
      </if>
      <if test="creater != null" >
        creater,
      </if>
      <if test="createTime != null" >
        create_time,
      </if>
      <if test="upater != null" >
        upater,
      </if>
      <if test="updateTime != null" >
        update_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="roleId != null" >
        #{roleId,jdbcType=INTEGER},
      </if>
      <if test="recordId != null" >
        #{recordId,jdbcType=NVARCHAR},
      </if>
      <if test="creater != null" >
        #{creater,jdbcType=NVARCHAR},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=NCHAR},
      </if>
      <if test="upater != null" >
        #{upater,jdbcType=NVARCHAR},
      </if>
      <if test="updateTime != null" >
        #{updateTime,jdbcType=NCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.emr.entity.emrRoleReader.Emr_Role_Reader" >
    update emr_role_reader
    <set >
      <if test="roleId != null" >
        role_id = #{roleId,jdbcType=INTEGER},
      </if>
      <if test="recordId != null" >
        record_id = #{recordId,jdbcType=NVARCHAR},
      </if>
      <if test="creater != null" >
        creater = #{creater,jdbcType=NVARCHAR},
      </if>
      <if test="createTime != null" >
        create_time = #{createTime,jdbcType=NCHAR},
      </if>
      <if test="upater != null" >
        upater = #{upater,jdbcType=NVARCHAR},
      </if>
      <if test="updateTime != null" >
        update_time = #{updateTime,jdbcType=NCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.emr.entity.emrRoleReader.Emr_Role_Reader" >
    update emr_role_reader
    set role_id = #{roleId,jdbcType=INTEGER},
      record_id = #{recordId,jdbcType=NVARCHAR},
      creater = #{creater,jdbcType=NVARCHAR},
      create_time = #{createTime,jdbcType=NCHAR},
      upater = #{upater,jdbcType=NVARCHAR},
      update_time = #{updateTime,jdbcType=NCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <!--根据角色id删除-->
  <delete id="deleteReaderByRoleId" parameterType="java.lang.Integer">
    DELETE FROM
        emr_role_reader
    WHERE
        role_id = ${roleId}
  </delete>
  <!--根据角色id查询全部-->
  <select id="selectAllByRoleId" resultMap="BaseResultMap" parameterType="java.lang.Integer">
    SELECT
        *
    FROM
        emr_role_reader
    WHERE
        role_id = ${roleId}
  </select>
  <insert id="SimpleInsert" parameterType="java.util.List">
      INSERT INTO
         emr_role_reader(
            role_id, record_id,creater, create_time, upater,update_time
         )
        <foreach collection="list" item="item" separator="union">
          select
            #{item.roleId,jdbcType=INTEGER}, #{item.recordId,jdbcType=NVARCHAR},
            #{item.creater,jdbcType=NVARCHAR}, #{item.createTime,jdbcType=NCHAR}, #{item.upater,jdbcType=NVARCHAR},
            #{item.updateTime,jdbcType=NCHAR}
        </foreach>
  </insert>
</mapper>