<?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.PcloudUserLabelMapper" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.personal.entity.PcloudUserLabel" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="wx_user_id" property="wxUserId" jdbcType="VARCHAR" />
    <result column="pcloud_label_id" property="pcloudLabelId" 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, wx_user_id, pcloud_label_id, create_time,
    update_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from pcloud_user_label
    where id = #{id,jdbcType=INTEGER}
  </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from pcloud_user_label
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.pcloud.book.personal.entity.PcloudUserLabel" >
    insert into pcloud_user_label (id, wx_user_id, pcloud_label_id, create_time,
      update_time)
    values (#{id,jdbcType=INTEGER}, #{wxUserId,jdbcType=VARCHAR}, #{pcloudLabelId,jdbcType=INTEGER},
    #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.pcloud.book.personal.entity.PcloudUserLabel" >
    insert into pcloud_user_label
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="wxUserId != null" >
        wx_user_id,
      </if>
      <if test="pcloudLabelId != null" >
        pcloud_label_id,
      </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="wxUserId != null" >
        #{wxUserId,jdbcType=VARCHAR},
      </if>
      <if test="pcloudLabelId != null" >
        #{pcloudLabelId,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.pcloud.book.personal.entity.PcloudUserLabel" >
    update pcloud_user_label
    <set >
      <if test="wxUserId != null" >
        wx_user_id = #{wxUserId,jdbcType=VARCHAR},
      </if>
      <if test="pcloudLabelId != null" >
        pcloud_label_id = #{pcloudLabelId,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=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.pcloud.book.personal.entity.PcloudUserLabel" >
    update pcloud_user_label
    set wx_user_id = #{wxUserId,jdbcType=VARCHAR},
    pcloud_label_id = #{pcloudLabelId,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <select id="getPcloudUserLabelList"  parameterType="string" resultType="com.pcloud.book.personal.dto.PcloudUserLabelDto">
    select
    pul.id,
    pul.wx_user_id wxUserId,
    pul.pcloud_label_id pcloudLabelId,
    pl.label_name pcloudLabelName,
    pl.label_type pcloudLabelType
    from
    pcloud_user_label pul
    left join pcloud_label pl
    on pul.pcloud_label_id = pl.id
    where
    pul.wx_user_id = #{wechatUserId}
    order by pul.create_time desc
  </select>

  <insert id="batchInsert" parameterType="com.pcloud.book.personal.entity.PcloudUserLabel">
    INSERT INTO  pcloud_user_label (
    wx_user_id,
    pcloud_label_id,
    create_time,
    update_time
    ) VALUES
    <foreach collection="list" item="item" index="index" separator="," >
      (
      #{item.wxUserId},
      #{item.pcloudLabelId},
      now(),
      now()
      )
    </foreach>
  </insert>

  <delete id="batchDeletePcloudUserLabel" parameterType="list">
    delete
    from
    pcloud_user_label
    where
    id in
    <foreach collection="list" item="item" index="index" open="(" close=")" separator="," >
      #{item}
    </foreach>
  </delete>

</mapper>