<?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_Modle_RelatedMapper" >
  <resultMap id="BaseResultMap" type="com.emr.entity.templateSearch.Emr_Modle_Related" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="modle_id" property="modleId" jdbcType="INTEGER" />
    <result column="customize_id" property="customizeId" 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>
  <resultMap id="BaseResultMap1" type="com.emr.vo.templateSearch.Emr_Modle_RelatedVo" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="modle_id" property="modleId" jdbcType="INTEGER" />
    <result column="customize_id" property="customizeId" 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" />

  </resultMap>
  <sql id="Base_Column_List" >
    id, modle_id, customize_id, creater, create_time, updater, update_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from emr_modle_related
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from emr_modle_related
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.emr.entity.templateSearch.Emr_Modle_Related" >
    insert into emr_modle_related (modle_id, customize_id,
      creater, create_time, updater, 
      update_time)
    values (#{modleId,jdbcType=INTEGER}, #{customizeId,jdbcType=INTEGER},
      #{creater,jdbcType=NVARCHAR}, #{createTime,jdbcType=NCHAR}, #{updater,jdbcType=NVARCHAR}, 
      #{updateTime,jdbcType=NCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.emr.entity.templateSearch.Emr_Modle_Related" >
    insert into emr_modle_related
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="modleId != null" >
        modle_id,
      </if>
      <if test="customizeId != null" >
        customize_id,
      </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="modleId != null" >
        #{modleId,jdbcType=INTEGER},
      </if>
      <if test="customizeId != null" >
        #{customizeId,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.templateSearch.Emr_Modle_Related" >
    update emr_modle_related
    <set >
      <if test="modleId != null" >
        modle_id = #{modleId,jdbcType=INTEGER},
      </if>
      <if test="customizeId != null" >
        customize_id = #{customizeId,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.templateSearch.Emr_Modle_Related" >
    update emr_modle_related
    set modle_id = #{modleId,jdbcType=INTEGER},
      customize_id = #{customizeId,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>
  <!--按模板id查询集合-->
  <select id="selectAllByModleId" resultMap="BaseResultMap1" parameterType="java.lang.Integer" >
    SELECT
        dbo.emr_modle_related.id,
        dbo.emr_modle_related.modle_id,
        dbo.emr_modle_related.customize_id,
        dbo.emr_customize.column_value,
        dbo.emr_customize.column_type,
        dbo.emr_customize.column_name,
        dbo.emr_customize.table_value,
        (dbo.emr_customize.table_value + '.' + dbo.emr_customize.column_value) name
    FROM
        dbo.emr_customize
    INNER JOIN
        dbo.emr_modle_related
    ON
        dbo.emr_customize.id = dbo.emr_modle_related.customize_id
    WHERE
        dbo.emr_modle_related.modle_id = ${modleId}
  </select>
  <!--按字段id删除集合-->
  <delete id="deleteByCustomizeId" parameterType="java.lang.Integer" >
    DELETE FROM
        emr_modle_related
    WHERE
        customize_id = ${customizeId}
  </delete>
  <!--按模板id删除集合-->
  <delete id="deleteByModleId" parameterType="java.lang.Integer" >
    DELETE FROM
        emr_modle_related
    WHERE
        modle_id = ${modleId}
  </delete>
  <!--批量插入-->
  <insert id="SimpleInsert" parameterType="java.util.List">
    INSERT INTO emr_modle_related(
        modle_id, customize_id, creater, create_time, updater, update_time
    )
    VALUES
    <foreach collection ="list" item="item" index= "index" separator =",">
      (
      #{item.modleId,jdbcType=INTEGER}, #{item.customizeId,jdbcType=INTEGER},
      #{item.creater,jdbcType=NVARCHAR}, #{item.createTime,jdbcType=NCHAR}, #{item.updater,jdbcType=NVARCHAR},
      #{item.updateTime,jdbcType=NCHAR}
      )
    </foreach >
  </insert>
</mapper>