<?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.recordType.Emr_TypeMapper" >
  <resultMap id="BaseResultMap" type="com.emr.entity.recordType.Emr_Type" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="type_flag" property="typeFlag" jdbcType="VARCHAR" />
    <result column="type_name" property="typeName" jdbcType="VARCHAR" />
    <result column="select_flag" property="selectFlag" jdbcType="INTEGER" />
    <result column="effective" property="effective" jdbcType="INTEGER" />
    <result column="type_sort" property="typeSort" jdbcType="INTEGER" />
    <result column="creater" property="creater" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="NCHAR" />
    <result column="updater" property="updater" jdbcType="VARCHAR" />
    <result column="update_time" property="updateTime" jdbcType="NCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, type_flag, type_name, select_flag, effective, type_sort, creater, create_time, 
    updater, update_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from emr_type
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from emr_type
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.emr.entity.recordType.Emr_Type" useGeneratedKeys="true" keyProperty="id">
    insert into emr_type (type_flag, type_name,
      select_flag, effective, type_sort, 
      creater, create_time, updater, 
      update_time)
    values (#{typeFlag,jdbcType=NVARCHAR}, #{typeName,jdbcType=NVARCHAR},
      #{selectFlag,jdbcType=INTEGER}, #{effective,jdbcType=INTEGER}, #{typeSort,jdbcType=INTEGER}, 
      #{creater,jdbcType=NVARCHAR}, #{createTime,jdbcType=NCHAR}, #{updater,jdbcType=NVARCHAR}, 
      #{updateTime,jdbcType=NCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.emr.entity.recordType.Emr_Type" >
    insert into emr_type
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="typeFlag != null" >
        type_flag,
      </if>
      <if test="typeName != null" >
        type_name,
      </if>
      <if test="selectFlag != null" >
        select_flag,
      </if>
      <if test="effective != null" >
        effective,
      </if>
      <if test="typeSort != null" >
        type_sort,
      </if>
      <if test="creater != null" >
        creater,
      </if>
      <if test="createTime != null" >
        create_time,
      </if>
      <if test="updater != null" >
        updater,
      </if>
      <if test="updateTime != null" >
        update_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="typeFlag != null" >
        #{typeFlag,jdbcType=NVARCHAR},
      </if>
      <if test="typeName != null" >
        #{typeName,jdbcType=NVARCHAR},
      </if>
      <if test="selectFlag != null" >
        #{selectFlag,jdbcType=INTEGER},
      </if>
      <if test="effective != null" >
        #{effective,jdbcType=INTEGER},
      </if>
      <if test="typeSort != null" >
        #{typeSort,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="updateTime != null" >
        #{updateTime,jdbcType=NCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.emr.entity.recordType.Emr_Type" >
    update emr_type
    <set >
      <if test="typeFlag != null" >
        type_flag = #{typeFlag,jdbcType=NVARCHAR},
      </if>
      <if test="typeName != null" >
        type_name = #{typeName,jdbcType=NVARCHAR},
      </if>
      <if test="selectFlag != null" >
        select_flag = #{selectFlag,jdbcType=INTEGER},
      </if>
      <if test="effective != null" >
        effective = #{effective,jdbcType=INTEGER},
      </if>
      <if test="typeSort != null" >
        type_sort = #{typeSort,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="updateTime != null" >
        update_time = #{updateTime,jdbcType=NCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.emr.entity.recordType.Emr_Type" >
    update emr_type
    set type_flag = #{typeFlag,jdbcType=NVARCHAR},
      type_name = #{typeName,jdbcType=NVARCHAR},
      select_flag = #{selectFlag,jdbcType=INTEGER},
      effective = #{effective,jdbcType=INTEGER},
      type_sort = #{typeSort,jdbcType=INTEGER},
      creater = #{creater,jdbcType=NVARCHAR},
      create_time = #{createTime,jdbcType=NCHAR},
      updater = #{updater,jdbcType=NVARCHAR},
      update_time = #{updateTime,jdbcType=NCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <!--根据创建用户查询默认选中对象-->
  <select id="selectFlagExist" resultType="com.emr.entity.recordType.Emr_Type" parameterType="java.lang.String" >
    SELECT
        TOP 1 *
    FROM
        emr_type
    WHERE
        select_flag = 1
        <if test="creater != null">
            AND creater = #{creater}
        </if>
  </select>
  <!--根据创建用户查询打印类别集合-->
  <select id="selectAllByCreater" resultMap="BaseResultMap" parameterType="java.lang.String" >
    SELECT
        *
    FROM
        emr_type
    <where>
      <if test="creater != null">
        creater IN (${creater})
      </if>
      <if test="isEffective != null">
        AND effective = 1
      </if>
    </where>
    ORDER BY
        select_flag desc,type_sort desc
  </select>
  <!--验证该用户创建的类别标识是否存在-->
  <select id="checkTypeNameByCreater" resultType="com.emr.entity.recordType.Emr_Type" parameterType="java.lang.String">
        SELECT
           id
        FROM
            emr_type
        WHERE
            creater = #{creater}
        AND
            type_name = #{typeName}
  </select>
  <!--验证该用户创建的类别名称是否存在-->
  <select id="checkTypeFlagByCreater" resultType="com.emr.entity.recordType.Emr_Type" parameterType="java.lang.String">
        SELECT
           id
        FROM
            emr_type
        <where>
            <if test="creater != null and creater != ''">
                creater = #{creater}
            </if>
            AND
            type_flag = #{typeFlag}
        </where>
  </select>
</mapper>