<?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.guide.mapper.PcloudGuideMessageMapper" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.guide.entity.PcloudGuideMessage" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="pcloud_guide_id" property="pcloudGuideId" jdbcType="INTEGER" />
    <result column="reply_type" property="replyType" jdbcType="INTEGER" />
    <result column="content" property="content" jdbcType="VARCHAR" />
    <result column="pic_url" property="picUrl" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, pcloud_guide_id, reply_type, content, pic_url, create_time, update_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from pcloud_guide_message
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from pcloud_guide_message
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.pcloud.book.guide.entity.PcloudGuideMessage" >
    insert into pcloud_guide_message (id, pcloud_guide_id, reply_type, 
      content, pic_url, create_time, 
      update_time)
    values (#{id,jdbcType=INTEGER}, #{pcloudGuideId,jdbcType=INTEGER}, #{replyType,jdbcType=INTEGER},
      #{content,jdbcType=VARCHAR}, #{picUrl,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, 
      #{updateTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.pcloud.book.guide.entity.PcloudGuideMessage" >
    insert into pcloud_guide_message
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="pcloudGuideId != null" >
        pcloud_guide_id,
      </if>
      <if test="replyType != null" >
        reply_type,
      </if>
      <if test="content != null" >
        content,
      </if>
      <if test="picUrl != null" >
        pic_url,
      </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="pcloudGuideId != null" >
        #{pcloudGuideId,jdbcType=INTEGER},
      </if>
      <if test="replyType != null" >
        #{replyType,jdbcType=INTEGER},
      </if>
      <if test="content != null" >
        #{content,jdbcType=VARCHAR},
      </if>
      <if test="picUrl != null" >
        #{picUrl,jdbcType=VARCHAR},
      </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.guide.entity.PcloudGuideMessage" >
    update pcloud_guide_message
    <set >
      <if test="pcloudGuideId != null" >
        pcloud_guide_id = #{pcloudGuideId,jdbcType=INTEGER},
      </if>
      <if test="replyType != null" >
        reply_type = #{replyType,jdbcType=INTEGER},
      </if>
      <if test="content != null" >
        content = #{content,jdbcType=VARCHAR},
      </if>
      <if test="picUrl != null" >
        pic_url = #{picUrl,jdbcType=VARCHAR},
      </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.guide.entity.PcloudGuideMessage" >
    update pcloud_guide_message
    set pcloud_guide_id = #{pcloudGuideId,jdbcType=INTEGER},
      reply_type = #{replyType,jdbcType=INTEGER},
      content = #{content,jdbcType=VARCHAR},
      pic_url = #{picUrl,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>
  
  <insert id="batchInsert" parameterType="com.pcloud.book.guide.entity.PcloudGuideMessage">
    insert into pcloud_guide_message (pcloud_guide_id, reply_type, 
      content, pic_url, create_time)
      values
      <foreach collection="list" item="item" separator=",">
        (#{item.pcloudGuideId}, #{item.replyType}, #{item.content}, #{item.picUrl}, now())
      </foreach>
  </insert>

  <delete id="deleteByGuideId" parameterType="Integer">
    delete from pcloud_guide_message where pcloud_guide_id = #{pcloudGuideId}
  </delete>

  <select id="listByGuideId" parameterType="Integer" resultType="com.pcloud.book.guide.vo.PcloudGuideMessageVO">
    SELECT
        reply_type replyType,
        content,
        pic_url picUrl
    FROM
        `pcloud_guide_message`
    WHERE
        pcloud_guide_id = #{pcloudGuideId}
  </select>

  <select id="listByRobotId" resultType="com.pcloud.book.guide.vo.PcloudGuideMessageVO">
    SELECT
        reply_type replyType,
        content,
        pic_url picUrl
    FROM
        pcloud_guide a
    LEFT JOIN pcloud_guide_message b ON a.id = b.pcloud_guide_id
    WHERE
        robot_wx_id = #{robotId}
  </select>

</mapper>