<?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.xhpc.activity.mapper.XhpcActivityTemplateMapper">
  <resultMap id="BaseResultMap" type="com.xhpc.activity.domain.XhpcActivityTemplateDomain">
    <id column="activity_template_id" jdbcType="INTEGER" property="activityTemplateId" />
    <result column="template_name" jdbcType="VARCHAR" property="templateName" />
    <result column="discount_type" jdbcType="SMALLINT" property="discountType" />
    <result column="discount_rate" jdbcType="DECIMAL" property="discountRate" />
    <result column="start_time" jdbcType="TIMESTAMP" property="startTime" />
    <result column="end_time" jdbcType="TIMESTAMP" property="endTime" />
    <result column="discount_count" jdbcType="SMALLINT" property="discountCount" />
    <result column="mini_display" jdbcType="SMALLINT" property="miniDisplay" />
    <result column="background_url" jdbcType="VARCHAR" property="backgroundUrl" />
    <result column="status" jdbcType="SMALLINT" property="status" />
    <result column="del_flag" jdbcType="SMALLINT" property="delFlag" />
    <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" />
    <result column="create_by" jdbcType="VARCHAR" property="createBy" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_by" jdbcType="VARCHAR" property="updateBy" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="applet_activity_name" jdbcType="VARCHAR" property="appletActivityName" />
  </resultMap>
  <sql id="Base_Column_List">
    activity_template_id, template_name, discount_type, discount_rate, start_time, end_time,
    discount_count, mini_display, background_url, `status`, del_flag, tenant_id, create_by,
    create_time, update_by, update_time,applet_activity_name
  </sql>


  <select id="selectByParams" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from xhpc_activity_template
    where del_flag=0
    <if test="params.tenantId!= null and params.tenantId!=''">
      and tenant_id=#{params.tenantId}
    </if>
    <if test="params.status!=null and params.status !=''">
      and status=#{params.status}
    </if>
    order by status asc, create_time desc
  </select>


  <select id="selectNameMapList" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    activity_temlpate_id as 'activityTemplateId',
           template_name as 'templateName'
    from xhpc_activity_template
    where del_flag=0 and status=1
    <if test="params.tenantId!= null and params.tenantId!=''">
      and tenant_id=#{params.tenantId}
    </if>
  </select>



  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from xhpc_activity_template
    where activity_template_id = #{activityTemplateId}
  </select>


  <update id="deleteLogicByPrimaryKey" parameterType="java.lang.Integer">
    update xhpc_activity_template set del_flag=2
    where activity_template_id = #{activityTemplateId}
  </update>


  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from xhpc_activity_template
    where activity_template_id = #{activityTemplateId}
  </delete>


  <insert id="insert" keyColumn="activity_temlpate_id" keyProperty="activityTemplateId" parameterType="com.xhpc.activity.domain.XhpcActivityTemplateDomain" useGeneratedKeys="true">
    insert into xhpc_activity_template (template_name, discount_type, discount_rate, 
      start_time, end_time, discount_count, 
      mini_display, background_url, `status`,
      del_flag, tenant_id, create_by, 
      create_time, update_by, update_time,applet_activity_name
      )
    values (#{templateName,jdbcType=VARCHAR}, #{discountType,jdbcType=SMALLINT}, #{discountRate,jdbcType=DECIMAL}, 
      #{startTime,jdbcType=TIMESTAMP}, #{endTime,jdbcType=TIMESTAMP}, #{discountCount,jdbcType=SMALLINT}, 
      #{miniDisplay,jdbcType=SMALLINT}, #{backgroundUrl,jdbcType=VARCHAR}, #{status,jdbcType=SMALLINT},
      0, #{tenantId,jdbcType=VARCHAR}, #{createBy,jdbcType=VARCHAR},
      sysdate(), #{updateBy,jdbcType=VARCHAR}, sysdate(),#{appletActivityName,jdbcType=VARCHAR}
      )
  </insert>


  <update id="updateByPrimaryKey" parameterType="com.xhpc.activity.domain.XhpcActivityTemplateDomain">
    update xhpc_activity_template
    set template_name = #{templateName,jdbcType=VARCHAR},
      discount_type = #{discountType,jdbcType=SMALLINT},
      discount_rate = #{discountRate,jdbcType=DECIMAL},
      start_time = #{startTime,jdbcType=TIMESTAMP},
      end_time = #{endTime,jdbcType=TIMESTAMP},
      discount_count = #{discountCount,jdbcType=SMALLINT},
      mini_display = #{miniDisplay,jdbcType=SMALLINT},
        background_url = #{backgroundUrl,jdbcType=VARCHAR},
      `status` = #{status,jdbcType=SMALLINT},
      tenant_id = #{tenantId,jdbcType=VARCHAR},
      update_by = #{updateBy,jdbcType=VARCHAR},
      update_time = sysdate(),
      applet_activity_name=#{appletActivityName,jdbcType=VARCHAR}
    where activity_template_id = #{activityTemplateId}
  </update>


  <update id="updateStatusByPrimaryKey" parameterType="com.xhpc.activity.domain.XhpcActivityTemplateDomain">
    update xhpc_activity_template
    set `status` = #{status,jdbcType=SMALLINT},
        update_by = #{updateBy,jdbcType=VARCHAR},
        update_time = sysdate()
    where activity_template_id = #{activityTemplateId}
  </update>

</mapper>