<?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.gic.haoban.manage.service.dao.mapper.TabHaobanTemplateApplicationRelatedMapper" >
  <resultMap id="BaseResultMap" type="com.gic.haoban.manage.service.entity.TabHaobanTemplateApplicationRelated" >
    <id column="template_application_related_id" property="templateApplicationRelatedId" jdbcType="VARCHAR" />
    <result column="application_id" property="applicationId" jdbcType="VARCHAR" />
    <result column="template_id" property="templateId" jdbcType="VARCHAR" />
    <result column="status_flag" property="statusFlag" jdbcType="INTEGER" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
  </resultMap>
  <sql id="Base_Column_List" >
    template_application_related_id, application_id, template_id, status_flag, create_time, 
    update_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from tab_haoban_template_application_related
    where template_application_related_id = #{templateApplicationRelatedId,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
    delete from tab_haoban_template_application_related
    where template_application_related_id = #{templateApplicationRelatedId,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.gic.haoban.manage.service.entity.TabHaobanTemplateApplicationRelated" >
    insert into tab_haoban_template_application_related (template_application_related_id, application_id, 
      template_id, status_flag, create_time, 
      update_time)
    values (#{templateApplicationRelatedId,jdbcType=VARCHAR}, #{applicationId,jdbcType=VARCHAR}, 
      #{templateId,jdbcType=VARCHAR}, #{statusFlag,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, 
      #{updateTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.gic.haoban.manage.service.entity.TabHaobanTemplateApplicationRelated" >
    insert into tab_haoban_template_application_related
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="templateApplicationRelatedId != null" >
        template_application_related_id,
      </if>
      <if test="applicationId != null" >
        application_id,
      </if>
      <if test="templateId != null" >
        template_id,
      </if>
      <if test="statusFlag != null" >
        status_flag,
      </if>
      <if test="createTime != null" >
        create_time,
      </if>
      <if test="updateTime != null" >
        update_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="templateApplicationRelatedId != null" >
        #{templateApplicationRelatedId,jdbcType=VARCHAR},
      </if>
      <if test="applicationId != null" >
        #{applicationId,jdbcType=VARCHAR},
      </if>
      <if test="templateId != null" >
        #{templateId,jdbcType=VARCHAR},
      </if>
      <if test="statusFlag != null" >
        #{statusFlag,jdbcType=INTEGER},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null" >
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.gic.haoban.manage.service.entity.TabHaobanTemplateApplicationRelated" >
    update tab_haoban_template_application_related
    <set >
      <if test="applicationId != null" >
        application_id = #{applicationId,jdbcType=VARCHAR},
      </if>
      <if test="templateId != null" >
        template_id = #{templateId,jdbcType=VARCHAR},
      </if>
      <if test="statusFlag != null" >
        status_flag = #{statusFlag,jdbcType=INTEGER},
      </if>
      <if test="createTime != null" >
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null" >
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where template_application_related_id = #{templateApplicationRelatedId,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.gic.haoban.manage.service.entity.TabHaobanTemplateApplicationRelated" >
    update tab_haoban_template_application_related
    set application_id = #{applicationId,jdbcType=VARCHAR},
      template_id = #{templateId,jdbcType=VARCHAR},
      status_flag = #{statusFlag,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP}
    where template_application_related_id = #{templateApplicationRelatedId,jdbcType=VARCHAR}
  </update>
  
  <select id="listTemplicationApplicationByTemplateId" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from tab_haoban_template_application_related
    where template_id = #{applicationTemplateId,jdbcType=VARCHAR}
    and status_flag = 1
  </select>
  
  <select id="selectByTemplateIdAndApplicationId" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from tab_haoban_template_application_related
    where template_id = #{applicationTemplateId,jdbcType=VARCHAR}
    and application_id = #{applicationId}
    and status_flag = 1
  </select>


  <select id="listMenuCodesByTemplateId" resultType="java.lang.String" parameterType="java.lang.String" >
    SELECT
      b.menu_code
    FROM
      tab_haoban_template_application_related a
        LEFT JOIN tab_haoban_application b ON a.application_id = b.application_id
    WHERE
      a.template_id = #{templateId}
      AND a.status_flag = 1
      AND b.status_flag = 1
      AND b.menu_code IS NOT NULL;
  </select>
</mapper>