<?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.templateSearch.Emr_CustomizeMapper" >
  <resultMap id="BaseResultMap" type="com.emr.entity.templateSearch.Emr_Customize" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="column_value" property="columnValue" jdbcType="NVARCHAR" />
    <result column="column_name" property="columnName" jdbcType="NVARCHAR" />
    <result column="column_type" property="columnType" jdbcType="NVARCHAR" />
    <result column="table_value" property="tableValue" jdbcType="NVARCHAR" />
    <result column="table_name" property="tableName" jdbcType="NVARCHAR" />
    <result column="select_value" property="selectValue" jdbcType="NVARCHAR" />
    <result column="effective" property="effective" jdbcType="INTEGER" />
    <result column="parent_id" property="parentId" jdbcType="INTEGER" />
    <result column="customize_sort" property="customizeSort" jdbcType="INTEGER" />
    <result column="remark" property="remark" jdbcType="NVARCHAR" />
    <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, column_value, column_name, column_type, table_value, table_name, select_value, 
    effective, parent_id, customize_sort, remark, creater, create_time, updater, update_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from emr_customize
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from emr_customize
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.emr.entity.templateSearch.Emr_Customize"  useGeneratedKeys="true" keyProperty="id">
    insert into emr_customize (column_value, column_name,
      column_type, table_value, table_name, 
      select_value, effective, parent_id, 
      customize_sort, remark, creater, 
      create_time, updater, update_time
      )
    values (#{columnValue,jdbcType=NVARCHAR}, #{columnName,jdbcType=NVARCHAR},
      #{columnType,jdbcType=NVARCHAR}, #{tableValue,jdbcType=NVARCHAR}, #{tableName,jdbcType=NVARCHAR}, 
      #{selectValue,jdbcType=NVARCHAR}, #{effective,jdbcType=INTEGER}, #{parentId,jdbcType=INTEGER}, 
      #{customizeSort,jdbcType=INTEGER}, #{remark,jdbcType=NVARCHAR}, #{creater,jdbcType=NVARCHAR}, 
      #{createTime,jdbcType=NCHAR}, #{updater,jdbcType=NVARCHAR}, #{updateTime,jdbcType=NCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.emr.entity.templateSearch.Emr_Customize" >
    insert into emr_customize
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="columnValue != null" >
        column_value,
      </if>
      <if test="columnName != null" >
        column_name,
      </if>
      <if test="columnType != null" >
        column_type,
      </if>
      <if test="tableValue != null" >
        table_value,
      </if>
      <if test="tableName != null" >
        table_name,
      </if>
      <if test="selectValue != null" >
        select_value,
      </if>
      <if test="effective != null" >
        effective,
      </if>
      <if test="parentId != null" >
        parent_id,
      </if>
      <if test="customizeSort != null" >
        customize_sort,
      </if>
      <if test="remark != null" >
        remark,
      </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="columnValue != null" >
        #{columnValue,jdbcType=NVARCHAR},
      </if>
      <if test="columnName != null" >
        #{columnName,jdbcType=NVARCHAR},
      </if>
      <if test="columnType != null" >
        #{columnType,jdbcType=NVARCHAR},
      </if>
      <if test="tableValue != null" >
        #{tableValue,jdbcType=NVARCHAR},
      </if>
      <if test="tableName != null" >
        #{tableName,jdbcType=NVARCHAR},
      </if>
      <if test="selectValue != null" >
        #{selectValue,jdbcType=NVARCHAR},
      </if>
      <if test="effective != null" >
        #{effective,jdbcType=INTEGER},
      </if>
      <if test="parentId != null" >
        #{parentId,jdbcType=INTEGER},
      </if>
      <if test="customizeSort != null" >
        #{customizeSort,jdbcType=INTEGER},
      </if>
      <if test="remark != null" >
        #{remark,jdbcType=NVARCHAR},
      </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.templateSearch.Emr_Customize" >
    update emr_customize
    <set >
      <if test="columnValue != null" >
        column_value = #{columnValue,jdbcType=NVARCHAR},
      </if>
      <if test="columnName != null" >
        column_name = #{columnName,jdbcType=NVARCHAR},
      </if>
      <if test="columnType != null" >
        column_type = #{columnType,jdbcType=NVARCHAR},
      </if>
      <if test="tableValue != null" >
        table_value = #{tableValue,jdbcType=NVARCHAR},
      </if>
      <if test="tableName != null" >
        table_name = #{tableName,jdbcType=NVARCHAR},
      </if>
      <if test="selectValue != null" >
        select_value = #{selectValue,jdbcType=NVARCHAR},
      </if>
      <if test="effective != null" >
        effective = #{effective,jdbcType=INTEGER},
      </if>
      <if test="parentId != null" >
        parent_id = #{parentId,jdbcType=INTEGER},
      </if>
      <if test="customizeSort != null" >
        customize_sort = #{customizeSort,jdbcType=INTEGER},
      </if>
      <if test="remark != null" >
        remark = #{remark,jdbcType=NVARCHAR},
      </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.templateSearch.Emr_Customize" >
    update emr_customize
    set column_value = #{columnValue,jdbcType=NVARCHAR},
      column_name = #{columnName,jdbcType=NVARCHAR},
      column_type = #{columnType,jdbcType=NVARCHAR},
      table_value = #{tableValue,jdbcType=NVARCHAR},
      table_name = #{tableName,jdbcType=NVARCHAR},
      select_value = #{selectValue,jdbcType=NVARCHAR},
      effective = #{effective,jdbcType=INTEGER},
      parent_id = #{parentId,jdbcType=INTEGER},
      customize_sort = #{customizeSort,jdbcType=INTEGER},
      remark = #{remark,jdbcType=NVARCHAR},
      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="selectListCheckName" resultType="java.lang.Integer">
    SELECT
        id
    FROM
        emr_customize
    WHERE
        parent_id = ${parentId}
    AND
        column_name = #{columnName}
  </select>
  <!--验证字段值+表名是否重复-->
  <select id="checkColumnExist" resultType="java.lang.Integer">
    SELECT
        id
    FROM
        emr_customize
    WHERE
        column_value = #{columnValue}
    AND
        table_value = #{tableValue}
  </select>
  <!--组织模板树-->
  <select id="selectAllByTree" resultMap="BaseResultMap">
    SELECT
        id,
        column_value,
        column_name,
        column_type,
        table_value,
        table_name,
        select_value,
        effective,
        parent_id,
        parent_id selfParentId,
        customize_sort,
        remark,
        column_name newName
    FROM
        emr_customize
    ORDER BY
        customize_sort desc
  </select>
  <!--全查只查询有效-->
  <select id="selectAll" resultMap="BaseResultMap">
    SELECT
        id,
        column_value,
        column_name,
        column_type,
        table_value,
        table_name,
        select_value,
        effective,
        parent_id,
        customize_sort,
        remark,
        column_name newName
    FROM
        emr_customize
    WHERE
        effective = 1
    ORDER BY
        customize_sort desc
  </select>
  <!--全查分类-->
  <select id="selectParents" resultMap="BaseResultMap">
    SELECT
        id,
        column_name
    FROM
        emr_customize
    WHERE
        parent_id = 0
    AND
      effective = 1
  </select>
</mapper>