<?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.pcloudkeyword.dao.impl.PcloudRobotWelcomeDaoImpl" >
  <resultMap id="BaseResultMap" type="PcloudRobotWelcome" >
    <id column="id" property="id" jdbcType="INTEGER" />
      <result column="pcloud_robot_id" property="pcloudRobotId" jdbcType="BIGINT"/>
      <result column="pcloud_classify_id" property="pcloudClassifyId" jdbcType="BIGINT"/>
      <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="file_name" property="fileName" jdbcType="VARCHAR"/>
      <result column="file_type" property="fileType" jdbcType="VARCHAR"/>
      <result column="file_url" property="fileUrl" jdbcType="VARCHAR"/>
      <result column="file_size" property="fileSize" jdbcType="BIGINT"/>
      <result column="resource_id" property="resourceId" jdbcType="INTEGER"/>
      <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
      <result column="personal_applets_id" property="personalAppletsId" jdbcType="BIGINT"/>
      <result column="robot_type" property="robotType" jdbcType="INTEGER"/>
      <result column="welcome_duration" property="welcomeDuration" jdbcType="INTEGER"/>
      <result column="is_open_push_h5url" property="isOpenPushH5url" jdbcType="INTEGER"/>

  </resultMap>
  <sql id="Base_Column_List" >
    id, pcloud_robot_id, pcloud_classify_id, reply_type, content, pic_url, file_name, file_type, file_url,
    file_size, resource_id, create_time,personal_applets_id,robot_type,welcome_duration,is_open_push_h5url
  </sql>

    <!--批量插入-->
    <insert id="batchInsert"  parameterType="PcloudRobotWelcome" useGeneratedKeys="true" keyProperty="id">
        insert into pcloud_robot_welcome (
        pcloud_robot_id,
        pcloud_classify_id,
        reply_type,
        content,
        pic_url,
        file_name,
        file_type,
        file_url,
        file_size,
        resource_id,
        create_time,
        personal_applets_id,
        robot_type,
        welcome_duration,
        is_open_push_h5url
        ) values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.pcloudRobotId,jdbcType=BIGINT},
            #{item.pcloudClassifyId,jdbcType=BIGINT},
            #{item.replyType,jdbcType=INTEGER},
            #{item.content,jdbcType=VARCHAR},
            #{item.picUrl,jdbcType=VARCHAR},
            #{item.fileName,jdbcType=VARCHAR},
            #{item.fileType,jdbcType=VARCHAR},
            #{item.fileUrl,jdbcType=VARCHAR},
            #{item.fileSize,jdbcType=BIGINT},
            #{item.resourceId,jdbcType=BIGINT},
            NOW(),
            #{item.personalAppletsId,jdbcType=BIGINT},
            #{item.robotType,jdbcType=INTEGER},
            #{item.welcomeDuration,jdbcType=INTEGER},
            #{item.isOpenPushH5url,jdbcType=INTEGER}
            )
        </foreach>
    </insert>

    <delete id="deleteByPcloudRobotId" parameterType="long">
        delete from pcloud_robot_welcome
        where pcloud_robot_id = #{pcloudRobotId}
    </delete>

    <delete id="deleteByPcloudClassifyId" parameterType="map">
        delete from pcloud_robot_welcome
        where pcloud_classify_id = #{pcloudClassifyId} and robot_type=#{robotType}
    </delete>

    <select id="getRobotWelcomeListByPcloudRobotId" parameterType="long" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from pcloud_robot_welcome
        where pcloud_robot_id = #{pcloudRobotId}
    </select>

    <select id="getRobotWelcomeListByPcloudClassifyId" parameterType="map" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from pcloud_robot_welcome
        where pcloud_classify_id = #{pcloudClassifyId} and robot_type=#{robotType}
    </select>
</mapper>