<?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.emrUserReader.Emr_User_ReaderMapper" >
  <resultMap id="BaseResultMap" type="com.emr.entity.emrUserReader.Emr_User_Reader" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="user_id" property="userId" jdbcType="INTEGER" />
    <result column="role_id" property="roleId" jdbcType="INTEGER" />
    <result column="record_id" property="recordId" jdbcType="NVARCHAR" />
    <result column="flag" property="flag" jdbcType="INTEGER" />
    <result column="creater" property="creater" jdbcType="NVARCHAR" />
    <result column="create_time" property="createTime" jdbcType="NCHAR" />
    <result column="updater" property="updater" jdbcType="NVARCHAR" />
    <result column="update_time" property="updateTime" jdbcType="NCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, user_id,role_id, record_id, flag, creater, create_time, updater, update_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from emr_user_reader
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from emr_user_reader
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.emr.entity.emrUserReader.Emr_User_Reader" >
    insert into emr_user_reader (user_id,role_id, record_id,
      flag, creater, create_time, 
      updater, update_time)
    values (#{userId,jdbcType=INTEGER}, #{roleId,jdbcType=INTEGER}, #{recordId,jdbcType=NVARCHAR},
      #{flag,jdbcType=INTEGER}, #{creater,jdbcType=NVARCHAR}, #{createTime,jdbcType=NCHAR}, 
      #{updater,jdbcType=NVARCHAR}, #{updateTime,jdbcType=NCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.emr.entity.emrUserReader.Emr_User_Reader" >
    insert into emr_user_reader
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="userId != null" >
        user_id,
      </if>
      <if test="roleId != null" >
        role_id,
      </if>
      <if test="recordId != null" >
        record_id,
      </if>
      <if test="flag != null" >
        flag,
      </if>
      <if test="creater != null" >
        creater,
      </if>
      <if test="createTime != null" >
        create_time,
      </if>
      <if test="updater != null" >
        updater,
      </if>
      <if test="upateTime != null" >
        upate_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="userId != null" >
        #{userId,jdbcType=INTEGER},
      </if>
      <if test="roleId != null" >
        #{roleId,jdbcType=INTEGER},
      </if>
      <if test="recordId != null" >
        #{recordId,jdbcType=NVARCHAR},
      </if>
      <if test="flag != null" >
        #{flag,jdbcType=INTEGER},
      </if>
      <if test="creater != null" >
        #{creater,jdbcType=NVARCHAR},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=NCHAR},
      </if>
      <if test="updater != null" >
        #{updater,jdbcType=NVARCHAR},
      </if>
      <if test="upateTime != null" >
        #{upateTime,jdbcType=NCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.emr.entity.emrUserReader.Emr_User_Reader" >
    update emr_user_reader
    <set >
      <if test="userId != null" >
        user_id = #{userId,jdbcType=INTEGER},
      </if>
      <if test="roleId != null" >
        role_id = #{roleId,jdbcType=INTEGER},
      </if>
      <if test="recordId != null" >
        record_id = #{recordId,jdbcType=NVARCHAR},
      </if>
      <if test="flag != null" >
        flag = #{flag,jdbcType=INTEGER},
      </if>
      <if test="creater != null" >
        creater = #{creater,jdbcType=NVARCHAR},
      </if>
      <if test="createTime != null" >
        create_time = #{createTime,jdbcType=NCHAR},
      </if>
      <if test="updater != null" >
        updater = #{updater,jdbcType=NVARCHAR},
      </if>
      <if test="upateTime != null" >
        upate_time = #{upateTime,jdbcType=NCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.emr.entity.emrUserReader.Emr_User_Reader" >
    update emr_user_reader
    set user_id = #{userId,jdbcType=INTEGER},
      role_id = #{roleId,jdbcType=INTEGER},
      record_id = #{recordId,jdbcType=NVARCHAR},
      flag = #{flag,jdbcType=INTEGER},
      creater = #{creater,jdbcType=NVARCHAR},
      create_time = #{createTime,jdbcType=NCHAR},
      updater = #{updater,jdbcType=NVARCHAR},
      upate_time = #{upateTime,jdbcType=NCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <!--根据用户id删除-->
  <delete id="deleteReaderByUserId" parameterType="java.lang.Integer">
    DELETE FROM
        emr_user_reader
    WHERE
        user_id = ${userId}
  </delete>
  <insert id="SimpleInsert" parameterType="java.util.List">
      INSERT INTO
          emr_user_reader(
              user_id,role_id, record_id,flag, creater, create_time,updater, update_time
          )
          <foreach collection="list" item="item" separator="union">
            select
            #{item.userId,jdbcType=INTEGER}, #{item.roleId,jdbcType=INTEGER}, #{item.recordId,jdbcType=NVARCHAR},
            #{item.flag,jdbcType=INTEGER}, #{item.creater,jdbcType=NVARCHAR}, #{item.createTime,jdbcType=NCHAR},
            #{item.updater,jdbcType=NVARCHAR}, #{item.updateTime,jdbcType=NCHAR}
          </foreach>
  </insert>
</mapper>