<?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.pcloud.book.applet.mapper.AppletUserLabelRelationMapper" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.applet.entity.AppletUserLabelRelation" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="applet_user_label_id" property="appletUserLabelId" jdbcType="BIGINT" />
    <result column="book_label_id" property="bookLabelId" jdbcType="BIGINT" />
    <result column="label_type" property="labelType" jdbcType="INTEGER" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, applet_user_label_id, book_label_id, label_type, create_time, update_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select 
    <include refid="Base_Column_List" />
    from applet_user_label_relation
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
    delete from applet_user_label_relation
    where id = #{id,jdbcType=BIGINT}
  </delete>

  <!-- 删除用户标签与年级标签和科目标签的关联关系-->
  <delete id="deleteByUserLabelId" parameterType="long">
    delete
    from
    applet_user_label_relation
    where
    applet_user_label_id = #{UserLabelId}
  </delete>

  <insert id="insert" parameterType="com.pcloud.book.applet.entity.AppletUserLabelRelation" >
    insert into applet_user_label_relation (id, applet_user_label_id, book_label_id, 
      label_type, create_time, update_time
      )
    values (#{id,jdbcType=BIGINT}, #{appletUserLabelId,jdbcType=BIGINT}, #{bookLabelId,jdbcType=BIGINT}, 
      #{labelType,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.pcloud.book.applet.entity.AppletUserLabelRelation" >
    insert into applet_user_label_relation
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="appletUserLabelId != null" >
        applet_user_label_id,
      </if>
      <if test="bookLabelId != null" >
        book_label_id,
      </if>
      <if test="labelType != null" >
        label_type,
      </if>
      <if test="createTime != null" >
        create_time,
      </if>
      <if test="updateTime != null" >
        update_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=BIGINT},
      </if>
      <if test="appletUserLabelId != null" >
        #{appletUserLabelId,jdbcType=BIGINT},
      </if>
      <if test="bookLabelId != null" >
        #{bookLabelId,jdbcType=BIGINT},
      </if>
      <if test="labelType != null" >
        #{labelType,jdbcType=INTEGER},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null" >
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <insert id="batchInsert" parameterType="com.pcloud.book.applet.entity.AppletUserLabelRelation">
    insert into applet_user_label_relation (applet_user_label_id, book_label_id,
    label_type, create_time, update_time
    )
    values
    <foreach collection="list" item="item" index="index" separator="," >
    (#{item.appletUserLabelId,jdbcType=BIGINT}, #{item.bookLabelId,jdbcType=BIGINT},
    #{item.labelType,jdbcType=INTEGER}, now(),now()
    )
    </foreach>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.pcloud.book.applet.entity.AppletUserLabelRelation" >
    update applet_user_label_relation
    <set >
      <if test="appletUserLabelId != null" >
        applet_user_label_id = #{appletUserLabelId,jdbcType=BIGINT},
      </if>
      <if test="bookLabelId != null" >
        book_label_id = #{bookLabelId,jdbcType=BIGINT},
      </if>
      <if test="labelType != null" >
        label_type = #{labelType,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 id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.pcloud.book.applet.entity.AppletUserLabelRelation" >
    update applet_user_label_relation
    set applet_user_label_id = #{appletUserLabelId,jdbcType=BIGINT},
      book_label_id = #{bookLabelId,jdbcType=BIGINT},
      label_type = #{labelType,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=BIGINT}
  </update>

  <select id="getByAppletUserLabelId" parameterType="long" resultMap="BaseResultMap">
    SELECT <include refid="Base_Column_List"/>
    FROM
    applet_user_label_relation
    WHERE
    applet_user_label_id = #{appletUserLabelId,jdbcType=BIGINT}
  </select>

</mapper>