<?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.personal.mapper.PcloudLabelMapper" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.personal.entity.PcloudLabel" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="label_name" property="labelName" jdbcType="VARCHAR" />
    <result column="label_type" property="labelType" jdbcType="TINYINT" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
  </resultMap>


  <resultMap id="labelGroupMap" type="com.pcloud.book.personal.dto.PcloudLabelGroupDto">
    <result column="pcloud_label_type" property="pcloudLabelType" jdbcType="TINYINT"/>
    <result column="pcloud_label_type_name" property="pcloudLabelTypeName" jdbcType="VARCHAR"/>
    <collection property="pcloudUserLabelDtos" ofType="com.pcloud.book.personal.dto.PcloudUserLabelDto">
      <id column="id" property="id" jdbcType="BIGINT"/>
      <result column="label_name" property="pcloudLabelName" jdbcType="VARCHAR"/>
      <result column="label_type" property="pcloudLabelType" jdbcType="TINYINT"/>
    </collection>
  </resultMap>
  <sql id="Base_Column_List" >
    id, label_name, label_type, create_time, update_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from pcloud_label
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from pcloud_label
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.pcloud.book.personal.entity.PcloudLabel" >
    insert into pcloud_label (id, label_name, label_type, 
      create_time, update_time)
    values (#{id,jdbcType=INTEGER}, #{labelName,jdbcType=VARCHAR}, #{labelType,jdbcType=TINYINT}, 
      #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.pcloud.book.personal.entity.PcloudLabel" >
    insert into pcloud_label
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="labelName != null" >
        label_name,
      </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=INTEGER},
      </if>
      <if test="labelName != null" >
        #{labelName,jdbcType=VARCHAR},
      </if>
      <if test="labelType != null" >
        #{labelType,jdbcType=TINYINT},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null" >
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.pcloud.book.personal.entity.PcloudLabel" >
    update pcloud_label
    <set >
      <if test="labelName != null" >
        label_name = #{labelName,jdbcType=VARCHAR},
      </if>
      <if test="labelType != null" >
        label_type = #{labelType,jdbcType=TINYINT},
      </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=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.pcloud.book.personal.entity.PcloudLabel" >
    update pcloud_label
    set label_name = #{labelName,jdbcType=VARCHAR},
      label_type = #{labelType,jdbcType=TINYINT},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <select id="getPcloudLabelGroup" resultMap="labelGroupMap">
    select
    plt.pcloud_label_type,
    plt.pcloud_label_type_name,
    pl.label_name,
    pl.id,
    pl.label_type
    from
    pcloud_label pl
    left join pcloud_label_type plt
    on pl.label_type = plt.pcloud_label_type
  </select>

</mapper>